From 06e79fe6fd63df252d477a11268593d813656fec Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 1 Dec 2014 13:19:07 +0100 Subject: [PATCH] Don't execute built-in commands on the master in remote command execution mode fixes #7708 --- lib/methods/clrchecktask.cpp | 12 +++++++++--- lib/methods/clusterchecktask.cpp | 3 +++ lib/methods/clusterzonechecktask.cpp | 6 +++++- lib/methods/icingachecktask.cpp | 3 +++ lib/methods/nullchecktask.cpp | 3 +++ lib/methods/randomchecktask.cpp | 3 +++ 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/methods/clrchecktask.cpp b/lib/methods/clrchecktask.cpp index af0fd3c98..e77fd69ff 100644 --- a/lib/methods/clrchecktask.cpp +++ b/lib/methods/clrchecktask.cpp @@ -171,7 +171,8 @@ void ClrCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult BOOST_FOREACH(const Dictionary::Pair& kv, env) { String name = kv.second; - Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult()); + Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult(), + NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); envMacros->Set(kv.first, value); } @@ -187,8 +188,13 @@ void ClrCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult if (it != l_Objects.end()) { vtObject = it->second; } else { - String clr_assembly = MacroProcessor::ResolveMacros("$clr_assembly$", resolvers, checkable->GetLastCheckResult()); - String clr_type = MacroProcessor::ResolveMacros("$clr_type$", resolvers, checkable->GetLastCheckResult()); + String clr_assembly = MacroProcessor::ResolveMacros("$clr_assembly$", resolvers, checkable->GetLastCheckResult(), + NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + String clr_type = MacroProcessor::ResolveMacros("$clr_type$", resolvers, checkable->GetLastCheckResult(), + NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + + if (resolvedMacros && !useResolvedMacros) + return; vtObject = CreateClrType(clr_assembly, clr_type); l_Objects[checkable] = vtObject; diff --git a/lib/methods/clusterchecktask.cpp b/lib/methods/clusterchecktask.cpp index f7e665fb9..36f24bea4 100644 --- a/lib/methods/clusterchecktask.cpp +++ b/lib/methods/clusterchecktask.cpp @@ -39,6 +39,9 @@ REGISTER_SCRIPTFUNCTION(ClusterCheck, &ClusterCheckTask::ScriptFunc); void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + if (resolvedMacros && !useResolvedMacros) + return; + ApiListener::Ptr listener = ApiListener::GetInstance(); if (!listener) { diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 96ee98727..a8fc94833 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -56,7 +56,11 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che resolvers.push_back(std::make_pair("command", commandObj)); resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); - String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult()); + String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(), + NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + + if (resolvedMacros && !useResolvedMacros) + return; if (zoneName.IsEmpty()) { cr->SetOutput("Macro 'cluster_zone' must be set."); diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 400d05f1e..808e1581c 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -35,6 +35,9 @@ REGISTER_SCRIPTFUNCTION(IcingaCheck, &IcingaCheckTask::ScriptFunc); void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + if (resolvedMacros && !useResolvedMacros) + return; + double interval = Utility::GetTime() - Application::GetStartTime(); if (interval > 60) diff --git a/lib/methods/nullchecktask.cpp b/lib/methods/nullchecktask.cpp index efb4795d3..09f369ddf 100644 --- a/lib/methods/nullchecktask.cpp +++ b/lib/methods/nullchecktask.cpp @@ -34,6 +34,9 @@ REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc); void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + if (resolvedMacros && !useResolvedMacros) + return; + String output = "Hello from "; output += Utility::GetFQDN(); diff --git a/lib/methods/randomchecktask.cpp b/lib/methods/randomchecktask.cpp index 1b8eaca37..79a10be52 100644 --- a/lib/methods/randomchecktask.cpp +++ b/lib/methods/randomchecktask.cpp @@ -34,6 +34,9 @@ REGISTER_SCRIPTFUNCTION(RandomCheck, &RandomCheckTask::ScriptFunc); void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + if (resolvedMacros && !useResolvedMacros) + return; + String output = "Hello from "; output += Utility::GetFQDN(); -- 2.40.0