[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/KDE/4.10] solid/solid/backends/udisks2: fix encrypted media handling
From:       Lukáš Tinkl <lukas () kde ! org>
Date:       2012-11-06 23:34:48
Message-ID: 20121106233448.3EAF8A60C4 () git ! kde ! org
[Download RAW message or body]

Git commit 108568eb11a4710d2c435b7a3f8138f71fd3b207 by Lukáš Tinkl.
Committed on 07/11/2012 at 00:32.
Pushed by lukas into branch 'KDE/4.10'.

fix encrypted media handling

storing clear text path in a member variable is not possible (doesn't
exist in udisks2), instead we have to query for it when needed as it
might change from outside

also fix the icon and description

M  +2    -2    solid/solid/backends/udisks2/udisksdevice.cpp
M  +55   -23   solid/solid/backends/udisks2/udisksstorageaccess.cpp
M  +1    -1    solid/solid/backends/udisks2/udisksstorageaccess.h

http://commits.kde.org/kdelibs/108568eb11a4710d2c435b7a3f8138f71fd3b207

diff --git a/solid/solid/backends/udisks2/udisksdevice.cpp \
b/solid/solid/backends/udisks2/udisksdevice.cpp index 270128b..df34b77 100644
--- a/solid/solid/backends/udisks2/udisksdevice.cpp
+++ b/solid/solid/backends/udisks2/udisksdevice.cpp
@@ -493,9 +493,9 @@ QString Device::volumeDescription() const
     if (isEncryptedContainer())
     {
         if (!size_str.isEmpty())
-            description = QCoreApplication::translate("", "%1 Encrypted Container", \
"%1 is the size").arg(size_str); +            description = \
QCoreApplication::translate("", "%1 Encrypted Drive", "%1 is the \
size").arg(size_str);  else
-            description = QCoreApplication::translate("", "Encrypted Container");
+            description = QCoreApplication::translate("", "Encrypted Drive");
     }
     else if (drive_type == Solid::StorageDrive::HardDisk && !drive_is_removable)
     {
diff --git a/solid/solid/backends/udisks2/udisksstorageaccess.cpp \
b/solid/solid/backends/udisks2/udisksstorageaccess.cpp index f28540b..5852536 100644
--- a/solid/solid/backends/udisks2/udisksstorageaccess.cpp
+++ b/solid/solid/backends/udisks2/udisksstorageaccess.cpp
@@ -22,10 +22,10 @@
 #include "udisksstorageaccess.h"
 #include "udisks2.h"
 
-#include <QtCore/QProcess>
 #include <QtDBus/QtDBus>
 #include <QtGui/QApplication>
 #include <QtGui/QWidget>
+#include <QtXml/QDomDocument>
 
 using namespace Solid::Backends::UDisks2;
 
@@ -63,9 +63,11 @@ bool StorageAccess::isLuksDevice() const
 bool StorageAccess::isAccessible() const
 {
     if (isLuksDevice()) { // check if the cleartext slave is mounted
-        if (m_clearTextPath.isEmpty() || m_clearTextPath == "/")
+        const QString path = clearTextPath();
+        //qDebug() << Q_FUNC_INFO << "CLEARTEXT device path: " << path;
+        if (path.isEmpty() || path == "/")
             return false;
-        Device holderDevice(m_clearTextPath);
+        Device holderDevice(path);
         return holderDevice.isMounted();
     }
 
@@ -74,15 +76,13 @@ bool StorageAccess::isAccessible() const
 
 QString StorageAccess::filePath() const
 {
-    if (!isAccessible())
-        return QString();
-
     QByteArrayList mntPoints;
 
     if (isLuksDevice()) {  // encrypted (and unlocked) device
-        if (m_clearTextPath.isEmpty() || m_clearTextPath == "/")
+        const QString path = clearTextPath();
+        if (path.isEmpty() || path == "/")
             return QString();
-        Device holderDevice(m_clearTextPath);
+        Device holderDevice(path);
         mntPoints = qdbus_cast<QByteArrayList>(holderDevice.prop("MountPoints"));
         if (!mntPoints.isEmpty())
             return QFile::decodeName(mntPoints.first()); // FIXME Solid doesn't \
support multiple mount points @@ -110,7 +110,7 @@ bool StorageAccess::setup()
     m_setupInProgress = true;
     m_device->broadcastActionRequested("setup");
 
-    if (m_device->isEncryptedContainer())
+    if (m_device->isEncryptedContainer() && clearTextPath().isEmpty())
         return requestPassphrase();
     else
         return mount();
@@ -136,18 +136,21 @@ void StorageAccess::checkAccessibility()
     const bool old_isAccessible = m_isAccessible;
     updateCache();
 
+    //qDebug() << QString("CHECKING ACCESSIBILITY, device %1 was mounted: \
%2").arg(m_device->udi()).arg(old_isAccessible); +    //qDebug() << "CLEARTEXT path:" \
<< clearTextPath(); +
     if (old_isAccessible != m_isAccessible) {
-        Q_EMIT accessibilityChanged(m_isAccessible, isLuksDevice() ? m_clearTextPath \
: m_device->udi()); +        //qDebug() << "\tnow is mounted:" << m_isAccessible;
+        Q_EMIT accessibilityChanged(m_isAccessible, isLuksDevice() ? clearTextPath() \
: m_device->udi());  }
 }
 
 void StorageAccess::slotDBusReply( const QDBusMessage & reply )
 {
+    const QString ctPath = clearTextPath();
     if (m_setupInProgress)
     {
         if (isLuksDevice() && !isAccessible()) { // unlocked device, now mount it
-            if (reply.type() == QDBusMessage::ReplyMessage)  // we've got a response \
                from Unlock
-                m_clearTextPath = \
reply.arguments().value(0).value<QDBusObjectPath>().path();  mount();
         }
         else // Don't broadcast setupDone unless the setup is really done. (Fix \
kde#271156) @@ -160,17 +163,17 @@ void StorageAccess::slotDBusReply( const \
QDBusMessage & reply )  }
     else if (m_teardownInProgress)  // FIXME
     {
-        if (isLuksDevice() && !m_clearTextPath.isEmpty() && m_clearTextPath != "/") \
// unlocked device, lock it +        if (isLuksDevice() && !ctPath.isEmpty() && \
ctPath != "/") // unlocked device, lock it  {
             callCryptoTeardown();
         }
-        else if (!m_clearTextPath.isEmpty() && m_clearTextPath != "/") {
+        else if (!ctPath.isEmpty() && ctPath != "/") {
             callCryptoTeardown(true); // Lock crypted parent
         }
         else
         {
             // try to "eject" (aka safely remove) from the (parent) drive, e.g. SD \
                card from a reader
-            QString drivePath = \
m_device->prop("Drive").value<QDBusObjectPath>().path(); +            QString \
drivePath = m_device->drivePath();  if (!drivePath.isEmpty() || drivePath != "/")
             {
                 Device drive(drivePath);
@@ -195,6 +198,8 @@ void StorageAccess::slotDBusReply( const QDBusMessage & reply )
 
 void StorageAccess::slotDBusError( const QDBusError & error )
 {
+    //qDebug() << Q_FUNC_INFO << "DBUS ERROR:" << error.name() << error.message();
+
     if (m_setupInProgress)
     {
         m_setupInProgress = false;
@@ -206,7 +211,6 @@ void StorageAccess::slotDBusError( const QDBusError & error )
     else if (m_teardownInProgress)
     {
         m_teardownInProgress = false;
-        m_clearTextPath.clear();
         m_device->broadcastActionDone("teardown", \
                m_device->errorToSolidError(error.name()),
                                       m_device->errorToString(error.name()) + ": " + \
error.message());  checkAccessibility();
@@ -238,7 +242,6 @@ void StorageAccess::slotTeardownRequested()
 void StorageAccess::slotTeardownDone(int error, const QString &errorString)
 {
     m_teardownInProgress = false;
-    m_clearTextPath.clear();
     Q_EMIT teardownDone(static_cast<Solid::ErrorType>(error), errorString, \
m_device->udi());  
     checkAccessibility();
@@ -247,9 +250,10 @@ void StorageAccess::slotTeardownDone(int error, const QString \
&errorString)  bool StorageAccess::mount()
 {
     QString path = m_device->udi();
+    const QString ctPath = clearTextPath();
 
-    if (isLuksDevice()) { // mount options for the cleartext volume
-        path = m_clearTextPath;
+    if (isLuksDevice() && !ctPath.isEmpty()) { // mount options for the cleartext \
volume +        path = ctPath;
     }
 
     QDBusConnection c = QDBusConnection::systemBus();
@@ -269,9 +273,10 @@ bool StorageAccess::mount()
 bool StorageAccess::unmount()
 {
     QString path = m_device->udi();
+    const QString ctPath = clearTextPath();
 
-    if (isLuksDevice()) { // unmount options for the cleartext volume
-        path = m_clearTextPath;
+    if (isLuksDevice() && !ctPath.isEmpty()) { // unmount options for the cleartext \
volume +        path = ctPath;
     }
 
     QDBusConnection c = QDBusConnection::systemBus();
@@ -292,6 +297,35 @@ QString StorageAccess::generateReturnObjectPath()
     return "/org/kde/solid/UDisks2StorageAccess_"+QString::number(number++);
 }
 
+QString StorageAccess::clearTextPath() const
+{
+    const QString prefix = "/org/freedesktop/UDisks2/block_devices";
+    QDBusMessage call = QDBusMessage::createMethodCall(UD2_DBUS_SERVICE, prefix,
+                                                       DBUS_INTERFACE_INTROSPECT, \
"Introspect"); +    QDBusPendingReply<QString> reply = \
QDBusConnection::systemBus().asyncCall(call); +    reply.waitForFinished();
+
+    if (reply.isValid()) {
+        QDomDocument dom;
+        dom.setContent(reply.value());
+        QDomNodeList nodeList = dom.documentElement().elementsByTagName("node");
+        for (int i = 0; i < nodeList.count(); i++) {
+            QDomElement nodeElem = nodeList.item(i).toElement();
+            if (!nodeElem.isNull() && nodeElem.hasAttribute("name")) {
+                const QString udi = prefix + "/" + nodeElem.attribute("name");
+                Device holderDevice(udi);
+
+                if (m_device->udi() == \
holderDevice.prop("CryptoBackingDevice").value<QDBusObjectPath>().path()) { +         \
//qDebug() << Q_FUNC_INFO << "CLEARTEXT device path: " << udi; +                    \
return udi; +                }
+            }
+        }
+    }
+
+    return QString();
+}
+
 bool StorageAccess::requestPassphrase()
 {
     QString udi = m_device->udi();
@@ -354,8 +388,6 @@ bool StorageAccess::callCryptoTeardown(bool actOnParent)
                                                       UD2_DBUS_INTERFACE_ENCRYPTED, \
"Lock");  msg << QVariantMap();   // options, unused now
 
-    m_clearTextPath.clear();
-
     return c.callWithCallback(msg, this,
                               SLOT(slotDBusReply(const QDBusMessage &)),
                               SLOT(slotDBusError(const QDBusError &)));
diff --git a/solid/solid/backends/udisks2/udisksstorageaccess.h \
b/solid/solid/backends/udisks2/udisksstorageaccess.h index 2901067..ec91f89 100644
--- a/solid/solid/backends/udisks2/udisksstorageaccess.h
+++ b/solid/solid/backends/udisks2/udisksstorageaccess.h
@@ -86,6 +86,7 @@ private:
     bool callCryptoTeardown( bool actOnParent=false );
 
     QString generateReturnObjectPath();
+    QString clearTextPath() const;
 
 private:
     bool m_isAccessible;
@@ -93,7 +94,6 @@ private:
     bool m_teardownInProgress;
     bool m_passphraseRequested;
     QString m_lastReturnObject;
-    QString m_clearTextPath;  // path to the unlocked cleartext device
 
     static const int s_unmountTimeout = 0x7fffffff;
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic