This manual page is for Mac OS X version 10.6.3

If you are running a different version of Mac OS X, view the documentation locally:

  • In Terminal, using the man(1) command

Reading manual pages

Manual pages are intended as a quick reference for people who already understand a technology.

  • For more information about the manual page format, see the manual page for manpages(5).

  • For more information about this technology, look for other documentation in the Apple Reference Library.

  • For general information about writing shell scripts, read Shell Scripting Primer.



GETPWENT(3)                             BSD Library Functions Manual                             GETPWENT(3)

NAME
     getpwent, getpwnam, getpwnam_r, getpwuid, getpwuid_r, setpassent, setpwent, endpwent -- password data-base database
     base operations

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <sys/types.h>
     #include <pwd.h>

     struct passwd *
     getpwent(void);

     struct passwd *
     getpwnam(const char *login);

     int
     getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result);

     struct passwd *
     getpwuid(uid_t uid);

     int
     getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result);

     int
     setpassent(int stayopen);

     void
     setpwent(void);

     void
     endpwent(void);

DESCRIPTION
     These functions obtain information from DirectoryService(8), including records in /etc/passwd which is
     described in passwd(5).  Each entry in the database is defined by the structure passwd found in the
     include file <pwd.h>:

           struct passwd {
                   char    *pw_name;       /* user name */
                   char    *pw_passwd;     /* encrypted password */
                   uid_t   pw_uid;         /* user uid */
                   gid_t   pw_gid;         /* user gid */
                   time_t  pw_change;      /* password change time */
                   char    *pw_class;      /* user access class */
                   char    *pw_gecos;      /* Honeywell login info */
                   char    *pw_dir;        /* home directory */
                   char    *pw_shell;      /* default shell */
                   time_t  pw_expire;      /* account expiration */
                   int     pw_fields;      /* internal: fields filled in */
           };

     The functions getpwnam() and getpwuid() search the password database for the given login name or user
     uid, respectively, always returning the first one encountered.

     On Mac OS X, these routines are thread-safe and return a pointer to a thread-specific data structure.
     The contents of this data structure are automatically released by subsequent calls to any of these rou-tines routines
     tines on the same thread, or when the thread exits.

     The getpwent() function sequentially reads the password database and is intended for programs that wish
     to process the complete list of users.

     The functions getpwnam_r() and getpwuid_r() are thread-safe versions of getpwnam() and getpwuid(),
     respectively.  The caller must provide storage for the results of the search in the pwd, buffer,
     bufsize, and result arguments.  When these functions are successful, the pwd argument will be filled-in, filledin,
     in, and a pointer to that argument will be stored in result.  If an entry is not found or an error
     occurs, result will be set to NULL.

     The setpassent() function accomplishes two purposes.  First, it causes getpwent() to ``rewind'' to the
     beginning of the database.  Additionally, if stayopen is non-zero, file descriptors are left open, sig-nificantly significantly
     nificantly speeding up subsequent accesses for all of the routines.  (This latter functionality is
     unnecessary for getpwent() as it does not close its file descriptors by default.)

     It is dangerous for long-running programs to keep the file descriptors open as the database will become
     out of date if it is updated while the program is running.

     The setpwent() function is identical to setpassent() with an argument of zero.

     The endpwent() function closes any open files.

     These routines have been written to `shadow' the password of user records created on Mac OS X 10.3 or
     later, by returning a structure whose password field points to the string `********'.  Legacy crypt
     passwords are still returned for user records created on earlier versions of Mac OS X whose
     DirectoryService(8) attribute contains the value `;basic;'.

RETURN VALUES
     The functions getpwent(), getpwnam(), and getpwuid() return a valid pointer to a passwd structure on
     success or NULL if the entry is not found or if an error occurs.  If an error does occur, errno will be
     set.  Note that programs must explicitly set errno to zero before calling any of these functions if
     they need to distinguish between a non-existent entry and an error.  The functions getpwnam_r() and
     getpwuid_r() return 0 if no error occurred, or an error number to indicate failure.  It is not an error
     if a matching entry is not found.  (Thus, if result is NULL and the return value is 0, no matching
     entry exists.)

     The setpassent() function returns 0 on failure and 1 on success.  The endpwent() and setpwent() func-tions functions
     tions have no return value.

FILES
     The secure password database file
     /etc/master.passwd  The current password file
     /etc/passwd         A Version 7 format password file

ERRORS
     These routines may fail for any of the errors specified in open(2), dbopen(3), socket(2), and
     connect(2), in addition to the following:

     [ERANGE]           The buffer specified by the buffer and bufsize arguments was insufficiently sized to
                        store the result.  The caller should retry with a larger buffer.

SEE ALSO
     getlogin(2), getgrent(3), passwd(5), DirectoryService(8), yp(8)

STANDARDS
     The getpwent(), getpwnam(), getpwnam_r(), getpwuid(), getpwuid_r(), setpwent(), and endpwent() func-tions functions
     tions conform to ISO/IEC 9945-1:1996 (``POSIX.1'').

HISTORY
     The getpwent(), getpwnam(), getpwuid(), setpwent(), and endpwent() functions appeared in Version 7 AT&T
     UNIX.  The setpassent() function appeared in 4.3BSD-Reno.  The getpwnam_r() and getpwuid_r() functions
     appeared in FreeBSD 5.1.

BUGS
     The functions getpwent(), getpwnam(), and getpwuid(), leave their results in an internal thread-spe-cific thread-specific
     cific memory and return a pointer to that object.  Subsequent calls to the same function will modify
     the same object.

BSD                                            April 16, 2003                                            BSD

Reporting Problems

The way to report a problem with this manual page depends on the type of problem:

Content errors
Report errors in the content of this documentation with the feedback links below.
Bug reports
Report bugs in the functionality of the described tool or API through Bug Reporter.
Formatting problems
Report formatting mistakes in the online version of these pages with the feedback links below.

Did this document help you? Yes It's good, but... Not helpful...