1GETSPNAM(3)                Linux Programmer's Manual               GETSPNAM(3)
2
3
4

NAME

6       getspnam,  getspnam_r,  getspent, getspent_r, setspent, endspent, fget‐
7       spent, fgetspent_r, sgetspent, sgetspent_r, putspent, lckpwdf, ulckpwdf
8       - get shadow password file entry
9

SYNOPSIS

11       /* General shadow password file API */
12       #include <shadow.h>
13
14       struct spwd *getspnam(const char *name);
15
16       struct spwd *getspent(void);
17
18       void setspent(void);
19
20       void endspent(void);
21
22       struct spwd *fgetspent(FILE *fp);
23
24       struct spwd *sgetspent(const char *s);
25
26       int putspent(struct spwd *p, FILE *fp);
27
28       int lckpwdf(void);
29
30       int ulckpwdf(void);
31
32       /* GNU extension */
33       #include <shadow.h>
34
35       int getspent_r(struct spwd *spbuf,
36               char *buf, size_t buflen, struct spwd **spbufp);
37
38       int getspnam_r(const char *name, struct spwd *spbuf,
39               char *buf, size_t buflen, struct spwd **spbufp);
40
41       int fgetspent_r(FILE *fp, struct spwd *spbuf,
42               char *buf, size_t buflen, struct spwd **spbufp);
43
44       int sgetspent_r(const char *s, struct spwd *spbuf,
45               char *buf, size_t buflen, struct spwd **spbufp);
46
47   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
48
49       getspent_r(), getspnam_r(), fgetspent_r(), sgetspent_r():
50           _BSD_SOURCE || _SVID_SOURCE
51

DESCRIPTION

53       Long ago it was considered safe to have encrypted passwords openly vis‐
54       ible in the password file.  When computers got faster  and  people  got
55       more  security-conscious,  this  was  no  longer  acceptable.  Julianne
56       Frances Haugh implemented the shadow  password  suite  that  keeps  the
57       encrypted  passwords  in  the shadow password database (e.g., the local
58       shadow password file /etc/shadow, NIS,  and  LDAP),  readable  only  by
59       root.
60
61       The  functions described below resemble those for the traditional pass‐
62       word database (e.g., see getpwnam(3) and getpwent(3)).
63
64       The getspnam() function returns a pointer to a structure containing the
65       broken-out  fields  of  the record in the shadow password database that
66       matches the username name.
67
68       The getspent() function returns a pointer to  the  next  entry  in  the
69       shadow password database.  The position in the input stream is initial‐
70       ized by setspent().  When done reading, the program may call endspent()
71       so that resources can be deallocated.
72
73       The fgetspent() function is similar to getspent() but uses the supplied
74       stream instead of the one implicitly opened by setspent().
75
76       The sgetspent() function parses the supplied string  s  into  a  struct
77       spwd.
78
79       The putspent() function writes the contents of the supplied struct spwd
80       *p as a text line in the shadow password file format to the stream  fp.
81       String  entries with value NULL and numerical entries with value -1 are
82       written as an empty string.
83
84       The lckpwdf() function is intended to protect against multiple simulta‐
85       neous  accesses of the shadow password database.  It tries to acquire a
86       lock, and returns 0 on success, or -1 on  failure  (lock  not  obtained
87       within  15  seconds).  The ulckpwdf() function releases the lock again.
88       Note that there is no protection against direct access  of  the  shadow
89       password file.  Only programs that use lckpwdf() will notice the lock.
90
91       These were the functions that formed the original shadow API.  They are
92       widely available.
93
94   Reentrant versions
95       Analogous to the reentrant functions for the password  database,  glibc
96       also  has  reentrant  functions  for the shadow password database.  The
97       getspnam_r() function is  like  getspnam()  but  stores  the  retrieved
98       shadow  password  structure  in  the  space  pointed to by spbuf.  This
99       shadow password structure  contains  pointers  to  strings,  and  these
100       strings  are stored in the buffer buf of size buflen.  A pointer to the
101       result (in case of success) or NULL (in case no entry was found  or  an
102       error occurred) is stored in *spbufp.
103
104       The  functions getspent_r(), fgetspent_r(), and sgetspent_r() are simi‐
105       larly analogous to their nonreentrant counterparts.
106
107       Some non-glibc systems also have functions with these names, often with
108       different prototypes.
109
110   Structure
111       The shadow password structure is defined in <shadow.h> as follows:
112
113           struct spwd {
114               char *sp_namp;     /* Login name */
115               char *sp_pwdp;     /* Encrypted password */
116               long  sp_lstchg;   /* Date of last change
117                                     (measured in days since
118                                     1970-01-01 00:00:00 +0000 (UTC)) */
119               long  sp_min;      /* Min # of days between changes */
120               long  sp_max;      /* Max # of days between changes */
121               long  sp_warn;     /* # of days before password expires
122                                     to warn user to change it */
123               long  sp_inact;    /* # of days after password expires
124                                     until account is disabled */
125               long  sp_expire;   /* Date when account expires
126                                     (measured in days since
127                                     1970-01-01 00:00:00 +0000 (UTC)) */
128               unsigned long sp_flag;  /* Reserved */
129           };
130

RETURN VALUE

132       The  functions that return a pointer return NULL if no more entries are
133       available or if an error occurs during processing.  The functions which
134       have  int  as the return value return 0 for success and -1 for failure,
135       with errno set to indicate the cause of the error.
136
137       For the nonreentrant functions, the return value may  point  to  static
138       area, and may be overwritten by subsequent calls to these functions.
139
140       The  reentrant  functions return zero on success.  In case of error, an
141       error number is returned.
142

ERRORS

144       EACCES The caller does not have permission to access the  shadow  pass‐
145              word file.
146
147       ERANGE Supplied buffer is too small.
148

FILES

150       /etc/shadow
151              local shadow password database file
152
153       /etc/.pwd.lock
154              lock file
155
156       The  include  file  <paths.h>  defines the constant _PATH_SHADOW to the
157       pathname of the shadow password file.
158

CONFORMING TO

160       The shadow password database and its associated API are  not  specified
161       in POSIX.1-2001.  However, many other systems provide a similar API.
162

SEE ALSO

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

COLOPHON

167       This  page  is  part of release 3.53 of the Linux man-pages project.  A
168       description of the project, and information about reporting  bugs,  can
169       be found at http://www.kernel.org/doc/man-pages/.
170
171
172
173GNU                               2013-04-19                       GETSPNAM(3)
Impressum