From c05fcc936c7441213cec1f89505500aca451e92a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 16 Feb 2022 13:17:39 +0100 Subject: [PATCH] #21 only change user if we are root --- BaseCommon/Daemon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseCommon/Daemon.cpp b/BaseCommon/Daemon.cpp index 5283040..46ad038 100644 --- a/BaseCommon/Daemon.cpp +++ b/BaseCommon/Daemon.cpp @@ -58,7 +58,7 @@ DAEMONIZE_RESULT CDaemon::daemonize(const std::string& pidFile, const std::strin } releaseLock(tempFd, ""); - if(user != nullptr) { + if(user != nullptr && getuid() == 0) { int res = chown(pidFile.c_str(), user->pw_uid, user->pw_gid); if(res != 0) { CLog::logFatal("Failed to set ownership of pidfile to user %s : %s", userName.c_str(), strerror(errno)); @@ -68,7 +68,7 @@ DAEMONIZE_RESULT CDaemon::daemonize(const std::string& pidFile, const std::strin } // change process ownership - if(user != nullptr) { + if(user != nullptr && getuid() == 0) { if(setgid(user->pw_gid) != 0) { CLog::logFatal("Failed to set %s GID : %s", userName.c_str(), strerror(errno)); return DR_FAILURE;