Skip to content

Commit

Permalink
Merge branch 'jb45974' into 'master'
Browse files Browse the repository at this point in the history
Do not expose /home and / partitions through udisk block devices

See merge request mer-core/nemo-qml-plugin-systemsettings!107
  • Loading branch information
rainemak committed May 28, 2019
2 parents d02d59d + fd5bef6 commit 72f3ec0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
40 changes: 17 additions & 23 deletions src/udisks2block.cpp
Expand Up @@ -28,11 +28,6 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
qCWarning(lcMemoryCardLog) << "Failed to connect to Block properties change interface" << m_path << m_connection.lastError().message();
}

QDBusInterface dbusPropertyInterface(UDISKS2_SERVICE,
m_path,
DBUS_OBJECT_PROPERTIES_INTERFACE,
m_connection);

qCInfo(lcMemoryCardLog) << "Creating a new block. Mountable:" << m_mountable << ", encrypted:" << m_encrypted << "object path:" << m_path << "data is empty:" << m_data.isEmpty();

if (m_interfacePropertyMap.isEmpty()) {
Expand Down Expand Up @@ -68,15 +63,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
qCInfo(lcMemoryCardLog) << "Drive properties:" << driveProperties;
m_drive = driveProperties;
});

connect(m_pendingDrive.data(), &QObject::destroyed, this, &Block::complete);
});

connect(m_pendingEncrypted.data(), &QObject::destroyed, this, &Block::complete);
connect(m_pendingFileSystem.data(), &QObject::destroyed, this, &Block::complete);
connect(m_pendingPartitionTable.data(), &QObject::destroyed, this, &Block::complete);
connect(m_pendingPartition.data(), &QObject::destroyed, this, &Block::complete);
connect(m_pendingBlock.data(), &QObject::destroyed, this, &Block::complete);
} else {
if (m_mountable) {
QVariantMap map = interfacePropertyMap.value(UDISKS2_FILESYSTEM_INTERFACE);
Expand Down Expand Up @@ -274,7 +261,8 @@ bool UDisks2::Block::isReadOnly() const
bool UDisks2::Block::isExternal() const
{
const QString prefDevice = preferredDevice();
return prefDevice != QStringLiteral("/dev/sailfish/home") && prefDevice != QStringLiteral("/dev/sailfish/root");
return prefDevice != QStringLiteral("/dev/sailfish/home") && prefDevice != QStringLiteral("/dev/sailfish/root")
&& mountPath() != QStringLiteral("/home") && mountPath() != QStringLiteral("/");
}

bool UDisks2::Block::isValid() const
Expand Down Expand Up @@ -345,7 +333,7 @@ void UDisks2::Block::addInterface(const QString &interface, QVariantMap property
{
m_interfacePropertyMap.insert(interface, propertyMap);
if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
setMountable(true);
updateFileSystemInterface(propertyMap);
} else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
setEncrypted(true);
}
Expand All @@ -359,7 +347,7 @@ void UDisks2::Block::removeInterface(const QString &interface)
} else if (interface == UDISKS2_DRIVE_INTERFACE) {
m_drive.clear();
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
setMountable(false);
updateFileSystemInterface(QVariantMap());
} else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
setEncrypted(false);
}
Expand Down Expand Up @@ -451,21 +439,25 @@ bool UDisks2::Block::isCompleted() const
void UDisks2::Block::updateFileSystemInterface(const QVariant &filesystemInterface)
{
QVariantMap filesystem = NemoDBus::demarshallArgument<QVariantMap>(filesystemInterface);
m_interfacePropertyMap.insert(UDISKS2_FILESYSTEM_INTERFACE, filesystem);

bool interfaceChange = m_interfacePropertyMap.contains(UDISKS2_FILESYSTEM_INTERFACE) != filesystem.isEmpty();
if (filesystem.isEmpty()) {
m_interfacePropertyMap.remove(UDISKS2_FILESYSTEM_INTERFACE);
} else {
m_interfacePropertyMap.insert(UDISKS2_FILESYSTEM_INTERFACE, filesystem);
}
QList<QByteArray> mountPointList = NemoDBus::demarshallArgument<QList<QByteArray> >(filesystem.value(QStringLiteral("MountPoints")));
m_mountPath.clear();

for (const QByteArray &bytes : mountPointList) {
if (bytes.startsWith("/run")) {
m_mountPath = QString::fromLocal8Bit(bytes);
break;
}
if (!mountPointList.isEmpty()) {
m_mountPath = QString::fromLocal8Bit(mountPointList.at(0));
}

bool triggerUpdate = false;
blockSignals(true);
triggerUpdate = setMountable(true);
triggerUpdate = setMountable(!filesystem.isEmpty());
triggerUpdate |= clearFormattingState();
triggerUpdate |= interfaceChange;
blockSignals(false);

if (triggerUpdate) {
Expand Down Expand Up @@ -529,6 +521,8 @@ void UDisks2::Block::getProperties(const QString &path, const QString &interface
m_connection);
QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall(DBUS_GET_ALL, interface);
watcherPointer = new QDBusPendingCallWatcher(pendingCall, this);

connect(watcherPointer.data(), &QObject::destroyed, this, &Block::complete);
connect(watcherPointer.data(), &QDBusPendingCallWatcher::finished, this, [success, path, interface](QDBusPendingCallWatcher *watcher) {
if (watcher->isValid() && watcher->isFinished()) {
QDBusPendingReply<> reply = *watcher;
Expand Down
2 changes: 1 addition & 1 deletion src/udisks2blockdevices.cpp
Expand Up @@ -280,7 +280,7 @@ void BlockDevices::complete(Block *block, bool forceAccept)
if (block->isEncrypted()) {
QString newPath = block->path();
unlocked = find([newPath](const Block *block) {
return block->cryptoBackingDeviceObjectPath() == newPath;
return block->cryptoBackingDeviceObjectPath() == newPath && !block->isLocking();
});
}

Expand Down
12 changes: 6 additions & 6 deletions src/udisks2monitor.cpp
Expand Up @@ -261,16 +261,16 @@ void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const
operation == UDISKS2_JOB_OF_FS_FORMAT) {
UDisks2::Job *job = new UDisks2::Job(path, dict);
updatePartitionStatus(job, true);
if (job->operation() == Job::Lock) {
for (const QString &dbusObjectPath : job->objects()) {
m_blockDevices->lock(dbusObjectPath);
}
}

connect(job, &UDisks2::Job::completed, this, [this](bool success) {
UDisks2::Job *job = qobject_cast<UDisks2::Job *>(sender());
job->dumpInfo();

if (job->operation() == Job::Lock) {
for (const QString &dbusObjectPath : job->objects()) {
m_blockDevices->lock(dbusObjectPath);
}
} else {
if (job->operation() != Job::Lock) {
updatePartitionStatus(job, success);
}
});
Expand Down

0 comments on commit 72f3ec0

Please sign in to comment.