1.\" $NetBSD: getgrent.3,v 1.17 2002/10/01 16:48:34 wiz 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. 92Identical group names or group gids may result in undefined behavior. 93.Pp 94The 95.Fn getgrent 96function sequentially reads the group database and is intended for programs 97that wish to step through the complete list of groups. 98.Pp 99All three functions will open the group file for reading, if necessary. 100.Pp 101The 102.Fn setgroupent 103function opens the file, or rewinds it if it is already open. 104If 105.Fa stayopen 106is non-zero, file descriptors are left open, significantly speeding 107functions subsequent calls. 108This functionality is unnecessary for 109.Fn getgrent 110as it doesn't close its file descriptors by default. 111It should also be noted that it is dangerous for long-running 112programs to use this functionality as the group file may be updated. 113.Pp 114The 115.Fn setgrent 116function is equivalent to 117.Fn setgroupent 118with an argument of zero. 119.Pp 120The 121.Fn endgrent 122function closes any open files. 123.Sh RETURN VALUES 124The functions 125.Fn getgrent , 126.Fn getgrnam , 127and 128.Fn getgrgid , 129return a pointer to the group entry if successful; if end-of-file 130is reached or an error occurs a null pointer is returned. 131The 132.Fn setgroupent 133function returns the value 1 if successful, otherwise the value 1340 is returned. 135The 136.Fn endgrent 137and 138.Fn setgrent 139functions have no return value. 140.Sh FILES 141.Bl -tag -width /etc/group -compact 142.It Pa /etc/group 143group database file 144.El 145.Sh SEE ALSO 146.Xr getpwent 3 , 147.Xr group 5 , 148.Xr nsswitch.conf 5 149.Sh STANDARDS 150The 151.Fn getgrnam 152and 153.Fn getgrgid 154functions conform to 155.St -p1003.1-90 . 156.Sh HISTORY 157The functions 158.Fn endgrent , 159.Fn getgrent , 160.Fn getgrnam , 161.Fn getgrgid , 162and 163.Fn setgrent 164appeared in 165.At v7 . 166The functions 167.Fn setgrfile 168and 169.Fn setgroupent 170appeared in 171.Bx 4.3 Reno . 172.Sh COMPATIBILITY 173The historic function 174.Fn setgrfile , 175which allowed the specification of alternative password databases, has 176been deprecated and is no longer available. 177.Sh BUGS 178The functions 179.Fn getgrent , 180.Fn getgrnam , 181.Fn getgrgid , 182.Fn setgroupent 183and 184.Fn setgrent 185leave their results in an internal static object and return 186a pointer to that object. 187Subsequent calls to the same function will modify the same object. 188.Pp 189The functions 190.Fn getgrent , 191.Fn endgrent , 192.Fn setgroupent , 193and 194.Fn setgrent 195are fairly useless in a networked environment and should be 196avoided, if possible. 197.Fn getgrent 198makes no attempt to suppress duplicate information if multiple 199sources are specified in 200.Xr nsswitch.conf 5 201