Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit 72f3ec0

Browse files
committed
Merge branch 'jb45974' into 'master'
Do not expose /home and / partitions through udisk block devices See merge request mer-core/nemo-qml-plugin-systemsettings!107
2 parents d02d59d + fd5bef6 commit 72f3ec0

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

src/udisks2block.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
2828
qCWarning(lcMemoryCardLog) << "Failed to connect to Block properties change interface" << m_path << m_connection.lastError().message();
2929
}
3030

31-
QDBusInterface dbusPropertyInterface(UDISKS2_SERVICE,
32-
m_path,
33-
DBUS_OBJECT_PROPERTIES_INTERFACE,
34-
m_connection);
35-
3631
qCInfo(lcMemoryCardLog) << "Creating a new block. Mountable:" << m_mountable << ", encrypted:" << m_encrypted << "object path:" << m_path << "data is empty:" << m_data.isEmpty();
3732

3833
if (m_interfacePropertyMap.isEmpty()) {
@@ -68,15 +63,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
6863
qCInfo(lcMemoryCardLog) << "Drive properties:" << driveProperties;
6964
m_drive = driveProperties;
7065
});
71-
72-
connect(m_pendingDrive.data(), &QObject::destroyed, this, &Block::complete);
7366
});
74-
75-
connect(m_pendingEncrypted.data(), &QObject::destroyed, this, &Block::complete);
76-
connect(m_pendingFileSystem.data(), &QObject::destroyed, this, &Block::complete);
77-
connect(m_pendingPartitionTable.data(), &QObject::destroyed, this, &Block::complete);
78-
connect(m_pendingPartition.data(), &QObject::destroyed, this, &Block::complete);
79-
connect(m_pendingBlock.data(), &QObject::destroyed, this, &Block::complete);
8067
} else {
8168
if (m_mountable) {
8269
QVariantMap map = interfacePropertyMap.value(UDISKS2_FILESYSTEM_INTERFACE);
@@ -274,7 +261,8 @@ bool UDisks2::Block::isReadOnly() const
274261
bool UDisks2::Block::isExternal() const
275262
{
276263
const QString prefDevice = preferredDevice();
277-
return prefDevice != QStringLiteral("/dev/sailfish/home") && prefDevice != QStringLiteral("/dev/sailfish/root");
264+
return prefDevice != QStringLiteral("/dev/sailfish/home") && prefDevice != QStringLiteral("/dev/sailfish/root")
265+
&& mountPath() != QStringLiteral("/home") && mountPath() != QStringLiteral("/");
278266
}
279267

280268
bool UDisks2::Block::isValid() const
@@ -345,7 +333,7 @@ void UDisks2::Block::addInterface(const QString &interface, QVariantMap property
345333
{
346334
m_interfacePropertyMap.insert(interface, propertyMap);
347335
if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
348-
setMountable(true);
336+
updateFileSystemInterface(propertyMap);
349337
} else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
350338
setEncrypted(true);
351339
}
@@ -359,7 +347,7 @@ void UDisks2::Block::removeInterface(const QString &interface)
359347
} else if (interface == UDISKS2_DRIVE_INTERFACE) {
360348
m_drive.clear();
361349
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
362-
setMountable(false);
350+
updateFileSystemInterface(QVariantMap());
363351
} else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
364352
setEncrypted(false);
365353
}
@@ -451,21 +439,25 @@ bool UDisks2::Block::isCompleted() const
451439
void UDisks2::Block::updateFileSystemInterface(const QVariant &filesystemInterface)
452440
{
453441
QVariantMap filesystem = NemoDBus::demarshallArgument<QVariantMap>(filesystemInterface);
454-
m_interfacePropertyMap.insert(UDISKS2_FILESYSTEM_INTERFACE, filesystem);
442+
443+
bool interfaceChange = m_interfacePropertyMap.contains(UDISKS2_FILESYSTEM_INTERFACE) != filesystem.isEmpty();
444+
if (filesystem.isEmpty()) {
445+
m_interfacePropertyMap.remove(UDISKS2_FILESYSTEM_INTERFACE);
446+
} else {
447+
m_interfacePropertyMap.insert(UDISKS2_FILESYSTEM_INTERFACE, filesystem);
448+
}
455449
QList<QByteArray> mountPointList = NemoDBus::demarshallArgument<QList<QByteArray> >(filesystem.value(QStringLiteral("MountPoints")));
456450
m_mountPath.clear();
457451

458-
for (const QByteArray &bytes : mountPointList) {
459-
if (bytes.startsWith("/run")) {
460-
m_mountPath = QString::fromLocal8Bit(bytes);
461-
break;
462-
}
452+
if (!mountPointList.isEmpty()) {
453+
m_mountPath = QString::fromLocal8Bit(mountPointList.at(0));
463454
}
464455

465456
bool triggerUpdate = false;
466457
blockSignals(true);
467-
triggerUpdate = setMountable(true);
458+
triggerUpdate = setMountable(!filesystem.isEmpty());
468459
triggerUpdate |= clearFormattingState();
460+
triggerUpdate |= interfaceChange;
469461
blockSignals(false);
470462

471463
if (triggerUpdate) {
@@ -529,6 +521,8 @@ void UDisks2::Block::getProperties(const QString &path, const QString &interface
529521
m_connection);
530522
QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall(DBUS_GET_ALL, interface);
531523
watcherPointer = new QDBusPendingCallWatcher(pendingCall, this);
524+
525+
connect(watcherPointer.data(), &QObject::destroyed, this, &Block::complete);
532526
connect(watcherPointer.data(), &QDBusPendingCallWatcher::finished, this, [success, path, interface](QDBusPendingCallWatcher *watcher) {
533527
if (watcher->isValid() && watcher->isFinished()) {
534528
QDBusPendingReply<> reply = *watcher;

src/udisks2blockdevices.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void BlockDevices::complete(Block *block, bool forceAccept)
280280
if (block->isEncrypted()) {
281281
QString newPath = block->path();
282282
unlocked = find([newPath](const Block *block) {
283-
return block->cryptoBackingDeviceObjectPath() == newPath;
283+
return block->cryptoBackingDeviceObjectPath() == newPath && !block->isLocking();
284284
});
285285
}
286286

src/udisks2monitor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,16 @@ void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const
261261
operation == UDISKS2_JOB_OF_FS_FORMAT) {
262262
UDisks2::Job *job = new UDisks2::Job(path, dict);
263263
updatePartitionStatus(job, true);
264+
if (job->operation() == Job::Lock) {
265+
for (const QString &dbusObjectPath : job->objects()) {
266+
m_blockDevices->lock(dbusObjectPath);
267+
}
268+
}
264269

265270
connect(job, &UDisks2::Job::completed, this, [this](bool success) {
266271
UDisks2::Job *job = qobject_cast<UDisks2::Job *>(sender());
267272
job->dumpInfo();
268-
269-
if (job->operation() == Job::Lock) {
270-
for (const QString &dbusObjectPath : job->objects()) {
271-
m_blockDevices->lock(dbusObjectPath);
272-
}
273-
} else {
273+
if (job->operation() != Job::Lock) {
274274
updatePartitionStatus(job, success);
275275
}
276276
});

0 commit comments

Comments
 (0)