mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
attempt to fix macos isAdmin
This commit is contained in:
parent
7c98ac9592
commit
1c4429f4aa
@ -12,6 +12,8 @@ namespace Configs {
|
||||
|
||||
bool IsAdmin(bool forceRenew=false);
|
||||
|
||||
bool isSetuidSet(const std::string& path);
|
||||
|
||||
QString GetBasePath();
|
||||
} // namespace Configs
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user