2018-08-12 16:45:39 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QSettings>
|
2020-08-24 21:36:45 +02:00
|
|
|
#include <QMessageBox>
|
2021-08-07 12:03:35 +02:00
|
|
|
#include <QStandardPaths>
|
2021-09-28 21:44:09 +02:00
|
|
|
#include <QProcess>
|
2022-01-04 23:27:39 +01:00
|
|
|
#include <QDir>
|
2022-01-04 23:44:37 +01:00
|
|
|
#include <QCommandLineParser>
|
2021-09-28 21:44:09 +02:00
|
|
|
|
2020-05-23 22:52:42 +02:00
|
|
|
#include "mainwindow.h"
|
2018-08-12 16:45:39 +02:00
|
|
|
#include "searchresult.h"
|
2022-01-03 23:02:21 +01:00
|
|
|
#include "previewresultpdf.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
#include "../shared/common.h"
|
2022-04-14 15:04:16 +02:00
|
|
|
#include "../shared/sandboxedprocessor.h"
|
2021-12-26 18:21:48 +01:00
|
|
|
#include "../submodules/exile.h/exile.h"
|
2021-09-28 21:44:09 +02:00
|
|
|
#include "ipcserver.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
|
2022-01-04 23:27:39 +01:00
|
|
|
void enableSandbox(QString socketPath)
|
2018-08-12 16:45:39 +02:00
|
|
|
{
|
2021-12-26 18:21:48 +01:00
|
|
|
struct exile_policy *policy = exile_init_policy();
|
2021-12-29 11:51:52 +01:00
|
|
|
if(policy == NULL)
|
|
|
|
{
|
|
|
|
qCritical() << "Failed to init policy for sandbox";
|
2022-01-04 23:27:39 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2021-12-29 11:51:52 +01:00
|
|
|
}
|
2022-01-04 23:27:39 +01:00
|
|
|
QDir dir;
|
|
|
|
dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
|
|
|
|
dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
|
|
|
|
2021-08-07 12:03:35 +02:00
|
|
|
std::string appDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation).toStdString();
|
|
|
|
std::string cacheDataLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toStdString();
|
2022-04-24 15:25:44 +02:00
|
|
|
std::string configDataLocation = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).toStdString();
|
2022-01-04 23:27:39 +01:00
|
|
|
|
2021-09-28 21:44:09 +02:00
|
|
|
std::string sockPath = socketPath.toStdString();
|
2022-04-24 15:25:44 +02:00
|
|
|
std::string dbPath = QFileInfo(Common::databasePath()).absolutePath().toStdString();
|
|
|
|
std::string mySelf = QFileInfo("/proc/self/exe").symLinkTarget().toStdString();
|
2021-12-26 18:21:48 +01:00
|
|
|
policy->namespace_options = EXILE_UNSHARE_NETWORK | EXILE_UNSHARE_USER;
|
2022-04-24 15:25:44 +02:00
|
|
|
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ, "/") != 0)
|
2021-12-29 11:51:52 +01:00
|
|
|
{
|
|
|
|
qCritical() << "Failed to append a path to the path policy";
|
2022-01-04 23:27:39 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2021-12-29 11:51:52 +01:00
|
|
|
}
|
2021-08-07 12:03:35 +02:00
|
|
|
|
2022-04-14 14:57:16 +02:00
|
|
|
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
|
|
|
|
appDataLocation.c_str()) != 0)
|
2021-12-29 11:51:52 +01:00
|
|
|
{
|
2022-04-24 15:25:44 +02:00
|
|
|
qCritical() << "Failed to append appDataLocation path to the path policy";
|
2022-01-04 23:27:39 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2021-12-29 11:51:52 +01:00
|
|
|
}
|
2022-04-14 14:57:16 +02:00
|
|
|
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
|
|
|
|
cacheDataLocation.c_str()) != 0)
|
2021-12-29 11:51:52 +01:00
|
|
|
{
|
2022-04-24 15:25:44 +02:00
|
|
|
qCritical() << "Failed to append cacheDataLocation path to the path policy";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if(exile_append_path_policies(policy,
|
|
|
|
EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_REMOVE_FILE | EXILE_FS_ALLOW_ALL_WRITE,
|
|
|
|
dbPath.c_str()) != 0)
|
|
|
|
{
|
|
|
|
qCritical() << "Failed to append dbPath path to the path policy";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_EXEC, mySelf.c_str(), "/lib64",
|
|
|
|
"/lib") != 0)
|
|
|
|
{
|
|
|
|
qCritical() << "Failed to append mySelf path to the path policy";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
|
|
|
|
configDataLocation.c_str()) != 0)
|
|
|
|
{
|
|
|
|
qCritical() << "Failed to append configDataLocation path to the path policy";
|
2022-01-04 23:27:39 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2021-12-29 11:51:52 +01:00
|
|
|
}
|
2021-12-26 18:21:48 +01:00
|
|
|
int ret = exile_enable_policy(policy);
|
2021-08-07 12:03:35 +02:00
|
|
|
if(ret != 0)
|
|
|
|
{
|
|
|
|
qDebug() << "Failed to establish sandbox";
|
2022-01-04 23:27:39 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2021-08-07 12:03:35 +02:00
|
|
|
}
|
2021-12-26 18:21:48 +01:00
|
|
|
exile_free_policy(policy);
|
2022-01-04 23:27:39 +01:00
|
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QString socketPath = "/tmp/looqs-spawner";
|
|
|
|
if(argc > 1)
|
|
|
|
{
|
|
|
|
QString arg = argv[1];
|
|
|
|
if(arg == "ipc")
|
|
|
|
{
|
2022-01-04 23:44:37 +01:00
|
|
|
Common::setupAppInfo();
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
2022-01-04 23:27:39 +01:00
|
|
|
IpcServer *ipcserver = new IpcServer();
|
2022-01-04 23:44:37 +01:00
|
|
|
qDebug() << "Launching IPC Server";
|
2022-01-04 23:27:39 +01:00
|
|
|
if(!ipcserver->startSpawner(socketPath))
|
|
|
|
{
|
|
|
|
qCritical() << "Error failed to spawn";
|
|
|
|
return 1;
|
|
|
|
}
|
2022-01-04 23:44:37 +01:00
|
|
|
qDebug() << "Launched IPC Server";
|
|
|
|
return a.exec();
|
2022-01-04 23:27:39 +01:00
|
|
|
}
|
2022-04-14 15:04:16 +02:00
|
|
|
if(arg == "process")
|
|
|
|
{
|
|
|
|
Common::setupAppInfo();
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
|
|
|
QStringList args = a.arguments();
|
|
|
|
if(args.length() < 1)
|
|
|
|
{
|
|
|
|
qDebug() << "Filename is required";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString file = args.at(1);
|
|
|
|
SandboxedProcessor processor(file);
|
|
|
|
return processor.process();
|
|
|
|
}
|
2022-01-04 23:27:39 +01:00
|
|
|
}
|
|
|
|
QProcess process;
|
|
|
|
QStringList args;
|
|
|
|
args << "ipc";
|
|
|
|
if(!process.startDetached("/proc/self/exe", args))
|
|
|
|
{
|
|
|
|
QString errorMsg = "Failed to start IPC server";
|
|
|
|
qDebug() << errorMsg;
|
|
|
|
QMessageBox::critical(nullptr, "Error", errorMsg);
|
|
|
|
}
|
2020-05-23 22:52:42 +02:00
|
|
|
Common::setupAppInfo();
|
2022-01-04 23:44:37 +01:00
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addOption({{"s", "no-sandbox"}, "Disable sandboxing"});
|
|
|
|
QStringList appArgs;
|
|
|
|
for(int i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
appArgs.append(argv[i]);
|
|
|
|
}
|
|
|
|
parser.parse(appArgs);
|
|
|
|
|
2020-08-24 21:36:45 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Common::ensureConfigured();
|
2022-04-24 17:13:43 +02:00
|
|
|
if(!parser.isSet("no-sandbox"))
|
|
|
|
{
|
|
|
|
enableSandbox(socketPath);
|
|
|
|
qInfo() << "Sandbox: on";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qInfo() << "Sandbox: off";
|
|
|
|
}
|
2020-08-24 21:36:45 +02:00
|
|
|
}
|
2021-06-12 14:59:58 +02:00
|
|
|
catch(LooqsGeneralException &e)
|
2020-08-24 21:36:45 +02:00
|
|
|
{
|
|
|
|
qDebug() << e.message;
|
|
|
|
QMessageBox::critical(nullptr, "Error", e.message);
|
|
|
|
return 1;
|
|
|
|
}
|
2022-04-24 17:13:43 +02:00
|
|
|
// Keep this post sandbox, afterwards does not work (suspect due to threads, but unconfirmed)
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
2018-08-12 16:45:39 +02:00
|
|
|
qRegisterMetaType<QVector<SearchResult>>("QVector<SearchResult>");
|
2022-01-03 23:02:21 +01:00
|
|
|
qRegisterMetaType<QVector<PreviewResultPdf>>("QVector<PreviewResultPdf>");
|
|
|
|
qRegisterMetaType<PreviewResultPdf>("PreviewResultPdf");
|
2022-04-14 15:04:16 +02:00
|
|
|
qRegisterMetaType<FileScanResult>("FileScanResult");
|
2021-09-28 21:44:09 +02:00
|
|
|
|
|
|
|
IPCClient client{socketPath};
|
|
|
|
MainWindow w{0, client};
|
2018-08-12 16:45:39 +02:00
|
|
|
w.showMaximized();
|
|
|
|
|
|
|
|
return a.exec();
|
|
|
|
}
|