mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
Remove need for RunAsUser/Group
They are now read form the sysconfig file which is owned by root
This commit is contained in:
parent
c6b86680a0
commit
d4b336ad20
@ -20,7 +20,7 @@
|
|||||||
#define ICINGA_INCLUDECONFDIR "${CMAKE_INSTALL_FULL_DATADIR}/icinga2/include"
|
#define ICINGA_INCLUDECONFDIR "${CMAKE_INSTALL_FULL_DATADIR}/icinga2/include"
|
||||||
#define ICINGA_USER "${ICINGA2_USER}"
|
#define ICINGA_USER "${ICINGA2_USER}"
|
||||||
#define ICINGA_GROUP "${ICINGA2_GROUP}"
|
#define ICINGA_GROUP "${ICINGA2_GROUP}"
|
||||||
|
#define ICINGA_SYSCONFIGFILE "${ICINGA2_SYSCONFIGFILE}"
|
||||||
#define ICINGA_BUILD_HOST_NAME "${ICINGA2_BUILD_HOST_NAME}"
|
#define ICINGA_BUILD_HOST_NAME "${ICINGA2_BUILD_HOST_NAME}"
|
||||||
#define ICINGA_BUILD_COMPILER_NAME "${ICINGA2_BUILD_COMPILER_NAME}"
|
#define ICINGA_BUILD_COMPILER_NAME "${ICINGA2_BUILD_COMPILER_NAME}"
|
||||||
#define ICINGA_BUILD_COMPILER_VERSION "${ICINGA2_BUILD_COMPILER_VERSION}"
|
#define ICINGA_BUILD_COMPILER_VERSION "${ICINGA2_BUILD_COMPILER_VERSION}"
|
||||||
|
@ -3,5 +3,3 @@
|
|||||||
* configuration file (icinga2.conf) is processed.
|
* configuration file (icinga2.conf) is processed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const RunAsUser = "@ICINGA2_USER@"
|
|
||||||
const RunAsGroup = "@ICINGA2_GROUP@"
|
|
||||||
|
@ -142,6 +142,7 @@ int Main(void)
|
|||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
Application::DeclarePrefixDir(ICINGA_PREFIX);
|
Application::DeclarePrefixDir(ICINGA_PREFIX);
|
||||||
|
Application::DeclareSysconfigFile(ICINGA_SYSCONFIGFILE);
|
||||||
Application::DeclareSysconfDir(ICINGA_SYSCONFDIR);
|
Application::DeclareSysconfDir(ICINGA_SYSCONFDIR);
|
||||||
Application::DeclareRunDir(ICINGA_RUNDIR);
|
Application::DeclareRunDir(ICINGA_RUNDIR);
|
||||||
Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
|
Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
|
||||||
@ -152,8 +153,17 @@ int Main(void)
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d");
|
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__
|
#ifdef __linux__
|
||||||
Application::DeclareRLimitFiles(Application::GetDefaultRLimitFiles());
|
Application::DeclareRLimitFiles(Application::GetDefaultRLimitFiles());
|
||||||
Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses());
|
Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses());
|
||||||
|
@ -1286,6 +1286,27 @@ void Application::DeclareStatePath(const String& path)
|
|||||||
ScriptGlobal::Set("StatePath", 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.
|
* Retrieves the path for the modified attributes file.
|
||||||
*
|
*
|
||||||
|
@ -105,6 +105,9 @@ public:
|
|||||||
static String GetIncludeConfDir(void);
|
static String GetIncludeConfDir(void);
|
||||||
static void DeclareIncludeConfDir(const String& path);
|
static void DeclareIncludeConfDir(const String& path);
|
||||||
|
|
||||||
|
static String GetSysconfigFile(void);
|
||||||
|
static void DeclareSysconfigFile(const String& path);
|
||||||
|
|
||||||
static String GetStatePath(void);
|
static String GetStatePath(void);
|
||||||
static void DeclareStatePath(const String& path);
|
static void DeclareStatePath(const String& path);
|
||||||
|
|
||||||
|
@ -1950,3 +1950,35 @@ String Utility::GetIcingaDataPath(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#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 */
|
||||||
|
}
|
||||||
|
@ -148,6 +148,8 @@ public:
|
|||||||
static String GetIcingaDataPath(void);
|
static String GetIcingaDataPath(void);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
static String GetFromSysconfig(const String& env);
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
static void SetTime(double);
|
static void SetTime(double);
|
||||||
static void IncrementTime(double);
|
static void IncrementTime(double);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user