Skip to content

Commit

Permalink
Checking requirements in script (#1210)
Browse files Browse the repository at this point in the history
* Checking requirements in script

Checking requirements for sudo users in script

* 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

* adding error codes

* added extended error descriptions
  • Loading branch information
lunardunno authored Nov 16, 2024
1 parent 9695a5b commit 0de55d8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions client/core/controllers/serverController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,12 @@ ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, D

if (!stdOut.contains("root :") && !stdOut.contains(" sudo") && !stdOut.contains(" wheel"))
return ErrorCode::ServerUserNotInSudo;
if (stdOut.contains("command not found"))
return ErrorCode::SudoPackageIsNotPreinstalled;
if (stdOut.contains("sudoers"))
return ErrorCode::ServerUserNotListedInSudoers;
if (stdOut.contains("password is required"))
return ErrorCode::ServerUserPasswordRequired;

return error;
}
Expand Down
3 changes: 3 additions & 0 deletions client/core/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace amnezia
ServerCancelInstallation = 204,
ServerUserNotInSudo = 205,
ServerPacketManagerError = 206,
SudoPackageIsNotPreinstalled = 207,
ServerUserNotListedInSudoers = 208,
ServerUserPasswordRequired = 209,

// Ssh connection errors
SshRequestDeniedError = 300,
Expand Down
3 changes: 3 additions & 0 deletions client/core/errorstrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion client/server_scripts/check_user_in_sudo.sh
Original file line number Diff line number Diff line change
@@ -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
groups $CUR_USER | grep sudo && sudo -nu $CUR_USER sudo -n uname > /dev/null

0 comments on commit 0de55d8

Please sign in to comment.