SHADOW(3)
πΈ SHADOW πΈ
bestie we're doing Library Calls today, and this one is literally the encrypted password file routines page π aka shadow and getspnam β yes those ones. the ones that touch the sacred text (/etc/shadow) π
β¨ NAME β¨
shadow, getspnam β encrypted password file routines π
π SYNTAX π
okay so first you gotta pull in the header, standard behavior:
#include <shadow.h>
struct spwd *getspent();
struct spwd *getspnam(char *name);
void setspent();
void endspent();
struct spwd *fgetspent(FILE *fp);
struct spwd *sgetspent(char *cp);
int putspent(struct spwd *p, FILE *fp);
int lckpwdf();
int ulckpwdf();
π DESCRIPTION π
so shadow is the little gremlin that manipulates the contents of the shadow password file, /etc/shadow. and the struct in the #include file? it's giving:
struct spwd {
char *sp_namp; /* user login name */
char *sp_pwdp; /* encrypted password */
long int sp_lstchg; /* last password change */
long int sp_min; /* days until change allowed. */
long int sp_max; /* days before change required */
long int sp_warn; /* days warning for expiration */
long int sp_inact; /* days before account inactive */
long int sp_expire; /* date when account expires */
unsigned long int sp_flag; /* reserved for future use */
}
and the meanings of each field, one by one, no skips:
sp_namp- pointer to null-terminated user namesp_pwdp- pointer to null-terminated passwordsp_lstchg- days since Jan 1, 1970 password was last changedsp_min- days before which password may not be changedsp_max- days after which password must be changedsp_warn- days before password is to expire that user is warned of pending password expirationsp_inact- days after password expires that account is considered inactive and disabledsp_expire- days since Jan 1, 1970 when account will be disabledsp_flag- reserved for future use
π DESCRIPTION (part two, the functions) π
not me writing two DESCRIPTION sections, but that's literally what the page does so we're doing it π
getspent, getspname, fgetspent, and sgetspent each return a pointer to a struct spwd. breaking it down:
getspentreturns the next entry from the file πfgetspentreturns the next entry from the given stream, which is assumed to be a file of the proper formatsgetspentreturns a pointer to astruct spwdusing the provided string as inputgetspnamsearches from the current position in the file for an entry matching name π
setspent and endspent may be used to begin and end, respectively, access to the shadow password file. open and close, the way that duo is supposed to work π«Ά
the lckpwdf and ulckpwdf routines should be used to insure exclusive access to the /etc/shadow file. lckpwdf attempts to acquire a lock using pw_lock for up to 15 seconds. it continues by attempting to acquire a second lock using spw_lock for the remainder of the initial 15 seconds. should either attempt fail after a total of 15 seconds, lckpwdf returns -1. when both locks are acquired 0 is returned β¨
lowkey dramatic but the lock window is real: 15 seconds total,-1if either attempt fails,0when both locks are yours π
π©Ί DIAGNOSTICS π©Ί
routines return NULL if no more entries are available or if an error occurs during processing. routines which have int as the return value return 0 for success and -1 for failure. that's it, that's the whole vibe check π
β οΈ CAVEATS β οΈ
these routines may only be used by the superuser as access to the shadow password file is restricted. so if you're not root, bestie, you're not getting in π no cap.
π FILES π
/etc/shadowβ secure user account information. π
π SEE ALSO π
and that's the whole page, periodt π
go forth and read your shadow entries responsibly. this was shadow-utils 4.20.0, dated 07/30/2026 β mwah, bye bestie ππ¦β¨
π¦ where this page comes from
- arch rolling: shadow 4.20.0.arch1-1 Β· 0BSD AND BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms