source: trunk/minix/man/man3/getpwent.3@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 3.2 KB
Line 
1.TH GETPWENT 3
2.SH NAME
3getpwent, getpwnam, getpwuid, setpwent, endpwent, setpwfile \- password file routines
4.SH SYNOPSIS
5.ft B
6.nf
7#include <pwd.h>
8
9struct passwd *getpwent(void)
10struct passwd *getpwnam(const char *\fIname\fP)
11struct passwd *getpwuid(uid_t \fIuid\fP)
12int setpwent(void)
13void endpwent(void)
14void setpwfile(const char *\fIfile\fP)
15.fi
16.ft P
17.SH DESCRIPTION
18These functions are used to obtain information from the password file. They
19return this information in a
20.B struct passwd
21as defined by <pwd.h>:
22.PP
23.nf
24.ta +4n +6n +15n
25struct passwd {
26 char *pw_name; /* login name */
27 char *pw_passwd; /* encrypted password */
28 uid_t pw_uid; /* numeric user id */
29 gid_t pw_gid; /* numeric group id */
30 char *pw_gecos; /* user full name and other info */
31 char *pw_dir; /* user's home directory */
32 char *pw_shell; /* name of the user's shell */
33};
34.fi
35.PP
36.B Getpwent()
37reads the password file entry by entry.
38.B Getpwnam()
39scans the entire password file for the user with the given
40.IR name .
41.B Getpwuid()
42looks for the first user with the given
43.IR uid .
44The
45.B setpwent()
46and
47.B endpwent()
48functions are used to open and later close the password file. With
49.B setpwfile()
50one can specify the file to read other than the normal password file. This
51only sets the name, the next
52.B setpwent()
53call will open the file. Do not touch the file name while it is active.
54Use
55.B setpwfile(NULL)
56to revert back to the normal password file.
57.PP
58The usual way to scan the password file is (error checking omitted):
59.PP
60.RS
61.nf
62.DT
63setpwent();
64while ((pw = getpwent()) != NULL)
65 if (appropriate_test(pw)) break;
66endpwent();
67.fi
68.RE
69.PP
70The
71.B pw
72variable contains the entry that is wanted if non-NULL. The
73.B getpwnam()
74and
75.B getpwuid()
76functions are implemented as in this example, with error checking of course.
77.PP
78.B Getpwent()
79calls
80.B setpwent()
81if this has not yet been done.
82.B Setpwent()
83first calls
84.B endpwent()
85if the password file is still open. (Other implementations may simply
86rewind the file.)
87.SH FILES
88.TP 15
89.B /etc/passwd
90The password file database.
91.SH "SEE ALSO"
92.BR cuserid (3),
93.BR getlogin (3),
94.BR getgrent (3),
95.BR passwd (5).
96.SH DIAGNOSTICS
97.B Setpwent()
98has the same return value and error codes as the
99.BR open (2)
100call it uses to open the password file. The
101.BI get xxx ()
102functions return NULL on end of file, entry not found, or error. You can
103set
104.B errno
105to zero before the call and check it after.
106.SH NOTES
107All
108.BI get xxx ()
109routines return a pointer to static storage that is overwritten in each call.
110.PP
111Only
112.B getpwnam()
113and
114.B getpwuid()
115are defined by \s-2POSIX\s+2. The
116.B _MINIX_SOURCE
117macro must be defined before including <pwd.h> to make the other functions
118visible. The
119.B pw_passwd
120and
121.B pw_gecos
122fields are also not defined by \s-2POSIX\s+2, but are always visible.
123Portable code cannot reliably detect errors by setting
124.B errno
125to zero. Under MINIX 3 it is better to make a
126.B getpwent()
127scan if you need to look up several user-id's or names, but portable code
128had better use several
129.B getpwuid()
130or
131.B getpwnam()
132calls. The
133.B getpwent()
134is usually available on other systems, but may be very expensive.
135.SH AUTHOR
136Kees J. Bot (kjb@cs.vu.nl)
137
138.\"
139.\" $PchId: getpwent.3,v 1.2 1996/04/11 06:37:43 philip Exp $
Note: See TracBrowser for help on using the repository browser.