]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed handling of keyfile subdir creation
authorSam Tuke <samtuke@owncloud.com>
Wed, 30 Jan 2013 18:52:02 +0000 (18:52 +0000)
committerSam Tuke <samtuke@owncloud.com>
Wed, 30 Jan 2013 18:52:02 +0000 (18:52 +0000)
Improved keyfile subdir deletion (1 bug remains here)

apps/files_encryption/lib/keymanager.php
apps/files_encryption/lib/proxy.php

index 8656bb96758d1d960e165c850cb9c28d573f0ba7..43af70dacc2be7a6b502bc68dd397130cbb738a2 100755 (executable)
@@ -83,38 +83,7 @@ class Keymanager {
                // Check if sharing is enabled\r
                if ( OC_App::isEnabled( 'files_sharing' ) ) {\r
                        \r
-//                     // Check if file was shared with other users\r
-//                     $query = \OC_DB::prepare( "\r
-//                             SELECT \r
-//                                     uid_owner\r
-//                                     , source\r
-//                                     , target\r
-//                                     , uid_shared_with \r
-//                             FROM \r
-//                                     `*PREFIX*sharing` \r
-//                             WHERE \r
-//                                     ( target = ? AND uid_shared_with = ? ) \r
-//                                     OR source = ? \r
-//                     " );\r
-//                     \r
-//                     $result = $query->execute( array ( $filepath, $userId, $filepath ) );\r
-// \r
-//                     $users = array();\r
-// \r
-//                     if ( $row = $result->fetchRow() ) \r
-// {\r
-//                             $source = $row['source'];\r
-//                             $owner = $row['uid_owner'];\r
-//                             $users[] = $owner;\r
-//                             // get the uids of all user with access to the file\r
-//                             $query = \OC_DB::prepare( "SELECT source, uid_shared_with FROM `*PREFIX*sharing` WHERE source = ?" );\r
-//                             $result = $query->execute( array ($source));\r
-//                             while ( ($row = $result->fetchRow()) ) {\r
-//                                     $users[] = $row['uid_shared_with'];\r
-// \r
-//                             }\r
-// \r
-//                     }\r
+\r
                \r
                } else {\r
                \r
@@ -160,37 +129,16 @@ class Keymanager {
                \r
                $targetPath = self::keySetPreparation( $view, $path, $basePath, $userId );\r
                \r
-//             // update $keytarget and $userId if key belongs to a file shared by someone else\r
-//             $query = $dbClassName::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" );\r
-//             \r
-//             $result = $query->execute(  array ( '/'.$userId.'/files/'.$targetPath, $userId ) );\r
-//             \r
-//             if ( $row = $result->fetchRow(  ) ) {\r
-//             \r
-//                     $targetPath = $row['source'];\r
-//                     \r
-//                     $targetPath_parts = explode( '/', $targetPath );\r
-//                     \r
-//                     $userId = $targetPath_parts[1];\r
-// \r
-//                     $rootview = new \OC_FilesystemView( '/' );\r
-//                     \r
-//                     if ( ! $rootview->is_writable( $targetPath ) ) {\r
-//                     \r
-//                             \OC_Log::write( 'Encryption library', "File Key not updated because you don't have write access for the corresponding file", \OC_Log::ERROR );\r
-//                             \r
-//                             return false;\r
-//                             \r
-//                     }\r
-//                     \r
-//                     $targetPath = str_replace( '/'.$userId.'/files/', '', $targetPath );\r
-//                     \r
-//                     //TODO: check for write permission on shared file once the new sharing API is in place\r
-//                     \r
-//             }\r
-               \r
-               // Save the keyfile in parallel directory\r
-               return $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );\r
+               if ( $view->is_dir( $basePath . '/' . $targetPath ) ) {\r
+               \r
+                       \r
+               \r
+               } else {\r
+\r
+                       // Save the keyfile in parallel directory\r
+                       return $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );\r
+               \r
+               }\r
                \r
        }\r
        \r
@@ -204,21 +152,7 @@ class Keymanager {
        public static function getFileKey( \OC_FilesystemView $view, $userId, $filePath ) {\r
                \r
                $filePath_f = ltrim( $filePath, '/' );\r
-\r
-//             // update $keypath and $userId if path point to a file shared by someone else\r
-//             $query = \OC_DB::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" );\r
-//             \r
-//             $result = $query->execute( array ('/'.$userId.'/files/'.$keypath, $userId));\r
-//             \r
-//             if ($row = $result->fetchRow()) {\r
-//             \r
-//                     $keypath = $row['source'];\r
-//                     $keypath_parts = explode( '/', $keypath );\r
-//                     $userId = $keypath_parts[1];\r
-//                     $keypath = str_replace( '/' . $userId . '/files/', '', $keypath );\r
-//                     \r
-//             }\r
-\r
+               \r
                $catfilePath = '/' . $userId . '/files_encryption/keyfiles/' . $filePath_f . '.key';\r
                \r
                if ( $view->file_exists( $catfilePath ) ) {\r
@@ -337,7 +271,7 @@ class Keymanager {
         * @brief Make preparations to vars and filesystem for saving a keyfile\r
         */\r
        public static function keySetPreparation( \OC_FilesystemView $view, $path, $basePath, $userId ) {\r
-       \r
+               \r
                $targetPath = ltrim( $path, '/' );\r
                \r
                $path_parts = pathinfo( $targetPath );\r
@@ -345,10 +279,10 @@ class Keymanager {
                // If the file resides within a subdirectory, create it\r
                if ( \r
                isset( $path_parts['dirname'] )\r
-               && ! $view->file_exists( $basePath . $path_parts['dirname'] ) \r
+               && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) \r
                ) {\r
                \r
-                       $view->mkdir( $basePath . $path_parts['dirname'] );\r
+                       $view->mkdir( $basePath . '/' . $path_parts['dirname'] );\r
                        \r
                }\r
                \r
index 9e1dbfe0d371bc0d8510e94663d59253d98bd964..f7245d11cf56ee65917b4109d2dae9147b5af9e6 100644 (file)
 *
 */
 
+/**
+* @brief Encryption proxy which handles filesystem operations before and after
+*        execution and encrypts, and handles keyfiles accordingly. Used for 
+*        webui.
+*/
+
 namespace OCA\Encryption;
 
 class Proxy extends \OC_FileProxy {
@@ -202,6 +208,8 @@ class Proxy extends \OC_FileProxy {
                
                $view = new \OC_FilesystemView( '/' );
                
+               $userId = \OCP\USER::getUser();
+               
                // Format path to be relative to user files dir
                $trimmed = ltrim( $path, '/' );
                $split = explode( '/', $trimmed );
@@ -212,11 +220,9 @@ class Proxy extends \OC_FileProxy {
                        
                        // Dirs must be handled separately as deleteFileKey 
                        // doesn't handle them
-                       $view->unlink( 'files_encryption/keyfiles/'. $relPath );
+                       $view->unlink( $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/'. $relPath );
                        
                } else {
-
-                       $userId = \OCP\USER::getUser();
                
                        // Delete keyfile so it isn't orphaned
                        $result = Keymanager::deleteFileKey( $view, $userId, $relPath );