From 7dc450118fbc31a3a04568f814392870d616a615 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 9 Sep 2021 10:17:00 +0200 Subject: [PATCH] Adding failure-command patch --- README.md | 5 +++++ config.def.h | 9 +++++++++ patches.def.h | 5 +++++ slock.c | 10 ++++++++++ 4 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 9eb7c1d719c8286b075064150f2df1a0c499dd53..3e1779faaf18a03f84551f7c43cbd1d5b9f750cc 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ slock tool, how to install it and how it works. ### Changelog: +2021-09-09 - Added the failure-command patch + 2021-06-08 - Added the color message patch 2020-08-03 - Added alpha, keypress_feedback and blur_pixelated_screen patches @@ -64,6 +66,9 @@ slock tool, how to install it and how it works. - the monitor will automatically be activated by pressing a key or moving the mouse and the password can be entered then + - [failure-command](https://tools.suckless.org/slock/patches/failure-command/) + - allows for a command to be run after a specified number of incorrect attempts + - [keypress_feedback](https://tools.suckless.org/slock/patches/keypress-feedback/) - draws random blocks on the screen to display keypress feedback diff --git a/config.def.h b/config.def.h index ac9ec206660dbe5b8e82473e100058caf3abe28a..8ed45ace27cbf0f9fb2f1d9f78af1214f6fb13fd 100644 --- a/config.def.h +++ b/config.def.h @@ -56,6 +56,15 @@ static const float alpha = 0.9; /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; +#if FAILURE_COMMAND_PATCH +/* number of failed password attempts until failcommand is executed. + Set to 0 to disable */ +static const int failcount = 0; + +/* command to be executed after [failcount] failed password attempts */ +static const char *failcommand = "shutdown"; +#endif // FAILURE_COMMAND_PATCH + #if BLUR_PIXELATED_SCREEN_PATCH /* Enable blur */ #define BLUR diff --git a/patches.def.h b/patches.def.h index a9e8b3788c61914c4a43a8ad000fb2e248eca986..790427c7c9356a3123bd305b4922f9c129520128 100644 --- a/patches.def.h +++ b/patches.def.h @@ -60,6 +60,11 @@ */ #define DPMS_PATCH 0 +/* This patch allows for a command to be run after a specified number of incorrect attempts. + * https://tools.suckless.org/slock/patches/failure-command/ + */ +#define FAILURE_COMMAND_PATCH 0 + /* Draws random blocks on the screen to display keypress feedback. * https://tools.suckless.org/slock/patches/keypress-feedback/ * https://patch-diff.githubusercontent.com/raw/phenax/bslock/pull/2.diff diff --git a/slock.c b/slock.c index 5d03e2ddf37021942dbdc1e2b175457f2e88c65c..6f781ab135bd6c0d4bc248f64fe92d123a2770b8 100644 --- a/slock.c +++ b/slock.c @@ -43,6 +43,9 @@ #include "util.h" char *argv0; +#if FAILURE_COMMAND_PATCH +int failtrack = 0; +#endif // FAILURE_COMMAND_PATCH #if QUICKCANCEL_PATCH static time_t locktime; @@ -272,6 +275,13 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, if (running) { XBell(dpy, 100); failure = 1; + #if FAILURE_COMMAND_PATCH + failtrack++; + + if (failtrack >= failcount && failcount != 0) { + system(failcommand); + } + #endif // FAILURE_COMMAND_PATCH } explicit_bzero(&passwd, sizeof(passwd)); len = 0;