diff --git a/Cargo.toml b/Cargo.toml index cc4c00a..900222b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ serde = "1.0.217" serde_derive = "1.0.217" sha2 = "0.10.8" toml = "0.8.20" -[target.'cfg(not(target_family = "unix"))'.dependencies] +[target.'cfg(target_family = "windows")'.dependencies] username = "0.2.0" [target.'cfg(target_family = "unix")'.dependencies] diff --git a/src/main.rs b/src/main.rs index 990eea4..d908081 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; use std::process; #[cfg(target_family = "unix")] use users; -#[cfg(not(target_family = "unix"))] +#[cfg(target_family = "windows")] use username; #[derive(Parser)] @@ -55,6 +55,23 @@ fn main() -> Result<(), String> { verbose: args.verbose }; + // warn to avoid root/admin + // unix-like + #[cfg(target_family = "unix")] + if users::get_current_uid() == 0 { + common::warning(format!("this program should not ran as root")); + } + // windows + #[cfg(target_family = "windows")] + match username::get_user_name() { + Ok(user) => { + if user.contains("Administrator") || user.contains("SYSTEM") { + common::warning(format!("this program should not ran as {}", user)); + } + }, + Err(_) => common::warning(format!("failed to get process username")), + } + common::verbose(refractr.verbose, 1, format!("Level {} verbosity enabled", refractr.verbose.to_string())); common::verbose(refractr.verbose, 3, format!("Process ID: {}", refractr.pid)); common::verbose(refractr.verbose, 3, format!("Running in Docker: {}", refractr.docker)); @@ -65,15 +82,6 @@ fn main() -> Result<(), String> { println!("{}", example); Ok(()) } else { - // warn to avoid root/admin - if refractr.unix { - if users::get_current_uid() == 0 { - common::warning(format!("this program should not ran as root")); - } - } else { - // TODO: print message for Windows - } - let cfgs = match config::read_config(args.config, &refractr) { Ok(cfgs) => cfgs, Err(e) => freak_out!(e)