-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: utam0k <k0ma@utam0k.jp>
- Loading branch information
Showing
8 changed files
with
479 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum SELinuxError { | ||
#[error("Failed to set file label for SELinux: {0}")] | ||
SetFileLabel(String), | ||
#[error("Failed to lset file label for SELinux: {0}")] | ||
LSetFileLabel(String), | ||
#[error("Failed to get file label for SELinux: {0}")] | ||
FileLabel(String), | ||
#[error("Failed to get lfile label for SELinux: {0}")] | ||
LFileLabel(String), | ||
#[error("Failed to call is_proc_handle for SELinux: {0}")] | ||
IsProcHandle(String), | ||
#[error("Failed to call read_con_fd for SELinux: {0}")] | ||
ReadConFd(String), | ||
#[error("Failed to call read_con for SELinux: {0}")] | ||
ReadCon(String), | ||
#[error("Failed to call write_con for SELinux: {0}")] | ||
WriteCon(String), | ||
#[error("Failed to find the index for a given class: {0}")] | ||
ClassIndex(String), | ||
#[error("Failed to call peer_label for SELinux: {0}")] | ||
PeerLabel(String), | ||
#[error("Failed to call open_context_file for SELinux: {0}")] | ||
OpenContextFile(String), | ||
#[error("Failed to set enforce mode of SELinux: {0}")] | ||
SetEnforceMode(String), | ||
#[error("Failed to read config file of SELinux: {0}")] | ||
GetConfigKey(String), | ||
#[error("Invalid format for SELinux label: {0}")] | ||
InvalidSELinuxLabel(String), | ||
#[error("Failed to load SELinux labels: {0}")] | ||
LoadLabels(String), | ||
#[error("Failed to load SELinux config: {0}")] | ||
LoadConfig(String), | ||
#[error("SELinux setting error: {0}")] | ||
SELinuxSettingError(#[from] SELinuxSettingError), | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum SELinuxSettingError { | ||
#[error("SELinux is not installed")] | ||
NotInstalled, | ||
#[error("Enforce file in SELinux not found: {0}")] | ||
EnforceFileNotFound(PathBuf), | ||
#[error("Invalid SELinux mode: {0}")] | ||
InvalidMode(String), | ||
#[error("Failed to set enforce mode of SELinux: {0}")] | ||
SetEnforceMode(String), | ||
#[error("Failed to load SELinux config: {0}")] | ||
LoadConfig(String), | ||
#[error("Failed to read config file of SELinux: {0}")] | ||
GetConfigKey(String), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
pub mod error; | ||
pub mod label; | ||
pub mod mode; | ||
pub mod selinux; | ||
pub mod selinux_label; | ||
pub mod setting; | ||
pub mod tools; | ||
|
||
pub use error::*; | ||
pub use mode::SELinuxMode; | ||
pub use selinux::SELinux; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::fmt; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum SELinuxMode { | ||
// ENFORCING constant to indicate SELinux is in enforcing mode | ||
ENFORCING = 1, | ||
// PERMISSIVE constant to indicate SELinux is in permissive mode | ||
PERMISSIVE = 0, | ||
// DISABLED constant to indicate SELinux is disabled | ||
DISABLED = -1, | ||
} | ||
|
||
impl From<i32> for SELinuxMode { | ||
fn from(mode: i32) -> Self { | ||
match mode { | ||
1 => SELinuxMode::ENFORCING, | ||
0 => SELinuxMode::PERMISSIVE, | ||
-1 => SELinuxMode::DISABLED, | ||
_ => SELinuxMode::DISABLED, | ||
} | ||
} | ||
} | ||
|
||
impl From<&str> for SELinuxMode { | ||
fn from(mode: &str) -> Self { | ||
match mode { | ||
"enforcing" => SELinuxMode::ENFORCING, | ||
"permissive" => SELinuxMode::PERMISSIVE, | ||
_ => SELinuxMode::DISABLED, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for SELinuxMode { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
let s = match self { | ||
SELinuxMode::ENFORCING => "enforcing", | ||
SELinuxMode::PERMISSIVE => "permissive", | ||
SELinuxMode::DISABLED => "disabled", | ||
}; | ||
write!(f, "{}", s) | ||
} | ||
} | ||
|
||
impl SELinuxMode { | ||
pub fn as_bytes(&self) -> &[u8] { | ||
match self { | ||
SELinuxMode::ENFORCING => b"1", | ||
SELinuxMode::PERMISSIVE => b"0", | ||
SELinuxMode::DISABLED => b"-1", | ||
} | ||
} | ||
} |
Oops, something went wrong.