Automatically determine user and group.

This commit is contained in:
2026-09-02 18:06:44 -07:00
parent 5e7e8958e5
commit 3f9a2b9e15
2 changed files with 20 additions and 7 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
/* user and group to drop privileges to */
static const char *user = "igor";
static const char *group = "igor";
/* NOTE: Leave these empty if you want them to be determined automatically. */
static const char *user = "";
static const char *group = "";
static const char *colorname[NUMCOLS] = {
[INIT] = "black", /* after initialization */
@@ -24,7 +25,7 @@ static const Passthrough passthroughs[] = {
{ 0, XF86XK_MonBrightnessDown },
};
static const char *dspoffcmd[] = { "xset", "dpms", "force", "off", NULL };
/*static const char *dspoffcmd[] = { "xset", "dpms", "force", "off", NULL };*/
static const Key keys[] = {
/* modifier key function argument */
+16 -4
View File
@@ -409,6 +409,8 @@ main(int argc, char **argv) {
int s, nlocks, nscreens;
int event_base, error_base;
char *username, *groupname;
ARGBEGIN {
case 'v':
puts("slock-"VERSION);
@@ -417,15 +419,25 @@ main(int argc, char **argv) {
usage();
} ARGEND
if(strlen(user) && strlen(group)) {
username = (char *)user;
groupname = (char *)group;
} else {
username = getenv("USER");
groupname = username;
}
printf("%s:%s\n", username, groupname);
/* validate drop-user and -group */
errno = 0;
if (!(pwd = getpwnam(user)))
die("slock: getpwnam %s: %s\n", user,
if (!(pwd = getpwnam(username)))
die("slock: getpwnam %s: %s\n", username,
errno ? strerror(errno) : "user entry not found");
duid = pwd->pw_uid;
errno = 0;
if (!(grp = getgrnam(group)))
die("slock: getgrnam %s: %s\n", group,
if (!(grp = getgrnam(groupname)))
die("slock: getgrnam %s: %s\n", groupname,
errno ? strerror(errno) : "group entry not found");
dgid = grp->gr_gid;