From 83898e87be3486ecec76ee240a8810ce693be888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 5 Jul 2013 10:07:23 +0200 Subject: [PATCH 01/24] Merge https://github.com/owncloud/core/pull/3900 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit a34098427720c2d0470367cd9698c184d85b8dfd Merge: ccf849b 955646c Author: Björn Schießle Date: Fri Jul 5 09:59:29 2013 +0200 Merge branch 'master' into theme_aware_mail_footer commit ccf849bc6f18d80cdb593e851529b87579fe072b Merge: 8d5fb70 3c1308f Author: Björn Schießle Date: Thu Jul 4 11:03:47 2013 +0200 Merge branch 'master' into theme_aware_mail_footer commit 8d5fb70e6dcb2e2e34dcdf2a883680ef034afeea Author: Björn Schießle Date: Thu Jul 4 10:38:39 2013 +0200 switch to non-static defaults.php commit 88ab2768dcc4ced12c48872c887baa94ad938d62 Merge: e199df8 84c25f9 Author: Björn Schießle Date: Wed Jul 3 16:59:48 2013 +0200 Merge branch 'theme_aware_mail_footer' of github.com:owncloud/core into theme_aware_mail_footer Conflicts: core/templates/altmail.php commit e199df844b5faf80a36d8380a5b0b58025cd425f Author: Björn Schießle Date: Wed Jul 3 16:56:29 2013 +0200 name and slogan should be in one line commit 84c25f9853e1bfbe4ae780371b1353aafb6b15c2 Author: Thomas Müller Date: Mon Jul 1 21:15:35 2013 +0200 no ?> at the end of a file commit 3bd8d38d011f62ce78bcd0c108eb8cf2ce97eb99 Author: Björn Schießle Date: Mon Jul 1 12:58:36 2013 +0200 print url unescaped commit d304ed18c8b7350e92e24565b9b9ba77b519d74c Author: Björn Schießle Date: Mon Jul 1 12:56:05 2013 +0200 make new mail templates aware of different ownCloud themes --- core/templates/altmail.php | 8 ++++---- core/templates/mail.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/templates/altmail.php b/core/templates/altmail.php index 37dc8eee94..a7df29a244 100644 --- a/core/templates/altmail.php +++ b/core/templates/altmail.php @@ -1,9 +1,9 @@ t("Hey there,\n\njust letting you know that %s shared %s with you.\nView it: %s\n\nCheers!", array($_['user_displayname'], $_['filename'], $_['link']))); ?> -- -ownCloud - t("web services under your control")); -?> -http://ownCloud.org +getName() . ' - ' . $defaults->getSlogan()); ?> +getBaseUrl()); diff --git a/core/templates/mail.php b/core/templates/mail.php index ebeefd5c7e..562ad82e95 100644 --- a/core/templates/mail.php +++ b/core/templates/mail.php @@ -1,3 +1,4 @@ +
@@ -20,10 +21,9 @@ print_unescaped($l->t('Hey there,

just letting you know that %s shared » +getName()); ?> - +getSlogan()); ?> +
getBaseUrl());?> From 13991be5ce6e318670b84458c2cdaa6878ad63cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Jul 2013 10:53:59 +0200 Subject: [PATCH 02/24] no anonymous upload on files only folders --- apps/files_sharing/public.php | 3 +++ core/js/share.js | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index fb18bc2624..96fe12fc86 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -151,6 +151,9 @@ if (isset($path)) { if (\OCP\App::isEnabled('files_encryption')) { $allowPublicUploadEnabled = false; } + if (isset($file)) { + $allowPublicUploadEnabled = false; + } $tmpl->assign('allowPublicUploadEnabled', $allowPublicUploadEnabled); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); diff --git a/core/js/share.js b/core/js/share.js index 588202d227..778a9f8e20 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -181,11 +181,13 @@ OC.Share={ html += '
'; html += ''; html += '
'; - html += ''; - html += ''; + if (itemType == 'folder') { + html += ''; + } + html += ''; html += ''; html += ''; html += ''; From 27c0cc7fda6c722a201ac8a549b855663cf9c68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Jul 2013 11:23:08 +0200 Subject: [PATCH 03/24] no anonymous upload on read-only folders --- core/js/share.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/js/share.js b/core/js/share.js index 588202d227..9494637c3d 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -163,10 +163,10 @@ OC.Share={ var allowPublicUploadStatus = false; $.each(data.shares, function(key, value) { - if (allowPublicUploadStatus) { - return true; - } - allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false; + if (allowPublicUploadStatus) { + return true; + } + allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false; }); html += ''; @@ -181,11 +181,13 @@ OC.Share={ html += '
'; html += ''; html += '
'; - html += ''; - html += ''; + if (possiblePermissions & OC.PERMISSION_CREATE) { + html += ''; + } + html += ''; html += ''; html += ''; html += ''; From 0c32f668998bfa95ae9a36bbddcc6263b2a98701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Jul 2013 12:15:47 +0200 Subject: [PATCH 04/24] get the real physical folder name for anonymous upload --- apps/files/ajax/upload.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 8433716dec..4b015e4d1f 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -18,7 +18,6 @@ if (empty($_POST['dirToken'])) { } } else { $linkItem = OCP\Share::getShareByToken($_POST['dirToken']); - if ($linkItem === false) { OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Invalid Token'))))); die(); @@ -27,11 +26,17 @@ if (empty($_POST['dirToken'])) { if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) { OCP\JSON::checkLoggedIn(); } else { + // translate linkItem to the real folder name on the file system + $sharedItem = OCP\Share::getItemShared($linkItem['item_type'], $linkItem['item_source']); + if (!$sharedItem || empty($sharedItem) || $sharedItem === false) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); + die(); + } // The token defines the target directory (security reasons) $dir = sprintf( "/%s/%s", - $linkItem['file_target'], + array_pop($sharedItem)['path'], isset($_POST['subdir']) ? $_POST['subdir'] : '' ); From d1d68855850022ee4dd91105f00a947029f2e4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Jul 2013 13:22:38 +0200 Subject: [PATCH 05/24] php 5.3 compliant now --- apps/files/ajax/upload.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 4b015e4d1f..733ed95974 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -34,9 +34,10 @@ if (empty($_POST['dirToken'])) { } // The token defines the target directory (security reasons) + $sharedItem = array_pop($sharedItem); $dir = sprintf( "/%s/%s", - array_pop($sharedItem)['path'], + $sharedItem['path'], isset($_POST['subdir']) ? $_POST['subdir'] : '' ); From 352c1415be55ae5797685d2ea22fcd07cdfbf4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Jul 2013 13:45:21 +0200 Subject: [PATCH 06/24] proper fix for getting the shared item if no user is logged in --- apps/files/ajax/upload.php | 9 +++++---- lib/public/share.php | 13 ++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 733ed95974..54604d1056 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -26,15 +26,18 @@ if (empty($_POST['dirToken'])) { if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) { OCP\JSON::checkLoggedIn(); } else { + // Setup FS with owner + OC_Util::tearDownFS(); + OC_Util::setupFS($linkItem['uid_owner']); + // translate linkItem to the real folder name on the file system - $sharedItem = OCP\Share::getItemShared($linkItem['item_type'], $linkItem['item_source']); + $sharedItem = OCP\Share::getSharedItem($linkItem['item_type'], $linkItem['item_source'], $linkItem['uid_owner']); if (!$sharedItem || empty($sharedItem) || $sharedItem === false) { OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); die(); } // The token defines the target directory (security reasons) - $sharedItem = array_pop($sharedItem); $dir = sprintf( "/%s/%s", $sharedItem['path'], @@ -45,8 +48,6 @@ if (empty($_POST['dirToken'])) { OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); die(); } - // Setup FS with owner - OC_Util::setupFS($linkItem['uid_owner']); } } diff --git a/lib/public/share.php b/lib/public/share.php index de7025d7b1..28878c2c86 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -312,11 +312,22 @@ class Share { * @return Return depends on format */ public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE, - $parameters = null, $includeCollections = false) { + $parameters = null, $includeCollections = false) { return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), $format, $parameters, -1, $includeCollections); } + /** + * @param $itemType + * @param $itemSource + * @param $uid_owner + * @return mixed + */ + public static function getSharedItem($itemType, $itemSource, $uid_owner) { + return self::getItems($itemType, $itemSource, null, null, $uid_owner, self::FORMAT_NONE, + null, 1, false); + } + /** * Get all users an item is shared with * @param string Item type From 3f5eb762b6d7572b68c77f0009a76ff9b1f8d946 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 5 Jul 2013 14:51:22 +0200 Subject: [PATCH 07/24] Scanner test: ensure mtime in the cache is the same as on the storage to prevent random failures --- tests/lib/files/cache/scanner.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index 042bf8991f..263ceadccc 100644 --- a/tests/lib/files/cache/scanner.php +++ b/tests/lib/files/cache/scanner.php @@ -132,6 +132,7 @@ class Scanner extends \PHPUnit_Framework_TestCase { $this->scanner->scan(''); $oldData = $this->cache->get(''); $this->storage->unlink('folder/bar.txt'); + $this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder'))); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE); $newData = $this->cache->get(''); $this->assertNotEquals($oldData['etag'], $newData['etag']); From 0c2ebb984e5d3764997a96cad54a40464623aeb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Jul 2013 15:07:05 +0200 Subject: [PATCH 08/24] adding tipsy to the upload button showing the max upload and restoring client side upload size validation --- apps/files_sharing/js/public.js | 2 + apps/files_sharing/templates/public.php | 142 ++++++++++++------------ 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 0244f392a0..294223aa09 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -11,6 +11,8 @@ var form_data; $(document).ready(function() { + $('#data-upload-form').tipsy({gravity:'ne', fade:true}); + if (typeof FileActions !== 'undefined') { var mimetype = $('#mimetype').val(); // Show file preview if previewer is available, images are already handled by the template diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 56ed4ca168..e8bf80b872 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -1,5 +1,5 @@
- +
@@ -9,88 +9,92 @@
+ +
-
- - - - -
- -
- -
- -
+
+ + - + +
+ +
+ +
+ +
+ + + - -
-
-

- getLongFooter()); ?> -

