]> granicus.if.org Git - icinga2/commitdiff
Config validator: Make sure that objects are not abstract.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 9 May 2014 17:40:56 +0000 (19:40 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 9 May 2014 17:40:56 +0000 (19:40 +0200)
Fixes #6148

lib/config/configitem.cpp
lib/config/configitem.h
lib/config/typerule.cpp

index d5964d1b5ace2ee178bb8a0d22c392e5640aec60..fa1372f92745c110ad209d951c9288280efdd340 100644 (file)
@@ -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<String, String> 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)
index 8ce6fa1ff80d4ca2d490eaf765da4666674191c1..4cd7acc4e5bdfc08bf7994b4646bada4dc332336 100644 (file)
@@ -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);
 
index e64639efca75d9bbc801063faae1fc8c30679aa2..27fb4a722eb268492a34680e4185d4765243e3f0 100644 (file)
@@ -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: