Lukas Tinkl b4e064e
diff -Naur kdelibs-4.1.72.policykit/solid/solid/backends/hal/halstorageaccess.cpp kdelibs-4.1.72/solid/solid/backends/hal/halstorageaccess.cpp
Lukas Tinkl b4e064e
--- kdelibs-4.1.72.policykit/solid/solid/backends/hal/halstorageaccess.cpp	2008-11-04 18:13:11.000000000 +0100
Lukas Tinkl b4e064e
+++ kdelibs-4.1.72/solid/solid/backends/hal/halstorageaccess.cpp	2008-11-10 18:45:41.000000000 +0100
Lukas Tinkl b4e064e
@@ -17,6 +17,8 @@
Lukas Tinkl 269fc22
 
Lukas Tinkl 269fc22
 */
Lukas Tinkl 269fc22
 
Lukas Tinkl 269fc22
+#include <config-prefix.h> // for LIBEXEC_INSTALL_DIR
Lukas Tinkl 269fc22
+
ac2f01c
 #include "halstorageaccess.h"
ac2f01c
 
Lukas Tinkl b4e064e
 #include "halfstabhandling.h"
Lukas Tinkl b4e064e
@@ -172,11 +174,21 @@
ac2f01c
 {
ac2f01c
     // TODO: Better error reporting here
ac2f01c
     if (m_setupInProgress) {
Lukas Tinkl b4e064e
+	if (error.name() == "org.freedesktop.Hal.Device.PermissionDeniedByPolicy") {
ac2f01c
+            if (callPrivilegedMount())
ac2f01c
+              return;
ac2f01c
+            // if we fail to run kdesu, fall through and emit the original PermissionDeniedByPolicy error
ac2f01c
+        }
ac2f01c
         m_setupInProgress = false;
ac2f01c
         emit setupDone(Solid::UnauthorizedOperation,
ac2f01c
                        error.name()+": "+error.message(),
ac2f01c
                        m_device->udi());
ac2f01c
     } else if (m_teardownInProgress) {
Lukas Tinkl b4e064e
+	if (error.name() == "org.freedesktop.Hal.Device.PermissionDeniedByPolicy") {
ac2f01c
+            if (callPrivilegedUnmount())
ac2f01c
+              return;
ac2f01c
+            // if we fail to run kdesu, fall through and emit the original PermissionDeniedByPolicy error
ac2f01c
+        }
ac2f01c
         m_teardownInProgress = false;
ac2f01c
         emit teardownDone(Solid::UnauthorizedOperation,
ac2f01c
                           error.name()+": "+error.message(),
Lukas Tinkl b4e064e
@@ -294,8 +306,9 @@
f83c982
 #else
f83c982
     QString uid="uid=";
f83c982
 #endif
f83c982
-    if (halOptions.contains(uid)) {
Lukas Tinkl b4e064e
-        options << uid+QString::number(::getuid());
Lukas Tinkl b4e064e
+    if (halOptions.contains(uid) &&
Lukas Tinkl b4e064e
+       (fstype == "vfat" || fstype == "iso9660" || fstype == "hfs" || fstype == "udf")) {
Lukas Tinkl b4e064e
+            options << uid+QString::number(::getuid());
f83c982
     }
f83c982
 
Lukas Tinkl b4e064e
 #ifdef Q_OS_FREEBSD
Lukas Tinkl b4e064e
@@ -333,6 +346,59 @@
ac2f01c
                               SLOT(slotDBusError(const QDBusError &)));
ac2f01c
 }
ac2f01c
 
ac2f01c
+bool Solid::Backends::Hal::StorageAccess::callPrivilegedMount()
ac2f01c
+{
ac2f01c
+    QString udi = m_device->udi();
ac2f01c
+    QString options;
ac2f01c
+    QStringList halOptions = m_device->property("volume.mount.valid_options").toStringList();
ac2f01c
+    QString fstype = m_device->property("volume.fstype").toString();
ac2f01c
+
ac2f01c
+    if (halOptions.contains("uid=")
ac2f01c
+        && (fstype == "vfat" || fstype == "iso9660" || fstype == "hfs" || fstype == "udf")) {
ac2f01c
+        options = "uid="+QString::number(::getuid());
ac2f01c
+    }
ac2f01c
+
ac2f01c
+    m_process = new QProcess(this);
ac2f01c
+
ac2f01c
+    connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
ac2f01c
+            this, SLOT(slotProcessFinished(int, QProcess::ExitStatus)));
ac2f01c
+
ac2f01c
+    m_process->start(LIBEXEC_INSTALL_DIR "/kdesu", QStringList() << "-d" << "-t"
ac2f01c
+        << "--noignorebutton" << "-c"
ac2f01c
+        << QString::fromLatin1("dbus-send  --system --print-reply --dest=org.freedesktop.Hal %1 "
ac2f01c
+                               "org.freedesktop.Hal.Device.Volume.Mount string: string: "
ac2f01c
+                               "array:string:%2").arg(udi).arg(options));
ac2f01c
+
ac2f01c
+    if (m_process->waitForStarted()) {
ac2f01c
+        return true;
ac2f01c
+    } else {
ac2f01c
+        delete m_process;
ac2f01c
+        return false;
ac2f01c
+    }
ac2f01c
+}
ac2f01c
+
ac2f01c
+bool Solid::Backends::Hal::StorageAccess::callPrivilegedUnmount()
ac2f01c
+{
ac2f01c
+    QString udi = m_device->udi();
ac2f01c
+
ac2f01c
+    m_process = new QProcess(this);
ac2f01c
+
ac2f01c
+    connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
ac2f01c
+            this, SLOT(slotProcessFinished(int, QProcess::ExitStatus)));
ac2f01c
+
ac2f01c
+    m_process->start(LIBEXEC_INSTALL_DIR "/kdesu", QStringList() << "-d" << "-t"
ac2f01c
+        << "--noignorebutton" << "-c"
ac2f01c
+        << QString::fromLatin1("dbus-send  --system --print-reply --dest=org.freedesktop.Hal %1 "
ac2f01c
+                               "org.freedesktop.Hal.Device.Volume.Unmount array:string:").arg(udi));
ac2f01c
+
ac2f01c
+    if (m_process->waitForStarted()) {
ac2f01c
+        return true;
ac2f01c
+    } else {
ac2f01c
+        delete m_process;
ac2f01c
+        return false;
ac2f01c
+    }
ac2f01c
+}
ac2f01c
+
Lukas Tinkl b4e064e
 bool StorageAccess::callHalVolumeUnmount()
ac2f01c
 {
Lukas Tinkl b4e064e
     QDBusConnection c = QDBusConnection::systemBus();
Lukas Tinkl b4e064e
diff -Naur kdelibs-4.1.72.policykit/solid/solid/backends/hal/halstorageaccess.h kdelibs-4.1.72/solid/solid/backends/hal/halstorageaccess.h
Lukas Tinkl b4e064e
--- kdelibs-4.1.72.policykit/solid/solid/backends/hal/halstorageaccess.h	2008-05-21 13:07:38.000000000 +0200
Lukas Tinkl b4e064e
+++ kdelibs-4.1.72/solid/solid/backends/hal/halstorageaccess.h	2008-11-10 18:45:01.000000000 +0100
ac2f01c
@@ -69,6 +69,9 @@
ac2f01c
     bool callSystemMount();
ac2f01c
     bool callSystemUnmount();
ac2f01c
 
ac2f01c
+    bool callPrivilegedMount();
ac2f01c
+    bool callPrivilegedUnmount();
ac2f01c
+
ac2f01c
     bool requestPassphrase();
ac2f01c
     void callCryptoSetup(const QString &passphrase);
ac2f01c
     bool callCryptoTeardown();