]> source.dussan.org Git - nextcloud-server.git/commitdiff
delete all share keys if a file gets deleted
authorBjörn Schießle <schiessle@owncloud.com>
Mon, 22 Apr 2013 13:29:58 +0000 (15:29 +0200)
committerBjörn Schießle <schiessle@owncloud.com>
Mon, 22 Apr 2013 13:29:58 +0000 (15:29 +0200)
apps/files_encryption/lib/keymanager.php
apps/files_encryption/lib/proxy.php

index 6fb1f128b5e6984e50dc903075f3c6563a9dcdf0..9885f5e5508b560ac37647bfb4e5678c28eda4f8 100755 (executable)
@@ -391,7 +391,26 @@ class Keymanager {
                return $result;
                
        }
-       
+
+       /**
+        * @brief delete all share keys of a given file
+        * @param \OC_FilesystemView $view
+        * @param type $userId owner of the file
+        * @param type $filePath path to the file, relative to the owners file dir
+        */
+       public static function delAllShareKeys(\OC_FilesystemView $view, $userId, $filePath) {
+               
+               if ($view->is_dir($userId.'/files/'.$filePath)) {
+                       $view->unlink($userId.'/files_encryption/share-keys/'.$filePath);
+               } else {
+                       $localKeyPath = $view->getLocalFile($userId.'/files_encryption/share-keys/'.$filePath);
+                       $matches = glob(preg_quote($localKeyPath).'*.shareKey');
+                       foreach ($matches as $ma) {
+                               unlink($ma);
+                       }
+               }
+       }
+
        /**
         * @brief Delete a single user's shareKey for a single file
         */
index 505fad440d5d2510432d2e0d98c27d3407d951f1..bd25465ee695327d8d0b01b26f04c5154fa79be2 100644 (file)
@@ -256,18 +256,13 @@ class Proxy extends \OC_FileProxy {
                // Format path to be relative to user files dir
                $relPath = $util->stripUserFilesPath( $path );
 
-//             list( $owner, $ownerPath ) = $util->getUidAndFilename( $relPath );
-
-               $fileOwner = \OC\Files\Filesystem::getOwner( $path );
-               $ownerPath = $util->stripUserFilesPath( $path );  // TODO: Don't trust $path, fetch owner path
-
-               $filePath = $fileOwner . '/' . 'files_encryption' . '/' . 'keyfiles' . '/'. $ownerPath;
+               list( $owner, $ownerPath ) = $util->getUidAndFilename( $relPath );
 
                // Delete keyfile & shareKey so it isn't orphaned
                if (
                        ! (
-                               Keymanager::deleteFileKey( $view, $fileOwner, $ownerPath )
-                               && Keymanager::delShareKey( $view, $fileOwner, $ownerPath )
+                               Keymanager::deleteFileKey( $view, $owner, $ownerPath )
+                               && Keymanager::delAllShareKeys( $view, $owner, $ownerPath )
                        )
                ) {