1*48352Scael.\" Copyright (c) 1988, 1991 The Regents of the University of California. 236875Sbostic.\" All rights reserved. 320340Smckusick.\" 443571Strent.\" %sccs.include.redist.man% 535521Sbostic.\" 6*48352Scael.\" @(#)getpwent.3 6.8 (Berkeley) 04/19/91 736875Sbostic.\" 8*48352Scael.Dd 9*48352Scael.Dt GETPWENT 3 10*48352Scael.Os 11*48352Scael.Sh NAME 12*48352Scael.Nm getpwent , 13*48352Scael.Nm getpwnam , 14*48352Scael.Nm getpwuid , 15*48352Scael.Nm setpassent , 16*48352Scael.Nm setpwent , 17*48352Scael.Nm endpwent 18*48352Scael.Nd password database operations 19*48352Scael.Sh SYNOPSIS 20*48352Scael.Fd #include <sys/types.h> 21*48352Scael.Fd #include <pwd.h> 22*48352Scael.Ft struct passwd * 23*48352Scael.Fn getpwent void 24*48352Scael.Ft struct passwd * 25*48352Scael.Fn getpwnam "const char *login" 26*48352Scael.Ft struct passwd * 27*48352Scael.Fn getpwuid "uid_t uid" 28*48352Scael.Ft int 29*48352Scael.Fn setpassent "int stayopen" 30*48352Scael.Ft int 31*48352Scael.Fn setpwent void 32*48352Scael.Ft void 33*48352Scael.Fn endpwent void 34*48352Scael.Sh DESCRIPTION 35*48352ScaelThese functions 36*48352Scaeloperate on the password database file 37*48352Scaelwhich is described 38*48352Scaelin 39*48352Scael.Xr passwd 5 . 40*48352ScaelEach entry in the database is defined by the structure 41*48352Scael.Ar passwd 42*48352Scaelfound in the include 43*48352Scaelfile 44*48352Scael.Aq Pa pwd.h : 45*48352Scael.Bd -literal -offset indent 4635521Sbosticstruct passwd { 47*48352Scael char *pw_name; /* user name */ 48*48352Scael char *pw_passwd; /* encrypted password */ 4936875Sbostic uid_t pw_uid; /* user uid */ 5036875Sbostic gid_t pw_gid; /* user gid */ 5136875Sbostic time_t pw_change; /* password change time */ 52*48352Scael char *pw_class; /* user access class */ 53*48352Scael char *pw_gecos; /* Honeywell login info */ 54*48352Scael char *pw_dir; /* home directory */ 55*48352Scael char *pw_shell; /* default shell */ 5636875Sbostic time_t pw_expire; /* account expiration */ 5735521Sbostic}; 58*48352Scael.Ed 59*48352Scael.Pp 60*48352ScaelThe functions 61*48352Scael.Fn getpwnam 6236875Sbosticand 63*48352Scael.Fn getpwuid 64*48352Scaelsearch the password database for the given login name or user uid, 6546375Sbosticrespectively, always returning the first one encountered. 66*48352Scael.Pp 67*48352ScaelThe 68*48352Scael.Fn getpwent 69*48352Scaelfunction 7036875Sbosticsequentially reads the password database and is intended for programs 7146375Sbosticthat wish to process the complete list of users. 72*48352Scael.Pp 73*48352ScaelThe 74*48352Scael.Fn setpassent 75*48352Scaelfunction 7646375Sbosticaccomplishes two purposes. 7746375SbosticFirst, it causes 78*48352Scael.Fn getpwent 7946375Sbosticto ``rewind'' to the beginning of the database. 8046375SbosticAdditionally, if 81*48352Scael.Fa stayopen 8236875Sbosticis non-zero, file descriptors are left open, significantly speeding 8346375Sbosticup subsequent accesses for all of the routines. 8446375Sbostic(This latter functionality is unnecessary for 85*48352Scael.Fn getpwent 8646375Sbosticas it doesn't close its file descriptors by default.) 87*48352Scael.Pp 8846375SbosticIt is dangerous for long-running programs to keep the file descriptors 8946375Sbosticopen the database will become out of date if it is updated while the 9046375Sbosticprogram is running. 91*48352Scael.Pp 92*48352ScaelThe 93*48352Scael.Fn setpwent 94*48352Scaelfunction 9536875Sbosticis identical to 96*48352Scael.Fn setpassent 9736875Sbosticwith an argument of zero. 98*48352Scael.Pp 99*48352ScaelThe 100*48352Scael.Fn endpwent 101*48352Scaelfunction 10236875Sbosticcloses any open files. 103*48352Scael.Pp 10436875SbosticThese routines have been written to ``shadow'' the password file, e.g. 10536875Sbosticallow only certain programs to have access to the encrypted password. 10646375SbosticIf the process which calls them has an effective uid of 0, the encrypted 10746375Sbosticpassword will be returned, otherwise, the password field of the retuned 108*48352Scaelstructure will point to the string 109*48352Scael.Ql * . 110*48352Scael.Sh RETURN VALUES 111*48352ScaelThe functions 112*48352Scael.Fn getpwent , 113*48352Scael.Fn getpwnam , 11436875Sbosticand 115*48352Scael.Fn getpwuid , 116*48352Scaelreturn a valid pointer to a passwd structure on success 117*48352Scaeland a null pointer if end-of-file is reached or an error occurs. 118*48352ScaelThe functions 119*48352Scael.Fn setpassent 12025346Smckusickand 121*48352Scael.Fn setpwent 12236875Sbosticreturn 0 on failure and 1 on success. 123*48352ScaelThe 124*48352Scael.Fn endpwent 125*48352Scaelfunction 12646375Sbostichas no return value. 127*48352Scael.Sh FILES 128*48352Scael.Bl -tag -width /etc/master.passwd -compact 129*48352Scael.It Pa /var/db/pwd.db 130*48352ScaelThe insecure password database file 131*48352Scael.It Pa /var/db/spwd.db 132*48352ScaelThe secure password database file 133*48352Scael.It Pa /etc/master.passwd 134*48352ScaelThe current password file 135*48352Scael.It Pa /etc/passwd 136*48352ScaelA Version 7 format password file 137*48352Scael.El 138*48352Scael.Sh SEE ALSO 139*48352Scael.Xr getlogin 3 , 140*48352Scael.Xr getgrent 3 , 141*48352Scael.Xr passwd 5 , 142*48352Scael.Xr pwd_mkdb 8 , 143*48352Scael.Xr vipw 8 144*48352Scael.Sh HISTORY 145*48352ScaelThe 146*48352Scael.Nm getpwent , 147*48352Scael.Nm getpwnam , 148*48352Scael.Nm getpwuid , 149*48352Scael.Nm setpwent, 150*48352Scaeland 151*48352Scael.Nm endpwent 152*48352Scaelfunctions appeared in 153*48352Scael.At v7 . 154*48352ScaelThe 155*48352Scael.Nm setpassent 156*48352Scaelfunction appeared in 157*48352Scael.Bx 4.3 Reno . 158*48352Scael.Sh BUGS 159*48352ScaelThe functions 160*48352Scael.Fn getpwent , 161*48352Scael.Fn getpwnam , 162*48352Scaeland 163*48352Scael.Fn getpwuid , 164*48352Scaelleave their results in an internal static object and return 165*48352Scaela pointer to that object. Subsequent calls to 166*48352Scaelthe same function 167*48352Scaelwill modify the same object. 168*48352Scael.Pp 16936875SbosticThe routines 170*48352Scael.Fn getpwent , 171*48352Scael.Fn endpwent , 172*48352Scael.Fn setpassent , 17336875Sbosticand 174*48352Scael.Fn setpwent 17536875Sbosticare fairly useless in a networked environment and should be 17636875Sbosticavoided, if possible. 177*48352Scael.Sh COMPATIBILITY 17846375SbosticThe historic function 179*48352Scael.Xr setpwfile 3 , 18046375Sbosticwhich allowed the specification of alternate password databases, 18146375Sbostichas been deprecated and is no longer available. 182