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 }) }