469 lines
12 KiB
HTML
469 lines
12 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETSPNAM</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETSPNAM</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
getspnam, getspnam_r, getspent, getspent_r, setspent, endspent,
|
|
fgetspent, fgetspent_r, sgetspent, sgetspent_r, putspent,
|
|
lckpwdf, ulckpwdf - get shadow password file entry
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
/* General shadow password file API */
|
|
<B>#include <<A HREF="file:///usr/include/shadow.h">shadow.h</A>></B>
|
|
|
|
<B>struct spwd *getspnam(const char *</B><I>name</I><B>);</B>
|
|
|
|
<B>struct spwd *getspent(void);</B>
|
|
|
|
<B>void setspent(void);</B>
|
|
|
|
<B>void endspent(void);</B>
|
|
|
|
<B>struct spwd *fgetspent(FILE *</B><I>stream</I><B>);</B>
|
|
|
|
<B>struct spwd *sgetspent(const char *</B><I>s</I><B>);</B>
|
|
|
|
<B>int putspent(const struct spwd *</B><I>p</I><B>, FILE *</B><I>stream</I><B>);</B>
|
|
|
|
<B>int lckpwdf(void);</B>
|
|
|
|
<B>int ulckpwdf(void);</B>
|
|
|
|
/* GNU extension */
|
|
<B>#include <<A HREF="file:///usr/include/shadow.h">shadow.h</A>></B>
|
|
|
|
<B>int getspent_r(struct spwd *</B><I>spbuf</I><B>,</B>
|
|
<B> char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>, struct spwd **</B><I>spbufp</I><B>);</B>
|
|
|
|
<B>int getspnam_r(const char *</B><I>name</I><B>, struct spwd *</B><I>spbuf</I><B>,</B>
|
|
<B> char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>, struct spwd **</B><I>spbufp</I><B>);</B>
|
|
|
|
<B>int fgetspent_r(FILE *</B><I>stream</I><B>, struct spwd *</B><I>spbuf</I><B>,</B>
|
|
<B> char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>, struct spwd **</B><I>spbufp</I><B>);</B>
|
|
|
|
<B>int sgetspent_r(const char *</B><I>s</I><B>, struct spwd *</B><I>spbuf</I><B>,</B>
|
|
<B> char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>, struct spwd **</B><I>spbufp</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
|
|
<B>getspent_r</B>(),
|
|
|
|
<B>getspnam_r</B>(),
|
|
|
|
<B>fgetspent_r</B>(),
|
|
|
|
<B>sgetspent_r</B>():
|
|
|
|
<BR> Since glibc 2.19:
|
|
<BR> _DEFAULT_SOURCE
|
|
<BR> Glibc 2.19 and earlier:
|
|
<BR> _BSD_SOURCE || _SVID_SOURCE
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
Long ago it was considered safe to have encrypted passwords openly
|
|
visible in the password file.
|
|
When computers got faster and people
|
|
got more security-conscious, this was no longer acceptable.
|
|
Julianne Frances Haugh implemented the shadow password suite
|
|
that keeps the encrypted passwords in
|
|
the shadow password database
|
|
(e.g., the local shadow password file
|
|
<I>/etc/shadow</I>,
|
|
|
|
NIS, and LDAP),
|
|
readable only by root.
|
|
<P>
|
|
|
|
The functions described below resemble those for
|
|
the traditional password database
|
|
(e.g., see
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwnam">getpwnam</A></B>(3)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwent">getpwent</A></B>(3)).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>getspnam</B>()
|
|
|
|
function returns a pointer to a structure containing
|
|
the broken-out fields of the record in the shadow password database
|
|
that matches the username
|
|
<I>name</I>.
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>getspent</B>()
|
|
|
|
function returns a pointer to the next entry in the shadow password
|
|
database.
|
|
The position in the input stream is initialized by
|
|
<B>setspent</B>().
|
|
|
|
When done reading, the program may call
|
|
<B>endspent</B>()
|
|
|
|
so that resources can be deallocated.
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>fgetspent</B>()
|
|
|
|
function is similar to
|
|
<B>getspent</B>()
|
|
|
|
but uses the supplied stream instead of the one implicitly opened by
|
|
<B>setspent</B>().
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>sgetspent</B>()
|
|
|
|
function parses the supplied string
|
|
<I>s</I>
|
|
|
|
into a struct
|
|
<I>spwd</I>.
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>putspent</B>()
|
|
|
|
function writes the contents of the supplied struct
|
|
<I>spwd</I>
|
|
|
|
<I>*p</I>
|
|
|
|
as a text line in the shadow password file format to
|
|
<I>stream</I>.
|
|
|
|
String entries with value NULL and numerical entries with value -1
|
|
are written as an empty string.
|
|
<P>
|
|
|
|
The
|
|
<B>lckpwdf</B>()
|
|
|
|
function is intended to protect against multiple simultaneous accesses
|
|
of the shadow password database.
|
|
It tries to acquire a lock, and returns 0 on success,
|
|
or -1 on failure (lock not obtained within 15 seconds).
|
|
The
|
|
<B>ulckpwdf</B>()
|
|
|
|
function releases the lock again.
|
|
Note that there is no protection against direct access of the shadow
|
|
password file.
|
|
Only programs that use
|
|
<B>lckpwdf</B>()
|
|
|
|
will notice the lock.
|
|
<P>
|
|
|
|
These were the functions that formed the original shadow API.
|
|
They are widely available.
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Reentrant versions</H3>
|
|
|
|
Analogous to the reentrant functions for the password database, glibc
|
|
also has reentrant functions for the shadow password database.
|
|
The
|
|
<B>getspnam_r</B>()
|
|
|
|
function is like
|
|
<B>getspnam</B>()
|
|
|
|
but stores the retrieved shadow password structure in the space pointed to by
|
|
<I>spbuf</I>.
|
|
|
|
This shadow password structure contains pointers to strings, and these strings
|
|
are stored in the buffer
|
|
<I>buf</I>
|
|
|
|
of size
|
|
<I>buflen</I>.
|
|
|
|
A pointer to the result (in case of success) or NULL (in case no entry
|
|
was found or an error occurred) is stored in
|
|
<I>*spbufp</I>.
|
|
|
|
<P>
|
|
|
|
The functions
|
|
<B>getspent_r</B>(),
|
|
|
|
<B>fgetspent_r</B>(),
|
|
|
|
and
|
|
<B>sgetspent_r</B>()
|
|
|
|
are similarly analogous to their nonreentrant counterparts.
|
|
<P>
|
|
|
|
Some non-glibc systems also have functions with these names,
|
|
often with different prototypes.
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Structure</H3>
|
|
|
|
The shadow password structure is defined in <I><<A HREF="file:///usr/include/shadow.h">shadow.h</A>></I> as follows:
|
|
<P>
|
|
|
|
|
|
|
|
struct spwd {
|
|
<BR> char *sp_namp; /* Login name */
|
|
<BR> char *sp_pwdp; /* Encrypted password */
|
|
<BR> long sp_lstchg; /* Date of last change
|
|
<BR> (measured in days since
|
|
<BR> 1970-01-01 00:00:00 +0000 (UTC)) */
|
|
<BR> long sp_min; /* Min # of days between changes */
|
|
<BR> long sp_max; /* Max # of days between changes */
|
|
<BR> long sp_warn; /* # of days before password expires
|
|
<BR> to warn user to change it */
|
|
<BR> long sp_inact; /* # of days after password expires
|
|
<BR> until account is disabled */
|
|
<BR> long sp_expire; /* Date when account expires
|
|
<BR> (measured in days since
|
|
<BR> 1970-01-01 00:00:00 +0000 (UTC)) */
|
|
<BR> unsigned long sp_flag; /* Reserved */
|
|
};
|
|
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The functions that return a pointer return NULL if no more entries
|
|
are available or if an error occurs during processing.
|
|
The functions which have <I>int</I> as the return value return 0 for
|
|
success and -1 for failure, with
|
|
<I>errno</I>
|
|
|
|
set to indicate the cause of the error.
|
|
<P>
|
|
|
|
For the nonreentrant functions, the return value may point to static area,
|
|
and may be overwritten by subsequent calls to these functions.
|
|
<P>
|
|
|
|
The reentrant functions return zero on success.
|
|
In case of error, an error number is returned.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EACCES</B>
|
|
|
|
<DD>
|
|
The caller does not have permission to access the shadow password file.
|
|
<DT id="2"><B>ERANGE</B>
|
|
|
|
<DD>
|
|
Supplied buffer is too small.
|
|
</DL>
|
|
<A NAME="lbAI"> </A>
|
|
<H2>FILES</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="3"><I>/etc/shadow</I>
|
|
|
|
<DD>
|
|
local shadow password database file
|
|
<DT id="4"><I>/etc/.pwd.lock</I>
|
|
|
|
<DD>
|
|
lock file
|
|
</DL>
|
|
<P>
|
|
|
|
The include file
|
|
<I><<A HREF="file:///usr/include/paths.h">paths.h</A>></I>
|
|
|
|
defines the constant
|
|
<B>_PATH_SHADOW</B>
|
|
|
|
to the pathname of the shadow password file.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>getspnam</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:getspnam locale
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>getspent</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:getspent
|
|
<BR>
|
|
|
|
race:spentbuf locale
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>setspent</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>endspent</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>getspent_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:getspent locale
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>fgetspent</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:fgetspent<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>sgetspent</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:sgetspent<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>putspent</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>getspnam_r</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>sgetspent_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>lckpwdf</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>ulckpwdf</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>fgetspent_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
In the above table,
|
|
<I>getspent</I>
|
|
|
|
in
|
|
<I>race:getspent</I>
|
|
|
|
signifies that if any of the functions
|
|
<B>setspent</B>(),
|
|
|
|
<B>getspent</B>(),
|
|
|
|
<B>getspent_r</B>(),
|
|
|
|
or
|
|
<B>endspent</B>()
|
|
|
|
are used in parallel in different threads of a program,
|
|
then data races could occur.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
The shadow password database and its associated API are
|
|
not specified in POSIX.1.
|
|
However, many other systems provide a similar API.
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getgrnam">getgrnam</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwnam">getpwnam</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwnam_r">getpwnam_r</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+shadow">shadow</A></B>(5)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="8"><A HREF="#lbAE">Reentrant versions</A><DD>
|
|
<DT id="9"><A HREF="#lbAF">Structure</A><DD>
|
|
</DL>
|
|
<DT id="10"><A HREF="#lbAG">RETURN VALUE</A><DD>
|
|
<DT id="11"><A HREF="#lbAH">ERRORS</A><DD>
|
|
<DT id="12"><A HREF="#lbAI">FILES</A><DD>
|
|
<DT id="13"><A HREF="#lbAJ">ATTRIBUTES</A><DD>
|
|
<DT id="14"><A HREF="#lbAK">CONFORMING TO</A><DD>
|
|
<DT id="15"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="16"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:44 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|