diff options
| -rw-r--r-- | config.mk | 5 | ||||
| -rw-r--r-- | slock.c | 22 | 
2 files changed, 25 insertions, 2 deletions
| @@ -15,11 +15,14 @@ INCS = -I. -I/usr/include -I${X11INC} | |||
| 15 | LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 | 15 | LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 | 
| 16 | 16 | ||
| 17 | # flags | 17 | # flags | 
| 18 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" | 18 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H | 
| 19 | LDFLAGS = ${LIBS} | 19 | LDFLAGS = ${LIBS} | 
| 20 | #CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" | 20 | #CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" | 
| 21 | #LDFLAGS = -g ${LIBS} | 21 | #LDFLAGS = -g ${LIBS} | 
| 22 | 22 | ||
| 23 | # On *BSD remove -DHAVE_SHADOW_H from CFLAGS | ||
| 24 | # On OpenBSD remove -lcrypt from LIBS | ||
| 25 | |||
| 23 | # compiler and linker | 26 | # compiler and linker | 
| 24 | CC = cc | 27 | CC = cc | 
| 25 | LD = ${CC} | 28 | LD = ${CC} | 
| @@ -2,7 +2,13 @@ | |||
| 2 | * See LICENSE file for license details. | 2 | * See LICENSE file for license details. | 
| 3 | */ | 3 | */ | 
| 4 | #define _XOPEN_SOURCE | 4 | #define _XOPEN_SOURCE | 
| 5 | |||
| 6 | #if HAVE_SHADOW_H | ||
| 5 | #include <shadow.h> | 7 | #include <shadow.h> | 
| 8 | #else | ||
| 9 | #include <pwd.h> | ||
| 10 | #endif | ||
| 11 | |||
| 6 | #include <stdlib.h> | 12 | #include <stdlib.h> | 
| 7 | #include <stdio.h> | 13 | #include <stdio.h> | 
| 8 | #include <string.h> | 14 | #include <string.h> | 
| @@ -17,7 +23,11 @@ main(int argc, char **argv) { | |||
| 17 | char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; | 23 | char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; | 
| 18 | char buf[32], passwd[256]; | 24 | char buf[32], passwd[256]; | 
| 19 | int num, prev_nitem, screen; | 25 | int num, prev_nitem, screen; | 
| 26 | #if HAVE_SHADOW_H | ||
| 20 | struct spwd *sp; | 27 | struct spwd *sp; | 
| 28 | #else | ||
| 29 | struct passwd *pw; | ||
| 30 | #endif | ||
| 21 | unsigned int i, len; | 31 | unsigned int i, len; | 
| 22 | Bool running = True; | 32 | Bool running = True; | 
| 23 | Cursor invisible; | 33 | Cursor invisible; | 
| @@ -33,11 +43,17 @@ main(int argc, char **argv) { | |||
| 33 | fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); | 43 | fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); | 
| 34 | exit(EXIT_SUCCESS); | 44 | exit(EXIT_SUCCESS); | 
| 35 | } | 45 | } | 
| 36 | if(!(sp = getspnam(getenv("USER")))) { | 46 | if(geteuid() != 0) { | 
| 37 | fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr); | 47 | fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr); | 
| 38 | exit(EXIT_FAILURE); | 48 | exit(EXIT_FAILURE); | 
| 39 | } | 49 | } | 
| 50 | #if HAVE_SHADOW_H | ||
| 51 | sp = getspnam(getenv("USER")); | ||
| 40 | endspent(); | 52 | endspent(); | 
| 53 | #else | ||
| 54 | pw = getpwuid(getuid()); | ||
| 55 | endpwent(); | ||
| 56 | #endif | ||
| 41 | if(!(dpy = XOpenDisplay(0))) { | 57 | if(!(dpy = XOpenDisplay(0))) { | 
| 42 | fputs("slock: cannot open display\n", stderr); | 58 | fputs("slock: cannot open display\n", stderr); | 
| 43 | exit(EXIT_FAILURE); | 59 | exit(EXIT_FAILURE); | 
| @@ -87,7 +103,11 @@ main(int argc, char **argv) { | |||
| 87 | } | 103 | } | 
| 88 | switch(ksym) { | 104 | switch(ksym) { | 
| 89 | case XK_Return: | 105 | case XK_Return: | 
| 106 | #if HAVE_SHADOW_H | ||
| 90 | if((running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd)))) | 107 | if((running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd)))) | 
| 108 | #else | ||
| 109 | if((running = strncmp(crypt(passwd, pw->pw_passwd), pw->pw_passwd, sizeof(passwd)))) | ||
| 110 | #endif | ||
| 91 | XBell(dpy, 100); | 111 | XBell(dpy, 100); | 
| 92 | passwd[0] = 0; | 112 | passwd[0] = 0; | 
| 93 | break; | 113 | break; | 
