1: int gbuf[259];
   2: int pbuf[259];
   3: int ttyb[3];
   4: char    name[10];
   5: char    passwd[10];
   6: char    space[1000];
   7: int peek;
   8: int pwdflg;
   9: 
  10: main(argc, argv)
  11: char *argv[];
  12: {
  13:     register id;
  14:     register char *p, *q;
  15: 
  16:     if(argc < 2) {
  17:         printf("usage: newgrp groupname\n");
  18:         done();
  19:     }
  20:     if(fopen("/etc/group", gbuf) < 0) {
  21:         printf("cannot open group file\n");
  22:         done();
  23:     }
  24:     do {
  25:         field(name, gbuf);
  26:         p = name;
  27:         q = argv[1];
  28:         while(*p == *q++)
  29:             if(*p++ == 0 || p >= name+8)
  30:                 goto l1;
  31:     } while(skip(gbuf));
  32:     printf("%s: not a valid group name\n", argv[1]);
  33:     done();
  34: 
  35: l1:
  36:     if(fopen("/etc/passwd", pbuf) < 0) {
  37:         printf("cannot open password file\n");
  38:         done();
  39:     }
  40:     p = space;
  41:     id = getuid() & 0377;
  42:     do {
  43:         field(p, pbuf);
  44:         field(name, pbuf);
  45:         if(value(pbuf) == id) {
  46:             if(name[0] == 0)
  47:                 pwdflg++;
  48:             while(*p++) ;
  49:         }
  50:     } while(skip(pbuf));
  51:     *p = 0;
  52: 
  53:     field(passwd, gbuf);
  54:     id = value(gbuf);
  55:     if(id == 1) {
  56:         pwdflg = 0;
  57:         goto l2;
  58:     }
  59:     do {
  60:         p = space;
  61:         field(name, gbuf);
  62:         while(*p) {
  63:             q = name;
  64:             while(*p == *q++) {
  65:                 if(*p++ == 0)
  66:                     goto l2;
  67:             }
  68:             while(*p++) ;
  69:         }
  70:     } while(peek == ',');
  71:     goto no;
  72: 
  73: l2:
  74:     if(pwdflg && passwd[0]) {
  75:         printf("password: ");
  76:         gtty(0, pbuf);
  77:         pbuf[3] = pbuf[2];
  78:         pbuf[2] =& ~010;
  79:         stty(0, pbuf);
  80:         read(0, gbuf, 512);
  81:         pbuf[2] = pbuf[3];
  82:         stty(0, pbuf);
  83:         printf("\n");
  84:         p = name;
  85:         q = gbuf;
  86:         while(p < name+8) {
  87:             if(*q == '\n')
  88:                 break;
  89:             *p++ = *q++;
  90:         }
  91:         *p = 0;
  92:         p = crypt(name);
  93:         q = passwd;
  94:         while(q < passwd+8)
  95:             if(*p++ != *q++)
  96:                 goto no;
  97:     }
  98:     if(setgid(id) < 0) {
  99:         perror("setgid");
 100:         goto no;
 101:     }
 102:     done();
 103: 
 104: no:
 105:     printf("Sorry\n");
 106:     done();
 107: }
 108: 
 109: skip(buf)
 110: {
 111: 
 112:     while(peek > 0) {
 113:         if(peek == '\n') {
 114:             peek = 1;
 115:             return(1);
 116:         }
 117:         peek = getc(buf);
 118:     }
 119:     return(0);
 120: }
 121: 
 122: field(cp, buf)
 123: {
 124:     register c;
 125:     register char *p, *q;
 126: 
 127:     p = cp;
 128:     q = p+8;
 129:     while((c = getc(buf)) != '\n') {
 130:         if(c == ',' || c == ':' || c <= 0)
 131:             break;
 132:         if(p < q)
 133:             *p++ = c;
 134:     }
 135:     *p = 0;
 136:     peek = c;
 137: }
 138: 
 139: value(buf)
 140: {
 141:     register n, c;
 142: 
 143:     n = 0;
 144:     while((c = getc(buf)) >= '0' && c <= '9')
 145:         n = n*10 + c-'0';
 146:     peek = c;
 147:     return(n);
 148: }
 149: 
 150: done()
 151: {
 152: 
 153:     setuid(getuid());
 154:     execl("/bin/sh", "-", 0);
 155:     exit();
 156: }

Defined functions

done defined in line 150; used 6 times
field defined in line 122; used 5 times
main defined in line 10; never used
skip defined in line 109; used 2 times
value defined in line 139; used 2 times

Defined variables

gbuf defined in line 1; used 8 times
name defined in line 4; used 10 times
passwd defined in line 5; used 4 times
pbuf defined in line 2; used 13 times
peek defined in line 7; used 7 times
pwdflg defined in line 8; used 3 times
space defined in line 6; used 2 times
ttyb defined in line 3; never used
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 922
Valid CSS Valid XHTML 1.0 Strict