-
+
+
+

+ getLongFooter()); ?> +

+
From c1cf829b9d3b54b9a798a30ee10d3c496f871958 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 5 Jul 2013 15:07:15 +0200 Subject: [PATCH 09/24] OC_Config: handle failure of glob('*.config.php') --- lib/config.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/config.php b/lib/config.php index fcd0a9d7c3..f1c139f22b 100644 --- a/lib/config.php +++ b/lib/config.php @@ -132,6 +132,9 @@ class OC_Config{ // read all file in config dir ending by config.php $config_files = glob( OC::$SERVERROOT."/config/*.config.php"); + if (!is_array($config_files)) { + $config_files = array(); + } //Filter only regular files $config_files = array_filter($config_files, 'is_file'); From 18b11f76b1e1a4e77ccf5e618f5312538db93532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Jul 2013 15:27:14 +0200 Subject: [PATCH 10/24] fixing === and ident --- core/js/share.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/js/share.js b/core/js/share.js index ced1e0aa8c..21e352ee1c 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -181,12 +181,12 @@ OC.Share={ html += '
'; html += ''; html += '
'; - if (itemType == 'folder' && (possiblePermissions & OC.PERMISSION_CREATE)) { - html += ''; - } + if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE)) { + html += ''; + } html += '
'; html += ''; html += ''; From 3e4dcafa892b7fe73dcd9afba65ded290dd54734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 12:21:54 +0200 Subject: [PATCH 11/24] handle system wide mount points --- apps/files_encryption/lib/keymanager.php | 49 +++++++++++++++++++----- apps/files_encryption/lib/util.php | 30 +++++++++++---- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index e911c1785d..084abdb2c2 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -126,7 +126,12 @@ class Keymanager { $util = new Util($view, \OCP\User::getUser()); list($owner, $filename) = $util->getUidAndFilename($path); - $basePath = '/' . $owner . '/files_encryption/keyfiles'; + // in case of system wide mount points the keys are stored directly in the data directory + if (self::isSystemWideMountPoint($filename)) { + $basePath = '/files_encryption/keyfiles'; + } else { + $basePath = '/' . $owner . '/files_encryption/keyfiles'; + } $targetPath = self::keySetPreparation($view, $filename, $basePath, $owner); @@ -233,7 +238,12 @@ class Keymanager { list($owner, $filename) = $util->getUidAndFilename($filePath); $filePath_f = ltrim($filename, '/'); - $keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key'; + // in case of system wide mount points the keys are stored directly in the data directory + if (self::isSystemWideMountPoint($filename)) { + $keyfilePath = '/files_encryption/keyfiles/' . $filePath_f . '.key'; + } else { + $keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key'; + } $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -341,19 +351,20 @@ class Keymanager { list($owner, $filename) = $util->getUidAndFilename($path); - $basePath = '/' . $owner . '/files_encryption/share-keys'; + // in case of system wide mount points the keys are stored directly in the data directory + if (self::isSystemWideMountPoint($filename)) { + $basePath = '/files_encryption/share-keys'; + } else { + $basePath = '/' . $owner . '/files_encryption/share-keys'; + } $shareKeyPath = self::keySetPreparation($view, $filename, $basePath, $owner); // try reusing key file if part file if (self::isPartialFilePath($shareKeyPath)) { - $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey'; - } else { - $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey'; - } $proxyStatus = \OC_FileProxy::$enabled; @@ -440,8 +451,13 @@ class Keymanager { $util = new Util($view, \OCP\User::getUser()); list($owner, $filename) = $util->getUidAndFilename($filePath); - $shareKeyPath = \OC\Files\Filesystem::normalizePath( - '/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'); + + // in case of system wide mount points the keys are stored directly in the data directory + if (self::isSystemWideMountPoint($filename)) { + $shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; + } else { + $shareKeyPath = '/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; + } if ($view->file_exists($shareKeyPath)) { @@ -568,4 +584,19 @@ class Keymanager { return $targetPath; } + + /** + * @brief check if the file is stored on a system wide mount point + * @param $path relative to /data/user with leading '/' + * @return boolean + */ + private static function isSystemWideMountPoint($path) { + $mount = OC_Mount_Config::getSystemMountPoints(); + foreach ($mount as $mountPoint => $data) { + if ($mountPoint == substr($path, 1, strlen($mountPoint))) { + return true; + } + } + return false; + } } \ No newline at end of file diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index b3de85254e..a5290013a4 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -992,13 +992,9 @@ class Util { \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled') && $this->recoveryEnabledForUser() ) { - $recoveryEnabled = true; - } else { - $recoveryEnabled = false; - } // Make sure that a share key is generated for the owner too @@ -1019,20 +1015,24 @@ class Util { // If recovery is enabled, add the // Admin UID to list of users to share to if ($recoveryEnabled) { - // Find recoveryAdmin user ID $recoveryKeyId = \OC_Appconfig::getValue('files_encryption', 'recoveryKeyId'); - // Add recoveryAdmin to list of users sharing $userIds[] = $recoveryKeyId; - } // add current user if given if ($currentUserId !== false) { - $userIds[] = $currentUserId; + } + // check if it is a group mount + $mount = OC_Mount_Config::getSystemMountPoints(); + foreach ($mount as $mountPoint => $data) { + if ($mountPoint == substr($ownerPath, 1, strlen($mountPoint))) { + $userIds = array_merge($userIds, + $this->getUserWithAccessToMountPoint($data['applicable']['users'], $data['applicable']['groups'])); + } } // Remove duplicate UIDs @@ -1042,6 +1042,20 @@ class Util { } + private function getUserWithAccessToMountPoint($users, $groups) { + $result = array(); + if (in_array('all', $users)) { + $result = \OCP\User::getUsers(); + } else { + $result = array_merge($result, $users); + foreach ($groups as $group) { + $result = array_merge($result, \OC_Group::usersInGroup($group)); + } + } + + return $result; + } + /** * @brief start migration mode to initially encrypt users data * @return boolean From 2e56f0e2f8b653a36a811ea4669b1b36fc876f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 13:36:43 +0200 Subject: [PATCH 12/24] fix path to OC_Mount_Config --- apps/files_encryption/lib/keymanager.php | 2 +- apps/files_encryption/lib/util.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 084abdb2c2..e1bf59d80b 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -591,7 +591,7 @@ class Keymanager { * @return boolean */ private static function isSystemWideMountPoint($path) { - $mount = OC_Mount_Config::getSystemMountPoints(); + $mount = \OC_Mount_Config::getSystemMountPoints(); foreach ($mount as $mountPoint => $data) { if ($mountPoint == substr($path, 1, strlen($mountPoint))) { return true; diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index a5290013a4..2bf17dcc22 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1027,7 +1027,7 @@ class Util { } // check if it is a group mount - $mount = OC_Mount_Config::getSystemMountPoints(); + $mount = \OC_Mount_Config::getSystemMountPoints(); foreach ($mount as $mountPoint => $data) { if ($mountPoint == substr($ownerPath, 1, strlen($mountPoint))) { $userIds = array_merge($userIds, From f2de4cb3422742e7c5c91f6bcd8c2024393bbd58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 14:15:53 +0200 Subject: [PATCH 13/24] some performance improvements, check for system wide mounts only once while writing share keys --- apps/files_encryption/lib/keymanager.php | 85 ++++++++++-------------- 1 file changed, 35 insertions(+), 50 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index e1bf59d80b..898ea945a6 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -335,17 +335,39 @@ class Keymanager { * @brief store share key * * @param \OC_FilesystemView $view - * @param string $path relative path of the file, including filename - * @param $userId + * @param string $path where the share key is stored * @param $shareKey - * @internal param string $key - * @internal param string $dbClassName * @return bool true/false * @note The keyfile is not encrypted here. Client code must * asymmetrically encrypt the keyfile before passing it to this method */ - public static function setShareKey(\OC_FilesystemView $view, $path, $userId, $shareKey) { + private static function setShareKey(\OC_FilesystemView $view, $path, $shareKey) { + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + $result = $view->file_put_contents($path, $shareKey); + + \OC_FileProxy::$enabled = $proxyStatus; + + if (is_int($result) && $result > 0) { + return true; + } else { + return false; + } + } + + /** + * @brief store multiple share keys for a single file + * @param \OC_FilesystemView $view + * @param $path + * @param array $shareKeys + * @return bool + */ + public static function setShareKeys(\OC_FilesystemView $view, $path, array $shareKeys) { + + // $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()); @@ -360,63 +382,26 @@ class Keymanager { $shareKeyPath = self::keySetPreparation($view, $filename, $basePath, $owner); - // try reusing key file if part file - if (self::isPartialFilePath($shareKeyPath)) { - $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey'; - } else { - $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey'; - } - - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; - - $result = $view->file_put_contents($writePath, $shareKey); - - \OC_FileProxy::$enabled = $proxyStatus; - - if ( - is_int($result) - && $result > 0 - ) { - - return true; - - } else { - - return false; - - } - - } - - /** - * @brief store multiple share keys for a single file - * @param \OC_FilesystemView $view - * @param $path - * @param array $shareKeys - * @return bool - */ - public static function setShareKeys(\OC_FilesystemView $view, $path, array $shareKeys) { - - // $shareKeys must be an array with the following format: - // [userId] => [encrypted key] - $result = true; foreach ($shareKeys as $userId => $shareKey) { - if (!self::setShareKey($view, $path, $userId, $shareKey)) { + // try reusing key file if part file + if (self::isPartialFilePath($shareKeyPath)) { + $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey'; + } else { + $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey'; + } + + if (!self::setShareKey($view, $writePath, $shareKey)) { // If any of the keys are not set, flag false $result = false; - } - } // Returns false if any of the keys weren't set return $result; - } /** From eb2587a08ffc53efe284a06832f0a946d17aebf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 14:25:00 +0200 Subject: [PATCH 14/24] move isSystemWideMountPoint() to util.php --- apps/files_encryption/lib/keymanager.php | 23 ++++------------------- apps/files_encryption/lib/util.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 898ea945a6..d43a0c2891 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -127,7 +127,7 @@ class Keymanager { list($owner, $filename) = $util->getUidAndFilename($path); // in case of system wide mount points the keys are stored directly in the data directory - if (self::isSystemWideMountPoint($filename)) { + if ($util->isSystemWideMountPoint($filename)) { $basePath = '/files_encryption/keyfiles'; } else { $basePath = '/' . $owner . '/files_encryption/keyfiles'; @@ -239,7 +239,7 @@ class Keymanager { $filePath_f = ltrim($filename, '/'); // in case of system wide mount points the keys are stored directly in the data directory - if (self::isSystemWideMountPoint($filename)) { + if ($util->isSystemWideMountPoint($filename)) { $keyfilePath = '/files_encryption/keyfiles/' . $filePath_f . '.key'; } else { $keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key'; @@ -374,7 +374,7 @@ class Keymanager { list($owner, $filename) = $util->getUidAndFilename($path); // in case of system wide mount points the keys are stored directly in the data directory - if (self::isSystemWideMountPoint($filename)) { + if ($util->isSystemWideMountPoint($filename)) { $basePath = '/files_encryption/share-keys'; } else { $basePath = '/' . $owner . '/files_encryption/share-keys'; @@ -438,7 +438,7 @@ class Keymanager { list($owner, $filename) = $util->getUidAndFilename($filePath); // in case of system wide mount points the keys are stored directly in the data directory - if (self::isSystemWideMountPoint($filename)) { + if ($util->isSystemWideMountPoint($filename)) { $shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; } else { $shareKeyPath = '/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; @@ -569,19 +569,4 @@ class Keymanager { return $targetPath; } - - /** - * @brief check if the file is stored on a system wide mount point - * @param $path relative to /data/user with leading '/' - * @return boolean - */ - private static function isSystemWideMountPoint($path) { - $mount = \OC_Mount_Config::getSystemMountPoints(); - foreach ($mount as $mountPoint => $data) { - if ($mountPoint == substr($path, 1, strlen($mountPoint))) { - return true; - } - } - return false; - } } \ No newline at end of file diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 2bf17dcc22..7228d2a647 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1561,4 +1561,19 @@ class Util { return $relativePath; } + /** + * @brief check if the file is stored on a system wide mount point + * @param $path relative to /data/user with leading '/' + * @return boolean + */ + public function isSystemWideMountPoint($path) { + $mount = \OC_Mount_Config::getSystemMountPoints(); + foreach ($mount as $mountPoint => $data) { + if ($mountPoint == substr($path, 1, strlen($mountPoint))) { + return true; + } + } + return false; + } + } From abc2ee2e07e1e4f73e6e50aa3855d15ca92f6468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 14:42:49 +0200 Subject: [PATCH 15/24] handle rename correctly for system wide mounts --- apps/files_encryption/hooks/hooks.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 197982010f..96f06b154f 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -476,10 +476,19 @@ class Hooks { $util = new Util($view, $userId); // Format paths to be relative to user files dir - $oldKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['oldpath']); - $newKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['newpath']); + if ($util->isSystemWideMountPoint($params['oldpath'])) { + $baseDir = 'files_encryption/'; + $oldKeyfilePath = $baseDir . 'keyfiles/' . $params['oldpath']; + } else { + $baseDir = $userId . '/' . 'files_encryption/'; + $oldKeyfilePath = $baseDir . 'keyfiles/' . $params['oldpath']; + } + + if ($util->isSystemWideMountPoint($params['newpath'])) { + $newKeyfilePath = $baseDir . 'keyfiles/' . $params['newpath']; + } else { + $newKeyfilePath = $baseDir . 'keyfiles/' . $params['newpath']; + } // add key ext if this is not an folder if (!$view->is_dir($oldKeyfilePath)) { @@ -487,7 +496,7 @@ class Hooks { $newKeyfilePath .= '.key'; // handle share-keys - $localKeyPath = $view->getLocalFile($userId . '/files_encryption/share-keys/' . $params['oldpath']); + $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']); $matches = glob(preg_quote($localKeyPath) . '*.shareKey'); foreach ($matches as $src) { $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src)); @@ -502,10 +511,8 @@ class Hooks { } else { // handle share-keys folders - $oldShareKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['oldpath']); - $newShareKeyfilePath = \OC\Files\Filesystem::normalizePath( - $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['newpath']); + $oldShareKeyfilePath = $baseDir . 'share-keys/' . $params['oldpath']; + $newShareKeyfilePath = $baseDir . 'share-keys/' . $params['newpath']; // create destination folder if not exists if (!$view->file_exists(dirname($newShareKeyfilePath))) { From 3043dbfb95b7ea84d2d3478aef7cc3c28c8d4b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 16:03:03 +0200 Subject: [PATCH 16/24] delete file keys from the correct location --- apps/files_encryption/lib/keymanager.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index d43a0c2891..0f60884374 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -277,7 +277,14 @@ class Keymanager { public static function deleteFileKey(\OC_FilesystemView $view, $userId, $path) { $trimmed = ltrim($path, '/'); - $keyPath = '/' . $userId . '/files_encryption/keyfiles/' . $trimmed; + + $util = new Util($view, \OCP\User::getUser()); + + if($util->isSystemWideMountPoint($path)) { + $keyPath = '/files_encryption/keyfiles/' . $trimmed; + } else { + $keyPath = '/' . $userId . '/files_encryption/keyfiles/' . $trimmed; + } $result = false; From af2cd6f5418078e813e4b3cad27cc859273592de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 16:41:24 +0200 Subject: [PATCH 17/24] always return normalized path --- apps/files_encryption/lib/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 7228d2a647..00b3192db8 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1193,7 +1193,7 @@ class Util { return array( $fileOwnerUid, - $filename + \OC_Filesystem::normalizePath($filename) ); } From 93730a090be9587a5b6c52fe52afaba0a48be1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 16:41:51 +0200 Subject: [PATCH 18/24] del share keys from correct location --- apps/files_encryption/lib/keymanager.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 0f60884374..8de1d41364 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -475,10 +475,19 @@ class Keymanager { */ public static function delAllShareKeys(\OC_FilesystemView $view, $userId, $filePath) { - if ($view->is_dir($userId . '/files/' . $filePath)) { - $view->unlink($userId . '/files_encryption/share-keys/' . $filePath); + $util = new util($view, $userId); + + if ($util->isSystemWideMountPoint($filePath)) { + $baseDir = '/files_encryption/share-keys/'; } else { - $localKeyPath = $view->getLocalFile($userId . '/files_encryption/share-keys/' . $filePath); + $baseDir = $userId . '/files_encryption/share-keys/'; + } + + + if ($view->is_dir($userId . '/files/' . $filePath)) { + $view->unlink($baseDir . $filePath); + } else { + $localKeyPath = $view->getLocalFile($baseDir . $filePath); $matches = glob(preg_quote($localKeyPath) . '*.shareKey'); foreach ($matches as $ma) { $result = unlink($ma); @@ -503,7 +512,11 @@ class Keymanager { list($owner, $filename) = $util->getUidAndFilename($filePath); - $shareKeyPath = \OC\Files\Filesystem::normalizePath('/' . $owner . '/files_encryption/share-keys/' . $filename); + if ($util->isSystemWideMountPoint($filename)) { + $shareKeyPath = \OC\Files\Filesystem::normalizePath('/files_encryption/share-keys/' . $filename); + } else { + $shareKeyPath = \OC\Files\Filesystem::normalizePath('/' . $owner . '/files_encryption/share-keys/' . $filename); + } if ($view->is_dir($shareKeyPath)) { From f9c337dd2149248be717f870bdba79ac21868bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 16:50:10 +0200 Subject: [PATCH 19/24] only escape glob pattern --- apps/files_encryption/hooks/hooks.php | 3 ++- apps/files_encryption/lib/keymanager.php | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 96f06b154f..c26119b6c2 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -497,7 +497,8 @@ class Hooks { // handle share-keys $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']); - $matches = glob(preg_quote($localKeyPath) . '*.shareKey'); + $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $src) { $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src)); diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 8de1d41364..da2ee380e8 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -488,7 +488,8 @@ class Keymanager { $view->unlink($baseDir . $filePath); } else { $localKeyPath = $view->getLocalFile($baseDir . $filePath); - $matches = glob(preg_quote($localKeyPath) . '*.shareKey'); + $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $ma) { $result = unlink($ma); if (!$result) { @@ -547,7 +548,10 @@ class Keymanager { */ private static function recursiveDelShareKeys($dir, $userIds) { foreach ($userIds as $userId) { - $matches = glob(preg_quote($dir) . '/*' . preg_quote('.' . $userId . '.shareKey')); + $extension = '.' . $userId . '.shareKey'; + $escapedDir = preg_replace('/(\*|\?|\[)/', '[$1]', $dir); + $escapedExtension = preg_replace('/(\*|\?|\[)/', '[$1]', $extension); + $matches = glob($escapedDir . '/*' . $escapedExtension); } /** @var $matches array */ foreach ($matches as $ma) { @@ -556,7 +560,7 @@ class Keymanager { 'Could not delete shareKey; does not exist: "' . $ma . '"', \OCP\Util::ERROR); } } - $subdirs = $directories = glob(preg_quote($dir) . '/*', GLOB_ONLYDIR); + $subdirs = $directories = glob($escapedDir . '/*', GLOB_ONLYDIR); foreach ($subdirs as $subdir) { self::recursiveDelShareKeys($subdir, $userIds); } From ae30eb48f26d5f7bf3f7cf83e9ef56ca9cdbcf3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 17:17:41 +0200 Subject: [PATCH 20/24] make trash bin aware of system wide mounts with respect to encryption keys --- apps/files_trashbin/lib/trash.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 1235d9d2ee..b9d900dfab 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -171,13 +171,19 @@ class Trashbin { list($owner, $ownerPath) = self::getUidAndFilename($file_path); + $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $user); // disable proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - // retain key files - $keyfile = \OC\Files\Filesystem::normalizePath($owner . '/files_encryption/keyfiles/' . $ownerPath); + if ($util->isSystemWideMountPoint($ownerPath)) { + $baseDir = '/files_encryption/'; + } else { + $baseDir = $owner . '/files_encryption/'; + } + + $keyfile = \OC\Files\Filesystem::normalizePath($baseDir . '/keyfiles/' . $ownerPath); if ($rootView->is_dir($keyfile) || $rootView->file_exists($keyfile . '.key')) { // move keyfiles @@ -191,7 +197,7 @@ class Trashbin { } // retain share keys - $sharekeys = \OC\Files\Filesystem::normalizePath($owner . '/files_encryption/share-keys/' . $ownerPath); + $sharekeys = \OC\Files\Filesystem::normalizePath($baseDir . '/share-keys/' . $ownerPath); if ($rootView->is_dir($sharekeys)) { $size += self::calculateSize(new \OC\Files\View($sharekeys)); @@ -403,6 +409,14 @@ class Trashbin { list($owner, $ownerPath) = self::getUidAndFilename($target); + $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $user); + + if ($util->isSystemWideMountPoint($ownerPath)) { + $baseDir = '/files_encryption/'; + } else { + $baseDir = $owner . '/files_encryption/'; + } + $path_parts = pathinfo($file); $source_location = $path_parts['dirname']; @@ -432,18 +446,18 @@ class Trashbin { // handle keyfiles $size += self::calculateSize(new \OC\Files\View($keyfile)); - $rootView->rename($keyfile, $owner . '/files_encryption/keyfiles/' . $ownerPath); + $rootView->rename($keyfile, $baseDir . '/keyfiles/' . $ownerPath); // handle share-keys if ($timestamp) { $sharekey .= '.d' . $timestamp; } $size += self::calculateSize(new \OC\Files\View($sharekey)); - $rootView->rename($sharekey, $owner . '/files_encryption/share-keys/' . $ownerPath); + $rootView->rename($sharekey, $baseDir . '/share-keys/' . $ownerPath); } else { // handle keyfiles $size += $rootView->filesize($keyfile); - $rootView->rename($keyfile, $owner . '/files_encryption/keyfiles/' . $ownerPath . '.key'); + $rootView->rename($keyfile, $baseDir . '/keyfiles/' . $ownerPath . '.key'); // handle share-keys $ownerShareKey = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user . '.shareKey'); @@ -454,7 +468,7 @@ class Trashbin { $size += $rootView->filesize($ownerShareKey); // move only owners key - $rootView->rename($ownerShareKey, $owner . '/files_encryption/share-keys/' . $ownerPath . '.' . $user . '.shareKey'); + $rootView->rename($ownerShareKey, $baseDir . '/share-keys/' . $ownerPath . '.' . $user . '.shareKey'); // try to re-share if file is shared $filesystemView = new \OC_FilesystemView('/'); From 15cb8e4efd5c7f74dc5f0336b0e0b5aba5a9d470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 17:46:04 +0200 Subject: [PATCH 21/24] only check for external mount points if the external storage app is enabled --- apps/files_encryption/lib/util.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 00b3192db8..50e823585d 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1027,11 +1027,12 @@ class Util { } // check if it is a group mount - $mount = \OC_Mount_Config::getSystemMountPoints(); - foreach ($mount as $mountPoint => $data) { - if ($mountPoint == substr($ownerPath, 1, strlen($mountPoint))) { - $userIds = array_merge($userIds, - $this->getUserWithAccessToMountPoint($data['applicable']['users'], $data['applicable']['groups'])); + if (\OCP\App::isEnabled("files_external")) { + $mount = \OC_Mount_Config::getSystemMountPoints(); + foreach ($mount as $mountPoint => $data) { + if ($mountPoint == substr($ownerPath, 1, strlen($mountPoint))) { + $userIds = array_merge($userIds, $this->getUserWithAccessToMountPoint($data['applicable']['users'], $data['applicable']['groups'])); + } } } @@ -1567,10 +1568,12 @@ class Util { * @return boolean */ public function isSystemWideMountPoint($path) { - $mount = \OC_Mount_Config::getSystemMountPoints(); - foreach ($mount as $mountPoint => $data) { - if ($mountPoint == substr($path, 1, strlen($mountPoint))) { - return true; + if (\OCP\App::isEnabled("files_external")) { + $mount = \OC_Mount_Config::getSystemMountPoints(); + foreach ($mount as $mountPoint => $data) { + if ($mountPoint == substr($path, 1, strlen($mountPoint))) { + return true; + } } } return false; From ec6350079f5eab706bb4567654c99c6f800a4f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 25 Jun 2013 18:03:05 +0200 Subject: [PATCH 22/24] fix getUidAndFilename() test --- apps/files_encryption/tests/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index cb10befc8e..368b7b3dc3 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -219,7 +219,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { \OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1); - $filename = 'tmp-' . time() . '.test'; + $filename = '/tmp-' . time() . '.test'; // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; From 9575c2f37c39ae0799c3b8faec4d7902d17e6832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 5 Jul 2013 14:58:33 +0200 Subject: [PATCH 23/24] added helper function to escape glob pattern Conflicts: apps/files_encryption/lib/helper.php --- apps/files_encryption/hooks/hooks.php | 2 +- apps/files_encryption/lib/helper.php | 12 +++++++++++- apps/files_encryption/lib/keymanager.php | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index c26119b6c2..b2a17f6bca 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -497,7 +497,7 @@ class Hooks { // handle share-keys $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']); - $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $escapedPath = Helper::escapeGlobPattern($localKeyPath); $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $src) { $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src)); diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 31cf48a039..1b9637c1b9 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -218,7 +218,6 @@ class Helper { exit(); } - /** * check requirements for encryption app. * @return bool true if requirements are met @@ -234,3 +233,14 @@ class Helper { return (bool) $result; } } + + /** + * @brief glob uses different pattern than regular expressions, escape glob pattern only + * @param unescaped path + * @return escaped path + */ + public static function escapeGlobPattern($path) { + return preg_replace('/(\*|\?|\[)/', '[$1]', $path); + } +} + diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index da2ee380e8..b2fd650f18 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -488,7 +488,7 @@ class Keymanager { $view->unlink($baseDir . $filePath); } else { $localKeyPath = $view->getLocalFile($baseDir . $filePath); - $escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); + $escapedPath = Helper::escapeGlobPattern($localKeyPath); $matches = glob($escapedPath . '*.shareKey'); foreach ($matches as $ma) { $result = unlink($ma); @@ -549,8 +549,8 @@ class Keymanager { private static function recursiveDelShareKeys($dir, $userIds) { foreach ($userIds as $userId) { $extension = '.' . $userId . '.shareKey'; - $escapedDir = preg_replace('/(\*|\?|\[)/', '[$1]', $dir); - $escapedExtension = preg_replace('/(\*|\?|\[)/', '[$1]', $extension); + $escapedDir = Helper::escapeGlobPattern($dir); + $escapedExtension = Helper::escapeGlobPattern($extension); $matches = glob($escapedDir . '/*' . $escapedExtension); } /** @var $matches array */ From 87063918f223bcab956bd19fe0845ca1e28e9013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 5 Jul 2013 16:05:05 +0200 Subject: [PATCH 24/24] remove wrong closing bracket --- apps/files_encryption/lib/helper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 1b9637c1b9..6eee8fed6a 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -232,7 +232,6 @@ class Helper { return (bool) $result; } -} /** * @brief glob uses different pattern than regular expressions, escape glob pattern only
  --
-ownCloud - t('web services under your control')); -?> -
http://ownCloud.org