GETPWENT(3V) — UNKNOWN SECTION OF THE MANUAL
NAME
getpwent, getpwuid, getpwnam, setpwent, endpwent, fgetpwent − get password file entry
SYNOPSIS
#include <pwd.h>
struct passwd ∗getpwent()
struct passwd ∗getpwuid(uid)
int uid;
struct passwd ∗getpwnam(name)
char ∗name;
int setpwent()
int endpwent()
struct passwd ∗fgetpwent(f)
FILE ∗f;
DESCRIPTION
getpwent, getpwuid and getpwnam each return a pointer to an object with the following structure containing the broken-out fields of a line in the password file. Each line in the file contains a “passwd” structure, declared in the <pwd.h> header file:
structpasswd { /∗ see getpwent(3) ∗/
char∗pw_name;
char∗pw_passwd;
intpw_uid;
intpw_gid;
char∗pw_age;
char∗pw_comment;
char∗pw_gecos;
char∗pw_dir;
char∗pw_shell;
};
struct passwd ∗getpwent(), ∗getpwuid(), ∗getpwnam();
This structure is declared in <pwd.h> so it is not necessary to redeclare it.
The field pw_comment is unused; the others have meanings described in passwd(5). When first called, getpwent returns a pointer to the first passwd structure in the file; thereafter, it returns a pointer to the next passwd structure in the file; so successive calls can be used to search the entire file. Getpwuid searches from the beginning of the file until a numerical user id matching uid is found and returns a pointer to the particular structure in which it was found. Getpwnam searches from the beginning of the file until a login name matching name is found, and returns a pointer to the particular structure in which it was found. If an end-of-file or an error is encountered on reading, these functions return a NULL pointer.
A call to setpwent has the effect of rewinding the password file to allow repeated searches. endpwent may be called to close the password file when processing is complete.
fgetpwent returns a pointer to the next passwd structure in the stream f, which matches the format of the password file /etc/passwd.
The field, pw_age, is used to hold a value for “password aging” on some systems; “password aging” is not supported on Sun systems. As such, it is effectively not used.
FILES
/etc/passwd
/etc/yp/domainname/passwd.byname
/etc/yp/domainname/passwd.byuid
SEE ALSO
getlogin(3), getgrent(3), passwd(5), ypserv(8), getpwent(3)
DIAGNOSTICS
A NULL pointer is returned on EOF or error.
WARNING
The above routines use <stdio.h>, which causes them to increase the size of programs, not otherwise using standard I/O, more than might be expected.
BUGS
All information is contained in a static area, so it must be copied if it is to be saved.
Sun Release 3.2 — Last change: 15 April 1986