mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
set_selinux_security_context split the ContextRetrievalFailure error in two
This commit is contained in:
parent
3bc267902c
commit
8d94add393
1 changed files with 8 additions and 5 deletions
|
@ -16,9 +16,12 @@ pub enum SeLinuxError {
|
||||||
#[error("Failed to open the file")]
|
#[error("Failed to open the file")]
|
||||||
FileOpenFailure,
|
FileOpenFailure,
|
||||||
|
|
||||||
#[error("Failed to retrieve or set the security context")]
|
#[error("Failed to retrieve the security context")]
|
||||||
ContextRetrievalFailure,
|
ContextRetrievalFailure,
|
||||||
|
|
||||||
|
#[error("Failed to set the security context")]
|
||||||
|
ContextSetFailure,
|
||||||
|
|
||||||
#[error("Invalid context string or conversion failure")]
|
#[error("Invalid context string or conversion failure")]
|
||||||
ContextConversionFailure,
|
ContextConversionFailure,
|
||||||
}
|
}
|
||||||
|
@ -29,7 +32,8 @@ impl From<SeLinuxError> for i32 {
|
||||||
SeLinuxError::SELinuxNotEnabled => 1,
|
SeLinuxError::SELinuxNotEnabled => 1,
|
||||||
SeLinuxError::FileOpenFailure => 2,
|
SeLinuxError::FileOpenFailure => 2,
|
||||||
SeLinuxError::ContextRetrievalFailure => 3,
|
SeLinuxError::ContextRetrievalFailure => 3,
|
||||||
SeLinuxError::ContextConversionFailure => 4,
|
SeLinuxError::ContextSetFailure => 4,
|
||||||
|
SeLinuxError::ContextConversionFailure => 5,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,11 +113,10 @@ pub fn set_selinux_security_context(
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.set_for_path(path, false, false)
|
.set_for_path(path, false, false)
|
||||||
.map_err(|_| SeLinuxError::ContextRetrievalFailure)
|
.map_err(|_| SeLinuxError::ContextSetFailure)
|
||||||
} 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)
|
SecurityContext::set_default_for_path(path).map_err(|_| SeLinuxError::ContextSetFailure)
|
||||||
.map_err(|_| SeLinuxError::ContextRetrievalFailure)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue