summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib/keymanager.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/lib/keymanager.php')
-rwxr-xr-xapps/files_encryption/lib/keymanager.php59
1 files changed, 24 insertions, 35 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index 98986d1486f..e71fec56854 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -133,20 +133,7 @@ class Keymanager {
$basePath = '/' . $owner . '/files_encryption/keyfiles';
}
- $targetPath = self::keySetPreparation($view, $filename, $basePath, $owner);
-
- if (!$view->is_dir($basePath . '/' . $targetPath)) {
-
- // create all parent folders
- $info = pathinfo($basePath . '/' . $targetPath);
- $keyfileFolderName = $view->getLocalFolder($info['dirname']);
-
- if (!file_exists($keyfileFolderName)) {
-
- mkdir($keyfileFolderName, 0750, true);
-
- }
- }
+ $targetPath = self::keySetPreparation($view, $filename, $basePath);
// try reusing key file if part file
if (Helper::isPartialFilePath($targetPath)) {
@@ -281,8 +268,9 @@ class Keymanager {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
- if (!$view->file_exists(''))
+ if (!$view->file_exists('')) {
$view->mkdir('');
+ }
$result = $view->file_put_contents($user . '.private.key', $key);
@@ -340,7 +328,7 @@ class Keymanager {
$basePath = '/' . $owner . '/files_encryption/share-keys';
}
- $shareKeyPath = self::keySetPreparation($view, $filename, $basePath, $owner);
+ $shareKeyPath = self::keySetPreparation($view, $filename, $basePath);
$result = true;
@@ -466,8 +454,7 @@ class Keymanager {
if ($view->is_dir($shareKeyPath)) {
- $localPath = \OC\Files\Filesystem::normalizePath($view->getLocalFolder($shareKeyPath));
- self::recursiveDelShareKeys($localPath, $userIds);
+ self::recursiveDelShareKeys($shareKeyPath, $userIds, $view);
} else {
@@ -491,23 +478,25 @@ class Keymanager {
* @param string $dir directory
* @param array $userIds user ids for which the share keys should be deleted
*/
- private static function recursiveDelShareKeys($dir, $userIds) {
- foreach ($userIds as $userId) {
- $extension = '.' . $userId . '.shareKey';
- $escapedDir = Helper::escapeGlobPattern($dir);
- $escapedExtension = Helper::escapeGlobPattern($extension);
- $matches = glob($escapedDir . '/*' . $escapedExtension);
- }
- /** @var $matches array */
- foreach ($matches as $ma) {
- if (!unlink($ma)) {
- \OCP\Util::writeLog('Encryption library',
- 'Could not delete shareKey; does not exist: "' . $ma . '"', \OCP\Util::ERROR);
+ private static function recursiveDelShareKeys($dir, $userIds, $view) {
+
+ $dirContent = $view->opendir($dir);
+
+ if (is_resource($dirContent)) {
+ while (($file = readdir($dirContent)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ if ($view->is_dir($dir . '/' . $file)) {
+ self::recursiveDelShareKeys($dir . '/' . $file, $userIds, $view);
+ } else {
+ foreach ($userIds as $userId) {
+ if (preg_match("/(.*)." . $userId . ".shareKey/", $file)) {
+ $view->unlink($dir . '/' . $file);
+ }
+ }
+ }
+ }
}
- }
- $subdirs = glob($escapedDir . '/*', GLOB_ONLYDIR);
- foreach ($subdirs as $subdir) {
- self::recursiveDelShareKeys($subdir, $userIds);
+ closedir($dirContent);
}
}
@@ -516,7 +505,7 @@ class Keymanager {
* @param string|boolean $path
* @param string $basePath
*/
- protected static function keySetPreparation(\OC\Files\View $view, $path, $basePath, $userId) {
+ protected static function keySetPreparation(\OC\Files\View $view, $path, $basePath) {
$targetPath = ltrim($path, '/');