diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/server.php | 3 | ||||
-rw-r--r-- | lib/private/share20/defaultshareprovider.php | 133 | ||||
-rw-r--r-- | lib/private/share20/manager.php | 118 | ||||
-rw-r--r-- | lib/private/share20/share.php | 9 | ||||
-rw-r--r-- | lib/private/user/manager.php | 4 |
5 files changed, 137 insertions, 130 deletions
diff --git a/lib/private/server.php b/lib/private/server.php index d3dbcba86ba..69406c2203f 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -617,7 +617,8 @@ class Server extends ServerContainer implements IServerContainer { $c->getMountManager(), $c->getGroupManager(), $c->getL10N('core'), - $factory + $factory, + $c->getUserManager() ); return $manager; diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 7b78be2b61d..38d1dae316d 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -29,7 +29,6 @@ use OC\Share20\Exception\BackendError; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\NotFoundException; use OCP\IGroup; -use OCP\IUser; use OCP\IGroupManager; use OCP\IUserManager; use OCP\Files\IRootFolder; @@ -102,14 +101,10 @@ class DefaultShareProvider implements IShareProvider { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { //Set the UID of the user we share with - /** @var IUser $sharedWith */ - $sharedWith = $share->getSharedWith(); - $qb->setValue('share_with', $qb->createNamedParameter($sharedWith->getUID())); + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { //Set the GID of the group we share with - /** @var IGroup $sharedWith */ - $sharedWith = $share->getSharedWith(); - $qb->setValue('share_with', $qb->createNamedParameter($sharedWith->getGID())); + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { //Set the token of the share $qb->setValue('token', $qb->createNamedParameter($share->getToken())); @@ -143,10 +138,10 @@ class DefaultShareProvider implements IShareProvider { $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); // Set who created this share - $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())); + $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); // Set who is the owner of this file/folder (and this the owner of the share) - $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())); + $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); // Set the file target $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); @@ -192,9 +187,9 @@ class DefaultShareProvider implements IShareProvider { $qb = $this->dbConn->getQueryBuilder(); $qb->update('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) - ->set('share_with', $qb->createNamedParameter($share->getSharedWith()->getUID())) - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) + ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) ->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) @@ -203,8 +198,8 @@ class DefaultShareProvider implements IShareProvider { $qb = $this->dbConn->getQueryBuilder(); $qb->update('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) ->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) @@ -216,8 +211,8 @@ class DefaultShareProvider implements IShareProvider { $qb = $this->dbConn->getQueryBuilder(); $qb->update('share') ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) ->execute(); @@ -237,8 +232,8 @@ class DefaultShareProvider implements IShareProvider { $qb->update('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) ->set('share_with', $qb->createNamedParameter($share->getPassword())) - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) ->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) @@ -255,7 +250,7 @@ class DefaultShareProvider implements IShareProvider { * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in * * @param \OCP\Share\IShare $parent - * @return IShare[] + * @return \OCP\Share\IShare[] */ public function getChildren(\OCP\Share\IShare $parent) { $children = []; @@ -311,17 +306,17 @@ class DefaultShareProvider implements IShareProvider { * this means we need a special entry in the share db. * * @param \OCP\Share\IShare $share - * @param IUser $recipient + * @param string $recipient UserId of recipient * @throws BackendError * @throws ProviderException */ - public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) { + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { - /** @var IGroup $group */ - $group = $share->getSharedWith(); + $group = $this->groupManager->get($share->getSharedWith()); + $user = $this->userManager->get($recipient); - if (!$group->inGroup($recipient)) { + if (!$group->inGroup($user)) { throw new ProviderException('Recipient not in receiving group'); } @@ -330,7 +325,7 @@ class DefaultShareProvider implements IShareProvider { $stmt = $qb->select('*') ->from('share') ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient->getUID()))) + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) ->execute(); @@ -349,9 +344,9 @@ class DefaultShareProvider implements IShareProvider { $qb->insert('share') ->values([ 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), - 'share_with' => $qb->createNamedParameter($recipient->getUID()), - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()), - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()), + 'share_with' => $qb->createNamedParameter($recipient), + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), 'parent' => $qb->createNamedParameter($share->getId()), 'item_type' => $qb->createNamedParameter($type), 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), @@ -387,7 +382,7 @@ class DefaultShareProvider implements IShareProvider { /** * @inheritdoc */ - public function move(\OCP\Share\IShare $share, IUser $recipient) { + public function move(\OCP\Share\IShare $share, $recipient) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { // Just update the target $qb = $this->dbConn->getQueryBuilder(); @@ -403,7 +398,7 @@ class DefaultShareProvider implements IShareProvider { $stmt = $qb->select('id') ->from('share') ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient->getUID()))) + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) ->setMaxResults(1) ->execute(); @@ -417,9 +412,9 @@ class DefaultShareProvider implements IShareProvider { $qb->insert('share') ->values([ 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), - 'share_with' => $qb->createNamedParameter($recipient->getUID()), - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()), - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()), + 'share_with' => $qb->createNamedParameter($recipient), + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), 'parent' => $qb->createNamedParameter($share->getId()), 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), @@ -444,7 +439,7 @@ class DefaultShareProvider implements IShareProvider { /** * Get all shares by the given user. Sharetype and path can be used to filter. * - * @param IUser $user + * @param string $userId * @param int $shareType * @param \OCP\Files\File|\OCP\Files\Folder $node * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator @@ -452,7 +447,7 @@ class DefaultShareProvider implements IShareProvider { * @param int $offset * @return Share[] */ - public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset) { + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { $qb = $this->dbConn->getQueryBuilder(); $qb->select('*') ->from('share'); @@ -465,21 +460,21 @@ class DefaultShareProvider implements IShareProvider { if ($reshares === false) { //Special case for old shares created via the web UI $or1 = $qb->expr()->andX( - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())), + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), $qb->expr()->isNull('uid_initiator') ); $qb->andWhere( $qb->expr()->orX( - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID())), + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), $or1 ) ); } else { $qb->andWhere( $qb->expr()->orX( - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())), - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID())) + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) ) ); } @@ -508,7 +503,7 @@ class DefaultShareProvider implements IShareProvider { /** * @inheritdoc */ - public function getShareById($id, $recipient = null) { + public function getShareById($id, $recipientId = null) { $qb = $this->dbConn->getQueryBuilder(); $qb->select('*') @@ -540,8 +535,8 @@ class DefaultShareProvider implements IShareProvider { } // If the recipient is set for a group share resolve to that user - if ($recipient !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { - $share = $this->resolveGroupShare($share, $recipient); + if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { + $share = $this->resolveGroupShare($share, $recipientId); } return $share; @@ -551,7 +546,7 @@ class DefaultShareProvider implements IShareProvider { * Get shares for a given path * * @param \OCP\Files\Node $path - * @return IShare[] + * @return \OCP\Share\IShare[] */ public function getSharesByPath(Node $path) { $qb = $this->dbConn->getQueryBuilder(); @@ -578,7 +573,7 @@ class DefaultShareProvider implements IShareProvider { /** * @inheritdoc */ - public function getSharedWith(IUser $user, $shareType, $node, $limit, $offset) { + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { /** @var Share[] $shares */ $shares = []; @@ -598,7 +593,7 @@ class DefaultShareProvider implements IShareProvider { $qb->setFirstResult($offset); $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID()))); + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); // Filter by node if provided if ($node !== null) { @@ -613,6 +608,7 @@ class DefaultShareProvider implements IShareProvider { $cursor->closeCursor(); } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $user = $this->userManager->get($userId); $allGroups = $this->groupManager->getUserGroups($user); /** @var Share[] $shares2 */ @@ -666,7 +662,7 @@ class DefaultShareProvider implements IShareProvider { * TODO: Optmize this! */ foreach($shares2 as $share) { - $shares[] = $this->resolveGroupShare($share, $user); + $shares[] = $this->resolveGroupShare($share, $userId); } } else { throw new BackendError('Invalid backend'); @@ -680,7 +676,7 @@ class DefaultShareProvider implements IShareProvider { * Get a share by token * * @param string $token - * @return IShare + * @return \OCP\Share\IShare * @throws ShareNotFound */ public function getShareByToken($token) { @@ -727,17 +723,9 @@ class DefaultShareProvider implements IShareProvider { $share->setShareTime($shareTime); if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { - $sharedWith = $this->userManager->get($data['share_with']); - if ($sharedWith === null) { - throw new InvalidShare(); - } - $share->setSharedWith($sharedWith); + $share->setSharedWith($data['share_with']); } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { - $sharedWith = $this->groupManager->get($data['share_with']); - if ($sharedWith === null) { - throw new InvalidShare(); - } - $share->setSharedWith($sharedWith); + $share->setSharedWith($data['share_with']); } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { $share->setPassword($data['share_with']); $share->setToken($data['token']); @@ -745,24 +733,15 @@ class DefaultShareProvider implements IShareProvider { if ($data['uid_initiator'] === null) { //OLD SHARE - $sharedBy = $this->userManager->get($data['uid_owner']); - if ($sharedBy === null) { - throw new InvalidShare(); - } - $share->setSharedBy($sharedBy); + $share->setSharedBy($data['uid_owner']); $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); $owner = $path->getOwner(); - $share->setShareOwner($owner); + $share->setShareOwner($owner->getUID()); } else { //New share! - $sharedBy = $this->userManager->get($data['uid_initiator']); - $shareOwner = $this->userManager->get($data['uid_owner']); - if ($sharedBy === null || $shareOwner === null) { - throw new InvalidShare(); - } - $share->setSharedBy($sharedBy); - $share->setShareOwner($shareOwner); + $share->setSharedBy($data['uid_initiator']); + $share->setShareOwner($data['uid_owner']); } $path = $this->getNode($share->getShareOwner(), (int)$data['file_source']); @@ -781,14 +760,14 @@ class DefaultShareProvider implements IShareProvider { /** * Get the node with file $id for $user * - * @param IUser $user + * @param string $user The userId * @param int $id * @return \OCP\Files\File|\OCP\Files\Folder * @throws InvalidShare */ - private function getNode(IUser $user, $id) { + private function getNode($user, $id) { try { - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); + $userFolder = $this->rootFolder->getUserFolder($user); } catch (NotFoundException $e) { throw new InvalidShare(); } @@ -806,18 +785,18 @@ class DefaultShareProvider implements IShareProvider { * Resolve a group share to a user specific share * Thus if the user moved their group share make sure this is properly reflected here. * - * @param Share $share - * @param IUser $user + * @param \OCP\Share\IShare $share + * @param string $userId * @return Share Returns the updated share if one was found else return the original share. */ - private function resolveGroupShare(Share $share, IUser $user) { + private function resolveGroupShare(\OCP\Share\IShare $share, $userId) { $qb = $this->dbConn->getQueryBuilder(); $stmt = $qb->select('*') ->from('share') ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID()))) + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) ->setMaxResults(1) ->execute(); diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index 520b5a53762..db42f76d7a2 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -21,7 +21,7 @@ namespace OC\Share20; -use OCP\Files\Node; +use OCP\IUserManager; use OCP\Share\IManager; use OCP\Share\IProviderFactory; use OC\Share20\Exception\BackendError; @@ -34,7 +34,6 @@ use OCP\Files\Mount\IMountManager; use OCP\IGroupManager; use OCP\Files\File; use OCP\Files\Folder; -use OCP\IUser; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\GenericShareException; @@ -68,6 +67,9 @@ class Manager implements IManager { /** @var IL10N */ private $l; + /** @var IUserManager */ + private $userManager; + /** * Manager constructor. * @@ -79,6 +81,7 @@ class Manager implements IManager { * @param IGroupManager $groupManager * @param IL10N $l * @param IProviderFactory $factory + * @param IUserManager $userManager */ public function __construct( ILogger $logger, @@ -88,7 +91,8 @@ class Manager implements IManager { IMountManager $mountManager, IGroupManager $groupManager, IL10N $l, - IProviderFactory $factory + IProviderFactory $factory, + IUserManager $userManager ) { $this->logger = $logger; $this->config = $config; @@ -98,6 +102,7 @@ class Manager implements IManager { $this->groupManager = $groupManager; $this->l = $l; $this->factory = $factory; + $this->userManager = $userManager; } /** @@ -150,13 +155,13 @@ class Manager implements IManager { protected function generalCreateChecks(\OCP\Share\IShare $share) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { // We expect a valid user as sharedWith for user shares - if (!($share->getSharedWith() instanceof \OCP\IUser)) { - throw new \InvalidArgumentException('SharedWith should be an IUser'); + if (!$this->userManager->userExists($share->getSharedWith())) { + throw new \InvalidArgumentException('SharedWith is not a valid user'); } } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { // We expect a valid group as sharedWith for group shares - if (!($share->getSharedWith() instanceof \OCP\IGroup)) { - throw new \InvalidArgumentException('SharedWith should be an IGroup'); + if (!$this->groupManager->groupExists($share->getSharedWith())) { + throw new \InvalidArgumentException('SharedWith is not a valid group'); } } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { if ($share->getSharedWith() !== null) { @@ -173,7 +178,8 @@ class Manager implements IManager { } // Cannot share with yourself - if ($share->getSharedWith() === $share->getSharedBy()) { + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && + $share->getSharedWith() === $share->getSharedBy()) { throw new \InvalidArgumentException('Can\'t share with yourself'); } @@ -215,7 +221,7 @@ class Manager implements IManager { * Validate if the expiration date fits the system settings * * @param \OCP\Share\IShare $share The share to validate the expiration date of - * @return \DateTime|null The expiration date or null if $expireDate was null and it is not required + * @return \OCP\Share\IShare The expiration date or null if $expireDate was null and it is not required * @throws GenericShareException * @throws \InvalidArgumentException * @throws \Exception @@ -285,10 +291,12 @@ class Manager implements IManager { protected function userCreateChecks(\OCP\Share\IShare $share) { // Check if we can share with group members only if ($this->shareWithGroupMembersOnly()) { + $sharedBy = $this->userManager->get($share->getSharedBy()); + $sharedWith = $this->userManager->get($share->getSharedWith()); // Verify we can share with this user $groups = array_intersect( - $this->groupManager->getUserGroupIds($share->getSharedBy()), - $this->groupManager->getUserGroupIds($share->getSharedWith()) + $this->groupManager->getUserGroupIds($sharedBy), + $this->groupManager->getUserGroupIds($sharedWith) ); if (empty($groups)) { throw new \Exception('Only sharing with group members is allowed'); @@ -314,10 +322,13 @@ class Manager implements IManager { } // The share is already shared with this user via a group share - if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && - $existingShare->getSharedWith()->inGroup($share->getSharedWith()) && - $existingShare->getShareOwner() !== $share->getShareOwner()) { - throw new \Exception('Path already shared with this user'); + if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { + $group = $this->groupManager->get($existingShare->getSharedWith()); + $user = $this->userManager->get($share->getSharedWith()); + + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { + throw new \Exception('Path already shared with this user'); + } } } } @@ -331,7 +342,9 @@ class Manager implements IManager { protected function groupCreateChecks(\OCP\Share\IShare $share) { // Verify if the user can share with this group if ($this->shareWithGroupMembersOnly()) { - if (!$share->getSharedWith()->inGroup($share->getSharedBy())) { + $sharedBy = $this->userManager->get($share->getSharedBy()); + $sharedWith = $this->groupManager->get($share->getSharedWith()); + if (!$sharedWith->inGroup($sharedBy)) { throw new \Exception('Only sharing within your own groups is allowed'); } } @@ -468,10 +481,11 @@ class Manager implements IManager { $this->pathCreateChecks($share->getNode()); // On creation of a share the owner is always the owner of the path - $share->setShareOwner($share->getNode()->getOwner()); + $share->setShareOwner($share->getNode()->getOwner()->getUID()); // Cannot share with the owner - if ($share->getSharedWith() === $share->getShareOwner()) { + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && + $share->getSharedWith() === $share->getShareOwner()) { throw new \InvalidArgumentException('Can\'t share with the share owner'); } @@ -480,16 +494,6 @@ class Manager implements IManager { $target = \OC\Files\Filesystem::normalizePath($target); $share->setTarget($target); - //Get sharewith for hooks - $sharedWith = null; - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { - $sharedWith = $share->getSharedWith()->getUID(); - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { - $sharedWith = $share->getSharedWith()->getGID(); - } else { - $sharedWith = $share->getSharedWith(); - } - // Pre share hook $run = true; $error = ''; @@ -497,13 +501,13 @@ class Manager implements IManager { 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemSource' => $share->getNode()->getId(), 'shareType' => $share->getShareType(), - 'uidOwner' => $share->getSharedBy()->getUID(), + 'uidOwner' => $share->getSharedBy(), 'permissions' => $share->getPermissions(), 'fileSource' => $share->getNode()->getId(), 'expiration' => $share->getExpirationDate(), 'token' => $share->getToken(), 'itemTarget' => $share->getTarget(), - 'shareWith' => $sharedWith, + 'shareWith' => $share->getSharedWith(), 'run' => &$run, 'error' => &$error, ]; @@ -521,13 +525,13 @@ class Manager implements IManager { 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemSource' => $share->getNode()->getId(), 'shareType' => $share->getShareType(), - 'uidOwner' => $share->getSharedBy()->getUID(), + 'uidOwner' => $share->getSharedBy(), 'permissions' => $share->getPermissions(), 'fileSource' => $share->getNode()->getId(), 'expiration' => $share->getExpirationDate(), 'token' => $share->getToken(), 'id' => $share->getId(), - 'shareWith' => $sharedWith, + 'shareWith' => $share->getSharedWith(), 'itemTarget' => $share->getTarget(), 'fileTarget' => $share->getTarget(), ]; @@ -542,6 +546,7 @@ class Manager implements IManager { * * @param \OCP\Share\IShare $share * @return \OCP\Share\IShare The share object + * @throws \InvalidArgumentException */ public function updateShare(\OCP\Share\IShare $share) { $expirationDateUpdated = false; @@ -564,7 +569,8 @@ class Manager implements IManager { } // Cannot share with the owner - if ($share->getSharedWith() === $share->getShareOwner()) { + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && + $share->getSharedWith() === $share->getShareOwner()) { throw new \InvalidArgumentException('Can\'t share with the share owner'); } @@ -606,7 +612,7 @@ class Manager implements IManager { 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemSource' => $share->getNode()->getId(), 'date' => $share->getExpirationDate(), - 'uidOwner' => $share->getSharedBy()->getUID(), + 'uidOwner' => $share->getSharedBy(), ]); } @@ -651,9 +657,9 @@ class Manager implements IManager { $shareType = $share->getShareType(); $sharedWith = ''; if ($shareType === \OCP\Share::SHARE_TYPE_USER) { - $sharedWith = $share->getSharedWith()->getUID(); + $sharedWith = $share->getSharedWith(); } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { - $sharedWith = $share->getSharedWith()->getGID(); + $sharedWith = $share->getSharedWith(); } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { $sharedWith = $share->getSharedWith(); } @@ -665,7 +671,7 @@ class Manager implements IManager { 'shareType' => $shareType, 'shareWith' => $sharedWith, 'itemparent' => $share->getParent(), - 'uidOwner' => $share->getSharedBy()->getUID(), + 'uidOwner' => $share->getSharedBy(), 'fileSource' => $share->getNode()->getId(), 'fileTarget' => $share->getTarget() ]; @@ -706,38 +712,45 @@ class Manager implements IManager { * handle this. * * @param \OCP\Share\IShare $share - * @param IUser $recipient + * @param string $recipientId */ - public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) { - list($providerId, $id) = $this->splitFullId($share->getId()); + public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { + list($providerId, ) = $this->splitFullId($share->getId()); $provider = $this->factory->getProvider($providerId); - $provider->deleteFromSelf($share, $recipient); + $provider->deleteFromSelf($share, $recipientId); } /** * @inheritdoc */ - public function moveShare(\OCP\Share\IShare $share, IUser $recipient) { + public function moveShare(\OCP\Share\IShare $share, $recipientId) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { throw new \InvalidArgumentException('Can\'t change target of link share'); } - if (($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipient) || - ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && !$share->getSharedWith()->inGroup($recipient))) { + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { throw new \InvalidArgumentException('Invalid recipient'); } + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { + $sharedWith = $this->groupManager->get($share->getSharedWith()); + $recipient = $this->userManager->get($recipientId); + if (!$sharedWith->inGroup($recipient)) { + throw new \InvalidArgumentException('Invalid recipient'); + } + } + list($providerId, ) = $this->splitFullId($share->getId()); $provider = $this->factory->getProvider($providerId); - $provider->move($share, $recipient); + $provider->move($share, $recipientId); } /** * Get shares shared by (initiated) by the provided user. * - * @param IUser $user + * @param string $userId * @param int $shareType * @param \OCP\Files\File|\OCP\Files\Folder $path * @param bool $reshares @@ -745,7 +758,7 @@ class Manager implements IManager { * @param int $offset * @return \OCP\Share\IShare[] */ - public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { if ($path !== null && !($path instanceof \OCP\Files\File) && !($path instanceof \OCP\Files\Folder)) { @@ -754,16 +767,16 @@ class Manager implements IManager { $provider = $this->factory->getProviderForType($shareType); - return $provider->getSharesBy($user, $shareType, $path, $reshares, $limit, $offset); + return $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); } /** * @inheritdoc */ - public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0) { + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { $provider = $this->factory->getProviderForType($shareType); - return $provider->getSharedWith($user, $shareType, $node, $limit, $offset); + return $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); } /** @@ -955,10 +968,10 @@ class Manager implements IManager { * * TODO: Deprecate fuction from OC_Util * - * @param IUser $user + * @param string $userId * @return bool */ - public function sharingDisabledForUser(IUser $user) { + public function sharingDisabledForUser($userId) { if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); $excludedGroups = json_decode($groupsList); @@ -967,6 +980,7 @@ class Manager implements IManager { $newValue = json_encode($excludedGroups); $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); } + $user = $this->userManager->get($userId); $usersGroups = $this->groupManager->getUserGroupIds($user); if (!empty($usersGroups)) { $remainingGroups = array_diff($usersGroups, $excludedGroups); diff --git a/lib/private/share20/share.php b/lib/private/share20/share.php index f9cba10a07a..db91ad4a91d 100644 --- a/lib/private/share20/share.php +++ b/lib/private/share20/share.php @@ -121,6 +121,9 @@ class Share implements \OCP\Share\IShare { * @inheritdoc */ public function setSharedWith($sharedWith) { + if (!is_string($sharedWith)) { + throw new \InvalidArgumentException(); + } $this->sharedWith = $sharedWith; return $this; } @@ -170,6 +173,9 @@ class Share implements \OCP\Share\IShare { * @inheritdoc */ public function setSharedBy($sharedBy) { + if (!is_string($sharedBy)) { + throw new \InvalidArgumentException(); + } //TODO checks $this->sharedBy = $sharedBy; @@ -188,6 +194,9 @@ class Share implements \OCP\Share\IShare { * @inheritdoc */ public function setShareOwner($shareOwner) { + if (!is_string($shareOwner)) { + throw new \InvalidArgumentException(); + } //TODO checks $this->shareOwner = $shareOwner; diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 86750dcd994..6798a7340c3 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -265,6 +265,10 @@ class Manager extends PublicEmitter implements IUserManager { if (trim($uid) == '') { throw new \Exception($l->t('A valid username must be provided')); } + // No whitespace at the beginning or at the end + if (strlen(trim($uid, "\t\n\r\0\x0B\xe2\x80\x8b")) !== strlen(trim($uid))) { + throw new \Exception($l->t('Username contains whitespace at the beginning or at the end')); + } // No empty password if (trim($password) == '') { throw new \Exception($l->t('A valid password must be provided')); |