From 259931d88d5524f76042deac6ff4ed00e7687dbf Mon Sep 17 00:00:00 2001 From: Acts1631 Date: Tue, 3 Nov 2026 10:06:11 -0500 Subject: [PATCH] Daemon: initialize supplementary groups when changing user The daemon_user path changed the primary group and user, but the initgroups() call was hidden behind the obsolete _BSD_SOURCE feature macro. Normal builds therefore retained supplementary groups inherited from the launcher. Initialize the configured user's supplementary groups before dropping the primary group and user, and abort if initialization fails. --- src/Daemon.cxx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Daemon.cxx b/src/Daemon.cxx index ed52196..04f7ab9 100644 --- a/src/Daemon.cxx +++ b/src/Daemon.cxx @@ -17,6 +17,7 @@ #include #include +#include #include #endif @@ -78,19 +79,14 @@ daemonize_set_user() if (user_name == nullptr) return; - /* get uid */ + /* Initialize supplementary groups before dropping privileges. */ + if (initgroups(user_name, user_gid) == -1) + throw FmtErrno("cannot init supplementary groups of user {:?}", + user_name); + if (setgid(user_gid) == -1) throw FmtErrno("cannot setgid for user {:?}", user_name); -#ifdef _BSD_SOURCE - /* init suplementary groups - * (must be done before we change our uid) - */ - if (initgroups(user_name, user_gid) == -1) - FmtErrno("cannot init supplementary groups of user {:?}", - user_name); -#endif - /* set uid */ if (setuid(user_uid) == -1) throw FmtErrno("cannot change to uid of user {:?}",