From 1dc51b30189d506d7948c7c00397cdad35e2180e Mon Sep 17 00:00:00 2001 From: tiyn Date: Sun, 29 Oct 2023 03:08:13 +0100 Subject: [PATCH] cleanup --- config.def.h | 16 ++++++++++------ slock.c | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config.def.h b/config.def.h index 052b5ab..14bb3f0 100644 --- a/config.def.h +++ b/config.def.h @@ -11,13 +11,17 @@ static const char *colorname[NUMCOLS] = { /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; -/* length of entries in scom */ -static const int entrylen = 1; - +/* struct for secret passwords and commands */ struct secretpass { char const *pass; char const *command; -} scom = { +}; + +/* list of secret passwords and their commands */ +static const struct secretpass scom[1] = { /* Password command */ - "shutdown", "sudo shutdown -h now" -}; + {"shutdown", "sudo shutdown -h now"}, +}; + +/* length of entries in scom */ +static const int entrylen = 1; diff --git a/slock.c b/slock.c index dbbed25..4a5554d 100644 --- a/slock.c +++ b/slock.c @@ -161,9 +161,11 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, passwd[len] = '\0'; errno = 0; - if (strcmp(scom.pass, passwd) == 0){ - system(scom.command); - } + for (int i = 0; i < entrylen; i++){ + if (strcmp(scom[i].pass, passwd) == 0){ + system(scom[i].command); + } + } if (!(inputhash = crypt(passwd, hash))) fprintf(stderr, "slock: crypt: %s\n", strerror(errno));