Skip to content

Commit

Permalink
Init mount points for user in more places in Keys\Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Jan 11, 2017
1 parent 85c5cc6 commit 5554dc4
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/private/encryption/keys/storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Storage implements IStorage {
/** @var array */
private $keyCache = [];

/** @var string */
private $currentUser = null;

/**
* @param View $view
* @param Util $util
Expand All @@ -64,16 +67,17 @@ public function __construct(View $view, Util $util) {
$this->encryption_base_dir = '/files_encryption';
$this->keys_base_dir = $this->encryption_base_dir .'/keys';
$this->root_dir = $this->util->getKeyStorageRoot();

$session = \OC::$server->getUserSession();
if (!is_null($session) && !is_null($session->getUser())) {
$this->currentUser = $session->getUser()->getUID();
}
}

/**
* @inheritdoc
*/
public function getUserKey($uid, $keyId, $encryptionModuleId) {
$currentUser = \OC_User::getUser();
if (!is_null($uid) && $uid !== '' && $uid !== $currentUser) {
\OC\Files\Filesystem::initMountPoints($uid);
}
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return $this->getKey($path);
}
Expand Down Expand Up @@ -174,6 +178,7 @@ protected function constructUserKeyPath($encryptionModuleId, $keyId, $uid) {
if ($uid === null) {
$path = $this->root_dir . '/' . $this->encryption_base_dir . '/' . $encryptionModuleId . '/' . $keyId;
} else {
$this->setupUserMounts($uid);
$path = $this->root_dir . '/' . $uid . $this->encryption_base_dir . '/'
. $encryptionModuleId . '/' . $uid . '.' . $keyId;
}
Expand Down Expand Up @@ -239,6 +244,7 @@ private function getFileKeyDir($encryptionModuleId, $path) {
if ($this->util->isSystemWideMountPoint($filename, $owner)) {
$keyPath = $this->root_dir . '/' . $this->keys_base_dir . $filename . '/';
} else {
$this->setupUserMounts($owner);
$keyPath = $this->root_dir . '/' . $owner . $this->keys_base_dir . $filename . '/';
}

Expand Down Expand Up @@ -302,6 +308,7 @@ protected function getPathToKeys($path) {
if ($systemWideMountPoint) {
$systemPath = $this->root_dir . '/' . $this->keys_base_dir . $relativePath . '/';
} else {
$this->setupUserMounts($owner);
$systemPath = $this->root_dir . '/' . $owner . $this->keys_base_dir . $relativePath . '/';
}

Expand All @@ -327,4 +334,19 @@ protected function keySetPreparation($path) {
}
}

/**
* Setup the mounts of the given user if different than
* the current user.
*
* This is needed because in many cases the keys are stored
* within the user's home storage.
*
* @param string $uid user id
*/
protected function setupUserMounts($uid) {
if (!is_null($uid) && $uid !== '' && $uid !== $this->currentUser) {
\OC\Files\Filesystem::initMountPoints($uid);
}
}

}

0 comments on commit 5554dc4

Please sign in to comment.