Skip to content

Commit 728b90d

Browse files
committed
selinux: use the uucore function
1 parent 77c4ba5 commit 728b90d

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

src/uu/id/src/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
130130
selinux_supported: {
131131
#[cfg(feature = "selinux")]
132132
{
133-
selinux::kernel_support() != selinux::KernelSupport::Unsupported
133+
uucore::selinux::is_selinux_enabled()
134134
}
135135
#[cfg(not(feature = "selinux"))]
136136
{

src/uu/ls/src/ls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ impl Config {
11241124
selinux_supported: {
11251125
#[cfg(feature = "selinux")]
11261126
{
1127-
selinux::kernel_support() != selinux::KernelSupport::Unsupported
1127+
uucore::selinux::is_selinux_enabled()
11281128
}
11291129
#[cfg(not(feature = "selinux"))]
11301130
{

src/uu/runcon/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ path = "src/runcon.rs"
1919

2020
[dependencies]
2121
clap = { workspace = true }
22-
uucore = { workspace = true, features = ["entries", "fs", "perms"] }
22+
uucore = { workspace = true, features = ["entries", "fs", "perms", "selinux"] }
2323
selinux = { workspace = true }
2424
thiserror = { workspace = true }
2525
libc = { workspace = true }

src/uu/runcon/src/runcon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn set_next_exec_context(context: &OpaqueSecurityContext) -> Result<()> {
271271
}
272272

273273
fn get_plain_context(context: &OsStr) -> Result<OpaqueSecurityContext> {
274-
if selinux::kernel_support() == selinux::KernelSupport::Unsupported {
274+
if !uucore::selinux::is_selinux_enabled() {
275275
return Err(Error::SELinuxNotEnabled);
276276
}
277277

@@ -342,7 +342,7 @@ fn get_custom_context(
342342
use OpaqueSecurityContext as OSC;
343343
type SetNewValueProc = fn(&OSC, &CStr) -> selinux::errors::Result<()>;
344344

345-
if selinux::kernel_support() == selinux::KernelSupport::Unsupported {
345+
if !uucore::selinux::is_selinux_enabled() {
346346
return Err(Error::SELinuxNotEnabled);
347347
}
348348

src/uucore/src/lib/features/selinux.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ mod tests {
235235

236236
#[test]
237237
fn test_get_selinux_security_context() {
238+
if !is_selinux_enabled() {
239+
// Skip the test if SELinux is not enabled
240+
return;
241+
}
242+
238243
let tmpfile = NamedTempFile::new().expect("Failed to create tempfile");
239244
let path = tmpfile.path();
240245

@@ -261,6 +266,11 @@ mod tests {
261266

262267
#[test]
263268
fn test_get_selinux_context_nonexistent_file() {
269+
if !is_selinux_enabled() {
270+
// Skip the test if SELinux is not enabled
271+
return;
272+
}
273+
264274
let path = Path::new("/nonexistent/file/that/does/not/exist");
265275

266276
let result = get_selinux_security_context(path);

tests/by-util/test_id.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ fn test_id_zero() {
381381
#[test]
382382
#[cfg(feature = "feat_selinux")]
383383
fn test_id_context() {
384-
use selinux::{self, KernelSupport};
385-
if selinux::kernel_support() == KernelSupport::Unsupported {
384+
if !uucore::selinux::is_selinux_enabled() {
386385
println!("test skipped: Kernel has no support for SElinux context");
387386
return;
388387
}
@@ -456,12 +455,11 @@ fn test_id_no_specified_user_posixly() {
456455
feature = "feat_selinux"
457456
))]
458457
{
459-
use selinux::{self, KernelSupport};
460-
if selinux::kernel_support() == KernelSupport::Unsupported {
461-
println!("test skipped: Kernel has no support for SElinux context");
462-
} else {
458+
if uucore::selinux::is_selinux_enabled() {
463459
let result = ts.ucmd().succeeds();
464460
assert!(result.stdout_str().contains("context="));
461+
} else {
462+
println!("test skipped: Kernel has no support for SElinux context");
465463
}
466464
}
467465
}

0 commit comments

Comments
 (0)