From eb39c4a7f194b7dc395ee890842e9f4d2ba99d6e Mon Sep 17 00:00:00 2001 From: imgrant Date: Fri, 5 Feb 2016 15:18:00 +0000 Subject: [PATCH] Fix for decrypted device name with LUKS-on-LVM. --- debian/changelog | 6 ++++++ usr/share/php/openmediavault/luks.inc | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0f7ce28..41fde53 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +openmediavault-luksencryption (2.1.2) stable; urgency=medium + + * Bugfix: opening LUKS-on-LVM devices would fail. + + -- OpenMediaVault Plugin Developers Fri, 05 Feb 2016 14:42:59 +0000 + openmediavault-luksencryption (2.1.1) unstable; urgency=medium * Bugfix: no LUKS devices present would cause an error message. diff --git a/usr/share/php/openmediavault/luks.inc b/usr/share/php/openmediavault/luks.inc index 8ce3bf8..d5d64da 100644 --- a/usr/share/php/openmediavault/luks.inc +++ b/usr/share/php/openmediavault/luks.inc @@ -146,6 +146,15 @@ class OMVLuksContainer extends OMVStorageDeviceAbstract { if($this->dataCached !== FALSE) return TRUE; + // Reset cached data + $this->uuid = ""; + $this->isOpen = FALSE; + $this->headerInfo = ""; + $this->usedKeySlots = 0; + $this->freeKeySlots = 8; + $this->deviceMapperDeviceFile = ""; + $this->deviceMapperName = ""; + // Look up the UUID for the LUKS container $cmd = sprintf("export LANG=C; cryptsetup luksUUID %s", $this->getDeviceFile()); @@ -336,6 +345,18 @@ class OMVLuksContainer extends OMVStorageDeviceAbstract { return $this->deviceMapperName; } + /** + * Helper function for determining a name for the decrypted device. + * Avoids naming problems with, e.g. LUKS-on-LVM where the devicefile + * is of the form /dev/mapper/VG-LV. + * @return A sanitised string for use as the mapped device name. + */ + private function generateDecryptedName() { + $dev = $this->getDeviceName(); + $dev = preg_replace("/^mapper\//", "", $dev); + return str_replace("/", "-", $dev); + } + /** * Get the description of the LUKS container. * @return The LUKS container description, FALSE on failure. @@ -477,7 +498,7 @@ class OMVLuksContainer extends OMVStorageDeviceAbstract { $cmd = sprintf("export LANG=C; cryptsetup luksOpen %s ". "%s-crypt --key-file %s 2>&1", escapeshellarg($this->getDeviceFile()), - escapeshellarg($this->getDeviceName()), + escapeshellarg($this->generateDecryptedName()), escapeshellarg($key)); break; case FALSE: @@ -486,7 +507,7 @@ class OMVLuksContainer extends OMVStorageDeviceAbstract { "cryptsetup luksOpen %s %s-crypt --key-file=- 2>&1", escapeshellarg($key), escapeshellarg($this->getDeviceFile()), - escapeshellarg($this->getDeviceName())); + escapeshellarg($this->generateDecryptedName())); } @OMVUtil::exec($cmd, $output, $result); if ($result !== 0) {