Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | .\" Copyright (c) 1988, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)getpwent.3 6.8 (Berkeley) 4/19/91 | |
33 | .\" | |
34 | .Dd April 19, 1991 | |
35 | .Dt GETPWENT 3 | |
36 | .Os | |
37 | .Sh NAME | |
38 | .Nm getpwent , | |
39 | .Nm getpwnam , | |
40 | .Nm getpwuid , | |
41 | .Nm setpassent , | |
42 | .Nm setpwent , | |
43 | .Nm endpwent | |
44 | .Nd password database operations | |
45 | .Sh SYNOPSIS | |
46 | .Fd #include <sys/types.h> | |
47 | .Fd #include <pwd.h> | |
48 | .Ft struct passwd * | |
49 | .Fn getpwent void | |
50 | .Ft struct passwd * | |
51 | .Fn getpwnam "const char *login" | |
52 | .Ft struct passwd * | |
53 | .Fn getpwuid "uid_t uid" | |
54 | .Ft int | |
55 | .Fn setpassent "int stayopen" | |
56 | .Ft int | |
57 | .Fn setpwent void | |
58 | .Ft void | |
59 | .Fn endpwent void | |
60 | .Sh DESCRIPTION | |
61 | These functions | |
62 | operate on the password database file | |
63 | which is described | |
64 | in | |
65 | .Xr passwd 5 . | |
66 | Each entry in the database is defined by the structure | |
67 | .Ar passwd | |
68 | found in the include | |
69 | file | |
70 | .Aq Pa pwd.h : | |
71 | .Bd -literal -offset indent | |
72 | struct passwd { | |
73 | char *pw_name; /* user name */ | |
74 | char *pw_passwd; /* encrypted password */ | |
75 | uid_t pw_uid; /* user uid */ | |
76 | gid_t pw_gid; /* user gid */ | |
77 | time_t pw_change; /* password change time */ | |
78 | char *pw_class; /* user access class */ | |
79 | char *pw_gecos; /* Honeywell login info */ | |
80 | char *pw_dir; /* home directory */ | |
81 | char *pw_shell; /* default shell */ | |
82 | time_t pw_expire; /* account expiration */ | |
83 | }; | |
84 | .Ed | |
85 | .Pp | |
86 | The functions | |
87 | .Fn getpwnam | |
88 | and | |
89 | .Fn getpwuid | |
90 | search the password database for the given login name or user uid, | |
91 | respectively, always returning the first one encountered. | |
92 | .Pp | |
93 | The | |
94 | .Fn getpwent | |
95 | function | |
96 | sequentially reads the password database and is intended for programs | |
97 | that wish to process the complete list of users. | |
98 | .Pp | |
99 | The | |
100 | .Fn setpassent | |
101 | function | |
102 | accomplishes two purposes. | |
103 | First, it causes | |
104 | .Fn getpwent | |
105 | to ``rewind'' to the beginning of the database. | |
106 | Additionally, if | |
107 | .Fa stayopen | |
108 | is non-zero, file descriptors are left open, significantly speeding | |
109 | up subsequent accesses for all of the routines. | |
110 | (This latter functionality is unnecessary for | |
111 | .Fn getpwent | |
112 | as it doesn't close its file descriptors by default.) | |
113 | .Pp | |
114 | It is dangerous for long-running programs to keep the file descriptors | |
115 | open the database will become out of date if it is updated while the | |
116 | program is running. | |
117 | .Pp | |
118 | The | |
119 | .Fn setpwent | |
120 | function | |
121 | is identical to | |
122 | .Fn setpassent | |
123 | with an argument of zero. | |
124 | .Pp | |
125 | The | |
126 | .Fn endpwent | |
127 | function | |
128 | closes any open files. | |
129 | .Pp | |
130 | These routines have been written to ``shadow'' the password file, e.g. | |
131 | allow only certain programs to have access to the encrypted password. | |
132 | If the process which calls them has an effective uid of 0, the encrypted | |
133 | password will be returned, otherwise, the password field of the retuned | |
134 | structure will point to the string | |
135 | .Ql * . | |
136 | .Sh RETURN VALUES | |
137 | The functions | |
138 | .Fn getpwent , | |
139 | .Fn getpwnam , | |
140 | and | |
141 | .Fn getpwuid , | |
142 | return a valid pointer to a passwd structure on success | |
143 | and a null pointer if end-of-file is reached or an error occurs. | |
144 | The functions | |
145 | .Fn setpassent | |
146 | and | |
147 | .Fn setpwent | |
148 | return 0 on failure and 1 on success. | |
149 | The | |
150 | .Fn endpwent | |
151 | function | |
152 | has no return value. | |
153 | .Sh FILES | |
154 | .Bl -tag -width /etc/master.passwd -compact | |
155 | .It Pa /var/db/pwd.db | |
156 | The insecure password database file | |
157 | .It Pa /var/db/spwd.db | |
158 | The secure password database file | |
159 | .It Pa /etc/master.passwd | |
160 | The current password file | |
161 | .It Pa /etc/passwd | |
162 | A Version 7 format password file | |
163 | .El | |
164 | .Sh SEE ALSO | |
165 | .Xr getlogin 3 , | |
166 | .Xr getgrent 3 , | |
167 | .Xr passwd 5 , | |
168 | .Xr pwd_mkdb 8 , | |
169 | .Xr vipw 8 | |
170 | .Sh HISTORY | |
171 | The | |
172 | .Nm getpwent , | |
173 | .Nm getpwnam , | |
174 | .Nm getpwuid , | |
175 | .Nm setpwent, | |
176 | and | |
177 | .Nm endpwent | |
178 | functions appeared in | |
179 | .At v7 . | |
180 | The | |
181 | .Nm setpassent | |
182 | function appeared in | |
183 | .Bx 4.3 Reno . | |
184 | .Sh BUGS | |
185 | The functions | |
186 | .Fn getpwent , | |
187 | .Fn getpwnam , | |
188 | and | |
189 | .Fn getpwuid , | |
190 | leave their results in an internal static object and return | |
191 | a pointer to that object. Subsequent calls to | |
192 | the same function | |
193 | will modify the same object. | |
194 | .Pp | |
195 | The routines | |
196 | .Fn getpwent , | |
197 | .Fn endpwent , | |
198 | .Fn setpassent , | |
199 | and | |
200 | .Fn setpwent | |
201 | are fairly useless in a networked environment and should be | |
202 | avoided, if possible. | |
203 | .Sh COMPATIBILITY | |
204 | The historic function | |
205 | .Xr setpwfile 3 , | |
206 | which allowed the specification of alternate password databases, | |
207 | has been deprecated and is no longer available. |