From 4651a58b82fa06348211fcf9b4e2dff931176410 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 16 Apr 2025 22:03:42 +0200 Subject: [PATCH] ls: add selinux support --- src/uu/ls/src/ls.rs | 8 ++------ tests/by-util/test_ls.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 60c91e478..ec52d48be 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2752,17 +2752,13 @@ fn display_item_long( let is_acl_set = has_acl(item.display_name.as_os_str()); write!( output_display, - "{}{}{} {}", + "{}{} {}", display_permissions(md, true), if item.security_context.len() > 1 { // GNU `ls` uses a "." character to indicate a file with a security context, // but not other alternate access method. "." - } else { - "" - }, - if is_acl_set { - // if acl has been set, we display a "+" at the end of the file permissions + } else if is_acl_set { "+" } else { "" diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 4123809fc..e63aeb483 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -4183,6 +4183,26 @@ fn test_ls_context2() { } } +#[test] +#[cfg(feature = "feat_selinux")] +fn test_ls_context_long() { + if !uucore::selinux::is_selinux_enabled() { + return; + } + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.touch("foo"); + for c_flag in ["-Zl", "-Zal"] { + let result = scene.ucmd().args(&[c_flag, "foo"]).succeeds(); + + let line: Vec<_> = result.stdout_str().split(" ").collect(); + assert!(line[0].ends_with(".")); + assert!(line[4].starts_with("unconfined_u")); + let s: Vec<_> = line[4].split(":").collect(); + assert!(s.len() == 4); + } +} + #[test] #[cfg(feature = "feat_selinux")] fn test_ls_context_format() {