sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 8803ffc878e4523ef36825f3dbdae97a2b850fed
parent 2dd296e1552dc4012749a3b240c90a84e494345f
Author: Max Schillinger <maxschillinger@web.de>
Date:   Sun,  2 Apr 2023 15:28:12 +0200

[slock][patch][custom_password] Add custom password patch

This patch allows you to set a custom password during compilation
instead of using the system login password. This gives you much faster
response on systems without a local user (depending on PAM
authentication).

Diffstat:
Atools.suckless.org/slock/patches/custom-password/index.md | 14++++++++++++++
Atools.suckless.org/slock/patches/custom-password/slock-custom-password-1.5.diff | 169+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 183 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/slock/patches/custom-password/index.md b/tools.suckless.org/slock/patches/custom-password/index.md @@ -0,0 +1,14 @@ +Custom Password +=============== + +Description +----------- +This patch allows you to set a password (only for slock) during compilation. Set your password when runninng make. Example: `make PW=xyz`. + +Download +-------- +* [slock-custom-password-1.5.diff](slock-custom-password-1.5.diff) + +Author +------ +* Max Schillinger - <maxschillinger@web.de> diff --git a/tools.suckless.org/slock/patches/custom-password/slock-custom-password-1.5.diff b/tools.suckless.org/slock/patches/custom-password/slock-custom-password-1.5.diff @@ -0,0 +1,169 @@ +diff --git a/Makefile b/Makefile +index b20fd4e..bbbf83f 100644 +--- a/Makefile ++++ b/Makefile +@@ -6,17 +6,18 @@ include config.mk + SRC = slock.c ${COMPATSRC} + OBJ = ${SRC:.c=.o} + +-all: options slock ++all: options clean slock + + options: + @echo slock build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" ++ @echo "DEFINES = ${DEFINES}" + + .c.o: + @echo CC $< +- @${CC} -c ${CFLAGS} $< ++ @${CC} -c ${CFLAGS} ${DEFINES} $< + + ${OBJ}: config.h config.mk arg.h util.h + +@@ -25,6 +26,10 @@ config.h: + @cp config.def.h $@ + + slock: ${OBJ} ++ @if [ -z ${PW} ]; then \ ++ echo "Define password when running make! Example: 'make PW=xyz'"; \ ++ exit 1; \ ++ fi + @echo CC -o $@ + @${CC} -o $@ ${OBJ} ${LDFLAGS} + +@@ -41,7 +46,7 @@ dist: clean + @gzip slock-${VERSION}.tar + @rm -rf slock-${VERSION} + +-install: all ++install: options slock + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + @mkdir -p ${DESTDIR}${PREFIX}/bin + @cp -f slock ${DESTDIR}${PREFIX}/bin +diff --git a/config.mk b/config.mk +index 1e1ca45..75ee770 100644 +--- a/config.mk ++++ b/config.mk +@@ -12,16 +12,15 @@ X11LIB = /usr/X11R6/lib + + # includes and libs + INCS = -I. -I/usr/include -I${X11INC} +-LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr ++LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXext -lXrandr + + # flags + CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H + CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} + LDFLAGS = -s ${LIBS} ++DEFINES += -DPW=\"${PW}\" + COMPATSRC = explicit_bzero.c + +-# On OpenBSD and Darwin remove -lcrypt from LIBS +-#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXext -lXrandr + # On *BSD remove -DHAVE_SHADOW_H from CPPFLAGS + # On NetBSD add -D_NETBSD_SOURCE to CPPFLAGS + #CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE +diff --git a/slock.c b/slock.c +index 5ae738c..b78e14a 100644 +--- a/slock.c ++++ b/slock.c +@@ -83,53 +83,11 @@ dontkillme(void) + } + #endif + +-static const char * +-gethash(void) +-{ +- const char *hash; +- struct passwd *pw; +- +- /* Check if the current user has a password entry */ +- errno = 0; +- if (!(pw = getpwuid(getuid()))) { +- if (errno) +- die("slock: getpwuid: %s\n", strerror(errno)); +- else +- die("slock: cannot retrieve password entry\n"); +- } +- hash = pw->pw_passwd; +- +-#if HAVE_SHADOW_H +- if (!strcmp(hash, "x")) { +- struct spwd *sp; +- if (!(sp = getspnam(pw->pw_name))) +- die("slock: getspnam: cannot retrieve shadow entry. " +- "Make sure to suid or sgid slock.\n"); +- hash = sp->sp_pwdp; +- } +-#else +- if (!strcmp(hash, "*")) { +-#ifdef __OpenBSD__ +- if (!(pw = getpwuid_shadow(getuid()))) +- die("slock: getpwnam_shadow: cannot retrieve shadow entry. " +- "Make sure to suid or sgid slock.\n"); +- hash = pw->pw_passwd; +-#else +- die("slock: getpwuid: cannot retrieve shadow entry. " +- "Make sure to suid or sgid slock.\n"); +-#endif /* __OpenBSD__ */ +- } +-#endif /* HAVE_SHADOW_H */ +- +- return hash; +-} +- + static void +-readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, +- const char *hash) ++readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens) + { + XRRScreenChangeNotifyEvent *rre; +- char buf[32], passwd[256], *inputhash; ++ char buf[32], passwd[256]; + int num, screen, running, failure, oldc; + unsigned int len, color; + KeySym ksym; +@@ -159,11 +117,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, + switch (ksym) { + case XK_Return: + passwd[len] = '\0'; +- errno = 0; +- if (!(inputhash = crypt(passwd, hash))) +- fprintf(stderr, "slock: crypt: %s\n", strerror(errno)); +- else +- running = !!strcmp(inputhash, hash); ++ running = !!strcmp(passwd, PW ); + if (running) { + XBell(dpy, 100); + failure = 1; +@@ -311,7 +265,6 @@ main(int argc, char **argv) { + struct group *grp; + uid_t duid; + gid_t dgid; +- const char *hash; + Display *dpy; + int s, nlocks, nscreens; + +@@ -339,10 +292,7 @@ main(int argc, char **argv) { + dontkillme(); + #endif + +- hash = gethash(); + errno = 0; +- if (!crypt("", hash)) +- die("slock: crypt: %s\n", strerror(errno)); + + if (!(dpy = XOpenDisplay(NULL))) + die("slock: cannot open display\n"); +@@ -389,7 +339,7 @@ main(int argc, char **argv) { + } + + /* everything is now blank. Wait for the correct password */ +- readpw(dpy, &rr, locks, nscreens, hash); ++ readpw(dpy, &rr, locks, nscreens); + + return 0; + }