]> granicus.if.org Git - icinga2/commitdiff
Determine NSClient++ installation path using MsiGetComponentPath
authorGunnar Beutner <gunnar@beutner.name>
Tue, 12 May 2015 13:44:44 +0000 (15:44 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 12 May 2015 13:45:40 +0000 (15:45 +0200)
fixes #9256

itl/command-nscp-local.conf
lib/base/CMakeLists.txt
lib/base/scriptutils.cpp
lib/base/scriptutils.hpp

index d8f092762e31400981d17f78cd41986e11864e5d..ed97fad501d858b2db0a4426c910ed732e437d21 100644 (file)
  ******************************************************************************/
 
 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" = {
index 726c490a92b10f8fa01d6aaa0d9af79e9e7e3027..900d3535be78883769fd8b6086fd068b5408a01e 100644 (file)
@@ -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 (
index 5e6ff0743a6b7f5db36509560f1884d9e9d51c0a..afdfa61bf3ff8864b02d66a12edc052941cdf69a 100644 (file)
@@ -30,6 +30,9 @@
 #include <boost/regex.hpp>
 #include <algorithm>
 #include <set>
+#ifdef _WIN32
+#include <msi.h>
+#endif /* _WIN32 */
 
 using namespace icinga;
 
@@ -51,6 +54,9 @@ REGISTER_SAFE_SCRIPTFUNCTION(string, &ScriptUtils::CastString);
 REGISTER_SAFE_SCRIPTFUNCTION(number, &ScriptUtils::CastNumber);
 REGISTER_SAFE_SCRIPTFUNCTION(bool, &ScriptUtils::CastBool);
 REGISTER_SAFE_SCRIPTFUNCTION(get_time, &Utility::GetTime);
+#ifdef _WIN32
+REGISTER_SAFE_SCRIPTFUNCTION(msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim);
+#endif /* _WIN32 */
 
 String ScriptUtils::CastString(const Value& value)
 {
@@ -264,3 +270,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 */
\ No newline at end of file
index 2f6deb584be0f17a190a30f12e3e4f3eafab00b9..15bf1169daf9cd141c4262025f7d4582c49062b5 100644 (file)
@@ -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);