commit 35fd53f6f2f5c911532572e889333c4b43927afa
parent 7dc450118fbc31a3a04568f814392870d616a615
Author: bakkeby <bakkeby@gmail.com>
Date: Thu, 9 Sep 2021 11:07:56 +0200
Adding secret password patch
Diffstat:
4 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -26,7 +26,7 @@ slock tool, how to install it and how it works.
### Changelog:
-2021-09-09 - Added the failure-command patch
+2021-09-09 - Added the failure-command and secret-password patches
2021-06-08 - Added the color message patch
@@ -88,6 +88,9 @@ slock tool, how to install it and how it works.
- this can be useful if you forgot to disable xautolock during an activity that requires no
input (e.g. reading text, watching video, etc.)
+ - [secret-password](https://tools.suckless.org/slock/patches/secret-password/)
+ - allows for commands to be executed when the user enters special passwords
+
- [terminalkeys](https://tools.suckless.org/slock/patches/terminalkeys/)
- adds key commands that are commonly used in terminal applications (in particular the login
prompt)
diff --git a/config.def.h b/config.def.h
@@ -65,6 +65,13 @@ static const int failcount = 0;
static const char *failcommand = "shutdown";
#endif // FAILURE_COMMAND_PATCH
+#if SECRET_PASSWORD_PATCH
+static const secretpass scom[] = {
+ /* Password command */
+ { "shutdown", "doas poweroff"},
+};
+#endif // SECRET_PASSWORD_PATCH
+
#if BLUR_PIXELATED_SCREEN_PATCH
/* Enable blur */
#define BLUR
diff --git a/patches.def.h b/patches.def.h
@@ -102,6 +102,11 @@
*/
#define QUICKCANCEL_PATCH 0
+/* This patch allows for commands to be executed when the user enters special passwords.
+ * https://tools.suckless.org/slock/patches/secret-password/
+ */
+#define SECRET_PASSWORD_PATCH 0
+
/* Adds key commands that are commonly used in terminal applications (in particular the
* login prompt) to slock.
* https://tools.suckless.org/slock/patches/terminalkeys/
diff --git a/slock.c b/slock.c
@@ -1,5 +1,6 @@
/* See LICENSE file for license details. */
#define _XOPEN_SOURCE 500
+#define LENGTH(X) (sizeof X / sizeof X[0])
#if HAVE_SHADOW_H
#include <shadow.h>
#endif
@@ -77,6 +78,14 @@ struct lock {
unsigned long colors[NUMCOLS];
};
+#if SECRET_PASSWORD_PATCH
+typedef struct secretpass secretpass;
+struct secretpass {
+ char *pass;
+ char *command;
+};
+#endif // SECRET_PASSWORD_PATCH
+
struct xrandr {
int active;
int evbase;
@@ -245,6 +254,18 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
case XK_Return:
passwd[len] = '\0';
errno = 0;
+
+ #if SECRET_PASSWORD_PATCH
+ for (int i = 0; i < LENGTH(scom); i++) {
+ if (strcmp(scom[i].pass, passwd) == 0) {
+ system(scom[i].command);
+ #if FAILURE_COMMAND_PATCH
+ failtrack = -1;
+ #endif // FAILURE_COMMAND_PATCH
+ }
+ }
+ #endif // SECRET_PASSWORD_PATCH
+
#if PAMAUTH_PATCH
retval = pam_start(pam_service, hash, &pamc, &pamh);
color = PAM;