How do I get shadow passwords by uid?
My system uses the getsp* suite of routines to get the sensitive user
information. However I do not havegetspuid()
, only
getspnam()
. How do I work around this, and get by uid?
The work around is relatively painless. The following routine should go
straight into your personal utility library:
#include <stdlib.h>
#include <stdio.h>
#include <pwd.h>
#include <shadow.h>
struct spwd *getspuid(uid_t pw_uid)
{
struct spwd *shadow;
struct passwd *ppasswd;
if( ((ppasswd = getpwuid(pw_uid)) == NULL)
|| ((shadow = getspnam(ppasswd->pw_name)) == NULL))
return NULL;
return shadow;
}
The problem is, that some systems do not keep the uid, or other
information in the shadow database.
Home | FAQ |