xref: /csrg-svn/lib/libc/gen/getpwent.3 (revision 65099)
161111Sbostic.\" Copyright (c) 1988, 1991, 1993
261111Sbostic.\"	The Regents of the University of California.  All rights reserved.
320340Smckusick.\"
443571Strent.\" %sccs.include.redist.man%
535521Sbostic.\"
6*65099Smckusick.\"     @(#)getpwent.3	8.2 (Berkeley) 12/11/93
736875Sbostic.\"
848352Scael.Dd
948352Scael.Dt GETPWENT 3
1048352Scael.Os
1148352Scael.Sh NAME
1248352Scael.Nm getpwent ,
1348352Scael.Nm getpwnam ,
1448352Scael.Nm getpwuid ,
1548352Scael.Nm setpassent ,
1648352Scael.Nm setpwent ,
1748352Scael.Nm endpwent
1848352Scael.Nd password database operations
1948352Scael.Sh SYNOPSIS
2048352Scael.Fd #include <sys/types.h>
2148352Scael.Fd #include <pwd.h>
2248352Scael.Ft struct passwd *
2348352Scael.Fn getpwent void
2448352Scael.Ft struct passwd *
2548352Scael.Fn getpwnam "const char *login"
2648352Scael.Ft struct passwd *
2748352Scael.Fn getpwuid "uid_t uid"
2848352Scael.Ft int
2948352Scael.Fn setpassent "int  stayopen"
3048352Scael.Ft int
3148352Scael.Fn setpwent void
3248352Scael.Ft void
3348352Scael.Fn endpwent void
3448352Scael.Sh DESCRIPTION
3548352ScaelThese functions
3648352Scaeloperate on the password database file
3748352Scaelwhich is described
3848352Scaelin
3948352Scael.Xr passwd 5 .
4048352ScaelEach entry in the database is defined by the structure
4148352Scael.Ar passwd
4248352Scaelfound in the include
4348352Scaelfile
4448352Scael.Aq Pa pwd.h :
4548352Scael.Bd -literal -offset indent
4635521Sbosticstruct passwd {
4748352Scael	char	*pw_name;	/* user name */
4848352Scael	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 */
5248352Scael	char	*pw_class;	/* user access class */
5348352Scael	char	*pw_gecos;	/* Honeywell login info */
5448352Scael	char	*pw_dir;	/* home directory */
5548352Scael	char	*pw_shell;	/* default shell */
5636875Sbostic	time_t	pw_expire;	/* account expiration */
5735521Sbostic};
5848352Scael.Ed
5948352Scael.Pp
6048352ScaelThe functions
6148352Scael.Fn getpwnam
6236875Sbosticand
6348352Scael.Fn getpwuid
6448352Scaelsearch the password database for the given login name or user uid,
6546375Sbosticrespectively, always returning the first one encountered.
6648352Scael.Pp
6748352ScaelThe
6848352Scael.Fn getpwent
6948352Scaelfunction
7036875Sbosticsequentially reads the password database and is intended for programs
7146375Sbosticthat wish to process the complete list of users.
7248352Scael.Pp
7348352ScaelThe
7448352Scael.Fn setpassent
7548352Scaelfunction
7646375Sbosticaccomplishes two purposes.
7746375SbosticFirst, it causes
7848352Scael.Fn getpwent
7946375Sbosticto ``rewind'' to the beginning of the database.
8046375SbosticAdditionally, if
8148352Scael.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
8548352Scael.Fn getpwent
8646375Sbosticas it doesn't close its file descriptors by default.)
8748352Scael.Pp
8846375SbosticIt is dangerous for long-running programs to keep the file descriptors
89*65099Smckusickopen as the database will become out of date if it is updated while the
9046375Sbosticprogram is running.
9148352Scael.Pp
9248352ScaelThe
9348352Scael.Fn setpwent
9448352Scaelfunction
9536875Sbosticis identical to
9648352Scael.Fn setpassent
9736875Sbosticwith an argument of zero.
9848352Scael.Pp
9948352ScaelThe
10048352Scael.Fn endpwent
10148352Scaelfunction
10236875Sbosticcloses any open files.
10348352Scael.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
107*65099Smckusickpassword will be returned, otherwise, the password field of the returned
10848352Scaelstructure will point to the string
10948352Scael.Ql * .
11048352Scael.Sh RETURN VALUES
11148352ScaelThe functions
11248352Scael.Fn getpwent ,
11348352Scael.Fn getpwnam ,
11436875Sbosticand
11548352Scael.Fn getpwuid ,
11648352Scaelreturn a valid pointer to a passwd structure on success
11748352Scaeland a null pointer if end-of-file is reached or an error occurs.
11848352ScaelThe functions
11948352Scael.Fn setpassent
12025346Smckusickand
12148352Scael.Fn setpwent
12236875Sbosticreturn 0 on failure and 1 on success.
12348352ScaelThe
12448352Scael.Fn endpwent
12548352Scaelfunction
12646375Sbostichas no return value.
12748352Scael.Sh FILES
12848352Scael.Bl -tag -width /etc/master.passwd -compact
12948352Scael.It Pa /var/db/pwd.db
13048352ScaelThe insecure password database file
13148352Scael.It Pa /var/db/spwd.db
13248352ScaelThe secure password database file
13348352Scael.It Pa /etc/master.passwd
13448352ScaelThe current password file
13548352Scael.It Pa /etc/passwd
13648352ScaelA Version 7 format password file
13748352Scael.El
13848352Scael.Sh SEE ALSO
13948352Scael.Xr getlogin 3 ,
14048352Scael.Xr getgrent 3 ,
14148352Scael.Xr passwd 5 ,
14248352Scael.Xr pwd_mkdb 8 ,
14348352Scael.Xr vipw 8
14448352Scael.Sh HISTORY
14548352ScaelThe
14648352Scael.Nm getpwent ,
14748352Scael.Nm getpwnam ,
14848352Scael.Nm getpwuid ,
14948352Scael.Nm setpwent,
15048352Scaeland
15148352Scael.Nm endpwent
15248352Scaelfunctions appeared in
15348352Scael.At v7 .
15448352ScaelThe
15548352Scael.Nm setpassent
15648352Scaelfunction appeared in
15748352Scael.Bx 4.3 Reno .
15848352Scael.Sh BUGS
15948352ScaelThe functions
16048352Scael.Fn getpwent ,
16148352Scael.Fn getpwnam ,
16248352Scaeland
16348352Scael.Fn getpwuid ,
16448352Scaelleave their results in an internal static object and return
16548352Scaela pointer to that object. Subsequent calls to
16648352Scaelthe same function
16748352Scaelwill modify the same object.
16848352Scael.Pp
16936875SbosticThe routines
17048352Scael.Fn getpwent ,
17148352Scael.Fn endpwent ,
17248352Scael.Fn setpassent ,
17336875Sbosticand
17448352Scael.Fn setpwent
17536875Sbosticare fairly useless in a networked environment and should be
17636875Sbosticavoided, if possible.
17748352Scael.Sh COMPATIBILITY
17846375SbosticThe historic function
17948352Scael.Xr setpwfile 3 ,
18046375Sbosticwhich allowed the specification of alternate password databases,
18146375Sbostichas been deprecated and is no longer available.
182