diff options
author | tylermurphy534 <tylermurphy534@gmail.com> | 2022-11-11 09:56:48 -0500 |
---|---|---|
committer | tylermurphy534 <tylermurphy534@gmail.com> | 2022-11-11 09:56:48 -0500 |
commit | de24d5499ac83f426228b28b90bed8f26e68fb3b (patch) | |
tree | 7a37f98005e8337d078db9edf1fec89de4a98f04 /src/main.rs | |
parent | update config format (diff) | |
download | crab-de24d5499ac83f426228b28b90bed8f26e68fb3b.tar.gz crab-de24d5499ac83f426228b28b90bed8f26e68fb3b.tar.bz2 crab-de24d5499ac83f426228b28b90bed8f26e68fb3b.zip |
doc string, refactor, config token error
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index cca85de..56df611 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,10 +8,11 @@ mod persist; mod secure; -const ERROR_ARGS: u8 = 1; -const ERROR_CONFIG: u8 = 2; -const ERROR_NOT_AUTHORIZED: u8 = 3; -const ERROR_AUTH_FAILED: u8 = 4; +const ERROR_ARGS: u8 = 1; +const ERROR_CONFIG: u8 = 2; +const ERROR_NOT_AUTHORIZED: u8 = 3; +const ERROR_AUTH_FAILED: u8 = 4; +const ERROR_ELEVATE_PRIVILEGES: u8 = 5; fn main() -> ExitCode { @@ -69,6 +70,12 @@ fn main() -> ExitCode { return ExitCode::from(ERROR_AUTH_FAILED); } + // elevate privileges + if nix::unistd::setuid(configs[auth].privlaged_uid).is_err() { + eprintln!("Failed to elevate privileges."); + return ExitCode::from(ERROR_ELEVATE_PRIVILEGES); + }; + // execute the passed command let start = 1 + flags.arg_count; let err = exec::execvp(&args[start], &args[start..]); |