Skip to content

Commit

Permalink
Automatically mount known/referenced filesystems inside LUKS containe…
Browse files Browse the repository at this point in the history
…rs when unlocking.

i.e. if the filesystem (UUID) is in /etc/fstab, then attempt to mount when opening.
Set OMV_LUKS_MOUNT_ON_UNLOCK to false (in /etc/default/openmediavault) to disable this behaviour.
  • Loading branch information
imgrant committed Nov 10, 2015
1 parent d7f087f commit 866a86f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
5 changes: 3 additions & 2 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
openmediavault-luksencryption (1.0.5) UNRELEASED; urgency=medium
openmediavault-luksencryption (1.0.6) UNRELEASED; urgency=medium

* Update dependencies (require OpenMediaVault>=2.1.19).
* Code formatting (e.g. tabs to spaces, 4-space indent etc.).
* Increase width of UI windows slightly.
* Auto-mount known filesystems when unlocking (use OMV_LUKS_MOUNT_ON_UNLOCK to disable).

-- OpenMediaVault Plugin Developers <[email protected]> Tue, 10 Nov 2015 09:51:39 +0000
-- OpenMediaVault Plugin Developers <[email protected]> Tue, 10 Nov 2015 11:21:33 +0000

openmediavault-luksencryption (1.0.2) unstable; urgency=low

Expand Down
35 changes: 30 additions & 5 deletions usr/share/openmediavault/engined/rpc/luks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ require_once("openmediavault/rpcservice.inc");
require_once("openmediavault/notify.inc");

class OMVRpcServiceLuksMgmt extends OMVRpcServiceAbstract {

private $mountOnUnlock = TRUE;

/**
* Get the RPC service name.
*/
Expand All @@ -41,6 +44,9 @@ class OMVRpcServiceLuksMgmt extends OMVRpcServiceAbstract {
* Initialize the RPC service.
*/
public function initialize() {
if(isset($GLOBALS['OMV_LUKS_MOUNT_ON_UNLOCK']))
$this->mountOnUnlock = boolvalEx($GLOBALS['OMV_LUKS_MOUNT_ON_UNLOCK']);

$this->registerMethod("enumerateContainers");
$this->registerMethod("getContainersList");
$this->registerMethod("getContainerCandidates");
Expand Down Expand Up @@ -122,14 +128,16 @@ class OMVRpcServiceLuksMgmt extends OMVRpcServiceAbstract {
$containers = $this->callMethod("enumerateContainers", NULL, $context);
foreach($containers as $luksk => &$luksv) {
$used = (!$luksv['unlocked']) ? NULL : FALSE;
// If open, does the container contain a filesystem and is it used?
// If open, does the container contain a filesystem and is it known
// or used (i.e. a configured mntent, aka referenced in /etc/fstab)?
if(!is_null($used)) {
if(FALSE !== OMVRpc::exec("FsTab", "getByFsName", array(
"id" => $luksv['decrypteddevicefile']), $context)) {
if(FALSE !== ($meObject = OMVRpc::exec("FsTab", "getByFsName",
array("id" => $luksv['decrypteddevicefile']), $context))) {
$used = TRUE;
}
}
$luksv['_used'] = $used; // null if locked, otherwise true if used, false if not
// null if locked, otherwise true if used, false if not
$luksv['_used'] = $used;
}
// Filter result.
return $this->applyFilter($containers,
Expand Down Expand Up @@ -261,6 +269,23 @@ class OMVRpcServiceLuksMgmt extends OMVRpcServiceAbstract {
$luks->getLastError()));
}
}
// If the container contains a (referenced) filesystem, then mount it
// (unless this automounting is disabled by the global configuration
// option, OMV_LUKS_MOUNT_ON_UNLOCK - see initialize() above)
if(TRUE === $this->mountOnUnlock) {
$sdluks = new OMVStorageDeviceLUKS($luks->getDecryptedDeviceFile());
$df = $sdluks->getDeviceFile();
if(FALSE !== OMVRpc::exec("FileSystemMgmt", "hasFilesystem",
array("devicefile" => $df), $context)) {
if(FALSE !== ($meObject = OMVRpc::exec("FsTab", "getByFsName",
array("id" => $df), $context))) {
OMVRpc::exec("FileSystemMgmt", "mount",
array("id" => $meObject['fsname'], "fstab" => FALSE),
$context);
}
}
}

}

/**
Expand Down Expand Up @@ -588,4 +613,4 @@ class OMVRpcServiceLuksMgmt extends OMVRpcServiceAbstract {

// Register the RPC service.
$rpcServiceMgr = &OMVRpcServiceMgr::getInstance();
$rpcServiceMgr->registerService(new OMVRpcServiceLuksMgmt());
$rpcServiceMgr->registerService(new OMVRpcServiceLuksMgmt());

0 comments on commit 866a86f

Please sign in to comment.