diff --git a/include/global/Configs.hpp b/include/global/Configs.hpp index 791eca3..c96cd73 100644 --- a/include/global/Configs.hpp +++ b/include/global/Configs.hpp @@ -12,6 +12,8 @@ namespace Configs { bool IsAdmin(bool forceRenew=false); + bool isSetuidSet(const std::string& path); + QString GetBasePath(); } // namespace Configs diff --git a/src/global/Configs.cpp b/src/global/Configs.cpp index 1203c71..697eb80 100644 --- a/src/global/Configs.cpp +++ b/src/global/Configs.cpp @@ -21,6 +21,8 @@ #include #endif #include +#include +#include #endif namespace Configs_ConfigItem { @@ -399,6 +401,24 @@ namespace Configs { short isAdminCache = -1; + bool isSetuidSet(const std::string& path) { +#ifdef Q_OS_MACOS + struct stat fileInfo; + + if (stat(path.c_str(), &fileInfo) != 0) { + return false; + } + + if (fileInfo.st_mode & S_ISUID) { + return true; + } else { + return false; + } +#else + return false; +#endif + } + // IsAdmin 主要判断:有无权限启动 Tun bool IsAdmin(bool forceRenew) { if (isAdminCache >= 0 && !forceRenew) return isAdminCache; diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 491398e..e80e47c 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -1002,9 +1002,8 @@ bool MainWindow::get_elevated_permissions(int reason) { #endif #ifdef Q_OS_MACOS - if (Configs::IsAdmin(true)) + if (Configs::isSetuidSet(Configs::FindCoreRealPath().toStdString())) { - Configs::IsAdmin(true); StopVPNProcess(); return true; }