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

NAME

6       getgrnam, getgrnam_r, getgrgid, getgrgid_r - get group file entry
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <grp.h>
11
12       struct group *getgrnam(const char *name);
13       struct group *getgrgid(gid_t gid);
14
15       int getgrnam_r(const char *restrict name, struct group *restrict grp,
16                      char *restrict buf, size_t buflen,
17                      struct group **restrict result);
18       int getgrgid_r(gid_t gid, struct group *restrict grp,
19                      char *restrict buf, size_t buflen,
20                      struct group **restrict result);
21
22   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
23
24       getgrnam_r(), getgrgid_r():
25           _POSIX_C_SOURCE
26               || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
27

DESCRIPTION

29       The getgrnam() function returns a pointer to a structure containing the
30       broken-out fields of the record in the group database (e.g., the  local
31       group file /etc/group, NIS, and LDAP) that matches the group name name.
32
33       The getgrgid() function returns a pointer to a structure containing the
34       broken-out fields of the record in the group database that matches  the
35       group ID gid.
36
37       The group structure is defined in <grp.h> as follows:
38
39           struct group {
40               char   *gr_name;        /* group name */
41               char   *gr_passwd;      /* group password */
42               gid_t   gr_gid;         /* group ID */
43               char  **gr_mem;         /* NULL-terminated array of pointers
44                                          to names of group members */
45           };
46
47       For more information about the fields of this structure, see group(5).
48
49       The getgrnam_r() and getgrgid_r() functions obtain the same information
50       as getgrnam() and getgrgid(), but store the retrieved  group  structure
51       in  the  space  pointed to by grp.  The string fields pointed to by the
52       members of the group structure are stored in the buffer buf of size bu‐
53       flen.  A pointer to the result (in case of success) or NULL (in case no
54       entry was found or an error occurred) is stored in *result.
55
56       The call
57
58           sysconf(_SC_GETGR_R_SIZE_MAX)
59
60       returns either -1, without changing errno, or an initial suggested size
61       for  buf.   (If  this size is too small, the call fails with ERANGE, in
62       which case the caller can retry with a larger buffer.)
63

RETURN VALUE

65       The getgrnam() and getgrgid() functions return a  pointer  to  a  group
66       structure,  or  NULL if the matching entry is not found or an error oc‐
67       curs.  If an error occurs, errno is set to indicate the error.  If  one
68       wants  to  check  errno after the call, it should be set to zero before
69       the call.
70
71       The return value may point to a static area, and may be overwritten  by
72       subsequent  calls  to  getgrent(3), getgrgid(), or getgrnam().  (Do not
73       pass the returned pointer to free(3).)
74
75       On success, getgrnam_r() and getgrgid_r() return zero, and set  *result
76       to  grp.  If no matching group record was found, these functions return
77       0 and store NULL in *result.  In case of error, an error number is  re‐
78       turned, and NULL is stored in *result.
79

ERRORS

81       0 or ENOENT or ESRCH or EBADF or EPERM or ...
82              The given name or gid was not found.
83
84       EINTR  A signal was caught; see signal(7).
85
86       EIO    I/O error.
87
88       EMFILE The per-process limit on the number of open file descriptors has
89              been reached.
90
91       ENFILE The system-wide limit on the total number of open files has been
92              reached.
93
94       ENOMEM Insufficient memory to allocate group structure.
95
96       ERANGE Insufficient buffer space supplied.
97

FILES

99       /etc/group
100              local group database file
101

ATTRIBUTES

103       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
104       tributes(7).
105
106       ┌──────────────┬───────────────┬───────────────────────────────────────┐
107Interface     Attribute     Value                                 
108       ├──────────────┼───────────────┼───────────────────────────────────────┤
109getgrnam()    │ Thread safety │ MT-Unsafe race:grnam locale           │
110       ├──────────────┼───────────────┼───────────────────────────────────────┤
111getgrgid()    │ Thread safety │ MT-Unsafe race:grgid locale           │
112       ├──────────────┼───────────────┼───────────────────────────────────────┤
113getgrnam_r(), │ Thread safety │ MT-Safe locale                        │
114getgrgid_r()  │               │                                       │
115       └──────────────┴───────────────┴───────────────────────────────────────┘
116

CONFORMING TO

118       POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
119

NOTES

121       The  formulation  given above under "RETURN VALUE" is from POSIX.1.  It
122       does not call "not found" an error, hence does not specify  what  value
123       errno  might  have  in this situation.  But that makes it impossible to
124       recognize errors.  One might argue that according to POSIX errno should
125       be  left  unchanged  if  an entry is not found.  Experiments on various
126       UNIX-like systems show that lots of different values occur in this sit‐
127       uation:  0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably oth‐
128       ers.
129

SEE ALSO

131       endgrent(3),  fgetgrent(3),  getgrent(3),   getpwnam(3),   setgrent(3),
132       group(5)
133

COLOPHON

135       This  page  is  part of release 5.12 of the Linux man-pages project.  A
136       description of the project, information about reporting bugs,  and  the
137       latest     version     of     this    page,    can    be    found    at
138       https://www.kernel.org/doc/man-pages/.
139
140
141
142                                  2021-03-22                       GETGRNAM(3)
Impressum