2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved.
45 .\" Portions Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved.
47 .TH GETGRNAM 3C "Feb 25, 2017"
49 getgrnam, getgrnam_r, getgrent, getgrent_r, getgrgid, getgrgid_r, setgrent,
50 endgrent, fgetgrent, fgetgrent_r \- group database entry functions
56 \fBstruct group *\fR\fBgetgrnam\fR(\fBconst char *\fR\fIname\fR);
61 \fBstruct group *\fR\fBgetgrnam_r\fR(\fBconst char *\fR\fIname\fR, \fBstruct group *\fR\fIgrp\fR,
62 \fBchar *\fR\fIbuffer\fR, \fBint\fR \fIbufsize\fR);
67 \fBstruct group *\fR\fBgetgrent\fR(\fBvoid\fR);
72 \fBstruct group *\fR\fBgetgrent_r\fR(\fBstruct group *\fR\fIgrp\fR, \fBchar *\fR\fIbuffer\fR, \fBint\fR \fIbufsize\fR);
77 \fBstruct group *\fR\fBgetgrgid\fR(\fBgid_t\fR \fIgid\fR);
82 \fBstruct group *\fR\fBgetgrgid_r\fR(\fBgid_t\fR \fIgid\fR, \fBstruct group *\fR\fIgrp\fR, \fBchar *\fR\fIbuffer\fR,
83 \fBint\fR \fIbufsize\fR);
88 \fBvoid\fR \fBsetgrent\fR(\fBvoid\fR);
93 \fBvoid\fR \fBendgrent\fR(\fBvoid\fR);
98 \fBstruct group *\fR\fBfgetgrent\fR(\fBFILE *\fR\fIf\fR);
103 \fBstruct group *\fR\fBfgetgrent_r\fR(\fBFILE *\fR\fIf\fR, \fBstruct group *\fR\fIgrp\fR, \fBchar *\fR\fIbuffer\fR,
104 \fBint\fR \fIbufsize\fR);
107 .SS "Standard conforming"
110 cc [ \fIflag\fR... ] \fIfile\fR... \fB-D_POSIX_PTHREAD_SEMANTICS\fR [ \fIlibrary\fR... ]
112 \fBint\fR \fBgetgrnam_r\fR(\fBconst char *\fR\fIname\fR, \fBstruct group *\fR\fIgrp\fR, \fBchar *\fR\fIbuffer\fR,
113 \fBsize_t\fR \fIbufsize\fR, \fBstruct group **\fR\fIresult\fR);
118 \fBint\fR \fBgetgrgid_r\fR(\fBgid_t\fR \fIgid\fR, \fBstruct group *\fR\fIgrp\fR, \fBchar *\fR\fIbuffer\fR,
119 \fBsize_t\fR \fIbufsize\fR, \fBstruct group **\fR\fIresult\fR);
124 These functions are used to obtain entries describing user groups. Entries can
125 come from any of the sources for \fBgroup\fR specified in the
126 \fB/etc/nsswitch.conf\fR file (see \fBnsswitch.conf\fR(4)).
129 The \fBgetgrnam()\fR function searches the group database for an entry with the
130 group name specified by the character string parameter \fIname\fR.
133 The \fBgetgrgid()\fR function searches the group database for an entry with the
134 (numeric) group id specified by \fIgid\fR.
137 The \fBsetgrent()\fR, \fBgetgrent()\fR, and \fBendgrent()\fR functions are used
138 to enumerate group entries from the database.
141 The \fBsetgrent()\fR function effectively rewinds the group database to allow
142 repeated searches. It sets (or resets) the enumeration to the beginning of the
143 set of group entries. This function should be called before the first call to
147 The \fBgetgrent()\fR function returns a pointer to a structure containing the
148 broken-out fields of an entry in the group database. When first called,
149 \fBgetgrent()\fR returns a pointer to a \fBgroup\fR structure containing the
150 next group structure in the group database. Successive calls can be used to
151 search the entire database.
154 The \fBendgrent()\fR function can be called to close the group database and
155 deallocate resources when processing is complete. It is permissible, though
156 possibly less efficient, for the process to call more group functions after
157 calling \fBendgrent()\fR.
160 The \fBfgetgrent()\fR function, unlike the other functions above, does not use
161 \fBnsswitch.conf\fR. It reads and parses the next line from the stream \fIf\fR,
162 which is assumed to have the format of the \fBgroup\fR file (see
164 .SS "Reentrant Interfaces"
166 The \fBgetgrnam()\fR, \fBgetgrgid()\fR, \fBgetgrent()\fR, and
167 \fBfgetgrent()\fR functions use thread-specific storage that is reused in each
168 call to one of these functions by the same thread, making them safe to use but
169 not recommended for multithreaded applications.
172 The parallel functions \fBgetgrnam_r()\fR, \fBgetgrgid_r()\fR,
173 \fBgetgrent_r()\fR, and \fBfgetgrent_r()\fR provide reentrant interfaces for
177 Each reentrant interface performs the same operation as its non-reentrant
178 counterpart, named by removing the \fB_r\fR suffix. The reentrant interfaces,
179 however, use buffers supplied by the caller to store returned results instead
180 of using thread-specific data that can be overwritten by each call. They are
181 safe for use in both single-threaded and multithreaded applications.
184 Each reentrant interface takes the same arguments as its non-reentrant
185 counterpart, as well as the following additional parameters. The \fIgrp\fR
186 argument must be a pointer to a \fBstruct group\fR structure allocated by the
187 caller. On successful completion, the function returns the group entry in this
188 structure. Storage referenced by the group structure is allocated from the
189 memory provided with the \fIbuffer\fR argument that is \fIbufsize\fR characters
190 in size. The maximum size needed for this buffer can be determined with the
191 \fB_SC_GETGR_R_SIZE_MAX\fR \fBsysconf\fR(3C) parameter. The standard-conforming
192 versions place a pointer to the modified \fIgrp\fR structure in the
193 \fIresult\fR parameter, instead of returning a pointer to this structure. A
194 null pointer is returned at the location pointed to by \fIresult\fR on error or
195 if the requested entry is not found.
198 For enumeration in multithreaded applications, the position within the
199 enumeration is a process-wide property shared by all threads. The
200 \fBsetgrent()\fR function can be used in a multithreaded application but resets
201 the enumeration position for all threads. If multiple threads interleave calls
202 to \fBgetgrent_r()\fR, the threads will enumerate disjoint subsets of the group
203 database. Like their non-reentrant counterparts, \fBgetgrnam_r()\fR and
204 \fBgetgrgid_r()\fR leave the enumeration position in an indeterminate state.
205 .SS "group Structure"
207 Group entries are represented by the \fBstruct group\fR structure defined in
213 char *gr_name; /* the name of the group */
214 char *gr_passwd; /* the encrypted group password */
215 gid_t gr_gid; /* the numerical group ID */
216 char **gr_mem; /* vector of pointers to member
224 The \fBgetgrnam()\fR, \fBgetgrnam_r()\fR, \fBgetgrgid()\fR, and
225 \fBgetgrgid_r()\fR functions each return a pointer to a \fBstruct group\fR if
226 they successfully locate the requested entry. They return a null pointer if
227 either the requested entry was not found or an error occurred. On error,
228 \fBerrno\fR is set to indicate the error. The standard-conforming functions
229 \fBgetgrnam_r()\fR and \fBgetgrgid_r()\fR return \fB0\fR upon success or an
230 error number in case of failure.
233 The \fBgetgrent()\fR, \fBgetgrent_r()\fR, \fBfgetgrent()\fR, and
234 \fBfgetgrent_r()\fR functions each return a pointer to a \fBstruct group\fR if
235 they successfully enumerate an entry; otherwise they return a null pointer on
236 end-of-file or error. On error, \fBerrno\fR is set to indicate the error.
239 The \fBgetgrnam()\fR, \fBgetgrgid()\fR, \fBgetgrent()\fR, and \fBfgetgrent()\fR
240 functions use thread-specific data storage, so returned data must be copied
241 before a subsequent call to any of these functions if the data are to be saved.
244 When the pointer returned by the reentrant functions \fBgetgrnam_r()\fR,
245 \fBgetgrgid_r()\fR, \fBgetgrent_r()\fR, and \fBfgetgrent_r()\fR is non-null, it
246 is always equal to the \fIgrp\fR pointer that was supplied by the caller.
249 Applications wishing to check for error situations should set \fBerrno\fR to 0
250 before calling \fBgetgrnam()\fR, \fBgetgrnam_r()\fR, \fBgetgrent()\fR,
251 \fBgetgrent_r()\fR\fBgetgrgid()\fR, \fBgetgrgid_r()\fR, \fBfgetgrent()\fR, and
252 \fBfgetgrent_r()\fR. If these functions return a null pointer and \fBerrno\fR
253 is non-zero, an error occurred.
256 The \fBgetgrent_r()\fR, \fBfgetgrent()\fR, and \fBfgetgrent_r()\fR functions
264 An I/O error has occurred.
273 Insufficient storage was supplied by \fIbuffer\fR and \fIbufsize\fR to contain
274 the data to be referenced by the resulting \fBgroup\fR structure.
279 The \fBgetgrent_r()\fR function will fail if:
286 There are {\fBOPEN_MAX\fR} file descriptors currently open in the calling
296 The maximum allowable number of files is currently open in the system.
301 The \fBgetgrnam()\fR, \fBgetgrnam_r()\fR, \fBgetgrgid()\fR, \fBgetgrgid_r()\fR,
302 and \fBgetgrent()\fR functions may fail if:
309 A signal was caught during the operation.
318 An I/O error has occurred.
327 There are {\fBOPEN_MAX\fR} file descriptors currently open in the calling
337 The maximum allowable number of files is currently open in the system.
342 The \fBgetgrnam_r()\fR and \fBgetgrgid_r()\fR functions may fail if:
349 Insufficient storage was supplied by \fIbuffer\fR and \fIbufsize\fR to contain
350 the data to be referenced by the resulting \fBgroup\fR structure.
355 See \fBattributes\fR(5) for descriptions of the following attributes:
363 ATTRIBUTE TYPE ATTRIBUTE VALUE
365 Interface Stability See below.
367 MT-Level See \fBReentrant Interfaces\fR in \fBDESCRIPTION\fR.
372 The \fBendgrent()\fR, \fBgetgrent()\fR, \fBgetgrgid()\fR, \fBgetgrgid_r()\fR,
373 \fBgetgrnam()\fR, \fBgetgrnam_r()\fR, and \fBsetgrent()\fR functions are
377 \fBIntro\fR(3), \fBgetpwnam\fR(3C), \fBgroup\fR(4), \fBnsswitch.conf\fR(4),
378 \fBpasswd\fR(4), \fBattributes\fR(5), \fBstandards\fR(5)
381 When compiling multithreaded programs, see \fBIntro\fR(3).
384 Use of the enumeration interfaces \fBgetgrent()\fR and \fBgetgrent_r()\fR is
385 discouraged; enumeration is supported for the group file and \fBNIS\fR
386 but in general is not efficient and might not be supported for all
387 database sources. The semantics of enumeration are discussed further in
388 \fBnsswitch.conf\fR(4).
391 Previous releases allowed the use of ``+'' and ``-'' entries in
392 \fB/etc/group\fR to selectively include and exclude entries from \fBNIS.\fR The
393 primary usage of these entries is superseded by the name service switch, so the
394 ``+/-'' form might not be supported in future releases.
397 If required, the ``+/-'' functionality can still be obtained for \fBNIS\fR by
398 specifying \fBcompat\fR as the source for \fBgroup\fR.
401 If the ``+/-'' functionality is required in conjunction with \fBLDAP,\fR
402 specify both \fBcompat\fR as the source for \fBgroup\fR and \fBldap\fR as
403 the source for the pseudo-database \fBgroup_compat\fR. See \fBgroup\fR(4), and
404 \fBnsswitch.conf\fR(4) for details.
407 Solaris 2.4 and earlier releases provided definitions of the \fBgetgrnam_r()\fR
408 and \fBgetgrgid_r()\fR functions as specified in POSIX.1c Draft 6. The final
409 POSIX.1c standard changed the interface for these functions. Support for the
410 Draft 6 interface is provided for compatibility only and might not be supported
411 in future releases. New applications and libraries should use the
412 standard-conforming interface.
415 For POSIX.1c-conforming applications, the \fB_POSIX_PTHREAD_SEMANTICS\fR and
416 \fB_REENTRANT\fR flags are automatically turned on by defining the
417 \fB_POSIX_C_SOURCE\fR flag with a value \(>=199506L.