1 .\" $NetBSD: getgrent.3,v 1.31 2011/04/28 16:34:01 wiz Exp $
3 .\" Copyright (c) 1989, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)getgrent.3 8.2 (Berkeley) 4/19/94
46 .Nd group database operations
55 .Fa "struct group *grp"
58 .Fa "struct group **result"
61 .Fn getgrgid "gid_t gid"
65 .Fa "struct group *grp"
68 .Fa "struct group **result"
71 .Fn getgrnam "const char *name"
74 .Fa "const char *name"
75 .Fa "struct group *grp"
78 .Fa "struct group **result"
81 .Fn setgroupent "int stayopen"
83 .\" .Fn setgrfile "const char *name"
89 These functions operate on the group database which is described in
91 Each line of the database is defined by the structure
96 .Bd -literal -offset indent
98 char *gr_name; /* group name */
99 char *gr_passwd; /* group password */
100 gid_t gr_gid; /* group id */
101 char **gr_mem; /* group members */
109 search the group database for the given group name pointed to by
111 or the group id pointed to by
113 respectively, returning the first one encountered.
114 Identical group names or group ids may result in undefined behavior.
118 function sequentially reads the group database and is intended for programs
119 that wish to step through the complete list of groups.
121 All three functions will open the group file for reading, if necessary.
128 act like their non re-entrant counterparts
129 respectively, updating the contents of
131 and storing a pointer to that in
142 If the requested entry cannot be found,
150 a non-zero error number will be returned and
156 from multiple threads will result in each thread reading a disjoint portion
157 of the group database.
161 function opens the file, or rewinds it if it is already open.
164 is non-zero, file descriptors are left open, significantly speeding
165 functions subsequent calls.
166 This functionality is unnecessary for
168 as it doesn't close its file descriptors by default.
169 It should also be noted that it is dangerous for long-running
170 programs to use this functionality as the group file may be updated.
174 function is equivalent to
176 with an argument of zero.
180 function closes any open files.
187 return a valid pointer to a group structure on success
190 pointer if the entry was not found or an error occured.
191 If an error occured, the global variable
193 is set to indicate the nature of the failure.
202 on success or entry not found, and non-zero on failure, setting the global
205 to indicate the nature of the failure.
209 function returns the value 1 if successful, otherwise the value
210 0 is returned, setting the global variable
212 to indicate the nature of the failure.
218 functions have no return value.
220 .Bl -tag -width /etc/group -compact
225 The historic function
227 which allowed the specification of alternative group databases, has
228 been deprecated and is no longer available.
230 The following error codes may be set in
243 A signal was caught during the database search.
245 An I/O error has occurred.
247 The limit on open files for this process has been reached.
249 The system limit on open files has been reached.
252 The following error code may be set in
263 does not fit in the space defined by
271 values may be set depending on the specific database backends.
329 leave their results in an internal static object and return
330 a pointer to that object.
331 Subsequent calls to the same function will modify the same object.
339 are fairly useless in a networked environment and should be
340 avoided, if possible.
342 makes no attempt to suppress duplicate information if multiple
343 sources are specified in