mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-23 18:10:34 +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 IsAdmin(bool forceRenew=false);
|
||||||
|
|
||||||
|
bool isSetuidSet(const std::string& path);
|
||||||
|
|
||||||
QString GetBasePath();
|
QString GetBasePath();
|
||||||
} // namespace Configs
|
} // namespace Configs
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,8 @@
|
|||||||
#include <include/sys/linux/LinuxCap.h>
|
#include <include/sys/linux/LinuxCap.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Configs_ConfigItem {
|
namespace Configs_ConfigItem {
|
||||||
@ -399,6 +401,24 @@ namespace Configs {
|
|||||||
|
|
||||||
short isAdminCache = -1;
|
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
|
// IsAdmin 主要判断:有无权限启动 Tun
|
||||||
bool IsAdmin(bool forceRenew) {
|
bool IsAdmin(bool forceRenew) {
|
||||||
if (isAdminCache >= 0 && !forceRenew) return isAdminCache;
|
if (isAdminCache >= 0 && !forceRenew) return isAdminCache;
|
||||||
|
|||||||
@ -1002,9 +1002,8 @@ bool MainWindow::get_elevated_permissions(int reason) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
if (Configs::IsAdmin(true))
|
if (Configs::isSetuidSet(Configs::FindCoreRealPath().toStdString()))
|
||||||
{
|
{
|
||||||
Configs::IsAdmin(true);
|
|
||||||
StopVPNProcess();
|
StopVPNProcess();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user