Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPN-6647: Ensure the app is started with a systemd application scope #10079

Merged
merged 7 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cmake/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ target_link_libraries(mozillavpn PRIVATE Qt6::DBus)
target_sources(mozillavpn PRIVATE
${CMAKE_SOURCE_DIR}/src/platforms/linux/backendlogsobserver.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/backendlogsobserver.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/dbustypes.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxappimageprovider.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxappimageprovider.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxapplistprovider.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxapplistprovider.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxdependencies.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxdependencies.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxnetworkwatcher.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxnetworkwatcher.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxnetworkwatcherworker.cpp
Expand All @@ -25,6 +24,8 @@ target_sources(mozillavpn PRIVATE
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxpingsender.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxsystemtraynotificationhandler.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxsystemtraynotificationhandler.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxutils.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/linuxutils.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/xdgcryptosettings.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/xdgcryptosettings.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/xdgportal.cpp
Expand Down Expand Up @@ -70,7 +71,6 @@ if(NOT BUILD_FLATPAK)
${CMAKE_SOURCE_DIR}/src/platforms/linux/daemon/apptracker.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/daemon/dbusservice.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/daemon/dbusservice.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/daemon/dbustypeslinux.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/daemon/dnsutilslinux.cpp
${CMAKE_SOURCE_DIR}/src/platforms/linux/daemon/dnsutilslinux.h
${CMAKE_SOURCE_DIR}/src/platforms/linux/daemon/iputilslinux.cpp
Expand Down
16 changes: 16 additions & 0 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
# include "platforms/macos/macosutils.h"
#endif

#ifdef MZ_LINUX
# include "platforms/linux/xdgportal.h"
#endif

#include <QApplication>
#include <QIcon>
#include <QTextStream>
Expand Down Expand Up @@ -100,6 +104,10 @@ bool Command::loadModels() {
int Command::runCommandLineApp(std::function<int()>&& a_callback) {
std::function<int()> callback = std::move(a_callback);

#ifdef MZ_LINUX
XdgPortal::setupAppScope(Constants::LINUX_APP_ID);
#endif

SettingsHolder settingsHolder;

if (settingsHolder.stagingServer()) {
Expand All @@ -124,6 +132,10 @@ int Command::runCommandLineApp(std::function<int()>&& a_callback) {
int Command::runGuiApp(std::function<int()>&& a_callback) {
std::function<int()> callback = std::move(a_callback);

#ifdef MZ_LINUX
XdgPortal::setupAppScope(Constants::LINUX_APP_ID);
#endif

SettingsHolder settingsHolder;

if (settingsHolder.stagingServer()) {
Expand Down Expand Up @@ -155,6 +167,10 @@ int Command::runGuiApp(std::function<int()>&& a_callback) {
int Command::runQmlApp(std::function<int()>&& a_callback) {
std::function<int()> callback = std::move(a_callback);

#ifdef MZ_LINUX
XdgPortal::setupAppScope(Constants::LINUX_APP_ID);
#endif

SettingsHolder settingsHolder;

if (settingsHolder.stagingServer()) {
Expand Down
8 changes: 4 additions & 4 deletions src/feature/featurelistcallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifdef MZ_LINUX
# include <QProcessEnvironment>

# include "platforms/linux/linuxdependencies.h"
# include "platforms/linux/linuxutils.h"
# include "versionutils.h"
#endif

Expand Down Expand Up @@ -123,7 +123,7 @@ bool FeatureCallback_splitTunnel() {

/* Control groups v2 must be mounted for app/traffic classification
*/
if (LinuxDependencies::findCgroup2Path().isNull()) {
if (LinuxUtils::findCgroup2Path().isNull()) {
return false;
}

Expand All @@ -135,15 +135,15 @@ bool FeatureCallback_splitTunnel() {
}
QStringList desktop = pe.value("XDG_CURRENT_DESKTOP").split(":");
if (desktop.contains("GNOME")) {
QString shellVersion = LinuxDependencies::gnomeShellVersion();
QString shellVersion = LinuxUtils::gnomeShellVersion();
if (shellVersion.isNull()) {
return false;
}
if (VersionUtils::compareVersions(shellVersion, "3.34") < 0) {
return false;
}
} else if (desktop.contains("KDE")) {
QString kdeVersion = LinuxDependencies::kdeFrameworkVersion();
QString kdeVersion = LinuxUtils::kdeFrameworkVersion();
if (kdeVersion.isNull()) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/platforms/linux/daemon/apptracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <QScopeGuard>
#include <QtDBus/QtDBus>

#include "../linuxdependencies.h"
#include "dbustypeslinux.h"
#include "leakdetector.h"
#include "logger.h"
#include "platforms/linux/dbustypes.h"
#include "platforms/linux/linuxutils.h"

constexpr const char* GTK_DESKTOP_APP_SERVICE = "org.gtk.gio.DesktopAppInfo";
constexpr const char* GTK_DESKTOP_APP_PATH = "/org/gtk/gio/DesktopAppInfo";
Expand All @@ -34,7 +34,7 @@ AppTracker::AppTracker(QObject* parent) : QObject(parent) {
logger.debug() << "AppTracker created.";

/* Monitor for changes to the user's application control groups. */
m_cgroupMount = LinuxDependencies::findCgroup2Path();
m_cgroupMount = LinuxUtils::findCgroup2Path();
}

AppTracker::~AppTracker() {
Expand Down Expand Up @@ -208,7 +208,7 @@ QString AppTracker::findDesktopFileId(const QString& cgroup) {
this);
QString source = interface.property("SourcePath").toString();
if (!source.isEmpty() && source.endsWith(".desktop")) {
return LinuxDependencies::desktopFileId(source);
return LinuxUtils::desktopFileId(source);
}

// Otherwise, we don't know the desktop ID for this control group.
Expand Down
15 changes: 2 additions & 13 deletions src/platforms/linux/daemon/dbusservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "leakdetector.h"
#include "logger.h"
#include "loghandler.h"
#include "platforms/linux/linuxdependencies.h"
#include "platforms/linux/linuxutils.h"

namespace {
Logger logger("DBusService");
Expand Down Expand Up @@ -139,7 +139,7 @@ bool DBusService::activate(const QString& jsonConfig) {
if (obj.contains("vpnDisabledApps")) {
QJsonArray disabledApps = obj["vpnDisabledApps"].toArray();
for (const QJsonValue& app : disabledApps) {
setAppState(LinuxDependencies::desktopFileId(app.toString()), Excluded);
setAppState(LinuxUtils::desktopFileId(app.toString()), Excluded);
}
}

Expand Down Expand Up @@ -382,14 +382,3 @@ bool DBusService::isCallerAuthorized() {
}
return (flag == CAP_SET);
}

// Workaround for QTBUG-108822 by manually registering QDBusObjectPath with the
// D-Bus meta-type system, otherwise we are unable to connect to some signals.
#if QT_VERSION < 0x060403
class QtbugRegistrationProxy {
public:
QtbugRegistrationProxy() { qDBusRegisterMetaType<QDBusObjectPath>(); }
};

static QtbugRegistrationProxy s_qtbugRegistrationProxy;
#endif
2 changes: 0 additions & 2 deletions src/platforms/linux/daemon/dnsutilslinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,3 @@ void DnsUtilsLinux::dnsDomainsReceived(QDBusPendingCallWatcher* call) {
setLinkDomains(m_ifindex, newlist);
delete call;
}

static DnsMetatypeRegistrationProxy s_dnsMetatypeProxy;
2 changes: 1 addition & 1 deletion src/platforms/linux/daemon/dnsutilslinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QDBusPendingCallWatcher>

#include "daemon/dnsutils.h"
#include "dbustypeslinux.h"
#include "platforms/linux/dbustypes.h"

class DnsUtilsLinux final : public DnsUtils {
Q_OBJECT
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/linux/daemon/wireguardutilslinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "leakdetector.h"
#include "logger.h"
#include "platforms/linux/linuxdependencies.h"
#include "platforms/linux/linuxutils.h"

// Import wireguard C library for Linux
#if defined(__cplusplus)
Expand Down Expand Up @@ -101,8 +101,8 @@ WireguardUtilsLinux::WireguardUtilsLinux(QObject* parent)
// In this situation, you will likely see this kernel log warning:
// cgroup: disabling cgroup2 socket matching due to net_prio or net_cls
// activation
m_cgroupNetClass = LinuxDependencies::findCgroupPath("net_cls");
m_cgroupUnified = LinuxDependencies::findCgroup2Path();
m_cgroupNetClass = LinuxUtils::findCgroupPath("net_cls");
m_cgroupUnified = LinuxUtils::findCgroup2Path();
if (!m_cgroupNetClass.isNull()) {
if (setupCgroupClass(m_cgroupNetClass + VPN_EXCLUDE_CGROUP,
VPN_EXCLUDE_CLASS_ID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DBUSTYPESLINUX_H
#define DBUSTYPESLINUX_H
#ifndef DBUSTYPES_H
#define DBUSTYPES_H

#include <sys/socket.h>

Expand Down Expand Up @@ -145,9 +145,61 @@ typedef QList<UserData> UserDataList;
Q_DECLARE_METATYPE(UserData);
Q_DECLARE_METATYPE(UserDataList);

class DnsMetatypeRegistrationProxy {
class SystemdUnitProp {
public:
DnsMetatypeRegistrationProxy() {
SystemdUnitProp(){};
SystemdUnitProp(const QString& n, const QVariant& v) : name(n), value(v){};
QString name;
QVariant value;

friend QDBusArgument& operator<<(QDBusArgument& args,
const SystemdUnitProp& data) {
args.beginStructure();
args << data.name << QDBusVariant(data.value);
args.endStructure();
return args;
}
friend const QDBusArgument& operator>>(const QDBusArgument& args,
SystemdUnitProp& data) {
QDBusVariant dv;
args.beginStructure();
args >> data.name >> dv;
args.endStructure();
data.value = dv.variant();
return args;
}
};
typedef QList<SystemdUnitProp> SystemdUnitPropList;
Q_DECLARE_METATYPE(SystemdUnitProp);
Q_DECLARE_METATYPE(SystemdUnitPropList);

class SystemdUnitAux {
public:
QString name;
SystemdUnitPropList prop;

friend QDBusArgument& operator<<(QDBusArgument& args,
const SystemdUnitAux& data) {
args.beginStructure();
args << data.name << data.prop;
args.endStructure();
return args;
}
friend const QDBusArgument& operator>>(const QDBusArgument& args,
SystemdUnitAux& data) {
args.beginStructure();
args >> data.name >> data.prop;
args.endStructure();
return args;
}
};
typedef QList<SystemdUnitAux> SystemdUnitAuxList;
Q_DECLARE_METATYPE(SystemdUnitAux);
Q_DECLARE_METATYPE(SystemdUnitAuxList);

class DBusMetatypeRegistrationProxy {
public:
DBusMetatypeRegistrationProxy() {
qRegisterMetaType<DnsResolver>();
qDBusRegisterMetaType<DnsResolver>();
qRegisterMetaType<DnsResolverList>();
Expand All @@ -164,6 +216,14 @@ class DnsMetatypeRegistrationProxy {
qDBusRegisterMetaType<UserData>();
qRegisterMetaType<UserDataList>();
qDBusRegisterMetaType<UserDataList>();
qRegisterMetaType<SystemdUnitProp>();
qDBusRegisterMetaType<SystemdUnitProp>();
qRegisterMetaType<SystemdUnitPropList>();
qDBusRegisterMetaType<SystemdUnitPropList>();
qRegisterMetaType<SystemdUnitAux>();
qDBusRegisterMetaType<SystemdUnitAux>();
qRegisterMetaType<SystemdUnitAuxList>();
qDBusRegisterMetaType<SystemdUnitAuxList>();
}
};

Expand Down
25 changes: 0 additions & 25 deletions src/platforms/linux/linuxdependencies.h

This file was deleted.

Loading
Loading