From 367678b804d802a8ec2e9fc8be6fb5b1f0e78dca Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Tue, 19 Nov 2024 06:54:49 +0000 Subject: [PATCH] src/lib.rs aktualisiert Add required ACLs if they don't exist (default value mode, this should be changed!) --- src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 795599f..8283961 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -176,6 +176,46 @@ impl PosixACL { entries.push(ACLEntry(qual, permset)); } + // There should be at leas a UserObj, GroupObj, Other and Mask on the non default ACL entries. If they dont exist, create them + + if !default { + let mut found_user = false; + let mut found_group = false; + let mut found_other = false; + let mut found_mask: Option = None; + + for ent in entries.iter() { + match ent.0 { + Qualifier::UserObj => { + found_user = true; + } + Qualifier::GroupObj => { + found_group = true; + } + Qualifier::Other => { + found_other = true; + } + Qualifier::Mask => found_mask = Some(ent.1), + _ => {} + } + } + + let def_perm = found_mask.unwrap_or(ACL_RWX); + + if !found_user { + entries.push(ACLEntry(Qualifier::UserObj, def_perm.clone())); + } + if !found_group { + entries.push(ACLEntry(Qualifier::GroupObj, def_perm.clone())); + } + if !found_other { + entries.push(ACLEntry(Qualifier::Other, def_perm.clone())); + } + if found_mask.is_none() { + entries.push(ACLEntry(Qualifier::Mask, def_perm.clone())); + } + } + Ok(PosixACL { entries }) }