1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl) and
2 .\" Walter Harms (walter.harms@informatik.uni-oldenburg.de)
4 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
5 .\" Distributed under GPL
8 .TH GETSPNAM 3 2017-09-15 "GNU" "Linux Programmer's Manual"
10 getspnam, getspnam_r, getspent, getspent_r, setspent, endspent,
11 fgetspent, fgetspent_r, sgetspent, sgetspent_r, putspent,
12 lckpwdf, ulckpwdf \- get shadow password file entry
15 /* General shadow password file API */
16 .B #include <shadow.h>
18 .BI "struct spwd *getspnam(const char *" name );
19 .B struct spwd *getspent(void);
21 .B void setspent(void);
22 .B void endspent(void);
24 .BI "struct spwd *fgetspent(FILE *" stream );
25 .BI "struct spwd *sgetspent(const char *" s );
27 .BI "int putspent(const struct spwd *" p ", FILE *" stream );
30 .B int ulckpwdf(void);
33 .B #include <shadow.h>
35 .BI "int getspent_r(struct spwd *" spbuf ,
36 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
37 .BI "int getspnam_r(const char *" name ", struct spwd *" spbuf ,
38 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
40 .BI "int fgetspent_r(FILE *" stream ", struct spwd *" spbuf ,
41 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
42 .BI "int sgetspent_r(const char *" s ", struct spwd *" spbuf ,
43 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
58 Glibc 2.19 and earlier:
59 _BSD_SOURCE || _SVID_SOURCE
62 Long ago it was considered safe to have encrypted passwords openly
63 visible in the password file.
64 When computers got faster and people
65 got more security-conscious, this was no longer acceptable.
66 Julianne Frances Haugh implemented the shadow password suite
67 that keeps the encrypted passwords in
68 the shadow password database
69 (e.g., the local shadow password file
72 readable only by root.
74 The functions described below resemble those for
75 the traditional password database
80 .\" FIXME . I've commented out the following for the
81 .\" moment. The relationship between PAM and nsswitch.conf needs
82 .\" to be clearly documented in one place, which is pointed to by
83 .\" the pages for the user, group, and shadow password functions.
86 .\" This shadow password setup has been superseded by PAM
87 .\" (pluggable authentication modules), and the file
88 .\" .I /etc/nsswitch.conf
89 .\" now describes the sources to be used.
93 function returns a pointer to a structure containing
94 the broken-out fields of the record in the shadow password database
95 that matches the username
100 function returns a pointer to the next entry in the shadow password
102 The position in the input stream is initialized by
104 When done reading, the program may call
106 so that resources can be deallocated.
107 .\" some systems require a call of setspent() before the first getspent()
112 function is similar to
114 but uses the supplied stream instead of the one implicitly opened by
119 function parses the supplied string
126 function writes the contents of the supplied struct
129 as a text line in the shadow password file format to
131 String entries with value NULL and numerical entries with value \-1
132 are written as an empty string.
136 function is intended to protect against multiple simultaneous accesses
137 of the shadow password database.
138 It tries to acquire a lock, and returns 0 on success,
139 or \-1 on failure (lock not obtained within 15 seconds).
142 function releases the lock again.
143 Note that there is no protection against direct access of the shadow
145 Only programs that use
147 will notice the lock.
149 These were the functions that formed the original shadow API.
150 They are widely available.
152 .\" SUN doesn't have sgetspent()
153 .SS Reentrant versions
154 Analogous to the reentrant functions for the password database, glibc
155 also has reentrant functions for the shadow password database.
160 but stores the retrieved shadow password structure in the space pointed to by
162 This shadow password structure contains pointers to strings, and these strings
163 are stored in the buffer
167 A pointer to the result (in case of success) or NULL (in case no entry
168 was found or an error occurred) is stored in
176 are similarly analogous to their nonreentrant counterparts.
178 Some non-glibc systems also have functions with these names,
179 often with different prototypes.
180 .\" SUN doesn't have sgetspent_r()
182 The shadow password structure is defined in \fI<shadow.h>\fP as follows:
187 char *sp_namp; /* Login name */
188 char *sp_pwdp; /* Encrypted password */
189 long sp_lstchg; /* Date of last change
190 (measured in days since
191 1970\-01\-01 00:00:00 +0000 (UTC)) */
192 long sp_min; /* Min # of days between changes */
193 long sp_max; /* Max # of days between changes */
194 long sp_warn; /* # of days before password expires
195 to warn user to change it */
196 long sp_inact; /* # of days after password expires
197 until account is disabled */
198 long sp_expire; /* Date when account expires
199 (measured in days since
200 1970\-01\-01 00:00:00 +0000 (UTC)) */
201 unsigned long sp_flag; /* Reserved */
206 The functions that return a pointer return NULL if no more entries
207 are available or if an error occurs during processing.
208 The functions which have \fIint\fP as the return value return 0 for
209 success and \-1 for failure, with
211 set to indicate the error.
213 For the nonreentrant functions, the return value may point to static area,
214 and may be overwritten by subsequent calls to these functions.
216 The reentrant functions return zero on success.
217 In case of error, an error number is returned.
221 The caller does not have permission to access the shadow password file.
224 Supplied buffer is too small.
228 local shadow password database file
237 to the pathname of the shadow password file.
239 For an explanation of the terms used in this section, see
247 Interface Attribute Value
251 MT-Unsafe race:getspnam locale
256 MT-Unsafe race:getspent
264 MT-Unsafe race:getspent locale
269 MT-Unsafe race:fgetspent
274 MT-Unsafe race:sgetspent
298 signifies that if any of the functions
304 are used in parallel in different threads of a program,
305 then data races could occur.
307 The shadow password database and its associated API are
308 not specified in POSIX.1.
309 However, many other systems provide a similar API.