From 1b66db72d916a763b1c22613b9df5c42e93593a8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 30 May 2016 14:56:19 +0200 Subject: Repair job to fix permissions for avatars Fixes #22978 On some older installations the permissions for the userRoot and the avatars are not correct. This breaks since we now use the Node API in the avatar code. This repair job makes sure that the permissions are set correctly. * Unit tests added --- lib/private/Repair.php | 2 + lib/private/Repair/AvatarPermissions.php | 107 +++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 lib/private/Repair/AvatarPermissions.php (limited to 'lib') diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 710bbbbaedf..bb2967d7e6e 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -29,6 +29,7 @@ namespace OC; use OC\Repair\AssetCache; +use OC\Repair\AvatarPermissions; use OC\Repair\CleanTags; use OC\Repair\Collation; use OC\Repair\DropOldJobs; @@ -134,6 +135,7 @@ class Repair implements IOutput{ new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new SharePropagation(\OC::$server->getConfig()), new RemoveOldShares(\OC::$server->getDatabaseConnection()), + new AvatarPermissions(\OC::$server->getDatabaseConnection()), ]; } diff --git a/lib/private/Repair/AvatarPermissions.php b/lib/private/Repair/AvatarPermissions.php new file mode 100644 index 00000000000..1d96a79ac1f --- /dev/null +++ b/lib/private/Repair/AvatarPermissions.php @@ -0,0 +1,107 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ +namespace OC\Repair; + +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +/** + * Class AvatarPermissions + * + * @package OC\Repair + */ +class AvatarPermissions implements IRepairStep { + /** @var IDBConnection */ + private $connection; + + /** + * AvatarPermissions constructor. + * + * @param IDBConnection $connection + */ + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + /** + * @return string + */ + public function getName() { + return 'Fix permissions so avatars can be stored again'; + } + + /** + * @param IOutput $output + */ + public function run(IOutput $output) { + $output->startProgress(2); + $this->fixUserRootPermissions(); + $output->advance(); + $this->fixAvatarPermissions(); + $output->finishProgress(); + } + + /** + * Make sure all user roots have permissions 23 (all but share) + */ + protected function fixUserRootPermissions() { + $qb = $this->connection->getQueryBuilder(); + $qb2 = $this->connection->getQueryBuilder(); + + $qb->select('numeric_id') + ->from('storages') + ->where($qb->expr()->like('id', $qb2->createParameter('like'))); + + $qb2->update('filecache') + ->set('permissions', $qb2->createNamedParameter(23)) + ->where($qb2->expr()->eq('path', $qb2->createNamedParameter(''))) + ->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL()))) + ->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(23))) + ->setParameter('like', 'home::%'); + + + $qb2->execute(); + } + + /** + * Make sure all avatar files in the user roots have permission 27 + */ + protected function fixAvatarPermissions() { + $qb = $this->connection->getQueryBuilder(); + $qb2 = $this->connection->getQueryBuilder(); + + $qb->select('numeric_id') + ->from('storages') + ->where($qb->expr()->like('id', $qb2->createParameter('like'))); + + $qb2->update('filecache') + ->set('permissions', $qb2->createNamedParameter(27)) + ->where($qb2->expr()->like('path', $qb2->createNamedParameter('avatar.%'))) + ->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL()))) + ->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(27))) + ->setParameter('like', 'home::%'); + + $qb2->execute(); + } + +} + -- cgit v1.2.3 From 28d9ad2817b744bcef35a9259f65eb56b0b2ae78 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 3 Jun 2016 14:43:31 +0200 Subject: Empty string is null on oracle --- lib/private/Repair/AvatarPermissions.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/Repair/AvatarPermissions.php b/lib/private/Repair/AvatarPermissions.php index 1d96a79ac1f..d23479f5ba8 100644 --- a/lib/private/Repair/AvatarPermissions.php +++ b/lib/private/Repair/AvatarPermissions.php @@ -20,6 +20,7 @@ */ namespace OC\Repair; +use Doctrine\DBAL\Platforms\OraclePlatform; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -71,9 +72,16 @@ class AvatarPermissions implements IRepairStep { ->from('storages') ->where($qb->expr()->like('id', $qb2->createParameter('like'))); + if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { + // '' is null on oracle + $path = $qb2->expr()->isNull('path'); + } else { + $path = $qb2->expr()->eq('path', $qb2->createNamedParameter('')); + } + $qb2->update('filecache') ->set('permissions', $qb2->createNamedParameter(23)) - ->where($qb2->expr()->eq('path', $qb2->createNamedParameter(''))) + ->where($path) ->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL()))) ->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(23))) ->setParameter('like', 'home::%'); -- cgit v1.2.3