2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-06-13 05:33:00 -04:00
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "icinga/command.hpp"
|
2018-01-18 07:50:38 -05:00
|
|
|
#include "icinga/command-ti.cpp"
|
2015-02-11 10:08:02 -05:00
|
|
|
#include "icinga/macroprocessor.hpp"
|
2014-12-18 09:43:01 -05:00
|
|
|
#include "base/exception.hpp"
|
2015-02-11 07:12:08 -05:00
|
|
|
#include "base/objectlock.hpp"
|
2013-06-13 05:33:00 -04:00
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
2013-11-08 10:07:21 -05:00
|
|
|
REGISTER_TYPE(Command);
|
2013-11-08 05:17:46 -05:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
void Command::Validate(int types, const ValidationUtils& utils)
|
2014-07-16 06:58:18 -04:00
|
|
|
{
|
2014-11-30 17:32:13 -05:00
|
|
|
ObjectImpl<Command>::Validate(types, utils);
|
2014-07-16 06:58:18 -04:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
Dictionary::Ptr arguments = GetArguments();
|
2015-02-11 07:12:08 -05:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (!(types & FAConfig))
|
2015-02-11 07:12:08 -05:00
|
|
|
return;
|
|
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (arguments) {
|
|
|
|
|
if (!GetCommandLine().IsObjectType<Array>())
|
2017-11-30 12:09:38 -05:00
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "command" }, "Attribute 'command' must be an array if the 'arguments' attribute is set."));
|
2015-02-11 07:12:08 -05:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
ObjectLock olock(arguments);
|
2016-08-25 00:19:44 -04:00
|
|
|
for (const Dictionary::Pair& kv : arguments) {
|
2014-11-30 17:32:13 -05:00
|
|
|
const Value& arginfo = kv.second;
|
|
|
|
|
Value argval;
|
2015-02-11 07:12:08 -05:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (arginfo.IsObjectType<Dictionary>()) {
|
|
|
|
|
Dictionary::Ptr argdict = arginfo;
|
2015-03-12 13:05:58 -04:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (argdict->Contains("value")) {
|
2015-11-10 01:59:10 -05:00
|
|
|
Value argvalue = argdict->Get("value");
|
2014-11-30 17:32:13 -05:00
|
|
|
|
2015-11-10 01:59:10 -05:00
|
|
|
if (argvalue.IsString() && !MacroProcessor::ValidateMacroString(argvalue))
|
2024-10-23 07:06:12 -04:00
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "arguments", kv.first, "value" }, "Closing $ not found in macro format string '" + argvalue + "'."));
|
2015-03-12 13:05:58 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (argdict->Contains("set_if")) {
|
2015-11-10 01:59:10 -05:00
|
|
|
Value argsetif = argdict->Get("set_if");
|
2015-03-12 13:05:58 -04:00
|
|
|
|
2015-11-10 01:59:10 -05:00
|
|
|
if (argsetif.IsString() && !MacroProcessor::ValidateMacroString(argsetif))
|
2017-11-30 12:09:38 -05:00
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "arguments", kv.first, "set_if" }, "Closing $ not found in macro format string '" + argsetif + "'."));
|
2015-03-12 13:05:58 -04:00
|
|
|
}
|
2015-11-10 01:59:10 -05:00
|
|
|
} else if (arginfo.IsString()) {
|
|
|
|
|
if (!MacroProcessor::ValidateMacroString(arginfo))
|
2017-11-30 12:09:38 -05:00
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "arguments", kv.first }, "Closing $ not found in macro format string '" + arginfo + "'."));
|
2015-03-12 13:05:58 -04:00
|
|
|
}
|
2015-02-11 07:12:08 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
Dictionary::Ptr env = GetEnv();
|
2015-02-11 07:12:08 -05:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (env) {
|
|
|
|
|
ObjectLock olock(env);
|
2016-08-25 00:19:44 -04:00
|
|
|
for (const Dictionary::Pair& kv : env) {
|
2014-11-30 17:32:13 -05:00
|
|
|
const Value& envval = kv.second;
|
2015-02-11 07:12:08 -05:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (!envval.IsString() || envval.IsEmpty())
|
|
|
|
|
continue;
|
2015-02-11 07:12:08 -05:00
|
|
|
|
2014-11-30 17:32:13 -05:00
|
|
|
if (!MacroProcessor::ValidateMacroString(envval))
|
2017-11-30 12:09:38 -05:00
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "env", kv.first }, "Closing $ not found in macro format string '" + envval + "'."));
|
2015-02-11 07:12:08 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|