]> granicus.if.org Git - icinga2/commitdiff
Fix validation problem with relative object names.
authorGunnar Beutner <gunnar@beutner.name>
Sat, 5 Apr 2014 20:53:44 +0000 (22:53 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 5 Apr 2014 21:23:39 +0000 (23:23 +0200)
Refs #5925

lib/config/aexpression.cpp

index f8c8777819a1263f43bbb3b2175ff7ac69915c52..46e81490279a7309da6b01525dba450ff8cb4cf7 100644 (file)
@@ -522,12 +522,23 @@ Value AExpression::OpObject(const AExpression* expr, const Dictionary::Ptr& loca
 
        ConfigItemBuilder::Ptr item = make_shared<ConfigItemBuilder>(expr->m_DebugInfo);
 
-       ConfigItem::Ptr oldItem = ConfigItem::GetObject(type, name);
+       String checkName = name;
 
-       if (oldItem) {
-               std::ostringstream msgbuf;
-               msgbuf << "Object '" << name << "' of type '" << type << "' re-defined: " << expr->m_DebugInfo << "; previous definition: " << oldItem->GetDebugInfo();
-               BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(expr->m_DebugInfo));
+       if (!abstract) {
+               const DynamicObjectNameHelper *nh = dynamic_cast<const DynamicObjectNameHelper *>(Type::GetByName(type));
+
+               if (nh)
+                       checkName = nh->MakeObjectName(name, Dictionary::Ptr());
+       }
+
+       if (!checkName.IsEmpty()) {
+               ConfigItem::Ptr oldItem = ConfigItem::GetObject(type, name);
+
+               if (oldItem) {
+                       std::ostringstream msgbuf;
+                       msgbuf << "Object '" << name << "' of type '" << type << "' re-defined: " << expr->m_DebugInfo << "; previous definition: " << oldItem->GetDebugInfo();
+                       BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(expr->m_DebugInfo));
+               }
        }
 
        item->SetType(type);