From 6c22a7372d1eb3e18754f1ea222fc8ebb21a5c36 Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:09:41 +0400 Subject: [PATCH 1/7] Checking requirements in script Checking requirements for sudo users in script --- client/server_scripts/check_user_in_sudo.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/server_scripts/check_user_in_sudo.sh b/client/server_scripts/check_user_in_sudo.sh index e7ee953c..29758d02 100644 --- a/client/server_scripts/check_user_in_sudo.sh +++ b/client/server_scripts/check_user_in_sudo.sh @@ -1,2 +1,3 @@ +echo $LC_MESSAGES | grep -qE "en_US.UTF-8|C.UTF-8" || export LC_MESSAGES=C.UTF-8;\ CUR_USER=$(whoami);\ -groups $CUR_USER \ No newline at end of file +groups $CUR_USER | grep sudo && sudo -n -u $CUR_USER sh -c "sudo -n uname 2>&1 > /dev/null" From ae681ad6d2496395303ce2d1e14c4d80de079ece Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Sun, 27 Oct 2024 15:33:08 +0400 Subject: [PATCH 2/7] simplification --- client/server_scripts/check_user_in_sudo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/server_scripts/check_user_in_sudo.sh b/client/server_scripts/check_user_in_sudo.sh index 29758d02..a5922c85 100644 --- a/client/server_scripts/check_user_in_sudo.sh +++ b/client/server_scripts/check_user_in_sudo.sh @@ -1,3 +1,3 @@ echo $LC_MESSAGES | grep -qE "en_US.UTF-8|C.UTF-8" || export LC_MESSAGES=C.UTF-8;\ CUR_USER=$(whoami);\ -groups $CUR_USER | grep sudo && sudo -n -u $CUR_USER sh -c "sudo -n uname 2>&1 > /dev/null" +groups $CUR_USER | grep sudo && sudo -nu $CUR_USER sudo -n uname > /dev/null From 43fd9d5d90f97ea130279148237163c973a7f557 Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:33:01 +0400 Subject: [PATCH 3/7] Adding error handling Adding error handling in the server controller for: Sudo package is not pre-installed for sudo users. Server user or associated group is not listed in the sudoers file. Server user password required --- client/core/controllers/serverController.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/core/controllers/serverController.cpp b/client/core/controllers/serverController.cpp index b6795a01..2ae3086e 100644 --- a/client/core/controllers/serverController.cpp +++ b/client/core/controllers/serverController.cpp @@ -770,6 +770,12 @@ ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, D if (!stdOut.contains("sudo")) return ErrorCode::ServerUserNotInSudo; + if (stdErr.contains("command not found")) + return ErrorCode::SudoPackageIsNotPreinstalled; + if (stdErr.contains("sudoers")) + return ErrorCode::ServerUserNotInSudoers; + if (stdErr.contains("password is required")) + return ErrorCode::ServerUserPasswordRequired; return error; } From 8ec4232a96e6d3fd336fae23066a1f8d2d0cbaf6 Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:17:06 +0400 Subject: [PATCH 4/7] Renaming one of the errors --- client/core/controllers/serverController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/core/controllers/serverController.cpp b/client/core/controllers/serverController.cpp index 2ae3086e..7183fa35 100644 --- a/client/core/controllers/serverController.cpp +++ b/client/core/controllers/serverController.cpp @@ -773,7 +773,7 @@ ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, D if (stdErr.contains("command not found")) return ErrorCode::SudoPackageIsNotPreinstalled; if (stdErr.contains("sudoers")) - return ErrorCode::ServerUserNotInSudoers; + return ErrorCode::ServerUserNotListedInSudoers; if (stdErr.contains("password is required")) return ErrorCode::ServerUserPasswordRequired; From b38225746041917e194c83a58dd714f239ffae0b Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:19:15 +0400 Subject: [PATCH 5/7] adding error codes --- client/core/defs.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/core/defs.h b/client/core/defs.h index d00d347b..13f881b7 100644 --- a/client/core/defs.h +++ b/client/core/defs.h @@ -56,6 +56,9 @@ namespace amnezia ServerCancelInstallation = 204, ServerUserNotInSudo = 205, ServerPacketManagerError = 206, + SudoPackageIsNotPreinstalled = 207, + ServerUserNotListedInSudoers = 208, + ServerUserPasswordRequired = 209, // Ssh connection errors SshRequestDeniedError = 300, From fbf11c168911e60e79cceb08386753f3c701e735 Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:48:13 +0400 Subject: [PATCH 6/7] added extended error descriptions --- client/core/errorstrings.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/core/errorstrings.cpp b/client/core/errorstrings.cpp index 49534606..7867ac5a 100644 --- a/client/core/errorstrings.cpp +++ b/client/core/errorstrings.cpp @@ -21,6 +21,9 @@ QString errorString(ErrorCode code) { case(ErrorCode::ServerCancelInstallation): errorMessage = QObject::tr("Installation canceled by user"); break; case(ErrorCode::ServerUserNotInSudo): errorMessage = QObject::tr("The user does not have permission to use sudo"); break; case(ErrorCode::ServerPacketManagerError): errorMessage = QObject::tr("Server error: Packet manager error"); break; + case(ErrorCode::SudoPackageIsNotPreinstalled): errorMessage = QObject::tr("The sudo package is not pre-installed"); break; + case(ErrorCode::ServerUserNotListedInSudoers): errorMessage = QObject::tr("The user is not listed in sudoers"); break; + case(ErrorCode::ServerUserPasswordRequired): errorMessage = QObject::tr("The user's password is required"); break; // Libssh errors case(ErrorCode::SshRequestDeniedError): errorMessage = QObject::tr("SSH request was denied"); break; From d85e4a413a45254aa4208fe10f61c682b4ec35c3 Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:18:42 +0400 Subject: [PATCH 7/7] changing stdErr to stdOut --- client/core/controllers/serverController.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/core/controllers/serverController.cpp b/client/core/controllers/serverController.cpp index 7183fa35..e74bd02b 100644 --- a/client/core/controllers/serverController.cpp +++ b/client/core/controllers/serverController.cpp @@ -770,11 +770,11 @@ ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, D if (!stdOut.contains("sudo")) return ErrorCode::ServerUserNotInSudo; - if (stdErr.contains("command not found")) + if (stdOut.contains("command not found")) return ErrorCode::SudoPackageIsNotPreinstalled; - if (stdErr.contains("sudoers")) + if (stdOut.contains("sudoers")) return ErrorCode::ServerUserNotListedInSudoers; - if (stdErr.contains("password is required")) + if (stdOut.contains("password is required")) return ErrorCode::ServerUserPasswordRequired; return error;