From c9567f20e4873eae9c4bf24c310e0accd996b744 Mon Sep 17 00:00:00 2001 From: Master Date: Mon, 29 Jun 2020 23:54:53 -0400 Subject: [PATCH] fix uid/gid set order --- src/Sproc/Sproc.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Sproc/Sproc.cpp b/src/Sproc/Sproc.cpp index 5d0b815..cf0b04d 100644 --- a/src/Sproc/Sproc.cpp +++ b/src/Sproc/Sproc.cpp @@ -78,14 +78,6 @@ int Sproc::execute(std::string run_as, std::string group, std::string command ) if ( pid == 0 ) { // child process - if ( seteuid( run_as_uid ) == 0 ) - { - slog.log( E_INFO, "Successfully set UID to '" + std::to_string(run_as_uid) + "' (" + run_as + ")." ); - } else { - slog.log( E_FATAL, "Failed to set UID. Panicking." ); - return -401; - } - int setegidval = setegid( run_as_gid ); if ( setegidval == 0 ) { @@ -94,6 +86,15 @@ int Sproc::execute(std::string run_as, std::string group, std::string command ) slog.log( E_FATAL, "Failed to set GID. Panicking. (setegid: " + std::to_string( setegidval ) + "/" + std::to_string(errno) + ")" ); return -401; } + + if ( seteuid( run_as_uid ) == 0 ) + { + slog.log( E_INFO, "Successfully set UID to '" + std::to_string(run_as_uid) + "' (" + run_as + ")." ); + } else { + slog.log( E_FATAL, "Failed to set UID. Panicking." ); + return -401; + } + exit_code_raw = system( command.c_str() ); exit( WEXITSTATUS( exit_code_raw ) ); } else if ( pid > 0 )