-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bjoern Schiessle
committed
Mar 17, 2015
1 parent
b07da6c
commit 429cab1
Showing
6 changed files
with
374 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* ownCloud | ||
* | ||
* @copyright (C) 2015 ownCloud, Inc. | ||
* | ||
* @author Bjoern Schiessle <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version. | ||
* | ||
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OC\Encryption\Keys; | ||
|
||
use OC\Encryption\Util; | ||
use OC\Files\View; | ||
use OC\User; | ||
|
||
/** | ||
* Factory provides KeyStorage for different encryption modules | ||
*/ | ||
class Factory { | ||
/** @var array */ | ||
protected $instances = array(); | ||
|
||
/** | ||
* get a KeyStorage instance | ||
* | ||
* @param string $encryptionModuleId | ||
* @param View $view | ||
* @param Util $util | ||
* @return Storage | ||
*/ | ||
public function get($encryptionModuleId,View $view, Util $util) { | ||
if (!isset($this->instances[$encryptionModuleId])) { | ||
$this->instances[$encryptionModuleId] = new Storage($encryptionModuleId, $view, $util); | ||
} | ||
return $this->instances[$encryptionModuleId]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,13 +49,25 @@ class Util { | |
*/ | ||
protected $blockSize = 8192; | ||
|
||
/** $var array */ | ||
/** @var \OC\Files\View */ | ||
protected $view; | ||
|
||
/** @var array */ | ||
protected $ocHeaderKeys; | ||
|
||
public function __construct() { | ||
/** @var \OC\User\Manager */ | ||
protected $userManager; | ||
|
||
/** | ||
* @param \OC\Files\View $view root view | ||
*/ | ||
public function __construct(\OC\Files\View $view, \OC\User\Manager $userManager) { | ||
$this->ocHeaderKeys = [ | ||
self::HEADER_ENCRYPTION_MODULE => self::HEADER_ENCRYPTION_MODULE_KEY | ||
]; | ||
|
||
$this->view = $view; | ||
$this->userManager = $userManager; | ||
} | ||
|
||
/** | ||
|
@@ -186,8 +198,62 @@ public function getBlockSize() { | |
return $this->blockSize; | ||
} | ||
|
||
public function getUidAndFilename($filename) { | ||
// TODO find a better implementation than in the current encyption app | ||
public function getUidAndFilename($path) { | ||
|
||
$parts = explode('/', $path); | ||
if (count($parts) > 2) { | ||
$uid = $parts[1]; | ||
if (!$this->userManager->userExists($uid)) { | ||
throw new \BadMethodCallException('path needs to be relative to the system wide data folder and point to a user specific file'); | ||
} | ||
} | ||
|
||
$pathinfo = pathinfo($path); | ||
$partfile = false; | ||
$parentFolder = false; | ||
if (array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'part') { | ||
// if the real file exists we check this file | ||
$filePath = $pathinfo['dirname'] . '/' . $pathinfo['filename']; | ||
if ($this->view->file_exists($filePath)) { | ||
$pathToCheck = $pathinfo['dirname'] . '/' . $pathinfo['filename']; | ||
} else { // otherwise we look for the parent | ||
$pathToCheck = $pathinfo['dirname']; | ||
$parentFolder = true; | ||
} | ||
$partfile = true; | ||
} else { | ||
$pathToCheck = $path; | ||
} | ||
|
||
$pathToCheck = substr($pathToCheck, strlen('/' . $uid)); | ||
|
||
$this->view->chroot('/' . $uid); | ||
$owner = $this->view->getOwner($pathToCheck); | ||
|
||
// Check that UID is valid | ||
if (!\OCP\User::userExists($owner)) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
throw new \BadMethodCallException('path needs to be relative to the system wide data folder and point to a user specific file'); | ||
} | ||
|
||
\OC\Files\Filesystem::initMountPoints($owner); | ||
This comment has been minimized.
Sorry, something went wrong.
DeepDiver1975
Member
|
||
|
||
$info = $this->view->getFileInfo($pathToCheck); | ||
$this->view->chroot('/' . $owner); | ||
$ownerPath = $this->view->getPath($info->getId()); | ||
$this->view->chroot('/'); | ||
|
||
if ($parentFolder) { | ||
$ownerPath = $ownerPath . '/'. $pathinfo['filename']; | ||
} | ||
|
||
if ($partfile) { | ||
$ownerPath = $ownerPath . '.' . $pathinfo['extension']; | ||
} | ||
|
||
return array( | ||
$owner, | ||
\OC\Files\Filesystem::normalizePath($ownerPath) | ||
); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
isn't there a normalizePath on the view as well?