/** * create a new share * * @param array $params * @return \OC_OCS_Result */ public function createShare($params) { if (!$this->isS2SEnabled(true)) { return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing'); } $remote = isset($_POST['remote']) ? $_POST['remote'] : null; $token = isset($_POST['token']) ? $_POST['token'] : null; $name = isset($_POST['name']) ? $_POST['name'] : null; $owner = isset($_POST['owner']) ? $_POST['owner'] : null; $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null; if ($remote && $token && $name && $owner && $remoteId && $shareWith) { if (!\OCP\Util::isValidFileName($name)) { return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.'); } // FIXME this should be a method in the user management instead \OCP\Util::writeLog('files_sharing', 'shareWith before, ' . $shareWith, \OCP\Util::DEBUG); \OCP\Util::emitHook('\\OCA\\Files_Sharing\\API\\Server2Server', 'preLoginNameUsedAsUserName', array('uid' => &$shareWith)); \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG); if (!\OCP\User::userExists($shareWith)) { return new \OC_OCS_Result(null, 400, 'User does not exists'); } \OC_Util::setupFS($shareWith); $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), $shareWith); try { $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); $user = $owner . '@' . $this->cleanupRemote($remote); \OC::$server->getActivityManager()->publishActivity(Activity::FILES_SHARING_APP, Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user, trim($name, '/')), '', array(), '', '', $shareWith, Activity::TYPE_REMOTE_SHARE, Activity::PRIORITY_LOW); /** * FIXME $urlGenerator = \OC::$server->getURLGenerator(); $notificationManager = \OC::$server->getNotificationManager(); $notification = $notificationManager->createNotification(); $notification->setApp('files_sharing') ->setUser($shareWith) ->setTimestamp(time()) ->setObject('remote_share', $remoteId) ->setSubject('remote_share', [$user, trim($name, '/')]); $declineAction = $notification->createAction(); $declineAction->setLabel('decline') ->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'DELETE'); $notification->addAction($declineAction); $acceptAction = $notification->createAction(); $acceptAction->setLabel('accept') ->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'POST'); $notification->addAction($acceptAction); $notificationManager->notify($notification); */ return new \OC_OCS_Result(); } catch (\Exception $e) { \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote); } } return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter'); }
public function __construct(array $urlParams = array()) { parent::__construct('files_sharing', $urlParams); $container = $this->getContainer(); $server = $container->getServer(); /** * Controllers */ $container->registerService('ShareController', function (SimpleContainer $c) use($server) { return new ShareController($c->query('AppName'), $c->query('Request'), $c->query('UserSession'), $server->getAppConfig(), $server->getConfig(), $c->query('URLGenerator'), $c->query('UserManager'), $server->getLogger(), $server->getActivityManager()); }); $container->registerService('ExternalSharesController', function (SimpleContainer $c) { return new ExternalSharesController($c->query('AppName'), $c->query('Request'), $c->query('IsIncomingShareEnabled'), $c->query('ExternalManager'), $c->query('HttpClientService')); }); /** * Core class wrappers */ $container->registerService('UserSession', function (SimpleContainer $c) use($server) { return $server->getUserSession(); }); $container->registerService('URLGenerator', function (SimpleContainer $c) use($server) { return $server->getUrlGenerator(); }); $container->registerService('UserManager', function (SimpleContainer $c) use($server) { return $server->getUserManager(); }); $container->registerService('HttpClientService', function (SimpleContainer $c) use($server) { return $server->getHTTPClientService(); }); $container->registerService('IsIncomingShareEnabled', function (SimpleContainer $c) { return Helper::isIncomingServer2serverShareEnabled(); }); $container->registerService('ExternalManager', function (SimpleContainer $c) use($server) { $user = $server->getUserSession()->getUser(); $uid = $user ? $user->getUID() : null; return new \OCA\Files_Sharing\External\Manager($server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), $server->getHTTPHelper(), $server->getNotificationManager(), $uid); }); /** * Middleware */ $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use($server) { return new SharingCheckMiddleware($c->query('AppName'), $server->getConfig(), $server->getAppManager()); }); // Execute middlewares $container->registerMiddleware('SharingCheckMiddleware'); $container->registerService('MountProvider', function (IContainer $c) { /** @var \OCP\IServerContainer $server */ $server = $c->query('ServerContainer'); return new MountProvider($server->getConfig(), $c->query('PropagationManager')); }); $container->registerService('PropagationManager', function (IContainer $c) { /** @var \OCP\IServerContainer $server */ $server = $c->query('ServerContainer'); return new PropagationManager($server->getUserSession(), $server->getConfig()); }); /* * Register capabilities */ $container->registerCapability('OCA\\Files_Sharing\\Capabilities'); }
/** * create a new share * * @param array $params * @return \OC_OCS_Result */ public function createShare($params) { if (!$this->isS2SEnabled(true)) { return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing'); } $remote = isset($_POST['remote']) ? $_POST['remote'] : null; $token = isset($_POST['token']) ? $_POST['token'] : null; $name = isset($_POST['name']) ? $_POST['name'] : null; $owner = isset($_POST['owner']) ? $_POST['owner'] : null; $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null; if ($remote && $token && $name && $owner && $remoteId && $shareWith) { if (!\OCP\Util::isValidFileName($name)) { return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.'); } if (!\OCP\User::userExists($shareWith)) { return new \OC_OCS_Result(null, 400, 'User does not exists'); } \OC_Util::setupFS($shareWith); $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), $shareWith); try { $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); $user = $owner . '@' . $this->cleanupRemote($remote); \OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user), '', array(), '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW); return new \OC_OCS_Result(); } catch (\Exception $e) { \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote); } } return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter'); }
public static function determineIcon($file) { if ($file['type'] === 'dir') { $dir = $file['directory']; $absPath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir . '/' . $file['name']); $mount = \OC\Files\Filesystem::getMountManager()->find($absPath); if (!is_null($mount)) { $sid = $mount->getStorageId(); if (!is_null($sid)) { $sid = explode(':', $sid); if ($sid[0] === 'shared') { return \OC_Helper::mimetypeIcon('dir-shared'); } if ($sid[0] !== 'local' and $sid[0] !== 'home') { return \OC_Helper::mimetypeIcon('dir-external'); } } } return \OC_Helper::mimetypeIcon('dir'); } if ($file['isPreviewAvailable']) { $pathForPreview = $file['directory'] . '/' . $file['name']; return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag']; } return \OC_Helper::mimetypeIcon($file['mimetype']); }
/** * Decline a remote share * * @param array $params contains the shareID 'id' which should be declined * @return \OC_OCS_Result */ public static function declineShare($params) { $externalManager = new Manager(\OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC_User::getUser()); if ($externalManager->declineShare($params['id'])) { return new \OC_OCS_Result(); } return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); }
public function setUp() { parent::setUp(); $this->userId = $this->getUniqueID(); $this->createUser($this->userId, 'pass'); $this->registerMount($this->userId, new Temporary(), '/' . $this->userId . '/files/'); \OC_Util::setupFS($this->userId); $this->view = new View(); $this->root = new Root(Filesystem::getMountManager(), $this->view, \OC::$server->getUserManager()->get($this->userId)); }
/** * @return Update */ private static function getUpdate() { if (is_null(self::$updater)) { $user = \OC::$server->getUserSession()->getUser(); $uid = ''; if ($user) { $uid = $user->getUID(); } self::$updater = new Update(new View(), new Util(new View(), \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getConfig()), Filesystem::getMountManager(), \OC::$server->getEncryptionManager(), \OC::$server->getEncryptionFilesHelper(), $uid); } return self::$updater; }
/** * get all storages for $dir * * @param string $dir * @return \OC\Files\Mount\MountPoint[] */ protected function getMounts($dir) { //TODO: move to the node based fileapi once that's done \OC_Util::tearDownFS(); \OC_Util::setupFS($this->user); $mountManager = Filesystem::getMountManager(); $mounts = $mountManager->findIn($dir); $mounts[] = $mountManager->find($dir); $mounts = array_reverse($mounts); //start with the mount of $dir return $mounts; }
public function __construct(array $urlParams = array()) { parent::__construct('files_sharing', $urlParams); $container = $this->getContainer(); $server = $container->getServer(); /** * Controllers */ $container->registerService('ShareController', function (SimpleContainer $c) use($server) { $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); return new ShareController($c->query('AppName'), $c->query('Request'), $server->getConfig(), $server->getURLGenerator(), $server->getUserManager(), $server->getLogger(), $server->getActivityManager(), $server->getShareManager(), $server->getSession(), $server->getPreviewManager(), $server->getRootFolder(), $federatedSharingApp->getFederatedShareProvider()); }); $container->registerService('ExternalSharesController', function (SimpleContainer $c) { return new ExternalSharesController($c->query('AppName'), $c->query('Request'), $c->query('ExternalManager'), $c->query('HttpClientService')); }); /** * Core class wrappers */ $container->registerService('HttpClientService', function (SimpleContainer $c) use($server) { return $server->getHTTPClientService(); }); $container->registerService('ExternalManager', function (SimpleContainer $c) use($server) { $user = $server->getUserSession()->getUser(); $uid = $user ? $user->getUID() : null; $discoveryManager = new DiscoveryManager(\OC::$server->getMemCacheFactory(), \OC::$server->getHTTPClientService()); return new \OCA\Files_Sharing\External\Manager($server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), $server->getHTTPHelper(), $server->getNotificationManager(), $discoveryManager, $uid); }); /** * Middleware */ $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use($server) { return new SharingCheckMiddleware($c->query('AppName'), $server->getConfig(), $server->getAppManager(), $c['ControllerMethodReflector']); }); // Execute middlewares $container->registerMiddleware('SharingCheckMiddleware'); $container->registerService('MountProvider', function (IContainer $c) { /** @var \OCP\IServerContainer $server */ $server = $c->query('ServerContainer'); return new MountProvider($server->getConfig(), $server->getShareManager(), $server->getLogger()); }); $container->registerService('ExternalMountProvider', function (IContainer $c) { /** @var \OCP\IServerContainer $server */ $server = $c->query('ServerContainer'); return new \OCA\Files_Sharing\External\MountProvider($server->getDatabaseConnection(), function () use($c) { return $c->query('ExternalManager'); }); }); /* * Register capabilities */ $container->registerCapability('OCA\\Files_Sharing\\Capabilities'); }
/** * unshare shared items below the deleted folder * * @param string $path */ private function unshareChildren($path) { $view = new \OC\Files\View('/'); // find share mount points within $path and unmount them $mountManager = \OC\Files\Filesystem::getMountManager(); $mountedShares = $mountManager->findIn($path); foreach ($mountedShares as $mount) { if ($mount->getStorage()->instanceOfStorage('OCA\\Files_Sharing\\ISharedStorage')) { $mountPoint = $mount->getMountPoint(); $view->unlink($mountPoint); } } }
/** * rename mount point from the children if the parent was renamed * * @param string $oldPath old path relative to data/user/files * @param string $newPath new path relative to data/user/files */ private static function renameChildren($oldPath, $newPath) { $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); $mountManager = \OC\Files\Filesystem::getMountManager(); $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); foreach ($mountedShares as $mount) { if ($mount->getStorage()->instanceOfStorage('OCA\\Files_Sharing\\ISharedStorage')) { $mountPoint = $mount->getMountPoint(); $target = str_replace($absOldPath, $absNewPath, $mountPoint); $mount->moveMount($target); } } }
protected function setUp() { parent::setUp(); $manager = \OC\Files\Filesystem::getMountManager(); \OC_Hook::clear('OC_Filesystem'); $user = new User($this->getUniqueID('user'), new \Test\Util\User\Dummy()); $this->loginAsUser($user->getUID()); $this->view = new View(); $this->root = new Root($manager, $this->view, $user); $storage = new Temporary(array()); $subStorage = new Temporary(array()); $this->storages[] = $storage; $this->storages[] = $subStorage; $this->root->mount($storage, '/'); $this->root->mount($subStorage, '/substorage/'); }
/** * Wraps the given storage when it is not a shared storage * * @param string $mountPoint * @param Storage $storage * @param IMountPoint $mount * @return Encryption|Storage */ public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) { $parameters = ['storage' => $storage, 'mountPoint' => $mountPoint, 'mount' => $mount]; if (!$storage->instanceOfStorage('OC\\Files\\Storage\\Shared') && !$storage->instanceOfStorage('OCA\\Files_Sharing\\External\\Storage') && !$storage->instanceOfStorage('OC\\Files\\Storage\\OwnCloud')) { $user = \OC::$server->getUserSession()->getUser(); $mountManager = Filesystem::getMountManager(); $uid = $user ? $user->getUID() : null; $fileHelper = \OC::$server->getEncryptionFilesHelper(); $keyStorage = \OC::$server->getEncryptionKeyStorage(); $util = new Util(new View(), \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getConfig()); $update = new Update(new View(), $util, Filesystem::getMountManager(), $this->manager, $fileHelper, $uid); return new Encryption($parameters, $this->manager, $util, $this->logger, $fileHelper, $uid, $keyStorage, $update, $mountManager, $this->arrayCache); } else { return $storage; } }
public function testReuseExistingFile() { $storage = new Temporary(array()); $mount = new MountPoint($storage, ''); Filesystem::getMountManager()->addMount($mount); $cache = $storage->getCache(); $storage->mkdir('folder'); $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->addMount($mount); $scanner->scan(''); $this->assertTrue($cache->inCache('folder/bar.txt')); $old = $cache->get('folder/bar.txt'); $scanner->scan(''); $new = $cache->get('folder/bar.txt'); $this->assertEquals($old, $new); }
/** * Tests that the home storage is not wrapped when no quota exists. */ function testHomeStorageWrapperWithQuota() { $user1 = $this->getUniqueID(); \OC_User::createUser($user1, 'test'); \OC::$server->getConfig()->setUserValue($user1, 'files', 'quota', '1024'); \OC_User::setUserId($user1); \OC_Util::setupFS($user1); $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/'); $this->assertNotNull($userMount); $this->assertTrue($userMount->getStorage()->instanceOfStorage('\\OC\\Files\\Storage\\Wrapper\\Quota')); // ensure that root wasn't wrapped $rootMount = \OC\Files\Filesystem::getMountManager()->find('/'); $this->assertNotNull($rootMount); $this->assertNotInstanceOf('\\OC\\Files\\Storage\\Wrapper\\Quota', $rootMount->getStorage()); // clean up \OC_User::setUserId(''); \OC_User::deleteUser($user1); \OC::$server->getConfig()->deleteAllUserValues($user1); \OC_Util::tearDownFS(); }
protected function setUp() { parent::setUp(); $manager = \OC\Files\Filesystem::getMountManager(); \OC_Hook::clear('OC_Filesystem'); \OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Updater', 'writeHook'); \OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Updater', 'deleteHook'); \OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Updater', 'renameHook'); \OC_Hook::connect('OC_Filesystem', 'post_touch', '\\OC\\Files\\Cache\\Updater', 'touchHook'); $user = new User($this->getUniqueID('user'), new \OC_User_Dummy()); $this->loginAsUser($user->getUID()); $this->view = new View(); $this->root = new Root($manager, $this->view, $user); $storage = new Temporary(array()); $subStorage = new Temporary(array()); $this->storages[] = $storage; $this->storages[] = $subStorage; $this->root->mount($storage, '/'); $this->root->mount($subStorage, '/substorage/'); }
public function testChangePropagator() { /** * @var \OC\Files\Cache\ChangePropagator $propagator */ $propagator = $this->getMock('\\OC\\Files\\Cache\\ChangePropagator', array('propagateChanges'), array(), '', false); $storage = new Temporary(array()); $mount = new Mount($storage, '/foo'); Filesystem::getMountManager()->addMount($mount); $cache = $storage->getCache(); $storage->mkdir('folder'); $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $scanner = new TestScanner('', \OC::$server->getDatabaseConnection()); $originalPropagator = $scanner->getPropagator(); $scanner->setPropagator($propagator); $scanner->addMount($mount); $scanner->scan(''); $changes = $propagator->getChanges(); $parents = $propagator->getAllParents(); sort($changes); sort($parents); $this->assertEquals(array('/foo', '/foo/folder', '/foo/folder/bar.txt', '/foo/foo.txt'), $changes); $this->assertEquals(array('/', '/foo', '/foo/folder'), $parents); $cache->put('foo.txt', array('storage_mtime' => time() - 50)); $propagator = $this->getMock('\\OC\\Files\\Cache\\ChangePropagator', array('propagateChanges'), array(), '', false); $scanner->setPropagator($propagator); $storage->file_put_contents('foo.txt', 'asdasd'); $scanner->scan(''); $changes = $propagator->getChanges(); $parents = $propagator->getAllParents(); $this->assertEquals(array('/foo/foo.txt'), $changes); $this->assertEquals(array('/', '/foo'), $parents); $scanner->setPropagator($originalPropagator); $oldInfo = $cache->get(''); $cache->put('foo.txt', array('storage_mtime' => time() - 70)); $storage->file_put_contents('foo.txt', 'asdasd'); $scanner->scan(''); $newInfo = $cache->get(''); $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']); }
/** * @param array $urlParams */ public function __construct(array $urlParams = array()) { parent::__construct('files_sharing', $urlParams); $container = $this->getContainer(); /** * Controllers */ $container->registerService('ShareController', function (SimpleContainer $c) { return new ShareController($c->query('AppName'), $c->query('Request'), $c->query('UserSession'), $c->query('ServerContainer')->getAppConfig(), $c->query('ServerContainer')->getConfig(), $c->query('URLGenerator'), $c->query('ServerContainer')->getUserManager(), $c->query('ServerContainer')->getLogger(), $c->query('ServerContainer')->getActivityManager()); }); $container->registerService('ExternalSharesController', function (SimpleContainer $c) { return new ExternalSharesController($c->query('AppName'), $c->query('Request'), $c->query('IsIncomingShareEnabled'), $c->query('ExternalManager')); }); /** * Core class wrappers */ $container->registerService('UserSession', function (SimpleContainer $c) { return $c->query('ServerContainer')->getUserSession(); }); $container->registerService('URLGenerator', function (SimpleContainer $c) { return $c->query('ServerContainer')->getUrlGenerator(); }); $container->registerService('IsIncomingShareEnabled', function (SimpleContainer $c) { return Helper::isIncomingServer2serverShareEnabled(); }); $container->registerService('ExternalManager', function (SimpleContainer $c) { return new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getUserSession(), \OC::$server->getHTTPHelper()); }); /** * Middleware */ $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) { return new SharingCheckMiddleware($c->query('AppName'), $c->query('ServerContainer')->getAppConfig(), $c->getCoreApi()); }); // Execute middlewares $container->registerMiddleware('SharingCheckMiddleware'); }
/** * Hook that mounts the given user's visible mount points * @param array $data */ public static function initMountPointsHook($data) { $mountPoints = self::getAbsoluteMountPoints($data['user']); $loader = \OC\Files\Filesystem::getLoader(); $manager = \OC\Files\Filesystem::getMountManager(); foreach ($mountPoints as $mountPoint => $options) { if (isset($options['options']['objectstore'])) { $objectClass = $options['options']['objectstore']['class']; $options['options']['objectstore'] = new $objectClass($options['options']['objectstore']); } if (isset($options['personal']) && $options['personal']) { $mount = new \OCA\Files_External\PersonalMount($options['class'], $mountPoint, $options['options'], $loader); } else { $mount = new \OC\Files\Mount\Mount($options['class'], $mountPoint, $options['options'], $loader); } $manager->addMount($mount); } if ($data['user']) { $user = \OC::$server->getUserManager()->get($data['user']); $userView = new \OC\Files\View('/' . $user->getUID() . '/files'); $changePropagator = new \OC\Files\Cache\ChangePropagator($userView); $etagPropagator = new \OCA\Files_External\EtagPropagator($user, $changePropagator, \OC::$server->getConfig()); $etagPropagator->propagateDirtyMountPoints(); \OCP\Util::connectHook(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create_mount, $etagPropagator, 'updateHook'); \OCP\Util::connectHook(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_delete_mount, $etagPropagator, 'updateHook'); } }
public function testRemoveMoveableMountPoint() { $mountPoint = '/' . $this->user . '/files/mount/'; // Mock the mount point $mount = $this->getMockBuilder('\\Test\\TestMoveableMountPoint')->disableOriginalConstructor()->getMock(); $mount->expects($this->once())->method('getMountPoint')->willReturn($mountPoint); $mount->expects($this->once())->method('removeMount')->willReturn('foo'); $mount->expects($this->any())->method('getInternalPath')->willReturn(''); // Register mount \OC\Files\Filesystem::getMountManager()->addMount($mount); // Listen for events $eventHandler = $this->getMockBuilder('\\stdclass')->setMethods(['umount', 'post_umount'])->getMock(); $eventHandler->expects($this->once())->method('umount')->with([\OC\Files\Filesystem::signal_param_path => '/mount']); $eventHandler->expects($this->once())->method('post_umount')->with([\OC\Files\Filesystem::signal_param_path => '/mount']); \OCP\Util::connectHook(\OC\Files\Filesystem::CLASSNAME, 'umount', $eventHandler, 'umount'); \OCP\Util::connectHook(\OC\Files\Filesystem::CLASSNAME, 'post_umount', $eventHandler, 'post_umount'); //Delete the mountpoint $view = new \OC\Files\View('/' . $this->user . '/files'); $this->assertEquals('foo', $view->rmdir('mount')); }
/** * Remove the mount points * * @return bool */ public function removeMount() { $mountManager = \OC\Files\Filesystem::getMountManager(); /** @var $storage \OC\Files\Storage\Shared */ $storage = $this->getStorage(); $result = $storage->unshareStorage(); $mountManager->removeMount($this->mountPoint); return $result; }
/** * Get the path of a file by id, relative to the view * * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file * * @param int $id * @return string|null */ public function getPath($id) { $id = (int) $id; $manager = Filesystem::getMountManager(); $mounts = $manager->findIn($this->fakeRoot); $mounts[] = $manager->find($this->fakeRoot); // reverse the array so we start with the storage this view is in // which is the most likely to contain the file we're looking for $mounts = array_reverse($mounts); foreach ($mounts as $mount) { /** * @var \OC\Files\Mount\MountPoint $mount */ if ($mount->getStorage()) { $cache = $mount->getStorage()->getCache(); $internalPath = $cache->getPathById($id); if (is_string($internalPath)) { $fullPath = $mount->getMountPoint() . $internalPath; if (!is_null($path = $this->getRelativePath($fullPath))) { return $path; } } } } return null; }
function __construct() { $this->registerService('ContactsManager', function ($c) { return new ContactsManager(); }); $this->registerService('Request', function ($c) { if (isset($c['urlParams'])) { $urlParams = $c['urlParams']; } else { $urlParams = array(); } if (\OC::$server->getSession()->exists('requesttoken')) { $requestToken = \OC::$server->getSession()->get('requesttoken'); } else { $requestToken = false; } if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) { $stream = 'fakeinput://data'; } else { $stream = 'php://input'; } return new Request(array('get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken), $stream); }); $this->registerService('PreviewManager', function ($c) { return new PreviewManager(); }); $this->registerService('TagManager', function ($c) { $user = \OC_User::getUser(); return new TagManager($user); }); $this->registerService('RootFolder', function ($c) { // TODO: get user and user manager from container as well $user = \OC_User::getUser(); /** @var $c SimpleContainer */ $userManager = $c->query('UserManager'); $user = $userManager->get($user); $manager = \OC\Files\Filesystem::getMountManager(); $view = new View(); return new Root($manager, $view, $user); }); $this->registerService('UserManager', function ($c) { /** * @var SimpleContainer $c * @var \OC\AllConfig $config */ $config = $c->query('AllConfig'); return new \OC\User\Manager($config); }); $this->registerService('GroupManager', function ($c) { /** * @var SimpleContainer $c * @var \OC\User\Manager $userManager */ $userManager = $c->query('UserManager'); return new \OC\Group\Manager($userManager); }); $this->registerService('UserSession', function ($c) { /** * @var SimpleContainer $c * @var \OC\User\Manager $manager */ $manager = $c->query('UserManager'); $userSession = new \OC\User\Session($manager, new \OC\Session\Memory('')); $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); }); $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); }); $userSession->listen('\\OC\\User', 'preDelete', function ($user) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); }); $userSession->listen('\\OC\\User', 'postDelete', function ($user) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); }); $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); }); $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); }); $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); }); $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); }); $userSession->listen('\\OC\\User', 'logout', function () { \OC_Hook::emit('OC_User', 'logout', array()); }); return $userSession; }); $this->registerService('NavigationManager', function ($c) { return new \OC\NavigationManager(); }); $this->registerService('AllConfig', function ($c) { return new \OC\AllConfig(); }); $this->registerService('AppConfig', function ($c) { return new \OC\AppConfig(\OC_DB::getConnection()); }); $this->registerService('L10NFactory', function ($c) { return new \OC\L10N\Factory(); }); $this->registerService('URLGenerator', function ($c) { /** @var $c SimpleContainer */ $config = $c->query('AllConfig'); return new \OC\URLGenerator($config); }); $this->registerService('AppHelper', function ($c) { return new \OC\AppHelper(); }); $this->registerService('UserCache', function ($c) { return new UserCache(); }); $this->registerService('MemCacheFactory', function ($c) { $instanceId = \OC_Util::getInstanceId(); return new \OC\Memcache\Factory($instanceId); }); $this->registerService('ActivityManager', function ($c) { return new ActivityManager(); }); $this->registerService('AvatarManager', function ($c) { return new AvatarManager(); }); $this->registerService('Logger', function ($c) { /** @var $c SimpleContainer */ $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); $logger = 'OC_Log_' . ucfirst($logClass); call_user_func(array($logger, 'init')); return new Log($logger); }); $this->registerService('JobList', function ($c) { /** * @var Server $c */ $config = $c->getConfig(); return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); }); $this->registerService('Router', function ($c) { /** * @var Server $c */ $cacheFactory = $c->getMemCacheFactory(); if ($cacheFactory->isAvailable()) { $router = new \OC\Route\CachingRouter($cacheFactory->create('route')); } else { $router = new \OC\Route\Router(); } return $router; }); $this->registerService('Search', function ($c) { return new Search(); }); $this->registerService('SecureRandom', function ($c) { return new SecureRandom(); }); $this->registerService('Crypto', function ($c) { return new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom()); }); $this->registerService('Db', function ($c) { return new Db(); }); }
/** * Share an item with a user, group, or via private link * @param string $itemType * @param string $itemSource * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string $shareWith User or group the item is being shared with * @param int $permissions CRUDS * @param string $itemSourceName * @param \DateTime $expirationDate * @param bool $passwordChanged * @return boolean|string Returns true on success or false on failure, Returns token on success for links * @throws \OC\HintException when the share type is remote and the shareWith is invalid * @throws \Exception */ public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) { $backend = self::getBackend($itemType); $l = \OC::$server->getL10N('lib'); if ($backend->isShareTypeAllowed($shareType) === false) { $message = 'Sharing %s failed, because the backend does not allow shares from type %i'; $message_t = $l->t('Sharing %s failed, because the backend does not allow shares from type %i', array($itemSourceName, $shareType)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareType), \OCP\Util::DEBUG); throw new \Exception($message_t); } $uidOwner = \OC_User::getUser(); $shareWithinGroupOnly = self::shareWithGroupMembersOnly(); if (is_null($itemSourceName)) { $itemSourceName = $itemSource; } $itemName = $itemSourceName; // check if file can be shared if ($itemType === 'file' or $itemType === 'folder') { $path = \OC\Files\Filesystem::getPath($itemSource); $itemName = $path; // verify that the file exists before we try to share it if (!$path) { $message = 'Sharing %s failed, because the file does not exist'; $message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); throw new \Exception($message_t); } // verify that the user has share permission if (!\OC\Files\Filesystem::isSharable($path)) { $message = 'You are not allowed to share %s'; $message_t = $l->t('You are not allowed to share %s', [$path]); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $path), \OCP\Util::DEBUG); throw new \Exception($message_t); } } //verify that we don't share a folder which already contains a share mount point if ($itemType === 'folder') { $path = '/' . $uidOwner . '/files' . \OC\Files\Filesystem::getPath($itemSource) . '/'; $mountManager = \OC\Files\Filesystem::getMountManager(); $mounts = $mountManager->findIn($path); foreach ($mounts as $mount) { if ($mount->getStorage()->instanceOfStorage('\\OCA\\Files_Sharing\\ISharedStorage')) { $message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!'; \OCP\Util::writeLog('OCP\\Share', $message, \OCP\Util::DEBUG); throw new \Exception($message); } } } // single file shares should never have delete permissions if ($itemType === 'file') { $permissions = (int) $permissions & ~\OCP\Constants::PERMISSION_DELETE; } //Validate expirationDate if ($expirationDate !== null) { try { /* * Reuse the validateExpireDate. * We have to pass time() since the second arg is the time * the file was shared, since it is not shared yet we just use * the current time. */ $expirationDate = self::validateExpireDate($expirationDate->format('Y-m-d'), time(), $itemType, $itemSource); } catch (\Exception $e) { throw new \OC\HintException($e->getMessage(), $e->getMessage(), 404); } } // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { if ($shareWith == $uidOwner) { $message = 'Sharing %s failed, because you can not share with yourself'; $message_t = $l->t('Sharing %s failed, because you can not share with yourself', [$itemName]); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); throw new \Exception($message_t); } if (!\OC_User::userExists($shareWith)) { $message = 'Sharing %s failed, because the user %s does not exist'; $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); throw new \Exception($message_t); } if ($shareWithinGroupOnly) { $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); if (empty($inGroup)) { $message = 'Sharing %s failed, because the user ' . '%s is not a member of any groups that %s is a member of'; $message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemName, $shareWith, $uidOwner)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemName, $shareWith, $uidOwner), \OCP\Util::DEBUG); throw new \Exception($message_t); } } // Check if the item source is already shared with the user, either from the same owner or a different user if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a user share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing %s failed, because this item is already shared with %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); throw new \Exception($message_t); } } if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_USER, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a user share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing %s failed, because this item is already shared with user %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with user %s', array($itemSourceName, $shareWith)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::ERROR); throw new \Exception($message_t); } } } else { if ($shareType === self::SHARE_TYPE_GROUP) { if (!\OC_Group::groupExists($shareWith)) { $message = 'Sharing %s failed, because the group %s does not exist'; $message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); throw new \Exception($message_t); } if ($shareWithinGroupOnly && !\OC_Group::inGroup($uidOwner, $shareWith)) { $message = 'Sharing %s failed, because ' . '%s is not a member of the group %s'; $message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $uidOwner, $shareWith), \OCP\Util::DEBUG); throw new \Exception($message_t); } // Check if the item source is already shared with the group, either from the same owner or a different user // The check for each user in the group is done inside the put() function if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a group share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing %s failed, because this item is already shared with %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); throw new \Exception($message_t); } } // Convert share with into an array with the keys group and users $group = $shareWith; $shareWith = array(); $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else { if ($shareType === self::SHARE_TYPE_LINK) { $updateExistingShare = false; if (\OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { // when updating a link share // FIXME Don't delete link if we update it if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) { // remember old token $oldToken = $checkExists['token']; $oldPermissions = $checkExists['permissions']; //delete the old share Helper::delete($checkExists['id']); $updateExistingShare = true; } if ($passwordChanged === null) { // Generate hash of password - same method as user passwords if (is_string($shareWith) && $shareWith !== '') { self::verifyPassword($shareWith); $shareWith = \OC::$server->getHasher()->hash($shareWith); } else { // reuse the already set password, but only if we change permissions // otherwise the user disabled the password protection if ($checkExists && (int) $permissions !== (int) $oldPermissions) { $shareWith = $checkExists['share_with']; } } } else { if ($passwordChanged === true) { if (is_string($shareWith) && $shareWith !== '') { self::verifyPassword($shareWith); $shareWith = \OC::$server->getHasher()->hash($shareWith); } } else { if ($updateExistingShare) { $shareWith = $checkExists['share_with']; } } } if (\OCP\Util::isPublicLinkPasswordRequired() && empty($shareWith)) { $message = 'You need to provide a password to create a public link, only protected links are allowed'; $message_t = $l->t('You need to provide a password to create a public link, only protected links are allowed'); \OCP\Util::writeLog('OCP\\Share', $message, \OCP\Util::DEBUG); throw new \Exception($message_t); } if ($updateExistingShare === false && self::isDefaultExpireDateEnabled() && empty($expirationDate)) { $expirationDate = Helper::calcExpireDate(); } // Generate token if (isset($oldToken)) { $token = $oldToken; } else { $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(self::TOKEN_LENGTH, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER . \OCP\Security\ISecureRandom::CHAR_DIGITS); } $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, $token, $itemSourceName, $expirationDate); if ($result) { return $token; } else { return false; } } $message = 'Sharing %s failed, because sharing with links is not allowed'; $message_t = $l->t('Sharing %s failed, because sharing with links is not allowed', array($itemSourceName)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); throw new \Exception($message_t); } else { if ($shareType === self::SHARE_TYPE_REMOTE) { /* * Check if file is not already shared with the remote user */ if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_REMOTE, $shareWith, $uidOwner, self::FORMAT_NONE, null, 1, true, true)) { $message = 'Sharing %s failed, because this item is already shared with %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); throw new \Exception($message_t); } $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(self::TOKEN_LENGTH, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER . \OCP\Security\ISecureRandom::CHAR_DIGITS); list($user, $remote) = Helper::splitUserRemote($shareWith); $shareWith = $user . '@' . $remote; $shareId = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, $token, $itemSourceName); $send = false; if ($shareId) { $send = self::sendRemoteShare($token, $shareWith, $itemSourceName, $shareId, $uidOwner); } if ($send === false) { $currentUser = \OC::$server->getUserSession()->getUser()->getUID(); self::unshare($itemType, $itemSource, $shareType, $shareWith, $currentUser); $message_t = $l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable.', array($itemSourceName, $shareWith)); throw new \Exception($message_t); } return $send; } else { // Future share types need to include their own conditions $message = 'Share type %s is not valid for %s'; $message_t = $l->t('Share type %s is not valid for %s', array($shareType, $itemSource)); \OCP\Util::writeLog('OCP\\Share', sprintf($message, $shareType, $itemSource), \OCP\Util::DEBUG); throw new \Exception($message_t); } } } } // Put the item into the database $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName, $expirationDate); return $result ? true : false; }
/** * Share an item with a user, group, or via private link * @param string $itemType * @param string $itemSource * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string $shareWith User or group the item is being shared with * @param int $permissions CRUDS * @param string $itemSourceName * @param \DateTime $expirationDate * @return boolean|string Returns true on success or false on failure, Returns token on success for links * @throws \Exception */ public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null) { $uidOwner = \OC_User::getUser(); $shareWithinGroupOnly = self::shareWithGroupMembersOnly(); $l = \OC_L10N::get('lib'); if (is_null($itemSourceName)) { $itemSourceName = $itemSource; } // check if file can be shared if ($itemType === 'file' or $itemType === 'folder') { $path = \OC\Files\Filesystem::getPath($itemSource); // verify that the file exists before we try to share it if (!$path) { $message = 'Sharing %s failed, because the file does not exist'; $message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR); throw new \Exception($message_t); } // verify that the user has share permission if (!\OC\Files\Filesystem::isSharable($path)) { $message = 'You are not allowed to share %s'; $message_t = $l->t('You are not allowed to share %s', array($itemSourceName)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR); throw new \Exception($message_t); } } //verify that we don't share a folder which already contains a share mount point if ($itemType === 'folder') { $path = '/' . $uidOwner . '/files' . \OC\Files\Filesystem::getPath($itemSource) . '/'; $mountManager = \OC\Files\Filesystem::getMountManager(); $mounts = $mountManager->findIn($path); foreach ($mounts as $mount) { if ($mount->getStorage()->instanceOfStorage('\\OCA\\Files_Sharing\\ISharedStorage')) { $message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } // single file shares should never have delete permissions if ($itemType === 'file') { $permissions = (int) $permissions & ~\OCP\PERMISSION_DELETE; } // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { if ($shareWith == $uidOwner) { $message = 'Sharing %s failed, because the user %s is the item owner'; $message_t = $l->t('Sharing %s failed, because the user %s is the item owner', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } if (!\OC_User::userExists($shareWith)) { $message = 'Sharing %s failed, because the user %s does not exist'; $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } if ($shareWithinGroupOnly) { $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); if (empty($inGroup)) { $message = 'Sharing %s failed, because the user ' . '%s is not a member of any groups that %s is a member of'; $message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemSourceName, $shareWith, $uidOwner)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith, $uidOwner), \OC_Log::ERROR); throw new \Exception($message_t); } } // Check if the item source is already shared with the user, either from the same owner or a different user if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a user share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing %s failed, because this item is already shared with %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } } } else { if ($shareType === self::SHARE_TYPE_GROUP) { if (!\OC_Group::groupExists($shareWith)) { $message = 'Sharing %s failed, because the group %s does not exist'; $message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } if ($shareWithinGroupOnly && !\OC_Group::inGroup($uidOwner, $shareWith)) { $message = 'Sharing %s failed, because ' . '%s is not a member of the group %s'; $message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $uidOwner, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } // Check if the item source is already shared with the group, either from the same owner or a different user // The check for each user in the group is done inside the put() function if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a group share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing %s failed, because this item is already shared with %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } } // Convert share with into an array with the keys group and users $group = $shareWith; $shareWith = array(); $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else { if ($shareType === self::SHARE_TYPE_LINK) { $updateExistingShare = false; if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { // when updating a link share // FIXME Don't delete link if we update it if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) { // remember old token $oldToken = $checkExists['token']; $oldPermissions = $checkExists['permissions']; //delete the old share Helper::delete($checkExists['id']); $updateExistingShare = true; } // Generate hash of password - same method as user passwords if (!empty($shareWith)) { $forcePortable = CRYPT_BLOWFISH != 1; $hasher = new \PasswordHash(8, $forcePortable); $shareWith = $hasher->HashPassword($shareWith . \OC_Config::getValue('passwordsalt', '')); } else { // reuse the already set password, but only if we change permissions // otherwise the user disabled the password protection if ($checkExists && (int) $permissions !== (int) $oldPermissions) { $shareWith = $checkExists['share_with']; } } if (\OCP\Util::isPublicLinkPasswordRequired() && empty($shareWith)) { $message = 'You need to provide a password to create a public link, only protected links are allowed'; $message_t = $l->t('You need to provide a password to create a public link, only protected links are allowed'); \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message_t); } if ($updateExistingShare === false && self::isDefaultExpireDateEnabled() && empty($expirationDate)) { $expirationDate = Helper::calcExpireDate(); } // Generate token if (isset($oldToken)) { $token = $oldToken; } else { $token = \OC_Util::generateRandomBytes(self::TOKEN_LENGTH); } $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, $token, $itemSourceName, $expirationDate); if ($result) { return $token; } else { return false; } } $message = 'Sharing %s failed, because sharing with links is not allowed'; $message_t = $l->t('Sharing %s failed, because sharing with links is not allowed', array($itemSourceName)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR); throw new \Exception($message_t); return false; } else { // Future share types need to include their own conditions $message = 'Share type %s is not valid for %s'; $message_t = $l->t('Share type %s is not valid for %s', array($shareType, $itemSource)); \OC_Log::write('OCP\\Share', sprintf($message, $shareType, $itemSource), \OC_Log::ERROR); throw new \Exception($message_t); } } } // Put the item into the database return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName, $expirationDate); }
public static function setup() { $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getUserSession()); $externalManager->setupMounts(); }
public static function setup($options) { $shares = \OCP\Share::getItemsSharedWith('file'); $manager = Filesystem::getMountManager(); $loader = Filesystem::getLoader(); if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user'] || $shares) { foreach ($shares as $share) { // don't mount shares where we have no permissions if ($share['permissions'] > 0) { $mount = new SharedMount('\\OC\\Files\\Storage\\Shared', $options['user_dir'] . '/' . $share['file_target'], array('share' => $share), $loader); $manager->addMount($mount); } } } }
/** * @param string $webRoot */ public function __construct($webRoot) { parent::__construct(); $this->webRoot = $webRoot; $this->registerService('ContactsManager', function ($c) { return new ContactsManager(); }); $this->registerService('PreviewManager', function (Server $c) { return new PreviewManager($c->getConfig()); }); $this->registerService('EncryptionManager', function (Server $c) { $view = new View(); $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig()); return new Encryption\Manager($c->getConfig(), $c->getLogger(), $c->getL10N('core'), new View(), $util); }); $this->registerService('EncryptionFileHelper', function (Server $c) { $util = new Encryption\Util(new View(), $c->getUserManager(), $c->getGroupManager(), $c->getConfig()); return new Encryption\File($util); }); $this->registerService('EncryptionKeyStorage', function (Server $c) { $view = new View(); $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig()); return new Encryption\Keys\Storage($view, $util); }); $this->registerService('TagMapper', function (Server $c) { return new TagMapper($c->getDatabaseConnection()); }); $this->registerService('TagManager', function (Server $c) { $tagMapper = $c->query('TagMapper'); return new TagManager($tagMapper, $c->getUserSession()); }); $this->registerService('SystemTagManager', function (Server $c) { return new SystemTag\SystemTagManager($c->getDatabaseConnection()); }); $this->registerService('SystemTagObjectMapper', function (Server $c) { return new SystemTag\SystemTagObjectMapper($c->getDatabaseConnection(), $c->getSystemTagManager()); }); $this->registerService('RootFolder', function (Server $c) { // TODO: get user and user manager from container as well $user = \OC_User::getUser(); /** @var $c SimpleContainer */ $userManager = $c->query('UserManager'); $user = $userManager->get($user); $manager = \OC\Files\Filesystem::getMountManager(); $view = new View(); $root = new Root($manager, $view, $user); $connector = new HookConnector($root, $view); $connector->viewToNode(); return $root; }); $this->registerService('UserManager', function (Server $c) { $config = $c->getConfig(); return new \OC\User\Manager($config); }); $this->registerService('GroupManager', function (Server $c) { $groupManager = new \OC\Group\Manager($this->getUserManager()); $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) { \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); }); $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) { \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); }); $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) { \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); }); $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) { \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); }); $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); }); $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); }); return $groupManager; }); $this->registerService('UserSession', function (Server $c) { $manager = $c->getUserManager(); $session = new \OC\Session\Memory(''); $userSession = new \OC\User\Session($manager, $session); $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); }); $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); }); $userSession->listen('\\OC\\User', 'preDelete', function ($user) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); }); $userSession->listen('\\OC\\User', 'postDelete', function ($user) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); }); $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); }); $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); }); $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); }); $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); }); $userSession->listen('\\OC\\User', 'logout', function () { \OC_Hook::emit('OC_User', 'logout', array()); }); return $userSession; }); $this->registerService('NavigationManager', function ($c) { return new \OC\NavigationManager(); }); $this->registerService('AllConfig', function (Server $c) { return new \OC\AllConfig($c->getSystemConfig()); }); $this->registerService('SystemConfig', function ($c) { return new \OC\SystemConfig(); }); $this->registerService('AppConfig', function ($c) { return new \OC\AppConfig(\OC_DB::getConnection()); }); $this->registerService('L10NFactory', function ($c) { return new \OC\L10N\Factory(); }); $this->registerService('URLGenerator', function (Server $c) { $config = $c->getConfig(); $cacheFactory = $c->getMemCacheFactory(); return new \OC\URLGenerator($config, $cacheFactory); }); $this->registerService('AppHelper', function ($c) { return new \OC\AppHelper(); }); $this->registerService('UserCache', function ($c) { return new Cache\File(); }); $this->registerService('MemCacheFactory', function (Server $c) { $config = $c->getConfig(); if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { $v = \OC_App::getAppVersions(); $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); $version = implode(',', $v); $instanceId = \OC_Util::getInstanceId(); $path = \OC::$SERVERROOT; $prefix = md5($instanceId . '-' . $version . '-' . $path); return new \OC\Memcache\Factory($prefix, $c->getLogger(), $config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.locking', null)); } return new \OC\Memcache\Factory('', $c->getLogger(), '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache'); }); $this->registerService('ActivityManager', function (Server $c) { return new ActivityManager($c->getRequest(), $c->getUserSession(), $c->getConfig()); }); $this->registerService('AvatarManager', function (Server $c) { return new AvatarManager($c->getUserManager(), $c->getRootFolder(), $c->getL10N('lib')); }); $this->registerService('Logger', function (Server $c) { $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); $logger = 'OC_Log_' . ucfirst($logClass); call_user_func(array($logger, 'init')); return new Log($logger); }); $this->registerService('JobList', function (Server $c) { $config = $c->getConfig(); return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); }); $this->registerService('Router', function (Server $c) { $cacheFactory = $c->getMemCacheFactory(); $logger = $c->getLogger(); if ($cacheFactory->isAvailable()) { $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); } else { $router = new \OC\Route\Router($logger); } return $router; }); $this->registerService('Search', function ($c) { return new Search(); }); $this->registerService('SecureRandom', function ($c) { return new SecureRandom(); }); $this->registerService('Crypto', function (Server $c) { return new Crypto($c->getConfig(), $c->getSecureRandom()); }); $this->registerService('Hasher', function (Server $c) { return new Hasher($c->getConfig()); }); $this->registerService('DatabaseConnection', function (Server $c) { $factory = new \OC\DB\ConnectionFactory(); $systemConfig = $c->getSystemConfig(); $type = $systemConfig->getValue('dbtype', 'sqlite'); if (!$factory->isValidType($type)) { throw new \OC\DatabaseException('Invalid database type'); } $connectionParams = $factory->createConnectionParams($systemConfig); $connection = $factory->getConnection($type, $connectionParams); $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); return $connection; }); $this->registerService('Db', function (Server $c) { return new Db($c->getDatabaseConnection()); }); $this->registerService('HTTPHelper', function (Server $c) { $config = $c->getConfig(); return new HTTPHelper($config, $c->getHTTPClientService()); }); $this->registerService('HttpClientService', function (Server $c) { $user = \OC_User::getUser(); $uid = $user ? $user : null; return new ClientService($c->getConfig(), new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())); }); $this->registerService('EventLogger', function (Server $c) { if ($c->getSystemConfig()->getValue('debug', false)) { return new EventLogger(); } else { return new NullEventLogger(); } }); $this->registerService('QueryLogger', function (Server $c) { if ($c->getSystemConfig()->getValue('debug', false)) { return new QueryLogger(); } else { return new NullQueryLogger(); } }); $this->registerService('TempManager', function (Server $c) { return new TempManager($c->getLogger(), $c->getConfig()); }); $this->registerService('AppManager', function (Server $c) { return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory()); }); $this->registerService('DateTimeZone', function (Server $c) { return new DateTimeZone($c->getConfig(), $c->getSession()); }); $this->registerService('DateTimeFormatter', function (Server $c) { $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language)); }); $this->registerService('MountConfigManager', function () { $loader = \OC\Files\Filesystem::getLoader(); return new \OC\Files\Config\MountProviderCollection($loader); }); $this->registerService('IniWrapper', function ($c) { return new IniGetWrapper(); }); $this->registerService('AsyncCommandBus', function (Server $c) { $jobList = $c->getJobList(); return new AsyncBus($jobList); }); $this->registerService('TrustedDomainHelper', function ($c) { return new TrustedDomainHelper($this->getConfig()); }); $this->registerService('IntegrityCodeChecker', function (Server $c) { // IConfig and IAppManager requires a working database. This code // might however be called when ownCloud is not yet setup. if (\OC::$server->getSystemConfig()->getValue('installed', false)) { $config = $c->getConfig(); $appManager = $c->getAppManager(); } else { $config = null; $appManager = null; } return new Checker(new EnvironmentHelper(), new FileAccessHelper(), new AppLocator(), $config, $c->getMemCacheFactory(), $appManager); }); $this->registerService('Request', function ($c) { if (isset($this['urlParams'])) { $urlParams = $this['urlParams']; } else { $urlParams = []; } if ($this->getSession()->exists('requesttoken')) { $requestToken = $this->getSession()->get('requesttoken'); } else { $requestToken = false; } if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) { $stream = 'fakeinput://data'; } else { $stream = 'php://input'; } return new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken], $this->getSecureRandom(), $this->getConfig(), $stream); }); $this->registerService('Mailer', function (Server $c) { return new Mailer($c->getConfig(), $c->getLogger(), new \OC_Defaults()); }); $this->registerService('OcsClient', function (Server $c) { return new OCSClient($this->getHTTPClientService(), $this->getConfig(), $this->getLogger()); }); $this->registerService('LockingProvider', function (Server $c) { if ($c->getConfig()->getSystemValue('filelocking.enabled', true) or defined('PHPUNIT_RUN') && PHPUNIT_RUN) { /** @var \OC\Memcache\Factory $memcacheFactory */ $memcacheFactory = $c->getMemCacheFactory(); $memcache = $memcacheFactory->createLocking('lock'); if (!$memcache instanceof \OC\Memcache\NullCache) { return new MemcacheLockingProvider($memcache); } return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory()); } return new NoopLockingProvider(); }); $this->registerService('MountManager', function () { return new \OC\Files\Mount\Manager(); }); $this->registerService('MimeTypeDetector', function (Server $c) { return new \OC\Files\Type\Detection($c->getURLGenerator(), \OC::$SERVERROOT . '/config/', \OC::$SERVERROOT . '/resources/config/'); }); $this->registerService('MimeTypeLoader', function (Server $c) { return new \OC\Files\Type\Loader($c->getDatabaseConnection()); }); $this->registerService('NotificationManager', function () { return new Manager(); }); $this->registerService('CapabilitiesManager', function (Server $c) { $manager = new \OC\CapabilitiesManager(); $manager->registerCapability(function () use($c) { return new \OC\OCS\CoreCapabilities($c->getConfig()); }); return $manager; }); $this->registerService('CommentsManager', function (Server $c) { $config = $c->getConfig(); $factoryClass = $config->getSystemValue('comments.managerFactory', '\\OC\\Comments\\ManagerFactory'); /** @var \OCP\Comments\ICommentsManagerFactory $factory */ $factory = new $factoryClass(); return $factory->getManager(); }); $this->registerService('EventDispatcher', function () { return new EventDispatcher(); }); $this->registerService('CryptoWrapper', function (Server $c) { // FIXME: Instantiiated here due to cyclic dependency $request = new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null], new SecureRandom(), $c->getConfig()); return new CryptoWrapper($c->getConfig(), $c->getCrypto(), $c->getSecureRandom(), $request); }); }
$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav')); // wait with registering these until auth is handled and the filesystem is setup $server->subscribeEvent('beforeMethod', function () use($server, $objectTree, $authBackend) { $share = $authBackend->getShare(); $rootShare = \OCP\Share::resolveReShare($share); $owner = $rootShare['uid_owner']; $isWritable = $share['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE); $fileId = $share['file_source']; if (!$isWritable) { \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) { return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage)); }); } OC_Util::setupFS($owner); $ownerView = \OC\Files\Filesystem::getView(); $path = $ownerView->getPath($fileId); $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); $rootInfo = $view->getFileInfo(''); // Create ownCloud Dir if ($rootInfo->getType() === 'dir') { $root = new OC_Connector_Sabre_Directory($view, $rootInfo); } else { $root = new OC_Connector_Sabre_File($view, $rootInfo); } $mountManager = \OC\Files\Filesystem::getMountManager(); $objectTree->init($root, $view, $mountManager); $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin($view)); }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request // And off we go! $server->exec();
/** * Returns the mount point for which to lock * * @param string $absolutePath absolute path * @param bool $useParentMount true to return parent mount instead of whatever * is mounted directly on the given path, false otherwise * @return \OC\Files\Mount\MountPoint mount point for which to apply locks */ private function getMountForLock($absolutePath, $useParentMount = false) { $results = []; $mount = Filesystem::getMountManager()->find($absolutePath); if (!$mount) { return $results; } if ($useParentMount) { // find out if something is mounted directly on the path $internalPath = $mount->getInternalPath($absolutePath); if ($internalPath === '') { // resolve the parent mount instead $mount = Filesystem::getMountManager()->find(dirname($absolutePath)); } } return $mount; }