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