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
+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;