From c197ad99a36ea820b528cb9fd10ff80f96674bb8 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Tue, 29 Nov 2022 23:05:28 +0000 Subject: when switching user also set the groups backport of 872a717687a377cc02860e44c67dc1934ebfa9cb --- gmid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gmid.c b/gmid.c index 3f2901f..0bc44b7 100644 --- a/gmid.c +++ b/gmid.c @@ -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) -- cgit v1.2.3