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 );
20 .B struct spwd *getspent(void);
22 .B void setspent(void);
24 .B void endspent(void);
26 .BI "struct spwd *fgetspent(FILE *" stream );
28 .BI "struct spwd *sgetspent(const char *" s );
30 .BI "int putspent(const struct spwd *" p ", FILE *" stream );
34 .B int ulckpwdf(void);
37 .B #include <shadow.h>
39 .BI "int getspent_r(struct spwd *" spbuf ,
40 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
42 .BI "int getspnam_r(const char *" name ", struct spwd *" spbuf ,
43 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
45 .BI "int fgetspent_r(FILE *" stream ", struct spwd *" spbuf ,
46 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
48 .BI "int sgetspent_r(const char *" s ", struct spwd *" spbuf ,
49 .BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
53 Feature Test Macro Requirements for glibc (see
54 .BR feature_test_macros (7)):
64 Glibc 2.19 and earlier:
65 _BSD_SOURCE || _SVID_SOURCE
68 Long ago it was considered safe to have encrypted passwords openly
69 visible in the password file.
70 When computers got faster and people
71 got more security-conscious, this was no longer acceptable.
72 Julianne Frances Haugh implemented the shadow password suite
73 that keeps the encrypted passwords in
74 the shadow password database
75 (e.g., the local shadow password file
78 readable only by root.
80 The functions described below resemble those for
81 the traditional password database
86 .\" FIXME . I've commented out the following for the
87 .\" moment. The relationship between PAM and nsswitch.conf needs
88 .\" to be clearly documented in one place, which is pointed to by
89 .\" the pages for the user, group, and shadow password functions.
92 .\" This shadow password setup has been superseded by PAM
93 .\" (pluggable authentication modules), and the file
94 .\" .I /etc/nsswitch.conf
95 .\" now describes the sources to be used.
99 function returns a pointer to a structure containing
100 the broken-out fields of the record in the shadow password database
101 that matches the username
106 function returns a pointer to the next entry in the shadow password
108 The position in the input stream is initialized by
110 When done reading, the program may call
112 so that resources can be deallocated.
113 .\" some systems require a call of setspent() before the first getspent()
118 function is similar to
120 but uses the supplied stream instead of the one implicitly opened by
125 function parses the supplied string
132 function writes the contents of the supplied struct
135 as a text line in the shadow password file format to
137 String entries with value NULL and numerical entries with value \-1
138 are written as an empty string.
142 function is intended to protect against multiple simultaneous accesses
143 of the shadow password database.
144 It tries to acquire a lock, and returns 0 on success,
145 or \-1 on failure (lock not obtained within 15 seconds).
148 function releases the lock again.
149 Note that there is no protection against direct access of the shadow
151 Only programs that use
153 will notice the lock.
155 These were the functions that formed the original shadow API.
156 They are widely available.
158 .\" SUN doesn't have sgetspent()
159 .SS Reentrant versions
160 Analogous to the reentrant functions for the password database, glibc
161 also has reentrant functions for the shadow password database.
166 but stores the retrieved shadow password structure in the space pointed to by
168 This shadow password structure contains pointers to strings, and these strings
169 are stored in the buffer
173 A pointer to the result (in case of success) or NULL (in case no entry
174 was found or an error occurred) is stored in
182 are similarly analogous to their nonreentrant counterparts.
184 Some non-glibc systems also have functions with these names,
185 often with different prototypes.
186 .\" SUN doesn't have sgetspent_r()
188 The shadow password structure is defined in \fI<shadow.h>\fP as follows:
193 char *sp_namp; /* Login name */
194 char *sp_pwdp; /* Encrypted password */
195 long sp_lstchg; /* Date of last change
196 (measured in days since
197 1970-01-01 00:00:00 +0000 (UTC)) */
198 long sp_min; /* Min # of days between changes */
199 long sp_max; /* Max # of days between changes */
200 long sp_warn; /* # of days before password expires
201 to warn user to change it */
202 long sp_inact; /* # of days after password expires
203 until account is disabled */
204 long sp_expire; /* Date when account expires
205 (measured in days since
206 1970-01-01 00:00:00 +0000 (UTC)) */
207 unsigned long sp_flag; /* Reserved */
212 The functions that return a pointer return NULL if no more entries
213 are available or if an error occurs during processing.
214 The functions which have \fIint\fP as the return value return 0 for
215 success and \-1 for failure, with
217 set to indicate the cause of the error.
219 For the nonreentrant functions, the return value may point to static area,
220 and may be overwritten by subsequent calls to these functions.
222 The reentrant functions return zero on success.
223 In case of error, an error number is returned.
227 The caller does not have permission to access the shadow password file.
230 Supplied buffer is too small.
234 local shadow password database file
243 to the pathname of the shadow password file.
245 For an explanation of the terms used in this section, see
251 Interface Attribute Value
255 MT-Unsafe race:getspnam locale
260 MT-Unsafe race:getspent
271 MT-Unsafe race:getspent locale
275 T} Thread safety MT-Unsafe race:fgetspent
278 T} Thread safety MT-Unsafe race:sgetspent
285 T} Thread safety MT-Safe locale
292 T} Thread safety MT-Safe
299 signifies that if any of the functions
305 are used in parallel in different threads of a program,
306 then data races could occur.
308 The shadow password database and its associated API are
309 not specified in POSIX.1.
310 However, many other systems provide a similar API.