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

NAME

6       getgrent, setgrent, endgrent - get group file entry
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <grp.h>
11
12       struct group *getgrent(void);
13
14       void setgrent(void);
15
16       void endgrent(void);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       setgrent():
21           _XOPEN_SOURCE >= 500
22               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
23               || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
24       getgrent(), endgrent():
25           Since glibc 2.22:
26               _XOPEN_SOURCE >= 500 ||
27                   _DEFAULT_SOURCE
28           Glibc 2.21 and earlier
29               _XOPEN_SOURCE >= 500
30                   || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
31                   || /* Glibc versions <= 2.19: */ _BSD_SOURCE ||
32           _SVID_SOURCE
33

DESCRIPTION

35       The getgrent() function returns a pointer to a structure containing the
36       broken-out  fields  of  a record in the group database (e.g., the local
37       group file /etc/group, NIS, and LDAP).  The first  time  getgrent()  is
38       called,  it  returns the first entry; thereafter, it returns successive
39       entries.
40
41       The setgrent() function rewinds to the beginning of the group database,
42       to allow repeated scans.
43
44       The  endgrent()  function is used to close the group database after all
45       processing has been performed.
46
47       The group structure is defined in <grp.h> as follows:
48
49           struct group {
50               char   *gr_name;        /* group name */
51               char   *gr_passwd;      /* group password */
52               gid_t   gr_gid;         /* group ID */
53               char  **gr_mem;         /* NULL-terminated array of pointers
54                                          to names of group members */
55           };
56
57       For more information about the fields of this structure, see group(5).
58

RETURN VALUE

60       The getgrent() function returns a pointer to a group structure, or NULL
61       if there are no more entries or an error occurs.
62
63       Upon  error,  errno  may be set.  If one wants to check errno after the
64       call, it should be set to zero before the call.
65
66       The return value may point to a static area, and may be overwritten  by
67       subsequent  calls  to getgrent(), getgrgid(3), or getgrnam(3).  (Do not
68       pass the returned pointer to free(3).)
69

ERRORS

71       EAGAIN The service was temporarily unavailable; try again  later.   For
72              NSS  backends  in glibc this indicates a temporary error talking
73              to the backend.  The error may correct itself, retrying later is
74              suggested.
75
76       EINTR  A signal was caught; see signal(7).
77
78       EIO    I/O error.
79
80       EMFILE The per-process limit on the number of open file descriptors has
81              been reached.
82
83       ENFILE The system-wide limit on the total number of open files has been
84              reached.
85
86       ENOENT A  necessary  input  file  cannot be found.  For NSS backends in
87              glibc this indicates the backend is not correctly configured.
88
89       ENOMEM Insufficient memory to allocate group structure.
90
91       ERANGE Insufficient buffer space supplied.
92

FILES

94       /etc/group
95              local group database file
96

ATTRIBUTES

98       For  an  explanation  of  the  terms  used   in   this   section,   see
99       attributes(7).
100
101       ┌────────────┬───────────────┬─────────────────────────────┐
102Interface   Attribute     Value                       
103       ├────────────┼───────────────┼─────────────────────────────┤
104getgrent()  │ Thread safety │ MT-Unsafe race:grent        │
105       │            │               │ race:grentbuf locale        │
106       ├────────────┼───────────────┼─────────────────────────────┤
107setgrent(), │ Thread safety │ MT-Unsafe race:grent locale │
108endgrent()  │               │                             │
109       └────────────┴───────────────┴─────────────────────────────┘
110       In the above table, grent in race:grent signifies that if  any  of  the
111       functions setgrent(), getgrent(), or endgrent() are used in parallel in
112       different threads of a program, then data races could occur.
113

CONFORMING TO

115       POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
116

SEE ALSO

118       fgetgrent(3), getgrent_r(3), getgrgid(3), getgrnam(3), getgrouplist(3),
119       putgrent(3), group(5)
120

COLOPHON

122       This  page  is  part of release 5.02 of the Linux man-pages project.  A
123       description of the project, information about reporting bugs,  and  the
124       latest     version     of     this    page,    can    be    found    at
125       https://www.kernel.org/doc/man-pages/.
126
127
128
129                                  2017-09-15                       GETGRENT(3)
Impressum