From 35fd53f6f2f5c911532572e889333c4b43927afa Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 9 Sep 2021 11:07:56 +0200 Subject: [PATCH] Adding secret password patch --- README.md | 5 ++++- config.def.h | 7 +++++++ patches.def.h | 5 +++++ slock.c | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e1779faaf18a03f84551f7c43cbd1d5b9f750cc..34f0e86bbc8126a716852b2d05b9d259d58aa879 100644 --- 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 index 8ed45ace27cbf0f9fb2f1d9f78af1214f6fb13fd..c009a752dbad843325d52bd6baba15cc483b5aae 100644 --- 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 index 790427c7c9356a3123bd305b4922f9c129520128..ff68ce80b56d2f4f708ba1db56ff3fcde4ea50ec 100644 --- 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 index 6f781ab135bd6c0d4bc248f64fe92d123a2770b8..bb8efa53d729799c4cd20f321e0186abc9e297f8 100644 --- 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 #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;