From 8d94add3930a91c53e510dfafb2894e66b7d2d94 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 26 Apr 2025 11:10:42 +0200 Subject: [PATCH] set_selinux_security_context split the ContextRetrievalFailure error in two --- src/uucore/src/lib/features/selinux.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/uucore/src/lib/features/selinux.rs b/src/uucore/src/lib/features/selinux.rs index 02a30112b..eb14eb816 100644 --- a/src/uucore/src/lib/features/selinux.rs +++ b/src/uucore/src/lib/features/selinux.rs @@ -16,9 +16,12 @@ pub enum SeLinuxError { #[error("Failed to open the file")] FileOpenFailure, - #[error("Failed to retrieve or set the security context")] + #[error("Failed to retrieve the security context")] ContextRetrievalFailure, + #[error("Failed to set the security context")] + ContextSetFailure, + #[error("Invalid context string or conversion failure")] ContextConversionFailure, } @@ -29,7 +32,8 @@ impl From for i32 { SeLinuxError::SELinuxNotEnabled => 1, SeLinuxError::FileOpenFailure => 2, SeLinuxError::ContextRetrievalFailure => 3, - SeLinuxError::ContextConversionFailure => 4, + SeLinuxError::ContextSetFailure => 4, + SeLinuxError::ContextConversionFailure => 5, } } } @@ -109,11 +113,10 @@ pub fn set_selinux_security_context( false, ) .set_for_path(path, false, false) - .map_err(|_| SeLinuxError::ContextRetrievalFailure) + .map_err(|_| SeLinuxError::ContextSetFailure) } else { // If no context provided, set the default SELinux context for the path - SecurityContext::set_default_for_path(path) - .map_err(|_| SeLinuxError::ContextRetrievalFailure) + SecurityContext::set_default_for_path(path).map_err(|_| SeLinuxError::ContextSetFailure) } }