-
Notifications
You must be signed in to change notification settings - Fork 347
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: Hiroyuki Moriya <[email protected]>
- Loading branch information
EC2 Default User
committed
Aug 3, 2024
1 parent
f0da9cb
commit d4b48cd
Showing
7 changed files
with
82 additions
and
21 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 |
---|---|---|
@@ -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(()) | ||
} |
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