Only look up group if one is named
This commit is contained in:
parent
87083ad381
commit
363ab9f834
19
daemon.c
19
daemon.c
@ -242,16 +242,17 @@ int main(int argc, char *argv[]) {
|
|||||||
struct passwd *user = (userName ? getpwnam(userName) : getpwuid(getuid()));
|
struct passwd *user = (userName ? getpwnam(userName) : getpwuid(getuid()));
|
||||||
if (errno) err(EX_OSFILE, "getpwnam");
|
if (errno) err(EX_OSFILE, "getpwnam");
|
||||||
if (!user) errx(EX_USAGE, "no such user %s", userName);
|
if (!user) errx(EX_USAGE, "no such user %s", userName);
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
struct group *group = (
|
|
||||||
groupName ? getgrnam(groupName) : getgrgid(user->pw_gid)
|
|
||||||
);
|
|
||||||
if (errno) err(EX_OSFILE, "getgrnam");
|
|
||||||
if (!group) errx(EX_USAGE, "no such group %s", groupName);
|
|
||||||
|
|
||||||
serviceUID = user->pw_uid;
|
serviceUID = user->pw_uid;
|
||||||
serviceGID = group->gr_gid;
|
|
||||||
|
if (groupName) {
|
||||||
|
errno = 0;
|
||||||
|
struct group *group = getgrnam(groupName);
|
||||||
|
if (errno) err(EX_OSFILE, "getgrnam");
|
||||||
|
if (!group) errx(EX_USAGE, "no such group %s", groupName);
|
||||||
|
serviceGID = group->gr_gid;
|
||||||
|
} else {
|
||||||
|
serviceGID = user->pw_gid;
|
||||||
|
}
|
||||||
|
|
||||||
int len = asprintf(&serviceEnviron[USER], "USER=%s", user->pw_name);
|
int len = asprintf(&serviceEnviron[USER], "USER=%s", user->pw_name);
|
||||||
if (len < 0) err(EX_OSERR, "asprintf");
|
if (len < 0) err(EX_OSERR, "asprintf");
|
||||||
|
Loading…
Reference in New Issue
Block a user