Thu Apr 28 16:34:01 2011 UTC ()
Sort sections and errors.


(wiz)
diff -r1.30 -r1.31 src/lib/libc/gen/getgrent.3

cvs diff -r1.30 -r1.31 src/lib/libc/gen/getgrent.3 (switch to unified diff)

--- src/lib/libc/gen/getgrent.3 2010/03/22 19:30:53 1.30
+++ src/lib/libc/gen/getgrent.3 2011/04/28 16:34:01 1.31
@@ -1,344 +1,344 @@ @@ -1,344 +1,344 @@
1.\" $NetBSD: getgrent.3,v 1.30 2010/03/22 19:30:53 joerg Exp $ 1.\" $NetBSD: getgrent.3,v 1.31 2011/04/28 16:34:01 wiz Exp $
2.\" 2.\"
3.\" Copyright (c) 1989, 1991, 1993 3.\" Copyright (c) 1989, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 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 15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission. 16.\" without specific prior written permission.
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 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 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.\" @(#)getgrent.3 8.2 (Berkeley) 4/19/94 30.\" @(#)getgrent.3 8.2 (Berkeley) 4/19/94
31.\" 31.\"
32.Dd April 30, 2008 32.Dd April 30, 2008
33.Dt GETGRENT 3 33.Dt GETGRENT 3
34.Os 34.Os
35.Sh NAME 35.Sh NAME
36.Nm getgrent , 36.Nm getgrent ,
37.Nm getgrent_r , 37.Nm getgrent_r ,
38.Nm getgrgid , 38.Nm getgrgid ,
39.Nm getgrgid_r , 39.Nm getgrgid_r ,
40.Nm getgrnam , 40.Nm getgrnam ,
41.Nm getgrnam_r , 41.Nm getgrnam_r ,
42.Nm setgroupent , 42.Nm setgroupent ,
43.\" .Nm setgrfile , 43.\" .Nm setgrfile ,
44.Nm setgrent , 44.Nm setgrent ,
45.Nm endgrent 45.Nm endgrent
46.Nd group database operations 46.Nd group database operations
47.Sh LIBRARY 47.Sh LIBRARY
48.Lb libc 48.Lb libc
49.Sh SYNOPSIS 49.Sh SYNOPSIS
50.In grp.h 50.In grp.h
51.Ft struct group * 51.Ft struct group *
52.Fn getgrent void 52.Fn getgrent void
53.Ft int 53.Ft int
54.Fo getgrent_r 54.Fo getgrent_r
55.Fa "struct group *grp" 55.Fa "struct group *grp"
56.Fa "char *buffer" 56.Fa "char *buffer"
57.Fa "size_t buflen" 57.Fa "size_t buflen"
58.Fa "struct group **result" 58.Fa "struct group **result"
59.Fc 59.Fc
60.Ft struct group * 60.Ft struct group *
61.Fn getgrgid "gid_t gid" 61.Fn getgrgid "gid_t gid"
62.Ft int 62.Ft int
63.Fo getgrgid_r 63.Fo getgrgid_r
64.Fa "gid_t gid" 64.Fa "gid_t gid"
65.Fa "struct group *grp" 65.Fa "struct group *grp"
66.Fa "char *buffer" 66.Fa "char *buffer"
67.Fa "size_t buflen" 67.Fa "size_t buflen"
68.Fa "struct group **result" 68.Fa "struct group **result"
69.Fc 69.Fc
70.Ft struct group * 70.Ft struct group *
71.Fn getgrnam "const char *name" 71.Fn getgrnam "const char *name"
72.Ft int 72.Ft int
73.Fo getgrnam_r 73.Fo getgrnam_r
74.Fa "const char *name" 74.Fa "const char *name"
75.Fa "struct group *grp" 75.Fa "struct group *grp"
76.Fa "char *buffer" 76.Fa "char *buffer"
77.Fa "size_t buflen" 77.Fa "size_t buflen"
78.Fa "struct group **result" 78.Fa "struct group **result"
79.Fc 79.Fc
80.Ft int 80.Ft int
81.Fn setgroupent "int stayopen" 81.Fn setgroupent "int stayopen"
82.\" .Ft void 82.\" .Ft void
83.\" .Fn setgrfile "const char *name" 83.\" .Fn setgrfile "const char *name"
84.Ft void 84.Ft void
85.Fn setgrent void 85.Fn setgrent void
86.Ft void 86.Ft void
87.Fn endgrent void 87.Fn endgrent void
88.Sh DESCRIPTION 88.Sh DESCRIPTION
89These functions operate on the group database which is described in 89These functions operate on the group database which is described in
90.Xr group 5 . 90.Xr group 5 .
91Each line of the database is defined by the structure 91Each line of the database is defined by the structure
92.Ar group 92.Ar group
93found in the include 93found in the include
94file 94file
95.In grp.h : 95.In grp.h :
96.Bd -literal -offset indent 96.Bd -literal -offset indent
97struct group { 97struct group {
98 char *gr_name; /* group name */ 98 char *gr_name; /* group name */
99 char *gr_passwd; /* group password */ 99 char *gr_passwd; /* group password */
100 gid_t gr_gid; /* group id */ 100 gid_t gr_gid; /* group id */
101 char **gr_mem; /* group members */ 101 char **gr_mem; /* group members */
102}; 102};
103.Ed 103.Ed
104.Pp 104.Pp
105The functions 105The functions
106.Fn getgrnam 106.Fn getgrnam
107and 107and
108.Fn getgrgid 108.Fn getgrgid
109search the group database for the given group name pointed to by 109search the group database for the given group name pointed to by
110.Ar name 110.Ar name
111or the group id pointed to by 111or the group id pointed to by
112.Ar gid , 112.Ar gid ,
113respectively, returning the first one encountered. 113respectively, returning the first one encountered.
114Identical group names or group ids may result in undefined behavior. 114Identical group names or group ids may result in undefined behavior.
115.Pp 115.Pp
116The 116The
117.Fn getgrent 117.Fn getgrent
118function sequentially reads the group database and is intended for programs 118function sequentially reads the group database and is intended for programs
119that wish to step through the complete list of groups. 119that wish to step through the complete list of groups.
120.Pp 120.Pp
121All three functions will open the group file for reading, if necessary. 121All three functions will open the group file for reading, if necessary.
122.Pp 122.Pp
123The functions 123The functions
124.Fn getgrnam_r , 124.Fn getgrnam_r ,
125.Fn getgrgid_r , 125.Fn getgrgid_r ,
126and 126and
127.Fn getgrent_r 127.Fn getgrent_r
128act like their non re-entrant counterparts 128act like their non re-entrant counterparts
129respectively, updating the contents of 129respectively, updating the contents of
130.Ar grp 130.Ar grp
131and storing a pointer to that in 131and storing a pointer to that in
132.Ar result , 132.Ar result ,
133and returning 133and returning
134.Dv 0 . 134.Dv 0 .
135Storage used by 135Storage used by
136.Ar grp 136.Ar grp
137is allocated from 137is allocated from
138.Ar buffer , 138.Ar buffer ,
139which is 139which is
140.Ar buflen 140.Ar buflen
141bytes in size. 141bytes in size.
142If the requested entry cannot be found, 142If the requested entry cannot be found,
143.Ar result 143.Ar result
144will point to 144will point to
145.Dv NULL 145.Dv NULL
146and 146and
147.Dv 0 147.Dv 0
148will be returned. 148will be returned.
149If an error occurs, 149If an error occurs,
150a non-zero error number will be returned and 150a non-zero error number will be returned and
151.Ar result 151.Ar result
152will point to 152will point to
153.Dv NULL . 153.Dv NULL .
154Calling 154Calling
155.Fn getgrent_r 155.Fn getgrent_r
156from multiple threads will result in each thread reading a disjoint portion 156from multiple threads will result in each thread reading a disjoint portion
157of the group database. 157of the group database.
158.Pp 158.Pp
159The 159The
160.Fn setgroupent 160.Fn setgroupent
161function opens the file, or rewinds it if it is already open. 161function opens the file, or rewinds it if it is already open.
162If 162If
163.Fa stayopen 163.Fa stayopen
164is non-zero, file descriptors are left open, significantly speeding 164is non-zero, file descriptors are left open, significantly speeding
165functions subsequent calls. 165functions subsequent calls.
166This functionality is unnecessary for 166This functionality is unnecessary for
167.Fn getgrent 167.Fn getgrent
168as it doesn't close its file descriptors by default. 168as it doesn't close its file descriptors by default.
169It should also be noted that it is dangerous for long-running 169It should also be noted that it is dangerous for long-running
170programs to use this functionality as the group file may be updated. 170programs to use this functionality as the group file may be updated.
171.Pp 171.Pp
172The 172The
173.Fn setgrent 173.Fn setgrent
174function is equivalent to 174function is equivalent to
175.Fn setgroupent 175.Fn setgroupent
176with an argument of zero. 176with an argument of zero.
177.Pp 177.Pp
178The 178The
179.Fn endgrent 179.Fn endgrent
180function closes any open files. 180function closes any open files.
181.Sh RETURN VALUES 181.Sh RETURN VALUES
182The functions 182The functions
183.Fn getgrgid , 183.Fn getgrgid ,
184.Fn getgrnam , 184.Fn getgrnam ,
185and 185and
186.Fn getgrent 186.Fn getgrent
187return a valid pointer to a group structure on success 187return a valid pointer to a group structure on success
188and a 188and a
189.Dv NULL 189.Dv NULL
190pointer if the entry was not found or an error occured. 190pointer if the entry was not found or an error occured.
191If an error occured, the global variable 191If an error occured, the global variable
192.Dv errno 192.Dv errno
193is set to indicate the nature of the failure. 193is set to indicate the nature of the failure.
194.Pp 194.Pp
195The functions 195The functions
196.Fn getgrgid_r , 196.Fn getgrgid_r ,
197.Fn getgrnam_r , 197.Fn getgrnam_r ,
198and 198and
199.Fn getgrent_r 199.Fn getgrent_r
200return 200return
201.Dv 0 201.Dv 0
202on success or entry not found, and non-zero on failure, setting the global 202on success or entry not found, and non-zero on failure, setting the global
203variable 203variable
204.Dv errno 204.Dv errno
205to indicate the nature of the failure. 205to indicate the nature of the failure.
206.Pp 206.Pp
207The 207The
208.Fn setgroupent 208.Fn setgroupent
209function returns the value 1 if successful, otherwise the value 209function returns the value 1 if successful, otherwise the value
2100 is returned, setting the global variable 2100 is returned, setting the global variable
211.Dv errno 211.Dv errno
212to indicate the nature of the failure. 212to indicate the nature of the failure.
213.Pp 213.Pp
214The 214The
215.Fn endgrent 215.Fn endgrent
216and 216and
217.Fn setgrent 217.Fn setgrent
218functions have no return value. 218functions have no return value.
 219.Sh FILES
 220.Bl -tag -width /etc/group -compact
 221.It Pa /etc/group
 222group database file
 223.El
 224.Sh COMPATIBILITY
 225The historic function
 226.Fn setgrfile ,
 227which allowed the specification of alternative group databases, has
 228been deprecated and is no longer available.
