mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-07-03 14:07:39 +02:00
39d4c6f1ec
- Validate IP/CIDR values from IPC before passing to Linux firewall - Replace shell interpolation with direct execve in firewall update functions - Block dangerous OpenVPN/WireGuard arguments in sanitizeArguments() - Add programId bounds check in IpcServerProcess::setProgram() - Add SO_PEERCRED peer authentication for IPC connections on Linux
127 lines
3.5 KiB
C++
127 lines
3.5 KiB
C++
#include "ipcserverprocess.h"
|
|
#include "ipc.h"
|
|
#include <QProcess>
|
|
|
|
#ifndef Q_OS_IOS
|
|
|
|
IpcServerProcess::IpcServerProcess(QObject *parent) :
|
|
IpcProcessInterfaceSource(parent),
|
|
m_process(QSharedPointer<QProcess>(new QProcess()))
|
|
{
|
|
connect(m_process.data(), &QProcess::errorOccurred, this, &IpcServerProcess::errorOccurred);
|
|
connect(m_process.data(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &IpcServerProcess::finished);
|
|
connect(m_process.data(), &QProcess::readyRead, this, &IpcServerProcess::readyRead);
|
|
connect(m_process.data(), &QProcess::readyReadStandardError, this, &IpcServerProcess::readyReadStandardError);
|
|
connect(m_process.data(), &QProcess::readyReadStandardOutput, this, &IpcServerProcess::readyReadStandardOutput);
|
|
connect(m_process.data(), &QProcess::started, this, &IpcServerProcess::started);
|
|
connect(m_process.data(), &QProcess::stateChanged, this, &IpcServerProcess::stateChanged);
|
|
|
|
connect(m_process.data(), &QProcess::errorOccurred, [&](QProcess::ProcessError error){
|
|
qDebug() << "IpcServerProcess errorOccurred " << error;
|
|
});
|
|
|
|
}
|
|
|
|
IpcServerProcess::~IpcServerProcess()
|
|
{
|
|
qDebug() << "IpcServerProcess::~IpcServerProcess";
|
|
}
|
|
|
|
void IpcServerProcess::start()
|
|
{
|
|
if (m_process->program().isEmpty()) {
|
|
qDebug() << "IpcServerProcess failed to start, program is empty";
|
|
}
|
|
|
|
Utils::killProcessByName(m_process->program());
|
|
m_process->start();
|
|
qDebug() << "IpcServerProcess started, " << m_process->program() << m_process->arguments();
|
|
|
|
m_process->waitForStarted();
|
|
}
|
|
|
|
void IpcServerProcess::terminate() {
|
|
m_process->terminate();
|
|
}
|
|
|
|
void IpcServerProcess::kill() {
|
|
m_process->kill();
|
|
}
|
|
|
|
void IpcServerProcess::close()
|
|
{
|
|
m_process->close();
|
|
}
|
|
|
|
void IpcServerProcess::setArguments(const QStringList &arguments)
|
|
{
|
|
m_process->setArguments(amnezia::sanitizeArguments(m_program, arguments));
|
|
}
|
|
|
|
void IpcServerProcess::setInputChannelMode(QProcess::InputChannelMode mode)
|
|
{
|
|
m_process->setInputChannelMode(mode);
|
|
}
|
|
|
|
void IpcServerProcess::setNativeArguments(const QString &arguments)
|
|
{
|
|
#ifdef Q_OS_WIN
|
|
m_process->setNativeArguments(arguments);
|
|
#endif
|
|
}
|
|
|
|
void IpcServerProcess::setProcessChannelMode(QProcess::ProcessChannelMode mode)
|
|
{
|
|
m_process->setProcessChannelMode(mode);
|
|
}
|
|
|
|
void IpcServerProcess::setProgram(int programId)
|
|
{
|
|
if (programId <= static_cast<int>(amnezia::PermittedProcess::Invalid) ||
|
|
programId >= static_cast<int>(amnezia::PermittedProcess::_Count)) {
|
|
qWarning() << "IPC: invalid programId" << programId << ", ignoring";
|
|
return;
|
|
}
|
|
m_program = static_cast<amnezia::PermittedProcess>(programId);
|
|
m_process->setProgram(amnezia::permittedProcessPath(m_program));
|
|
m_process->setArguments({});
|
|
}
|
|
|
|
void IpcServerProcess::setWorkingDirectory(const QString &dir)
|
|
{
|
|
m_process->setWorkingDirectory(dir);
|
|
}
|
|
|
|
QByteArray IpcServerProcess::readAll()
|
|
{
|
|
return m_process->readAll();
|
|
}
|
|
|
|
QByteArray IpcServerProcess::readAllStandardError()
|
|
{
|
|
return m_process->readAllStandardError();
|
|
}
|
|
|
|
QByteArray IpcServerProcess::readAllStandardOutput()
|
|
{
|
|
return m_process->readAllStandardOutput();
|
|
}
|
|
|
|
bool IpcServerProcess::waitForStarted() {
|
|
return m_process->waitForStarted();
|
|
}
|
|
|
|
bool IpcServerProcess::waitForStarted(int msecs) {
|
|
return m_process->waitForStarted(msecs);
|
|
}
|
|
|
|
bool IpcServerProcess::waitForFinished() {
|
|
return m_process->waitForFinished();
|
|
}
|
|
|
|
bool IpcServerProcess::waitForFinished(int msecs) {
|
|
return m_process->waitForFinished(msecs);
|
|
}
|
|
|
|
#endif
|