X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=slock.c;h=face75e7e3e09ba96453e7fea5b6a9aef9c21c22;hb=66e31556db4921b5f24ced47dae5e1c7ea3bd150;hp=467937cee0c0474ea98b5bfb1bf7c2c9b2a9cbd4;hpb=ba3acfc0dcf1d0603bd9d6bdee1e319339b1a509;p=slock.git diff --git a/slock.c b/slock.c index 467937c..face75e 100644 --- a/slock.c +++ b/slock.c @@ -23,6 +23,8 @@ #include #endif +#include "config.h" + typedef struct { int screen; Window root, win; @@ -65,19 +67,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 +149,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; } @@ -256,7 +261,7 @@ main(int argc, char **argv) { int screen; if((argc == 2) && !strcmp("-v", argv[1])) - die("slock-%s, © 2006-2012 Anselm R Garbe\n", VERSION); + die("slock-%s, © 2006-2014 slock engineers\n", VERSION); else if(argc != 1) usage();