]> granicus.if.org Git - icinga2/commitdiff
Disallow DynamicObject::Set() for config variables.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 25 Jan 2013 09:12:55 +0000 (10:12 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 25 Jan 2013 09:12:55 +0000 (10:12 +0100)
Fixes #3573

lib/base/dynamicobject.cpp
lib/base/dynamicobject.h

index 0551eb85bda5a8acb6b38cbe03a5fd860dff968d..8be09c20bd0c1afd19946ed6a5f68f3abb9bab29 100644 (file)
@@ -126,7 +126,7 @@ void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate,
                if (!HasAttribute(it->first))
                        RegisterAttribute(it->first, static_cast<DynamicAttributeType>(type));
 
-               InternalSetAttribute(it->first, data, tx, suppressEvents);
+               InternalSetAttribute(it->first, data, tx, suppressEvents, true);
        }
 }
 
@@ -160,7 +160,7 @@ Value DynamicObject::Get(const String& name) const
 }
 
 void DynamicObject::InternalSetAttribute(const String& name, const Value& data,
-    double tx, bool suppressEvent)
+    double tx, bool suppressEvent, bool allowEditConfig)
 {
        DynamicAttribute attr;
        attr.Type = Attribute_Transient;
@@ -172,6 +172,9 @@ void DynamicObject::InternalSetAttribute(const String& name, const Value& data,
 
        Value oldValue;
 
+       if (!allowEditConfig && (tt.first->second.Type & Attribute_Config))
+               throw_exception(runtime_error("Config properties are immutable: '" + name + "'."));
+
        if (!tt.second && tx >= tt.first->second.Tx) {
                oldValue = tt.first->second.Data;
                tt.first->second.Data = data;
index f809f846d963ea733221493a6d7f5cb075a3ce3d..c06973e2bcdcef92dd99c923dfc933778d418587 100644 (file)
@@ -145,7 +145,7 @@ protected:
        virtual void OnAttributeChanged(const String& name, const Value& oldValue);
 
 private:
-       void InternalSetAttribute(const String& name, const Value& data, double tx, bool suppressEvent = false);
+       void InternalSetAttribute(const String& name, const Value& data, double tx, bool suppressEvent = false, bool allowEditConfig = false);
        Value InternalGetAttribute(const String& name) const;
 
        AttributeMap m_Attributes;