Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions apps/files/lib/Command/TransferOwnership.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@

namespace OCA\Files\Command;

use OC\Encryption\CustomEncryptionWrapper;
use OC\Encryption\Manager;
use OC\Files\CustomView;
use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Wrapper;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OCP\Files\FileInfo;
use OCP\Files\Mount\IMountManager;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\Share\IManager;
use OCP\Share\IShare;
Expand All @@ -49,6 +55,12 @@ class TransferOwnership extends Command {
/** @var IMountManager */
private $mountManager;

/** @var Manager */
private $encryptionManager;

/** @var ILogger */
private $logger;

/** @var FileInfo[] */
private $allFiles = [];

Expand All @@ -70,10 +82,12 @@ class TransferOwnership extends Command {
/** @var string */
private $finalTarget;

public function __construct(IUserManager $userManager, IManager $shareManager, IMountManager $mountManager) {
public function __construct(IUserManager $userManager, IManager $shareManager, IMountManager $mountManager, Manager $encryptionManager, ILogger $logger) {
$this->userManager = $userManager;
$this->shareManager = $shareManager;
$this->mountManager = $mountManager;
$this->encryptionManager = $encryptionManager;
$this->logger = $logger;
parent::__construct();
}

Expand Down Expand Up @@ -249,7 +263,7 @@ private function collectUsersShares(OutputInterface $output) {
* @param OutputInterface $output
*/
protected function transfer(OutputInterface $output) {
$view = new View();
$view = new CustomView();
$output->writeln("Transferring files to $this->finalTarget ...");
$sourcePath = (strlen($this->inputPath) > 0) ? $this->inputPath : "$this->sourceUser/files";
// This change will help user to transfer the folder specified using --path option.
Expand All @@ -260,7 +274,19 @@ protected function transfer(OutputInterface $output) {
$this->finalTarget = $this->finalTarget . '/' . basename($sourcePath);
}
}
$view->rename($sourcePath, $this->finalTarget);
/**
* If encryption is enabled and masterkey is the option selected
* kindly use the CustomView wrapper.
*/
if ($this->encryptionManager->isEnabled() &&
\OC::$server->getAppConfig()->getValue('encryption', 'useMasterKey', 0) !== 0) {
$customEncryptionWrapper = new CustomEncryptionWrapper(new ArrayCache(), \OC::$server->getEncryptionManager(), \OC::$server->getLogger());
Filesystem::addStorageWrapper('oc_customencryption', [$customEncryptionWrapper, 'wrapCustomStorage'], 2);
//A new wrapper for view.
$view->renameCustom($sourcePath, $this->finalTarget);
} else {
$view->rename($sourcePath, $this->finalTarget);
}
if (!is_dir("$this->sourceUser/files")) {
// because the files folder is moved away we need to recreate it
$view->mkdir("$this->sourceUser/files");
Expand Down
127 changes: 127 additions & 0 deletions lib/private/Encryption/CustomEncryptionWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
/**
* @author Björn Schießle <[email protected]>
* @author Joas Schilling <[email protected]>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/


namespace OC\Encryption;


use OC\Files\Storage\Wrapper\CustomEncryption;
use OC\Memcache\ArrayCache;
use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Encryption;
use OCP\Files\Mount\IMountPoint;
use OC\Files\View;
use OCP\Files\Storage;
use OCP\ILogger;

/**
* Class EncryptionWrapper
*
* applies the encryption storage wrapper
*
* @package OC\Encryption
*/
class CustomEncryptionWrapper {

/** @var ArrayCache */
private $arrayCache;

/** @var Manager */
private $manager;

/** @var ILogger */
private $logger;

/**
* EncryptionWrapper constructor.
*
* @param ArrayCache $arrayCache
* @param Manager $manager
* @param ILogger $logger
*/
public function __construct(ArrayCache $arrayCache,
Manager $manager,
ILogger $logger
) {
$this->arrayCache = $arrayCache;
$this->manager = $manager;
$this->logger = $logger;
}

/**
* Wraps the given storage when it is not a shared storage
*
* @param string $mountPoint
* @param Storage $storage
* @param IMountPoint $mount
* @return Encryption|Storage
*/
public function wrapCustomStorage($mountPoint, Storage $storage, IMountPoint $mount) {
$parameters = [
'storage' => $storage,
'mountPoint' => $mountPoint,
'mount' => $mount
];

if (!$storage->instanceOfStorage('OCA\Files_Sharing\SharedStorage')
&& !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')
&& !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud')) {

$user = \OC::$server->getUserSession()->getUser();
$mountManager = Filesystem::getMountManager();
$uid = $user ? $user->getUID() : null;
$fileHelper = \OC::$server->getEncryptionFilesHelper();
$keyStorage = \OC::$server->getEncryptionKeyStorage();

$util = new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()
);
$update = new Update(
new View(),
$util,
Filesystem::getMountManager(),
$this->manager,
$fileHelper,
$uid
);

return new CustomEncryption(
$parameters,
$this->manager,
$util,
$this->logger,
$fileHelper,
$uid,
$keyStorage,
$update,
$mountManager,
$this->arrayCache
);
} else {
return $storage;
}
}

}
Loading