1: /*
2: * Modified version of getpwent which doesn't use stdio.
3: * This is done to keep it (and hence csh) small at a small
4: * cost in speed.
5: *
6: * This version also uses the UCB hashed password file if whoami.h
7: * indicates that UCB_PWHASH is available. In any case if it fails
8: * it tries the regular linear search.
9: *
10: * Define BBGETPW (Bare Bones GETPW) if all you are interested in is
11: * the name, uid, and directory fields. This will make getpwent smaller
12: * and a bit faster and is useful for things like csh.
13: */
14: #define BBGETPW
15:
16: #include <pwd.h>
17: #include <whoami.h>
18:
19: #ifdef UCB_PWHASH
20: #define pwf _pw_file /* unlikely symbol name */
21: #endif
22:
23: /*
24: * predefined strings
25: */
26: #undef BUFSIZ
27: #define BUFSIZ 160
28:
29: int pwf = -1; /* password file pointer */
30:
31: char line[BUFSIZ+1]; /* input buffer */
32:
33: struct passwd passwd; /* password entry */
34:
35: setpwent()
36: {
37: if( pwf == -1 )
38: pwf = open( "/etc/passwd", 0 );
39: else
40: lseek(pwf, 0l, 0);
41: }
42:
43: endpwent()
44: {
45: if( pwf != -1 ){
46: close( pwf );
47: pwf = -1;
48: }
49: }
50:
51: static char *
52: pwskip(p)
53: register char *p;
54: {
55: while( *p && *p != ':' )
56: ++p;
57: if( *p ) *p++ = 0;
58: return(p);
59: }
60:
61: struct passwd *
62: getpwent()
63: {
64: register char *p, *q;
65: register int i, j;
66:
67: if (pwf == -1) {
68: if( (pwf = open( "/etc/passwd", 0 )) == -1 )
69: return(0);
70: }
71: i = read(pwf, line, BUFSIZ);
72: for (j = 0; j < i; j++)
73: if (line[j] == '\n')
74: break;
75: if (j >= i)
76: return(0);
77: line[++j] = 0;
78: lseek(pwf, (long) (j - i), 1);
79: p = line;
80: passwd.pw_name = p;
81: p = pwskip(p);
82: #ifndef BBGETPW
83: passwd.pw_passwd = p;
84: #endif
85: p = pwskip(p);
86: passwd.pw_uid = atoi(p);
87: p = pwskip(p);
88: #ifndef BBGETPW
89: passwd.pw_gid = atoi(p);
90: passwd.pw_quota = 0;
91: passwd.pw_comment = "";
92: #endif
93: p = pwskip(p);
94: #ifndef BBGETPW
95: passwd.pw_gecos = p;
96: #endif
97: p = pwskip(p);
98: passwd.pw_dir = p;
99: p = pwskip(p);
100: #ifndef BBGETPW
101: passwd.pw_shell = p;
102: while(*p && *p != '\n') p++;
103: *p = '\0';
104: #endif
105: return(&passwd);
106: }
Defined functions
Defined variables
line
defined in line
31; used 4 times
passwd
defined in line
33; used 10 times
pwf
defined in line
29;
never used
Defined macros
pwf
defined in line
20; used 10 times