From 53f8622a6a4a47a49431bcbb4f63aa09220bb835 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 25 Oct 2020 14:13:23 +0800 Subject: tdehwmonitor: added Unlock/Lock buttons to LUKS disks. Signed-off-by: Michele Calgaro --- kcontrol/hwmanager/CMakeLists.txt | 4 +- kcontrol/hwmanager/devicepropsdlg.cpp | 97 ++++++++++++++++++- kcontrol/hwmanager/devicepropsdlg.h | 11 ++- kcontrol/hwmanager/devicepropsdlgbase.ui | 16 +++ kcontrol/hwmanager/passworddlg.cpp | 59 +++++++++++ kcontrol/hwmanager/passworddlg.h | 58 +++++++++++ kcontrol/hwmanager/unlockdialog.ui | 161 +++++++++++++++++++++++++++++++ 7 files changed, 397 insertions(+), 9 deletions(-) create mode 100644 kcontrol/hwmanager/passworddlg.cpp create mode 100644 kcontrol/hwmanager/passworddlg.h create mode 100644 kcontrol/hwmanager/unlockdialog.ui (limited to 'kcontrol') diff --git a/kcontrol/hwmanager/CMakeLists.txt b/kcontrol/hwmanager/CMakeLists.txt index be8d3f2cb..bd06bd930 100644 --- a/kcontrol/hwmanager/CMakeLists.txt +++ b/kcontrol/hwmanager/CMakeLists.txt @@ -48,7 +48,7 @@ set_property( SOURCE hwmanager.cpp APPEND PROPERTY COMPILE_DEFINITIONS KDE_CONFD tde_add_kpart( kcm_hwmanager AUTOMOC SOURCES hwmanager.cpp deviceiconview.cpp devicepropsdlg.cpp devicepropsdlgbase.ui hwmanagerbase.ui - cryptpassworddlg.cpp cryptpassworddlgbase.ui hwmanager.skel + cryptpassworddlg.cpp unlockdialog.ui passworddlg.cpp cryptpassworddlgbase.ui hwmanager.skel LINK tdeio-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) @@ -61,4 +61,4 @@ tde_add_executable( tdehwdevicetray AUTOMOC hwdevicetray_configdialog.cpp LINK tdeio-shared tdeutils-shared tdeui-shared DESTINATION ${BIN_INSTALL_DIR} -) \ No newline at end of file +) diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp index 05b5832fa..717a23942 100644 --- a/kcontrol/hwmanager/devicepropsdlg.cpp +++ b/kcontrol/hwmanager/devicepropsdlg.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #undef Unsorted // Required for --enable-final (tqdir.h) #include @@ -45,6 +47,7 @@ #include #include "cryptpassworddlg.h" +#include "passworddlg.h" #include "devicepropsdlg.h" @@ -250,7 +253,7 @@ void SensorDisplayWidget::updateDisplay() { } DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidget *parent) - : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true) + : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true), m_passDlg(NULL) { m_device = device; enableButtonOK( false ); @@ -301,6 +304,8 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge TDEStorageDevice* sdevice = static_cast(m_device); connect(base->buttonDiskMount, TQT_SIGNAL(clicked()), this, TQT_SLOT(mountDisk())); connect(base->buttonDiskUnmount, TQT_SIGNAL(clicked()), this, TQT_SLOT(unmountDisk())); + connect(base->buttonDiskUnlock, TQT_SIGNAL(clicked()), this, TQT_SLOT(unlockDisk())); + connect(base->buttonDiskLock, TQT_SIGNAL(clicked()), this, TQT_SLOT(lockDisk())); if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { connect(base->cryptLUKSAddKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSAddKey())); connect(base->cryptLUKSDelKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSDelKey())); @@ -345,6 +350,10 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge DevicePropertiesDialog::~DevicePropertiesDialog() { + if (m_passDlg) + { + delete m_passDlg; + } } void DevicePropertiesDialog::processHardwareRemoved(TDEGenericDevice* dev) { @@ -450,16 +459,32 @@ void DevicePropertiesDialog::populateDeviceInformation() { status_text += "Hidden
"; } if (status_text == "") { - status_text += "Unavailable"; + status_text += "Unknown"; } status_text += ""; base->labelDiskStatus->setText(status_text); // Update mount/unmount button status + base->buttonDiskMount->setEnabled(false); + base->buttonDiskUnmount->setEnabled(false); + base->buttonDiskUnlock->setEnabled(false); + base->buttonDiskLock->setEnabled(false); + base->buttonDiskMount->setHidden(true); + base->buttonDiskUnmount->setHidden(true); + base->buttonDiskUnlock->setHidden(true); + base->buttonDiskLock->setHidden(true); if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Mountable)) { base->groupDiskActions->show(); base->buttonDiskMount->setEnabled((sdevice->mountPath() == "")); base->buttonDiskUnmount->setEnabled((sdevice->mountPath() != "")); + base->buttonDiskMount->setHidden(false); + base->buttonDiskUnmount->setHidden(false); + } + else if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { + base->buttonDiskUnlock->setEnabled(!sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); + base->buttonDiskLock->setEnabled(sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); + base->buttonDiskUnlock->setHidden(false); + base->buttonDiskLock->setHidden(false); } else { base->groupDiskActions->hide(); @@ -928,6 +953,74 @@ void DevicePropertiesDialog::unmountDisk() { populateDeviceInformation(); } +void DevicePropertiesDialog::unlockDisk() { + TDEStorageDevice* sdevice = static_cast(m_device); + + if (!m_passDlg) + { + m_passDlg = new PasswordDlg(sdevice->deviceNode(), "drive-harddisk-locked"); + connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk())); + } + m_passDlg->show(); +} + +void DevicePropertiesDialog::doUnlockDisk() { + TDEStorageDevice* sdevice = static_cast(m_device); + + // Use DCOP call to unlock the disk to make sure the status and mime type of the underlying medium + // is correctly updated throughout TDE + TQString qerror; + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("unlockByNode", sdevice->deviceNode(), m_passDlg->getPassword()); + TQStringVariantMap unlockResult; + if (reply.isValid()) { + reply.get(unlockResult); + } + if (!unlockResult.contains("result") || !unlockResult["result"].toBool()) { + qerror = i18n("Unable to unlock this device.

