]> 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>
Fri, 23 Feb 2018 13:01:43 +0000 (14:01 +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 1903b287c59635f90c73ffc47e0adbe54fb33d90..7529f05ab5890e3e303004f778d5f7555cbcaa1f 100644 (file)
@@ -20,7 +20,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 f5665c9830d9f969206ef169560caef33fd213a5..368906876701c30974f81ec1a6bd96bc627d685d 100644 (file)
@@ -142,6 +142,7 @@ int Main(void)
 
 #endif /* _WIN32 */
                Application::DeclarePrefixDir(ICINGA_PREFIX);
+               Application::DeclareSysconfigFile(ICINGA_SYSCONFIGFILE);
                Application::DeclareSysconfDir(ICINGA_SYSCONFDIR);
                Application::DeclareRunDir(ICINGA_RUNDIR);
                Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
@@ -152,8 +153,17 @@ int Main(void)
 #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 ce4982e2a570ac52e185f6df068cde06b75000f7..70b2c40e9b591c8270cc142646d970c5da2618dc 100644 (file)
@@ -1286,6 +1286,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 bd04bbd02a975d841a9f09fca363715028b2af60..05b2e5d91c4f672739b474b12e337e3f8657ef06 100644 (file)
@@ -105,6 +105,9 @@ public:
        static String GetIncludeConfDir(void);
        static void DeclareIncludeConfDir(const String& path);
 
+       static String GetSysconfigFile(void);
+       static void DeclareSysconfigFile(const String& path);
+
        static String GetStatePath(void);
        static void DeclareStatePath(const String& path);
 
index 836393b03224778cc1a4000ad82555964ff4756f..9aaddb8baaa61426a9d3bbab8dad6f7f1beb3149 100644 (file)
@@ -1950,3 +1950,35 @@ String Utility::GetIcingaDataPath(void)
 }
 
 #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 3e19301f032d797918b16dd58f7eb317a27c0f74..08c1f1999596cc38f137a3ca6f9ff826ec4faeca 100644 (file)
@@ -148,6 +148,8 @@ public:
        static String GetIcingaDataPath(void);
 #endif /* _WIN32 */
 
+       static String GetFromSysconfig(const String& env);
+
 #ifdef I2_DEBUG
        static void SetTime(double);
        static void IncrementTime(double);