diff --git a/userspace/ksud/src/event.rs b/userspace/ksud/src/event.rs index c2a1514e..ccce392b 100644 --- a/userspace/ksud/src/event.rs +++ b/userspace/ksud/src/event.rs @@ -245,7 +245,7 @@ pub fn on_boot_completed() -> Result<()> { pub fn install() -> Result<()> { ensure_dir_exists(defs::ADB_DIR)?; std::fs::copy("/proc/self/exe", defs::DAEMON_PATH)?; - restorecon::setcon(defs::DAEMON_PATH, restorecon::ADB_CON)?; + restorecon::lsetfilecon(defs::DAEMON_PATH, restorecon::ADB_CON)?; // install binary assets assets::ensure_binaries().with_context(|| "Failed to extract assets")?; diff --git a/userspace/ksud/src/restorecon.rs b/userspace/ksud/src/restorecon.rs index 93b984be..97571eda 100644 --- a/userspace/ksud/src/restorecon.rs +++ b/userspace/ksud/src/restorecon.rs @@ -1,3 +1,4 @@ +use crate::defs; use anyhow::Result; use jwalk::{Parallelism::Serial, WalkDir}; use std::path::Path; @@ -5,15 +6,15 @@ use std::path::Path; #[cfg(any(target_os = "linux", target_os = "android"))] use anyhow::{Context, Ok}; #[cfg(any(target_os = "linux", target_os = "android"))] -use extattr::{setxattr, Flags as XattrFlags}; +use extattr::{lsetxattr, Flags as XattrFlags}; pub const SYSTEM_CON: &str = "u:object_r:system_file:s0"; pub const ADB_CON: &str = "u:object_r:adb_data_file:s0"; const SELINUX_XATTR: &str = "security.selinux"; -pub fn setcon>(path: P, con: &str) -> Result<()> { +pub fn lsetfilecon>(path: P, con: &str) -> Result<()> { #[cfg(any(target_os = "linux", target_os = "android"))] - setxattr(&path, SELINUX_XATTR, con, XattrFlags::empty()).with_context(|| { + lsetxattr(&path, SELINUX_XATTR, con, XattrFlags::empty()).with_context(|| { format!( "Failed to change SELinux context for {}", path.as_ref().display() @@ -24,7 +25,7 @@ pub fn setcon>(path: P, con: &str) -> Result<()> { #[cfg(any(target_os = "linux", target_os = "android"))] pub fn setsyscon>(path: P) -> Result<()> { - setcon(path, SYSTEM_CON) + lsetfilecon(path, SYSTEM_CON) } #[cfg(not(any(target_os = "linux", target_os = "android")))] @@ -35,10 +36,7 @@ pub fn setsyscon>(path: P) -> Result<()> { pub fn restore_syscon>(dir: P) -> Result<()> { for dir_entry in WalkDir::new(dir).parallelism(Serial) { if let Some(path) = dir_entry.ok().map(|dir_entry| dir_entry.path()) { - #[cfg(any(target_os = "linux", target_os = "android"))] - setxattr(&path, SELINUX_XATTR, SYSTEM_CON, XattrFlags::empty()).with_context(|| { - format!("Failed to change SELinux context for {}", path.display()) - })?; + setsyscon(&path)?; } } Ok(())