From 2f3a8be2e6b07337ec7ffb141929fbbbf00c569f Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 12 May 2015 15:44:44 +0200 Subject: [PATCH] Determine NSClient++ installation path using MsiGetComponentPath fixes #9256 --- itl/command-nscp-local.conf | 4 ++-- lib/base/CMakeLists.txt | 2 +- lib/base/scriptutils.cpp | 19 +++++++++++++++++++ lib/base/scriptutils.hpp | 3 +++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/itl/command-nscp-local.conf b/itl/command-nscp-local.conf index d8f092762..ed97fad50 100644 --- a/itl/command-nscp-local.conf +++ b/itl/command-nscp-local.conf @@ -18,13 +18,13 @@ ******************************************************************************/ if (!globals.contains("NscpPath")) { - NscpPath = "C:\\Program Files\\NSClient++" + NscpPath = msi_get_component_path("{5C45463A-4AE9-4325-96DB-6E239C034F93}") } object CheckCommand "nscp-local" { import "plugin-check-command" - command = [ "$nscp_path$\\nscp.exe", "client" ] + command = [ NscpPath, "client" ] arguments = { "-q" = { diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 0a880e2c3..f497d8eda 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -63,7 +63,7 @@ if(UNIX OR CYGWIN) endif() if(WIN32) - target_link_libraries(base ws2_32 dbghelp shlwapi) + target_link_libraries(base ws2_32 dbghelp shlwapi msi) endif() set_target_properties ( diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 3b743169d..f77f17280 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -31,6 +31,9 @@ #include #include #include +#ifdef _WIN32 +#include +#endif /* _WIN32 */ using namespace icinga; @@ -52,6 +55,9 @@ REGISTER_SCRIPTFUNCTION(string, &ScriptUtils::CastString); REGISTER_SCRIPTFUNCTION(number, &ScriptUtils::CastNumber); REGISTER_SCRIPTFUNCTION(bool, &ScriptUtils::CastBool); REGISTER_SCRIPTFUNCTION(get_time, &Utility::GetTime); +#ifdef _WIN32 +REGISTER_SCRIPTFUNCTION(msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim); +#endif /* _WIN32 */ String ScriptUtils::CastString(const Value& value) { @@ -278,3 +284,16 @@ void ScriptUtils::Assert(const Value& arg) BOOST_THROW_EXCEPTION(std::runtime_error("Assertion failed")); } +#ifdef _WIN32 +String ScriptUtils::MsiGetComponentPathShim(const String& component) +{ + TCHAR productCode[39]; + if (MsiGetProductCode(component.CStr(), productCode) != ERROR_SUCCESS) + return ""; + TCHAR path[2048]; + DWORD szPath = sizeof(path); + path[0] = '\0'; + MsiGetComponentPath(productCode, component.CStr(), path, &szPath); + return path; +} +#endif /* _WIN32 */ diff --git a/lib/base/scriptutils.hpp b/lib/base/scriptutils.hpp index 2f6deb584..15bf1169d 100644 --- a/lib/base/scriptutils.hpp +++ b/lib/base/scriptutils.hpp @@ -50,6 +50,9 @@ public: static DynamicObject::Ptr GetObject(const Type::Ptr& type, const String& name); static Array::Ptr GetObjects(const Type::Ptr& type); static void Assert(const Value& arg); +#ifdef _WIN32 + static String MsiGetComponentPathShim(const String& component); +#endif /* _WIN32 */ private: ScriptUtils(void); -- 2.40.0