HP-UX Reference (11i v1 05/09) - 3 Library Functions A-M (vol 6)

g
getpwent(3C) getpwent(3C)
NAME
getpwent(), getpwuid(), getpwuid_r(), getpwnam( ), getpwnam_r(), setpwent(), endpwent(), fgetpwent(), -
get password file entry
SYNOPSIS
#include <pwd.h>
struct passwd *getpwent(void);
struct passwd *getpwuid(uid_t uid);
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
size_t buflen, struct passwd **result);
struct passwd *getpwnam(const char *name);
int getpwnam_r(char *name, struct passwd *pwd, char *buffer,
size_t buflen, struct passwd **result);
void setpwent(void);
void endpwent(void);
struct passwd *fgetpwent(FILE *stream);
Obsolescent Interfaces
#include <pwd.h>
int getpwent_r(struct passwd *result, char *buffer, int buflen,
FILE **pwfp);
void setpwent_r(FILE **pwfp);
void endpwent_r(FILE **pwfp);
int fgetpwent_r(FILE *f, struct passwd *result, char *buffer,
int buflen);
DESCRIPTION
getpwent() , getpwuid() , and getpwnam() are used to obtain password entries, and return a
pointer to an object of passwd structure. An entry may come from any of the sources for
passwd
specified in the /etc/nsswitch.conf
file. See nsswitch.conf(4).
The
passwd structure is defined in <pwd.h> and includes the following members:
char *pw_name; /* user name */
char *pw_passwd; /* encrypted password */
uid_t pw_uid; /* user id */
gid_t pw_gid; /* group id */
char *pw_age; /* password aging */
char *pw_comment; /* unused */
char *pw_gecos; /* user fullname, office, extension, homephone*/
char *pw_dir; /* initial directory */
char *pw_shell; /* initial shell */
aid_t pw_audid; /* numerical audit id */
int pw_audflg; /* numerical audit flag */
The pw_comment field is unused; for more information on the other fields, refer to passwd(4).
getpwent() When first called, getpwent() returns a pointer to the first passwd structure in the
password database. Thereafter, it returns a pointer to the next passwd structure in
the database;
setpwent() Has the effect of rewinding the password database to allow repeated searches;
endpwent() Can be called to indicate that password database processing is complete;
getpwuid() Searches from the beginning of the password database until a numeric user ID match-
ing uid is found, and returns a pointer to the particular structure in which it was
found;
Section 3370 Hewlett-Packard Company 1 HP-UX 11i Version 1: September 2005