Skip to content

Commit

Permalink
Merge pull request #4 from OpenMediaVault-Plugin-Developers/img-dev
Browse files Browse the repository at this point in the history
Merge dev into testing.
  • Loading branch information
imgrant committed Feb 5, 2016
2 parents a36dd48 + eb39c4a commit 9201926
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
openmediavault-luksencryption (2.1.2) stable; urgency=medium

* Bugfix: opening LUKS-on-LVM devices would fail.

-- OpenMediaVault Plugin Developers <[email protected]> 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.
Expand Down
25 changes: 23 additions & 2 deletions usr/share/php/openmediavault/luks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand Down

0 comments on commit 9201926

Please sign in to comment.