xref: /csrg-svn/lib/libcompat/4.1/getpw.c (revision 21327)
1*21327Sdist /*
2*21327Sdist  * Copyright (c) 1980 Regents of the University of California.
3*21327Sdist  * All rights reserved.  The Berkeley software License Agreement
4*21327Sdist  * specifies the terms and conditions for redistribution.
5*21327Sdist  */
6*21327Sdist 
7*21327Sdist #ifndef lint
8*21327Sdist static char sccsid[] = "@(#)getpw.c	5.1 (Berkeley) 05/30/85";
9*21327Sdist #endif not lint
10*21327Sdist 
112018Swnj #include	<stdio.h>
122018Swnj 
132018Swnj getpw(uid, buf)
142018Swnj int uid;
152018Swnj char buf[];
162018Swnj {
172018Swnj 	static FILE *pwf;
182018Swnj 	register n, c;
192018Swnj 	register char *bp;
202018Swnj 
212018Swnj 	if(pwf == 0)
222018Swnj 		pwf = fopen("/etc/passwd", "r");
232018Swnj 	if(pwf == NULL)
242018Swnj 		return(1);
252018Swnj 	rewind(pwf);
262018Swnj 
272018Swnj 	for (;;) {
282018Swnj 		bp = buf;
292018Swnj 		while((c=getc(pwf)) != '\n') {
302018Swnj 			if(c == EOF)
312018Swnj 				return(1);
322018Swnj 			*bp++ = c;
332018Swnj 		}
342018Swnj 		*bp++ = '\0';
352018Swnj 		bp = buf;
362018Swnj 		n = 3;
372018Swnj 		while(--n)
382018Swnj 		while((c = *bp++) != ':')
392018Swnj 			if(c == '\n')
402018Swnj 				return(1);
412018Swnj 		while((c = *bp++) != ':') {
422018Swnj 			if(c<'0' || c>'9')
432018Swnj 				continue;
442018Swnj 			n = n*10+c-'0';
452018Swnj 		}
462018Swnj 		if(n == uid)
472018Swnj 			return(0);
482018Swnj 	}
492018Swnj }
50