Seth Woolley's Man Viewer

getspnam(3) - endspent, fgetspent, fgetspent_r, getspent, getspent_r, getspnam, getspnam_r, lckpwdf, putspent, setspent, sgetspent, sgetspent_r, ulckpwdf, endspent, fgetspent, fgetspent_r, getspent, getspent_r, getspnam, getspnam_r, lckpwdf, putspent, setspent, sgetspent, sgetspent_r, ulckpwdf - get shadow password file entry - man 3 getspnam

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

GETSPNAM(3)                Linux Programmer's Manual               GETSPNAM(3)

       getspnam,  getspnam_r,  getspent, getspent_r, setspent, endspent, fget-
       spent, fgetspent_r, sgetspent, sgetspent_r, putspent, lckpwdf, ulckpwdf
       - get shadow(3,5) password file(1,n) entry

       /* General shadow(3,5) password file(1,n) API */
       #include <shadow.h>

       struct spwd *getspnam(const char *name);

       struct spwd *getspent(void);

       void setspent(void);

       void endspent(void);

       struct spwd *fgetspent(FILE *fp);

       struct spwd *sgetspent(const char *s);

       int putspent(struct spwd *p, FILE *fp);

       int lckpwdf(void);

       int ulckpwdf(void);

       /* GNU extension */
       #define _SVID_SOURCE    /* or _BSD_SOURCE */
       #include <shadow.h>

       int getspent_r(struct spwd *spbuf,
               char *buf, size_t buflen, struct spwd **spbufp);

       int getspnam_r(const char *name, struct spwd *spbuf,
               char *buf, size_t buflen, struct spwd **spbufp);

       int fgetspent_r(FILE *fp, struct spwd *spbuf,
               char *buf, size_t buflen, struct spwd **spbufp);

       int sgetspent_r(const char *s, struct spwd *spbuf,
               char *buf, size_t buflen, struct spwd **spbufp);

       Long ago it was considered safe to have encrypted passwords openly vis-
       ible in(1,8) the password file. When computers got  faster  and  people  got
       more  security-conscious,  this  was  no  longer  acceptable.  Julianne
       Frances Haugh implemented the shadow(3,5)  password  suite  that  keeps  the
       encrypted passwords in(1,8) /etc/shadow(3,5), readable only by root.

       The  access(2,5)  routines  described  below resemble those for /etc/passwd(1,5).
       This shadow(3,5) password  setup(2,8)  has  been  superseded  by  PAM  (pluggable
       authentication  modules), and the file(1,n) /etc/nsswitch.conf now describes
       the sources to be used.

       The getspnam() function returns a pointer to a structure containing the
       broken out fields of a line from /etc/shadow(3,5) for the entry that matches
       the user name name.

       The getspent() function returns a pointer to  the  next  entry  in(1,8)  the
       shadow(3,5)  password file.  The position in(1,8) the input stream is initialized
       by setspent().  When done reading, the program may call  endspent()  so
       that resources can be deallocated.

       The fgetspent() function is similar to getspent() but uses the supplied
       stream instead of the one implicitly opened by setspent().

       The sgetspent() function parses the supplied string(3,n)  s  into  a  struct

       The putspent() function writes the contents of the supplied struct spwd
       *p as a text line in(1,8) the shadow(3,5) password file(1,n) format to the stream  fp.
       String  entries with value NULL and numerical entries with value -1 are
       written as an empty string.

       The lckpwdf() function is intended to protect against  multiple  access(2,5)
       of  the  shadow(3,5)  password  database.  It  tries  to acquire a lock, and
       returns 0 on success, -1 on failure (lock not obtained within  15  sec-
       onds).   The  ulckpwdf()  function  releases the lock again.  Note that
       there is no protection against direct access(2,5)  of  the  shadow(3,5)  password
       file. Only programs that use lckpwdf() will notice the lock.

       These  were the routines that formed the original shadow(3,5) API.  They are
       widely available.

   Reentrant versions
       Analogous to the "reentrant" routines for the password file(1,n), glibc also
       has  reentrant versions here.  The getspnam_r() function is like getsp-
       nam() but stores the retrieved shadow(3,5) passwd(1,5)  structure  in(1,8)  the  space
       pointed to by spbuf.  This shadow(3,5) passwd(1,5) structure contains pointers to
       strings, and these strings are stored in(1,8) the buffer buf of size buflen.
       A  pointer to the result (in(1,8) case of success) or NULL (in(1,8) case no entry
       was found or an error(8,n) occurred) is stored in(1,8) *spbufp.

       The functions getspent_r(), fgetspent_r(), and sgetspent_r()  are  com-
       pletely analogous.

       Some non-glibc systems also have functions with these names, often with
       different prototypes.

       The shadow(3,5) passwd(1,5) structure is defined in(1,8) <shadow.h> as follows:

       struct spwd {
           char *sp_namp;         /* Login name */
           char *sp_pwdp;         /* Encrypted password */
           long sp_lstchg;        /* Date of last change */
           long sp_min;           /* Min #days between changes */
           long sp_max;           /* Max #days between changes */
           long sp_warn;          /* #days before pwd(1,n,1 builtins) expires
                                     to warn user to change it */
           long sp_inact;         /* #days after pwd(1,n,1 builtins) expires
                                     until account is disabled */
           long sp_expire;        /* #days since 1970-01-01
                                     until account is disabled */
           unsigned long sp_flag; /* Reserved */

       Routines return NULL if(3,n) no more entries are available or  if(3,n)  an  error(8,n)
       occurs  during processing.  Routines which have int as the return value
       return 0 for success and -1 for failure.

       For the non-reentrant functions, the return value may point  to  static
       area, and may be overwritten by subsequent calls to these functions.

       The  reentrant  functions return zero on success.  In case of error(8,n), an
       error(8,n) value is returned.

       ERANGE Supplied buffer is too small.

              shadow(3,5) password database file(1,n)

              lock file(1,n)

       The include file(1,n) <paths.h> defines the  constant  _PATH_SHADOW  to  the
       pathname of the shadow(3,5) password file.

       getgrnam(3), getpwnam(3), getpwnam_r(3), shadow(3,5)(5)

Shadow                            2003-11-15                       GETSPNAM(3)

References for this manual (incoming links)