xref: /freebsd/lib/libc/gen/getgrent.3 (revision 58f0484fa251c266ede97b591b499fe3dd4f578e)
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.\"
3258f0484fSRodney W. Grimes.\"     @(#)getgrent.3	8.2 (Berkeley) 4/19/94
3358f0484fSRodney W. Grimes.\"
3458f0484fSRodney W. Grimes.Dd April 19, 1994
3558f0484fSRodney W. Grimes.Dt GETGRENT 3
3658f0484fSRodney W. Grimes.Os
3758f0484fSRodney W. Grimes.Sh NAME
3858f0484fSRodney W. Grimes.Nm getgrent ,
3958f0484fSRodney W. Grimes.Nm getgrnam ,
4058f0484fSRodney W. Grimes.Nm getgrgid ,
4158f0484fSRodney W. Grimes.Nm setgroupent ,
4258f0484fSRodney W. Grimes.\" .Nm setgrfile ,
4358f0484fSRodney W. Grimes.Nm setgrent ,
4458f0484fSRodney W. Grimes.Nm endgrent
4558f0484fSRodney W. Grimes.Nd group database operations
4658f0484fSRodney W. Grimes.Sh SYNOPSIS
4758f0484fSRodney W. Grimes.Fd #include <grp.h>
4858f0484fSRodney W. Grimes.Ft struct group *
4958f0484fSRodney W. Grimes.Fn getgrent void
5058f0484fSRodney W. Grimes.Ft struct group *
5158f0484fSRodney W. Grimes.Fn getgrnam "const char *name"
5258f0484fSRodney W. Grimes.Ft struct group *
5358f0484fSRodney W. Grimes.Fn getgrgid "gid_t gid"
5458f0484fSRodney W. Grimes.Ft struct group *
5558f0484fSRodney W. Grimes.Fn setgroupent "int stayopen"
5658f0484fSRodney W. Grimes.\" .Ft void
5758f0484fSRodney W. Grimes.\" .Fn setgrfile "const char *name"
5858f0484fSRodney W. Grimes.Ft int
5958f0484fSRodney W. Grimes.Fn setgrent void
6058f0484fSRodney W. Grimes.Ft void
6158f0484fSRodney W. Grimes.Fn endgrent void
6258f0484fSRodney W. Grimes.Sh DESCRIPTION
6358f0484fSRodney W. GrimesThese functions operate on the group database file
6458f0484fSRodney W. Grimes.Pa /etc/group
6558f0484fSRodney W. Grimeswhich is described
6658f0484fSRodney W. Grimesin
6758f0484fSRodney W. Grimes.Xr group 5 .
6858f0484fSRodney W. GrimesEach line of the database is defined by the structure
6958f0484fSRodney W. Grimes.Ar group
7058f0484fSRodney W. Grimesfound in the include
7158f0484fSRodney W. Grimesfile
7258f0484fSRodney W. Grimes.Aq Pa grp.h :
7358f0484fSRodney W. Grimes.Bd -literal -offset indent
7458f0484fSRodney W. Grimesstruct group {
7558f0484fSRodney W. Grimes	char	*gr_name;	/* group name */
7658f0484fSRodney W. Grimes	char	*gr_passwd;	/* group password */
7758f0484fSRodney W. Grimes	gid_t	gr_gid;		/* group id */
7858f0484fSRodney W. Grimes	char	**gr_mem;	/* group members */
7958f0484fSRodney W. Grimes};
8058f0484fSRodney W. Grimes.Ed
8158f0484fSRodney W. Grimes.Pp
8258f0484fSRodney W. GrimesThe functions
8358f0484fSRodney W. Grimes.Fn getgrnam
8458f0484fSRodney W. Grimesand
8558f0484fSRodney W. Grimes.Fn getgrgid
8658f0484fSRodney W. Grimessearch the group database for the given group name pointed to by
8758f0484fSRodney W. Grimes.Ar name
8858f0484fSRodney W. Grimesor the group id pointed to by
8958f0484fSRodney W. Grimes.Ar gid ,
9058f0484fSRodney W. Grimesrespectively, returning the first one encountered.  Identical group
9158f0484fSRodney W. Grimesnames or group gids may result in undefined behavior.
9258f0484fSRodney W. Grimes.Pp
9358f0484fSRodney W. GrimesThe
9458f0484fSRodney W. Grimes.Fn getgrent
9558f0484fSRodney W. Grimesfunction
9658f0484fSRodney W. Grimessequentially reads the group database and is intended for programs
9758f0484fSRodney W. Grimesthat wish to step through the complete list of groups.
9858f0484fSRodney W. Grimes.Pp
9958f0484fSRodney W. GrimesAll three routines will open the group file for reading, if necessary.
10058f0484fSRodney W. Grimes.Pp
10158f0484fSRodney W. GrimesThe
10258f0484fSRodney W. Grimes.Fn setgroupent
10358f0484fSRodney W. Grimesfunction
10458f0484fSRodney W. Grimesopens the file, or rewinds it if it is already open.  If
10558f0484fSRodney W. Grimes.Fa stayopen
10658f0484fSRodney W. Grimesis non-zero, file descriptors are left open, significantly speeding
10758f0484fSRodney W. Grimesfunctions subsequent calls.  This functionality is unnecessary for
10858f0484fSRodney W. Grimes.Fn getgrent
10958f0484fSRodney W. Grimesas it doesn't close its file descriptors by default.  It should also
11058f0484fSRodney W. Grimesbe noted that it is dangerous for long-running programs to use this
11158f0484fSRodney W. Grimesfunctionality as the group file may be updated.
11258f0484fSRodney W. Grimes.Pp
11358f0484fSRodney W. GrimesThe
11458f0484fSRodney W. Grimes.Fn setgrent
11558f0484fSRodney W. Grimesfunction
11658f0484fSRodney W. Grimesis identical to
11758f0484fSRodney W. Grimes.Fn setgroupent
11858f0484fSRodney W. Grimeswith an argument of zero.
11958f0484fSRodney W. Grimes.Pp
12058f0484fSRodney W. GrimesThe
12158f0484fSRodney W. Grimes.Fn endgrent
12258f0484fSRodney W. Grimesfunction
12358f0484fSRodney W. Grimescloses any open files.
12458f0484fSRodney W. Grimes.Sh RETURN VALUES
12558f0484fSRodney W. GrimesThe functions
12658f0484fSRodney W. Grimes.Fn getgrent ,
12758f0484fSRodney W. Grimes.Fn getgrnam ,
12858f0484fSRodney W. Grimesand
12958f0484fSRodney W. Grimes.Fn getgrgid ,
13058f0484fSRodney W. Grimesreturn a pointer to the group entry if successful; if end-of-file
13158f0484fSRodney W. Grimesis reached or an error occurs a null pointer is returned.
13258f0484fSRodney W. GrimesThe functions
13358f0484fSRodney W. Grimes.Fn setgroupent
13458f0484fSRodney W. Grimesand
13558f0484fSRodney W. Grimes.Fn setgrent
13658f0484fSRodney W. Grimesreturn the value 1 if successful, otherwise the value
13758f0484fSRodney W. Grimes0 is returned.
13858f0484fSRodney W. GrimesThe functions
13958f0484fSRodney W. Grimes.Fn endgrent
14058f0484fSRodney W. Grimesand
14158f0484fSRodney W. Grimes.Fn setgrfile
14258f0484fSRodney W. Grimeshave no return value.
14358f0484fSRodney W. Grimes.Sh FILES
14458f0484fSRodney W. Grimes.Bl -tag -width /etc/group -compact
14558f0484fSRodney W. Grimes.It Pa /etc/group
14658f0484fSRodney W. Grimesgroup database file
14758f0484fSRodney W. Grimes.El
14858f0484fSRodney W. Grimes.Sh SEE ALSO
14958f0484fSRodney W. Grimes.Fn getpwent 3 ,
15058f0484fSRodney W. Grimes.Fn group 5
15158f0484fSRodney W. Grimes.Sh HISTORY
15258f0484fSRodney W. GrimesThe functions
15358f0484fSRodney W. Grimes.Fn endgrent ,
15458f0484fSRodney W. Grimes.Fn getgrent ,
15558f0484fSRodney W. Grimes.Fn getgrnam ,
15658f0484fSRodney W. Grimes.Fn getgrgid ,
15758f0484fSRodney W. Grimesand
15858f0484fSRodney W. Grimes.Fn setgrent
15958f0484fSRodney W. Grimesappeared in
16058f0484fSRodney W. Grimes.At v7 .
16158f0484fSRodney W. GrimesThe functions
16258f0484fSRodney W. Grimes.Fn setgrfile
16358f0484fSRodney W. Grimesand
16458f0484fSRodney W. Grimes.Fn setgroupent
16558f0484fSRodney W. Grimesappeared in
16658f0484fSRodney W. Grimes.Bx 4.3 Reno .
16758f0484fSRodney W. Grimes.Sh COMPATIBILITY
16858f0484fSRodney W. GrimesThe historic function
16958f0484fSRodney W. Grimes.Fn setgrfile ,
17058f0484fSRodney W. Grimeswhich allowed the specification of alternate password databases, has
17158f0484fSRodney W. Grimesbeen deprecated and is no longer available.
17258f0484fSRodney W. Grimes.Sh BUGS
17358f0484fSRodney W. GrimesThe functions
17458f0484fSRodney W. Grimes.Fn getgrent ,
17558f0484fSRodney W. Grimes.Fn getgrnam ,
17658f0484fSRodney W. Grimes.Fn getgrgid ,
17758f0484fSRodney W. Grimes.Fn setgroupent
17858f0484fSRodney W. Grimesand
17958f0484fSRodney W. Grimes.Fn setgrent
18058f0484fSRodney W. Grimesleave their results in an internal static object and return
18158f0484fSRodney W. Grimesa pointer to that object. Subsequent calls to
18258f0484fSRodney W. Grimesthe same function
18358f0484fSRodney W. Grimeswill modify the same object.
18458f0484fSRodney W. Grimes.Pp
18558f0484fSRodney W. GrimesThe functions
18658f0484fSRodney W. Grimes.Fn getgrent ,
18758f0484fSRodney W. Grimes.Fn endgrent ,
18858f0484fSRodney W. Grimes.Fn setgroupent ,
18958f0484fSRodney W. Grimesand
19058f0484fSRodney W. Grimes.Fn setgrent
19158f0484fSRodney W. Grimesare fairly useless in a networked environment and should be
19258f0484fSRodney W. Grimesavoided, if possible.
193