mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
check super permission: win && linux
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -629,3 +629,9 @@ extern "C" {
|
||||
pub fn quit_gui() {
|
||||
unsafe { gtk_main_quit() };
|
||||
}
|
||||
|
||||
pub fn check_super_user_permission() -> ResultType<bool> {
|
||||
// TODO: replace echo with a rustdesk's program, which is location-fixed and non-gui.
|
||||
let status = std::process::Command::new("pkexec").arg("echo").status()?;
|
||||
Ok(status.success() && status.code() == Some(0))
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use hbb_common::{
|
||||
};
|
||||
use std::io::prelude::*;
|
||||
use std::{
|
||||
ffi::OsString,
|
||||
ffi::{CString, OsString},
|
||||
fs, io, mem,
|
||||
sync::{Arc, Mutex},
|
||||
time::{Duration, Instant},
|
||||
@@ -17,7 +17,8 @@ use winapi::{
|
||||
shared::{minwindef::*, ntdef::NULL, windef::*},
|
||||
um::{
|
||||
errhandlingapi::GetLastError, handleapi::CloseHandle, minwinbase::STILL_ACTIVE,
|
||||
processthreadsapi::GetExitCodeProcess, winbase::*, wingdi::*, winnt::HANDLE, winuser::*,
|
||||
processthreadsapi::GetExitCodeProcess, shellapi::ShellExecuteA, winbase::*, wingdi::*,
|
||||
winnt::HANDLE, winuser::*,
|
||||
},
|
||||
};
|
||||
use windows_service::{
|
||||
@@ -1418,3 +1419,17 @@ pub fn get_user_token(session_id: u32, as_user: bool) -> HANDLE {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_super_user_permission() -> ResultType<bool> {
|
||||
unsafe {
|
||||
let ret = ShellExecuteA(
|
||||
NULL as _,
|
||||
CString::new("runas")?.as_ptr() as _,
|
||||
CString::new("cmd")?.as_ptr() as _,
|
||||
CString::new("/c /q")?.as_ptr() as _,
|
||||
NULL as _,
|
||||
SW_SHOWNORMAL,
|
||||
);
|
||||
return Ok(ret as i32 > 32);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user