Merge branch 'files_encryption' of https://github.com/owncloud/core into files_encryption

This commit is contained in:
Florin Peter 2013-04-22 18:51:11 +02:00
commit 2827004634
5 changed files with 48 additions and 27 deletions

View File

@ -193,8 +193,18 @@ class Hooks {
$util = new Util($view, $userId); $util = new Util($view, $userId);
$path = $util->fileIdToPath($params['itemSource']); $path = $util->fileIdToPath($params['itemSource']);
//check if this is a reshare action, that's true if the item source is already shared with me
$sharedItem = \OCP\Share::getItemSharedWithBySource($params['itemType'], $params['itemSource']);
if ($sharedItem) {
// if it is a re-share than the file is located in my Shared folder
$path = '/Shared'.$sharedItem['file_target'];
} else {
$path = $util->fileIdToPath($params['itemSource']);
}
$sharingEnabled = \OCP\Share::isEnabled(); $sharingEnabled = \OCP\Share::isEnabled();
// if a folder was shared, get a list if all (sub-)folders
if ($params['itemType'] === 'folder') { if ($params['itemType'] === 'folder') {
$allFiles = $util->getAllFiles($path); $allFiles = $util->getAllFiles($path);
} else { } else {
@ -243,12 +253,14 @@ class Hooks {
$util = new Util( $view, $userId ); $util = new Util( $view, $userId );
$path = $util->fileIdToPath( $params['itemSource'] ); $path = $util->fileIdToPath( $params['itemSource'] );
// for group shares get a list of the group members
if ($params['shareType'] == \OCP\Share::SHARE_TYPE_GROUP) { if ($params['shareType'] == \OCP\Share::SHARE_TYPE_GROUP) {
$userIds = \OC_Group::usersInGroup($params['shareWith']); $userIds = \OC_Group::usersInGroup($params['shareWith']);
} else { } else {
$userIds = array($params['shareWith']); $userIds = array($params['shareWith']);
} }
// if we unshare a folder we need a list of all (sub-)files
if ($params['itemType'] === 'folder') { if ($params['itemType'] === 'folder') {
$allFiles = $util->getAllFiles($path); $allFiles = $util->getAllFiles($path);
} else { } else {

View File

@ -54,7 +54,7 @@ class Keymanager {
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
return $view->file_get_contents( '/public-keys/' . '/' . $userId . '.public.key' ); return $view->file_get_contents( '/public-keys/' . $userId . '.public.key' );
\OC_FileProxy::$enabled = true; \OC_FileProxy::$enabled = true;
@ -392,6 +392,25 @@ class Keymanager {
} }
/**
* @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 * @brief Delete a single user's shareKey for a single file
*/ */

View File

@ -256,18 +256,13 @@ class Proxy extends \OC_FileProxy {
// Format path to be relative to user files dir // Format path to be relative to user files dir
$relPath = $util->stripUserFilesPath( $path ); $relPath = $util->stripUserFilesPath( $path );
// list( $owner, $ownerPath ) = $util->getUidAndFilename( $relPath ); 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;
// Delete keyfile & shareKey so it isn't orphaned // Delete keyfile & shareKey so it isn't orphaned
if ( if (
! ( ! (
Keymanager::deleteFileKey( $view, $fileOwner, $ownerPath ) Keymanager::deleteFileKey( $view, $owner, $ownerPath )
&& Keymanager::delShareKey( $view, $fileOwner, $ownerPath ) && Keymanager::delAllShareKeys( $view, $owner, $ownerPath )
) )
) { ) {

View File

@ -668,7 +668,7 @@ class Util {
// public system user 'ownCloud' (for public shares) // public system user 'ownCloud' (for public shares)
if ( if (
$util->ready() $util->ready()
or $user == 'ownCloud' or $user == 'owncloud'
) { ) {
// Construct array of ready UIDs for Keymanager{} // Construct array of ready UIDs for Keymanager{}
@ -805,15 +805,10 @@ class Util {
// Make sure that a share key is generated for the owner too // Make sure that a share key is generated for the owner too
list($owner, $ownerPath) = $this->getUidAndFilename($filePath); list($owner, $ownerPath) = $this->getUidAndFilename($filePath);
//$userIds = array( $this->userId );
$userIds = array();
if ( $sharingEnabled ) { if ( $sharingEnabled ) {
// Find out who, if anyone, is sharing the file // Find out who, if anyone, is sharing the file
$shareUids = \OCP\Share::getUsersSharingFile( $ownerPath, $owner,true, true, true ); $userIds = \OCP\Share::getUsersSharingFile( $ownerPath, $owner,true, true, true );
$userIds = array_merge( $userIds, $shareUids );
} }
@ -894,14 +889,14 @@ class Util {
} }
/** /**
*@ brief geo recursively through a dir and collect all files and sub files. * @brief geo recursively through a dir and collect all files and sub files.
* @param type $dir relative to the users files folder * @param type $dir relative to the users files folder
* @return array with list of files relative to the users files folder * @return array with list of files relative to the users files folder
*/ */
public function getAllFiles($dir) { public function getAllFiles($dir) {
$result = array(); $result = array();
$path = $this->view->getLocalFile();
$content = $this->view->getDirectoryContent("/".$this->userFilesDir.'/'.$this->filesFolderName.$dir); $content = $this->view->getDirectoryContent($this->userFilesDir.$dir);
foreach ($content as $c) { foreach ($content as $c) {
if ($c['type'] === "dir" ) { if ($c['type'] === "dir" ) {

View File

@ -150,10 +150,10 @@ class Share {
FROM FROM
`*PREFIX*share` `*PREFIX*share`
WHERE WHERE
item_source = ? AND share_type = ? AND uid_owner = ?' item_source = ? AND share_type = ?'
); );
$result = $query->execute( array( $source, self::SHARE_TYPE_USER, $user ) ); $result = $query->execute( array( $source, self::SHARE_TYPE_USER ) );
if ( \OC_DB::isError( $result ) ) { if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR ); \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
@ -170,10 +170,10 @@ class Share {
FROM FROM
`*PREFIX*share` `*PREFIX*share`
WHERE WHERE
item_source = ? AND share_type = ? AND uid_owner = ?' item_source = ? AND share_type = ?'
); );
$result = $query->execute( array( $source, self::SHARE_TYPE_GROUP, $user ) ); $result = $query->execute( array( $source, self::SHARE_TYPE_GROUP ) );
if ( \OC_DB::isError( $result ) ) { if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR ); \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
@ -190,17 +190,17 @@ class Share {
FROM FROM
`*PREFIX*share` `*PREFIX*share`
WHERE WHERE
item_source = ? AND share_type = ? AND uid_owner = ?' item_source = ? AND share_type = ?'
); );
$result = $query->execute( array( $source, self::SHARE_TYPE_LINK, $user ) ); $result = $query->execute( array( $source, self::SHARE_TYPE_LINK ) );
if ( \OC_DB::isError( $result ) ) { if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR ); \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
} }
if ($result->fetchRow()) { if ($result->fetchRow()) {
$shares[] = "ownCloud"; $shares[] = "owncloud";
} }
} }
// Include owner in list of users, if requested // Include owner in list of users, if requested