mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-18 04:54:38 +03:00
optimize linux tun capability
This commit is contained in:
33
sys/linux/LinuxCap.cpp
Normal file
33
sys/linux/LinuxCap.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "LinuxCap.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
#define EXIT_CODE(p) (p.exitStatus() == QProcess::NormalExit ? p.exitCode() : -1)
|
||||
|
||||
QString Linux_GetCapString(const QString &path) {
|
||||
QProcess p;
|
||||
p.setProgram("getcap");
|
||||
p.setArguments({path});
|
||||
p.start();
|
||||
p.waitForFinished(500);
|
||||
return p.readAllStandardOutput();
|
||||
}
|
||||
|
||||
int Linux_Pkexec_SetCapString(const QString &path, const QString &cap) {
|
||||
QProcess p;
|
||||
p.setProgram("pkexec");
|
||||
p.setArguments({"setcap", cap, path});
|
||||
p.start();
|
||||
p.waitForFinished(-1);
|
||||
return EXIT_CODE(p);
|
||||
}
|
||||
|
||||
bool Linux_HavePkexec() {
|
||||
QProcess p;
|
||||
p.setProgram("pkexec");
|
||||
p.setArguments({"--help"});
|
||||
p.setProcessChannelMode(QProcess::SeparateChannels);
|
||||
p.start();
|
||||
p.waitForFinished(500);
|
||||
return EXIT_CODE(p) == 0;
|
||||
}
|
||||
9
sys/linux/LinuxCap.h
Normal file
9
sys/linux/LinuxCap.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
QString Linux_GetCapString(const QString &path);
|
||||
|
||||
int Linux_Pkexec_SetCapString(const QString &path, const QString &cap);
|
||||
|
||||
bool Linux_HavePkexec();
|
||||
Reference in New Issue
Block a user