diff options
author | Michele Calgaro <[email protected]> | 2019-06-10 15:00:20 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2020-10-17 10:48:27 +0800 |
commit | 3676cf129d85151dd430633847e3c289327405d5 (patch) | |
tree | 5ef29a2767f54ad7b642a75355bff277e47c9449 /tdeioslave/media/mediamanager | |
parent | 11beb5658031277ef94a1506a6668ff32b1ea111 (diff) | |
download | tdebase-3676cf129d85151dd430633847e3c289327405d5.tar.gz tdebase-3676cf129d85151dd430633847e3c289327405d5.zip |
tdeioslave media: added initial support for unlocking/locking of encrypted devices.
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'tdeioslave/media/mediamanager')
-rw-r--r-- | tdeioslave/media/mediamanager/halbackend.cpp | 2 | ||||
-rw-r--r-- | tdeioslave/media/mediamanager/mediamanager.cpp | 6 | ||||
-rw-r--r-- | tdeioslave/media/mediamanager/tdehardwarebackend.cpp | 89 | ||||
-rw-r--r-- | tdeioslave/media/mediamanager/tdehardwarebackend.h | 4 |
4 files changed, 88 insertions, 13 deletions
diff --git a/tdeioslave/media/mediamanager/halbackend.cpp b/tdeioslave/media/mediamanager/halbackend.cpp index 157f89212..b6f35c997 100644 --- a/tdeioslave/media/mediamanager/halbackend.cpp +++ b/tdeioslave/media/mediamanager/halbackend.cpp @@ -1417,7 +1417,6 @@ void HALBackend::slotResult(TDEIO::Job *job) if (job->error() == TDEIO::ERR_COULD_NOT_UNMOUNT) { TQString proclist(listUsingProcesses(medium)); - qerror = "<qt>"; qerror += "<p>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and " "currently mounted at <b>%4</b> could not be unmounted. ").arg( "system:/media/" + medium->name(), @@ -1430,7 +1429,6 @@ void HALBackend::slotResult(TDEIO::Job *job) if (!proclist.isEmpty()) { qerror += proclist; } - qerror += "</qt>"; } else if (job->error()) { qerror = job->errorText(); } diff --git a/tdeioslave/media/mediamanager/mediamanager.cpp b/tdeioslave/media/mediamanager/mediamanager.cpp index 7a8262eec..38e433bfe 100644 --- a/tdeioslave/media/mediamanager/mediamanager.cpp +++ b/tdeioslave/media/mediamanager/mediamanager.cpp @@ -297,7 +297,6 @@ TQStringVariantMap MediaManager::unmount(const TQString &uid) TQStringVariantMap MediaManager::unlock(const TQString &uid, const TQString &password) { TQStringVariantMap result; -/* #ifdef COMPILE_TDEHARDWAREBACKEND if (!m_tdebackend) { result["errStr"] = i18n("Feature only available with the TDE hardware backend"); @@ -306,8 +305,6 @@ TQStringVariantMap MediaManager::unlock(const TQString &uid, const TQString &pas } return m_tdebackend->unlock(uid, password); #elif defined COMPILE_HALBACKEND -*/ -#if defined COMPILE_HALBACKEND if (!m_halbackend) { result["errStr"] = i18n("Feature only available with HAL"); result["result"] = false; @@ -328,7 +325,6 @@ TQStringVariantMap MediaManager::unlock(const TQString &uid, const TQString &pas TQStringVariantMap MediaManager::lock(const TQString &uid) { TQStringVariantMap result; -/* #ifdef COMPILE_TDEHARDWAREBACKEND if (!m_tdebackend) { result["errStr"] = i18n("Feature only available with the TDE hardware backend"); @@ -337,8 +333,6 @@ TQStringVariantMap MediaManager::lock(const TQString &uid) } return m_tdebackend->lock(uid); #elif defined COMPILE_HALBACKEND -*/ -#if defined COMPILE_HALBACKEND if (!m_halbackend) { result["errStr"] = i18n("Feature only available with HAL"); result["result"] = false; diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp index c399d280d..f0c432a37 100644 --- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp +++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp @@ -1441,7 +1441,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id) // Failed as BUSY TQString processesUsingDev = listUsingProcesses(medium); if (!processesUsingDev.isNull()) { - if (KMessageBox::warningYesNo(0, i18n("<qt>The device <b>%1</b> (%2) named <b>'%3'</b> and currently " + if (KMessageBox::warningYesNo(0, i18n("The device <b>%1</b> (%2) named <b>'%3'</b> and currently " "mounted at <b>%4</b> can not be unmounted at this time.<p>%5<p><b>Would you like to forcibly " "terminate these processes?</b><br><i>All unsaved data would be lost</i>").arg("system:/media/" + medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL()) @@ -1480,6 +1480,91 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id) return result; } +TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &password) +{ + kdDebug(1219) << "TDEBackend::unlock for id " << id << endl; + + TQStringVariantMap result; + + const Medium* medium = m_mediaList.findById(id); + if (!medium) { + result["errStr"] = i18n("No such medium: %1").arg(id); + result["result"] = false; + return result; + } + + if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) { + result["result"] = true; + return result; + } + + TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id()); + if (!sdevice) { + result["errStr"] = i18n("Internal error. Couldn't find medium."); + result["result"] = false; + return result; + } + + TQStringVariantMap unlockResult = sdevice->unlockDevice(password); + if (unlockResult["result"].toBool() == false) { + TQString qerror = i18n("Unable to unlock the device."); + TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null; + if (!errStr.isEmpty()) { + qerror.append(i18n("<p>Technical details:<br>").append(errStr)); + result["errStr"] = qerror; + result["result"] = false; + return result; + } + } + + result["result"] = unlockResult["unlockedDevice"]; + result["result"] = true; + return result; +} + +TQStringVariantMap TDEBackend::lock(const TQString &id) +{ + kdDebug(1219) << "TDEBackend::lock for id " << id << endl; + + TQStringVariantMap result; + + const Medium* medium = m_mediaList.findById(id); + if (!medium) { + result["errStr"] = i18n("No such medium: %1").arg(id); + result["result"] = false; + return result; + } + + if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) { + result["result"] = true; + return result; + } + + TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id()); + if (!sdevice) { + result["errStr"] = i18n("Internal error. Couldn't find medium."); + result["result"] = false; + return result; + } + + TQStringVariantMap lockResult = sdevice->lockDevice(); + if (lockResult["result"].toBool() == false) { + TQString qerror = i18n("Unable to lock the device."); + TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null; + if (!errStr.isEmpty()) { + qerror.append(i18n("<p>Technical details:<br>").append(errStr)); + result["errStr"] = qerror; + result["result"] = false; + return result; + } + } + + result["result"] = true; + return result; +} + void TDEBackend::slotResult(TDEIO::Job *job) { TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); @@ -1491,7 +1576,6 @@ void TDEBackend::slotResult(TDEIO::Job *job) if (job->error() == TDEIO::ERR_COULD_NOT_UNMOUNT) { TQString proclist(listUsingProcesses(medium)); - qerror = "<qt>"; qerror += "<p>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and " "currently mounted at <b>%4</b> could not be unmounted. ").arg( "system:/media/" + medium->name(), @@ -1504,7 +1588,6 @@ void TDEBackend::slotResult(TDEIO::Job *job) if (!proclist.isEmpty()) { qerror += proclist; } - qerror += "</qt>"; } else if (job->error()) { qerror = job->errorText(); } diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.h b/tdeioslave/media/mediamanager/tdehardwarebackend.h index 5c6ce1260..fd81e9a3e 100644 --- a/tdeioslave/media/mediamanager/tdehardwarebackend.h +++ b/tdeioslave/media/mediamanager/tdehardwarebackend.h @@ -71,8 +71,8 @@ public: TQStringVariantMap mount(const TQString &id); TQStringVariantMap mount(const Medium *medium); TQStringVariantMap unmount(const TQString &id); -// TQStringVariantMap unlock(const TQString &id, const TQString &password); -// TQStringVariantMap lock(const TQString &id); + TQStringVariantMap unlock(const TQString &id, const TQString &password); + TQStringVariantMap lock(const TQString &id); private: /** |