|
|
1.1 root 1: #include <stdio.h>
2: #include <pwd.h>
3:
4: static char PASSWD[] = "/etc/passwd";
5: static char EMPTY[] = "";
6: static FILE *pwf = NULL;
7: static char line[BUFSIZ+1];
8: static struct passwd passwd;
9:
10: setpwent()
11: {
12: if( pwf == NULL )
13: pwf = fopen( PASSWD, "r" );
14: else
15: rewind( pwf );
16: }
17:
18: endpwent()
19: {
20: if( pwf != NULL ){
21: fclose( pwf );
22: pwf = NULL;
23: }
24: }
25:
26: static char *
27: pwskip(p)
28: register char *p;
29: {
30: while( *p && *p != ':' )
31: ++p;
32: if( *p ) *p++ = 0;
33: return(p);
34: }
35:
36: struct passwd *
37: getpwent()
38: {
39: register char *p;
40:
41: if (pwf == NULL) {
42: if( (pwf = fopen( PASSWD, "r" )) == NULL )
43: return(0);
44: }
45: p = fgets(line, BUFSIZ, pwf);
46: if (p==NULL)
47: return(0);
48: passwd.pw_name = p;
49: p = pwskip(p);
50: passwd.pw_passwd = p;
51: p = pwskip(p);
52: passwd.pw_uid = atoi(p);
53: p = pwskip(p);
54: passwd.pw_gid = atoi(p);
55: passwd.pw_quota = 0;
56: passwd.pw_comment = EMPTY;
57: p = pwskip(p);
58: passwd.pw_gecos = p;
59: p = pwskip(p);
60: passwd.pw_dir = p;
61: p = pwskip(p);
62: passwd.pw_shell = p;
63: while(*p && *p != '\n') p++;
64: *p = '\0';
65: return(&passwd);
66: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.