1: #
   2: /*
   3:  * login [ name ]
   4:  */
   5: 
   6: struct {
   7:     char    name[8];
   8:     char    tty;
   9:     char    ifill;
  10:     int time[2];
  11:     int ufill;
  12: } utmp;
  13: 
  14: struct {
  15:     int speeds;
  16:     char    erase, kill;
  17:     int tflags;
  18: } ttyb;
  19: 
  20: struct {
  21:     int junk[5];
  22:     int size;
  23:     int more[12];
  24: } statb;
  25: 
  26: char    *ttyx;
  27: 
  28: #define ECHO    010
  29: 
  30: main(argc, argv)
  31: char **argv;
  32: {
  33:     char pbuf[128];
  34:     register char *namep, *np;
  35:     char pwbuf[9];
  36:     int t, sflags, f, c, uid, gid;
  37: 
  38:     signal(3, 1);
  39:     signal(2, 1);
  40:     nice(0);
  41:     ttyx = "/dev/ttyx";
  42:     if ((utmp.tty=ttyn(0)) == 'x') {
  43:         write(1, "Sorry.\n", 7);
  44:         exit();
  45:     }
  46:     ttyx[8] = utmp.tty;
  47:     gtty(0, &ttyb);
  48:     ttyb.erase = '#';
  49:     ttyb.kill = '@';
  50:     stty(0, &ttyb);
  51:     loop:
  52:     namep = utmp.name;
  53:     if (argc>1) {
  54:         np = argv[1];
  55:         while (namep<utmp.name+8 && *np)
  56:             *namep++ = *np++;
  57:         argc = 0;
  58:     } else {
  59:         write(1, "Name: ", 7);
  60:         while ((c = getchar()) != '\n') {
  61:             if (c <= 0)
  62:                 exit();
  63:             if (namep < utmp.name+8)
  64:                 *namep++ = c;
  65:         }
  66:     }
  67:     while (namep < utmp.name+8)
  68:         *namep++ = ' ';
  69:     if (getpwentry(utmp.name, pbuf))
  70:         goto bad;
  71:     np = colon(pbuf);
  72:     if (*np!=':') {
  73:         sflags = ttyb.tflags;
  74:         ttyb.tflags =& ~ ECHO;
  75:         stty(0, &ttyb);
  76:         write(1, "Password: ", 10);
  77:         namep = pwbuf;
  78:         while ((c=getchar()) != '\n') {
  79:             if (c <= 0)
  80:                 exit();
  81:             if (namep<pwbuf+8)
  82:                 *namep++ = c;
  83:         }
  84:         *namep++ = '\0';
  85:         ttyb.tflags = sflags;
  86:         stty(0, &ttyb);
  87:         write(1, "\n", 1);
  88:         namep = crypt(pwbuf);
  89:         while (*namep++ == *np++);
  90:         if (*--namep!='\0' || *--np!=':')
  91:             goto bad;
  92:     }
  93:     np = colon(np);
  94:     uid = 0;
  95:     while (*np != ':')
  96:         uid = uid*10 + *np++ - '0';
  97:     np++;
  98:     gid = 0;
  99:     while (*np != ':')
 100:         gid = gid*10 + *np++ - '0';
 101:     np++;
 102:     np = colon(np);
 103:     namep = np;
 104:     np = colon(np);
 105:     if (chdir(namep)<0) {
 106:         write(1, "No directory\n", 13);
 107:         goto loop;
 108:     }
 109:     time(utmp.time);
 110:     if ((f = open("/etc/utmp", 1)) >= 0) {
 111:         t = utmp.tty;
 112:         if (t>='a')
 113:             t =- 'a' - (10+'0');
 114:         seek(f, (t-'0')*16, 0);
 115:         write(f, &utmp, 16);
 116:         close(f);
 117:     }
 118:     if ((f = open("/usr/adm/wtmp", 1)) >= 0) {
 119:         seek(f, 0, 2);
 120:         write(f, &utmp, 16);
 121:         close(f);
 122:     }
 123:     if ((f = open("/etc/motd", 0)) >= 0) {
 124:         while(read(f, &t, 1) > 0)
 125:             write(1, &t, 1);
 126:         close(f);
 127:     }
 128:     if(stat(".mail", &statb) >= 0 && statb.size)
 129:         write(1, "You have mail.\n", 15);
 130:     chown(ttyx, uid);
 131:     setgid(gid);
 132:     setuid(uid);
 133:     if (*np == '\0')
 134:         np = "/bin/sh";
 135:     execl(np, "-", 0);
 136:     write(1, "No shell.\n", 9);
 137:     exit();
 138: bad:
 139:     write(1, "Login incorrect.\n", 17);
 140:     goto loop;
 141: }
 142: 
 143: getpwentry(name, buf)
 144: char *name, *buf;
 145: {
 146:     extern fin;
 147:     int fi, r, c;
 148:     register char *gnp, *rnp;
 149: 
 150:     fi = fin;
 151:     r = 1;
 152:     if((fin = open("/etc/passwd", 0)) < 0)
 153:         goto ret;
 154: loop:
 155:     gnp = name;
 156:     rnp = buf;
 157:     while((c=getchar()) != '\n') {
 158:         if(c <= 0)
 159:             goto ret;
 160:         *rnp++ = c;
 161:     }
 162:     *rnp++ = '\0';
 163:     rnp = buf;
 164:     while (*gnp++ == *rnp++);
 165:     if ((*--gnp!=' ' && gnp<name+8) || *--rnp!=':')
 166:         goto loop;
 167:     r = 0;
 168: ret:
 169:     close(fin);
 170:     fin = 0;
 171:     (&fin)[1] = 0;
 172:     (&fin)[2] = 0;
 173:     return(r);
 174: }
 175: 
 176: colon(p)
 177: char *p;
 178: {
 179:     register char *rp;
 180: 
 181:     rp = p;
 182:     while (*rp != ':') {
 183:         if (*rp++ == '\0') {
 184:             write(1, "Bad /etc/passwd\n", 16);
 185:             exit();
 186:         }
 187:     }
 188:     *rp++ = '\0';
 189:     return(rp);
 190: }

Defined functions

colon defined in line 176; used 4 times
getpwentry defined in line 143; used 1 times
  • in line 69
main defined in line 30; never used

Defined variables

ttyx defined in line 26; used 3 times

Defined macros

ECHO defined in line 28; used 1 times
  • in line 74
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 7775
Valid CSS Valid XHTML 1.0 Strict