1 <?xml version="1.0" encoding="UTF-8"?>
3 Copyright (c) 1989 - 1993, Julianne Frances Haugh
4 Copyright (c) 2007 - 2008, Nicolas François
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3. The name of the copyright holders or contributors may not be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 <refentry id='shadow.3'>
34 <refentrytitle>shadow</refentrytitle>
35 <manvolnum>3</manvolnum>
36 <refmiscinfo class="sectdesc">Library Calls</refmiscinfo>
38 <refnamediv id='name'>
39 <refname>shadow</refname>
40 <refname>getspnam</refname>
41 <refpurpose>encrypted password file routines</refpurpose>
44 <refsect1 id='syntax'>
47 <emphasis>#include <shadow.h></emphasis>
51 <emphasis>struct spwd *getspent();</emphasis>
55 <emphasis>struct spwd *getspnam(char</emphasis> <emphasis
56 remap='I'>*name</emphasis><emphasis>);</emphasis>
60 <emphasis>void setspent();</emphasis>
64 <emphasis>void endspent();</emphasis>
68 <emphasis>struct spwd *fgetspent(FILE</emphasis> <emphasis
69 remap='I'>*fp</emphasis><emphasis>);</emphasis>
73 <emphasis>struct spwd *sgetspent(char</emphasis> <emphasis
74 remap='I'>*cp</emphasis><emphasis>);</emphasis>
78 <emphasis>int putspent(struct spwd</emphasis> <emphasis
79 remap='I'>*p,</emphasis> <emphasis>FILE</emphasis> <emphasis
80 remap='I'>*fp</emphasis><emphasis>);</emphasis>
84 <emphasis>int lckpwdf();</emphasis>
88 <emphasis>int ulckpwdf();</emphasis>
92 <refsect1 id='description'>
93 <title>DESCRIPTION</title>
95 <emphasis remap='I'>shadow</emphasis> manipulates the contents of the
96 shadow password file, <filename>/etc/shadow</filename>. The structure
97 in the <emphasis remap='I'>#include</emphasis> file is:
99 <programlisting>struct spwd {
100 char *sp_namp; /* user login name */
101 char *sp_pwdp; /* encrypted password */
102 long int sp_lstchg; /* last password change */
103 long int sp_min; /* days until change allowed. */
104 long int sp_max; /* days before change required */
105 long int sp_warn; /* days warning for expiration */
106 long int sp_inact; /* days before account inactive */
107 long int sp_expire; /* date when account expires */
108 unsigned long int sp_flag; /* reserved for future use */
111 <para>The meanings of each field are:</para>
112 <itemizedlist mark='bullet'>
114 <para>sp_namp - pointer to null-terminated user name</para>
117 <para>sp_pwdp - pointer to null-terminated password</para>
120 <para>sp_lstchg - days since Jan 1, 1970 password was last changed</para>
123 <para>sp_min - days before which password may not be changed</para>
126 <para>sp_max - days after which password must be changed</para>
129 <para>sp_warn - days before password is to expire that user is warned of
130 pending password expiration
134 <para>sp_inact - days after password expires that account is considered
135 inactive and disabled
139 <para>sp_expire - days since Jan 1, 1970 when account will be disabled</para>
142 <para>sp_flag - reserved for future use</para>
148 <refsect1 id='description2'>
149 <title>DESCRIPTION</title>
151 <emphasis>getspent</emphasis>, <emphasis>getspname</emphasis>,
152 <emphasis>fgetspent</emphasis>, and <emphasis>sgetspent</emphasis>
153 each return a pointer to a <emphasis>struct spwd</emphasis>.
154 <emphasis>getspent</emphasis> returns the next entry from the file,
155 and <emphasis>fgetspent</emphasis> returns the next entry from the
156 given stream, which is assumed to be a file of the proper format.
157 <emphasis>sgetspent</emphasis> returns a pointer to a <emphasis>struct
158 spwd</emphasis> using the provided string as input.
159 <emphasis>getspnam</emphasis> searches from the current position in
160 the file for an entry matching <emphasis>name</emphasis>.
164 <emphasis>setspent</emphasis> and <emphasis>endspent</emphasis> may be
165 used to begin and end, respectively, access to the shadow password
170 The <emphasis>lckpwdf</emphasis> and <emphasis>ulckpwdf</emphasis>
171 routines should be used to insure exclusive access to the
172 <filename>/etc/shadow</filename> file. <emphasis>lckpwdf</emphasis>
173 attempts to acquire a lock using <emphasis>pw_lock</emphasis> for up
174 to 15 seconds. It continues by attempting to acquire a second lock
175 using <emphasis>spw_lock</emphasis> for the remainder of the initial
176 15 seconds. Should either attempt fail after a total of 15 seconds,
177 <emphasis>lckpwdf</emphasis> returns -1. When both locks are acquired
182 <refsect1 id='diagnostics'>
183 <title>DIAGNOSTICS</title>
185 Routines return NULL if no more entries are available or if an error
186 occurs during processing. Routines which have <emphasis>int</emphasis>
187 as the return value return 0 for success and
192 <refsect1 id='caveats'>
193 <title>CAVEATS</title>
195 These routines may only be used by the superuser as access to the
196 shadow password file is restricted.
200 <refsect1 id='files'>
204 <term><filename>/etc/shadow</filename></term>
206 <para>Secure user account information.</para>
212 <refsect1 id='see_also'>
213 <title>SEE ALSO</title>
216 <refentrytitle>getpwent</refentrytitle><manvolnum>3</manvolnum>
219 <refentrytitle>shadow</refentrytitle><manvolnum>5</manvolnum>