From e30b356eb018adcfb3efbce97c81bc0d99934826 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 29 Dec 2013 13:58:39 +0100 Subject: daemon: no initgroups() when already running as the configured user We can assume that initgroups() would be a no-op in that case, however initgroups() is not allowed for unprivileged users anyway. --- src/Daemon.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/Daemon.cxx') diff --git a/src/Daemon.cxx b/src/Daemon.cxx index d40c49d5d..557c47777 100644 --- a/src/Daemon.cxx +++ b/src/Daemon.cxx @@ -116,7 +116,11 @@ daemonize_set_user(void) /* init supplementary groups * (must be done before we change our uid) */ - if (!had_group && initgroups(user_name, user_gid) == -1) { + if (!had_group && + /* no need to set the new user's supplementary groups if + we are already this user */ + user_uid != getuid() && + initgroups(user_name, user_gid) == -1) { FormatFatalSystemError("Failed to set supplementary groups " "of user \"%s\"", user_name); -- cgit v1.2.3