#if HAVE_SHADOW_H #include #endif #include #include #include #include #include #include #include "util.h" static const char *get_hash(); const char * get_hash() { const char *hash; struct passwd *pw; /* Check if the current user has a password entry */ errno = 0; if (!(pw = getpwuid(getuid()))) { if (errno) die("slock: getpwuid: %s\n", strerror(errno)); else die("slock: cannot retrieve password entry\n"); } hash = pw->pw_passwd; #if HAVE_SHADOW_H if (!strcmp(hash, "x")) { struct spwd *sp; if (!(sp = getspnam(pw->pw_name))) die("slock: getspnam: cannot retrieve shadow entry. " "Make sure to suid or sgid slock.\n"); hash = sp->sp_pwdp; } #else if (!strcmp(hash, "*")) { #ifdef __OpenBSD__ if (!(pw = getpwuid_shadow(getuid()))) die("slock: getpwnam_shadow: cannot retrieve shadow entry. " "Make sure to suid or sgid slock.\n"); hash = pw->pw_passwd; #else die("slock: getpwuid: cannot retrieve shadow entry. " "Make sure to suid or sgid slock.\n"); #endif /* __OpenBSD__ */ } #endif /* HAVE_SHADOW_H */ return hash; }