Changes: Ready for 5.13
[man-pages.git] / man3 / getgrnam.3
blobb942cb3ca907ad78035a1ad161bff60a56c9a853
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 1993-07-24 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified 2003-11-15 by aeb
32 .\"
33 .TH GETGRNAM 3 2021-03-22 "" "Linux Programmer's Manual"
34 .SH NAME
35 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
36 .SH SYNOPSIS
37 .nf
38 .B #include <sys/types.h>
39 .B #include <grp.h>
40 .PP
41 .BI "struct group *getgrnam(const char *" name );
42 .BI "struct group *getgrgid(gid_t " gid );
43 .PP
44 .BI "int getgrnam_r(const char *restrict " name \
45 ", struct group *restrict " grp ,
46 .BI "               char *restrict " buf ", size_t " buflen ,
47 .BI "               struct group **restrict " result );
48 .BI "int getgrgid_r(gid_t " gid ", struct group *restrict " grp ,
49 .BI "               char *restrict " buf ", size_t " buflen ,
50 .BI "               struct group **restrict " result );
51 .fi
52 .PP
53 .RS -4
54 Feature Test Macro Requirements for glibc (see
55 .BR feature_test_macros (7)):
56 .RE
57 .PP
58 .BR getgrnam_r (),
59 .BR getgrgid_r ():
60 .nf
61     _POSIX_C_SOURCE
62         || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
63 .fi
64 .SH DESCRIPTION
65 The
66 .BR getgrnam ()
67 function returns a pointer to a structure containing
68 the broken-out fields of the record in the group database
69 (e.g., the local group file
70 .IR /etc/group ,
71 NIS, and LDAP)
72 that matches the group name
73 .IR name .
74 .PP
75 The
76 .BR getgrgid ()
77 function returns a pointer to a structure containing
78 the broken-out fields of the record in the group database
79 that matches the group ID
80 .IR gid .
81 .PP
82 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
83 .PP
84 .in +4n
85 .EX
86 struct group {
87     char   *gr_name;        /* group name */
88     char   *gr_passwd;      /* group password */
89     gid_t   gr_gid;         /* group ID */
90     char  **gr_mem;         /* NULL\-terminated array of pointers
91                                to names of group members */
93 .EE
94 .in
95 .PP
96 For more information about the fields of this structure, see
97 .BR group (5).
98 .PP
99 The
100 .BR getgrnam_r ()
102 .BR getgrgid_r ()
103 functions obtain the same information as
104 .BR getgrnam ()
106 .BR getgrgid (),
107 but store the retrieved
108 .I group
109 structure
110 in the space pointed to by
111 .IR grp .
112 The string fields pointed to by the members of the
113 .I group
114 structure are stored in the buffer
115 .I buf
116 of size
117 .IR buflen .
118 A pointer to the result (in case of success) or NULL (in case no entry
119 was found or an error occurred) is stored in
120 .IR *result .
122 The call
124     sysconf(_SC_GETGR_R_SIZE_MAX)
126 returns either \-1, without changing
127 .IR errno ,
128 or an initial suggested size for
129 .IR buf .
130 (If this size is too small,
131 the call fails with
132 .BR ERANGE ,
133 in which case the caller can retry with a larger buffer.)
134 .SH RETURN VALUE
136 .BR getgrnam ()
138 .BR getgrgid ()
139 functions return a pointer to a
140 .I group
141 structure, or NULL if the matching entry
142 is not found or an error occurs.
143 If an error occurs,
144 .I errno
145 is set to indicate the error.
146 If one wants to check
147 .I errno
148 after the call, it should be set to zero before the call.
150 The return value may point to a static area, and may be overwritten
151 by subsequent calls to
152 .BR getgrent (3),
153 .BR getgrgid (),
155 .BR getgrnam ().
156 (Do not pass the returned pointer to
157 .BR free (3).)
159 On success,
160 .BR getgrnam_r ()
162 .BR getgrgid_r ()
163 return zero, and set
164 .IR *result
166 .IR grp .
167 If no matching group record was found,
168 these functions return 0 and store NULL in
169 .IR *result .
170 In case of error, an error number is returned, and NULL is stored in
171 .IR *result .
172 .SH ERRORS
174 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ..."
175 The given
176 .I name
178 .I gid
179 was not found.
181 .B EINTR
182 A signal was caught; see
183 .BR signal (7).
185 .B EIO
186 I/O error.
188 .B EMFILE
189 The per-process limit on the number of open file descriptors has been reached.
191 .B ENFILE
192 The system-wide limit on the total number of open files has been reached.
194 .B ENOMEM
195 .\" not in POSIX
196 Insufficient memory to allocate
197 .I group
198 structure.
199 .\" to allocate the group structure, or to allocate buffers
201 .B ERANGE
202 Insufficient buffer space supplied.
203 .SH FILES
205 .I /etc/group
206 local group database file
207 .SH ATTRIBUTES
208 For an explanation of the terms used in this section, see
209 .BR attributes (7).
210 .ad l
213 allbox;
214 lb lb lbx
215 l l l.
216 Interface       Attribute       Value
218 .BR getgrnam ()
219 T}      Thread safety   T{
220 MT-Unsafe race:grnam locale
223 .BR getgrgid ()
224 T}      Thread safety   T{
225 MT-Unsafe race:grgid locale
228 .BR getgrnam_r (),
229 .BR getgrgid_r ()
230 T}      Thread safety   MT-Safe locale
234 .sp 1
235 .SH CONFORMING TO
236 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
237 .SH NOTES
238 The formulation given above under "RETURN VALUE" is from POSIX.1.
239 .\" POSIX.1-2001, POSIX.1-2008
240 It does not call "not found" an error, hence does not specify what value
241 .I errno
242 might have in this situation.
243 But that makes it impossible to recognize
244 errors.
245 One might argue that according to POSIX
246 .I errno
247 should be left unchanged if an entry is not found.
248 Experiments on various
249 UNIX-like systems show that lots of different values occur in this
250 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.
251 .\" more precisely:
252 .\" AIX 5.1 - gives ESRCH
253 .\" OSF1 4.0g - gives EWOULDBLOCK
254 .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
255 .\" glibc since version 2.7 - give 0
256 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
257 .\" SunOS 5.8 - gives EBADF
258 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
259 .SH SEE ALSO
260 .BR endgrent (3),
261 .BR fgetgrent (3),
262 .BR getgrent (3),
263 .BR getpwnam (3),
264 .BR setgrent (3),
265 .BR group (5)