Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

endpwent, getpwent, setpwent - manage user catalog

&pagelevel(4)&pagelevel

Syntax

#include <pwd.h>

void endpwent (void);

struct passwd *getpwent (void);

void setpwent (void); 

Description

getpwent() returns a pointer to an object with the structure shown below, which contains

the individual fields of a line of the /etc/passwd file. Each line contains an object of the
passwd structure, which is declared in the header file pwd.h, with the following elements:

struct passwd {
      char    *pw_name;
      char    *pw_passwd;
      uid_t    pw_uid;
      gid_t    pw_gid;
      char    *pw_age;
      char    *pw_comment;
      char    *pw_gecos;
      char    *pw_dir;
      char    *pw_shell; 
};

The components of this structure are read serially from the user catalog.
getpwent() returns a pointer to the first password structure in the user catalog the first
time it is called; after this it returns a pointer to the next password structure in the file. In this
way, consecutive calls can be used to search through the entire user catalog.

setpwent() deletes the pointer with which the user catalog is to be serially searched by
means of getpwent(). A subsequent getpwent call returns a pointer to the first password
structure.

endpwent() can be called at the end of processing in order to close the user catalog.

endpwent(), getpwent() and setpwent() are not thread-safe.

Return val.

getpwent():

Pointer to the structure of type passwd



if successful.

Errors

endpwent() will fail if:

EACCES         the user ID (uid) of the caller is invalid.

getpwent(), setpwent() and endpwent() will fail if:

 

EFAULT

ENOENT

errors occur during creation of the passwd structure.

the user does not exists.

Notes

The return value of getpwent() can point to an area that will be overwritten by a subsequent
call of getpwuid(), getpwnam() or getpwent().

There is no /etc/passwd password file in the POSIX subsystem. The user data is stored
internally in the user catalog (see manual "POSIX Basics" [1 (Related publications)]).

These functions are only supported for reasons of compatibility.

The characteristics of a current process can be defined as follows:

  • getpwuid(geteuid()) returns the name of the effective user ID of the process

  • getlogin() returns the login name of the process

  • getpwuid(getuid()) returns the name of the real user ID of the process.

If error situations are to be investigated, errno must be set to 0 before getpwent() is
called. 

See also

endgrent(), getlogin(), getpwnam(), getpwuid(), putpwent(), pwd.h,
manual "POSIX Basics" [1 (Related publications)].