161111Sbostic.\" Copyright (c) 1989, 1991, 1993 261111Sbostic.\" The Regents of the University of California. All rights reserved. 320331Smckusick.\" 443571Strent.\" %sccs.include.redist.man% 535521Sbostic.\" 6*66944Sbostic.\" @(#)getgrent.3 8.2 (Berkeley) 04/19/94 737082Sbostic.\" 848352Scael.Dd 948352Scael.Dt GETGRENT 3 1048352Scael.Os 1148352Scael.Sh NAME 1248352Scael.Nm getgrent , 1348352Scael.Nm getgrnam , 1448352Scael.Nm getgrgid , 1548352Scael.Nm setgroupent , 1648376Scael.\" .Nm setgrfile , 1748352Scael.Nm setgrent , 1848352Scael.Nm endgrent 1948352Scael.Nd group database operations 2048352Scael.Sh SYNOPSIS 2148352Scael.Fd #include <grp.h> 2248352Scael.Ft struct group * 2348352Scael.Fn getgrent void 2448352Scael.Ft struct group * 2559086Sbostic.Fn getgrnam "const char *name" 2648352Scael.Ft struct group * 2748352Scael.Fn getgrgid "gid_t gid" 2848352Scael.Ft struct group * 2948352Scael.Fn setgroupent "int stayopen" 3048376Scael.\" .Ft void 3148376Scael.\" .Fn setgrfile "const char *name" 3248352Scael.Ft int 3348352Scael.Fn setgrent void 3448352Scael.Ft void 3548352Scael.Fn endgrent void 3648352Scael.Sh DESCRIPTION 3748352ScaelThese functions operate on the group database file 3848352Scael.Pa /etc/group 3948352Scaelwhich is described 4048352Scaelin 4148352Scael.Xr group 5 . 4248352ScaelEach line of the database is defined by the structure 4348352Scael.Ar group 4448352Scaelfound in the include 4537082Sbosticfile 4648352Scael.Aq Pa grp.h : 4748352Scael.Bd -literal -offset indent 4837082Sbosticstruct group { 4948352Scael char *gr_name; /* group name */ 5048352Scael char *gr_passwd; /* group password */ 5137082Sbostic gid_t gr_gid; /* group id */ 5248352Scael char **gr_mem; /* group members */ 5335521Sbostic}; 5448352Scael.Ed 5548352Scael.Pp 5648352ScaelThe functions 5748352Scael.Fn getgrnam 5837082Sbosticand 5948352Scael.Fn getgrgid 6048352Scaelsearch the group database for the given group name pointed to by 6148352Scael.Ar name 6248352Scaelor the group id pointed to by 6348352Scael.Ar gid , 6437082Sbosticrespectively, returning the first one encountered. Identical group 6537082Sbosticnames or group gids may result in undefined behavior. 6648352Scael.Pp 6748352ScaelThe 6848352Scael.Fn getgrent 6948352Scaelfunction 7037082Sbosticsequentially reads the group database and is intended for programs 7137082Sbosticthat wish to step through the complete list of groups. 7248352Scael.Pp 73*66944SbosticAll three routines will open the group file for reading, if necessary. 7448352Scael.Pp 7548352ScaelThe 7648352Scael.Fn setgroupent 7748352Scaelfunction 7837082Sbosticopens the file, or rewinds it if it is already open. If 7948352Scael.Fa stayopen 8037082Sbosticis non-zero, file descriptors are left open, significantly speeding 8148352Scaelfunctions subsequent calls. This functionality is unnecessary for 8248352Scael.Fn getgrent 8337082Sbosticas it doesn't close its file descriptors by default. It should also 8437082Sbosticbe noted that it is dangerous for long-running programs to use this 8537082Sbosticfunctionality as the group file may be updated. 8648352Scael.Pp 8748352ScaelThe 8848352Scael.Fn setgrent 8948352Scaelfunction 9037082Sbosticis identical to 9148352Scael.Fn setgroupent 9237082Sbosticwith an argument of zero. 9348352Scael.Pp 9448352ScaelThe 9548352Scael.Fn endgrent 9648352Scaelfunction 9735521Sbosticcloses any open files. 9848352Scael.Sh RETURN VALUES 9948352ScaelThe functions 10048352Scael.Fn getgrent , 10148352Scael.Fn getgrnam , 10235521Sbosticand 10348352Scael.Fn getgrgid , 10448352Scaelreturn a pointer to the group entry if successful; if end-of-file 10548352Scaelis reached or an error occurs a null pointer is returned. 10648352ScaelThe functions 10748352Scael.Fn setgroupent 10837082Sbosticand 10948352Scael.Fn setgrent 11048352Scaelreturn the value 1 if successful, otherwise the value 11148352Scael0 is returned. 11248352ScaelThe functions 11348352Scael.Fn endgrent 11437082Sbosticand 11548352Scael.Fn setgrfile 11648352Scaelhave no return value. 11748352Scael.Sh FILES 11848352Scael.Bl -tag -width /etc/group -compact 11948352Scael.It Pa /etc/group 12048352Scaelgroup database file 12148352Scael.El 12248352Scael.Sh SEE ALSO 12348352Scael.Fn getpwent 3 , 12448352Scael.Fn group 5 12548352Scael.Sh HISTORY 12648352ScaelThe functions 12748352Scael.Fn endgrent , 12848352Scael.Fn getgrent , 12948352Scael.Fn getgrnam , 13048352Scael.Fn getgrgid , 13148352Scaeland 13248352Scael.Fn setgrent 13348352Scaelappeared in 13448352Scael.At v7 . 13548352ScaelThe functions 13648352Scael.Fn setgrfile 13748352Scaeland 13848352Scael.Fn setgroupent 13948352Scaelappeared in 14048352Scael.Bx 4.3 Reno . 14148376Scael.Sh COMPATIBILITY 14248376ScaelThe historic function 14348376Scael.Fn setgrfile , 14448376Scaelwhich allowed the specification of alternate password databases, has 14548376Scaelbeen deprecated and is no longer available. 14648352Scael.Sh BUGS 14748352ScaelThe functions 14848352Scael.Fn getgrent , 14948352Scael.Fn getgrnam , 15048352Scael.Fn getgrgid , 15148352Scael.Fn setgroupent 15248352Scaeland 15348352Scael.Fn setgrent 15448352Scaelleave their results in an internal static object and return 15548352Scaela pointer to that object. Subsequent calls to 15648352Scaelthe same function 15748352Scaelwill modify the same object. 15848352Scael.Pp 15948352ScaelThe functions 16048352Scael.Fn getgrent , 16148352Scael.Fn endgrent , 16248352Scael.Fn setgroupent , 16348352Scaeland 16448352Scael.Fn setgrent 16537082Sbosticare fairly useless in a networked environment and should be 16637082Sbosticavoided, if possible. 167