]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/getpwent.3
capget.2, gettimeofday.2, nanosleep.2, process_vm_readv.2, readv.2, seccomp.2, semop...
[thirdparty/man-pages.git] / man3 / getpwent.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\" 386BSD man pages
29 .\"
30 .\" Modified Sat Jul 24 19:22:14 1993 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified Mon May 27 21:37:47 1996 by Martin Schulze (joey@linux.de)
32 .\"
33 .TH GETPWENT 3 2016-03-15 "GNU" "Linux Programmer's Manual"
34 .SH NAME
35 getpwent, setpwent, endpwent \- get password file entry
36 .SH SYNOPSIS
37 .nf
38 .B #include <sys/types.h>
39 .B #include <pwd.h>
40 .PP
41 .B struct passwd *getpwent(void);
42 .PP
43 .B void setpwent(void);
44 .PP
45 .B void endpwent(void);
46 .fi
47 .PP
48 .in -4n
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
51 .in
52 .PP
53 .ad l
54 .BR getpwent (),
55 .BR setpwent (),
56 .BR endpwent ():
57 .RS 4
58 _XOPEN_SOURCE\ >=\ 500
59 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
60 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
61 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
62 .RE
63 .ad b
64 .SH DESCRIPTION
65 The
66 .BR getpwent ()
67 function returns a pointer to a structure containing
68 the broken-out fields of a record from the password database
69 (e.g., the local password file
70 .IR /etc/passwd ,
71 NIS, and LDAP).
72 The first time
73 .BR getpwent ()
74 is called, it returns the first entry; thereafter, it returns successive
75 entries.
76 .PP
77 The
78 .BR setpwent ()
79 function rewinds to the beginning
80 of the password database.
81 .PP
82 The
83 .BR endpwent ()
84 function is used to close the password database
85 after all processing has been performed.
86 .PP
87 The \fIpasswd\fP structure is defined in \fI<pwd.h>\fP as follows:
88 .PP
89 .in +4n
90 .nf
91 struct passwd {
92 char *pw_name; /* username */
93 char *pw_passwd; /* user password */
94 uid_t pw_uid; /* user ID */
95 gid_t pw_gid; /* group ID */
96 char *pw_gecos; /* user information */
97 char *pw_dir; /* home directory */
98 char *pw_shell; /* shell program */
99 };
100 .fi
101 .in
102 .PP
103 For more information about the fields of this structure, see
104 .BR passwd (5).
105 .SH RETURN VALUE
106 The
107 .BR getpwent ()
108 function returns a pointer to a
109 .I passwd
110 structure, or NULL if
111 there are no more entries or an error occurred.
112 If an error occurs,
113 .I errno
114 is set appropriately.
115 If one wants to check
116 .I errno
117 after the call, it should be set to zero before the call.
118 .PP
119 The return value may point to a static area, and may be overwritten
120 by subsequent calls to
121 .BR getpwent (),
122 .BR getpwnam (3),
123 or
124 .BR getpwuid (3).
125 (Do not pass the returned pointer to
126 .BR free (3).)
127 .SH ERRORS
128 .TP
129 .B EINTR
130 A signal was caught; see
131 .BR signal (7).
132 .TP
133 .B EIO
134 I/O error.
135 .TP
136 .B EMFILE
137 The per-process limit on the number of open file descriptors has been reached.
138 .TP
139 .B ENFILE
140 The system-wide limit on the total number of open files has been reached.
141 .TP
142 .B ENOMEM
143 .\" not in POSIX
144 Insufficient memory to allocate
145 .I passwd
146 structure.
147 .\" to allocate the passwd structure, or to allocate buffers
148 .TP
149 .B ERANGE
150 Insufficient buffer space supplied.
151 .SH FILES
152 .TP
153 .I /etc/passwd
154 local password database file
155 .SH ATTRIBUTES
156 For an explanation of the terms used in this section, see
157 .BR attributes (7).
158 .TS
159 allbox;
160 lbw11 lb lb
161 l l l.
162 Interface Attribute Value
163 T{
164 .BR getpwent ()
165 T} Thread safety T{
166 MT-Unsafe race:pwent
167 .br
168 race:pwentbuf locale
169 T}
170 T{
171 .BR setpwent (),
172 .br
173 .BR endpwent ()
174 T} Thread safety MT-Unsafe race:pwent locale
175 .TE
176 .sp 1
177 In the above table,
178 .I pwent
179 in
180 .I race:pwent
181 signifies that if any of the functions
182 .BR setpwent (),
183 .BR getpwent (),
184 or
185 .BR endpwent ()
186 are used in parallel in different threads of a program,
187 then data races could occur.
188 .SH CONFORMING TO
189 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
190 The
191 .I pw_gecos
192 field is not specified in POSIX, but is present on most implementations.
193 .SH SEE ALSO
194 .BR fgetpwent (3),
195 .BR getpw (3),
196 .BR getpwent_r (3),
197 .BR getpwnam (3),
198 .BR getpwuid (3),
199 .BR putpwent (3),
200 .BR passwd (5)