|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)getpw.c 5.2 (Berkeley) 7/2/83"; ! 3: #endif ! 4: ! 5: #include <stdio.h> ! 6: ! 7: getpw(uid, buf) ! 8: int uid; ! 9: char buf[]; ! 10: { ! 11: static FILE *pwf; ! 12: register n, c; ! 13: register char *bp; ! 14: ! 15: if(pwf == 0) ! 16: pwf = fopen("/etc/passwd", "r"); ! 17: if(pwf == NULL) ! 18: return(1); ! 19: rewind(pwf); ! 20: uid &= 0377; ! 21: ! 22: for (;;) { ! 23: bp = buf; ! 24: while((c=getc(pwf)) != '\n') { ! 25: if(c <= 0) ! 26: return(1); ! 27: *bp++ = c; ! 28: } ! 29: *bp++ = '\0'; ! 30: bp = buf; ! 31: n = 3; ! 32: while(--n) ! 33: while((c = *bp++) != ':') ! 34: if(c == '\n') ! 35: return(1); ! 36: while((c = *bp++) != ':') { ! 37: if(c<'0' || c>'9') ! 38: continue; ! 39: n = n*10+c-'0'; ! 40: } ! 41: if(n == uid) ! 42: return(0); ! 43: } ! 44: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.