From 872a717687a377cc02860e44c67dc1934ebfa9cb Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Sun, 27 Nov 2022 10:05:13 +0000 Subject: [PATCH] when switching user also set the groups --- gmid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gmid.c b/gmid.c index 0e7918b..4908c7b 100644 --- a/gmid.c +++ b/gmid.c @@ -296,9 +296,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)