From c7b1bdf00e65cca2a42d77fc5f27d0ea69e53be3 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Wed, 30 Jan 2013 18:52:02 +0000 Subject: [PATCH] Fixed handling of keyfile subdir creation Improved keyfile subdir deletion (1 bug remains here) --- apps/files_encryption/lib/keymanager.php | 96 ++++-------------------- apps/files_encryption/lib/proxy.php | 12 ++- 2 files changed, 24 insertions(+), 84 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 8656bb96758..43af70dacc2 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -83,38 +83,7 @@ class Keymanager { // Check if sharing is enabled if ( OC_App::isEnabled( 'files_sharing' ) ) { -// // Check if file was shared with other users -// $query = \OC_DB::prepare( " -// SELECT -// uid_owner -// , source -// , target -// , uid_shared_with -// FROM -// `*PREFIX*sharing` -// WHERE -// ( target = ? AND uid_shared_with = ? ) -// OR source = ? -// " ); -// -// $result = $query->execute( array ( $filepath, $userId, $filepath ) ); -// -// $users = array(); -// -// if ( $row = $result->fetchRow() ) -// { -// $source = $row['source']; -// $owner = $row['uid_owner']; -// $users[] = $owner; -// // get the uids of all user with access to the file -// $query = \OC_DB::prepare( "SELECT source, uid_shared_with FROM `*PREFIX*sharing` WHERE source = ?" ); -// $result = $query->execute( array ($source)); -// while ( ($row = $result->fetchRow()) ) { -// $users[] = $row['uid_shared_with']; -// -// } -// -// } + } else { @@ -160,37 +129,16 @@ class Keymanager { $targetPath = self::keySetPreparation( $view, $path, $basePath, $userId ); -// // update $keytarget and $userId if key belongs to a file shared by someone else -// $query = $dbClassName::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" ); -// -// $result = $query->execute( array ( '/'.$userId.'/files/'.$targetPath, $userId ) ); -// -// if ( $row = $result->fetchRow( ) ) { -// -// $targetPath = $row['source']; -// -// $targetPath_parts = explode( '/', $targetPath ); -// -// $userId = $targetPath_parts[1]; -// -// $rootview = new \OC_FilesystemView( '/' ); -// -// if ( ! $rootview->is_writable( $targetPath ) ) { -// -// \OC_Log::write( 'Encryption library', "File Key not updated because you don't have write access for the corresponding file", \OC_Log::ERROR ); -// -// return false; -// -// } -// -// $targetPath = str_replace( '/'.$userId.'/files/', '', $targetPath ); -// -// //TODO: check for write permission on shared file once the new sharing API is in place -// -// } - - // Save the keyfile in parallel directory - return $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile ); + if ( $view->is_dir( $basePath . '/' . $targetPath ) ) { + + + + } else { + + // Save the keyfile in parallel directory + return $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile ); + + } } @@ -204,21 +152,7 @@ class Keymanager { public static function getFileKey( \OC_FilesystemView $view, $userId, $filePath ) { $filePath_f = ltrim( $filePath, '/' ); - -// // update $keypath and $userId if path point to a file shared by someone else -// $query = \OC_DB::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" ); -// -// $result = $query->execute( array ('/'.$userId.'/files/'.$keypath, $userId)); -// -// if ($row = $result->fetchRow()) { -// -// $keypath = $row['source']; -// $keypath_parts = explode( '/', $keypath ); -// $userId = $keypath_parts[1]; -// $keypath = str_replace( '/' . $userId . '/files/', '', $keypath ); -// -// } - + $catfilePath = '/' . $userId . '/files_encryption/keyfiles/' . $filePath_f . '.key'; if ( $view->file_exists( $catfilePath ) ) { @@ -337,7 +271,7 @@ class Keymanager { * @brief Make preparations to vars and filesystem for saving a keyfile */ public static function keySetPreparation( \OC_FilesystemView $view, $path, $basePath, $userId ) { - + $targetPath = ltrim( $path, '/' ); $path_parts = pathinfo( $targetPath ); @@ -345,10 +279,10 @@ class Keymanager { // If the file resides within a subdirectory, create it if ( isset( $path_parts['dirname'] ) - && ! $view->file_exists( $basePath . $path_parts['dirname'] ) + && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) ) { - $view->mkdir( $basePath . $path_parts['dirname'] ); + $view->mkdir( $basePath . '/' . $path_parts['dirname'] ); } diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 9e1dbfe0d37..f7245d11cf5 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -22,6 +22,12 @@ * */ +/** +* @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 ); -- 2.39.5