1GETPWENT(3) Linux Programmer's Manual GETPWENT(3)
2
3
4
6 getpwent, setpwent, endpwent - get password file entry
7
9 #include <sys/types.h>
10 #include <pwd.h>
11
12 struct passwd *getpwent(void);
13 void setpwent(void);
14 void endpwent(void);
15
16 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18 getpwent(), setpwent(), endpwent():
19 _XOPEN_SOURCE >= 500
20 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
21 || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
22
24 The getpwent() function returns a pointer to a structure containing the
25 broken-out fields of a record from the password database (e.g., the lo‐
26 cal password file /etc/passwd, NIS, and LDAP). The first time getp‐
27 went() is called, it returns the first entry; thereafter, it returns
28 successive entries.
29
30 The setpwent() function rewinds to the beginning of the password data‐
31 base.
32
33 The endpwent() function is used to close the password database after
34 all processing has been performed.
35
36 The passwd structure is defined in <pwd.h> as follows:
37
38 struct passwd {
39 char *pw_name; /* username */
40 char *pw_passwd; /* user password */
41 uid_t pw_uid; /* user ID */
42 gid_t pw_gid; /* group ID */
43 char *pw_gecos; /* user information */
44 char *pw_dir; /* home directory */
45 char *pw_shell; /* shell program */
46 };
47
48 For more information about the fields of this structure, see passwd(5).
49
51 The getpwent() function returns a pointer to a passwd structure, or
52 NULL if there are no more entries or an error occurred. If an error
53 occurs, errno is set to indicate the error. If one wants to check er‐
54 rno after the call, it should be set to zero before the call.
55
56 The return value may point to a static area, and may be overwritten by
57 subsequent calls to getpwent(), getpwnam(3), or getpwuid(3). (Do not
58 pass the returned pointer to free(3).)
59
61 EINTR A signal was caught; see signal(7).
62
63 EIO I/O error.
64
65 EMFILE The per-process limit on the number of open file descriptors has
66 been reached.
67
68 ENFILE The system-wide limit on the total number of open files has been
69 reached.
70
71 ENOMEM Insufficient memory to allocate passwd structure.
72
73 ERANGE Insufficient buffer space supplied.
74
76 /etc/passwd
77 local password database file
78
80 For an explanation of the terms used in this section, see at‐
81 tributes(7).
82
83 ┌────────────┬───────────────┬─────────────────────────────────────────┐
84 │Interface │ Attribute │ Value │
85 ├────────────┼───────────────┼─────────────────────────────────────────┤
86 │getpwent() │ Thread safety │ MT-Unsafe race:pwent race:pwentbuf │
87 │ │ │ locale │
88 ├────────────┼───────────────┼─────────────────────────────────────────┤
89 │setpwent(), │ Thread safety │ MT-Unsafe race:pwent locale │
90 │endpwent() │ │ │
91 └────────────┴───────────────┴─────────────────────────────────────────┘
92 In the above table, pwent in race:pwent signifies that if any of the
93 functions setpwent(), getpwent(), or endpwent() are used in parallel in
94 different threads of a program, then data races could occur.
95
97 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD. The pw_gecos field is not
98 specified in POSIX, but is present on most implementations.
99
101 fgetpwent(3), getpw(3), getpwent_r(3), getpwnam(3), getpwuid(3), putp‐
102 went(3), passwd(5)
103
105 This page is part of release 5.12 of the Linux man-pages project. A
106 description of the project, information about reporting bugs, and the
107 latest version of this page, can be found at
108 https://www.kernel.org/doc/man-pages/.
109
110
111
112GNU 2021-03-22 GETPWENT(3)