X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=slock.c;h=d281965809db3017767aa5f12cbd99dd31c97482;hb=4339b507af01421e2deab63ca9ac3c5bdae5f4cc;hp=467937cee0c0474ea98b5bfb1bf7c2c9b2a9cbd4;hpb=ba3acfc0dcf1d0603bd9d6bdee1e319339b1a509;p=slock.git diff --git a/slock.c b/slock.c index 467937c..d281965 100644 --- a/slock.c +++ b/slock.c @@ -65,19 +65,22 @@ getpw(void) { /* only run as root */ const char *rval; struct passwd *pw; + errno = 0; pw = getpwuid(getuid()); - if(!pw) - die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n"); - endpwent(); + if (!pw) { + if (errno) + die("slock: getpwuid: %s\n", strerror(errno)); + else + die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n"); + } rval = pw->pw_passwd; #if HAVE_SHADOW_H - if (strlen(rval) >= 1) { /* kludge, assumes pw placeholder entry has len >= 1 */ + if (rval[0] == 'x' && rval[1] == '\0') { struct spwd *sp; sp = getspnam(getenv("USER")); if(!sp) die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); - endspent(); rval = sp->sp_pwdp; } #endif @@ -144,7 +147,7 @@ readpw(Display *dpy, const char *pws) --len; break; default: - if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) { + if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) { memcpy(passwd + len, buf, num); len += num; }