From 6cc4f85c66bc28b27bc0935f2b2b6371c0afb67b Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 15 Oct 2015 16:33:20 +0200 Subject: [PATCH] Disallow modify attribute for certain object attributes fixes #9095 --- lib/base/configobject.cpp | 3 +++ lib/base/configobject.ti | 20 ++++++++++---------- lib/base/type.hpp | 3 ++- lib/icinga/host.ti | 2 +- lib/icinga/service.ti | 2 +- lib/icinga/user.ti | 2 +- tools/mkclass/class_lexer.ll | 1 + tools/mkclass/classcompiler.hpp | 3 ++- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp index 87cd3d910..37446413e 100644 --- a/lib/base/configobject.cpp +++ b/lib/base/configobject.cpp @@ -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(); diff --git a/lib/base/configobject.ti b/lib/base/configobject.ti index cb97e18ee..90a514a1c 100644 --- a/lib/base/configobject.ti +++ b/lib/base/configobject.ti @@ -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; }}} diff --git a/lib/base/type.hpp b/lib/base/type.hpp index 04cfedb41..dd13d9902 100644 --- a/lib/base/type.hpp +++ b/lib/base/type.hpp @@ -38,7 +38,8 @@ enum FieldAttribute FAState = 4, FAInternal = 64, FARequired = 512, - FANavigation = 1024 + FANavigation = 1024, + FANoModify = 2048 }; class Type; diff --git a/lib/icinga/host.ti b/lib/icinga/host.ti index 06c96dcc1..c183998c9 100644 --- a/lib/icinga/host.ti +++ b/lib/icinga/host.ti @@ -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(); }}} }; diff --git a/lib/icinga/service.ti b/lib/icinga/service.ti index 2fcbcc39d..db09fe945 100644 --- a/lib/icinga/service.ti +++ b/lib/icinga/service.ti @@ -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(); }}} }; diff --git a/lib/icinga/user.ti b/lib/icinga/user.ti index 5b90019ad..e6781ade7 100644 --- a/lib/icinga/user.ti +++ b/lib/icinga/user.ti @@ -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) { diff --git a/tools/mkclass/class_lexer.ll b/tools/mkclass/class_lexer.ll index d339c11c9..63eaf1ddb 100644 --- a/tools/mkclass/class_lexer.ll +++ b/tools/mkclass/class_lexer.ll @@ -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; } diff --git a/tools/mkclass/classcompiler.hpp b/tools/mkclass/classcompiler.hpp index fca2f6a62..576cd61ad 100644 --- a/tools/mkclass/classcompiler.hpp +++ b/tools/mkclass/classcompiler.hpp @@ -71,7 +71,8 @@ enum FieldAttribute FANoStorage = 128, FALoadDependency = 256, FARequired = 512, - FANavigation = 1024 + FANavigation = 1024, + FANoModify = 2048 }; struct FieldType