Skip to content

Commit 543ee82

Browse files
committed
ls: add selinux support
1 parent 219e87d commit 543ee82

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/uu/ls/src/ls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,9 @@ fn display_item_long(
27612761
} else {
27622762
""
27632763
},
2764-
if is_acl_set {
2764+
if is_acl_set && item.security_context.len() <= 1 {
2765+
// if selinux on the file, it is
2766+
// "."
27652767
// if acl has been set, we display a "+" at the end of the file permissions
27662768
"+"
27672769
} else {

tests/by-util/test_ls.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4183,6 +4183,28 @@ fn test_ls_context2() {
41834183
}
41844184
}
41854185

4186+
#[test]
4187+
#[cfg(feature = "feat_selinux")]
4188+
fn test_ls_context_long() {
4189+
use selinux::{self, KernelSupport};
4190+
if selinux::kernel_support() == KernelSupport::Unsupported {
4191+
println!("test skipped: Kernel has no support for SElinux context",);
4192+
return;
4193+
}
4194+
let scene = TestScenario::new(util_name!());
4195+
let at = &scene.fixtures;
4196+
at.touch("foo");
4197+
for c_flag in ["-Zl", "-Zal"] {
4198+
let result = scene.ucmd().args(&[c_flag, "foo"]).succeeds();
4199+
4200+
let line: Vec<_> = result.stdout_str().split(" ").collect();
4201+
assert!(line[0].ends_with("."));
4202+
assert!(line[4].starts_with("unconfined_u"));
4203+
let s: Vec<_> = line[4].split(":").collect();
4204+
assert!(s.len() == 4);
4205+
}
4206+
}
4207+
41864208
#[test]
41874209
#[cfg(feature = "feat_selinux")]
41884210
fn test_ls_context_format() {

0 commit comments

Comments
 (0)