mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge pull request #7768 from sylvestre/ls-selinux
ls: add selinux support
This commit is contained in:
commit
6ea58ea0aa
2 changed files with 25 additions and 12 deletions
|
@ -2777,17 +2777,13 @@ fn display_item_long(
|
||||||
let is_acl_set = has_acl(item.display_name.as_os_str());
|
let is_acl_set = has_acl(item.display_name.as_os_str());
|
||||||
write!(
|
write!(
|
||||||
output_display,
|
output_display,
|
||||||
"{}{}{} {}",
|
"{}{} {}",
|
||||||
display_permissions(md, true),
|
display_permissions(md, true),
|
||||||
if item.security_context.len() > 1 {
|
if item.security_context.len() > 1 {
|
||||||
// GNU `ls` uses a "." character to indicate a file with a security context,
|
// GNU `ls` uses a "." character to indicate a file with a security context,
|
||||||
// but not other alternate access method.
|
// but not other alternate access method.
|
||||||
"."
|
"."
|
||||||
} else {
|
} else if is_acl_set {
|
||||||
""
|
|
||||||
},
|
|
||||||
if is_acl_set {
|
|
||||||
// if acl has been set, we display a "+" at the end of the file permissions
|
|
||||||
"+"
|
"+"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
|
|
@ -4153,8 +4153,7 @@ fn test_ls_dangling_symlinks() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "feat_selinux")]
|
#[cfg(feature = "feat_selinux")]
|
||||||
fn test_ls_context1() {
|
fn test_ls_context1() {
|
||||||
use selinux::{self, KernelSupport};
|
if !uucore::selinux::is_selinux_enabled() {
|
||||||
if selinux::kernel_support() == KernelSupport::Unsupported {
|
|
||||||
println!("test skipped: Kernel has no support for SElinux context");
|
println!("test skipped: Kernel has no support for SElinux context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4169,8 +4168,7 @@ fn test_ls_context1() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "feat_selinux")]
|
#[cfg(feature = "feat_selinux")]
|
||||||
fn test_ls_context2() {
|
fn test_ls_context2() {
|
||||||
use selinux::{self, KernelSupport};
|
if !uucore::selinux::is_selinux_enabled() {
|
||||||
if selinux::kernel_support() == KernelSupport::Unsupported {
|
|
||||||
println!("test skipped: Kernel has no support for SElinux context");
|
println!("test skipped: Kernel has no support for SElinux context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4183,11 +4181,30 @@ 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]
|
#[test]
|
||||||
#[cfg(feature = "feat_selinux")]
|
#[cfg(feature = "feat_selinux")]
|
||||||
fn test_ls_context_format() {
|
fn test_ls_context_format() {
|
||||||
use selinux::{self, KernelSupport};
|
if !uucore::selinux::is_selinux_enabled() {
|
||||||
if selinux::kernel_support() == KernelSupport::Unsupported {
|
|
||||||
println!("test skipped: Kernel has no support for SElinux context");
|
println!("test skipped: Kernel has no support for SElinux context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue