Feat: Ersetzt is_run_as_root durch die Implementation von Crate sudo_ctdra

This commit is contained in:
2026-08-26 19:13:36 +02:00
parent 34f61bba5f
commit bf32d82ae7
3 changed files with 12 additions and 24 deletions
Generated
+10 -1
View File
@@ -13,8 +13,8 @@ name = "config-ctdra"
version = "1.0.2"
dependencies = [
"confy",
"libc",
"serde",
"sudo-ctdra",
]
[[package]]
@@ -141,6 +141,15 @@ dependencies = [
"serde_core",
]
[[package]]
name = "sudo-ctdra"
version = "1.0.0"
source = "sparse+https://gitea.creative-dragonslayer.de/api/packages/Rust-Crates/cargo/"
checksum = "2c2746122bbe36f821de70db3ca4ad24edfb77118fc6a6bc7693082b50d23e5f"
dependencies = [
"libc",
]
[[package]]
name = "syn"
version = "3.0.4"
+1 -1
View File
@@ -11,7 +11,7 @@ description = "Einfache, threadsichere Konfigurationsverwaltung für Rust mit au
[dependencies]
confy = "2.0.0"
serde = { version = "1.0.229", features = ["derive"] }
libc = "1.0.0-alpha.4"
sudo-ctdra = { version = "1.0.0", registry = "gitea" }
[profile.release]
debug = "none"
+1 -22
View File
@@ -36,6 +36,7 @@ use std::sync::{OnceLock, RwLock};
pub use confy::ConfyError;
use serde::de::DeserializeOwned;
use serde::Serialize;
use sudo_ctdra::is_run_as_root;
/// Optionaler benutzerdefinierter Programmname für die Konfigurationspfade.
static PROGRAM_NAME: OnceLock<RwLock<Option<String>>> = OnceLock::new();
@@ -56,28 +57,6 @@ static GLOBAL_CONFIGS: OnceLock<RwLock<HashMap<TypeId, &'static (dyn Any + Send
/// Standardname für Konfigurationsdateien.
const DEFAULT_CONFIG_NAME: &str = "config";
/// Prüft, ob das Programm mit Root-/Administrator-Rechten ausgeführt wird.
///
/// # Returns
///
/// * `true` - Das Programm läuft mit erhöhten Rechten (z. B. UID 0 unter Linux/Unix)
/// * `false` - Das Programm läuft mit normalen Benutzerrechten
pub fn is_run_as_root() -> bool {
#[cfg(target_os = "windows")]
{
std::process::Command::new("net")
.args(["session"])
.output()
.map(|output| output.status.success())
.unwrap_or(false)
}
#[cfg(not(target_os = "windows"))]
{
unsafe { libc::geteuid() == 0 }
}
}
/// Setzt den Programmnamen für die Pfadermittlung explizit.
pub fn set_program_name(name: impl Into<String>) {
let lock = PROGRAM_NAME.get_or_init(|| RwLock::new(None));