From 329bfd81c33ed95fdc91658cd914611605cd114f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 27 May 2014 15:09:43 +0200 Subject: remove encryption keys if user unshares a file --- apps/files_encryption/hooks/hooks.php | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 66e2bccd59f..99edcf25ec5 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -34,6 +34,8 @@ class Hooks { private static $renamedFiles = array(); // file for which we want to delete the keys after the delete operation was successful private static $deleteFiles = array(); + // file for which we want to delete the keys after the delete operation was successful + private static $umountedFiles = array(); /** * Startup encryption backend upon user login @@ -610,4 +612,57 @@ class Hooks { 'path' => $ownerPath); } + /** + * remember files/folders which get unmounted + */ + public static function preUmount($params) { + $path = $params[\OC\Files\Filesystem::signal_param_path]; + $user = \OCP\USER::getUser(); + + $view = new \OC\Files\View(); + $itemType = $view->is_dir('/' . $user . '/files' . $path) ? 'folder' : 'file'; + + $util = new Util($view, $user); + list($owner, $ownerPath) = $util->getUidAndFilename($path); + + self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array( + 'uid' => $owner, + 'path' => $ownerPath, + 'itemType' => $itemType); + } + + public static function postUmount($params) { + + if (!isset(self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]])) { + return true; + } + + $umountedFile = self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]]; + $path = $umountedFile['path']; + $user = $umountedFile['uid']; + $itemType = $umountedFile['itemType']; + + $view = new \OC\Files\View(); + $util = new Util($view, $user); + + // we don't need to remember the file any longer + unset(self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]]); + + // if we unshare a folder we need a list of all (sub-)files + if ($itemType === 'folder') { + $allFiles = $util->getAllFiles($path); + } else { + $allFiles = array($path); + } + + foreach ($allFiles as $path) { + + // check if the user still has access to the file, otherwise delete share key + $sharingUsers = $result = \OCP\Share::getUsersSharingFile($path, $user); + if (!in_array(\OCP\User::getUser(), $sharingUsers['users'])) { + Keymanager::delShareKey($view, array(\OCP\User::getUser()), $path); + } + } + } + } -- cgit v1.2.3 From cf5eb0fef546de0523157e943a97abcc8f3d1186 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 27 May 2014 21:15:39 +0200 Subject: remove unused variable --- apps/files_encryption/hooks/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 99edcf25ec5..f546ef72373 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -658,7 +658,7 @@ class Hooks { foreach ($allFiles as $path) { // check if the user still has access to the file, otherwise delete share key - $sharingUsers = $result = \OCP\Share::getUsersSharingFile($path, $user); + $sharingUsers = \OCP\Share::getUsersSharingFile($path, $user); if (!in_array(\OCP\User::getUser(), $sharingUsers['users'])) { Keymanager::delShareKey($view, array(\OCP\User::getUser()), $path); } -- cgit v1.2.3