1GETPWENT(3)                Linux Programmer's Manual               GETPWENT(3)
2
3
4

NAME

6       getpwent, setpwent, endpwent - get password file entry
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <pwd.h>
11
12       struct passwd *getpwent(void);
13
14       void setpwent(void);
15
16       void endpwent(void);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       getpwent(), setpwent(), endpwent():
21           _XOPEN_SOURCE >= 500
22               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
23               || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
24

DESCRIPTION

26       The getpwent() function returns a pointer to a structure containing the
27       broken-out fields of a record from the  password  database  (e.g.,  the
28       local  password file /etc/passwd, NIS, and LDAP).  The first time getp‐
29       went() is called, it returns the first entry;  thereafter,  it  returns
30       successive entries.
31
32       The  setpwent() function rewinds to the beginning of the password data‐
33       base.
34
35       The endpwent() function is used to close the  password  database  after
36       all processing has been performed.
37
38       The passwd structure is defined in <pwd.h> as follows:
39
40           struct passwd {
41               char   *pw_name;       /* username */
42               char   *pw_passwd;     /* user password */
43               uid_t   pw_uid;        /* user ID */
44               gid_t   pw_gid;        /* group ID */
45               char   *pw_gecos;      /* user information */
46               char   *pw_dir;        /* home directory */
47               char   *pw_shell;      /* shell program */
48           };
49
50       For more information about the fields of this structure, see passwd(5).
51

RETURN VALUE

53       The  getpwent()  function  returns  a pointer to a passwd structure, or
54       NULL if there are no more entries or an error occurred.   If  an  error
55       occurs,  errno is set appropriately.  If one wants to check errno after
56       the call, it should be set to zero before the call.
57
58       The return value may point to a static area, and may be overwritten  by
59       subsequent  calls  to getpwent(), getpwnam(3), or getpwuid(3).  (Do not
60       pass the returned pointer to free(3).)
61

ERRORS

63       EINTR  A signal was caught; see signal(7).
64
65       EIO    I/O error.
66
67       EMFILE The per-process limit on the number of open file descriptors has
68              been reached.
69
70       ENFILE The system-wide limit on the total number of open files has been
71              reached.
72
73       ENOMEM Insufficient memory to allocate passwd structure.
74
75       ERANGE Insufficient buffer space supplied.
76

FILES

78       /etc/passwd
79              local password database file
80

ATTRIBUTES

82       For  an  explanation  of  the  terms  used   in   this   section,   see
83       attributes(7).
84
85       ┌────────────┬───────────────┬─────────────────────────────┐
86Interface   Attribute     Value                       
87       ├────────────┼───────────────┼─────────────────────────────┤
88getpwent()  │ Thread safety │ MT-Unsafe race:pwent        │
89       │            │               │ race:pwentbuf locale        │
90       ├────────────┼───────────────┼─────────────────────────────┤
91setpwent(), │ Thread safety │ MT-Unsafe race:pwent locale │
92endpwent()  │               │                             │
93       └────────────┴───────────────┴─────────────────────────────┘
94       In  the  above  table, pwent in race:pwent signifies that if any of the
95       functions setpwent(), getpwent(), or endpwent() are used in parallel in
96       different threads of a program, then data races could occur.
97

CONFORMING TO

99       POSIX.1-2001,  POSIX.1-2008,  SVr4,  4.3BSD.  The pw_gecos field is not
100       specified in POSIX, but is present on most implementations.
101

SEE ALSO

103       fgetpwent(3), getpw(3), getpwent_r(3), getpwnam(3), getpwuid(3),  putp‐
104       went(3), passwd(5)
105

COLOPHON

107       This  page  is  part of release 4.15 of the Linux man-pages project.  A
108       description of the project, information about reporting bugs,  and  the
109       latest     version     of     this    page,    can    be    found    at
110       https://www.kernel.org/doc/man-pages/.
111
112
113
114GNU                               2017-09-15                       GETPWENT(3)
Impressum