Potential reasons include:
Wrong password and/or user privilege level.
Corrupt data on storage device."); + TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : i18n("Unknown unlock error."); + if (!errStr.isEmpty()) { + qerror.append(i18n("

Technical details:
").append(errStr)); + } + qerror.append(""); + } + else { + m_passDlg->hide(); + qerror = ""; + } + + if (qerror != "") KMessageBox::error(this, qerror, i18n("Unlock Failed")); + + populateDeviceInformation(); +} + +void DevicePropertiesDialog::lockDisk() { + TDEStorageDevice* sdevice = static_cast(m_device); + + // Use DCOP call to lock the disk to make sure the status and mime type of the underlying medium + // is correctly updated throughout TDE + TQString qerror; + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode()); + TQStringVariantMap lockResult; + if (reply.isValid()) { + reply.get(lockResult); + } + if (lockResult["result"].toBool() == false) { + // Lock failed! + qerror = "" + i18n("Unfortunately, the device could not be locked."); + TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null; + if (!errStr.isEmpty()) { + qerror.append(i18n("

Technical details:
").append(errStr)); + } + qerror.append(""); + } + + if (qerror != "") KMessageBox::error(this, qerror, i18n("Lock Failed")); + + populateDeviceInformation(); +} + void DevicePropertiesDialog::cryptLUKSAddKey() { int retcode; diff --git a/kcontrol/hwmanager/devicepropsdlg.h b/kcontrol/hwmanager/devicepropsdlg.h index e958d39ba..50fd1cac1 100644 --- a/kcontrol/hwmanager/devicepropsdlg.h +++ b/kcontrol/hwmanager/devicepropsdlg.h @@ -20,13 +20,13 @@ #define __devicepropsdlg_h__ #include - #include - #include #include "devicepropsdlgbase.h" +class PasswordDlg; + /** * * Simple sensor name and text label value display widget @@ -190,6 +190,9 @@ private slots: void mountDisk(); void unmountDisk(); + void unlockDisk(); + void doUnlockDisk(); + void lockDisk(); void cryptLUKSAddKey(); void cryptLUKSDelKey(); @@ -204,9 +207,7 @@ private slots: private: TDEGenericDevice* m_device; DevicePropertiesDialogBase* base; - - class DevicePropertiesDialogPrivate; - DevicePropertiesDialogPrivate* d; + PasswordDlg *m_passDlg; TQGridLayout* m_sensorDataGrid; SensorDisplayWidgetList m_sensorDataGridWidgets; diff --git a/kcontrol/hwmanager/devicepropsdlgbase.ui b/kcontrol/hwmanager/devicepropsdlgbase.ui index b6c53c331..b5ffe362d 100644 --- a/kcontrol/hwmanager/devicepropsdlgbase.ui +++ b/kcontrol/hwmanager/devicepropsdlgbase.ui @@ -355,6 +355,22 @@ Unmount + + + buttonDiskUnlock + + + Unlock + + + + + buttonDiskLock + + + Lock + + diff --git a/kcontrol/hwmanager/passworddlg.cpp b/kcontrol/hwmanager/passworddlg.cpp new file mode 100644 index 000000000..d9f1f54a6 --- /dev/null +++ b/kcontrol/hwmanager/passworddlg.cpp @@ -0,0 +1,59 @@ +/* This file is part of the KDE project + * Copyright (C) 2007 Jan Klötzke + * + * Based on kryptomedia- Another KDE cryto media application. + * Copyright (C) 2006 Daniel Gollub + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "passworddlg.h" + +PasswordDlg::PasswordDlg(TQString url, TQString iconName) : + KDialogBase(NULL, "PasswordDlg", true, i18n("Unlock Storage Device"), (Cancel|User1), User1, false, KGuiItem(i18n("Unlock"), "unlocked" )) +{ + unlockDialog = new UnlockDialog(this); + + unlockDialog->descLabel->setText(unlockDialog->descLabel->text().arg(url)); + unlockDialog->descLabel->adjustSize(); + unlockDialog->adjustSize(); + + enableButton( User1, false ); + + TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon(iconName, TDEIcon::NoGroup, TDEIcon::SizeLarge); + unlockDialog->encryptedIcon->setPixmap( pixmap ); + + connect(unlockDialog->passwordEdit, TQT_SIGNAL (textChanged(const TQString &)), this, TQT_SLOT (slotPasswordChanged(const TQString &))); + + setMainWidget(unlockDialog); +} + +PasswordDlg::~PasswordDlg() +{ + delete unlockDialog; +} + +TQString PasswordDlg::getPassword() +{ + return unlockDialog->passwordEdit->text(); +} + +void PasswordDlg::slotPasswordChanged(const TQString &text) +{ + enableButton( User1, !text.isEmpty() ); +} + +#include "passworddlg.moc" diff --git a/kcontrol/hwmanager/passworddlg.h b/kcontrol/hwmanager/passworddlg.h new file mode 100644 index 000000000..77ee06803 --- /dev/null +++ b/kcontrol/hwmanager/passworddlg.h @@ -0,0 +1,58 @@ +/* This file is part of the KDE project + * Copyright (C) 2007 Jan Klötzke + * + * Based on kryptomedia- Another KDE cryto media application. + * Copyright (C) 2006 Daniel Gollub + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef DIALOG_H_ +#define DIALOG_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "unlockdialog.h" + +class PasswordDlg : public KDialogBase +{ + + Q_OBJECT + +public: + PasswordDlg(TQString url, TQString iconName); + ~PasswordDlg(); + + TQString getPassword(); + +public slots: + void slotPasswordChanged(const TQString &text); + +private: + UnlockDialog *unlockDialog; +}; + +#endif // DIALOG_H_ + diff --git a/kcontrol/hwmanager/unlockdialog.ui b/kcontrol/hwmanager/unlockdialog.ui new file mode 100644 index 000000000..7b78cdb42 --- /dev/null +++ b/kcontrol/hwmanager/unlockdialog.ui @@ -0,0 +1,161 @@ + +UnlockDialog + + + UnlockDialog + + + + 0 + 0 + 207 + 172 + + + + + 5 + 3 + 0 + 0 + + + + Decrypting Storage Device + + + + unnamed + + + + layout5 + + + + unnamed + + + + layout4 + + + + unnamed + + + + encryptedIcon + + + + 0 + 0 + 0 + 0 + + + + + 48 + 48 + + + + + 32 + 32 + + + + true + + + AlignTop + + + + + spacer2_2 + + + Vertical + + + Expanding + + + + 31 + 41 + + + + + + + + descLabel + + + + 3 + 3 + 0 + 0 + + + + <p><b>%1</b> is an encrypted storage device.</p> +<p>Please enter the password to unlock the storage device.</p> + + + WordBreak|AlignTop + + + + + + + layout4 + + + + unnamed + + + + textLabel1 + + + &Password: + + + passwordEdit + + + + + passwordEdit + + + true + + + + 5 + 0 + 1 + 0 + + + + Password + + + + + + + + -- cgit v1.2.1