man-pages/man3/getspnam.3.html
2021-03-31 01:06:50 +01:00

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">&nbsp;</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">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
/* General shadow password file API */
<B>#include &lt;<A HREF="file:///usr/include/shadow.h">shadow.h</A>&gt;</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 &lt;<A HREF="file:///usr/include/shadow.h">shadow.h</A>&gt;</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>&nbsp;&nbsp;&nbsp;&nbsp;Since&nbsp;glibc&nbsp;2.19:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Glibc&nbsp;2.19&nbsp;and&nbsp;earlier:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_BSD_SOURCE&nbsp;||&nbsp;_SVID_SOURCE
<A NAME="lbAD">&nbsp;</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">&nbsp;</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">&nbsp;</A>
<H3>Structure</H3>
The shadow password structure is defined in <I>&lt;<A HREF="file:///usr/include/shadow.h">shadow.h</A>&gt;</I> as follows:
<P>
struct spwd {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*sp_namp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Login&nbsp;name&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*sp_pwdp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Encrypted&nbsp;password&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;sp_lstchg;&nbsp;&nbsp;&nbsp;/*&nbsp;Date&nbsp;of&nbsp;last&nbsp;change
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(measured&nbsp;in&nbsp;days&nbsp;since
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1970-01-01&nbsp;00:00:00&nbsp;+0000&nbsp;(UTC))&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;sp_min;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Min&nbsp;#&nbsp;of&nbsp;days&nbsp;between&nbsp;changes&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;sp_max;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Max&nbsp;#&nbsp;of&nbsp;days&nbsp;between&nbsp;changes&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;sp_warn;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;#&nbsp;of&nbsp;days&nbsp;before&nbsp;password&nbsp;expires
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;warn&nbsp;user&nbsp;to&nbsp;change&nbsp;it&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;sp_inact;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;#&nbsp;of&nbsp;days&nbsp;after&nbsp;password&nbsp;expires
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;until&nbsp;account&nbsp;is&nbsp;disabled&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;sp_expire;&nbsp;&nbsp;&nbsp;/*&nbsp;Date&nbsp;when&nbsp;account&nbsp;expires
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(measured&nbsp;in&nbsp;days&nbsp;since
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1970-01-01&nbsp;00:00:00&nbsp;+0000&nbsp;(UTC))&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;sp_flag;&nbsp;&nbsp;/*&nbsp;Reserved&nbsp;*/
};
<A NAME="lbAG">&nbsp;</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">&nbsp;</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">&nbsp;</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>&lt;<A HREF="file:///usr/include/paths.h">paths.h</A>&gt;</I>
defines the constant
<B>_PATH_SHADOW</B>
to the pathname of the shadow password file.
<A NAME="lbAJ">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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>