From 1e5d03da800e5ad36e7b5adbab7eef03a2add80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 12 Feb 2013 12:45:54 +0100 Subject: [PATCH] use right location of the file is the source and not the target it is shared to --- apps/files_encryption/hooks/hooks.php | 32 ++++++++++++++++----------- apps/files_encryption/lib/crypt.php | 6 ++--- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index c14ce3e91d..ebc345a47e 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -163,6 +163,20 @@ class Hooks { } + /** + * @brief get path of a file. + * @param $fileId id of the file + * @return path of the file + */ + private static function getFilePath($fileId) { + $query = \OC_DB::prepare('SELECT `path`' + .' FROM `*PREFIX*filecache`' + .' WHERE `fileid` = ?'); + $result = $query->execute(array($fileId)); + $row = $result->fetchRow(); + return $row['path']; + } + /** * @brief */ @@ -182,7 +196,7 @@ class Hooks { $shares = \OCP\Share::getUsersSharingFile( $params['itemSource'], 1 ); - return Crypt::encKeyfileToMultipleUsers($shares, $params['fileTarget']); + return Crypt::encKeyfileToMultipleUsers($shares, self::getFilePath($params['itemSource'])); } @@ -191,25 +205,17 @@ class Hooks { */ public static function preUnshare( $params ) { $shares = \OCP\Share::getUsersSharingFile( $params['itemSource'], 1 ); - - $userIds = array(); - foreach ( $shares as $share ) { - error_log("keek user id: " . $share['userId']); - $userIds[] = $share['userId']; - } - // remove the user from the list from which the file will be unshared - unset($userIds[$params['shareWith']]); - - return Crypt::encKeyfileToMultipleUsers($userIDs, $item[0]['file_target']); + unset($shares[$params['shareWith']]); + + return Crypt::encKeyfileToMultipleUsers($shares, self::getFilePath($params['itemSource'])); } /** * @brief */ public static function preUnshareAll( $params ) { - $items = \OCP\Share::getItemSharedWithBySource($params['itemType'], $params['itemSource']); - return Crypt::encKeyfileToMultipleUsers(array($items[0]['uid_owner']), $items[0]['file_target']); + return Crypt::encKeyfileToMultipleUsers(array(\OCP\User::getUser()), self::getFilePath($params['itemSource'])); } } diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index a8cc2b3726..cbdae323e5 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -750,7 +750,7 @@ class Crypt { * @param $users list of users which should be able to access the file * @param $fileTarget target of the file */ - public static function encKeyfileToMultipleUsers($users, $fileTarget) { + public static function encKeyfileToMultipleUsers($users, $filePath) { $view = new \OC_FilesystemView( '/' ); $owner = \OCP\User::getUser(); $util = new Util( $view, $userId ); @@ -785,7 +785,7 @@ class Crypt { \OC_FileProxy::$enabled = false; // get the keyfile - $encKeyfile = Keymanager::getFileKey( $view, $owner, $fileTarget ); + $encKeyfile = Keymanager::getFileKey( $view, $owner, $filePath ); $privateKey = $session->getPrivateKey(); @@ -796,7 +796,7 @@ class Crypt { $shareKeys = Crypt::multiKeyEncrypt( $plainKeyfile, $userPubKeys ); // save sharekeys - if ( ! Keymanager::setShareKeys( $view, $fileTarget, $shareKeys['keys'] ) ) { + if ( ! Keymanager::setShareKeys( $view, $filePath, $shareKeys['keys'] ) ) { trigger_error( "SET Share keys failed" );