xref: /freebsd/lib/libc/gen/getgrent.3 (revision 24a0682c6465290759ed0b09ea16e40e7cd47053)
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.\"
3505f98035SJacques Vidrine.Dd April 16, 2003
3658f0484fSRodney W. Grimes.Dt GETGRENT 3
3758f0484fSRodney W. Grimes.Os
3858f0484fSRodney W. Grimes.Sh NAME
3958f0484fSRodney W. Grimes.Nm getgrent ,
4005f98035SJacques Vidrine.Nm getgrent_r ,
4158f0484fSRodney W. Grimes.Nm getgrnam ,
4205f98035SJacques Vidrine.Nm getgrnam_r ,
4358f0484fSRodney W. Grimes.Nm getgrgid ,
4405f98035SJacques Vidrine.Nm getgrgid_r ,
4558f0484fSRodney W. Grimes.Nm setgroupent ,
4658f0484fSRodney W. Grimes.Nm setgrent ,
4758f0484fSRodney W. Grimes.Nm endgrent
4858f0484fSRodney W. Grimes.Nd group database operations
4925bb73e0SAlexey Zelkin.Sh LIBRARY
5025bb73e0SAlexey Zelkin.Lb libc
5158f0484fSRodney W. Grimes.Sh SYNOPSIS
5232eef9aeSRuslan Ermilov.In grp.h
5358f0484fSRodney W. Grimes.Ft struct group *
5458f0484fSRodney W. Grimes.Fn getgrent void
5505f98035SJacques Vidrine.Ft int
5605f98035SJacques Vidrine.Fn getgrent_r "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result"
5758f0484fSRodney W. Grimes.Ft struct group *
5858f0484fSRodney W. Grimes.Fn getgrnam "const char *name"
5905f98035SJacques Vidrine.Ft int
6005f98035SJacques Vidrine.Fn getgrnam_r "const char *name" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result"
6158f0484fSRodney W. Grimes.Ft struct group *
6258f0484fSRodney W. Grimes.Fn getgrgid "gid_t gid"
63712dc76eSMike Pritchard.Ft int
6405f98035SJacques Vidrine.Fn getgrgid_r "gid_t gid" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result"
6505f98035SJacques Vidrine.Ft int
6658f0484fSRodney W. Grimes.Fn setgroupent "int stayopen"
6758f0484fSRodney W. Grimes.Ft int
6858f0484fSRodney W. Grimes.Fn setgrent void
6958f0484fSRodney W. Grimes.Ft void
7058f0484fSRodney W. Grimes.Fn endgrent void
7158f0484fSRodney W. Grimes.Sh DESCRIPTION
7258f0484fSRodney W. GrimesThese functions operate on the group database file
7358f0484fSRodney W. Grimes.Pa /etc/group
7458f0484fSRodney W. Grimeswhich is described
7558f0484fSRodney W. Grimesin
7658f0484fSRodney W. Grimes.Xr group 5 .
7758f0484fSRodney W. GrimesEach line of the database is defined by the structure
785c564baeSRuslan Ermilov.Vt group
7958f0484fSRodney W. Grimesfound in the include
8058f0484fSRodney W. Grimesfile
81fe08efe6SRuslan Ermilov.In grp.h :
8258f0484fSRodney W. Grimes.Bd -literal -offset indent
8358f0484fSRodney W. Grimesstruct group {
8458f0484fSRodney W. Grimes	char	*gr_name;	/* group name */
8558f0484fSRodney W. Grimes	char	*gr_passwd;	/* group password */
865567b258SMark Murray	gid_t	gr_gid;		/* group id */
871ffa6450SMike Pritchard	char	**gr_mem;	/* group members */
8858f0484fSRodney W. Grimes};
8958f0484fSRodney W. Grimes.Ed
9058f0484fSRodney W. Grimes.Pp
9158f0484fSRodney W. GrimesThe functions
9258f0484fSRodney W. Grimes.Fn getgrnam
9358f0484fSRodney W. Grimesand
9458f0484fSRodney W. Grimes.Fn getgrgid
9558f0484fSRodney W. Grimessearch the group database for the given group name pointed to by
965c564baeSRuslan Ermilov.Fa name
9758f0484fSRodney W. Grimesor the group id pointed to by
985c564baeSRuslan Ermilov.Fa gid ,
991a0a9345SRuslan Ermilovrespectively, returning the first one encountered.
1001a0a9345SRuslan ErmilovIdentical group
10158f0484fSRodney W. Grimesnames or group gids may result in undefined behavior.
10258f0484fSRodney W. Grimes.Pp
10358f0484fSRodney W. GrimesThe
10458f0484fSRodney W. Grimes.Fn getgrent
10558f0484fSRodney W. Grimesfunction
10658f0484fSRodney W. Grimessequentially reads the group database and is intended for programs
10758f0484fSRodney W. Grimesthat wish to step through the complete list of groups.
10858f0484fSRodney W. Grimes.Pp
10905f98035SJacques VidrineThe functions
11005f98035SJacques Vidrine.Fn getgrent_r ,
11105f98035SJacques Vidrine.Fn getgrnam_r ,
11205f98035SJacques Vidrineand
11305f98035SJacques Vidrine.Fn getgrgid_r
11405f98035SJacques Vidrineare thread-safe versions of
11505f98035SJacques Vidrine.Fn getgrent ,
11605f98035SJacques Vidrine.Fn getgrnam ,
11705f98035SJacques Vidrineand
11805f98035SJacques Vidrine.Fn getgrgid ,
11905f98035SJacques Vidrinerespectively.
12005f98035SJacques VidrineThe caller must provide storage for the results of the search in
12105f98035SJacques Vidrinethe
12205f98035SJacques Vidrine.Fa grp ,
12305f98035SJacques Vidrine.Fa buffer ,
12405f98035SJacques Vidrine.Fa bufsize ,
12505f98035SJacques Vidrineand
12605f98035SJacques Vidrine.Fa result
12705f98035SJacques Vidrinearguments.
12805f98035SJacques VidrineWhen these functions are successful, the
12905f98035SJacques Vidrine.Fa grp
13005f98035SJacques Vidrineargument will be filled-in, and a pointer to that argument will be
13105f98035SJacques Vidrinestored in
13205f98035SJacques Vidrine.Fa result .
13305f98035SJacques VidrineIf an entry is not found or an error occurs,
13405f98035SJacques Vidrine.Fa result
13505f98035SJacques Vidrinewill be set to
13605f98035SJacques Vidrine.Dv NULL .
13705f98035SJacques Vidrine.Pp
13805f98035SJacques VidrineThese functions will open the group file for reading, if necessary.
13958f0484fSRodney W. Grimes.Pp
14058f0484fSRodney W. GrimesThe
14158f0484fSRodney W. Grimes.Fn setgroupent
14258f0484fSRodney W. Grimesfunction
1431a0a9345SRuslan Ermilovopens the file, or rewinds it if it is already open.
1441a0a9345SRuslan ErmilovIf
14558f0484fSRodney W. Grimes.Fa stayopen
14658f0484fSRodney W. Grimesis non-zero, file descriptors are left open, significantly speeding
1471a0a9345SRuslan Ermilovfunctions subsequent calls.
1481a0a9345SRuslan ErmilovThis functionality is unnecessary for
14958f0484fSRodney W. Grimes.Fn getgrent
1501a0a9345SRuslan Ermilovas it doesn't close its file descriptors by default.
1511a0a9345SRuslan ErmilovIt should also
15258f0484fSRodney W. Grimesbe noted that it is dangerous for long-running programs to use this
15358f0484fSRodney W. Grimesfunctionality as the group file may be updated.
15458f0484fSRodney W. Grimes.Pp
15558f0484fSRodney W. GrimesThe
15658f0484fSRodney W. Grimes.Fn setgrent
15758f0484fSRodney W. Grimesfunction
15858f0484fSRodney W. Grimesis identical to
15958f0484fSRodney W. Grimes.Fn setgroupent
16058f0484fSRodney W. Grimeswith an argument of zero.
16158f0484fSRodney W. Grimes.Pp
16258f0484fSRodney W. GrimesThe
16358f0484fSRodney W. Grimes.Fn endgrent
16458f0484fSRodney W. Grimesfunction
16558f0484fSRodney W. Grimescloses any open files.
16658f0484fSRodney W. Grimes.Sh RETURN VALUES
16758f0484fSRodney W. GrimesThe functions
16858f0484fSRodney W. Grimes.Fn getgrent ,
16958f0484fSRodney W. Grimes.Fn getgrnam ,
17058f0484fSRodney W. Grimesand
17158f0484fSRodney W. Grimes.Fn getgrgid ,
17205f98035SJacques Vidrinereturn a pointer to a group structure on success or
17305f98035SJacques Vidrine.Dv NULL
17405f98035SJacques Vidrineif the entry is not found or if an error occurs.
1759b8f137bSTim KientzleIf an error does occur,
17605f98035SJacques Vidrine.Va errno
17705f98035SJacques Vidrinewill be set.
1789b8f137bSTim KientzleNote that programs must explicitly set
1799b8f137bSTim Kientzle.Va errno
1809b8f137bSTim Kientzleto zero before calling any of these functions if they need to
1819b8f137bSTim Kientzledistinguish between a non-existent entry and an error.
18205f98035SJacques VidrineThe functions
18305f98035SJacques Vidrine.Fn getgrent_r ,
18405f98035SJacques Vidrine.Fn getgrnam_r ,
18505f98035SJacques Vidrineand
18605f98035SJacques Vidrine.Fn getgrgid_r
18705f98035SJacques Vidrinereturn 0 if no error occurred, or an error number to indicate failure.
18805f98035SJacques VidrineIt is not an error if a matching entry is not found.
18905f98035SJacques Vidrine(Thus, if
19005f98035SJacques Vidrine.Fa result
19105f98035SJacques Vidrineis set to
19205f98035SJacques Vidrine.Dv NULL
19305f98035SJacques Vidrineand the return value is 0, no matching entry exists.)
19405f98035SJacques Vidrine.Pp
19558f0484fSRodney W. GrimesThe functions
19658f0484fSRodney W. Grimes.Fn setgroupent
19758f0484fSRodney W. Grimesand
19858f0484fSRodney W. Grimes.Fn setgrent
19958f0484fSRodney W. Grimesreturn the value 1 if successful, otherwise the value
20058f0484fSRodney W. Grimes0 is returned.
20158f0484fSRodney W. GrimesThe functions
20258f0484fSRodney W. Grimes.Fn endgrent
20358f0484fSRodney W. Grimesand
20458f0484fSRodney W. Grimes.Fn setgrfile
20558f0484fSRodney W. Grimeshave no return value.
20658f0484fSRodney W. Grimes.Sh FILES
20758f0484fSRodney W. Grimes.Bl -tag -width /etc/group -compact
20858f0484fSRodney W. Grimes.It Pa /etc/group
20958f0484fSRodney W. Grimesgroup database file
21058f0484fSRodney W. Grimes.El
21124a0682cSRuslan Ermilov.Sh COMPATIBILITY
21224a0682cSRuslan ErmilovThe historic function
21324a0682cSRuslan Ermilov.Fn setgrfile ,
21424a0682cSRuslan Ermilovwhich allowed the specification of alternate password databases, has
21524a0682cSRuslan Ermilovbeen deprecated and is no longer available.
21658f0484fSRodney W. Grimes.Sh SEE ALSO
21728f86af2SMike Pritchard.Xr getpwent 3 ,
218248aee62SJacques Vidrine.Xr group 5 ,
219491a8429SRuslan Ermilov.Xr nsswitch.conf 5 ,
220491a8429SRuslan Ermilov.Xr yp 8
22124a0682cSRuslan Ermilov.Sh STANDARDS
22224a0682cSRuslan ErmilovThe
22324a0682cSRuslan Ermilov.Fn getgrent ,
22424a0682cSRuslan Ermilov.Fn getgrnam ,
22524a0682cSRuslan Ermilov.Fn getgrnam_r ,
22624a0682cSRuslan Ermilov.Fn getgrgid ,
22724a0682cSRuslan Ermilov.Fn getgrgid_r
22824a0682cSRuslan Ermilovand
22924a0682cSRuslan Ermilov.Fn endgrent
23024a0682cSRuslan Ermilovfunctions conform to
23124a0682cSRuslan Ermilov.St -p1003.1-96 .
23224a0682cSRuslan ErmilovThe
23324a0682cSRuslan Ermilov.Fn setgrent
23424a0682cSRuslan Ermilovfunction differs from that standard in that its return type is
23524a0682cSRuslan Ermilov.Vt int
23624a0682cSRuslan Ermilovrather than
23724a0682cSRuslan Ermilov.Vt void .
23858f0484fSRodney W. Grimes.Sh HISTORY
23958f0484fSRodney W. GrimesThe functions
24058f0484fSRodney W. Grimes.Fn endgrent ,
24158f0484fSRodney W. Grimes.Fn getgrent ,
24258f0484fSRodney W. Grimes.Fn getgrnam ,
24358f0484fSRodney W. Grimes.Fn getgrgid ,
24458f0484fSRodney W. Grimesand
24558f0484fSRodney W. Grimes.Fn setgrent
24658f0484fSRodney W. Grimesappeared in
24758f0484fSRodney W. Grimes.At v7 .
24858f0484fSRodney W. GrimesThe functions
24958f0484fSRodney W. Grimes.Fn setgrfile
25058f0484fSRodney W. Grimesand
25158f0484fSRodney W. Grimes.Fn setgroupent
25258f0484fSRodney W. Grimesappeared in
25358f0484fSRodney W. Grimes.Bx 4.3 Reno .
25405f98035SJacques VidrineThe functions
25505f98035SJacques Vidrine.Fn getgrent_r ,
25605f98035SJacques Vidrine.Fn getgrnam_r ,
25705f98035SJacques Vidrineand
25805f98035SJacques Vidrine.Fn getgrgid_r
25905f98035SJacques Vidrineappeared in
26005f98035SJacques Vidrine.Fx 5.1 .
26158f0484fSRodney W. Grimes.Sh BUGS
26258f0484fSRodney W. GrimesThe functions
26358f0484fSRodney W. Grimes.Fn getgrent ,
26458f0484fSRodney W. Grimes.Fn getgrnam ,
26558f0484fSRodney W. Grimes.Fn getgrgid ,
26658f0484fSRodney W. Grimes.Fn setgroupent
26758f0484fSRodney W. Grimesand
26858f0484fSRodney W. Grimes.Fn setgrent
26958f0484fSRodney W. Grimesleave their results in an internal static object and return
270c6ff3a1bSSheldon Hearna pointer to that object.
271c6ff3a1bSSheldon HearnSubsequent calls to
27258f0484fSRodney W. Grimesthe same function
27358f0484fSRodney W. Grimeswill modify the same object.
274248aee62SJacques Vidrine.Pp
275248aee62SJacques VidrineThe functions
276248aee62SJacques Vidrine.Fn getgrent ,
27705f98035SJacques Vidrine.Fn getgrent_r ,
278248aee62SJacques Vidrine.Fn endgrent ,
279248aee62SJacques Vidrine.Fn setgroupent ,
280248aee62SJacques Vidrineand
281248aee62SJacques Vidrine.Fn setgrent
282248aee62SJacques Vidrineare fairly useless in a networked environment and should be
283248aee62SJacques Vidrineavoided, if possible.
28495f4226bSRuslan ErmilovThe
285248aee62SJacques Vidrine.Fn getgrent
28605f98035SJacques Vidrineand
28705f98035SJacques Vidrine.Fn getgrent_r
28805f98035SJacques Vidrinefunctions
28905f98035SJacques Vidrinemake no attempt to suppress duplicate information if multiple
290248aee62SJacques Vidrinesources are specified in
291248aee62SJacques Vidrine.Xr nsswitch.conf 5 .
292