getspnam(3C)
NAME
getspnam, getspent, setspent, endspent, fgetspent − get password entry
SYNOPSIS
#include <shadow.h>
struct spwd ∗getspnam(const char ∗name);
struct spwd ∗getspent(void);
void setspent(void);
void endspent(void);
struct spwd ∗fgetspent(FILE ∗fp);
DESCRIPTION
getspent() and getspnam() each return a shadow password entry. The entry may come from one of the following sources: the shadow file (see shadow(4)), the NIS map “passwd.byname” and the NIS+ table “passwd”. The sources and their lookup order are the same as those used by getpwnam() and getpwent(); they are specified in the /etc/nsswitch.conf file (see getpwnam(3C) and nsswitch.conf(4)).
getspnam() searches for a shadow entry with a given login name.
getspent() enumerates shadow entries: successive calls to getspent() will return either successive shadow password entries or NULL. Enumeration may not be supported by some sources.
setspent() “rewinds” to the beginning of the enumeration of shadow entries. Calls to getspnam() may leave the enumeration in an indeterminate state, so setspent() should be called before the first getspent().
endspent() may be called to indicate that shadow processing is complete; the system may then close any open shadow file, deallocate storage, and so forth. It is legitimate, but possibly less efficient, to call more shadow password routines after endspent().
fgetspent(), unlike the routines above, does not use nsswitch.conf; it reads and parses the next line from the stream f, which is assumed to have the format of shadow(4).
The internal representation of a shadow password entry is a shadow structure defined in <shadow.h> with the following members:
char∗sp_namp;
char∗sp_pwdp;
longsp_lstchg;
longsp_min;
longsp_max;
longsp_warn;
longsp_inact;
longsp_expire;
unsigned longsp_flag;
RETURN VALUES
getspnam() returns a pointer to a struct shadow if it successfully locates the requested entry; otherwise it returns NULL.
getspent() and fgetspent() return a pointer to a struct shadow if they successfully enumerate an entry; otherwise they return NULL, indicating the end of the enumeration.
FILES
/etc/shadow
/etc/nsswitch.conf
/etc/passwd
SEE ALSO
passwd(1), getpwnam(3C), getlogin(3C), shadow(4), nsswitch.conf(4), passwd(4)
NOTES
All information is contained in a static area, so it must be copied if it is to be saved.
Use of the NIS map “passwd.byname” as a shadow entry source does not give the same amount of security and privacy that the shadow file offers. The passwd.byname map can store only the sp_namp and sp_pwdp fields of struct shadow and returns -1 for the rest of the fields. The NIS+ table “passwd” does not have any of these drawbacks; therefore, “nisplus” is preferred to “nis” as a password/shadow source. See shadow(4), passwd(4), and nsswitch.conf(4) for details.
Use of getspent() is deprecated; enumeration is well-defined for the passwd file and is supported (albeit inefficiently) for NIS and NIS+, but in general may not be well-defined. The semantics of enumeration are discussed in nsswitch.conf(4).
BUGS
Programs that call getspnam() routines cannot be linked statically since the implementation of these routines requires dynamic linker functionality to access shared objects at run time.
SunOS 5.1/SPARC — Last change: 24 Feb 1992