diff --git a/imagrc.toml b/imagrc.toml index 148e53d0..5453e9d8 100644 --- a/imagrc.toml +++ b/imagrc.toml @@ -24,6 +24,7 @@ post-delete-hook-aspects = [ "debug" ] [[aspects.debug]] parallel = false +mutable_hooks = false [store.hooks] diff --git a/libimagstore/src/configuration.rs b/libimagstore/src/configuration.rs index f5ba495f..d0be520a 100644 --- a/libimagstore/src/configuration.rs +++ b/libimagstore/src/configuration.rs @@ -193,6 +193,7 @@ pub fn get_post_move_aspect_names(value: &Option) -> Vec { #[derive(Debug)] pub struct AspectConfig { parallel: bool, + mutable_hooks: bool, config: Value, } @@ -200,8 +201,10 @@ impl AspectConfig { pub fn new(init: Value) -> AspectConfig { let parallel = AspectConfig::is_parallel(&init); + let muthooks = AspectConfig::allows_mutable_hooks(&init); AspectConfig { config: init, + mutable_hooks: muthooks, parallel: parallel, } } @@ -220,6 +223,24 @@ impl AspectConfig { } } + fn allows_mutable_hooks(init: &Value) -> bool { + match *init { + Value::Table(ref t) => + t.get("mutable_hooks") + .map_or(false, |value| { + match *value { + Value::Boolean(b) => b, + _ => false, + } + }), + _ => false, + } + } + + pub fn allow_mutable_hooks(&self) -> bool { + self.mutable_hooks + } + /// Get the aspect configuration for an aspect. /// /// Pass the store configuration object, this searches in `[aspects][]`. diff --git a/libimagstore/src/hook/aspect.rs b/libimagstore/src/hook/aspect.rs index 8c80b6cb..38b5cd07 100644 --- a/libimagstore/src/hook/aspect.rs +++ b/libimagstore/src/hook/aspect.rs @@ -73,6 +73,10 @@ impl StoreIdAccessor for Aspect { impl MutableHookDataAccessor for Aspect { fn access_mut(&self, fle: &mut FileLockEntry) -> HookResult<()> { + if !self.cfg.as_ref().map(|c| c.allow_mutable_hooks()).unwrap_or(false) { + return Err(HE::new(HEK::MutableHooksNotAllowed, None)); + } + let accessors : Vec = self.hooks.iter().map(|h| h.accessor()).collect(); fn is_file_accessor(a: &HDA) -> bool { diff --git a/libimagstore/src/hook/error.rs b/libimagstore/src/hook/error.rs index 77095844..1db64c59 100644 --- a/libimagstore/src/hook/error.rs +++ b/libimagstore/src/hook/error.rs @@ -3,7 +3,8 @@ generate_error_imports!(); generate_custom_error_types!(HookError, HookErrorKind, CustomData, HookExecutionError => "Hook exec error", - AccessTypeViolation => "Hook access type violation" + AccessTypeViolation => "Hook access type violation", + MutableHooksNotAllowed => "Mutable Hooks are denied" ); #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Copy)]