Skip to content

Commit

Permalink
Verify XDG_RUNTIME_DIR permissions and owner automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
plfiorini committed Jan 21, 2024
1 parent a700099 commit 8b292d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/compositor/compositor_api/aurorawaylandcompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@
#include "aurorawaylandsharedmemoryformathelper_p.h"

#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QStringList>
#include <QtCore/QSocketNotifier>
#include <QtCore/QStandardPaths>

#include <QtGui/QDesktopServices>
#include <QtGui/QScreen>
Expand Down Expand Up @@ -149,6 +153,8 @@ WaylandCompositorPrivate::WaylandCompositorPrivate(WaylandCompositor *compositor
ownsDisplay = true;
}

verifyXdgRuntimeDir();

eventHandler.reset(new Internal::WindowSystemEventHandler(compositor));
timer.start();

Expand All @@ -163,6 +169,48 @@ WaylandCompositorPrivate::WaylandCompositorPrivate(WaylandCompositor *compositor
#endif
}

void WaylandCompositorPrivate::verifyXdgRuntimeDir()
{
const auto runtimePath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
if (runtimePath.isEmpty()) {
qFatal("The XDG_RUNTIME_DIR environment variable is not set.\n"
"Refer to your distribution on how to get it, or read\n"
"http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
"on how to implement it.");
}

const auto runtimeDir = QDir(runtimePath);
if (!runtimeDir.exists()) {
qFatal("Runtime directory does not exist, please check the "
"XDG_RUNTIME_DIR environment variable.\n"
"Refer to your distribution on how to get it, or read\n"
"http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
"on how to implement it.");
}

// Check directory permissions
QFileInfo fileInfo(runtimePath);
if (!(fileInfo.permissions() & QFile::ReadUser) || !(fileInfo.permissions() & QFile::WriteUser)
|| !(fileInfo.permissions() & QFile::ExeUser)) {
qFatal("Runtime directory \"%s\" does not have 700 permissions.\n"
"Please check the XDG_RUNTIME_DIR environment variable."
"Refer to your distribution on how to get it, or read\n"
"http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
"on how to implement it.",
qPrintable(runtimePath));
}

// Check owner
if (fileInfo.ownerId() != getuid()) {
qFatal("Current user is not the owner of the runtime directory."
"Please check the XDG_RUNTIME_DIR environment variable."
"Refer to your distribution on how to get it, or read\n"
"http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
"on how to implement it.",
qPrintable(runtimePath));
}
}

void WaylandCompositorPrivate::init()
{
Q_Q(WaylandCompositor);
Expand Down
2 changes: 2 additions & 0 deletions src/compositor/compositor_api/aurorawaylandcompositor_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class LIRIAURORACOMPOSITOR_EXPORT WaylandCompositorPrivate : public QObjectPriva
void preInit();
void init();

void verifyXdgRuntimeDir();

void destroySurface(WaylandSurface *surface);
void unregisterSurface(WaylandSurface *surface);

Expand Down

0 comments on commit 8b292d0

Please sign in to comment.