diff --git a/client/core/controllers/serverController.cpp b/client/core/controllers/serverController.cpp index b6795a01b..ba589da52 100644 --- a/client/core/controllers/serverController.cpp +++ b/client/core/controllers/serverController.cpp @@ -751,10 +751,6 @@ ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credential ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, DockerContainer container) { - if (credentials.userName == "root") { - return ErrorCode::NoError; - } - QString stdOut; auto cbReadStdOut = [&](const QString &data, libssh::Client &) { stdOut += data + "\n"; @@ -768,8 +764,14 @@ ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, D const QString scriptData = amnezia::scriptData(SharedScriptType::check_user_in_sudo); ErrorCode error = runScript(credentials, replaceVars(scriptData, genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr); - if (!stdOut.contains("sudo")) + if (credentials.userName != "root" && !stdOut.contains("sudo") && !stdOut.contains("wheel")) return ErrorCode::ServerUserNotInSudo; + if (credentials.userName != "root" && stdOut.contains("sudo:") && !stdOut.contains("uname:") && stdOut.contains("not found")) + return ErrorCode::SudoPackageIsNotPreinstalled; + if (stdOut.contains("sudoers")) + return ErrorCode::ServerUserNotAllowedInSudoers; + if (stdOut.contains("password is required")) + return ErrorCode::ServerUserPasswordRequired; return error; } diff --git a/client/core/defs.h b/client/core/defs.h index d00d347b1..ea8e5b6d1 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, + ServerUserNotAllowedInSudoers = 208, + ServerUserPasswordRequired = 209, // Ssh connection errors SshRequestDeniedError = 300, diff --git a/client/core/errorstrings.cpp b/client/core/errorstrings.cpp index 495346063..9c8475014 100644 --- a/client/core/errorstrings.cpp +++ b/client/core/errorstrings.cpp @@ -19,8 +19,11 @@ QString errorString(ErrorCode code) { case(ErrorCode::ServerContainerMissingError): errorMessage = QObject::tr("Server error: Docker container missing"); break; case(ErrorCode::ServerDockerFailedError): errorMessage = QObject::tr("Server error: Docker failed"); break; 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::ServerUserNotInSudo): errorMessage = QObject::tr("The user is not a member of the sudo group"); break; + case(ErrorCode::ServerPacketManagerError): errorMessage = QObject::tr("Server error: Package manager error"); break; + case(ErrorCode::SudoPackageIsNotPreinstalled): errorMessage = QObject::tr("The sudo package is not pre-installed"); break; + case(ErrorCode::ServerUserNotAllowedInSudoers): errorMessage = QObject::tr("Action not allowed 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; diff --git a/client/server_scripts/check_user_in_sudo.sh b/client/server_scripts/check_user_in_sudo.sh index e7ee953cd..411c3b42f 100644 --- a/client/server_scripts/check_user_in_sudo.sh +++ b/client/server_scripts/check_user_in_sudo.sh @@ -1,2 +1,5 @@ -CUR_USER=$(whoami);\ -groups $CUR_USER \ No newline at end of file +CUR_USER=$(whoami 2> /dev/null || echo ~ | sed 's/.*\///');\ +echo $LANG | grep -qE '^(en_US.UTF-8|C.UTF-8|C)$' || export LC_ALL=C;\ +if [ "$CUR_USER" = "root" ] || ( groups "$CUR_USER" | grep -E '\<(sudo|wheel)\>' ); then \ + sudo -K && sudo -nu $CUR_USER uname > /dev/null && sudo -n uname > /dev/null;\ +fi diff --git a/client/server_scripts/prepare_host.sh b/client/server_scripts/prepare_host.sh index c6defdb0d..d06bdafb7 100644 --- a/client/server_scripts/prepare_host.sh +++ b/client/server_scripts/prepare_host.sh @@ -1,4 +1,4 @@ -CUR_USER=$(whoami);\ +CUR_USER=$(whoami 2> /dev/null || echo ~ | sed 's/.*\///');\ sudo mkdir -p $DOCKERFILE_FOLDER;\ sudo chown $CUR_USER $DOCKERFILE_FOLDER;\ if ! sudo docker network ls | grep -q amnezia-dns-net; then sudo docker network create \ diff --git a/client/translations/amneziavpn_ar_EG.ts b/client/translations/amneziavpn_ar_EG.ts index e176d8eb3..7a092a742 100644 --- a/client/translations/amneziavpn_ar_EG.ts +++ b/client/translations/amneziavpn_ar_EG.ts @@ -3254,8 +3254,8 @@ Already installed containers were found on the server. All installed containers - The user does not have permission to use sudo - ليس لدي المستخدم الصلحيات لأستخدام sudo + The user is not a member of the sudo group + المستخدم ليس عضوًا في مجموعة sudo @@ -3319,7 +3319,7 @@ Already installed containers were found on the server. All installed containers - Server error: Packet manager error + Server error: Package manager error خطأ في الخادم: خطأ في مدير الحزم diff --git a/client/translations/amneziavpn_fa_IR.ts b/client/translations/amneziavpn_fa_IR.ts index 6cd78e77e..80de1287a 100644 --- a/client/translations/amneziavpn_fa_IR.ts +++ b/client/translations/amneziavpn_fa_IR.ts @@ -3388,8 +3388,8 @@ It's okay as long as it's from someone you trust. - The user does not have permission to use sudo - The user does not have permission to use sudo + The user is not a member of the sudo group + کاربر عضو گروه sudo نیست @@ -3510,8 +3510,8 @@ It's okay as long as it's from someone you trust. - Server error: Packet manager error - Server error: Packet manager error + Server error: Package manager error + خطای سرور: خطای مدیر بسته diff --git a/client/translations/amneziavpn_hi_IN.ts b/client/translations/amneziavpn_hi_IN.ts index ab459b7c4..5255fce30 100644 --- a/client/translations/amneziavpn_hi_IN.ts +++ b/client/translations/amneziavpn_hi_IN.ts @@ -3354,13 +3354,13 @@ Already installed containers were found on the server. All installed containers - The user does not have permission to use sudo - उपयोगकर्ता के पास sudo का उपयोग करने की अनुमति नहीं है + The user is not a member of the sudo group + उपयोगकर्ता sudo समूह का सदस्य नहीं है - Server error: Packet manager error - सर्वर त्रुटि: पैकेट प्रबंधक त्रुटि + Server error: Package manager error + सर्वर त्रुटि: पैकेज प्रबंधक त्रुटि diff --git a/client/translations/amneziavpn_my_MM.ts b/client/translations/amneziavpn_my_MM.ts index 3e964cc9e..101abae59 100644 --- a/client/translations/amneziavpn_my_MM.ts +++ b/client/translations/amneziavpn_my_MM.ts @@ -3250,8 +3250,8 @@ Already installed containers were found on the server. All installed containers - The user does not have permission to use sudo - ဤအသုံးပြုသူသည် sudo ကိုအသုံးပြုရန်ခွင့်ပြုချက်မရှိပါ + The user is not a member of the sudo group + ဤအသုံးပြုသူသည် sudo အဖွဲ့၏ အဖွဲ့ဝင်မဟုတ်ပါ @@ -3315,8 +3315,8 @@ Already installed containers were found on the server. All installed containers - Server error: Packet manager error - ဆာဗာ မှားယွင်းမှု: Packet Manager မှားယွင်းမှု + Server error: Package manager error + ဆာဗာ အမှား- Package manager အမှား diff --git a/client/translations/amneziavpn_ru_RU.ts b/client/translations/amneziavpn_ru_RU.ts index 2fb21259e..085e868af 100644 --- a/client/translations/amneziavpn_ru_RU.ts +++ b/client/translations/amneziavpn_ru_RU.ts @@ -3524,12 +3524,12 @@ and will not be shared or disclosed to the Amnezia or any third parties - The user does not have permission to use sudo - У пользователя нет прав на использование sudo + The user is not a member of the sudo group + Пользователь не входит в группу sudo - Server error: Packet manager error + Server error: Package manager error Ошибка сервера: ошибка менеджера пакетов diff --git a/client/translations/amneziavpn_uk_UA.ts b/client/translations/amneziavpn_uk_UA.ts index c7195119d..c0d3e4397 100644 --- a/client/translations/amneziavpn_uk_UA.ts +++ b/client/translations/amneziavpn_uk_UA.ts @@ -3620,13 +3620,13 @@ and will not be shared or disclosed to the Amnezia or any third parties - The user does not have permission to use sudo - The user does not have permission to use sudo + The user is not a member of the sudo group + Користувач не входить до групи sudo - Server error: Packet manager error - + Server error: Package manager error + Помилка сервера: помилка менеджера пакетів diff --git a/client/translations/amneziavpn_ur_PK.ts b/client/translations/amneziavpn_ur_PK.ts index cf445bfa3..93057609d 100644 --- a/client/translations/amneziavpn_ur_PK.ts +++ b/client/translations/amneziavpn_ur_PK.ts @@ -3353,8 +3353,8 @@ Already installed containers were found on the server. All installed containers - The user does not have permission to use sudo - صارف کو sudo استعمال کرنے کی اجازت نہیں ہے + The user is not a member of the sudo group + صارف sudo گروپ کا رکن نہیں ہے @@ -3418,7 +3418,7 @@ Already installed containers were found on the server. All installed containers - Server error: Packet manager error + Server error: Package manager error سرور خطا: پیکیج منیجر خطا diff --git a/client/translations/amneziavpn_zh_CN.ts b/client/translations/amneziavpn_zh_CN.ts index 39b6bee0d..0de2daceb 100644 --- a/client/translations/amneziavpn_zh_CN.ts +++ b/client/translations/amneziavpn_zh_CN.ts @@ -3603,13 +3603,13 @@ and will not be shared or disclosed to the Amnezia or any third parties - The user does not have permission to use sudo - 用户没有root权限 + The user is not a member of the sudo group + 用户不是 sudo 组的成员 - Server error: Packet manager error - + Server error: Package manager error + 服务器错误:包管理器错误