2020-05-11 01:20:00 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "BrowserShared.h"
|
2021-07-12 02:10:29 +00:00
|
|
|
|
2020-05-11 01:20:00 +00:00
|
|
|
#include "config-keepassx.h"
|
|
|
|
|
|
Move socket into separate directory (#8030)
This is mostly to ease setup and configuration with sandboxed browsers.
The socket currently existing in `$XDG_RUNTIME_DIR`. When sandboxing a browser, it would be unsafe to mount this directory inside the sandbox.
Mounting the socket into the sandbox's filesystem is also not possible in cases where KeePassXC is [re]started after the browser has started.
This commit moves the socket into its own isolated subdirectory, which can be safely mounted into sandboxes. Sandbox engines can create the directory themselves (in case the browser starts before KeePassXC). Both Flatpak and Firejail support this configuration.
A symlink is also created, linking the previous location to the new location. This is meant for backwards compatibility and should eventually be dropped.
The directory can't be named `org.keepassxc.KeePassXC.BrowserServer`,
since that would collide with the symlink. Instead, the directory has been created to match the format used for Flatpak builds, which make it a bit less of a snowflake build, while following accepted conventions.
Given that the preferred path now matches what Flatpak uses, the block handling Flatpak and non-Flatpak is now the same.
If `$XDG_RUNTIME_DIR` is undefined, the temporary directory is used, though reading the socket from this location is discouraged.
Closes: https://github.com/keepassxreboot/keepassxc/issues/8018
References: https://github.com/keepassxreboot/keepassxc/discussions/6741
2022-05-28 22:19:48 +00:00
|
|
|
#include <QDir>
|
2020-05-11 01:20:00 +00:00
|
|
|
#include <QStandardPaths>
|
2022-02-28 13:04:41 +00:00
|
|
|
#if defined(KEEPASSXC_DIST_SNAP)
|
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
|
#endif
|
2020-05-11 01:20:00 +00:00
|
|
|
|
|
|
|
|
namespace BrowserShared
|
|
|
|
|
{
|
|
|
|
|
QString localServerPath()
|
|
|
|
|
{
|
2020-05-15 18:17:58 +00:00
|
|
|
const auto serverName = QStringLiteral("/org.keepassxc.KeePassXC.BrowserServer");
|
2020-05-11 01:20:00 +00:00
|
|
|
#if defined(KEEPASSXC_DIST_SNAP)
|
|
|
|
|
return QProcessEnvironment::systemEnvironment().value("SNAP_USER_COMMON") + serverName;
|
|
|
|
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
Move socket into separate directory (#8030)
This is mostly to ease setup and configuration with sandboxed browsers.
The socket currently existing in `$XDG_RUNTIME_DIR`. When sandboxing a browser, it would be unsafe to mount this directory inside the sandbox.
Mounting the socket into the sandbox's filesystem is also not possible in cases where KeePassXC is [re]started after the browser has started.
This commit moves the socket into its own isolated subdirectory, which can be safely mounted into sandboxes. Sandbox engines can create the directory themselves (in case the browser starts before KeePassXC). Both Flatpak and Firejail support this configuration.
A symlink is also created, linking the previous location to the new location. This is meant for backwards compatibility and should eventually be dropped.
The directory can't be named `org.keepassxc.KeePassXC.BrowserServer`,
since that would collide with the symlink. Instead, the directory has been created to match the format used for Flatpak builds, which make it a bit less of a snowflake build, while following accepted conventions.
Given that the preferred path now matches what Flatpak uses, the block handling Flatpak and non-Flatpak is now the same.
If `$XDG_RUNTIME_DIR` is undefined, the temporary directory is used, though reading the socket from this location is discouraged.
Closes: https://github.com/keepassxreboot/keepassxc/issues/8018
References: https://github.com/keepassxreboot/keepassxc/discussions/6741
2022-05-28 22:19:48 +00:00
|
|
|
// This returns XDG_RUNTIME_DIR or else a temporary subdirectory.
|
2020-05-11 01:20:00 +00:00
|
|
|
QString path = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
|
Move socket into separate directory (#8030)
This is mostly to ease setup and configuration with sandboxed browsers.
The socket currently existing in `$XDG_RUNTIME_DIR`. When sandboxing a browser, it would be unsafe to mount this directory inside the sandbox.
Mounting the socket into the sandbox's filesystem is also not possible in cases where KeePassXC is [re]started after the browser has started.
This commit moves the socket into its own isolated subdirectory, which can be safely mounted into sandboxes. Sandbox engines can create the directory themselves (in case the browser starts before KeePassXC). Both Flatpak and Firejail support this configuration.
A symlink is also created, linking the previous location to the new location. This is meant for backwards compatibility and should eventually be dropped.
The directory can't be named `org.keepassxc.KeePassXC.BrowserServer`,
since that would collide with the symlink. Instead, the directory has been created to match the format used for Flatpak builds, which make it a bit less of a snowflake build, while following accepted conventions.
Given that the preferred path now matches what Flatpak uses, the block handling Flatpak and non-Flatpak is now the same.
If `$XDG_RUNTIME_DIR` is undefined, the temporary directory is used, though reading the socket from this location is discouraged.
Closes: https://github.com/keepassxreboot/keepassxc/issues/8018
References: https://github.com/keepassxreboot/keepassxc/discussions/6741
2022-05-28 22:19:48 +00:00
|
|
|
|
|
|
|
|
// Put the socket in a dedicated directory.
|
|
|
|
|
// This directory will be easily mountable by sandbox containers.
|
|
|
|
|
QString subPath = path + "/app/org.keepassxc.KeePassXC/";
|
|
|
|
|
QDir().mkpath(subPath);
|
|
|
|
|
|
|
|
|
|
QString socketPath = subPath + serverName;
|
|
|
|
|
#ifndef KEEPASSXC_DIST_FLATPAK
|
2022-10-25 12:59:15 +00:00
|
|
|
QFile::remove(socketPath);
|
Move socket into separate directory (#8030)
This is mostly to ease setup and configuration with sandboxed browsers.
The socket currently existing in `$XDG_RUNTIME_DIR`. When sandboxing a browser, it would be unsafe to mount this directory inside the sandbox.
Mounting the socket into the sandbox's filesystem is also not possible in cases where KeePassXC is [re]started after the browser has started.
This commit moves the socket into its own isolated subdirectory, which can be safely mounted into sandboxes. Sandbox engines can create the directory themselves (in case the browser starts before KeePassXC). Both Flatpak and Firejail support this configuration.
A symlink is also created, linking the previous location to the new location. This is meant for backwards compatibility and should eventually be dropped.
The directory can't be named `org.keepassxc.KeePassXC.BrowserServer`,
since that would collide with the symlink. Instead, the directory has been created to match the format used for Flatpak builds, which make it a bit less of a snowflake build, while following accepted conventions.
Given that the preferred path now matches what Flatpak uses, the block handling Flatpak and non-Flatpak is now the same.
If `$XDG_RUNTIME_DIR` is undefined, the temporary directory is used, though reading the socket from this location is discouraged.
Closes: https://github.com/keepassxreboot/keepassxc/issues/8018
References: https://github.com/keepassxreboot/keepassxc/discussions/6741
2022-05-28 22:19:48 +00:00
|
|
|
// Create a symlink at the legacy location for backwards compatibility.
|
|
|
|
|
QFile::link(socketPath, path + serverName);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return socketPath;
|
2020-05-11 01:20:00 +00:00
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
|
// Windows uses named pipes
|
2020-09-28 03:04:19 +00:00
|
|
|
return serverName + "_" + qgetenv("USERNAME");
|
2020-05-11 01:20:00 +00:00
|
|
|
#else // Q_OS_MACOS and others
|
|
|
|
|
return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverName;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
} // namespace BrowserShared
|