diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs index ed89e76..cca85de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use std::env; use std::process::ExitCode; -use pwd::Passwd; mod auth; @@ -11,9 +10,8 @@ mod secure; const ERROR_ARGS: u8 = 1; const ERROR_CONFIG: u8 = 2; -const ERROR_NO_USER: u8 = 3; -const ERROR_NOT_AUTHORIZED: u8 = 4; -const ERROR_AUTH_FAILED: u8 = 5; +const ERROR_NOT_AUTHORIZED: u8 = 3; +const ERROR_AUTH_FAILED: u8 = 4; fn main() -> ExitCode { @@ -33,7 +31,7 @@ fn main() -> ExitCode { // If the version arg flag is set, print the crab version if flags.version { - println!("crab version 0.0.5"); + println!("crab version 0.0.6"); return ExitCode::SUCCESS; } @@ -50,23 +48,15 @@ fn main() -> ExitCode { } // Load the command config from /etc - let config = match auth::load_config("/etc/crab.conf") { + let configs = match auth::load_config_file("/etc/crab.conf") { Some(data) => data, None => return ExitCode::from(ERROR_CONFIG) }; - // get the current user login - let user = match Passwd::current_user() { - Some(data) => data, - None => { - eprintln!("You dont exist."); - return ExitCode::from(ERROR_NO_USER); - } - }; // check if the user is authorized - let persist = match auth::authorize(&config, &user.name) { - Some(data) => data && !flags.dont_persist, + let auth = match auth::authorize(&configs, nix::unistd::getuid()) { + Some(data) => data, None => { eprintln!("Operation Not Permitted."); return ExitCode::from(ERROR_NOT_AUTHORIZED); @@ -74,7 +64,7 @@ fn main() -> ExitCode { }; // authenticate the user - if !auth::authenticate(&user.name, persist) { + if !auth::authenticate(&configs[auth], flags.dont_persist, nix::unistd::getuid()) { eprintln!("Authentication failed."); return ExitCode::from(ERROR_AUTH_FAILED); } |