-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selinux: implemented remaining selinux functions (#2850)
* added selinux functions Signed-off-by: Hiroyuki Moriya <[email protected]> * not use arc Signed-off-by: Hiroyuki Moriya <[email protected]> * follow reviewer comment Signed-off-by: Hiroyuki Moriya <[email protected]> * divided selinux impl into two files Signed-off-by: Hiroyuki Moriya <[email protected]> * fix Signed-off-by: Hiroyuki Moriya <[email protected]> * fix Signed-off-by: Hiroyuki Moriya <[email protected]> * fix Signed-off-by: Hiroyuki Moriya <[email protected]> * use SELinuxLabel struct Signed-off-by: Hiroyuki Moriya <[email protected]> * use pointer instead of clone Signed-off-by: Hiroyuki Moriya <[email protected]> * not loop Signed-off-by: Hiroyuki Moriya <[email protected]> * add main.rs Signed-off-by: Hiroyuki Moriya <[email protected]> --------- Signed-off-by: Hiroyuki Moriya <[email protected]>
- Loading branch information
Showing
11 changed files
with
883 additions
and
287 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,2 +1,5 @@ | ||
pub mod selinux; | ||
pub mod xattrs; | ||
pub mod selinux_label; | ||
pub mod tools; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use anyhow::Result; | ||
use selinux::selinux::*; | ||
use selinux::selinux_label::*; | ||
use std::fs::File; | ||
use std::path::Path; | ||
|
||
fn main() -> Result<()> { | ||
let mut selinux_instance: SELinux = SELinux::new(); | ||
|
||
if selinux_instance.get_enabled() { | ||
println!("selinux is enabled"); | ||
} else { | ||
println!("selinux is not enabled"); | ||
|
||
match selinux_instance.set_enforce_mode(SELinuxMode::PERMISSIVE) { | ||
Ok(_) => println!("set selinux mode as permissive"), | ||
Err(e) => println!("{}", e), | ||
} | ||
} | ||
println!( | ||
"default enforce mode is: {}", | ||
selinux_instance.default_enforce_mode() | ||
); | ||
println!( | ||
"current enforce mode is: {}", | ||
selinux_instance.enforce_mode() | ||
); | ||
|
||
match selinux_instance.current_label() { | ||
Ok(l) => println!("SELinux label of current process is: {}", l), | ||
Err(e) => println!("{}", e), | ||
} | ||
|
||
let file_path = Path::new("./test_file.txt"); | ||
let _file = File::create(file_path)?; | ||
let selinux_label = | ||
SELinuxLabel::try_from("unconfined_u:object_r:public_content_t:s1".to_string())?; | ||
SELinux::set_file_label(file_path, selinux_label)?; | ||
let current_label = SELinux::file_label(file_path)?; | ||
println!("file label is {}", current_label); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.