-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mkdir
: added acl
permissions inheritance for subdirectories
#6676
Conversation
src/uu/mkdir/src/mkdir.rs
Outdated
/// Only default acl entries get inherited by objects under the path i.e. if child directories | ||
/// will have their permissions modified. | ||
#[cfg(not(windows))] | ||
fn get_acl_perm_bits(path: &Path) -> u32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have this function:
pub fn retrieve_xattrs<P: AsRef<Path>>(source: P) -> std::io::Result<HashMap<OsString, Vec<u8>>> { |
maybe use it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it but i couldn't figure out how to correctly and reliably interpret the Vec<u8>
value , the key is system.posix_acl_default
for a file when i do setfacl -d -m group::rmx test_file
so that's fine. I just need to reliably parse the byte sequences to extract the permission bits.
I will try to look through the fsxattr source code in https://github.com/torvalds/linux/blob/master/fs/xattr.c to check how they interpret things. I would definitely appreciate some help or some other resources you can point me to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, makes sense
could you please move the function into fsxattr ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, makes sense could you please move the function into fsxattr ?
Okay, will do that.
GNU testsuite comparison:
|
6fa394b
to
50bbac0
Compare
50bbac0
to
78cc1c3
Compare
GNU testsuite comparison:
|
d651140
to
de4a0cb
Compare
GNU testsuite comparison:
|
e2642de
to
04befe4
Compare
Changes:
|
04befe4
to
6ed128a
Compare
GNU testsuite comparison:
|
|
||
let mut map: HashMap<OsString, Vec<u8>> = HashMap::new(); | ||
let xattr_val: Vec<u8> = vec![ | ||
2, 0, 0, 0, 1, 0, 7, 0, 255, 255, 255, 255, 4, 0, 7, 0, 255, 255, 255, 255, 32, 0, 5, 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment explaining these values and how to get them
Waiting on a fix for this rust-lang/rust-bindgen#2926 |
ca7f284
to
cbde96a
Compare
GNU testsuite comparison:
|
you should disable it on android too:
and maybe freebsd:
|
3e84528
to
c6a9e66
Compare
Changes since last push
Freebsd acl entries have differences, which would be better implemented by someone with a bsd system as they could check if the bindgen is creating wrong entries. |
GNU testsuite comparison:
|
src/uu/mkdir/src/mkdir.rs
Outdated
|
||
// TODO: Make this macos and freebsd compatible by creating a function to get permission bits from | ||
// acl in extended attributes | ||
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "freebsd")))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about ?
it makes it clear that the call is always chmod and we just have different mode for each platform?
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "freebsd")))]
Comment
let new_mode = if is_parent {
(!mode::get_umask() & 0o777) | 0o300
} else {
mode
};
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "freebsd")))]
let new_mode = if !path_exists {
let acl_perm_bits = uucore::fsxattr::get_acl_perm_bits_from_xattr(path);
new_mode | acl_perm_bits
} else {
new_mode
};
#[cfg(windows)]
let new_mode = mode;
chmod(path, new_mode)?;
Ok(())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that feels more deliberate.
We replace the large os exceptions with this
#[cfg(all(unix,not(target_os="linux")))]
Comment
let new_mode = if is_parent {
(!mode::get_umask() & 0o777) | 0o300
} else {
mode
};
#[cfg(all(unix,target_os="linux"))]
let new_mode = if !path_exists {
let acl_perm_bits = uucore::fsxattr::get_acl_perm_bits_from_xattr(path);
new_mode | acl_perm_bits
} else {
new_mode
};
#[cfg(windows)]
let new_mode = mode;
chmod(path, new_mode)?;
From the earlier CI checks , i don't think android xattr works either, it does seem its because the tag values i am using is different for android so the test kept failing. There seems to be some differences in every platform, which would require reading into their source code. Ideally we could have used the "exacl" crate but it wouldn't work on most systems as most distros ship without libacl.
Edit 1: If this code snippet looks okay, then please tell me, i will commit it. It feels like kinda bad to make a linux specific change.
Edit 2: If we merge this , we should create a tracking issue to extend acl support to other platforms. And then work through it, i guess.
7885343
to
2f2680c
Compare
GNU testsuite comparison:
|
fails on freebsd:
|
cbef610
to
c5d833c
Compare
GNU testsuite comparison:
|
c5d833c
to
8415b88
Compare
GNU testsuite comparison:
|
well done :) |
This will fix
mkdir/p-acl
gnu test