slock-custom-password-1.5.diff (4440B)
1 diff --git a/Makefile b/Makefile 2 index b20fd4e..bbbf83f 100644 3 --- a/Makefile 4 +++ b/Makefile 5 @@ -6,17 +6,18 @@ include config.mk 6 SRC = slock.c ${COMPATSRC} 7 OBJ = ${SRC:.c=.o} 8 9 -all: options slock 10 +all: options clean slock 11 12 options: 13 @echo slock build options: 14 @echo "CFLAGS = ${CFLAGS}" 15 @echo "LDFLAGS = ${LDFLAGS}" 16 @echo "CC = ${CC}" 17 + @echo "DEFINES = ${DEFINES}" 18 19 .c.o: 20 @echo CC $< 21 - @${CC} -c ${CFLAGS} $< 22 + @${CC} -c ${CFLAGS} ${DEFINES} $< 23 24 ${OBJ}: config.h config.mk arg.h util.h 25 26 @@ -25,6 +26,10 @@ config.h: 27 @cp config.def.h $@ 28 29 slock: ${OBJ} 30 + @if [ -z ${PW} ]; then \ 31 + echo "Define password when running make! Example: 'make PW=xyz'"; \ 32 + exit 1; \ 33 + fi 34 @echo CC -o $@ 35 @${CC} -o $@ ${OBJ} ${LDFLAGS} 36 37 @@ -41,7 +46,7 @@ dist: clean 38 @gzip slock-${VERSION}.tar 39 @rm -rf slock-${VERSION} 40 41 -install: all 42 +install: options slock 43 @echo installing executable file to ${DESTDIR}${PREFIX}/bin 44 @mkdir -p ${DESTDIR}${PREFIX}/bin 45 @cp -f slock ${DESTDIR}${PREFIX}/bin 46 diff --git a/config.mk b/config.mk 47 index 1e1ca45..75ee770 100644 48 --- a/config.mk 49 +++ b/config.mk 50 @@ -12,16 +12,15 @@ X11LIB = /usr/X11R6/lib 51 52 # includes and libs 53 INCS = -I. -I/usr/include -I${X11INC} 54 -LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr 55 +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXext -lXrandr 56 57 # flags 58 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H 59 CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} 60 LDFLAGS = -s ${LIBS} 61 +DEFINES += -DPW=\"${PW}\" 62 COMPATSRC = explicit_bzero.c 63 64 -# On OpenBSD and Darwin remove -lcrypt from LIBS 65 -#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXext -lXrandr 66 # On *BSD remove -DHAVE_SHADOW_H from CPPFLAGS 67 # On NetBSD add -D_NETBSD_SOURCE to CPPFLAGS 68 #CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE 69 diff --git a/slock.c b/slock.c 70 index 5ae738c..b78e14a 100644 71 --- a/slock.c 72 +++ b/slock.c 73 @@ -83,53 +83,11 @@ dontkillme(void) 74 } 75 #endif 76 77 -static const char * 78 -gethash(void) 79 -{ 80 - const char *hash; 81 - struct passwd *pw; 82 - 83 - /* Check if the current user has a password entry */ 84 - errno = 0; 85 - if (!(pw = getpwuid(getuid()))) { 86 - if (errno) 87 - die("slock: getpwuid: %s\n", strerror(errno)); 88 - else 89 - die("slock: cannot retrieve password entry\n"); 90 - } 91 - hash = pw->pw_passwd; 92 - 93 -#if HAVE_SHADOW_H 94 - if (!strcmp(hash, "x")) { 95 - struct spwd *sp; 96 - if (!(sp = getspnam(pw->pw_name))) 97 - die("slock: getspnam: cannot retrieve shadow entry. " 98 - "Make sure to suid or sgid slock.\n"); 99 - hash = sp->sp_pwdp; 100 - } 101 -#else 102 - if (!strcmp(hash, "*")) { 103 -#ifdef __OpenBSD__ 104 - if (!(pw = getpwuid_shadow(getuid()))) 105 - die("slock: getpwnam_shadow: cannot retrieve shadow entry. " 106 - "Make sure to suid or sgid slock.\n"); 107 - hash = pw->pw_passwd; 108 -#else 109 - die("slock: getpwuid: cannot retrieve shadow entry. " 110 - "Make sure to suid or sgid slock.\n"); 111 -#endif /* __OpenBSD__ */ 112 - } 113 -#endif /* HAVE_SHADOW_H */ 114 - 115 - return hash; 116 -} 117 - 118 static void 119 -readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 120 - const char *hash) 121 +readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens) 122 { 123 XRRScreenChangeNotifyEvent *rre; 124 - char buf[32], passwd[256], *inputhash; 125 + char buf[32], passwd[256]; 126 int num, screen, running, failure, oldc; 127 unsigned int len, color; 128 KeySym ksym; 129 @@ -159,11 +117,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 130 switch (ksym) { 131 case XK_Return: 132 passwd[len] = '\0'; 133 - errno = 0; 134 - if (!(inputhash = crypt(passwd, hash))) 135 - fprintf(stderr, "slock: crypt: %s\n", strerror(errno)); 136 - else 137 - running = !!strcmp(inputhash, hash); 138 + running = !!strcmp(passwd, PW ); 139 if (running) { 140 XBell(dpy, 100); 141 failure = 1; 142 @@ -311,7 +265,6 @@ main(int argc, char **argv) { 143 struct group *grp; 144 uid_t duid; 145 gid_t dgid; 146 - const char *hash; 147 Display *dpy; 148 int s, nlocks, nscreens; 149 150 @@ -339,10 +292,7 @@ main(int argc, char **argv) { 151 dontkillme(); 152 #endif 153 154 - hash = gethash(); 155 errno = 0; 156 - if (!crypt("", hash)) 157 - die("slock: crypt: %s\n", strerror(errno)); 158 159 if (!(dpy = XOpenDisplay(NULL))) 160 die("slock: cannot open display\n"); 161 @@ -389,7 +339,7 @@ main(int argc, char **argv) { 162 } 163 164 /* everything is now blank. Wait for the correct password */ 165 - readpw(dpy, &rr, locks, nscreens, hash); 166 + readpw(dpy, &rr, locks, nscreens); 167 168 return 0; 169 }