slock-user-1.5.diff 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From 7f1f66dfb1feb2b6df87565f1b895dd7a12d7ceb Mon Sep 17 00:00:00 2001
  2. From: Phillip Tischler <ptgit@protonmail.com>
  3. Date: Sat, 18 Mar 2023 22:59:55 +0100
  4. Subject: [PATCH] Always use the current users password ($USER)
  5. ---
  6. config.def.h | 4 ----
  7. slock.c | 8 ++++----
  8. 2 files changed, 4 insertions(+), 8 deletions(-)
  9. diff --git a/config.def.h b/config.def.h
  10. index 9855e21..3229e62 100644
  11. --- a/config.def.h
  12. +++ b/config.def.h
  13. @@ -1,7 +1,3 @@
  14. -/* user and group to drop privileges to */
  15. -static const char *user = "nobody";
  16. -static const char *group = "nogroup";
  17. -
  18. static const char *colorname[NUMCOLS] = {
  19. [INIT] = "black", /* after initialization */
  20. [INPUT] = "#005577", /* during input */
  21. diff --git a/slock.c b/slock.c
  22. index 5ae738c..7444eac 100644
  23. --- a/slock.c
  24. +++ b/slock.c
  25. @@ -325,13 +325,13 @@ main(int argc, char **argv) {
  26. /* validate drop-user and -group */
  27. errno = 0;
  28. - if (!(pwd = getpwnam(user)))
  29. - die("slock: getpwnam %s: %s\n", user,
  30. + if (!(pwd = getpwnam(getenv("USER"))))
  31. + die("slock: getpwnam %s: %s\n", getenv("USER"),
  32. errno ? strerror(errno) : "user entry not found");
  33. duid = pwd->pw_uid;
  34. errno = 0;
  35. - if (!(grp = getgrnam(group)))
  36. - die("slock: getgrnam %s: %s\n", group,
  37. + if (!(grp = getgrnam(getenv("USER"))))
  38. + die("slock: getgrnam %s: %s\n", getenv("USER"),
  39. errno ? strerror(errno) : "group entry not found");
  40. dgid = grp->gr_gid;
  41. --
  42. 2.30.2