From b9c18d16fe67f71015d1a233e2716bc7c0812140 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 20 Nov 2013 23:23:23 +0100 Subject: [PATCH] make sure that we always use the correct user id --- apps/files_encryption/lib/keymanager.php | 18 +++++++++++------- apps/files_encryption/lib/stream.php | 12 +++++++++--- apps/files_encryption/lib/util.php | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 8d3e72b422..b207b1437b 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -125,8 +125,8 @@ class Keymanager { $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - //here we need the currently logged in user, while userId can be a different user - $util = new Util($view, \OCP\User::getUser()); + $userId = Helper::getUser($path); + $util = new Util($view, $userId); list($owner, $filename) = $util->getUidAndFilename($path); // in case of system wide mount points the keys are stored directly in the data directory @@ -225,7 +225,8 @@ class Keymanager { $trimmed = ltrim($path, '/'); - $util = new Util($view, \OCP\User::getUser()); + $userId = Helper::getUser($path); + $util = new Util($view, $userId); if($util->isSystemWideMountPoint($path)) { $keyPath = '/files_encryption/keyfiles/' . $trimmed; @@ -322,8 +323,10 @@ class Keymanager { // $shareKeys must be an array with the following format: // [userId] => [encrypted key] - // Here we need the currently logged in user, while userId can be a different user - $util = new Util($view, \OCP\User::getUser()); + + $userId = Helper::getUser($path); + + $util = new Util($view, $userId); list($owner, $filename) = $util->getUidAndFilename($path); @@ -441,8 +444,9 @@ class Keymanager { $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - //here we need the currently logged in user, while userId can be a different user - $util = new Util($view, \OCP\User::getUser()); + $userId = Helper::getUser($filePath); + + $util = new Util($view, $userId); list($owner, $filename) = $util->getUidAndFilename($filePath); diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 393c133d76..2497e56e89 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -92,10 +92,14 @@ class Stream { $this->session = new \OCA\Encryption\Session($this->rootView); - $this->privateKey = $this->session->getPrivateKey($this->userId); + $this->privateKey = $this->session->getPrivateKey(); - $util = new Util($this->rootView, \OCP\USER::getUser()); + $userId = Helper::getUser($path); + $util = new Util($this->rootView, $userId); + + // need to get the userId once more from util, because now this can be the + // public share key ID $this->userId = $util->getUserId(); // rawPath is relative to the data directory @@ -509,7 +513,9 @@ class Stream { // Check if OC sharing api is enabled $sharingEnabled = \OCP\Share::isEnabled(); - $util = new Util($this->rootView, $this->userId); + $userId = Helper::getUser($this->rawPath); + + $util = new Util($this->rootView, $userId); // Get all users sharing the file includes current user $uniqueUserIds = $util->getSharingUsersArray($sharingEnabled, $this->relPath, $this->userId); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index ce3d253cc9..1e8b852fb3 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -69,7 +69,7 @@ class Util { $this->userFilesDir = '/' . $userId . '/' . $this->fileFolderName; // TODO: Does this need to be user configurable? $this->publicKeyDir = '/' . 'public-keys'; - $this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption'; + $this->encryptionDir = '/' . $userId . '/' . 'files_encryption'; $this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles'; $this->shareKeysPath = $this->encryptionDir . '/' . 'share-keys'; $this->publicKeyPath =