]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
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. | |
c13182ef | 12 | .\" |
fea681da MK |
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. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
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 | .\" | |
29b41e74 | 33 | .TH GETGRNAM 3 2015-12-28 "" "Linux Programmer's Manual" |
fea681da MK |
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 | .sp | |
41 | .BI "struct group *getgrnam(const char *" name ); | |
42 | .sp | |
43 | .BI "struct group *getgrgid(gid_t " gid ); | |
44 | .sp | |
3b11a494 | 45 | .BI "int getgrnam_r(const char *" name ", struct group *" grp , |
fea681da | 46 | .br |
3b11a494 | 47 | .BI " char *" buf ", size_t " buflen ", struct group **" result ); |
fea681da | 48 | .sp |
3b11a494 | 49 | .BI "int getgrgid_r(gid_t " gid ", struct group *" grp , |
fea681da | 50 | .br |
3b11a494 | 51 | .BI " char *" buf ", size_t " buflen ", struct group **" result ); |
fea681da | 52 | .fi |
0f200f07 MK |
53 | .sp |
54 | .in -4n | |
55 | Feature Test Macro Requirements for glibc (see | |
56 | .BR feature_test_macros (7)): | |
57 | .ad l | |
58 | .in | |
59 | .sp | |
60 | .BR getgrnam_r (), | |
61 | .BR getgrgid_r (): | |
47bec168 | 62 | .RS 4 |
0f200f07 MK |
63 | _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE || |
64 | _SVID_SOURCE || _POSIX_SOURCE | |
47bec168 | 65 | .RE |
0f200f07 | 66 | .ad b |
fea681da MK |
67 | .SH DESCRIPTION |
68 | The | |
63aa9df0 | 69 | .BR getgrnam () |
fea681da | 70 | function returns a pointer to a structure containing |
f936cf26 | 71 | the broken-out fields of the record in the group database |
c13182ef | 72 | (e.g., the local group file |
f2738b39 MK |
73 | .IR /etc/group , |
74 | NIS, and LDAP) | |
f936cf26 | 75 | that matches the group name |
fea681da MK |
76 | .IR name . |
77 | .PP | |
78 | The | |
63aa9df0 | 79 | .BR getgrgid () |
fea681da | 80 | function returns a pointer to a structure containing |
f2738b39 | 81 | the broken-out fields of the record in the group database |
f936cf26 | 82 | that matches the group ID |
fea681da MK |
83 | .IR gid . |
84 | .PP | |
b39f3e05 MK |
85 | The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows: |
86 | .sp | |
87 | .in +4n | |
88 | .nf | |
89 | struct group { | |
5e333b1b MK |
90 | char *gr_name; /* group name */ |
91 | char *gr_passwd; /* group password */ | |
92 | gid_t gr_gid; /* group ID */ | |
b7800b44 MK |
93 | char **gr_mem; /* NULL-terminated array of pointers |
94 | to names of group members */ | |
b39f3e05 MK |
95 | }; |
96 | .fi | |
97 | .in | |
98 | .PP | |
99 | For more information about the fields of this structure, see | |
100 | .BR group (5). | |
101 | .PP | |
fea681da | 102 | The |
63aa9df0 | 103 | .BR getgrnam_r () |
fea681da | 104 | and |
63aa9df0 | 105 | .BR getgrgid_r () |
b39f3e05 MK |
106 | functions obtain the same information as |
107 | .BR getgrnam () | |
108 | and | |
109 | .BR getgrgid (), | |
110 | but store the retrieved | |
f2738b39 MK |
111 | .I group |
112 | structure | |
fea681da | 113 | in the space pointed to by |
3b11a494 | 114 | .IR grp . |
b39f3e05 | 115 | The string fields pointed to by the members of the |
f2738b39 | 116 | .I group |
b39f3e05 | 117 | structure are stored in the buffer |
fea681da MK |
118 | .I buf |
119 | of size | |
120 | .IR buflen . | |
121 | A pointer to the result (in case of success) or NULL (in case no entry | |
122 | was found or an error occurred) is stored in | |
3b11a494 | 123 | .IR *result . |
fea681da | 124 | .PP |
f7bae7f8 MK |
125 | The call |
126 | ||
127 | sysconf(_SC_GETGR_R_SIZE_MAX) | |
128 | ||
129 | returns either \-1, without changing | |
130 | .IR errno , | |
131 | or an initial suggested size for | |
132 | .IR buf . | |
133 | (If this size is too small, | |
134 | the call fails with | |
135 | .BR ERANGE , | |
136 | in which case the caller can retry with a larger buffer.) | |
47297adb | 137 | .SH RETURN VALUE |
60a90ecd MK |
138 | The |
139 | .BR getgrnam () | |
140 | and | |
141 | .BR getgrgid () | |
142 | functions return a pointer to a | |
f2738b39 MK |
143 | .I group |
144 | structure, or NULL if the matching entry | |
145 | is not found or an error occurs. | |
146 | If an error occurs, | |
fea681da | 147 | .I errno |
f2738b39 MK |
148 | is set appropriately. |
149 | If one wants to check | |
fea681da MK |
150 | .I errno |
151 | after the call, it should be set to zero before the call. | |
152 | .LP | |
c34a8ff7 | 153 | The return value may point to a static area, and may be overwritten |
fea681da | 154 | by subsequent calls to |
91fe9d5c | 155 | .BR getgrent (3), |
63aa9df0 | 156 | .BR getgrgid (), |
fea681da | 157 | or |
63aa9df0 | 158 | .BR getgrnam (). |
48e4cfa0 MK |
159 | (Do not pass the returned pointer to |
160 | .BR free (3).) | |
fea681da | 161 | .LP |
2ac1e1d3 | 162 | On success, |
60a90ecd MK |
163 | .BR getgrnam_r () |
164 | and | |
165 | .BR getgrgid_r () | |
b006e083 | 166 | return zero, and set |
3b11a494 | 167 | .IR *result |
b006e083 | 168 | to |
3b11a494 | 169 | .IR grp . |
b006e083 MK |
170 | If no matching group record was found, |
171 | these functions return 0 and store NULL in | |
3b11a494 | 172 | .IR *result . |
b006e083 | 173 | In case of error, an error number is returned, and NULL is stored in |
3b11a494 | 174 | .IR *result . |
fea681da MK |
175 | .SH ERRORS |
176 | .TP | |
177 | .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... " | |
178 | The given | |
179 | .I name | |
180 | or | |
181 | .I gid | |
182 | was not found. | |
183 | .TP | |
184 | .B EINTR | |
185 | A signal was caught. | |
186 | .TP | |
187 | .B EIO | |
188 | I/O error. | |
189 | .TP | |
190 | .B EMFILE | |
26c32fab | 191 | The per-process limit on the number of open file descriptors has been reached. |
fea681da MK |
192 | .TP |
193 | .B ENFILE | |
e258766b | 194 | The system-wide limit on the total number of open files has been reached. |
fea681da MK |
195 | .TP |
196 | .B ENOMEM | |
f2738b39 | 197 | .\" not in POSIX |
b2133414 MK |
198 | Insufficient memory to allocate |
199 | .I group | |
200 | structure. | |
fea681da MK |
201 | .\" to allocate the group structure, or to allocate buffers |
202 | .TP | |
203 | .B ERANGE | |
204 | Insufficient buffer space supplied. | |
205 | .SH FILES | |
206 | .TP | |
207 | .I /etc/group | |
f2738b39 | 208 | local group database file |
8c3438a6 | 209 | .SH ATTRIBUTES |
9209a9c2 MK |
210 | For an explanation of the terms used in this section, see |
211 | .BR attributes (7). | |
212 | .TS | |
213 | allbox; | |
ab10d107 | 214 | lb lb lb |
9209a9c2 MK |
215 | l l l. |
216 | Interface Attribute Value | |
217 | T{ | |
ab10d107 MS |
218 | .BR getgrnam () |
219 | T} Thread safety MT-Unsafe race:grnam locale | |
220 | T{ | |
8c3438a6 | 221 | .BR getgrgid () |
ab10d107 | 222 | T} Thread safety MT-Unsafe race:grgid locale |
9209a9c2 MK |
223 | T{ |
224 | .BR getgrnam_r (), | |
ab10d107 | 225 | .br |
8c3438a6 | 226 | .BR getgrgid_r () |
ab10d107 | 227 | T} Thread safety MT-Safe locale |
9209a9c2 | 228 | .TE |
47297adb | 229 | .SH CONFORMING TO |
f3ee8d98 | 230 | POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD. |
fea681da | 231 | .SH NOTES |
6497bbd9 MK |
232 | The formulation given above under "RETURN VALUE" is from POSIX.1. |
233 | .\" POSIX.1-2001, POSIX.1-2008 | |
fea681da MK |
234 | It does not call "not found" an error, hence does not specify what value |
235 | .I errno | |
c13182ef MK |
236 | might have in this situation. |
237 | But that makes it impossible to recognize | |
238 | errors. | |
239 | One might argue that according to POSIX | |
fea681da | 240 | .I errno |
c13182ef MK |
241 | should be left unchanged if an entry is not found. |
242 | Experiments on various | |
6497bbd9 | 243 | UNIX-like systems show that lots of different values occur in this |
a797afac | 244 | situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others. |
fea681da MK |
245 | .\" more precisely: |
246 | .\" AIX 5.1 - gives ESRCH | |
247 | .\" OSF1 4.0g - gives EWOULDBLOCK | |
db85058b MK |
248 | .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT |
249 | .\" glibc since version 2.7 - give 0 | |
fea681da MK |
250 | .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM |
251 | .\" SunOS 5.8 - gives EBADF | |
252 | .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0 | |
47297adb | 253 | .SH SEE ALSO |
fea681da MK |
254 | .BR endgrent (3), |
255 | .BR fgetgrent (3), | |
256 | .BR getgrent (3), | |
257 | .BR getpwnam (3), | |
258 | .BR setgrent (3), | |
259 | .BR group (5) |