3 Commits
0.1.0 ... 0.1.4

3 changed files with 21 additions and 16 deletions

2
Cargo.lock generated
View File

@ -31,7 +31,7 @@ checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a"
[[package]]
name = "posix-acl"
version = "0.1.0"
version = "0.1.4"
dependencies = [
"acl-sys",
"anyhow",

View File

@ -1,6 +1,6 @@
[package]
name = "posix-acl"
version = "0.1.0"
version = "0.1.4"
edition = "2021"
[dependencies]

View File

@ -35,22 +35,22 @@ pub static ACL_NONE: PermSet = PermSet::empty();
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum Qualifier {
UserObj,
GroupObj,
Other,
User(u32),
GroupObj,
Group(u32),
Mask,
Other,
}
impl Qualifier {
pub fn get_tag(&self) -> i32 {
match self {
Qualifier::UserObj => ACL_USER_OBJ,
Qualifier::GroupObj => ACL_GROUP_OBJ,
Qualifier::Other => ACL_OTHER,
Qualifier::User(_) => ACL_USER,
Qualifier::GroupObj => ACL_GROUP_OBJ,
Qualifier::Group(_) => ACL_GROUP,
Qualifier::Mask => ACL_MASK,
Qualifier::Other => ACL_OTHER,
}
}
@ -63,12 +63,18 @@ impl Qualifier {
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ACLEntry(Qualifier, PermSet);
#[derive(Debug, Clone, PartialEq, Eq, Ord)]
pub struct ACLEntry(pub Qualifier, pub PermSet);
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
impl PartialOrd for ACLEntry {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.0.cmp(&other.0))
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
pub struct PosixACL {
entries: Vec<ACLEntry>,
pub entries: Vec<ACLEntry>,
}
impl PosixACL {
@ -201,6 +207,7 @@ impl PosixACL {
pub fn write<P: AsRef<Path>>(&self, path: P) -> Result<()> {
// Write ACL to file
self.write_type(path, ACL_TYPE_ACCESS)?;
// TODO: If necessary fix mask
Ok(())
}
@ -238,11 +245,6 @@ impl PosixACL {
return Err(anyhow!("Other entry is required"));
}
let has_mask = self.entries.iter().any(|x| matches!(x.0, Qualifier::Mask));
if !has_mask {
return Err(anyhow!("Mask entry is required"));
}
for acl_entry in &self.entries {
let mut entry = null_mut();
check_return(
@ -333,8 +335,11 @@ mod test {
file.write_all(b"Hello, world!").unwrap();
acl.write(path).unwrap();
acl.entries.sort();
let mut acl_r = PosixACL::new_from_file(path, false).unwrap();
acl_r.entries.sort();
let acl_r = PosixACL::new_from_file(path, false).unwrap();
println!("{:?}", acl);
assert_eq!(acl.entries.len(), acl_r.entries.len());
let missing = acl