when switching user also set the groups

backport of 872a717687
This commit is contained in:
Omar Polo 2022-11-29 23:05:28 +00:00
parent 52772181b5
commit c197ad99a3
1 changed files with 4 additions and 3 deletions

7
gmid.c
View File

@ -408,9 +408,10 @@ drop_priv(void)
}
if (pw != NULL) {
if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1)
fatal("setresuid(%d): %s", pw->pw_uid,
strerror(errno));
if (setgroups(1, &pw->pw_gid) == -1 ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1 ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1)
fatal("cannot drop privileges");
}
if (getuid() == 0)