mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
chmod: implement special handling of directory setuid/setgid
This commit is contained in:
parent
9697c89d17
commit
15b40f6aa2
4 changed files with 66 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::common::util::*;
|
||||
use std::fs::{metadata, set_permissions, OpenOptions};
|
||||
use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
|
||||
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||
use std::sync::Mutex;
|
||||
|
||||
|
@ -490,3 +490,26 @@ fn test_chmod_strip_minus_from_mode() {
|
|||
assert_eq!(test.1, args.join(" "));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chmod_keep_setgid() {
|
||||
for &(from, arg, to) in &[
|
||||
(0o7777, "777", 0o46777),
|
||||
(0o7777, "=777", 0o40777),
|
||||
(0o7777, "0777", 0o46777),
|
||||
(0o7777, "=0777", 0o40777),
|
||||
(0o7777, "00777", 0o40777),
|
||||
(0o2444, "a+wx", 0o42777),
|
||||
(0o2444, "a=wx", 0o42333),
|
||||
(0o1444, "g+s", 0o43444),
|
||||
(0o4444, "u-s", 0o40444),
|
||||
(0o7444, "a-s", 0o41444),
|
||||
] {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("dir");
|
||||
set_permissions(at.plus("dir"), Permissions::from_mode(from)).unwrap();
|
||||
let r = ucmd.arg(arg).arg("dir").succeeds();
|
||||
println!("{}", r.stderr_str());
|
||||
assert_eq!(at.metadata("dir").permissions().mode(), to);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue