1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

set_selinux_security_context: match GNU's error

This commit is contained in:
Sylvestre Ledru 2025-04-26 11:16:22 +02:00
parent 8d94add393
commit 595f56a9e7
3 changed files with 8 additions and 7 deletions

View file

@ -19,8 +19,8 @@ pub enum SeLinuxError {
#[error("Failed to retrieve the security context")] #[error("Failed to retrieve the security context")]
ContextRetrievalFailure, ContextRetrievalFailure,
#[error("Failed to set the security context")] #[error("failed to set default file creation context to {0}")]
ContextSetFailure, ContextSetFailure(String),
#[error("Invalid context string or conversion failure")] #[error("Invalid context string or conversion failure")]
ContextConversionFailure, ContextConversionFailure,
@ -32,7 +32,7 @@ impl From<SeLinuxError> for i32 {
SeLinuxError::SELinuxNotEnabled => 1, SeLinuxError::SELinuxNotEnabled => 1,
SeLinuxError::FileOpenFailure => 2, SeLinuxError::FileOpenFailure => 2,
SeLinuxError::ContextRetrievalFailure => 3, SeLinuxError::ContextRetrievalFailure => 3,
SeLinuxError::ContextSetFailure => 4, SeLinuxError::ContextSetFailure(_) => 4,
SeLinuxError::ContextConversionFailure => 5, SeLinuxError::ContextConversionFailure => 5,
} }
} }
@ -113,10 +113,11 @@ pub fn set_selinux_security_context(
false, false,
) )
.set_for_path(path, false, false) .set_for_path(path, false, false)
.map_err(|_| SeLinuxError::ContextSetFailure) .map_err(|_| SeLinuxError::ContextSetFailure(ctx_str.to_string()))
} else { } else {
// If no context provided, set the default SELinux context for the path // If no context provided, set the default SELinux context for the path
SecurityContext::set_default_for_path(path).map_err(|_| SeLinuxError::ContextSetFailure) SecurityContext::set_default_for_path(path)
.map_err(|_| SeLinuxError::ContextSetFailure("".to_string()))
} }
} }

View file

@ -160,7 +160,7 @@ fn test_mkfifo_selinux_invalid() {
.arg(arg) .arg(arg)
.arg(dest) .arg(dest)
.fails() .fails()
.stderr_contains("Failed to"); .stderr_contains("failed to");
if at.file_exists(dest) { if at.file_exists(dest) {
at.remove(dest); at.remove(dest);
} }

View file

@ -187,7 +187,7 @@ fn test_mknod_selinux_invalid() {
.arg(dest) .arg(dest)
.arg("p") .arg("p")
.fails() .fails()
.stderr_contains("Failed to"); .stderr_contains("failed to");
if at.file_exists(dest) { if at.file_exists(dest) {
at.remove(dest); at.remove(dest);
} }