mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
@@ -648,6 +648,10 @@ pub fn quit_gui() {
|
||||
unsafe { gtk_main_quit() };
|
||||
}
|
||||
|
||||
pub fn exec_privileged(args: &[&str]) -> ResultType<Child> {
|
||||
Ok(Command::new("pkexec").args(args).spawn()?)
|
||||
}
|
||||
|
||||
pub fn check_super_user_permission() -> ResultType<bool> {
|
||||
let file = "/usr/share/rustdesk/files/polkit";
|
||||
let arg;
|
||||
@@ -656,11 +660,11 @@ pub fn check_super_user_permission() -> ResultType<bool> {
|
||||
} else {
|
||||
arg = "echo";
|
||||
}
|
||||
let status = Command::new("pkexec").arg(arg).status()?;
|
||||
let status = exec_privileged(&[arg])?.wait()?;
|
||||
Ok(status.success() && status.code() == Some(0))
|
||||
}
|
||||
|
||||
pub fn elevate(args: Vec<&str>) -> ResultType<Option<Child>> {
|
||||
pub fn elevate(args: Vec<&str>) -> ResultType<bool> {
|
||||
let cmd = std::env::current_exe()?;
|
||||
match cmd.to_str() {
|
||||
Some(cmd) => {
|
||||
@@ -670,8 +674,24 @@ pub fn elevate(args: Vec<&str>) -> ResultType<Option<Child>> {
|
||||
if is_opensuse() {
|
||||
args_with_exe.insert(0, "-E");
|
||||
}
|
||||
let task = Command::new("pkexec").args(args_with_exe).spawn()?;
|
||||
Ok(Some(task))
|
||||
let res = match exec_privileged(&args_with_exe)?.wait() {
|
||||
Ok(status) => {
|
||||
if status.success() {
|
||||
true
|
||||
} else {
|
||||
log::error!(
|
||||
"Failed to wait install process, process status: {:?}",
|
||||
status
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to wait install process, error: {}", e);
|
||||
false
|
||||
}
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
None => {
|
||||
hbb_common::bail!("Failed to get current exe as str");
|
||||
|
||||
Reference in New Issue
Block a user