Commit dc21669b authored by Ivan Čukić's avatar Ivan Čukić 👁

Never use non-resolved paths for mounts and devices

BUG:405527
parent a73e803a
......@@ -114,7 +114,7 @@ FutureResult<> CryFsBackend::mount(const Device &device,
const auto cypher = payload["cryfs-cipher"].toString();
const auto shouldUpgrade = payload["cryfs-fs-upgrade"].toBool();
if (!dir.mkpath(device) || !dir.mkpath(mountPoint)) {
if (!dir.mkpath(device.data()) || !dir.mkpath(mountPoint.data())) {
return errorResult(Error::BackendError, i18n("Failed to create directories, check your permissions"));
}
......@@ -124,21 +124,21 @@ FutureResult<> CryFsBackend::mount(const Device &device,
cryfs({
"--cipher",
cypher,
device, // source directory to initialize cryfs in
mountPoint // where to mount the file system
device.data(), // source directory to initialize cryfs in
mountPoint.data() // where to mount the file system
})
// Cypher is not specified, use the default, whatever it is
:shouldUpgrade ?
cryfs({
device, // source directory to initialize cryfs in
mountPoint, // where to mount the file system
device.data(), // source directory to initialize cryfs in
mountPoint.data(), // where to mount the file system
"--allow-filesystem-upgrade"
})
: cryfs({
device, // source directory to initialize cryfs in
mountPoint // where to mount the file system
device.data(), // source directory to initialize cryfs in
mountPoint.data() // where to mount the file system
})
;
......
......@@ -70,15 +70,15 @@ FutureResult<> EncFsBackend::mount(const Device &device,
const auto password = payload[KEY_PASSWORD].toString();
if (!dir.mkpath(device) || !dir.mkpath(mountPoint)) {
if (!dir.mkpath(device.data()) || !dir.mkpath(mountPoint.data())) {
return errorResult(Error::BackendError, i18n("Failed to create directories, check your permissions"));
}
auto process = encfs({
"-S", // read password from stdin
"--standard", // If creating a file system, use the default options
device, // source directory to initialize encfs in
mountPoint // where to mount the file system
device.data(), // source directory to initialize encfs in
mountPoint.data() // where to mount the file system
});
auto result = makeFuture(process, hasProcessFinishedSuccessfully);
......
......@@ -123,7 +123,7 @@ FutureResult<> FuseBackend::initialize(const QString &name,
errorResult(Error::BackendError,
i18n("This directory already contains encrypted data")) :
directoryExists(device) || directoryExists(mountPoint) ?
directoryExists(device.data()) || directoryExists(mountPoint.data()) ?
errorResult(Error::BackendError,
i18n("You need to select empty directories for the encrypted storage and for the mount point")) :
......@@ -145,7 +145,7 @@ FutureResult<> FuseBackend::import(const QString &name,
errorResult(Error::BackendError,
i18n("This directory doesn't contain encrypted data")) :
!directoryExists(device) || directoryExists(mountPoint) ?
!directoryExists(device.data()) || directoryExists(mountPoint.data()) ?
errorResult(Error::BackendError,
i18n("You need to select an empty directory for the mount point")) :
......@@ -181,7 +181,7 @@ FutureResult<> FuseBackend::close(const Device &device,
i18n("Device is not open")) :
// otherwise
makeFuture(fusermount({ "-u", mountPoint }),
makeFuture(fusermount({ "-u", mountPoint.data() }),
hasProcessFinishedSuccessfully);
}
......@@ -270,12 +270,12 @@ bool FuseBackend::isOpened(const MountPoint &mountPoint) const
{
// warning: KMountPoint depends on /etc/mtab according to the documentation.
KMountPoint::Ptr ptr
= KMountPoint::currentMountPoints().findByPath(mountPoint);
= KMountPoint::currentMountPoints().findByPath(mountPoint.data());
// we can not rely on ptr->realDeviceName() since it is empty,
// KMountPoint can not get the source
return ptr && ptr->mountPoint() == mountPoint;
return ptr && ptr->mountPoint() == mountPoint.data();
}
} // namespace PlasmaVault
......
......@@ -46,7 +46,7 @@ Device::Device(const QString &device)
{
}
Device::operator QString() const
QString Device::data() const
{
// Done here because canonicalFilePath relies on file existence
return normalizePath(m_device);
......@@ -57,7 +57,7 @@ MountPoint::MountPoint(const QString &mountPoint)
{
}
MountPoint::operator QString() const
QString MountPoint::data() const
{
// Done here because canonicalFilePath relies on file existence
return normalizePath(m_mountPoint);
......
......@@ -31,12 +31,7 @@ namespace PlasmaVault {
class Device {
public:
explicit Device(const QString &device = QString());
operator QString() const;
inline QString data() const
{
return m_device;
}
QString data() const;
private:
QString m_device;
......@@ -57,18 +52,13 @@ inline bool operator== (const Device &left, const Device &right)
class MountPoint {
public:
explicit MountPoint(const QString &mountPoint = QString());
operator QString() const;
QString data() const;
inline bool isEmpty() const
{
return m_mountPoint.isEmpty();
}
inline QString data() const
{
return m_mountPoint;
}
private:
QString m_mountPoint;
};
......
......@@ -246,7 +246,7 @@ public:
const QString actualMountPoint = vaultData.mountPoint.data();
vaultConfig.writeEntry(CFG_MOUNT_POINT, actualMountPoint);
const QDir mountPointDir(vaultData.mountPoint);
const QDir mountPointDir(vaultData.mountPoint.data());
return
......@@ -261,7 +261,7 @@ public:
i18n("Mount point is not specified")) :
// Lets try to create the mount point
!mountPointDir.exists() && !QDir().mkpath(vaultData.mountPoint) ?
!mountPointDir.exists() && !QDir().mkpath(vaultData.mountPoint.data()) ?
errorData(Error::MountPointError,
i18n("Cannot create the mount point")) :
......@@ -470,7 +470,7 @@ FutureResult<> Vault::close()
} else {
// We want to check whether there is an application
// that is accessing the vault
AsynQt::Process::getOutput(QStringLiteral("lsof"), { QStringLiteral("-t"), mountPoint() })
AsynQt::Process::getOutput(QStringLiteral("lsof"), { QStringLiteral("-t"), mountPoint().data() })
| cast<QString>()
| onError([this] {
d->updateMessage(i18n("Unable to close the vault, an application is using it"));
......@@ -528,7 +528,7 @@ FutureResult<> Vault::forceClose()
using namespace AsynQt::operators;
AsynQt::await(
AsynQt::Process::getOutput(QStringLiteral("lsof"), { QStringLiteral("-t"), mountPoint() })
AsynQt::Process::getOutput(QStringLiteral("lsof"), { QStringLiteral("-t"), mountPoint().data() })
| cast<QString>()
| onError([this] {
d->updateMessage(i18n("Failed to fetch the list of applications using this vault"));
......@@ -651,7 +651,7 @@ MountPoint Vault::mountPoint() const
void Vault::setMountPoint(const MountPoint &mountPoint)
{
if (d->data->mountPoint != mountPoint.data()) {
if (d->data->mountPoint.data() != mountPoint.data()) {
QDir().rmpath(d->data->mountPoint.data());
QDir().mkpath(mountPoint.data());
......@@ -735,7 +735,7 @@ VaultInfo Vault::info() const
{
VaultInfo vaultInfo;
vaultInfo.device = device();
vaultInfo.device = device().data();
vaultInfo.name = name();
vaultInfo.status = status();
......
......@@ -51,8 +51,8 @@ class Vault: public QObject {
Q_OBJECT
Q_PROPERTY(PlasmaVault::Device device READ device)
Q_PROPERTY(PlasmaVault::MountPoint mountPoint READ mountPoint NOTIFY mountPointChanged)
Q_PROPERTY(QString mountPoint READ mountPoint NOTIFY mountPointChanged)
Q_PROPERTY(VaultInfo::Status status READ status NOTIFY statusChanged)
Q_PROPERTY(bool isInitialized READ isInitialized NOTIFY isInitializedChanged)
......
......@@ -192,13 +192,13 @@ void PlasmaVaultService::registerVault(Vault *vault)
{
if (!vault->isValid()) {
qWarning() << "Warning: Trying to register an invalid vault: "
<< vault->device();
<< vault->device().data();
return;
}
if (d->knownVaults.contains(vault->device())) {
qWarning() << "Warning: This one is already registered: "
<< vault->device();
<< vault->device().data();
return;
}
......@@ -266,16 +266,16 @@ void PlasmaVaultService::onVaultStatusChanged(VaultInfo::Status status)
// should be added or removed from the
// inhibitors list
const bool alreadyInhibiting =
devicesInhibittingNetworking.contains(vault->device());
devicesInhibittingNetworking.contains(vault->device().data());
if (status == VaultInfo::Opened && !alreadyInhibiting) {
auto deviceOpeningHandle = "{opening}" + vault->device();
auto deviceOpeningHandle = "{opening}" + vault->device().data();
devicesInhibittingNetworking.removeAll(deviceOpeningHandle);
devicesInhibittingNetworking << vault->device();
devicesInhibittingNetworking << vault->device().data();
}
if (status != VaultInfo::Opened && alreadyInhibiting) {
devicesInhibittingNetworking.removeAll(vault->device());
devicesInhibittingNetworking.removeAll(vault->device().data());
}
// Now, let's handle the networking part
......@@ -334,7 +334,7 @@ void PlasmaVaultService::openVault(const QString &device)
d->saveNetworkingState();
auto& devicesInhibittingNetworking = d->savedNetworkingState->devicesInhibittingNetworking;
auto deviceOpeningHandle = "{opening}" + vault->device();
auto deviceOpeningHandle = "{opening}" + vault->device().data();
// We need to check whether this vault
// should be added or removed from the
......@@ -351,7 +351,7 @@ void PlasmaVaultService::openVault(const QString &device)
auto stopInhibiting = [this, vault] {
auto& devicesInhibittingNetworking = d->savedNetworkingState->devicesInhibittingNetworking;
auto deviceOpeningHandle = "{opening}" + vault->device();
auto deviceOpeningHandle = "{opening}" + vault->device().data();
devicesInhibittingNetworking.removeAll(deviceOpeningHandle);
};
......@@ -409,18 +409,18 @@ void PlasmaVaultService::openVaultInFileManager(const QString &device)
{
if (auto vault = d->vaultFor(device)) {
if (vault->isOpened()) {
new KRun(QUrl::fromLocalFile((QString)vault->mountPoint()), nullptr);
new KRun(QUrl::fromLocalFile((QString)vault->mountPoint().data()), nullptr);
} else {
showPasswordMountDialog(vault,
[this, vault] {
emit vaultChanged(vault->info());
new KRun(QUrl::fromLocalFile((QString)vault->mountPoint()), nullptr);
new KRun(QUrl::fromLocalFile((QString)vault->mountPoint().data()), nullptr);
},
[this, vault] {
if (vault->status() != VaultInfo::Opened) {
auto& devicesInhibittingNetworking = d->savedNetworkingState->devicesInhibittingNetworking;
devicesInhibittingNetworking.removeAll(vault->device());
devicesInhibittingNetworking.removeAll(vault->device().data());
d->restoreNetworkingState();
}
});
......
......@@ -103,9 +103,9 @@ public:
auto modules = logic[Key(vault->backend().toLatin1())];
Vault::Payload payload {
{ KEY_DEVICE, QVariant(vault->device()) },
{ KEY_DEVICE, QVariant(vault->device().data()) },
{ KEY_NAME, QVariant(vault->name()) },
{ KEY_MOUNT_POINT, QVariant(vault->mountPoint()) },
{ KEY_MOUNT_POINT, QVariant(vault->mountPoint().data()) },
{ KEY_ACTIVITIES, QVariant(vault->activities()) },
{ KEY_OFFLINEONLY, QVariant(vault->isOfflineOnly()) }
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment