/**
  * @param string $path
  * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
  * @param \OCP\Lock\ILockingProvider $provider
  */
 public function releaseLock($path, $type, ILockingProvider $provider)
 {
     /** @var \OCP\Files\Storage $targetStorage */
     list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
     $targetStorage->releaseLock($targetInternalPath, $type, $provider);
     // unlock the parent folders of the owner when unlocking the share as recipient
     if ($path === '') {
         $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
         $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
     }
 }
Exemple #2
0
 /**
  * Verify the password of a public share
  *
  * @param \OCP\Share\IShare $share
  * @param string $password
  * @return bool
  */
 public function checkPassword(\OCP\Share\IShare $share, $password)
 {
     if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) {
         //TODO maybe exception?
         return false;
     }
     if ($password === null || $share->getPassword() === null) {
         return false;
     }
     $newHash = '';
     if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
         return false;
     }
     if (!empty($newHash)) {
         $share->setPassword($newHash);
         $provider = $this->factory->getProviderForType($share->getShareType());
         $provider->update($share);
     }
     return true;
 }
 /**
  * @inheritdoc
  */
 public function move(\OCP\Share\IShare $share, IUser $recipient)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         // Just update the target
         $qb = $this->dbConn->getQueryBuilder();
         $qb->update('share')->set('file_target', $qb->createNamedParameter($share->getTarget()))->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->execute();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             // Check if there is a usergroup share
             $qb = $this->dbConn->getQueryBuilder();
             $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('parent', $qb->createNamedParameter($share->getId())))->setMaxResults(1)->execute();
             $data = $stmt->fetch();
             $stmt->closeCursor();
             if ($data === false) {
                 // No usergroup share yet. Create one.
                 $qb = $this->dbConn->getQueryBuilder();
                 $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()), 'parent' => $qb->createNamedParameter($share->getId()), 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_target' => $qb->createNamedParameter($share->getTarget()), 'permissions' => $qb->createNamedParameter($share->getPermissions()), 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp())])->execute();
             } else {
                 // Already a usergroup share. Update it.
                 $qb = $this->dbConn->getQueryBuilder();
                 $qb->update('share')->set('file_target', $qb->createNamedParameter($share->getTarget()))->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))->execute();
             }
         }
     }
     return $share;
 }
