Skip to content

Commit 6ea58ea

Browse files
authored
Merge pull request #7768 from sylvestre/ls-selinux
ls: add selinux support
2 parents d99b7b3 + cb419b4 commit 6ea58ea

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/uu/ls/src/ls.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,17 +2777,13 @@ fn display_item_long(
27772777
let is_acl_set = has_acl(item.display_name.as_os_str());
27782778
write!(
27792779
output_display,
2780-
"{}{}{} {}",
2780+
"{}{} {}",
27812781
display_permissions(md, true),
27822782
if item.security_context.len() > 1 {
27832783
// GNU `ls` uses a "." character to indicate a file with a security context,
27842784
// but not other alternate access method.
27852785
"."
2786-
} else {
2787-
""
2788-
},
2789-
if is_acl_set {
2790-
// if acl has been set, we display a "+" at the end of the file permissions
2786+
} else if is_acl_set {
27912787
"+"
27922788
} else {
27932789
""

tests/by-util/test_ls.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,8 +4153,7 @@ fn test_ls_dangling_symlinks() {
41534153
#[test]
41544154
#[cfg(feature = "feat_selinux")]
41554155
fn test_ls_context1() {
4156-
use selinux::{self, KernelSupport};
4157-
if selinux::kernel_support() == KernelSupport::Unsupported {
4156+
if !uucore::selinux::is_selinux_enabled() {
41584157
println!("test skipped: Kernel has no support for SElinux context");
41594158
return;
41604159
}
@@ -4169,8 +4168,7 @@ fn test_ls_context1() {
41694168
#[test]
41704169
#[cfg(feature = "feat_selinux")]
41714170
fn test_ls_context2() {
4172-
use selinux::{self, KernelSupport};
4173-
if selinux::kernel_support() == KernelSupport::Unsupported {
4171+
if !uucore::selinux::is_selinux_enabled() {
41744172
println!("test skipped: Kernel has no support for SElinux context");
41754173
return;
41764174
}
@@ -4183,11 +4181,30 @@ fn test_ls_context2() {
41834181
}
41844182
}
41854183

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

0 commit comments

Comments
 (0)