attempt to fix macos isAdmin

This commit is contained in:
Nova 2025-10-03 00:48:35 +03:30
parent 7c98ac9592
commit 1c4429f4aa
3 changed files with 23 additions and 2 deletions

View File

@ -12,6 +12,8 @@ namespace Configs {
bool IsAdmin(bool forceRenew=false);
bool isSetuidSet(const std::string& path);
QString GetBasePath();
} // namespace Configs

View File

@ -21,6 +21,8 @@
#include <include/sys/linux/LinuxCap.h>
#endif
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#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;

View File

@ -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;
}