windows now works

This commit is contained in:
Bryson Steck 2025-03-15 17:37:54 -06:00
parent c1d5b9fed6
commit e64c1eda93
Signed by: bryson
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4
2 changed files with 19 additions and 11 deletions

View file

@ -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]

View file

@ -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)