From 33794c4ec3572327ac077e272523234aac464aa2 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 10 Oct 2020 14:31:22 +0800 Subject: Fixed displaying of encrypted disks. Signed-off-by: Michele Calgaro --- tdecore/tdehw/tdehardwaredevices.cpp | 20 +++---- tdecore/tdehw/tdestoragedevice.cpp | 90 +++++------------------------ tdecore/tdehw/tdestoragedevice.h | 106 ++++++++++++++++------------------- 3 files changed, 71 insertions(+), 145 deletions(-) diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp index f0069d38f..acdd67b8a 100644 --- a/tdecore/tdehw/tdehardwaredevices.cpp +++ b/tdecore/tdehw/tdehardwaredevices.cpp @@ -2626,6 +2626,15 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist device = classifyUnknownDeviceByExternalRules(dev, device, true); // Check external rules for possible subtype overrides disktype = sdevice->diskType(); // The type can be overridden by an external rule + // Set unlocked crypt flag is device has any holders + if ((filesystemtype.upper() == "CRYPTO_LUKS" || filesystemtype.upper() == "CRYPTO") && + holdingDeviceNodes.count() > 0) { + disktype = disktype | TDEDiskDeviceType::UnlockedCrypt; + } + else { + disktype = disktype & ~TDEDiskDeviceType::UnlockedCrypt; + } + if (TQString(udev_device_get_property_value(dev, "UDISKS_IGNORE")) == "1") { diskstatus = diskstatus | TDEDiskDeviceStatus::Hidden; } @@ -2796,17 +2805,6 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist } // See if any slaves were crypted - for ( TQStringList::Iterator slaveit = slaveDeviceNodes.begin(); slaveit != slaveDeviceNodes.end(); ++slaveit ) { - struct udev_device *slavedev; - slavedev = udev_device_new_from_syspath(m_udevStruct, (*slaveit).ascii()); - TQString slavediskfstype(udev_device_get_property_value(slavedev, "ID_FS_TYPE")); - if ((slavediskfstype.upper() == "CRYPTO_LUKS") || (slavediskfstype.upper() == "CRYPTO")) { - disktype = disktype | TDEDiskDeviceType::UnlockedCrypt; - // Set disk type based on parent device - disktype = disktype | classifyDiskType(slavedev, devicenode, TQString(udev_device_get_property_value(dev, "ID_BUS")), TQString(udev_device_get_property_value(dev, "ID_TYPE")), (*slaveit), TQString(udev_device_get_property_value(dev, "ID_VENDOR")), TQString(udev_device_get_property_value(dev, "ID_MODEL")), TQString(udev_device_get_property_value(dev, "ID_FS_TYPE")), TQString(udev_device_get_driver(dev))); - } - udev_device_unref(slavedev); - } sdevice->internalSetDiskType(disktype); sdevice->internalSetDiskUUID(diskuuid); diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp index a995e49fa..862e7b10e 100644 --- a/tdecore/tdehw/tdestoragedevice.cpp +++ b/tdecore/tdehw/tdestoragedevice.cpp @@ -789,6 +789,7 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM mountResult = udisks2MountDrive(devNode, fileSystemType, optionString); if (mountResult["result"].toBool()) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["mountPath"] = mountPath(); result["result"] = true; @@ -796,6 +797,7 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM } else if (mountResult["retcode"].toInt() == -1) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["errStr"] = mountResult["errStr"]; result["result"] = false; @@ -809,6 +811,7 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM mountResult = udisksMountDrive(devNode, fileSystemType, udisksOptions); if (mountResult["result"].toBool()) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["mountPath"] = mountPath(); result["result"] = true; @@ -816,6 +819,7 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM } else if (mountResult["retcode"].toInt() == -1) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["errStr"] = mountResult["errStr"]; result["result"] = false; @@ -911,81 +915,7 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM } // Update internal mount data - TDEGlobal::hardwareDevices()->processModifiedMounts(); - result["mountPath"] = mountPath(); - result["result"] = !mountPath().isEmpty(); - return result; -} - -TQStringVariantMap TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, - TDEStorageMountOptions mountOptions) { - TQStringVariantMap result; - - // Check if device is already mounted - TQString mountpath = mountPath(); - if (!mountpath.isEmpty()) { - result["mountPath"] = mountpath; - result["result"] = true; - return result; - } - - // Create dummy password file - KTempFile passwordFile(TQString::null, "tmp", 0600); - passwordFile.setAutoDelete(true); - TQFile* pwFile = passwordFile.file(); - if (!pwFile) { - result["errStr"] = i18n("Cannot create temporary password file"); - result["result"] = false; - return result; - } - - pwFile->writeBlock(passphrase.ascii(), passphrase.length()); - pwFile->flush(); - - TQString optionString; - if (mountOptions["ro"] == "true") { - optionString.append(" -r"); - } - - if (mountOptions["atime"] != "true") { - optionString.append(" -A"); - } - - if (mountOptions["utf8"] == "true") { - optionString.append(" -c utf8"); - } - - if (mountOptions["sync"] == "true") { - optionString.append(" -s"); - } - - if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) { - optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"])); - } - - if (mountOptions.contains("locale")) { - optionString.append(TQString(" -c %1").arg(mountOptions["locale"])); - } - - TQString passFileName = passwordFile.name(); - TQString devNode = deviceNode(); - passFileName.replace("'", "'\\''"); - devNode.replace("'", "'\\''"); - mediaName.replace("'", "'\\''"); - TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1") - .arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); - - FILE *exepipe = popen(command.local8Bit(), "r"); - if (exepipe) { - TQTextStream* ts = new TQTextStream(exepipe, IO_ReadOnly); - TQString mount_output = ts->read(); - delete ts; - int retcode = pclose(exepipe); - result["errStr"] = mount_output; - result["retCode"] = retcode; - } - - // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["mountPath"] = mountPath(); result["result"] = !mountPath().isEmpty(); @@ -1012,12 +942,14 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() { unmountResult = udisks2UnmountDrive(devNode, TQString::null); if (unmountResult["result"].toBool()) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["result"] = true; return result; } else if (unmountResult["retcode"].toInt() == -1) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["errStr"] = unmountResult["errStr"]; result["result"] = false; @@ -1031,12 +963,14 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() { unmountResult = udisksUnmountDrive(devNode, TQStringList()); if (unmountResult["result"].toBool()) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["result"] = true; return result; } else if (unmountResult["retcode"].toInt() == -1) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["errStr"] = unmountResult["errStr"]; result["result"] = false; @@ -1071,6 +1005,7 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() { int retcode = pclose(exepipe); if (retcode == 0) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["result"] = true; return result; @@ -1082,6 +1017,7 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() { } // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["result"] = false; return result; @@ -1109,6 +1045,7 @@ TQStringVariantMap TDEStorageDevice::unlockDevice(const TQString &passphrase) unlockResult = udisks2UnlockDrive(devNode, passphrase); if (unlockResult["result"].toBool()) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["unlockedDevice"] = unlockResult["unlockedDevice"]; result["result"] = true; @@ -1116,6 +1053,7 @@ TQStringVariantMap TDEStorageDevice::unlockDevice(const TQString &passphrase) } else if (unlockResult["retcode"].toInt() == -1) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["errStr"] = unlockResult["errStr"]; result["result"] = false; @@ -1151,12 +1089,14 @@ TQStringVariantMap TDEStorageDevice::lockDevice() lockResult = udisks2LockDrive(devNode); if (lockResult["result"].toBool()) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["result"] = true; return result; } else if (lockResult["retcode"].toInt() == -1) { // Update internal mount data + TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TDEGlobal::hardwareDevices()->processModifiedMounts(); result["errStr"] = lockResult["errStr"]; result["result"] = false; diff --git a/tdecore/tdehw/tdestoragedevice.h b/tdecore/tdehw/tdestoragedevice.h index 79223d185..88991315e 100644 --- a/tdecore/tdehw/tdestoragedevice.h +++ b/tdecore/tdehw/tdestoragedevice.h @@ -32,53 +32,53 @@ enum TDEDiskDeviceType : unsigned long long { #else enum TDEDiskDeviceType { #endif - Null = 0x0000000000000000ULL, - MediaDevice = 0x0000000000000001ULL, - Floppy = 0x0000000000000002ULL, - CDROM = 0x0000000000000004ULL, - CDR = 0x0000000000000008ULL, - CDRW = 0x0000000000000010ULL, - CDMO = 0x0000000000000020ULL, - CDMRRW = 0x0000000000000040ULL, - CDMRRWW = 0x0000000000000080ULL, - DVDROM = 0x0000000000000100ULL, - DVDRAM = 0x0000000000000200ULL, - DVDR = 0x0000000000000400ULL, - DVDRW = 0x0000000000000800ULL, - DVDRDL = 0x0000000000001000ULL, - DVDRWDL = 0x0000000000002000ULL, - DVDPLUSR = 0x0000000000004000ULL, - DVDPLUSRW = 0x0000000000008000ULL, - DVDPLUSRDL = 0x0000000000010000ULL, - DVDPLUSRWDL = 0x0000000000020000ULL, - BDROM = 0x0000000000040000ULL, - BDR = 0x0000000000080000ULL, - BDRW = 0x0000000000100000ULL, - HDDVDROM = 0x0000000000200000ULL, - HDDVDR = 0x0000000000400000ULL, - HDDVDRW = 0x0000000000800000ULL, - Zip = 0x0000000001000000ULL, - Jaz = 0x0000000002000000ULL, - Camera = 0x0000000004000000ULL, - LUKS = 0x0000000008000000ULL, - OtherCrypted = 0x0000000010000000ULL, - CDAudio = 0x0000000020000000ULL, - CDVideo = 0x0000000040000000ULL, - DVDVideo = 0x0000000080000000ULL, - BDVideo = 0x0000000100000000ULL, - Flash = 0x0000000200000000ULL, - USB = 0x0000000400000000ULL, - Tape = 0x0000000800000000ULL, - HDD = 0x0000001000000000ULL, - Optical = 0x0000002000000000ULL, - RAM = 0x0000004000000000ULL, - Loop = 0x0000008000000000ULL, - CompactFlash = 0x0000010000000000ULL, - MemoryStick = 0x0000020000000000ULL, - SmartMedia = 0x0000040000000000ULL, - SDMMC = 0x0000080000000000ULL, - UnlockedCrypt = 0x0000100000000000ULL, - Other = 0x8000000000000000ULL + Null = 0x0000000000000000ULL, + MediaDevice = 0x0000000000000001ULL, + Floppy = 0x0000000000000002ULL, + CDROM = 0x0000000000000004ULL, + CDR = 0x0000000000000008ULL, + CDRW = 0x0000000000000010ULL, + CDMO = 0x0000000000000020ULL, + CDMRRW = 0x0000000000000040ULL, + CDMRRWW = 0x0000000000000080ULL, + DVDROM = 0x0000000000000100ULL, + DVDRAM = 0x0000000000000200ULL, + DVDR = 0x0000000000000400ULL, + DVDRW = 0x0000000000000800ULL, + DVDRDL = 0x0000000000001000ULL, + DVDRWDL = 0x0000000000002000ULL, + DVDPLUSR = 0x0000000000004000ULL, + DVDPLUSRW = 0x0000000000008000ULL, + DVDPLUSRDL = 0x0000000000010000ULL, + DVDPLUSRWDL = 0x0000000000020000ULL, + BDROM = 0x0000000000040000ULL, + BDR = 0x0000000000080000ULL, + BDRW = 0x0000000000100000ULL, + HDDVDROM = 0x0000000000200000ULL, + HDDVDR = 0x0000000000400000ULL, + HDDVDRW = 0x0000000000800000ULL, + Zip = 0x0000000001000000ULL, + Jaz = 0x0000000002000000ULL, + Camera = 0x0000000004000000ULL, + LUKS = 0x0000000008000000ULL, + OtherCrypted = 0x0000000010000000ULL, + CDAudio = 0x0000000020000000ULL, + CDVideo = 0x0000000040000000ULL, + DVDVideo = 0x0000000080000000ULL, + BDVideo = 0x0000000100000000ULL, + Flash = 0x0000000200000000ULL, + USB = 0x0000000400000000ULL, + Tape = 0x0000000800000000ULL, + HDD = 0x0000001000000000ULL, + Optical = 0x0000002000000000ULL, + RAM = 0x0000004000000000ULL, + Loop = 0x0000008000000000ULL, + CompactFlash = 0x0000010000000000ULL, + MemoryStick = 0x0000020000000000ULL, + SmartMedia = 0x0000040000000000ULL, + SDMMC = 0x0000080000000000ULL, + UnlockedCrypt = 0x0000100000000000ULL, + Other = 0x8000000000000000ULL }; inline TDEDiskDeviceType operator|(TDEDiskDeviceType a, TDEDiskDeviceType b) @@ -239,18 +239,6 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice TQStringVariantMap mountDevice(TQString mediaName = TQString::null, TDEStorageMountOptions mountOptions = TDEStorageMountOptions()); - /** - * Mounts the encrypted device if the correct passphrase is given - * - * @param a TQString containing the passphrase - * @param a TQString containing a requested mount name under /media, if desired - * @param a TDEStorageMountOptions containing any mount options for pmount, if desired - * - * @return a TQStringVariantMap object containing information about the operation outcome - */ - TQStringVariantMap mountEncryptedDevice(TQString passphrase, TQString mediaName = TQString::null, - TDEStorageMountOptions mountOptions = TDEStorageMountOptions()); - /** * Unmounts the device * -- cgit v1.2.1