219.Sh ERRORS 229.Sh ERRORS
220The following error codes may be set in 230The following error codes may be set in
221.Va errno  231.Va errno
222for 232for
223.Nm getgrent , 233.Nm getgrent ,
224.Nm getgrent_r , 234.Nm getgrent_r ,
225.Nm getgrnam , 235.Nm getgrnam ,
226.Nm getgrnam_r , 236.Nm getgrnam_r ,
227.Nm getgrgid , 237.Nm getgrgid ,
228.Nm getgrgid_r , 238.Nm getgrgid_r ,
229and 239and
230.Nm setgroupent : 240.Nm setgroupent :
231.Bl -tag -width Er 241.Bl -tag -width Er
232.It Bq Er EIO 
233An I/O error has occurred. 
234.It Bq Er EINTR 242.It Bq Er EINTR
235A signal was caught during the database search. 243A signal was caught during the database search.
 244.It Bq Er EIO
 245An I/O error has occurred.
236.It Bq Er EMFILE 246.It Bq Er EMFILE
237The limit on open files for this process has been reached. 247The limit on open files for this process has been reached.
238.It Bq Er ENFILE 248.It Bq Er ENFILE
239The system limit on open files has been reached. 249The system limit on open files has been reached.
240.El 250.El
241.Pp 251.Pp
242The following error code may be set in 252The following error code may be set in
243.Va errno  253.Va errno
244for 254for
245.Nm getgrent_r , 255.Nm getgrent_r ,
246.Nm getgrnam_r , 256.Nm getgrnam_r ,
247and 257and
248.Nm getgrgid_r : 258.Nm getgrgid_r :
249.Bl -tag -width Er 259.Bl -tag -width Er
250.It Bq Er ERANGE 260.It Bq Er ERANGE
251The resulting 261The resulting
252.Ft struct group 262.Ft struct group
253does not fit in the space defined by 263does not fit in the space defined by
254.Dv buffer 264.Dv buffer
255and 265and
256.Dv buflen 266.Dv buflen
257.El 267.El
258.Pp 268.Pp
259Other 269Other
260.Dv errno 270.Dv errno
261values may be set depending on the specific database backends. 271values may be set depending on the specific database backends.
262.Sh FILES 
263.Bl -tag -width /etc/group -compact 
264.It Pa /etc/group 
265group database file 
266.El 
267.Sh SEE ALSO 272.Sh SEE ALSO
268.Xr getpwent 3 , 273.Xr getpwent 3 ,
269.Xr group 5 , 274.Xr group 5 ,
270.Xr nsswitch.conf 5 275.Xr nsswitch.conf 5
271.Sh STANDARDS 276.Sh STANDARDS
272The 277The
273.Fn getgrgid 278.Fn getgrgid
274and 279and
275.Fn getgrnam 280.Fn getgrnam
276functions conform to 281functions conform to
277.St -p1003.1-90 . 282.St -p1003.1-90 .
278The 283The
279.Fn getgrgid_r 284.Fn getgrgid_r
280and 285and
281.Fn getgrnam_r 286.Fn getgrnam_r
282functions conform to 287functions conform to
283.St -p1003.1c-95 . 288.St -p1003.1c-95 .
284The 289The
285.Fn endgrent , 290.Fn endgrent ,
286.Fn getgrent , 291.Fn getgrent ,
287and 292and
288.Fn setgrent 293.Fn setgrent
289functions conform to 294functions conform to
290.St -xpg4.2 295.St -xpg4.2
291and 296and
292.St -p1003.1-2004 297.St -p1003.1-2004
293(XSI extension). 298(XSI extension).
294.Sh HISTORY 299.Sh HISTORY
295The functions 300The functions
296.Fn endgrent , 301.Fn endgrent ,
297.Fn getgrent , 302.Fn getgrent ,
298.Fn getgrgid , 303.Fn getgrgid ,
299.Fn getgrnam , 304.Fn getgrnam ,
300and 305and
301.Fn setgrent 306.Fn setgrent
302appeared in 307appeared in
303.At v7 . 308.At v7 .
304The functions 309The functions
305.Fn setgrfile 310.Fn setgrfile
306and 311and
307.Fn setgroupent 312.Fn setgroupent
308appeared in 313appeared in
309.Bx 4.3 Reno . 314.Bx 4.3 Reno .
310The functions 315The functions
311.Fn getgrgid_r 316.Fn getgrgid_r
312and 317and
313.Fn getgrnam_r 318.Fn getgrnam_r
314appeared in 319appeared in
315.Nx 3.0 . 320.Nx 3.0 .
316.Sh COMPATIBILITY 
317The historic function 
318.Fn setgrfile , 
319which allowed the specification of alternative group databases, has 
320been deprecated and is no longer available. 
321.Sh BUGS 321.Sh BUGS
322The functions 322The functions
323.Fn getgrent , 323.Fn getgrent ,
324.Fn getgrgid , 324.Fn getgrgid ,
325.Fn getgrnam , 325.Fn getgrnam ,
326.Fn setgroupent 326.Fn setgroupent
327and 327and
328.Fn setgrent 328.Fn setgrent
329leave their results in an internal static object and return 329leave their results in an internal static object and return
330a pointer to that object. 330a pointer to that object.
331Subsequent calls to the same function will modify the same object. 331Subsequent calls to the same function will modify the same object.
332.Pp 332.Pp
333The functions 333The functions
334.Fn getgrent , 334.Fn getgrent ,
335.Fn endgrent , 335.Fn endgrent ,
336.Fn setgroupent , 336.Fn setgroupent ,
337and 337and
338.Fn setgrent 338.Fn setgrent
339are fairly useless in a networked environment and should be 339are fairly useless in a networked environment and should be
340avoided, if possible. 340avoided, if possible.
341.Fn getgrent 341.Fn getgrent
342makes no attempt to suppress duplicate information if multiple 342makes no attempt to suppress duplicate information if multiple
343sources are specified in 343sources are specified in
344.Xr nsswitch.conf 5 344.Xr nsswitch.conf 5