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

Move socket into separate directory #8030

Merged
merged 2 commits into from
May 28, 2022
Merged
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
21 changes: 15 additions & 6 deletions src/browser/BrowserShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "config-keepassx.h"

#include <QDir>
#include <QStandardPaths>
#if defined(KEEPASSXC_DIST_SNAP)
#include <QProcessEnvironment>
Expand All @@ -31,14 +32,22 @@ namespace BrowserShared
const auto serverName = QStringLiteral("/org.keepassxc.KeePassXC.BrowserServer");
#if defined(KEEPASSXC_DIST_SNAP)
return QProcessEnvironment::systemEnvironment().value("SNAP_USER_COMMON") + serverName;
#elif defined(KEEPASSXC_DIST_FLATPAK)
return QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation) + "/app/" + "org.keepassxc.KeePassXC"
+ serverName;
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
// Use XDG_RUNTIME_DIR instead of /tmp if it's available
// This returns XDG_RUNTIME_DIR or else a temporary subdirectory.
QString path = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved
return path.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverName
: path + serverName;

// Put the socket in a dedicated directory.
// This directory will be easily mountable by sandbox containers.
QString subPath = path + "/app/org.keepassxc.KeePassXC/";
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved
QDir().mkpath(subPath);

QString socketPath = subPath + serverName;
#ifndef KEEPASSXC_DIST_FLATPAK
// Create a symlink at the legacy location for backwards compatibility.
QFile::link(socketPath, path + serverName);
#endif

return socketPath;
#elif defined(Q_OS_WIN)
// Windows uses named pipes
return serverName + "_" + qgetenv("USERNAME");
Expand Down