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