From 0b1ad27ba8ecb8799e2a34ecad9206619cb8d14e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 29 Dec 2013 13:47:23 +0100 Subject: Daemon: fix typo in cast --- src/Daemon.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Daemon.cxx') diff --git a/src/Daemon.cxx b/src/Daemon.cxx index 4f214517e..088e7926d 100644 --- a/src/Daemon.cxx +++ b/src/Daemon.cxx @@ -52,7 +52,7 @@ static char *user_name; static uid_t user_uid = (uid_t)-1; /** the Unix group id which MPD runs as */ -static gid_t user_gid = (pid_t)-1; +static gid_t user_gid = (gid_t)-1; /** the absolute path of the pidfile */ static AllocatedPath pidfile = AllocatedPath::Null(); -- cgit v1.2.3 From 20ffedc745f8360aeed59479d77601cf6cf7cc03 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 29 Dec 2013 13:56:50 +0100 Subject: Daemon: simplify nested "if" --- src/Daemon.cxx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/Daemon.cxx') diff --git a/src/Daemon.cxx b/src/Daemon.cxx index 088e7926d..1623cca24 100644 --- a/src/Daemon.cxx +++ b/src/Daemon.cxx @@ -106,11 +106,10 @@ daemonize_set_user(void) return; /* set gid */ - if (user_gid != (gid_t)-1 && user_gid != getgid()) { - if (setgid(user_gid) == -1) { - FormatFatalSystemError("Failed to set group %d", - (int)user_gid); - } + if (user_gid != (gid_t)-1 && user_gid != getgid() && + setgid(user_gid) == -1) { + FormatFatalSystemError("Failed to set group %d", + (int)user_gid); } #ifdef _BSD_SOURCE -- cgit v1.2.3 From 09a0803116e642be4e983d1d09295afc788f37ca Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 29 Dec 2013 13:59:01 +0100 Subject: Daemon: fix typo in comment --- src/Daemon.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Daemon.cxx') diff --git a/src/Daemon.cxx b/src/Daemon.cxx index 1623cca24..d40c49d5d 100644 --- a/src/Daemon.cxx +++ b/src/Daemon.cxx @@ -113,7 +113,7 @@ daemonize_set_user(void) } #ifdef _BSD_SOURCE - /* init suplementary groups + /* init supplementary groups * (must be done before we change our uid) */ if (!had_group && initgroups(user_name, user_gid) == -1) { -- cgit v1.2.3 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