]> git.saurik.com Git - apple/libinfo.git/blob - lookup.subproj/getpwent.3
Libinfo-330.3.tar.gz
[apple/libinfo.git] / lookup.subproj / getpwent.3
1 .\" Copyright (c) 1988, 1991, 1993
2 .\" The Regents of the University of California. 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 .\" 4. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\" From: @(#)getpwent.3 8.2 (Berkeley) 12/11/93
29 .\" $FreeBSD: src/lib/libc/gen/getpwent.3,v 1.30 2007/01/09 00:27:54 imp Exp $
30 .\"
31 .Dd April 16, 2003
32 .Dt GETPWENT 3
33 .Os
34 .Sh NAME
35 .Nm getpwent ,
36 .\".Nm getpwent_r ,
37 .Nm getpwnam ,
38 .Nm getpwnam_r ,
39 .Nm getpwuid ,
40 .Nm getpwuid_r ,
41 .Nm setpassent ,
42 .Nm setpwent ,
43 .Nm endpwent
44 .Nd password database operations
45 .Sh LIBRARY
46 .Lb libc
47 .Sh SYNOPSIS
48 .In sys/types.h
49 .In pwd.h
50 .Ft struct passwd *
51 .Fn getpwent void
52 .\".Ft int
53 .\".Fn getpwent_r "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
54 .Ft struct passwd *
55 .Fn getpwnam "const char *login"
56 .Ft int
57 .Fn getpwnam_r "const char *name" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
58 .Ft struct passwd *
59 .Fn getpwuid "uid_t uid"
60 .Ft int
61 .Fn getpwuid_r "uid_t uid" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
62 .Ft int
63 .Fn setpassent "int stayopen"
64 .Ft void
65 .Fn setpwent void
66 .Ft void
67 .Fn endpwent void
68 .Sh DESCRIPTION
69 These functions
70 .\"operate on the password database file
71 obtain information from
72 .Xr DirectoryService 8 ,
73 including records in
74 .Pa /etc/passwd
75 which is described
76 in
77 .Xr passwd 5 .
78 Each entry in the database is defined by the structure
79 .Vt passwd
80 found in the include
81 file
82 .In pwd.h :
83 .Bd -literal -offset indent
84 struct passwd {
85 char *pw_name; /* user name */
86 char *pw_passwd; /* encrypted password */
87 uid_t pw_uid; /* user uid */
88 gid_t pw_gid; /* user gid */
89 time_t pw_change; /* password change time */
90 char *pw_class; /* user access class */
91 char *pw_gecos; /* Honeywell login info */
92 char *pw_dir; /* home directory */
93 char *pw_shell; /* default shell */
94 time_t pw_expire; /* account expiration */
95 int pw_fields; /* internal: fields filled in */
96 };
97 .Ed
98 .Pp
99 The functions
100 .Fn getpwnam
101 and
102 .Fn getpwuid
103 search the password database for the given login name or user uid,
104 respectively, always returning the first one encountered.
105 .Pp
106 On Mac OS X, these routines are thread-safe and return a pointer to a
107 thread-specific data structure. The contents of this data
108 structure are automatically released by subsequent calls to
109 any of these routines on the same thread, or when the thread exits.
110 .Pp
111 The
112 .Fn getpwent
113 function
114 sequentially reads the password database and is intended for programs
115 that wish to process the complete list of users.
116 .Pp
117 The functions
118 .\".Fn getpwent_r ,
119 .\".Fn getpwnam_r ,
120 .Fn getpwnam_r
121 and
122 .Fn getpwuid_r
123 are thread-safe versions of
124 .\".Fn getpwent ,
125 .\".Fn getpwnam ,
126 .Fn getpwnam
127 and
128 .Fn getpwuid ,
129 respectively.
130 The caller must provide storage for the results of the search in
131 the
132 .Fa pwd ,
133 .Fa buffer ,
134 .Fa bufsize ,
135 and
136 .Fa result
137 arguments.
138 When these functions are successful, the
139 .Fa pwd
140 argument will be filled-in, and a pointer to that argument will be
141 stored in
142 .Fa result .
143 If an entry is not found or an error occurs,
144 .Fa result
145 will be set to
146 .Dv NULL .
147 .Pp
148 The
149 .Fn setpassent
150 function
151 accomplishes two purposes.
152 First, it causes
153 .Fn getpwent
154 to ``rewind'' to the beginning of the database.
155 Additionally, if
156 .Fa stayopen
157 is non-zero, file descriptors are left open, significantly speeding
158 up subsequent accesses for all of the routines.
159 (This latter functionality is unnecessary for
160 .Fn getpwent
161 as it does not close its file descriptors by default.)
162 .Pp
163 It is dangerous for long-running programs to keep the file descriptors
164 open as the database will become out of date if it is updated while the
165 program is running.
166 .Pp
167 The
168 .Fn setpwent
169 function
170 is identical to
171 .Fn setpassent
172 with an argument of zero.
173 .Pp
174 The
175 .Fn endpwent
176 function
177 closes any open files.
178 .Pp
179 .\"These routines have been written to ``shadow'' the password file, e.g.\&
180 .\"allow only certain programs to have access to the encrypted password.
181 .\"If the process which calls them has an effective uid of 0, the encrypted
182 .\"password will be returned, otherwise, the password field of the returned
183 .\"structure will point to the string
184 These routines have been written to
185 .Ql shadow
186 the password of user records created on Mac OS X 10.3 or later,
187 by returning a structure whose password field points to the string
188 .Ql ******** .
189 Legacy crypt passwords are still returned for user records created on
190 earlier versions of Mac OS X whose
191 .Xr DirectoryService 8
192 .Dt AuthenticationAuthority
193 attribute contains the value
194 .Ql ;basic; .
195 .Sh RETURN VALUES
196 The functions
197 .Fn getpwent ,
198 .Fn getpwnam ,
199 and
200 .Fn getpwuid
201 return a valid pointer to a passwd structure on success
202 or
203 .Dv NULL
204 if the entry is not found or if an error occurs.
205 If an error does occur,
206 .Va errno
207 will be set.
208 Note that programs must explicitly set
209 .Va errno
210 to zero before calling any of these functions if they need to
211 distinguish between a non-existent entry and an error.
212 The functions
213 .\".Fn getpwent_r ,
214 .\".Fn getpwnam_r ,
215 .Fn getpwnam_r
216 and
217 .Fn getpwuid_r
218 return 0 if no error occurred, or an error number to indicate failure.
219 It is not an error if a matching entry is not found.
220 (Thus, if
221 .Fa result
222 is
223 .Dv NULL
224 and the return value is 0, no matching entry exists.)
225 .Pp
226 The
227 .Fn setpassent
228 function returns 0 on failure and 1 on success.
229 The
230 .Fn endpwent
231 and
232 .Fn setpwent
233 functions
234 have no return value.
235 .Sh FILES
236 .Bl -tag -width /etc/master.passwd -compact
237 .\".It Pa /etc/pwd.db
238 .\"The insecure password database file
239 .\".It Pa /etc/spwd.db
240 The secure password database file
241 .It Pa /etc/master.passwd
242 The current password file
243 .It Pa /etc/passwd
244 A Version 7 format password file
245 .El
246 .\".Sh COMPATIBILITY
247 .\"The historic function
248 .\".Xr setpwfile 3 ,
249 .\"which allowed the specification of alternate password databases,
250 .\"has been deprecated and is no longer available.
251 .Sh ERRORS
252 These routines may fail for any of the errors specified in
253 .Xr open 2 ,
254 .Xr dbopen 3 ,
255 .Xr socket 2 ,
256 and
257 .Xr connect 2 ,
258 in addition to the following:
259 .Bl -tag -width Er
260 .It Bq Er ERANGE
261 The buffer specified by the
262 .Fa buffer
263 and
264 .Fa bufsize
265 arguments was insufficiently sized to store the result.
266 The caller should retry with a larger buffer.
267 .El
268 .Sh SEE ALSO
269 .Xr getlogin 2 ,
270 .Xr getgrent 3 ,
271 .\".Xr nsswitch.conf 5 ,
272 .Xr passwd 5 ,
273 .\".Xr pwd_mkdb 8 ,
274 .\".Xr vipw 8 ,
275 .Xr DirectoryService 8 ,
276 .Xr yp 8
277 .Sh STANDARDS
278 The
279 .Fn getpwent ,
280 .Fn getpwnam ,
281 .Fn getpwnam_r ,
282 .Fn getpwuid ,
283 .Fn getpwuid_r ,
284 .Fn setpwent ,
285 and
286 .Fn endpwent
287 functions conform to
288 .St -p1003.1-96 .
289 .Sh HISTORY
290 The
291 .Fn getpwent ,
292 .Fn getpwnam ,
293 .Fn getpwuid ,
294 .Fn setpwent ,
295 and
296 .Fn endpwent
297 functions appeared in
298 .At v7 .
299 The
300 .Fn setpassent
301 function appeared in
302 .Bx 4.3 Reno .
303 The
304 .\".Fn getpwent_r ,
305 .\".Fn getpwnam_r ,
306 .Fn getpwnam_r
307 and
308 .Fn getpwuid_r
309 functions appeared in
310 .Fx 5.1 .
311 .Sh BUGS
312 The functions
313 .Fn getpwent ,
314 .Fn getpwnam ,
315 and
316 .Fn getpwuid ,
317 .\"leave their results in an internal static object and return
318 leave their results in an internal thread-specific memory and return
319 a pointer to that object.
320 Subsequent calls to
321 the same function
322 will modify the same object.
323 .\".Pp
324 .\"The functions
325 .\".Fn getpwent ,
326 .\".Fn getpwent_r ,
327 .\".Fn endpwent ,
328 .\".Fn setpassent ,
329 .\"and
330 .\".Fn setpwent
331 .\"are fairly useless in a networked environment and should be
332 .\"avoided, if possible.
333 .\"The
334 .\".Fn getpwent
335 .\"and
336 .\".Fn getpwent_r
337 .\"functions
338 .\"make no attempt to suppress duplicate information if multiple
339 .\"sources are specified in
340 .\".Xr nsswitch.conf 5 .