#include <pwd.h> struct passwd *getpwuid(uid) int uid; struct passwd *getpwnam(name) char *name; struct passwd *getpwent() setpwent() endpwent() setpwfile(name) char *name;
struct passwd { /* see getpwent(3) */ char *pw_name; char *pw_passwd; int pw_uid; int pw_gid; int pw_quota; char *pw_comment; char *pw_gecos; char *pw_dir; char *pw_shell; };
The fields pw_quota and pw_comment are unused; the others have meanings described in passwd(5).
If the flat file is searched, then searching of the password file may be done using the ndbm database access routines.
Setpwent opens the database; endpwent closes it. Getpwuid and getpwnam search the database (opening it if necessary) for a matching uid or name. EOF is returned if there is no entry.
For programs wishing to read the entire database, getpwent reads the next line (opening the database if necessary). In addition to opening the database, setpwent can be used to make getpwent begin its search from the beginning of the database.
Setpwfile changes the default password file to name thus allowing alternate password files to be used. Note that it does not close the previous file. If this is desired, endpwent should be called prior to it.