From de24d5499ac83f426228b28b90bed8f26e68fb3b Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Fri, 11 Nov 2022 09:56:48 -0500 Subject: doc string, refactor, config token error --- src/main.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/main.rs') 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..]); -- cgit v1.2.3-freya