Commit a8551e99 authored by chriadam's avatar chriadam Committed by Raine Makelainen

[nemo-qml-plugin-systemsettings] Support lock/unlock in udisks2monitor. Contributes to JB#42526

If an external mass storage device (USB or SDCard) is encrypted, we
need to allow the user the unlock (decrypt) the device from the
mass storage UI.  This commit adds unlock() (and lock()) methods
to the partition model (and plumbs that to the udisks2monitor)
to allow such a request to be performed.
parent beee054c
......@@ -62,7 +62,11 @@ public:
Mounted,
Unmounting,
Formatting,
Formatted
Formatted,
Unlocking,
Unlocked,
Locking,
Locked
};
Q_DECLARE_FLAGS(StorageTypes, StorageType)
......
......@@ -56,6 +56,8 @@ PartitionManagerPrivate::PartitionManagerPrivate()
m_udisksMonitor.reset(new UDisks2::Monitor(this));
connect(m_udisksMonitor.data(), &UDisks2::Monitor::status, this, &PartitionManagerPrivate::status);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::errorMessage, this, &PartitionManagerPrivate::errorMessage);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::lockError, this, &PartitionManagerPrivate::lockError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::unlockError, this, &PartitionManagerPrivate::unlockError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::mountError, this, &PartitionManagerPrivate::mountError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::unmountError, this, &PartitionManagerPrivate::unmountError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::formatError, this, &PartitionManagerPrivate::formatError);
......@@ -273,11 +275,33 @@ void PartitionManagerPrivate::refresh(const Partitions &partitions, Partitions &
}
}
void PartitionManagerPrivate::lock(const Partition &partition)
{
qCInfo(lcMemoryCardLog) << "Can lock:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->lock(partition.deviceName());
} else {
qCWarning(lcMemoryCardLog) << "Lock allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
}
void PartitionManagerPrivate::unlock(const Partition &partition, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << "Can unlock:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->instance()->unlock(partition.deviceName(), passphrase);
} else {
qCWarning(lcMemoryCardLog) << "Unlock allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
}
void PartitionManagerPrivate::mount(const Partition &partition)
{
qCInfo(lcMemoryCardLog) << "Can mount:" << externalMedia.match(partition.deviceName()).hasMatch() << partition.deviceName();
if (externalMedia.match(partition.deviceName()).hasMatch()) {
m_udisksMonitor->mount(partition.deviceName());
m_udisksMonitor->instance()->mount(partition.deviceName());
} else {
qCWarning(lcMemoryCardLog) << "Mount allowed only for external memory cards," << partition.devicePath() << "is not allowed";
}
}
......
......@@ -66,6 +66,8 @@ public:
void refresh(PartitionPrivate *partition);
void refresh(const Partitions &partitions, Partitions &changedPartitions);
void lock(const Partition &partition);
void unlock(const Partition &partition, const QString &passphrase);
void mount(const Partition &partition);
void unmount(const Partition &partition);
void format(const Partition &partition, const QString &type, const QString &label, const QString &passphrase);
......@@ -79,6 +81,8 @@ signals:
void status(const QString &deviceName, Partition::Status);
void errorMessage(const QString &objectPath, const QString &errorName);
void lockError(Partition::Error error);
void unlockError(Partition::Error error);
void mountError(Partition::Error error);
void unmountError(Partition::Error error);
void formatError(Partition::Error error);
......
......@@ -51,6 +51,13 @@ PartitionModel::PartitionModel(QObject *parent)
connect(m_manager.data(), &PartitionManagerPrivate::errorMessage, this, &PartitionModel::errorMessage);
connect(m_manager.data(), &PartitionManagerPrivate::lockError, this, [this](Partition::Error error) {
emit lockError(static_cast<PartitionModel::Error>(error));
});
connect(m_manager.data(), &PartitionManagerPrivate::unlockError, this, [this](Partition::Error error) {
emit unlockError(static_cast<PartitionModel::Error>(error));
});
connect(m_manager.data(), &PartitionManagerPrivate::mountError, this, [this](Partition::Error error) {
emit mountError(static_cast<PartitionModel::Error>(error));
});
......@@ -112,40 +119,94 @@ void PartitionModel::refresh(int index)
}
}
void PartitionModel::lock(const QString &deviceName)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->lock(partition);
break;
}
}
if (!found) {
qCWarning(lcMemoryCardLog) << "Unable to lock unknown device:" << deviceName;
}
}
void PartitionModel::unlock(const QString &deviceName, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->unlock(partition, passphrase);
break;
}
}
if (!found) {
qCWarning(lcMemoryCardLog) << "Unable to unlock unknown device:" << deviceName;
}
}
void PartitionModel::mount(const QString &deviceName)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->mount(partition);
break;
}
}
if (!found) {
qCWarning(lcMemoryCardLog) << "Unable to mount unknown device:" << deviceName;
}
}
void PartitionModel::unmount(const QString &deviceName)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->unmount(partition);
break;
}
}
if (!found) {
qCWarning(lcMemoryCardLog) << "Unable to unmount unknown device:" << deviceName;
}
}
void PartitionModel::format(const QString &deviceName, const QString &type, const QString &label, const QString &passphrase)
{
qCInfo(lcMemoryCardLog) << Q_FUNC_INFO << deviceName << type << label << m_partitions.count();
bool found = false;
for (const Partition &partition : m_partitions) {
if (deviceName == partition.deviceName()) {
found = true;
m_manager->format(partition, type, label, passphrase);
break;
}
}
if (!found) {
qCWarning(lcMemoryCardLog) << "Unable to format unknown device:" << deviceName;
}
}
void PartitionModel::update()
......
......@@ -119,6 +119,8 @@ public:
Q_INVOKABLE void refresh();
Q_INVOKABLE void refresh(int index);
Q_INVOKABLE void lock(const QString &deviceName);
Q_INVOKABLE void unlock(const QString &deviceName, const QString &passphrase);
Q_INVOKABLE void mount(const QString &deviceName);
Q_INVOKABLE void unmount(const QString &deviceName);
Q_INVOKABLE void format(const QString &deviceName, const QString &type, const QString &label, const QString &passphrase = QString());
......@@ -133,6 +135,8 @@ signals:
void storageTypesChanged();
void errorMessage(const QString &objectPath, const QString &errorName);
void lockError(Error error);
void unlockError(Error error);
void mountError(Error error);
void unmountError(Error error);
void formatError(Error error);
......
......@@ -49,6 +49,8 @@
#define UDISKS2_JOB_INTERFACE QLatin1String("org.freedesktop.UDisks2.Job")
// Jobs
#define UDISKS2_JOB_OP_ENC_LOCK QLatin1String("encrypted-lock")
#define UDISKS2_JOB_OP_ENC_UNLOCK QLatin1String("encrypted-unlock")
#define UDISKS2_JOB_OP_FS_UNMOUNT QLatin1String("filesystem-unmount")
#define UDISKS2_JOB_OP_FS_MOUNT QLatin1String("filesystem-mount")
#define UDISKS2_JOB_OP_CLEANUP QLatin1String("cleanup")
......@@ -61,6 +63,8 @@
// Lock, Unlock, Mount, Unmount, Format
#define UDISKS2_BLOCK_DEVICE_PATH QString(QLatin1String("/org/freedesktop/UDisks2/block_devices/%1"))
#define UDISKS2_BLOCK_FORMAT QLatin1String("Format")
#define UDISKS2_ENCRYPTED_LOCK QLatin1String("Lock")
#define UDISKS2_ENCRYPTED_UNLOCK QLatin1String("Unlock")
#define UDISKS2_FILESYSTEM_MOUNT QLatin1String("Mount")
#define UDISKS2_FILESYSTEM_UNMOUNT QLatin1String("Unmount")
......
......@@ -124,6 +124,10 @@ UDisks2::Job::Operation UDisks2::Job::operation() const
return Unmount;
} else if (operation == UDISKS2_JOB_OF_FS_FORMAT) {
return Format;
} else if (operation == UDISKS2_JOB_OP_ENC_LOCK) {
return Lock;
} else if (operation == UDISKS2_JOB_OP_ENC_UNLOCK) {
return Unlock;
} else {
return Unknown;
}
......
......@@ -53,6 +53,8 @@ public:
Q_ENUM(Status)
enum Operation {
Lock,
Unlock,
Mount,
Unmount,
Format,
......
This diff is collapsed.
......@@ -37,6 +37,7 @@
#include <QExplicitlySharedDataPointer>
#include <QRegularExpression>
#include <QQueue>
#include <QVariantList>
#include "partitionmodel.h"
#include "partitionmanager_p.h"
......@@ -56,15 +57,17 @@ class Job;
struct Operation
{
Operation(const QString &command, const QString &deviceName, const QString &type, const QVariantHash &arguments)
Operation(const QString &command, const QString &deviceName, const QString &dbusObjectPath, const QString &type, const QVariantHash &arguments)
: command(command)
, deviceName(deviceName)
, dbusObjectPath(dbusObjectPath)
, type(type)
, arguments(arguments)
{}
QString command;
QString deviceName;
QString dbusObjectPath;
QString type;
QVariantHash arguments;
};
......@@ -78,6 +81,9 @@ public:
static Monitor *instance();
void lock(const QString &deviceName);
void unlock(const QString &deviceName, const QString &passphrase);
void mount(const QString &deviceName);
void unmount(const QString &deviceName);
......@@ -86,6 +92,8 @@ public:
signals:
void status(const QString &deviceName, Partition::Status);
void errorMessage(const QString &objectPath, const QString &errorName);
void lockError(Partition::Error error);
void unlockError(Partition::Error error);
void mountError(Partition::Error error);
void unmountError(Partition::Error error);
void formatError(Partition::Error error);
......@@ -100,13 +108,14 @@ private:
void updatePartitionStatus(const UDisks2::Job *job, bool success);
bool externalBlockDevice(const QString &objectPathStr) const;
void startMountOperation(const QString &dbusMethod, const QString &deviceName, QVariantHash arguments);
void startLuksOperation(const QString &deviceName, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
void startMountOperation(const QString &deviceName, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
void lookupPartitions(PartitionManagerPrivate::Partitions &affectedPartions, const QStringList &objects);
void createPartition(const Block *block);
void createBlockDevice(const QString &path, const QVariantMap &dict);
void doFormat(const QString &deviceName, const QString &type, const QVariantHash &arguments);
void doFormat(const QString &deviceName, const QString &dbusObjectPath, const QString &type, const QVariantHash &arguments);
void getBlockDevices();
private:
......
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