From: Gunnar Beutner Date: Fri, 9 May 2014 17:40:56 +0000 (+0200) Subject: Config validator: Make sure that objects are not abstract. X-Git-Tag: v0.0.11~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c31bae792d48d0379853f2e4a29ce625b9a0112;p=icinga2 Config validator: Make sure that objects are not abstract. Fixes #6148 --- diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index d5964d1b5..fa1372f92 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -245,20 +245,6 @@ ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name) return ConfigItem::Ptr(); } -bool ConfigItem::HasObject(const String& type, const String& name) -{ - std::pair key = std::make_pair(type, name); - ConfigItem::ItemMap::iterator it; - - { - boost::mutex::scoped_lock lock(m_Mutex); - - it = m_Items.find(key); - } - - return (it != m_Items.end()); -} - void ConfigItem::ValidateItem(void) { if (m_Validated) diff --git a/lib/config/configitem.h b/lib/config/configitem.h index 8ce6fa1ff..4cd7acc4e 100644 --- a/lib/config/configitem.h +++ b/lib/config/configitem.h @@ -61,7 +61,6 @@ public: static ConfigItem::Ptr GetObject(const String& type, const String& name); - static bool HasObject(const String& type, const String& name); void ValidateItem(void); diff --git a/lib/config/typerule.cpp b/lib/config/typerule.cpp index e64639efc..27fb4a722 100644 --- a/lib/config/typerule.cpp +++ b/lib/config/typerule.cpp @@ -45,6 +45,8 @@ bool TypeRule::MatchName(const String& name) const bool TypeRule::MatchValue(const Value& value, String *hint) const { + ConfigItem::Ptr item; + if (value.IsEmpty()) return true; @@ -76,11 +78,18 @@ bool TypeRule::MatchValue(const Value& value, String *hint) const if (!value.IsScalar()) return false; - if (!ConfigItem::HasObject(m_NameType, value)) { + item = ConfigItem::GetObject(m_NameType, value); + + if (!item) { *hint = "Object '" + value + "' of type '" + m_NameType + "' does not exist."; return false; } + if (item->IsAbstract()) { + *hint = "Object '" + value + "' of type '" + m_NameType + "' must not be a template."; + return false; + } + return true; default: