summaryrefslogtreecommitdiffstats
path: root/lib/private/encryption
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-04-23 16:48:11 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2015-04-23 17:18:48 +0200
commit2990b0e07e418577d55368c21200ada86c381b51 (patch)
treef09260b3be548d9ea0a86dd9d54b28ee8323ef14 /lib/private/encryption
parentf8f354b351a349898bbb5cdf2d9bee1c798c0f73 (diff)
downloadnextcloud-server-2990b0e07e418577d55368c21200ada86c381b51.tar.gz
nextcloud-server-2990b0e07e418577d55368c21200ada86c381b51.zip
update share keys if a file is moved to a shared folder
Diffstat (limited to 'lib/private/encryption')
-rw-r--r--lib/private/encryption/file.php4
-rw-r--r--lib/private/encryption/manager.php20
-rw-r--r--lib/private/encryption/update.php66
-rw-r--r--lib/private/encryption/util.php20
4 files changed, 77 insertions, 33 deletions
diff --git a/lib/private/encryption/file.php b/lib/private/encryption/file.php
index 48cd0d1187b..5a7357b9e28 100644
--- a/lib/private/encryption/file.php
+++ b/lib/private/encryption/file.php
@@ -36,7 +36,7 @@ class File implements \OCP\Encryption\IFile {
* get list of users with access to the file
*
* @param string $path to the file
- * @return array
+ * @return array ['users' => $uniqueUserIds, 'public' => $public]
*/
public function getAccessList($path) {
@@ -46,7 +46,7 @@ class File implements \OCP\Encryption\IFile {
// always add owner to the list of users with access to the file
$userIds = array($owner);
- if (!$this->util->isFile($ownerPath)) {
+ if (!$this->util->isFile($owner . '/' . $ownerPath)) {
return array('users' => $userIds, 'public' => false);
}
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php
index 97203b7756d..8e080507c81 100644
--- a/lib/private/encryption/manager.php
+++ b/lib/private/encryption/manager.php
@@ -22,6 +22,7 @@
namespace OC\Encryption;
+use OC\Files\Filesystem;
use OC\Files\Storage\Shared;
use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View;
@@ -222,7 +223,24 @@ class Manager implements IManager {
$uid = $user ? $user->getUID() : null;
$fileHelper = \OC::$server->getEncryptionFilesHelper();
$keyStorage = \OC::$server->getEncryptionKeyStorage();
- return new Encryption($parameters, $manager, $util, $logger, $fileHelper, $uid, $keyStorage);
+ $update = new Update(
+ new View(),
+ $util,
+ Filesystem::getMountManager(),
+ $manager,
+ $fileHelper,
+ $uid
+ );
+ return new Encryption(
+ $parameters,
+ $manager,
+ $util,
+ $logger,
+ $fileHelper,
+ $uid,
+ $keyStorage,
+ $update
+ );
} else {
return $storage;
}
diff --git a/lib/private/encryption/update.php b/lib/private/encryption/update.php
index 7a170a03adc..f262099a3c5 100644
--- a/lib/private/encryption/update.php
+++ b/lib/private/encryption/update.php
@@ -22,6 +22,7 @@
namespace OC\Encryption;
+use OC\Files\Filesystem;
use \OC\Files\Mount;
use \OC\Files\View;
@@ -74,46 +75,73 @@ class Update {
$this->uid = $uid;
}
+ /**
+ * hook after file was shared
+ *
+ * @param array $params
+ */
public function postShared($params) {
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
- $this->update($params['fileSource']);
+ $path = Filesystem::getPath($params['fileSource']);
+ list($owner, $ownerPath) = $this->getOwnerPath($path);
+ $absPath = '/' . $owner . '/files/' . $ownerPath;
+ $this->update($absPath);
}
}
+ /**
+ * hook after file was unshared
+ *
+ * @param array $params
+ */
public function postUnshared($params) {
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
- $this->update($params['fileSource']);
+ $path = Filesystem::getPath($params['fileSource']);
+ list($owner, $ownerPath) = $this->getOwnerPath($path);
+ $absPath = '/' . $owner . '/files/' . $ownerPath;
+ $this->update($absPath);
}
}
/**
- * update keyfiles and share keys recursively
+ * get owner and path relative to data/<owner>/files
*
- * @param int $fileSource file source id
+ * @param string $path path to file for current user
+ * @return array ['owner' => $owner, 'path' => $path]
+ * @throw \InvalidArgumentException
*/
- private function update($fileSource) {
- $path = \OC\Files\Filesystem::getPath($fileSource);
- $info = \OC\Files\Filesystem::getFileInfo($path);
- $owner = \OC\Files\Filesystem::getOwner($path);
- $view = new \OC\Files\View('/' . $owner . '/files');
- $ownerPath = $view->getPath($info->getId());
- $absPath = '/' . $owner . '/files' . $ownerPath;
+ private function getOwnerPath($path) {
+ $info = Filesystem::getFileInfo($path);
+ $owner = Filesystem::getOwner($path);
+ $view = new View('/' . $owner . '/files');
+ $path = $view->getPath($info->getId());
+ if ($path === null) {
+ throw new \InvalidArgumentException('No file found for ' . $info->getId());
+ }
+
+ return array($owner, $path);
+ }
- $mount = $this->mountManager->find($path);
- $mountPoint = $mount->getMountPoint();
+ /**
+ * notify encryption module about added/removed users from a file/folder
+ *
+ * @param string $path relative to data/
+ * @throws Exceptions\ModuleDoesNotExistsException
+ */
+ public function update($path) {
// if a folder was shared, get a list of all (sub-)folders
- if ($this->view->is_dir($absPath)) {
- $allFiles = $this->util->getAllFiles($absPath, $mountPoint);
+ if ($this->view->is_dir($path)) {
+ $allFiles = $this->util->getAllFiles($path);
} else {
- $allFiles = array($absPath);
+ $allFiles = array($path);
}
$encryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
- foreach ($allFiles as $path) {
- $usersSharing = $this->file->getAccessList($path);
- $encryptionModule->update($path, $this->uid, $usersSharing);
+ foreach ($allFiles as $file) {
+ $usersSharing = $this->file->getAccessList($file);
+ $encryptionModule->update($file, $this->uid, $usersSharing);
}
}
diff --git a/lib/private/encryption/util.php b/lib/private/encryption/util.php
index 98a38012dba..032ac83f37e 100644
--- a/lib/private/encryption/util.php
+++ b/lib/private/encryption/util.php
@@ -25,6 +25,7 @@ namespace OC\Encryption;
use OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException;
use OC\Encryption\Exceptions\EncryptionHeaderToLargeException;
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
+use OC\Files\Filesystem;
use OC\Files\View;
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
@@ -181,10 +182,9 @@ class Util {
* go recursively through a dir and collect all files and sub files.
*
* @param string $dir relative to the users files folder
- * @param string $mountPoint
* @return array with list of files relative to the users files folder
*/
- public function getAllFiles($dir, $mountPoint = '') {
+ public function getAllFiles($dir) {
$result = array();
$dirList = array($dir);
@@ -193,13 +193,10 @@ class Util {
$content = $this->view->getDirectoryContent($dir);
foreach ($content as $c) {
- // getDirectoryContent() returns the paths relative to the mount points, so we need
- // to re-construct the complete path
- $path = ($mountPoint !== '') ? $mountPoint . '/' . $c->getPath() : $c->getPath();
- if ($c['type'] === 'dir') {
- $dirList[] = \OC\Files\Filesystem::normalizePath($path);
+ if ($c->getType() === 'dir') {
+ $dirList[] = $c->getPath();
} else {
- $result[] = \OC\Files\Filesystem::normalizePath($path);
+ $result[] = $c->getPath();
}
}
@@ -212,11 +209,12 @@ class Util {
* check if it is a file uploaded by the user stored in data/user/files
* or a metadata file
*
- * @param string $path
+ * @param string $path relative to the data/ folder
* @return boolean
*/
public function isFile($path) {
- if (substr($path, 0, strlen('/files/')) === '/files/') {
+ $parts = explode('/', Filesystem::normalizePath($path), 4);
+ if (isset($parts[2]) && $parts[2] === 'files') {
return true;
}
return false;
@@ -262,7 +260,7 @@ class Util {
$ownerPath = implode('/', array_slice($parts, 2));
- return array($uid, \OC\Files\Filesystem::normalizePath($ownerPath));
+ return array($uid, Filesystem::normalizePath($ownerPath));
}