xref: /csrg-svn/usr.bin/uucp/port/getpw.c (revision 13650)
1*13650Ssam #ifndef lint
2*13650Ssam static char sccsid[] = "@(#)getpw.c	5.1 (Berkeley) 07/02/83";
3*13650Ssam #endif
4*13650Ssam 
5*13650Ssam #include "stdio.h"
6*13650Ssam 
7*13650Ssam getpw(uid, buf)
8*13650Ssam int uid;
9*13650Ssam char buf[];
10*13650Ssam {
11*13650Ssam 	static FILE *pwf;
12*13650Ssam 	register n, c;
13*13650Ssam 	register char *bp;
14*13650Ssam 
15*13650Ssam 	if(pwf == 0)
16*13650Ssam 		pwf = fopen("/etc/passwd", "r");
17*13650Ssam 	if(pwf == NULL)
18*13650Ssam 		return(1);
19*13650Ssam 	rewind(pwf);
20*13650Ssam 	uid &= 0377;
21*13650Ssam 
22*13650Ssam 	for (;;) {
23*13650Ssam 		bp = buf;
24*13650Ssam 		while((c=getc(pwf)) != '\n') {
25*13650Ssam 			if(c <= 0)
26*13650Ssam 				return(1);
27*13650Ssam 			*bp++ = c;
28*13650Ssam 		}
29*13650Ssam 		*bp++ = '\0';
30*13650Ssam 		bp = buf;
31*13650Ssam 		n = 3;
32*13650Ssam 		while(--n)
33*13650Ssam 		while((c = *bp++) != ':')
34*13650Ssam 			if(c == '\n')
35*13650Ssam 				return(1);
36*13650Ssam 		while((c = *bp++) != ':') {
37*13650Ssam 			if(c<'0' || c>'9')
38*13650Ssam 				continue;
39*13650Ssam 			n = n*10+c-'0';
40*13650Ssam 		}
41*13650Ssam 		if(n == uid)
42*13650Ssam 			return(0);
43*13650Ssam 	}
44*13650Ssam }
45