Add diclaimer of copyright to _osname() manual page.
[unix-history] / lib / libc / gen / getgrent.3
CommitLineData
15637ed4
RG
1.\" Copyright (c) 1989, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)getgrent.3 6.8 (Berkeley) 4/20/91
33.\"
34.Dd April 20, 1991
35.Dt GETGRENT 3
36.Os
37.Sh NAME
38.Nm getgrent ,
39.Nm getgrnam ,
40.Nm getgrgid ,
41.Nm setgroupent ,
42.\" .Nm setgrfile ,
43.Nm setgrent ,
44.Nm endgrent
45.Nd group database operations
46.Sh SYNOPSIS
47.Fd #include <grp.h>
48.Ft struct group *
49.Fn getgrent void
50.Ft struct group *
0ec6b6bd 51.Fn getgrnam "const char *name"
15637ed4
RG
52.Ft struct group *
53.Fn getgrgid "gid_t gid"
54.Ft struct group *
55.Fn setgroupent "int stayopen"
56.\" .Ft void
57.\" .Fn setgrfile "const char *name"
58.Ft int
59.Fn setgrent void
60.Ft void
61.Fn endgrent void
62.Sh DESCRIPTION
63These functions operate on the group database file
64.Pa /etc/group
65which is described
66in
67.Xr group 5 .
68Each line of the database is defined by the structure
69.Ar group
70found in the include
71file
72.Aq Pa grp.h :
73.Bd -literal -offset indent
74struct group {
75 char *gr_name; /* group name */
76 char *gr_passwd; /* group password */
77 gid_t gr_gid; /* group id */
78 char **gr_mem; /* group members */
79};
80.Ed
81.Pp
82The functions
83.Fn getgrnam
84and
85.Fn getgrgid
86search the group database for the given group name pointed to by
87.Ar name
88or the group id pointed to by
89.Ar gid ,
90respectively, returning the first one encountered. Identical group
91names or group gids may result in undefined behavior.
92.Pp
93The
94.Fn getgrent
95function
96sequentially reads the group database and is intended for programs
97that wish to step through the complete list of groups.
98.Pp
99All three routines will open the group file for reading, if necesssary.
100.Pp
101The
102.Fn setgroupent
103function
104opens the file, or rewinds it if it is already open. If
105.Fa stayopen
106is non-zero, file descriptors are left open, significantly speeding
107functions subsequent calls. This functionality is unnecessary for
108.Fn getgrent
109as it doesn't close its file descriptors by default. It should also
110be noted that it is dangerous for long-running programs to use this
111functionality as the group file may be updated.
112.Pp
113The
114.Fn setgrent
115function
116is identical to
117.Fn setgroupent
118with an argument of zero.
119.Pp
120The
121.Fn endgrent
122function
123closes any open files.
124.Sh RETURN VALUES
125The functions
126.Fn getgrent ,
127.Fn getgrnam ,
128and
129.Fn getgrgid ,
130return a pointer to the group entry if successful; if end-of-file
131is reached or an error occurs a null pointer is returned.
132The functions
133.Fn setgroupent
134and
135.Fn setgrent
136return the value 1 if successful, otherwise the value
1370 is returned.
138The functions
139.Fn endgrent
140and
141.Fn setgrfile
142have no return value.
143.Sh FILES
144.Bl -tag -width /etc/group -compact
145.It Pa /etc/group
146group database file
147.El
148.Sh SEE ALSO
149.Fn getpwent 3 ,
150.Fn group 5
151.Sh HISTORY
152The functions
153.Fn endgrent ,
154.Fn getgrent ,
155.Fn getgrnam ,
156.Fn getgrgid ,
157and
158.Fn setgrent
159appeared in
160.At v7 .
161The functions
162.Fn setgrfile
163and
164.Fn setgroupent
165appeared in
166.Bx 4.3 Reno .
167.Sh COMPATIBILITY
168The historic function
169.Fn setgrfile ,
170which allowed the specification of alternate password databases, has
171been deprecated and is no longer available.
172.Sh BUGS
173The functions
174.Fn getgrent ,
175.Fn getgrnam ,
176.Fn getgrgid ,
177.Fn setgroupent
178and
179.Fn setgrent
180leave their results in an internal static object and return
181a pointer to that object. Subsequent calls to
182the same function
183will modify the same object.
184.Pp
185The functions
186.Fn getgrent ,
187.Fn endgrent ,
188.Fn setgroupent ,
189and
190.Fn setgrent
191are fairly useless in a networked environment and should be
192avoided, if possible.