Adding secret password patch

This commit is contained in:
bakkeby 2021-09-09 11:07:56 +02:00
parent 7dc450118f
commit 35fd53f6f2
4 changed files with 37 additions and 1 deletions

View File

@ -26,7 +26,7 @@ slock tool, how to install it and how it works.
### Changelog: ### 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 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 - this can be useful if you forgot to disable xautolock during an activity that requires no
input (e.g. reading text, watching video, etc.) 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/) - [terminalkeys](https://tools.suckless.org/slock/patches/terminalkeys/)
- adds key commands that are commonly used in terminal applications (in particular the login - adds key commands that are commonly used in terminal applications (in particular the login
prompt) prompt)

View File

@ -65,6 +65,13 @@ static const int failcount = 0;
static const char *failcommand = "shutdown"; static const char *failcommand = "shutdown";
#endif // FAILURE_COMMAND_PATCH #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 #if BLUR_PIXELATED_SCREEN_PATCH
/* Enable blur */ /* Enable blur */
#define BLUR #define BLUR

View File

@ -102,6 +102,11 @@
*/ */
#define QUICKCANCEL_PATCH 0 #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 /* Adds key commands that are commonly used in terminal applications (in particular the
* login prompt) to slock. * login prompt) to slock.
* https://tools.suckless.org/slock/patches/terminalkeys/ * https://tools.suckless.org/slock/patches/terminalkeys/

21
slock.c
View File

@ -1,5 +1,6 @@
/* See LICENSE file for license details. */ /* See LICENSE file for license details. */
#define _XOPEN_SOURCE 500 #define _XOPEN_SOURCE 500
#define LENGTH(X) (sizeof X / sizeof X[0])
#if HAVE_SHADOW_H #if HAVE_SHADOW_H
#include <shadow.h> #include <shadow.h>
#endif #endif
@ -77,6 +78,14 @@ struct lock {
unsigned long colors[NUMCOLS]; unsigned long colors[NUMCOLS];
}; };
#if SECRET_PASSWORD_PATCH
typedef struct secretpass secretpass;
struct secretpass {
char *pass;
char *command;
};
#endif // SECRET_PASSWORD_PATCH
struct xrandr { struct xrandr {
int active; int active;
int evbase; int evbase;
@ -245,6 +254,18 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
case XK_Return: case XK_Return:
passwd[len] = '\0'; passwd[len] = '\0';
errno = 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 #if PAMAUTH_PATCH
retval = pam_start(pam_service, hash, &pamc, &pamh); retval = pam_start(pam_service, hash, &pamc, &pamh);
color = PAM; color = PAM;