mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
refactor(linux): replace users crate with libc::geteuid for root detection
Closes #5333
This commit is contained in:
11
src-tauri/Cargo.lock
generated
11
src-tauri/Cargo.lock
generated
@@ -1158,7 +1158,6 @@ dependencies = [
|
|||||||
"tauri-plugin-window-state",
|
"tauri-plugin-window-state",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"users",
|
|
||||||
"warp",
|
"warp",
|
||||||
"winapi",
|
"winapi",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
@@ -8699,16 +8698,6 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "users"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf-8"
|
name = "utf-8"
|
||||||
version = "0.7.6"
|
version = "0.7.6"
|
||||||
|
|||||||
@@ -112,9 +112,6 @@ windows-sys = { version = "0.61.2", features = [
|
|||||||
"Win32_UI_WindowsAndMessaging",
|
"Win32_UI_WindowsAndMessaging",
|
||||||
] }
|
] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
|
||||||
users = "0.11.0"
|
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
signal-hook = "0.3.18"
|
signal-hook = "0.3.18"
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ async fn reinstall_service() -> Result<()> {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
async fn uninstall_service() -> Result<()> {
|
async fn uninstall_service() -> Result<()> {
|
||||||
logging!(info, Type::Service, "uninstall service");
|
logging!(info, Type::Service, "uninstall service");
|
||||||
use users::get_effective_uid;
|
|
||||||
|
|
||||||
let uninstall_path =
|
let uninstall_path =
|
||||||
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-uninstall");
|
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-uninstall");
|
||||||
@@ -134,13 +133,14 @@ async fn uninstall_service() -> Result<()> {
|
|||||||
let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ ");
|
let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ ");
|
||||||
|
|
||||||
let elevator = crate::utils::help::linux_elevator();
|
let elevator = crate::utils::help::linux_elevator();
|
||||||
let status = match get_effective_uid() {
|
let status = if linux_running_as_root() {
|
||||||
0 => StdCommand::new(uninstall_shell).status()?,
|
StdCommand::new(&uninstall_path).status()?
|
||||||
_ => StdCommand::new(elevator)
|
} else {
|
||||||
|
StdCommand::new(elevator)
|
||||||
.arg("sh")
|
.arg("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(uninstall_shell)
|
.arg(uninstall_shell)
|
||||||
.status()?,
|
.status()?
|
||||||
};
|
};
|
||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
@@ -163,7 +163,6 @@ async fn uninstall_service() -> Result<()> {
|
|||||||
#[allow(clippy::unused_async)]
|
#[allow(clippy::unused_async)]
|
||||||
async fn install_service() -> Result<()> {
|
async fn install_service() -> Result<()> {
|
||||||
logging!(info, Type::Service, "install service");
|
logging!(info, Type::Service, "install service");
|
||||||
use users::get_effective_uid;
|
|
||||||
|
|
||||||
let install_path =
|
let install_path =
|
||||||
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-install");
|
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-install");
|
||||||
@@ -175,13 +174,14 @@ async fn install_service() -> Result<()> {
|
|||||||
let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ ");
|
let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ ");
|
||||||
|
|
||||||
let elevator = crate::utils::help::linux_elevator();
|
let elevator = crate::utils::help::linux_elevator();
|
||||||
let status = match get_effective_uid() {
|
let status = if linux_running_as_root() {
|
||||||
0 => StdCommand::new(install_shell).status()?,
|
StdCommand::new(&install_path).status()?
|
||||||
_ => StdCommand::new(elevator)
|
} else {
|
||||||
|
StdCommand::new(elevator)
|
||||||
.arg("sh")
|
.arg("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(install_shell)
|
.arg(install_shell)
|
||||||
.status()?,
|
.status()?
|
||||||
};
|
};
|
||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
@@ -218,6 +218,13 @@ async fn reinstall_service() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn linux_running_as_root() -> bool {
|
||||||
|
const ROOT_UID: u32 = 0;
|
||||||
|
|
||||||
|
unsafe { libc::geteuid() == ROOT_UID }
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
async fn uninstall_service() -> Result<()> {
|
async fn uninstall_service() -> Result<()> {
|
||||||
use crate::utils::i18n::t;
|
use crate::utils::i18n::t;
|
||||||
|
|||||||
Reference in New Issue
Block a user