diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-11-03 12:14:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-03 12:14:28 +0100 |
commit | b33ceb6fdd7a9458ba2d8730b401271eb640822d (patch) | |
tree | 88773bb64938ddbc2dd7f41ca883b20781116544 /lib | |
parent | e11197bc4872f2ada4740736969f4c96e24ea229 (diff) | |
parent | 6920e609c02814d03a5dc83792de12d05f1da854 (diff) | |
download | nextcloud-server-b33ceb6fdd7a9458ba2d8730b401271eb640822d.tar.gz nextcloud-server-b33ceb6fdd7a9458ba2d8730b401271eb640822d.zip |
Merge pull request #1915 from nextcloud/downstream-26398
Add using casing check/fix for initMountPoints
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Filesystem.php | 14 | ||||
-rw-r--r-- | lib/private/Files/Node/Root.php | 59 | ||||
-rw-r--r-- | lib/private/Server.php | 9 | ||||
-rw-r--r-- | lib/private/Share/Share.php | 29 | ||||
-rw-r--r-- | lib/public/Share.php | 10 |
5 files changed, 96 insertions, 25 deletions
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index 113bb5a85c6..d2662af527a 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -394,9 +394,6 @@ class Filesystem { if ($user === null || $user === false || $user === '') { throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session'); } - if (isset(self::$usersSetup[$user])) { - return; - } $userManager = \OC::$server->getUserManager(); $userObject = $userManager->get($user); @@ -406,6 +403,17 @@ class Filesystem { throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); } + // workaround in case of different casings + if ($user !== $userObject->getUID()) { + $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50)); + \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $userObject->getUID() . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN); + } + $user = $userObject->getUID(); + + if (isset(self::$usersSetup[$user])) { + return; + } + self::$usersSetup[$user] = true; /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 0cda2c8b822..515a795d6e0 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -36,6 +36,8 @@ use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OC\Hooks\PublicEmitter; use OCP\Files\IRootFolder; +use OCP\ILogger; +use OCP\IUserManager; /** * Class Root @@ -57,42 +59,43 @@ use OCP\Files\IRootFolder; * @package OC\Files\Node */ class Root extends Folder implements IRootFolder { - - /** - * @var \OC\Files\Mount\Manager $mountManager - */ + /** @var Manager */ private $mountManager; - - /** - * @var \OC\Hooks\PublicEmitter - */ + /** @var PublicEmitter */ private $emitter; - - /** - * @var \OC\User\User $user - */ + /** @var null|\OC\User\User */ private $user; - + /** @var CappedMemoryCache */ private $userFolderCache; - - /** - * @var IUserMountCache - */ + /** @var IUserMountCache */ private $userMountCache; + /** @var ILogger */ + private $logger; + /** @var IUserManager */ + private $userManager; /** * @param \OC\Files\Mount\Manager $manager * @param \OC\Files\View $view * @param \OC\User\User|null $user * @param IUserMountCache $userMountCache - */ - public function __construct($manager, $view, $user, IUserMountCache $userMountCache) { + * @param ILogger $logger + * @param IUserManager $userManager + */ + public function __construct($manager, + $view, + $user, + IUserMountCache $userMountCache, + ILogger $logger, + IUserManager $userManager) { parent::__construct($this, $view, ''); $this->mountManager = $manager; $this->user = $user; $this->emitter = new PublicEmitter(); $this->userFolderCache = new CappedMemoryCache(); $this->userMountCache = $userMountCache; + $this->logger = $logger; + $this->userManager = $userManager; } /** @@ -345,8 +348,26 @@ class Root extends Folder implements IRootFolder { * * @param String $userId user ID * @return \OCP\Files\Folder + * @throws \OC\User\NoUserException */ public function getUserFolder($userId) { + $userObject = $this->userManager->get($userId); + + if (is_null($userObject)) { + $this->logger->error( + sprintf( + 'Backends provided no user object for %s', + $userId + ), + [ + 'app' => 'files', + ] + ); + throw new \OC\User\NoUserException('Backends provided no user object'); + } + + $userId = $userObject->getUID(); + if (!$this->userFolderCache->hasKey($userId)) { \OC\Files\Filesystem::initMountPoints($userId); diff --git a/lib/private/Server.php b/lib/private/Server.php index dca50c15733..9f993ade7fe 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -182,7 +182,14 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('RootFolder', function (Server $c) { $manager = \OC\Files\Filesystem::getMountManager(null); $view = new View(); - $root = new Root($manager, $view, null, $c->getUserMountCache()); + $root = new Root( + $manager, + $view, + null, + $c->getUserMountCache(), + $this->getLogger(), + $this->getUserManager() + ); $connector = new HookConnector($root, $view); $connector->viewToNode(); return $root; diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 33801cd6347..f6da19f3bb8 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -45,6 +45,8 @@ namespace OC\Share; use OC\Files\Filesystem; use OCA\FederatedFileSharing\DiscoveryManager; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\ILogger; +use OCP\IUserManager; use OCP\IUserSession; use OCP\IDBConnection; use OCP\IConfig; @@ -128,14 +130,39 @@ class Share extends Constants { * Find which users can access a shared item * @param string $path to the file * @param string $ownerUser owner of the file + * @param IUserManager $userManager + * @param ILogger $logger * @param boolean $includeOwner include owner to the list of users with access to the file * @param boolean $returnUserPaths Return an array with the user => path map * @param boolean $recursive take all parent folders into account (default true) * @return array * @note $path needs to be relative to user data dir, e.g. 'file.txt' * not '/admin/data/file.txt' + * @throws \OC\User\NoUserException */ - public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) { + public static function getUsersSharingFile($path, + $ownerUser, + IUserManager $userManager, + ILogger $logger, + $includeOwner = false, + $returnUserPaths = false, + $recursive = true) { + $userObject = $userManager->get($ownerUser); + + if (is_null($userObject)) { + $logger->error( + sprintf( + 'Backends provided no user object for %s', + $ownerUser + ), + [ + 'app' => 'files', + ] + ); + throw new \OC\User\NoUserException('Backends provided no user object'); + } + + $ownerUser = $userObject->getUID(); Filesystem::initMountPoints($ownerUser); $shares = $sharePaths = $fileTargets = array(); diff --git a/lib/public/Share.php b/lib/public/Share.php index bc7aa828f62..ec3a7c8db1b 100644 --- a/lib/public/Share.php +++ b/lib/public/Share.php @@ -89,7 +89,15 @@ class Share extends \OC\Share\Constants { * @since 5.0.0 - $recursive was added in 9.0.0 */ public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) { - return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths, $recursive); + return \OC\Share\Share::getUsersSharingFile( + $path, + $ownerUser, + \OC::$server->getUserManager(), + \OC::$server->getLogger(), + $includeOwner, + $returnUserPaths, + $recursive + ); } /** |