From 23aa628665f2230b7ae45033b2e57114c183f784 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Fri, 4 Jun 2021 11:17:48 +0200 Subject: [PATCH] Windows: automatically migrate from mainlog to windowseventlog --- etc/CMakeLists.txt | 2 +- etc/icinga2/features-enabled/mainlog.conf | 1 - .../features-enabled/windowseventlog.conf | 1 + icinga-installer/icinga-installer.cpp | 29 ++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) delete mode 100644 etc/icinga2/features-enabled/mainlog.conf create mode 100644 etc/icinga2/features-enabled/windowseventlog.conf diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index 47c8a40e2..ff138bd4c 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -56,7 +56,7 @@ if(NOT WIN32) install(FILES bash_completion.d/icinga2 DESTINATION ${BASHCOMPLETION_DIR}) else() - install_if_not_exists(icinga2/features-enabled/mainlog.conf ${ICINGA2_CONFIGDIR}/features-enabled) + install_if_not_exists(icinga2/features-enabled/windowseventlog.conf ${ICINGA2_CONFIGDIR}/features-enabled) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "(Linux|Solaris|SunOS)") diff --git a/etc/icinga2/features-enabled/mainlog.conf b/etc/icinga2/features-enabled/mainlog.conf deleted file mode 100644 index 6d7a47f06..000000000 --- a/etc/icinga2/features-enabled/mainlog.conf +++ /dev/null @@ -1 +0,0 @@ -include "../features-available/mainlog.conf" diff --git a/etc/icinga2/features-enabled/windowseventlog.conf b/etc/icinga2/features-enabled/windowseventlog.conf new file mode 100644 index 000000000..8e5787339 --- /dev/null +++ b/etc/icinga2/features-enabled/windowseventlog.conf @@ -0,0 +1 @@ +include "../features-available/windowseventlog.conf" diff --git a/icinga-installer/icinga-installer.cpp b/icinga-installer/icinga-installer.cpp index 233f90cab..4dc050de6 100644 --- a/icinga-installer/icinga-installer.cpp +++ b/icinga-installer/icinga-installer.cpp @@ -213,10 +213,11 @@ static int UpgradeNSIS(void) static int InstallIcinga(void) { std::string installDir = GetIcingaInstallPath(); + std::string skelDir = installDir + "\\share\\skel"; std::string dataDir = GetIcingaDataPath(); if (!PathExists(dataDir)) { - std::string sourceDir = installDir + "\\share\\skel" + std::string(1, '\0'); + std::string sourceDir = skelDir + std::string(1, '\0'); std::string destinationDir = dataDir + std::string(1, '\0'); SHFILEOPSTRUCT fop; @@ -243,6 +244,32 @@ static int InstallIcinga(void) MkDirP(dataDir + "/var/spool/icinga2/tmp"); } + // Upgrade from versions older than 2.13 by making the windowseventlog feature available, + // enable it by default and disable the old mainlog feature. + if (!PathExists(dataDir + "/etc/icinga2/features-available/windowseventlog.conf")) { + // Disable the old mainlog feature as it is replaced by windowseventlog by default. + std::string mainlogEnabledFile = dataDir + "/etc/icinga2/features-enabled/mainlog.conf"; + if (PathExists(mainlogEnabledFile)) { + if (DeleteFileA(mainlogEnabledFile.c_str()) == 0) { + throw std::runtime_error("deleting '" + mainlogEnabledFile + "' failed"); + } + } + + // Install the new windowseventlog feature. As features-available/windowseventlog.conf is used as a marker file, + // copy it as the last step, so that this is run again should the upgrade be interrupted. + for (const std::string& d : {"features-enabled", "features-available"}) { + std::string sourceFile = skelDir + "/etc/icinga2/" + d + "/windowseventlog.conf"; + std::string destinationFile = dataDir + "/etc/icinga2/" + d + "/windowseventlog.conf"; + + if (CopyFileA(sourceFile.c_str(), destinationFile.c_str(), false) == 0) { + throw std::runtime_error("copying '" + sourceFile + "' to '" + destinationFile + "' failed"); + } + } + } + + // TODO: In Icinga 2.14, rename features-available/mainlog.conf to mainlog.conf.deprecated + // so that it's no longer listed as an available feature. + ExecuteCommand("icacls", "\"" + dataDir + "\" /grant *S-1-5-20:(oi)(ci)m"); ExecuteCommand("icacls", "\"" + dataDir + "\\etc\" /inheritance:r /grant:r *S-1-5-20:(oi)(ci)m *S-1-5-32-544:(oi)(ci)f");