GETSPNAM
NAME
getspnam, getspnam_r, getspent, getspent_r, setspent, endspent,
fgetspent, fgetspent_r, sgetspent, sgetspent_r, putspent,
lckpwdf, ulckpwdf - get shadow password file entry
SYNOPSIS
/* General shadow password file API */
#include <shadow.h>
I struct spwd *getspnam(const char * name );
struct spwd *getspent(void);
void setspent(void);
void endspent(void);
I struct spwd *fgetspent(FILE * fp );
I struct spwd *sgetspent(const char * s );
I int putspent(struct spwd * p , FILE * fp );
int lckpwdf(void);
int ulckpwdf(void);
/* GNU extension */
R #define _SVID_SOURCE /* or _BSD_SOURCE */
#include <shadow.h>
I int getspent_r(struct spwd * spbuf ,
I char * buf , size_t buflen , struct spwd ** spbufp );
I int getspnam_r(const char * name , struct spwd * spbuf ,
I char * buf , size_t buflen , struct spwd ** spbufp );
I int fgetspent_r(FILE * fp , struct spwd * spbuf ,
I char * buf , size_t buflen , struct spwd ** spbufp );
I int sgetspent_r(const char * s , struct spwd * spbuf ,
I char * buf , size_t buflen , struct spwd ** spbufp );
DESCRIPTION
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
R /etc/shadow ,
NIS, and LDAP),
readable only by root.
The functions described below resemble those for
the traditional password database
(e.g., see
getpwnam(3)
and
getpwent(3)).
The
R getspnam ()
function returns a pointer to a structure containing
the broken-out fields of the record in the shadow password database
that matches the user name
R name .
The
R getspent ()
function returns a pointer to the next entry in the shadow password
database.
The position in the input stream is initialized by
R setspent ().
When done reading, the program may call
R endspent ()
so that resources can be deallocated.
The
R fgetspent ()
function is similar to
R getspent ()
but uses the supplied stream instead of the one implicitly opened by
R setspent ().
The
R sgetspent ()
function parses the supplied string
s
into a struct
R spwd .
The
R putspent ()
function writes the contents of the supplied struct
spwd
*p
as a text line in the shadow password file format to the stream
R fp .
String entries with value NULL and numerical entries with value -1
are written as an empty string.
The
R lckpwdf ()
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
R ulckpwdf ()
function releases the lock again.
Note that there is no protection against direct access of the shadow
password file.
Only programs that use
R lckpwdf ()
will notice the lock.
These were the functions that formed the original shadow API.
They are widely available.
Reentrant versions
Analogous to the reentrant functions for the password database, glibc
also has reentrant functions for the shadow password database.
The
R getspnam_r ()
function is like
R getspnam ()
but stores the retrieved shadow password structure in the space pointed to by
R spbuf .
This shadow password structure contains pointers to strings, and these strings
are stored in the buffer
buf
of size
R buflen .
A pointer to the result (in case of success) or NULL (in case no entry
was found or an error occurred) is stored in
*spbufp.
The functions
R getspent_r (),
R fgetspent_r (),
and
R sgetspent_r ()
are similarly analogous to their non-reentrant counterparts.
Some non-glibc systems also have functions with these names,
often with different prototypes.
Structure
The shadow password structure is defined in
<shadow.h> as follows:
struct spwd {
char *sp_namp; /* Login name */
char *sp_pwdp; /* Encrypted password */
long sp_lstchg; /* Date of last change */
long sp_min; /* Min #days between changes */
long sp_max; /* Max #days between changes */
long sp_warn; /* #days before pwd expires
to warn user to change it */
long sp_inact; /* #days after pwd expires
until account is disabled */
long sp_expire; /* #days since 1970-01-01
until account is disabled */
unsigned long sp_flag; /* Reserved */
};
RETURN VALUE
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 int as the return value return 0 for
success and -1 for failure.
For the non-reentrant functions, the return value may point to static area,
and may be overwritten by subsequent calls to these functions.
The reentrant functions return zero on success.
In case of error, an error number is returned.
ERRORS
ERANGE
Supplied buffer is too small.
FILES
/etc/shadow
local shadow password database file
The include file
<paths.h>
defines the constant
_PATH_SHADOW
to the pathname of the shadow password file.
CONFORMING TO
The shadow password database and its associated API are
not specified in POSIX.1-2001.
However, many other systems provide a similar API.
SEE ALSO