]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getspnam.3
ffix
[thirdparty/man-pages.git] / man3 / getspnam.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl) and
2.\" Walter Harms (walter.harms@informatik.uni-oldenburg.de)
3.\"
4.\" Distributed under GPL
5.\"
cc4615cc 6.TH GETSPNAM 3 2007-07-26 "GNU" "Linux Programmer's Manual"
fea681da
MK
7.SH NAME
8getspnam, getspnam_r, getspent, getspent_r, setspent, endspent,
9fgetspent, fgetspent_r, sgetspent, sgetspent_r, putspent,
10lckpwdf, ulckpwdf \- get shadow password file entry
11.SH SYNOPSIS
12.nf
13/* General shadow password file API */
14.br
15.B #include <shadow.h>
16.sp
17.BI "struct spwd *getspnam(const char *" name );
18.sp
19.B struct spwd *getspent(void);
20.sp
21.B void setspent(void);
22.sp
23.B void endspent(void);
24.sp
25.BI "struct spwd *fgetspent(FILE *" fp );
26.sp
27.BI "struct spwd *sgetspent(const char *" s );
28.sp
29.BI "int putspent(struct spwd *" p ", FILE *" fp );
30.sp
31.B int lckpwdf(void);
32.sp
33.B int ulckpwdf(void);
34.sp
35/* GNU extension */
36.br
fea681da
MK
37.B #include <shadow.h>
38.sp
39.BI "int getspent_r(struct spwd *" spbuf ,
40.br
41.BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
42.sp
43.BI "int getspnam_r(const char *" name ", struct spwd *" spbuf ,
44.br
45.BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
46.sp
47.BI "int fgetspent_r(FILE *" fp ", struct spwd *" spbuf ,
48.br
49.BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
50.sp
51.BI "int sgetspent_r(const char *" s ", struct spwd *" spbuf ,
52.br
53.BI " char *" buf ", size_t " buflen ", struct spwd **" spbufp );
fea681da 54.fi
cc4615cc
MK
55.sp
56.in -4n
57Feature Test Macro Requirements for glibc (see
58.BR feature_test_macros (7)):
59.in
60.sp
61.ad l
62.BR getspent_r (),
63.BR getspnam_r (),
64.BR fgetspent_r (),
65.BR sgetspent_r ():
66_BSD_SOURCE || _SVID_SOURCE
67.ad b
fea681da
MK
68.SH DESCRIPTION
69Long ago it was considered safe to have encrypted passwords openly
c13182ef
MK
70visible in the password file.
71When computers got faster and people
fea681da
MK
72got more security-conscious, this was no longer acceptable.
73Julianne Frances Haugh implemented the shadow password suite
74that keeps the encrypted passwords in
05461740 75the shadow password database
c13182ef 76(e.g., the local shadow password file
fea681da 77.IR /etc/shadow ,
05461740 78NIS, and LDAP),
fea681da
MK
79readable only by root.
80.LP
05461740
MK
81The functions described below resemble those for
82the traditional password database
83(e.g., see
84.BR getpwnam (3)
85and
86.BR getpwent (3)).
777f5a9e 87.\" FIXME I've commented out the following for the
c13182ef
MK
88.\" moment. The relationship between PAM and nsswitch.conf needs
89.\" to be clearly documented in one place, which is pointed to by
90.\" the pages for the user, group, and shadow password functions.
777f5a9e 91.\" (Jul 2005, mtk)
c13182ef
MK
92.\"
93.\" This shadow password setup has been superseded by PAM
05461740
MK
94.\" (pluggable authentication modules), and the file
95.\" .I /etc/nsswitch.conf
96.\" now describes the sources to be used.
fea681da
MK
97.LP
98The
63aa9df0 99.BR getspnam ()
fea681da 100function returns a pointer to a structure containing
05461740
MK
101the broken-out fields of the record in the shadow password database
102that matches the user name
fea681da
MK
103.IR name .
104.LP
105The
63aa9df0 106.BR getspent ()
05461740
MK
107function returns a pointer to the next entry in the shadow password
108database.
fea681da 109The position in the input stream is initialized by
63aa9df0 110.BR setspent ().
fea681da 111When done reading, the program may call
63aa9df0 112.BR endspent ()
fea681da
MK
113so that resources can be deallocated.
114.\" some systems require a call of setspent() before the first getspent()
115.\" glibc does not
116.LP
117The
63aa9df0 118.BR fgetspent ()
fea681da 119function is similar to
63aa9df0 120.BR getspent ()
fea681da 121but uses the supplied stream instead of the one implicitly opened by
63aa9df0 122.BR setspent ().
fea681da
MK
123.LP
124The
63aa9df0 125.BR sgetspent ()
fea681da
MK
126function parses the supplied string
127.I s
05461740
MK
128into a struct
129.IR spwd .
fea681da
MK
130.LP
131The
63aa9df0 132.BR putspent ()
05461740
MK
133function writes the contents of the supplied struct
134.I spwd
fea681da
MK
135.RI * p
136as a text line in the shadow password file format to the stream
137.IR fp .
138String entries with value NULL and numerical entries with value \-1
139are written as an empty string.
140.LP
141The
63aa9df0 142.BR lckpwdf ()
c13182ef 143function is intended to protect against multiple simultaneous accesses
05461740
MK
144of the shadow password database.
145It tries to acquire a lock, and returns 0 on success,
146or \-1 on failure (lock not obtained within 15 seconds).
fea681da 147The
63aa9df0 148.BR ulckpwdf ()
fea681da
MK
149function releases the lock again.
150Note that there is no protection against direct access of the shadow
c13182ef
MK
151password file.
152Only programs that use
63aa9df0 153.BR lckpwdf ()
fea681da
MK
154will notice the lock.
155.LP
05461740 156These were the functions that formed the original shadow API.
fea681da
MK
157They are widely available.
158.\" Also in libc5
159.\" SUN doesn't have sgetspent()
160.SS "Reentrant versions"
05461740
MK
161Analogous to the reentrant functions for the password database, glibc
162also has reentrant functions for the shadow password database.
fea681da 163The
63aa9df0 164.BR getspnam_r ()
fea681da 165function is like
63aa9df0 166.BR getspnam ()
05461740 167but stores the retrieved shadow password structure in the space pointed to by
fea681da 168.IR spbuf .
05461740 169This shadow password structure contains pointers to strings, and these strings
fea681da
MK
170are stored in the buffer
171.I buf
172of size
173.IR buflen .
174A pointer to the result (in case of success) or NULL (in case no entry
175was found or an error occurred) is stored in
176.RI * spbufp .
177.LP
178The functions
63aa9df0
MK
179.BR getspent_r (),
180.BR fgetspent_r (),
fea681da 181and
63aa9df0 182.BR sgetspent_r ()
05461740 183are similarly analogous to their non-reentrant counterparts.
fea681da
MK
184.LP
185Some non-glibc systems also have functions with these names,
186often with different prototypes.
187.\" SUN doesn't have sgetspent_r()
188.SS Structure
05461740 189The shadow password structure is defined in \fI<shadow.h>\fP as follows:
fea681da 190.sp
05461740 191.RS +0.25i
fea681da
MK
192.nf
193struct spwd {
194 char *sp_namp; /* Login name */
195 char *sp_pwdp; /* Encrypted password */
05461740
MK
196 long sp_lstchg; /* Date of last change */
197 long sp_min; /* Min #days between changes */
198 long sp_max; /* Max #days between changes */
199 long sp_warn; /* #days before pwd expires
fea681da 200 to warn user to change it */
05461740 201 long sp_inact; /* #days after pwd expires
fea681da 202 until account is disabled */
05461740 203 long sp_expire; /* #days since 1970-01-01
fea681da
MK
204 until account is disabled */
205 unsigned long sp_flag; /* Reserved */
206};
207.fi
05461740 208.RE
fea681da 209.SH "RETURN VALUE"
05461740
MK
210The functions that return a pointer return NULL if no more entries
211are available or if an error occurs during processing.
a8d55537 212The functions which have \fIint\fP as the return value return 0 for
8729177b 213success and \-1 for failure.
fea681da
MK
214.LP
215For the non-reentrant functions, the return value may point to static area,
216and may be overwritten by subsequent calls to these functions.
217.LP
218The reentrant functions return zero on success.
05461740 219In case of error, an error number is returned.
fea681da
MK
220.SH ERRORS
221.TP
222.B ERANGE
223Supplied buffer is too small.
224.SH FILES
225.TP
226.I /etc/shadow
05461740 227local shadow password database file
fea681da
MK
228.TP
229.I /etc/.pwd.lock
230lock file
231.LP
232The include file
233.I <paths.h>
2f0af33b
MK
234defines the constant
235.B _PATH_SHADOW
236to the pathname of the shadow password file.
fea681da 237.SH "CONFORMING TO"
c13182ef 238The shadow password database and its associated API are
05461740
MK
239not specified in POSIX.1-2001.
240However, many other systems provide a similar API.
fea681da
MK
241.SH "SEE ALSO"
242.BR getgrnam (3),
243.BR getpwnam (3),
244.BR getpwnam_r (3),
cc4615cc 245.BR shadow (5)