]> granicus.if.org Git - icinga2/commitdiff
Disallow modify attribute for certain object attributes
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 15 Oct 2015 14:33:20 +0000 (16:33 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 16 Oct 2015 10:44:08 +0000 (12:44 +0200)
fixes #9095

lib/base/configobject.cpp
lib/base/configobject.ti
lib/base/type.hpp
lib/icinga/host.ti
lib/icinga/service.ti
lib/icinga/user.ti
tools/mkclass/class_lexer.ll
tools/mkclass/classcompiler.hpp

index 87cd3d910955b937180597a2c2b0dd8ccdb7f303..37446413e0b273a2a085e4a9a45a0979a8851ce2 100644 (file)
@@ -130,6 +130,9 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
        int fid = type->GetFieldId(fieldName);
        Field field = type->GetFieldInfo(fid);
 
+       if (field.Attributes & FAInternal || field.Attributes & FANoModify)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Attribute cannot be modified."));
+
        if (field.Attributes & FAConfig) {
                if (!original_attributes) {
                        original_attributes = new Dictionary();
index cb97e18ee453a0b3ebea9271def91bc6b1e41a00..90a514a1c789a5e27f0bab3d9a10938e320fcb15 100644 (file)
@@ -68,8 +68,8 @@ private:
 
 abstract class ConfigObject : ConfigObjectBase
 {
-       [config, internal] String __name (Name);
-       [config] String "name" (ShortName) {
+       [config, internal, no_modify] String __name (Name);
+       [config, no_modify] String "name" (ShortName) {
                get {{{
                        if (m_ShortName.IsEmpty())
                                return GetName();
@@ -77,22 +77,22 @@ abstract class ConfigObject : ConfigObjectBase
                                return m_ShortName;
                }}}
        };
-       [config, internal, get_protected] String type (TypeNameV);
+       [config, internal, get_protected, no_modify] String type (TypeNameV);
        [config] name(Zone) zone (ZoneName);
        [config] String package;
-       [config, internal, get_protected] Array::Ptr templates;
+       [config, internal, get_protected, no_modify] Array::Ptr templates;
        [get_protected] bool active;
        [get_protected] bool paused {
                default {{{ return true; }}}
        };
-       [get_protected, internal] bool start_called;
-       [get_protected, internal] bool stop_called;
-       [get_protected, internal] bool pause_called;
-       [get_protected, internal] bool resume_called;
+       [get_protected, internal, no_modify] bool start_called;
+       [get_protected, internal, no_modify] bool stop_called;
+       [get_protected, internal, no_modify] bool pause_called;
+       [get_protected, internal, no_modify] bool resume_called;
        [enum] HAMode ha_mode (HAMode);
-       [protected] Dictionary::Ptr extensions;
+       [protected, no_modify] Dictionary::Ptr extensions;
 
-       [protected] bool state_loaded;
+       [protected, no_modify] bool state_loaded;
        Dictionary::Ptr original_attributes;
        [state] double version {
                default {{{ return 0; }}}
index 04cfedb4150f0881eae10b5c4c6cc48cade07171..dd13d9902f0d2bbce046a3ecccd763172e4ea002 100644 (file)
@@ -38,7 +38,8 @@ enum FieldAttribute
        FAState = 4,
        FAInternal = 64,
        FARequired = 512,
-       FANavigation = 1024
+       FANavigation = 1024,
+       FANoModify = 2048
 };
 
 class Type;
index 06c96dcc119759b6aeaee9e2e8a6e10ba2a536ad..c183998c9d895ae6cbb67d6be1c0e8f0990c4a5b 100644 (file)
@@ -27,7 +27,7 @@ namespace icinga
 
 class Host : Checkable
 {
-       [config] array(name(HostGroup)) groups {
+       [config, no_modify] array(name(HostGroup)) groups {
                default {{{ return new Array(); }}}
        };
 
index 2fcbcc39da41e1123b8ec5b37e680e89dec8edfc..db09fe9451d80d661bec007bea3c5cdd5cab37d6 100644 (file)
@@ -40,7 +40,7 @@ class Service : Checkable < ServiceNameComposer
 {
        load_after Host;
 
-       [config] array(name(ServiceGroup)) groups {
+       [config, no_modify] array(name(ServiceGroup)) groups {
                default {{{ return new Array(); }}}
        };
 
index 5b90019adba34660c6d08a9d5072f46205ea68f9..e6781ade7adc0491083e8a879858f0c88bb3242b 100644 (file)
@@ -35,7 +35,7 @@ class User : CustomVarObject
                                return m_DisplayName;
                }}}
        };
-       [config] array(name(UserGroup)) groups {
+       [config, no_modify] array(name(UserGroup)) groups {
                default {{{ return new Array(); }}}
        };
        [config, navigation] name(TimePeriod) period (PeriodRaw) {
index d339c11c930b8cc42d745592905f66d223486f74..63eaf1ddb6c4327ac7e379f94dc728c84338629b 100644 (file)
@@ -146,6 +146,7 @@ protected                   { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTR
 internal                       { yylval->num = FAInternal; return T_FIELD_ATTRIBUTE; }
 no_storage                     { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; }
 navigation                     { return T_NAVIGATION; }
+no_modify                      { yylval->num = FANoModify; return T_FIELD_ATTRIBUTE; }
 validator                      { return T_VALIDATOR; }
 required                       { return T_REQUIRED; }
 name                           { return T_NAME; }
index fca2f6a6227aa0c334a99d971edd2e9abbe7e413..576cd61ad6bb7be568b38de4a65197ee33858b9d 100644 (file)
@@ -71,7 +71,8 @@ enum FieldAttribute
        FANoStorage = 128,
        FALoadDependency = 256,
        FARequired = 512,
-       FANavigation = 1024
+       FANavigation = 1024,
+       FANoModify = 2048
 };
 
 struct FieldType