mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
fix: linux cap test with libcap-progs at /usr/sbin (gh#764)
Signed-off-by: xtex <xtexchooser@duck.com>
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
#include "LinuxCap.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#define EXIT_CODE(p) (p.exitStatus() == QProcess::NormalExit ? p.exitCode() : -1)
|
||||
|
||||
QString Linux_GetCapString(const QString &path) {
|
||||
QProcess p;
|
||||
p.setProgram("getcap");
|
||||
p.setProgram(Linux_FindCapProgsExec("getcap"));
|
||||
p.setArguments({path});
|
||||
p.start();
|
||||
p.waitForFinished(500);
|
||||
@@ -16,7 +18,7 @@ QString Linux_GetCapString(const QString &path) {
|
||||
int Linux_Pkexec_SetCapString(const QString &path, const QString &cap) {
|
||||
QProcess p;
|
||||
p.setProgram("pkexec");
|
||||
p.setArguments({"setcap", cap, path});
|
||||
p.setArguments({Linux_FindCapProgsExec("setcap"), cap, path});
|
||||
p.start();
|
||||
p.waitForFinished(-1);
|
||||
return EXIT_CODE(p);
|
||||
@@ -31,3 +33,16 @@ bool Linux_HavePkexec() {
|
||||
p.waitForFinished(500);
|
||||
return EXIT_CODE(p) == 0;
|
||||
}
|
||||
|
||||
QString Linux_FindCapProgsExec(const QString &name) {
|
||||
QString exec = QStandardPaths::findExecutable(name);
|
||||
if (exec.isEmpty())
|
||||
exec = QStandardPaths::findExecutable(name, {"/usr/sbin", "/sbin"});
|
||||
|
||||
if (exec.isEmpty())
|
||||
qDebug() << "Executable" << name << "could not be resolved";
|
||||
else
|
||||
qDebug() << "Found exec" << name << "at" << exec;
|
||||
|
||||
return exec.isEmpty() ? name : exec;
|
||||
}
|
||||
|
||||
@@ -7,3 +7,5 @@ QString Linux_GetCapString(const QString &path);
|
||||
int Linux_Pkexec_SetCapString(const QString &path, const QString &cap);
|
||||
|
||||
bool Linux_HavePkexec();
|
||||
|
||||
QString Linux_FindCapProgsExec(const QString &name);
|
||||
|
||||
Reference in New Issue
Block a user