xref: /freebsd/lib/libc/gen/getgrent.3 (revision 95f4226b2755f1600e3bf4e32e8aa0db0886c280)
158f0484fSRodney W. Grimes.\" Copyright (c) 1989, 1991, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
658f0484fSRodney W. Grimes.\" are met:
758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
858f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1058f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1158f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1258f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
1358f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1458f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1558f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
1758f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1858f0484fSRodney W. Grimes.\"    without specific prior written permission.
1958f0484fSRodney W. Grimes.\"
2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3058f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3158f0484fSRodney W. Grimes.\"
326af9798fSGarrett Wollman.\"     From: @(#)getgrent.3	8.2 (Berkeley) 4/19/94
337f3dea24SPeter Wemm.\" $FreeBSD$
3458f0484fSRodney W. Grimes.\"
356af9798fSGarrett Wollman.Dd September 29, 1994
3658f0484fSRodney W. Grimes.Dt GETGRENT 3
3758f0484fSRodney W. Grimes.Os
3858f0484fSRodney W. Grimes.Sh NAME
3958f0484fSRodney W. Grimes.Nm getgrent ,
4058f0484fSRodney W. Grimes.Nm getgrnam ,
4158f0484fSRodney W. Grimes.Nm getgrgid ,
4258f0484fSRodney W. Grimes.Nm setgroupent ,
4358f0484fSRodney W. Grimes.\" .Nm setgrfile ,
4458f0484fSRodney W. Grimes.Nm setgrent ,
4558f0484fSRodney W. Grimes.Nm endgrent
4658f0484fSRodney W. Grimes.Nd group database operations
4725bb73e0SAlexey Zelkin.Sh LIBRARY
4825bb73e0SAlexey Zelkin.Lb libc
4958f0484fSRodney W. Grimes.Sh SYNOPSIS
5032eef9aeSRuslan Ermilov.In grp.h
5158f0484fSRodney W. Grimes.Ft struct group *
5258f0484fSRodney W. Grimes.Fn getgrent void
5358f0484fSRodney W. Grimes.Ft struct group *
5458f0484fSRodney W. Grimes.Fn getgrnam "const char *name"
5558f0484fSRodney W. Grimes.Ft struct group *
5658f0484fSRodney W. Grimes.Fn getgrgid "gid_t gid"
57712dc76eSMike Pritchard.Ft int
5858f0484fSRodney W. Grimes.Fn setgroupent "int stayopen"
5958f0484fSRodney W. Grimes.\" .Ft void
6058f0484fSRodney W. Grimes.\" .Fn setgrfile "const char *name"
6158f0484fSRodney W. Grimes.Ft int
6258f0484fSRodney W. Grimes.Fn setgrent void
6358f0484fSRodney W. Grimes.Ft void
6458f0484fSRodney W. Grimes.Fn endgrent void
6558f0484fSRodney W. Grimes.Sh DESCRIPTION
6658f0484fSRodney W. GrimesThese functions operate on the group database file
6758f0484fSRodney W. Grimes.Pa /etc/group
6858f0484fSRodney W. Grimeswhich is described
6958f0484fSRodney W. Grimesin
7058f0484fSRodney W. Grimes.Xr group 5 .
7158f0484fSRodney W. GrimesEach line of the database is defined by the structure
7258f0484fSRodney W. Grimes.Ar group
7358f0484fSRodney W. Grimesfound in the include
7458f0484fSRodney W. Grimesfile
7558f0484fSRodney W. Grimes.Aq Pa grp.h :
7658f0484fSRodney W. Grimes.Bd -literal -offset indent
7758f0484fSRodney W. Grimesstruct group {
7858f0484fSRodney W. Grimes	char	*gr_name;	/* group name */
7958f0484fSRodney W. Grimes	char	*gr_passwd;	/* group password */
805567b258SMark Murray	gid_t	gr_gid;		/* group id */
811ffa6450SMike Pritchard	char	**gr_mem;	/* group members */
8258f0484fSRodney W. Grimes};
8358f0484fSRodney W. Grimes.Ed
8458f0484fSRodney W. Grimes.Pp
8558f0484fSRodney W. GrimesThe functions
8658f0484fSRodney W. Grimes.Fn getgrnam
8758f0484fSRodney W. Grimesand
8858f0484fSRodney W. Grimes.Fn getgrgid
8958f0484fSRodney W. Grimessearch the group database for the given group name pointed to by
9058f0484fSRodney W. Grimes.Ar name
9158f0484fSRodney W. Grimesor the group id pointed to by
9258f0484fSRodney W. Grimes.Ar gid ,
9358f0484fSRodney W. Grimesrespectively, returning the first one encountered.  Identical group
9458f0484fSRodney W. Grimesnames or group gids may result in undefined behavior.
9558f0484fSRodney W. Grimes.Pp
9658f0484fSRodney W. GrimesThe
9758f0484fSRodney W. Grimes.Fn getgrent
9858f0484fSRodney W. Grimesfunction
9958f0484fSRodney W. Grimessequentially reads the group database and is intended for programs
10058f0484fSRodney W. Grimesthat wish to step through the complete list of groups.
10158f0484fSRodney W. Grimes.Pp
10258f0484fSRodney W. GrimesAll three routines will open the group file for reading, if necessary.
10358f0484fSRodney W. Grimes.Pp
10458f0484fSRodney W. GrimesThe
10558f0484fSRodney W. Grimes.Fn setgroupent
10658f0484fSRodney W. Grimesfunction
10758f0484fSRodney W. Grimesopens the file, or rewinds it if it is already open.  If
10858f0484fSRodney W. Grimes.Fa stayopen
10958f0484fSRodney W. Grimesis non-zero, file descriptors are left open, significantly speeding
11058f0484fSRodney W. Grimesfunctions subsequent calls.  This functionality is unnecessary for
11158f0484fSRodney W. Grimes.Fn getgrent
11258f0484fSRodney W. Grimesas it doesn't close its file descriptors by default.  It should also
11358f0484fSRodney W. Grimesbe noted that it is dangerous for long-running programs to use this
11458f0484fSRodney W. Grimesfunctionality as the group file may be updated.
11558f0484fSRodney W. Grimes.Pp
11658f0484fSRodney W. GrimesThe
11758f0484fSRodney W. Grimes.Fn setgrent
11858f0484fSRodney W. Grimesfunction
11958f0484fSRodney W. Grimesis identical to
12058f0484fSRodney W. Grimes.Fn setgroupent
12158f0484fSRodney W. Grimeswith an argument of zero.
12258f0484fSRodney W. Grimes.Pp
12358f0484fSRodney W. GrimesThe
12458f0484fSRodney W. Grimes.Fn endgrent
12558f0484fSRodney W. Grimesfunction
12658f0484fSRodney W. Grimescloses any open files.
12758f0484fSRodney W. Grimes.Sh RETURN VALUES
12858f0484fSRodney W. GrimesThe functions
12958f0484fSRodney W. Grimes.Fn getgrent ,
13058f0484fSRodney W. Grimes.Fn getgrnam ,
13158f0484fSRodney W. Grimesand
13258f0484fSRodney W. Grimes.Fn getgrgid ,
13358f0484fSRodney W. Grimesreturn a pointer to the group entry if successful; if end-of-file
13458f0484fSRodney W. Grimesis reached or an error occurs a null pointer is returned.
13558f0484fSRodney W. GrimesThe functions
13658f0484fSRodney W. Grimes.Fn setgroupent
13758f0484fSRodney W. Grimesand
13858f0484fSRodney W. Grimes.Fn setgrent
13958f0484fSRodney W. Grimesreturn the value 1 if successful, otherwise the value
14058f0484fSRodney W. Grimes0 is returned.
14158f0484fSRodney W. GrimesThe functions
14258f0484fSRodney W. Grimes.Fn endgrent
14358f0484fSRodney W. Grimesand
14458f0484fSRodney W. Grimes.Fn setgrfile
14558f0484fSRodney W. Grimeshave no return value.
14658f0484fSRodney W. Grimes.Sh FILES
14758f0484fSRodney W. Grimes.Bl -tag -width /etc/group -compact
14858f0484fSRodney W. Grimes.It Pa /etc/group
14958f0484fSRodney W. Grimesgroup database file
15058f0484fSRodney W. Grimes.El
15158f0484fSRodney W. Grimes.Sh SEE ALSO
15228f86af2SMike Pritchard.Xr getpwent 3 ,
153248aee62SJacques Vidrine.Xr group 5 ,
154491a8429SRuslan Ermilov.Xr nsswitch.conf 5 ,
155491a8429SRuslan Ermilov.Xr yp 8
15658f0484fSRodney W. Grimes.Sh HISTORY
15758f0484fSRodney W. GrimesThe functions
15858f0484fSRodney W. Grimes.Fn endgrent ,
15958f0484fSRodney W. Grimes.Fn getgrent ,
16058f0484fSRodney W. Grimes.Fn getgrnam ,
16158f0484fSRodney W. Grimes.Fn getgrgid ,
16258f0484fSRodney W. Grimesand
16358f0484fSRodney W. Grimes.Fn setgrent
16458f0484fSRodney W. Grimesappeared in
16558f0484fSRodney W. Grimes.At v7 .
16658f0484fSRodney W. GrimesThe functions
16758f0484fSRodney W. Grimes.Fn setgrfile
16858f0484fSRodney W. Grimesand
16958f0484fSRodney W. Grimes.Fn setgroupent
17058f0484fSRodney W. Grimesappeared in
17158f0484fSRodney W. Grimes.Bx 4.3 Reno .
17258f0484fSRodney W. Grimes.Sh COMPATIBILITY
17358f0484fSRodney W. GrimesThe historic function
17458f0484fSRodney W. Grimes.Fn setgrfile ,
17558f0484fSRodney W. Grimeswhich allowed the specification of alternate password databases, has
17658f0484fSRodney W. Grimesbeen deprecated and is no longer available.
17758f0484fSRodney W. Grimes.Sh BUGS
17858f0484fSRodney W. GrimesThe functions
17958f0484fSRodney W. Grimes.Fn getgrent ,
18058f0484fSRodney W. Grimes.Fn getgrnam ,
18158f0484fSRodney W. Grimes.Fn getgrgid ,
18258f0484fSRodney W. Grimes.Fn setgroupent
18358f0484fSRodney W. Grimesand
18458f0484fSRodney W. Grimes.Fn setgrent
18558f0484fSRodney W. Grimesleave their results in an internal static object and return
186c6ff3a1bSSheldon Hearna pointer to that object.
187c6ff3a1bSSheldon HearnSubsequent calls to
18858f0484fSRodney W. Grimesthe same function
18958f0484fSRodney W. Grimeswill modify the same object.
190248aee62SJacques Vidrine.Pp
191248aee62SJacques VidrineThe functions
192248aee62SJacques Vidrine.Fn getgrent ,
193248aee62SJacques Vidrine.Fn endgrent ,
194248aee62SJacques Vidrine.Fn setgroupent ,
195248aee62SJacques Vidrineand
196248aee62SJacques Vidrine.Fn setgrent
197248aee62SJacques Vidrineare fairly useless in a networked environment and should be
198248aee62SJacques Vidrineavoided, if possible.
19995f4226bSRuslan ErmilovThe
200248aee62SJacques Vidrine.Fn getgrent
20195f4226bSRuslan Ermilovfunction
202248aee62SJacques Vidrinemakes no attempt to suppress duplicate information if multiple
203248aee62SJacques Vidrinesources are specified in
204248aee62SJacques Vidrine.Xr nsswitch.conf 5 .
205