[wiki] [sites] [slock][patch][custom_password] Add custom password patch || Max Schillinger
commit 8803ffc878e4523ef36825f3dbdae97a2b850fed
Author: Max Schillinger <maxschillinger_AT_web.de>
Date: Sun Apr 2 15:28:12 2023 +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).
diff --git a/tools.suckless.org/slock/patches/custom-password/index.md b/tools.suckless.org/slock/patches/custom-password/index.md
new file mode 100644
index 00000000..394be5d6
--- /dev/null
+++ b/tools.suckless.org/slock/patches/custom-password/index.md
_AT_@ -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_AT_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
new file mode 100644
index 00000000..87c5f1e2
--- /dev/null
+++ b/tools.suckless.org/slock/patches/custom-password/slock-custom-password-1.5.diff
_AT_@ -0,0 +1,169 @@
+diff --git a/Makefile b/Makefile
+index b20fd4e..bbbf83f 100644
+--- a/Makefile
++++ b/Makefile
+_AT_@ -6,17 +6,18 @@ include config.mk
+ SRC = slock.c ${COMPATSRC}
+ OBJ = ${SRC:.c=.o}
+
+-all: options slock
++all: options clean slock
+
+ options:
+ _AT_echo slock build options:
+ _AT_echo "CFLAGS = ${CFLAGS}"
+ _AT_echo "LDFLAGS = ${LDFLAGS}"
+ _AT_echo "CC = ${CC}"
++ _AT_echo "DEFINES = ${DEFINES}"
+
+ .c.o:
+ _AT_echo CC $<
+- _AT_${CC} -c ${CFLAGS} $<
++ _AT_${CC} -c ${CFLAGS} ${DEFINES} $<
+
+ ${OBJ}: config.h config.mk arg.h util.h
+
+_AT_@ -25,6 +26,10 @@ config.h:
+ _AT_cp config.def.h $@
+
+ slock: ${OBJ}
++ _AT_if [ -z ${PW} ]; then \
++ echo "Define password when running make! Example: 'make PW=xyz'"; \
++ exit 1; \
++ fi
+ _AT_echo CC -o $@
+ _AT_${CC} -o $@ ${OBJ} ${LDFLAGS}
+
+_AT_@ -41,7 +46,7 @@ dist: clean
+ _AT_gzip slock-${VERSION}.tar
+ _AT_rm -rf slock-${VERSION}
+
+-install: all
++install: options slock
+ _AT_echo installing executable file to ${DESTDIR}${PREFIX}/bin
+ _AT_mkdir -p ${DESTDIR}${PREFIX}/bin
+ _AT_cp -f slock ${DESTDIR}${PREFIX}/bin
+diff --git a/config.mk b/config.mk
+index 1e1ca45..75ee770 100644
+--- a/config.mk
++++ b/config.mk
+_AT_@ -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
+_AT_@ -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
", strerror(errno));
+- else
+- die("slock: cannot retrieve password entry
");
+- }
+- 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.
");
+- 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.
");
+- hash = pw->pw_passwd;
+-#else
+- die("slock: getpwuid: cannot retrieve shadow entry. "
+- "Make sure to suid or sgid slock.
");
+-#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;
+_AT_@ -159,11 +117,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ switch (ksym) {
+ case XK_Return:
+ passwd[len] = '+- errno = 0;
+- if (!(inputhash = crypt(passwd, hash)))
+- fprintf(stderr, "slock: crypt: %s
", strerror(errno));
+- else
+- running = !!strcmp(inputhash, hash);
++ running = !!strcmp(passwd, PW );
+ if (running) {
+ XBell(dpy, 100);
+ failure = 1;
+_AT_@ -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;
+
+_AT_@ -339,10 +292,7 @@ main(int argc, char **argv) {
+ dontkillme();
+ #endif
+
+- hash = gethash();
+ errno = 0;
+- if (!crypt("", hash))
+- die("slock: crypt: %s
", strerror(errno));
+
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("slock: cannot open display
");
+_AT_@ -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;
+ }
Received on Sun Apr 02 2023 - 15:35:11 CEST
This archive was generated by hypermail 2.3.0
: Sun Apr 02 2023 - 15:36:50 CEST