From 17059388482eabf6a1d05ea4c8d09e0f67ed9c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 22 Apr 2013 12:32:38 +0200 Subject: [PATCH 1/6] removed some leftover code; use already existing var for path to users file folder --- apps/files_encryption/lib/util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index de63e0ff9f4..d1377df9a95 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -895,8 +895,8 @@ class Util { */ public function getAllFiles($dir) { $result = array(); - $path = $this->view->getLocalFile(); - $content = $this->view->getDirectoryContent("/".$this->userFilesDir.'/'.$this->filesFolderName.$dir); + + $content = $this->view->getDirectoryContent($this->userFilesDir.$dir); foreach ($content as $c) { if ($c['type'] === "dir" ) { From b24a673714289bf515c93999a1dd0dfc552eb7cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 22 Apr 2013 14:12:18 +0200 Subject: [PATCH 2/6] the owner uid is not interesting. We want to get all users who have access to the given item source, no matter from whom it was shared --- lib/public/share.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index acdf895c920..9fd8eb42fb7 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -150,10 +150,10 @@ class Share { FROM `*PREFIX*share` WHERE - item_source = ? AND share_type = ? AND uid_owner = ?' + item_source = ? AND share_type = ?' ); - $result = $query->execute( array( $source, self::SHARE_TYPE_USER, $user ) ); + $result = $query->execute( array( $source, self::SHARE_TYPE_USER ) ); if ( \OC_DB::isError( $result ) ) { \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR ); @@ -170,10 +170,10 @@ class Share { FROM `*PREFIX*share` WHERE - item_source = ? AND share_type = ? AND uid_owner = ?' + item_source = ? AND share_type = ?' ); - $result = $query->execute( array( $source, self::SHARE_TYPE_GROUP, $user ) ); + $result = $query->execute( array( $source, self::SHARE_TYPE_GROUP ) ); if ( \OC_DB::isError( $result ) ) { \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR ); @@ -190,10 +190,10 @@ class Share { FROM `*PREFIX*share` WHERE - item_source = ? AND share_type = ? AND uid_owner = ?' + item_source = ? AND share_type = ?' ); - $result = $query->execute( array( $source, self::SHARE_TYPE_LINK, $user ) ); + $result = $query->execute( array( $source, self::SHARE_TYPE_LINK ) ); if ( \OC_DB::isError( $result ) ) { \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR ); From bcb2e87846407959a1826b3c38d6956d180e3468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 22 Apr 2013 14:13:59 +0200 Subject: [PATCH 3/6] check if the item source was shared to me to decide if it is a re-share or not. Re-sharing of encrypted files should work now, we might still need to test some corner cases --- apps/files_encryption/hooks/hooks.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index e3861e7cc5a..88ec64b492d 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -193,8 +193,18 @@ class Hooks { $util = new Util($view, $userId); $path = $util->fileIdToPath($params['itemSource']); + //check if this is a reshare action, that's true if the item source is already shared with me + $sharedItem = \OCP\Share::getItemSharedWithBySource($params['itemType'], $params['itemSource']); + if ($sharedItem) { + // if it is a re-share than the file is located in my Shared folder + $path = '/Shared'.$sharedItem['file_target']; + } else { + $path = $util->fileIdToPath($params['itemSource']); + } + $sharingEnabled = \OCP\Share::isEnabled(); + // if a folder was shared, get a list if all (sub-)folders if ($params['itemType'] === 'folder') { $allFiles = $util->getAllFiles($path); } else { @@ -243,12 +253,14 @@ class Hooks { $util = new Util( $view, $userId ); $path = $util->fileIdToPath( $params['itemSource'] ); + // for group shares get a list of the group members if ($params['shareType'] == \OCP\Share::SHARE_TYPE_GROUP) { $userIds = \OC_Group::usersInGroup($params['shareWith']); } else { $userIds = array($params['shareWith']); } + // if we unshare a folder we need a list of all (sub-)files if ($params['itemType'] === 'folder') { $allFiles = $util->getAllFiles($path); } else { From b57478fa27a2dc2dcfeba68064e44aca5848e145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 22 Apr 2013 14:14:28 +0200 Subject: [PATCH 4/6] fix comment, remove unused variable --- apps/files_encryption/lib/util.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index d1377df9a95..1ba339c15df 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -805,15 +805,10 @@ class Util { // Make sure that a share key is generated for the owner too list($owner, $ownerPath) = $this->getUidAndFilename($filePath); - //$userIds = array( $this->userId ); - $userIds = array(); - if ( $sharingEnabled ) { // Find out who, if anyone, is sharing the file - $shareUids = \OCP\Share::getUsersSharingFile( $ownerPath, $owner,true, true, true ); - - $userIds = array_merge( $userIds, $shareUids ); + $userIds = \OCP\Share::getUsersSharingFile( $ownerPath, $owner,true, true, true ); } @@ -889,7 +884,7 @@ class Util { } /** - *@ brief geo recursively through a dir and collect all files and sub files. + * @brief geo recursively through a dir and collect all files and sub files. * @param type $dir relative to the users files folder * @return array with list of files relative to the users files folder */ From b5cb5dab513441b8c914aaa043921d0affae4604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 22 Apr 2013 14:30:10 +0200 Subject: [PATCH 5/6] fix encryption to owncloud user for public link shares --- apps/files_encryption/lib/keymanager.php | 2 +- apps/files_encryption/lib/util.php | 2 +- lib/public/share.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index f23423062b9..6fb1f128b5e 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -54,7 +54,7 @@ class Keymanager { \OC_FileProxy::$enabled = false; - return $view->file_get_contents( '/public-keys/' . '/' . $userId . '.public.key' ); + return $view->file_get_contents( '/public-keys/' . $userId . '.public.key' ); \OC_FileProxy::$enabled = true; diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 1ba339c15df..143ba69f254 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -668,7 +668,7 @@ class Util { // public system user 'ownCloud' (for public shares) if ( $util->ready() - or $user == 'ownCloud' + or $user == 'owncloud' ) { // Construct array of ready UIDs for Keymanager{} diff --git a/lib/public/share.php b/lib/public/share.php index 9fd8eb42fb7..5cd556c6acb 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -200,7 +200,7 @@ class Share { } if ($result->fetchRow()) { - $shares[] = "ownCloud"; + $shares[] = "owncloud"; } } // Include owner in list of users, if requested From a4364a93d0e80e0d1daa2b28713df05c25970fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 22 Apr 2013 15:29:58 +0200 Subject: [PATCH 6/6] delete all share keys if a file gets deleted --- apps/files_encryption/lib/keymanager.php | 21 ++++++++++++++++++++- apps/files_encryption/lib/proxy.php | 11 +++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 6fb1f128b5e..9885f5e5508 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -391,7 +391,26 @@ class Keymanager { return $result; } - + + /** + * @brief delete all share keys of a given file + * @param \OC_FilesystemView $view + * @param type $userId owner of the file + * @param type $filePath path to the file, relative to the owners file dir + */ + public static function delAllShareKeys(\OC_FilesystemView $view, $userId, $filePath) { + + if ($view->is_dir($userId.'/files/'.$filePath)) { + $view->unlink($userId.'/files_encryption/share-keys/'.$filePath); + } else { + $localKeyPath = $view->getLocalFile($userId.'/files_encryption/share-keys/'.$filePath); + $matches = glob(preg_quote($localKeyPath).'*.shareKey'); + foreach ($matches as $ma) { + unlink($ma); + } + } + } + /** * @brief Delete a single user's shareKey for a single file */ diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 505fad440d5..bd25465ee69 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -256,18 +256,13 @@ class Proxy extends \OC_FileProxy { // Format path to be relative to user files dir $relPath = $util->stripUserFilesPath( $path ); -// list( $owner, $ownerPath ) = $util->getUidAndFilename( $relPath ); - - $fileOwner = \OC\Files\Filesystem::getOwner( $path ); - $ownerPath = $util->stripUserFilesPath( $path ); // TODO: Don't trust $path, fetch owner path - - $filePath = $fileOwner . '/' . 'files_encryption' . '/' . 'keyfiles' . '/'. $ownerPath; + list( $owner, $ownerPath ) = $util->getUidAndFilename( $relPath ); // Delete keyfile & shareKey so it isn't orphaned if ( ! ( - Keymanager::deleteFileKey( $view, $fileOwner, $ownerPath ) - && Keymanager::delShareKey( $view, $fileOwner, $ownerPath ) + Keymanager::deleteFileKey( $view, $owner, $ownerPath ) + && Keymanager::delAllShareKeys( $view, $owner, $ownerPath ) ) ) {