multiuser: Use setresgid, setresuid and fix checks.

pw_gid and pw_uid aren't pointers, so checking them for 0 just
meant we didn't change the UIDs if we were something other
than root.
(cherry picked from commit acf0e80dc0fe1ae63d89211dfd28133a254a9753)

Change-Id: Ia567d61f645356bb122dd1bce99c581369f8f19f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/11498
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2026-08-08 17:13:13 +00:00
committed by waddlesplash
parent b86ecd28ca
commit 8c1b894d60
+2 -2
View File
@@ -179,13 +179,13 @@ setup_environment(struct passwd* passwd, bool preserveEnvironment, bool chngdir)
return errno;
}
if (passwd->pw_gid && setgid(passwd->pw_gid) != 0)
if (setresgid(passwd->pw_gid, passwd->pw_gid, passwd->pw_gid) != 0)
return errno;
if (initgroups(passwd->pw_name, passwd->pw_gid) != 0)
return errno;
if (passwd->pw_uid && setuid(passwd->pw_uid) != 0)
if (setresuid(passwd->pw_uid, passwd->pw_uid, passwd->pw_uid) != 0)
return errno;
if (chngdir) {