ksud: fix selinux unlabeled of modules dir

This commit is contained in:
tiann
2023-01-05 16:58:00 +08:00
parent 06cc677278
commit ea3cfbd0ca
2 changed files with 15 additions and 1 deletions

View File

@@ -6,6 +6,18 @@ use subprocess::Exec;
const SYSTEM_CON: &str = "u:object_r:system_file:s0";
const _ADB_CON: &str = "u:object_r:adb_data_file:s0";
pub fn setcon(path: &str, con: &str) -> Result<()> {
// todo use libselinux directly
let cmd = format!("chcon {} {}", con, path);
let result = Exec::shell(cmd).join()?;
ensure!(result.success(), "chcon for: {} failed.", path);
Ok(())
}
pub fn setsyscon(path: &str) -> Result<()> {
setcon(path, SYSTEM_CON)
}
pub fn restore_syscon(dir: &str) -> Result<()> {
// todo use libselinux directly
let cmd = format!("chcon -R {} {}", SYSTEM_CON, dir);