]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/Extras/libg/getpw.c
Replaced use of snprintf() with memcpy()/memmove().
[nmh] / docs / historical / mh-jun-1982 / Extras / libg / getpw.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8
9 struct buf {
10
11 int fildes;
12 int nleft;
13 char *nextp;
14 char buff[512];
15
16 };
17
18 int pich;
19
20
21 getpw(uid, buf)
22 char *buf;
23 {
24 auto pbuf[259];
25 register n, c;
26 register char *bp;
27
28 if (pich == 0) pich = open("/etc/passwd",0);
29 if (pich < 0) return(1);
30 seek(pich,0,0);
31 pbuf->fildes = pich;
32 pbuf->nleft = 0;
33 uid =& 0377; /* not for harv unix */
34
35 for(;;) {
36 bp = buf;
37 while((c=pwgetc(&pbuf)) != '\n') {
38 if (c <= 0) return(1);
39 *bp++ = c;
40 }
41 *bp++ = '\0';
42 bp = buf;
43 n = 3;
44 while(--n)
45 while((c = *bp++) != ':')
46 if (c == '\n') return(1);
47 while((c = *bp++) != ':') {
48 if (c < '0' || c > '9') continue;
49 n = n * 10 + c - '0';
50 }
51 if (n == uid) return(0);
52 }
53 return(1);
54 }
55
56 pwgetc(buf)
57 struct buf *buf;
58 {
59 register struct buf *bp;
60
61 bp = buf;
62 if (--bp->nleft < 0) {
63 bp->nleft = read(bp->fildes,bp->buff,512)-1;
64 if (bp->nleft < 0) return(-1);
65 bp->nextp = bp->buff;
66 }
67 return(*bp->nextp++);
68 }