getpwnam,
GETPWNAM(M)         Linux Programmer's Manual         GETPWNAM(M)



NAME
       getpwnam, getpwuid - get password file entry

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

       struct passwd *getpwnam(const char *name);

       struct passwd *getpwuid(uid_t uid);

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

DESCRIPTION
       The  getpwnam()  function returns a pointer to a structure
       containing the broken out fields of a line from  the  user
       password database for the entry that matches the user name
       name.

       The getpwuid() function returns a pointer to  a  structure
       containing  the  broken out fields of a line from the user
       password database for the entry that matches the user  uid
       uid.

       The  getpwnam_r()  function  updates  the passwd structure
       pointed to by passwd and stores a pointer to  that  struc-
       ture  at the location pointed to by result.  The structure
       will contain an entry from the system  user  database  for
       the entry that matches the user name name.  Storage refer-
       enced by the structure is allocated from the  memory  pro-
       vided  with  the buffer parameter, which is buflen charac-
       ters large.  A NULL pointer is returned  at  the  location
       pointed to by result on error or if the requested entry is
       not found.

       The passwd structure is defined in <pwd.h> as follows:

              struct passwd {
                      char    *pw_name;       /* user name */
                      char    *pw_passwd;     /* user password */
                      uid_t   pw_uid;         /* user id */
                      gid_t   pw_gid;         /* group id */
                      char    *pw_gecos;      /* real name */
                      char    *pw_dir;        /* home directory */
                      char    *pw_shell;      /* shell program */
              };

RETURN VALUE
       The getpwnam() and getpwuid() functions return  a  pointer
       to  the passwd structure, or NULL if the matching entry is
       not found or an error occurs.

       The getpwnam_r() function returns zero on success  and  an
       error number to indicate the error.

ERRORS
       ENOMEM Insufficient memory to allocate passwd structure.

NOTE
       The  user  password database mostly refers to /etc/passwd.
       However, with recent systems it  also  refers  to  network
       wide  databases  using  NIS, LDAP and other local files as
       configured in /etc/nsswitch.conf.

FILES
       /etc/passwd
              password database file

       /etc/nsswitch.conf
              System Databases and Name Service Switch configura-
              tion file

CONFORMING TO
       SVID 3, POSIX, BSD 4.3

SEE ALSO
       fgetpwent(t), getgrnam(m), getpwent(t), setpwent(t), endp-
       went(t),    getpw(w),    putpwent(t),    nsswitch.conf(f),
       passwd(d)



GNU                         2002-03-09                GETPWNAM(M)