core: Fixing regression in PrivilegeHelper that prevented running as non-root
PrivilegeHelper was properly initialized only when general section was
present. When section was omitted, s_privilegedUid/s_privilegedGid/s_normalUid/s_normalGid
variables was not properly initialized (set to 0), resulting in
exception during the subsequent PrivilegeHelper::drop call.
Change-Id: Iffd7f05e7e6c86d227da2c9b7920ca6e3b607211
diff --git a/daemon/core/privilege-helper.cpp b/core/privilege-helper.cpp
similarity index 93%
rename from daemon/core/privilege-helper.cpp
rename to core/privilege-helper.cpp
index f48c4d0..6f87f43 100644
--- a/daemon/core/privilege-helper.cpp
+++ b/core/privilege-helper.cpp
@@ -32,11 +32,11 @@
NFD_LOG_INIT("PrivilegeHelper");
-uid_t PrivilegeHelper::s_normalUid;
-gid_t PrivilegeHelper::s_normalGid;
+uid_t PrivilegeHelper::s_normalUid = ::geteuid();
+gid_t PrivilegeHelper::s_normalGid = ::getegid();
-uid_t PrivilegeHelper::s_privilegedUid;
-gid_t PrivilegeHelper::s_privilegedGid;
+uid_t PrivilegeHelper::s_privilegedUid = ::geteuid();
+gid_t PrivilegeHelper::s_privilegedGid = ::getegid();
void
PrivilegeHelper::initialize(const std::string& userName, const std::string& groupName)
@@ -50,14 +50,6 @@
NFD_LOG_TRACE("initializing privilege helper with user \"" << userName << "\""
<< " group \"" << groupName << "\"");
- s_privilegedUid = ::geteuid();
- s_privilegedGid = ::getegid();
-
- NFD_LOG_TRACE("saving effective uid=" << s_privilegedUid << " gid=" << s_privilegedGid);
-
- s_normalUid = s_privilegedUid;
- s_normalGid = s_privilegedGid;
-
// workflow from man getpwnam_r
if (!groupName.empty())
diff --git a/daemon/core/privilege-helper.hpp b/core/privilege-helper.hpp
similarity index 100%
rename from daemon/core/privilege-helper.hpp
rename to core/privilege-helper.hpp