]> source.dussan.org Git - nextcloud-server.git/commitdiff
new file structure for share keys; sub-folder need to be generated each by one (we...
authorBjörn Schießle <schiessle@owncloud.com>
Tue, 26 Mar 2013 10:58:54 +0000 (11:58 +0100)
committerBjörn Schießle <schiessle@owncloud.com>
Tue, 26 Mar 2013 10:58:54 +0000 (11:58 +0100)
apps/files_encryption/lib/keymanager.php

index 6837dcf67b5cee743192605943e26ee9c71f0812..6ef256553d7dbdc43870934f15167bf8d23af430 100755 (executable)
@@ -28,6 +28,22 @@ namespace OCA\Encryption;
  * @note Where a method requires a view object, it's root must be '/'\r
  */\r
 class Keymanager {\r
+\r
+       /**\r
+        * @brief get uid of the owners of the file and the path to the file\r
+        * @param $filename\r
+        * @return array\r
+        */\r
+       public static function getUidAndFilename($filename) {\r
+               $uid = \OC\Files\Filesystem::getOwner($filename);\r
+               \OC\Files\Filesystem::initMountPoints($uid);\r
+               if ( $uid != \OCP\User::getUser() ) {\r
+                       $info = \OC\Files\Filesystem::getFileInfo($filename);\r
+                       $ownerView = new \OC\Files\View('/'.$uid.'/files');\r
+                       $filename = $ownerView->getPath($info['fileid']);\r
+               }\r
+               return array($uid, $filename);\r
+       }\r
                \r
        /**\r
         * @brief retrieve the ENCRYPTED private key from a user\r
@@ -264,15 +280,17 @@ class Keymanager {
         * asymmetrically encrypt the keyfile before passing it to this method\r
         */\r
        public static function setShareKey( \OC_FilesystemView $view, $path, $userId, $shareKey ) {\r
+\r
+               list($owner, $filename) = self::getUidAndFilename($path);\r
+\r
+               $basePath = '/' . $owner . '/files_encryption/share-keys';\r
                \r
-               $basePath = '/' . $userId . '/files_encryption/share-keys';\r
-               \r
-               $shareKeyPath = self::keySetPreparation( $view, $path, $basePath, $userId );\r
+               $shareKeyPath = self::keySetPreparation( $view, $filename, $basePath, $owner );\r
                \r
-               $writePath = $basePath . '/' . $shareKeyPath . '.shareKey';\r
+               $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';\r
                \r
                \OC_FileProxy::$enabled = false;\r
-               \r
+\r
                $result = $view->file_put_contents( $writePath, $shareKey );\r
                \r
                if ( \r
@@ -295,7 +313,7 @@ class Keymanager {
         * @return bool\r
         */\r
        public static function setShareKeys( \OC_FilesystemView $view, $path, array $shareKeys ) {\r
-       \r
+\r
                // $shareKeys must be  an array with the following format:\r
                // [userId] => [encrypted key]\r
                \r
@@ -395,9 +413,14 @@ class Keymanager {
                isset( $path_parts['dirname'] )\r
                && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) \r
                ) {\r
-               \r
-                       $view->mkdir( $basePath . '/' . $path_parts['dirname'] );\r
-                       \r
+                       $sub_dirs = explode(DIRECTORY_SEPARATOR, $basePath . '/' . $path_parts['dirname']);\r
+                       $dir = '';\r
+                       foreach ($sub_dirs as $sub_dir) {\r
+                               $dir .= '/' . $sub_dir;\r
+                               if (!$view->is_dir($dir)) {\r
+                                       $view->mkdir($dir);\r
+                               }\r
+                       }\r
                }\r
                \r
                return $targetPath;\r