]> granicus.if.org Git - icinga2/commitdiff
Remove need for RunAsUser/Group
authorJean Flach <jean-marcel.flach@icinga.com>
Fri, 26 Jan 2018 15:27:16 +0000 (16:27 +0100)
committerJean Flach <jean-marcel.flach@icinga.com>
Tue, 20 Feb 2018 13:16:43 +0000 (14:16 +0100)
They are now read form the sysconfig file which is owned by root

config.h.cmake
etc/icinga2/init.conf.cmake
icinga-app/icinga.cpp
lib/base/application.cpp
lib/base/application.hpp
lib/base/utility.cpp
lib/base/utility.hpp

index e8a7bdcba0c5cdd8d6149413520a32fde31bb5c4..c461e029f93a2740900a1187c94362353ac27fe5 100644 (file)
@@ -21,7 +21,7 @@
 #define ICINGA_INCLUDECONFDIR "${CMAKE_INSTALL_FULL_DATADIR}/icinga2/include"
 #define ICINGA_USER "${ICINGA2_USER}"
 #define ICINGA_GROUP "${ICINGA2_GROUP}"
-
+#define ICINGA_SYSCONFIGFILE "${ICINGA2_SYSCONFIGFILE}"
 #define ICINGA_BUILD_HOST_NAME "${ICINGA2_BUILD_HOST_NAME}"
 #define ICINGA_BUILD_COMPILER_NAME "${ICINGA2_BUILD_COMPILER_NAME}"
 #define ICINGA_BUILD_COMPILER_VERSION "${ICINGA2_BUILD_COMPILER_VERSION}"
index 9f57bca82ab1d23bded7562b8b6153f5d34980fc..22406a99832cb9b1a1b80198b931799aa30ad4c1 100644 (file)
@@ -3,5 +3,3 @@
  * configuration file (icinga2.conf) is processed.
  */
 
-const RunAsUser = "@ICINGA2_USER@"
-const RunAsGroup = "@ICINGA2_GROUP@"
index ef66278187fe8095ad235daa4aad57dacf9e71ca..f40a135419e91dfa0baf2402cbce27199f6bd786 100644 (file)
@@ -143,6 +143,7 @@ static int Main()
 
 #endif /* _WIN32 */
                Application::DeclarePrefixDir(ICINGA_PREFIX);
+               Application::DeclareSysconfigFile(ICINGA_SYSCONFIGFILE);
                Application::DeclareSysconfDir(ICINGA_SYSCONFDIR);
                Application::DeclareRunDir(ICINGA_RUNDIR);
                Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
@@ -153,8 +154,17 @@ static int Main()
 #endif /* _WIN32 */
 
        Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
-       Application::DeclareRunAsUser(ICINGA_USER);
-       Application::DeclareRunAsGroup(ICINGA_GROUP);
+
+       String icinga_user = Utility::GetFromSysconfig("ICINGA2_USER");
+       if (icinga_user.IsEmpty())
+               icinga_user = ICINGA_USER;
+
+       String icinga_group = Utility::GetFromSysconfig("ICINGA2_GROUP");
+       if (icinga_group.IsEmpty())
+               icinga_group = ICINGA_GROUP;
+
+       Application::DeclareRunAsUser(icinga_user);
+       Application::DeclareRunAsGroup(icinga_group);
 #ifdef __linux__
        Application::DeclareRLimitFiles(Application::GetDefaultRLimitFiles());
        Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses());
index 7c552eaeb44012ee0b6e03836e6b602938cafdf9..1c1aa6776143905895a06b85cdc69f02eed060b2 100644 (file)
@@ -1326,6 +1326,27 @@ void Application::DeclareStatePath(const String& path)
                ScriptGlobal::Set("StatePath", path);
 }
 
+/**
+ * Retrives the path of the sysconfig file.
+ *
+ * @returns The path.
+ */
+String Application::GetSysconfigFile(void)
+{
+       return ScriptGlobal::Get("SysconfigFile");
+}
+
+/**
+ * Sets the path of the sysconfig file.
+ *
+ * @param path The new path.
+ */
+void Application::DeclareSysconfigFile(const String& path)
+{
+       if (!ScriptGlobal::Exists("SysconfigFile"))
+               ScriptGlobal::Set("SysconfigFile", path);
+}
+
 /**
  * Retrieves the path for the modified attributes file.
  *
index ecdb1e92bdd3c41b3296cfe4ae2921cf2abeb0ae..03d83599b02be5fd03ee14b479ee2c8fe6e075cd 100644 (file)
@@ -106,7 +106,10 @@ public:
        static String GetIncludeConfDir();
        static void DeclareIncludeConfDir(const String& path);
 
-       static String GetStatePath();
+       static String GetSysconfigFile(void);
+       static void DeclareSysconfigFile(const String& path);
+
+       static String GetStatePath(void);
        static void DeclareStatePath(const String& path);
 
        static String GetModAttrPath();
index f9cf18cdb46550e23d056cbacdc1758f9996f705..6869e353d579e037c9e2ae12542c908cde803f09 100644 (file)
@@ -1935,3 +1935,35 @@ String Utility::GetIcingaDataPath()
 }
 
 #endif /* _WIN32 */
+
+String Utility::GetFromSysconfig(const String& env)
+{
+#ifndef _WIN32
+       String sysconf = Application::GetSysconfigFile();
+       if (sysconf.IsEmpty())
+               return "";
+
+       String cmdInner = ". " + EscapeShellArg(sysconf) + " 2>&1 >/dev/null;echo \"$" + env + "\"";
+       String cmd = "sh -c " + EscapeShellArg(cmdInner);
+
+       FILE *fp = popen(cmd.CStr(), "r");
+
+       if (!fp)
+               return "";
+
+       char line[1024];
+       String out;
+
+       if (fgets(line, sizeof(line), fp))
+               out = line;
+       else
+               return "";
+
+       pclose(fp);
+
+       return out.Trim();
+#else
+       //TODO: Figure out how to do this on windows
+       return "";
+#endif /* _WIN32 */
+}
index dd542c30a18aa6d9dbdc88a5bf47b8d6d668b5b1..97bb834b89b5d076384ae8add6523187616f5e10 100644 (file)
@@ -147,6 +147,8 @@ public:
        static String GetIcingaDataPath();
 #endif /* _WIN32 */
 
+       static String GetFromSysconfig(const String& env);
+
 #ifdef I2_DEBUG
        static void SetTime(double);
        static void IncrementTime(double);