Exemple #4
0
 /**
  * Get the file id of the root of the storage
  *
  * @return int
  */
 public function getStorageRootId()
 {
     return $this->share->getNodeId();
 }
 /**
  * Validate the permissions of the share
  *
  * @param Share\IShare $share
  * @return bool
  */
 private function validateShare(\OCP\Share\IShare $share)
 {
     return $share->getNode()->isReadable() && $share->getNode()->isShareable();
 }
 /**
  * @dataProvider dataFormatShare
  *
  * @param array $expects
  * @param \OCP\Share\IShare $share
  * @param array $users
  * @param $exception
  */
 public function testFormatShare(array $expects, \OCP\Share\IShare $share, array $users, $exception)
 {
     $this->userManager->method('get')->will($this->returnValueMap($users));
     $this->urlGenerator->method('linkToRouteAbsolute')->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken'])->willReturn('myLink');
     $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf());
     if (!$exception) {
         $this->rootFolder->method('getById')->with($share->getNodeId())->willReturn([$share->getNode()]);
         $this->rootFolder->method('getRelativePath')->with($share->getNode()->getPath())->will($this->returnArgument(0));
     }
     try {
         $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
         $this->assertFalse($exception);
         $this->assertEquals($expects, $result);
     } catch (NotFoundException $e) {
         $this->assertTrue($exception);
     }
 }
 /**
  * Makes sure the user is already properly authenticated when a password is required and none
  * was provided
  *
  * @param IShare $share
  *
  * @throws CheckException
  */
 private function checkSession($share)
 {
     // Not authenticated ?
     if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== (string) $share->getId()) {
         throw new CheckException("Missing password", Http::STATUS_UNAUTHORIZED);
     }
 }
 /**
  * remove share from table
  *
  * @param IShare $share
  */
 public function removeShareFromTable(IShare $share)
 {
     $this->removeShareFromTableById($share->getId());
 }
 /**
  * Unshare a share from the recipient. If this is a group share
  * this means we need a special entry in the share db.
  *
  * @param \OCP\Share\IShare $share
  * @param IUser $recipient
  * @throws BackendError
  * @throws ProviderException
  */
 public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
         /** @var IGroup $group */
         $group = $share->getSharedWith();
         if (!$group->inGroup($recipient)) {
             throw new ProviderException('Recipient not in receiving group');
         }
         // Try to fetch user specific share
         $qb = $this->dbConn->getQueryBuilder();
         $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('parent', $qb->createNamedParameter($share->getId())))->execute();
         $data = $stmt->fetch();
         /*
          * Check if there already is a user specific group share.
          * If there is update it (if required).
          */
         if ($data === false) {
             $qb = $this->dbConn->getQueryBuilder();
             $type = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
             //Insert new share
             $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()), 'parent' => $qb->createNamedParameter($share->getId()), 'item_type' => $qb->createNamedParameter($type), 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_target' => $qb->createNamedParameter($share->getTarget()), 'permissions' => $qb->createNamedParameter(0), 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp())])->execute();
         } else {
             if ($data['permissions'] !== 0) {
                 // Update existing usergroup share
                 $qb = $this->dbConn->getQueryBuilder();
                 $qb->update('share')->set('permissions', $qb->createNamedParameter(0))->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))->execute();
             }
         }
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
             if ($share->getSharedWith() !== $recipient) {
                 throw new ProviderException('Recipient does not match');
             }
             // We can just delete user and link shares
             $this->delete($share);
         } else {
             throw new ProviderException('Invalid shareType');
         }
     }
 }
 /**
  * remove share from table
  *
  * @param IShare $share
  */
 public function removeShareFromTable(IShare $share)
 {
     $qb = $this->dbConnection->getQueryBuilder();
     $qb->delete('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
     $qb->execute();
     $qb->delete('federated_reshares')->where($qb->expr()->eq('share_id', $qb->createNamedParameter($share->getId())));
     $qb->execute();
 }
 /**
  * Creates the environment based on the share the token links to
  *
  * @param IShare $share
  */
 public function setTokenBasedEnv($share)
 {
     $origShareOwnerId = $share->getShareOwner();
     $this->userFolder = $this->rootFolder->getUserFolder($origShareOwnerId);
     $this->sharedNodeId = $share->getNodeId();
     $this->sharedNode = $share->getNode();
     $this->fromRootToFolder = $this->buildFromRootToFolder($this->sharedNodeId);
     $this->folderName = $share->getTarget();
     $this->userId = $origShareOwnerId;
     $this->sharePassword = $share->getPassword();
 }
 /**
  * check if we got the right share
  *
  * @param Share\IShare $share
  * @param string $token
  * @return bool
  */
 protected function verifyShare(Share\IShare $share, $token)
 {
     if ($share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && $share->getToken() === $token) {
         return true;
     }
     return false;
 }
Exemple #13
0
 /**
  * @expectedException \OCP\Share\Exceptions\IllegalIDChangeException
  * @expectedExceptionMessage Not allowed to assign a new provider id to a share
  */
 public function testSetProviderIdOnce()
 {
     $this->share->setProviderId('foo');
     $this->share->setProviderId('bar');
 }
Exemple #14
0
 /**
  * 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 \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(\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($userId)))->setMaxResults(1)->execute();
     $data = $stmt->fetch();
     $stmt->closeCursor();
     if ($data !== false) {
         $share->setPermissions((int) $data['permissions']);
         $share->setTarget($data['file_target']);
     }
     return $share;
 }
Exemple #15
0
 /**
  * @param \OCP\Share\IShare $share
  * @return bool
  */
 protected function canAccessShare(\OCP\Share\IShare $share)
 {
     // A file with permissions 0 can't be accessed by us. So Don't show it
     if ($share->getPermissions() === 0) {
         return false;
     }
     // Owner of the file and the sharer of the file can always get share
     if ($share->getShareOwner() === $this->currentUser->getUID() || $share->getSharedBy() === $this->currentUser->getUID()) {
         return true;
     }
     // If the share is shared with you (or a group you are a member of)
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $this->currentUser->getUID()) {
         return true;
     }
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
         $sharedWith = $this->groupManager->get($share->getSharedWith());
         if ($sharedWith->inGroup($this->currentUser)) {
             return true;
         }
     }
     return false;
 }
 /**
  * Delete a share
  *
  * @param IShare $share
  */
 public function delete(IShare $share)
 {
     $qb = $this->dbConnection->getQueryBuilder();
     $qb->delete('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
     $qb->execute();
     list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
     $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
 }
Exemple #17
0
 /**
  * update fileTarget in the database if the mount point changed
  *
  * @param string $newPath
  * @param \OCP\Share\IShare $share
  * @return bool
  */
 private function updateFileTarget($newPath, &$share)
 {
     $share->setTarget($newPath);
     foreach ($this->groupedShares as $share) {
         $share->setTarget($newPath);
         \OC::$server->getShareManager()->moveShare($share, $this->user);
     }
 }