diff options
-rw-r--r-- | slock.c | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -85,9 +85,9 @@ dontkillme(void) | |||
85 | #endif | 85 | #endif |
86 | 86 | ||
87 | static const char * | 87 | static const char * |
88 | getpw(void) | 88 | gethash(void) |
89 | { | 89 | { |
90 | const char *rval; | 90 | const char *hash; |
91 | struct passwd *pw; | 91 | struct passwd *pw; |
92 | 92 | ||
93 | /* Check if the current user has a password entry */ | 93 | /* Check if the current user has a password entry */ |
@@ -98,35 +98,35 @@ getpw(void) | |||
98 | else | 98 | else |
99 | die("slock: cannot retrieve password entry\n"); | 99 | die("slock: cannot retrieve password entry\n"); |
100 | } | 100 | } |
101 | rval = pw->pw_passwd; | 101 | hash = pw->pw_passwd; |
102 | 102 | ||
103 | #if HAVE_SHADOW_H | 103 | #if HAVE_SHADOW_H |
104 | if (rval[0] == 'x' && rval[1] == '\0') { | 104 | if (hash[0] == 'x' && hash[1] == '\0') { |
105 | struct spwd *sp; | 105 | struct spwd *sp; |
106 | if (!(sp = getspnam(getenv("USER")))) | 106 | if (!(sp = getspnam(getenv("USER")))) |
107 | die("slock: getspnam: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); | 107 | die("slock: getspnam: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); |
108 | rval = sp->sp_pwdp; | 108 | hash = sp->sp_pwdp; |
109 | } | 109 | } |
110 | #else | 110 | #else |
111 | if (rval[0] == '*' && rval[1] == '\0') { | 111 | if (hash[0] == '*' && hash[1] == '\0') { |
112 | #ifdef __OpenBSD__ | 112 | #ifdef __OpenBSD__ |
113 | if (!(pw = getpwnam_shadow(getenv("USER")))) | 113 | if (!(pw = getpwnam_shadow(getenv("USER")))) |
114 | die("slock: getpwnam_shadow: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); | 114 | die("slock: getpwnam_shadow: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); |
115 | rval = pw->pw_passwd; | 115 | hash = pw->pw_passwd; |
116 | #else | 116 | #else |
117 | die("slock: getpwuid: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); | 117 | die("slock: getpwuid: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); |
118 | #endif /* __OpenBSD__ */ | 118 | #endif /* __OpenBSD__ */ |
119 | } | 119 | } |
120 | #endif /* HAVE_SHADOW_H */ | 120 | #endif /* HAVE_SHADOW_H */ |
121 | 121 | ||
122 | return rval; | 122 | return hash; |
123 | } | 123 | } |
124 | 124 | ||
125 | static void | 125 | static void |
126 | readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, | 126 | readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, |
127 | const char *pws) | 127 | const char *hash) |
128 | { | 128 | { |
129 | char buf[32], passwd[256], *encrypted; | 129 | char buf[32], passwd[256], *inputhash; |
130 | int num, screen, running, failure; | 130 | int num, screen, running, failure; |
131 | unsigned int len, color; | 131 | unsigned int len, color; |
132 | KeySym ksym; | 132 | KeySym ksym; |
@@ -161,10 +161,10 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, | |||
161 | case XK_Return: | 161 | case XK_Return: |
162 | passwd[len] = 0; | 162 | passwd[len] = 0; |
163 | errno = 0; | 163 | errno = 0; |
164 | if (!(encrypted = crypt(passwd, pws))) | 164 | if (!(inputhash = crypt(passwd, hash))) |
165 | fprintf(stderr, "slock: crypt: %s\n", strerror(errno)); | 165 | fprintf(stderr, "slock: crypt: %s\n", strerror(errno)); |
166 | else | 166 | else |
167 | running = !!strcmp(encrypted, pws); | 167 | running = !!strcmp(inputhash, hash); |
168 | if (running) { | 168 | if (running) { |
169 | XBell(dpy, 100); | 169 | XBell(dpy, 100); |
170 | failure = True; | 170 | failure = True; |
@@ -292,7 +292,7 @@ main(int argc, char **argv) { | |||
292 | struct group *grp; | 292 | struct group *grp; |
293 | uid_t duid; | 293 | uid_t duid; |
294 | gid_t dgid; | 294 | gid_t dgid; |
295 | const char *pws; | 295 | const char *hash; |
296 | Display *dpy; | 296 | Display *dpy; |
297 | int s, nlocks, nscreens; | 297 | int s, nlocks, nscreens; |
298 | 298 | ||
@@ -320,8 +320,8 @@ main(int argc, char **argv) { | |||
320 | dontkillme(); | 320 | dontkillme(); |
321 | #endif | 321 | #endif |
322 | 322 | ||
323 | pws = getpw(); | 323 | hash = gethash(); |
324 | if (strlen(pws) < 2) | 324 | if (strlen(hash) < 2) |
325 | die("slock: failed to get user password hash.\n"); | 325 | die("slock: failed to get user password hash.\n"); |
326 | 326 | ||
327 | if (!(dpy = XOpenDisplay(NULL))) | 327 | if (!(dpy = XOpenDisplay(NULL))) |
@@ -370,7 +370,7 @@ main(int argc, char **argv) { | |||
370 | } | 370 | } |
371 | 371 | ||
372 | /* everything is now blank. Wait for the correct password */ | 372 | /* everything is now blank. Wait for the correct password */ |
373 | readpw(dpy, &rr, locks, nscreens, pws); | 373 | readpw(dpy, &rr, locks, nscreens, hash); |
374 | 374 | ||
375 | return 0; | 375 | return 0; |
376 | } | 376 | } |