1 .\" $NetBSD: getpwent.3,v 1.35 2005/05/25 10:05:22 wiz Exp $
3 .\" Copyright (c) 1988, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)getpwent.3 8.2 (Berkeley) 12/11/93
45 .Nd password database operations
54 .Fa "struct passwd *pw"
57 .Fa "struct passwd **result"
60 .Fn getpwnam "const char *name"
63 .Fa "const char *name"
64 .Fa "struct passwd *pw"
67 .Fa "struct passwd **result"
70 .Fn getpwuid "uid_t uid"
74 .Fa "struct passwd *pw"
77 .Fa "struct passwd **result"
80 .Fn setpassent "int stayopen"
87 operate on the password database
91 Each entry in the database is defined by the structure
96 .Bd -literal -offset indent
98 char *pw_name; /* user name */
99 char *pw_passwd; /* encrypted password */
100 uid_t pw_uid; /* user uid */
101 gid_t pw_gid; /* user gid */
102 time_t pw_change; /* password change time */
103 char *pw_class; /* user login class */
104 char *pw_gecos; /* general information */
105 char *pw_dir; /* home directory */
106 char *pw_shell; /* default shell */
107 time_t pw_expire; /* account expiration */
115 search the password database for the given user name pointed to by
117 or user id pointed to by
119 respectively, always returning the first one encountered.
120 Identical user names or user ids may result in undefined behavior.
125 sequentially reads the password database and is intended for programs
126 that wish to process the complete list of users.
133 act like their non re-entrant counterparts, updating the contents of
135 and storing a pointer to that in
146 If the requested entry cannot be found,
154 a non-zero error number will be returned and
160 from multiple threads will result in each thread reading a disjoint portion
161 of the password database.
166 accomplishes two purposes.
171 to the beginning of the database.
174 is non-zero, file descriptors are left open, significantly speeding
175 up subsequent accesses for all of the functions.
176 (This latter functionality is unnecessary for
178 as it doesn't close its file descriptors by default.)
180 It is dangerous for long-running programs to keep the file descriptors
181 open as the database will become out of date if it is updated while the
189 with an argument of zero.
194 closes any open files.
196 These functions have been written to
198 the password file, e.g. allow only certain programs to have access
199 to the encrypted password.
200 If the process which calls them has an effective uid of 0, the encrypted
201 password will be returned, otherwise, the password field of the returned
202 structure will point to the string
210 return a valid pointer to a passwd structure on success
213 pointer if the entry was not found or an error occured.
214 If an error occured, the global variable
216 is set to indicate the nature of the failure.
219 function returns 0 on failure, setting the global variable
221 to indicate the nature of the failure, and 1 on success.
227 have no return value.
235 on success or entry not found, and non-zero on failure, setting the global
238 to indicate the nature of the failure.
240 The following error codes may be set in
253 An I/O error has occurred.
255 A signal was caught during the database search.
257 The limit on open files for this process has been reached.
259 The system limit on open files has been reached.
262 The following error code may be set in
273 does not fit in the space defined by
281 values may be set depending on the specific database backends.
283 .Bl -tag -width /etc/master.passwd -compact
285 The insecure password database file
287 The secure password database file
288 .It Pa /etc/master.passwd
289 The current password file
291 A Version 7 format password file
296 .Xr nsswitch.conf 5 ,
332 functions appeared in
350 leave their results in an internal static object and return
351 a pointer to that object.
352 Subsequent calls to any of these functions will modify the same object.
360 are fairly useless in a networked environment and should be
361 avoided, if possible.
363 makes no attempt to suppress duplicate information if multiple
364 sources are specified in
365 .Xr nsswitch.conf 5 .
367 The historic function
369 which allowed the specification of alternative password databases,
370 has been deprecated and is no longer available.