Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ab23ae085 | |||
367678b804 | |||
![]() |
29a51767c8 | ||
![]() |
82b96cbb88 | ||
![]() |
dfad5cc74c | ||
![]() |
d1ef6513ce |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -31,7 +31,7 @@ checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "posix-acl"
|
name = "posix-acl"
|
||||||
version = "0.1.0"
|
version = "0.1.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"acl-sys",
|
"acl-sys",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "posix-acl"
|
name = "posix-acl"
|
||||||
version = "0.1.0"
|
version = "0.1.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
78
src/lib.rs
78
src/lib.rs
@ -35,22 +35,22 @@ pub static ACL_NONE: PermSet = PermSet::empty();
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Qualifier {
|
pub enum Qualifier {
|
||||||
UserObj,
|
UserObj,
|
||||||
GroupObj,
|
|
||||||
Other,
|
|
||||||
User(u32),
|
User(u32),
|
||||||
|
GroupObj,
|
||||||
Group(u32),
|
Group(u32),
|
||||||
Mask,
|
Mask,
|
||||||
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Qualifier {
|
impl Qualifier {
|
||||||
pub fn get_tag(&self) -> i32 {
|
pub fn get_tag(&self) -> i32 {
|
||||||
match self {
|
match self {
|
||||||
Qualifier::UserObj => ACL_USER_OBJ,
|
Qualifier::UserObj => ACL_USER_OBJ,
|
||||||
Qualifier::GroupObj => ACL_GROUP_OBJ,
|
|
||||||
Qualifier::Other => ACL_OTHER,
|
|
||||||
Qualifier::User(_) => ACL_USER,
|
Qualifier::User(_) => ACL_USER,
|
||||||
|
Qualifier::GroupObj => ACL_GROUP_OBJ,
|
||||||
Qualifier::Group(_) => ACL_GROUP,
|
Qualifier::Group(_) => ACL_GROUP,
|
||||||
Qualifier::Mask => ACL_MASK,
|
Qualifier::Mask => ACL_MASK,
|
||||||
|
Qualifier::Other => ACL_OTHER,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,12 +63,18 @@ impl Qualifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, Ord)]
|
||||||
pub struct ACLEntry(Qualifier, PermSet);
|
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 {
|
pub struct PosixACL {
|
||||||
entries: Vec<ACLEntry>,
|
pub entries: Vec<ACLEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PosixACL {
|
impl PosixACL {
|
||||||
@ -117,8 +123,6 @@ impl PosixACL {
|
|||||||
return Err(anyhow!("Failed to get ACL entry"));
|
return Err(anyhow!("Failed to get ACL entry"));
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("entry: {:?}", entry);
|
|
||||||
|
|
||||||
let mut tag_type: i32 = 0;
|
let mut tag_type: i32 = 0;
|
||||||
check_return(
|
check_return(
|
||||||
unsafe { acl_get_tag_type(entry, &mut tag_type) },
|
unsafe { acl_get_tag_type(entry, &mut tag_type) },
|
||||||
@ -161,7 +165,6 @@ impl PosixACL {
|
|||||||
"acl_get_permset",
|
"acl_get_permset",
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("permset: {:?}", permset);
|
|
||||||
let perm = if permset.is_null() {
|
let perm = if permset.is_null() {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
@ -173,6 +176,46 @@ impl PosixACL {
|
|||||||
entries.push(ACLEntry(qual, permset));
|
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<PermSet> = 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 })
|
Ok(PosixACL { entries })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +244,7 @@ impl PosixACL {
|
|||||||
pub fn write<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
pub fn write<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||||
// Write ACL to file
|
// Write ACL to file
|
||||||
self.write_type(path, ACL_TYPE_ACCESS)?;
|
self.write_type(path, ACL_TYPE_ACCESS)?;
|
||||||
|
// TODO: If necessary fix mask
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,11 +282,6 @@ impl PosixACL {
|
|||||||
return Err(anyhow!("Other entry is required"));
|
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 {
|
for acl_entry in &self.entries {
|
||||||
let mut entry = null_mut();
|
let mut entry = null_mut();
|
||||||
check_return(
|
check_return(
|
||||||
@ -303,7 +342,6 @@ impl<T> Drop for AclPtr<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn check_return(ret: i32, func: &str) {
|
pub(crate) fn check_return(ret: i32, func: &str) {
|
||||||
println!("ret: {} fnc: {}", ret, func);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ret,
|
ret,
|
||||||
0,
|
0,
|
||||||
@ -333,9 +371,11 @@ mod test {
|
|||||||
file.write_all(b"Hello, world!").unwrap();
|
file.write_all(b"Hello, world!").unwrap();
|
||||||
|
|
||||||
acl.write(path).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());
|
assert_eq!(acl.entries.len(), acl_r.entries.len());
|
||||||
let missing = acl
|
let missing = acl
|
||||||
.entries
|
.entries
|
||||||
|
Loading…
x
Reference in New Issue
Block a user