I have done two patches for slock.
The first simplifying the use of cpp and the other adding user defined password.
feel free to modify, test, commit or adapt those patches into mainstream if you
like.
--pancake
diff -r 4d3769ac5d02 -r 69b727153929 slock.c
--- a/slock.c Thu Nov 26 12:53:26 2009 +0000
+++ b/slock.c Sat Dec 19 21:15:20 2009 +0100
@@ -44,26 +44,22 @@
exit(EXIT_FAILURE);
}
-#ifndef HAVE_BSD_AUTH
+#ifdef HAVE_SHADOW_H
static const char *
get_password(void) { /* only run as root */
const char *rval;
struct passwd *pw;
+ struct spwd *sp;
if(geteuid() != 0)
die("cannot retrieve password entry (make sure to suid slock)");
pw = getpwuid(getuid());
endpwent();
- rval = pw->pw_passwd;
+ rval = pw->pw_passwd;
-#if HAVE_SHADOW_H
- {
- struct spwd *sp;
- sp = getspnam(getenv("USER"));
- endspent();
- rval = sp->sp_pwdp;
- }
-#endif
+ sp = getspnam(getenv("USER"));
+ endspent();
+ rval = sp->sp_pwdp;
/* drop privileges */
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
@@ -73,11 +69,7 @@
#endif
static void
-#ifdef HAVE_BSD_AUTH
-read_password(Display *dpy)
-#else
read_password(Display *dpy, const char *pws)
-#endif
{
char buf[32], passwd[256];
int num;
@@ -215,9 +207,7 @@
int
main(int argc, char **argv) {
-#ifndef HAVE_BSD_AUTH
- const char *pws;
-#endif
+ const char *pws = NULL;
Display *dpy;
int nscreens, screen;
@@ -247,11 +237,7 @@
XSync(dpy, False);
/* Everything is now blank. Now wait for the correct password. */
-#ifdef HAVE_BSD_AUTH
- read_password(dpy);
-#else
read_password(dpy, pws);
-#endif
/* Password ok, unlock everything and quit. */
for (screen = 0; screen < nscreens; screen++)
diff -r 69b727153929 -r 2984d3edbdfd config.mk
--- a/config.mk Sat Dec 19 21:15:20 2009 +0100
+++ b/config.mk Sat Dec 19 21:21:34 2009 +0100
@@ -3,6 +3,11 @@
# Customize below to fit your system
+# password to use instead of system one
+PASSWORD = 123
+#AUTHMODE = -DHAVE_SHADOW_H
+#AUTHMODE = -DHAVE_BSD_AUTH
+
# paths
PREFIX = /usr/local
@@ -14,13 +19,10 @@
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext
# flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H
+CPPFLAGS = -DVERSION=\"${VERSION}\" -DPASSWORD=\"${PASSWORD}\" ${AUTHMODE}
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS}
-# On *BSD remove -DHAVE_SHADOW_H from CPPFLAGS and add -DHAVE_BSD_AUTH
-# On OpenBSD and Darwin remove -lcrypt from LIBS
-
# compiler and linker
CC = cc
diff -r 69b727153929 -r 2984d3edbdfd slock.c
--- a/slock.c Sat Dec 19 21:15:20 2009 +0100
+++ b/slock.c Sat Dec 19 21:21:34 2009 +0100
@@ -106,8 +106,10 @@
passwd[len] = 0;
#ifdef HAVE_BSD_AUTH
running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
+#elif HAVE_SHADOW_H
+ running = strcmp(crypt(passwd, pws), pws);
#else
- running = strcmp(crypt(passwd, pws), pws);
+ running = strcmp(passwd, pws);
#endif
if (running != 0)
XBell(dpy, 100);
@@ -207,7 +209,7 @@
int
main(int argc, char **argv) {
- const char *pws = NULL;
+ const char *pws = PASSWORD;
Display *dpy;
int nscreens, screen;
@@ -218,7 +220,7 @@
else if(argc != 1)
usage();
-#ifndef HAVE_BSD_AUTH
+#ifdef HAVE_SHADOW_H
pws = get_password();
#endif