diff --git a/Cargo.lock b/Cargo.lock index 7f7af17..da7eabe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1649,6 +1649,7 @@ dependencies = [ "serde", "serde_derive", "toml", + "users", ] [[package]] @@ -1948,6 +1949,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "users" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +dependencies = [ + "libc", + "log", +] + [[package]] name = "utf16_iter" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index 08bc996..144c2b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ gix = "0.70.0" serde = "1.0.217" serde_derive = "1.0.217" toml = "0.8.20" +users = "0.11.0" diff --git a/src/config.rs b/src/config.rs index e760f4a..f4a79e9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,6 +82,7 @@ impl fmt::Display for ConfigFile { } } +#[derive(PartialEq)] #[derive(Deserialize)] pub struct Config { from: String, @@ -92,11 +93,13 @@ pub struct Config { schedule: Schedule } +#[derive(PartialEq)] #[derive(Deserialize)] struct Git { ssh_identity_file: String, } +#[derive(PartialEq)] #[derive(Deserialize)] struct Schedule { enabled: bool, @@ -135,13 +138,14 @@ pub fn read_config(paths: Vec, refractr: &common::Refractr) -> Vec &'static str { } } -fn main() { +fn main() -> std::io::Result<()> { let args = Args::parse(); let refractr = common::Refractr { verbose: args.verbose, @@ -44,6 +45,15 @@ fn main() { let example = include_str!("example/config.toml"); println!("{}", example); } else { + // warn to avoid root/admin + if refractr.unix { + if users::get_current_uid() == 0 { + eprintln!("refractr: warning: this program should not ran as root") + } + } else { + // TODO: print message for Windows + } + let cfgs = config::read_config(args.config, &refractr); if refractr.verbose >= 2 { // no need to loop over configs if verbose is not at the correct level @@ -54,4 +64,6 @@ fn main() { common::verbose(refractr.verbose, 1, format!("Config file(s) read successfully")); } + + Ok(()) }