logo

skeud

Simple and portable utilities to deal with user accounts (su, login)
commit: baa0af5f8d7aa2c51d6ab068e664086604f1b504
parent 74ae56b5afeea243873567b593f8defc09fff739
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 11 Sep 2023 08:56:20 +0200

su: Call initgroups(3)

Diffstat:

Msu.c7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/su.c b/su.c @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L -// for explicit_bzero +// for explicit_bzero, initgroups #define _DEFAULT_SOURCE #ifdef __linux__ @@ -14,6 +14,7 @@ #include <assert.h> // assert #include <errno.h> // errno +#include <grp.h> // initgroups #include <pwd.h> // getpwnam #include <stdbool.h> // bool #include <stdio.h> // fprintf, perror @@ -198,6 +199,10 @@ main(int argc, char *argv[]) { perror("su: setgid"); } + if(initgroups(username, pwent->pw_gid) < 0) + { + perror("su: initgroups"); + } if(setuid(pwent->pw_uid) < 0) { perror("su: setuid");