diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/files.php | 27 | ||||
-rw-r--r-- | lib/private/files/storage/wrapper/encryption.php | 8 | ||||
-rw-r--r-- | lib/private/mimetypes.list.php | 1 | ||||
-rw-r--r-- | lib/private/share/helper.php | 80 | ||||
-rw-r--r-- | lib/private/share/share.php | 31 |
5 files changed, 111 insertions, 36 deletions
diff --git a/lib/private/files.php b/lib/private/files.php index 17899966797..17e2e5a398f 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -42,6 +42,9 @@ // TODO: get rid of this using proper composer packages require_once 'mcnetic/phpzipstreamer/ZipStreamer.php'; +use OC\Lock\NoopLockingProvider; +use OCP\Lock\ILockingProvider; + /** * Class for file server access * @@ -81,11 +84,15 @@ class OC_Files { * @param boolean $only_header ; boolean to only send header of the request */ public static function get($dir, $files, $only_header = false) { + $view = \OC\Files\Filesystem::getView(); $xsendfile = false; - if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || - isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) || - isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { - $xsendfile = true; + if (\OC::$server->getLockingProvider() instanceof NoopLockingProvider) { + if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || + isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) || + isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED']) + ) { + $xsendfile = true; + } } if (is_array($files) && count($files) === 1) { @@ -130,7 +137,9 @@ class OC_Files { OC_Util::obEnd(); try { - + if ($get_type === self::FILE) { + $view->lockFile($filename, ILockingProvider::LOCK_SHARED); + } if ($zip or \OC\Files\Filesystem::isReadable($filename)) { self::sendHeaders($filename, $name, $zip); } elseif (!\OC\Files\Filesystem::file_exists($filename)) { @@ -167,7 +176,6 @@ class OC_Files { set_time_limit($executionTime); } else { if ($xsendfile) { - $view = \OC\Files\Filesystem::getView(); /** @var $storage \OC\Files\Storage\Storage */ list($storage) = $view->resolvePath($filename); if ($storage->isLocal()) { @@ -179,6 +187,13 @@ class OC_Files { \OC\Files\Filesystem::readfile($filename); } } + if ($get_type === self::FILE) { + $view->unlockFile($filename, ILockingProvider::LOCK_SHARED); + } + } catch (\OCP\Lock\LockedException $ex) { + $l = \OC::$server->getL10N('core'); + $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; + \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint); } catch (\Exception $ex) { $l = \OC::$server->getL10N('core'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 58d4c43ad91..ae04e3bec4d 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -353,7 +353,7 @@ class Encryption extends Wrapper { $size = $unencryptedSize = 0; $realFile = $this->util->stripPartialFileExtension($path); - $targetExists = $this->file_exists($realFile); + $targetExists = $this->file_exists($realFile) || $this->file_exists($path); $targetIsEncrypted = false; if ($targetExists) { // in case the file exists we require the explicit module as @@ -611,7 +611,11 @@ class Encryption extends Wrapper { $header = ''; $realFile = $this->util->stripPartialFileExtension($path); if ($this->storage->file_exists($realFile)) { - $handle = $this->storage->fopen($realFile, 'r'); + $path = $realFile; + } + + if ($this->storage->file_exists($path)) { + $handle = $this->storage->fopen($path, 'r'); $firstBlock = fread($handle, $this->util->getHeaderSize()); fclose($handle); if (substr($firstBlock, 0, strlen(Util::HEADER_START)) === Util::HEADER_START) { diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php index 1ee4e934ee9..efb8089420e 100644 --- a/lib/private/mimetypes.list.php +++ b/lib/private/mimetypes.list.php @@ -47,6 +47,7 @@ return array( 'blend' => array('application/x-blender', null), 'bin' => array('application/x-bin', null), 'bmp' => array('image/bmp', null), + 'bpg' => array('image/bpg', null), 'cb7' => array('application/x-cbr', null), 'cba' => array('application/x-cbr', null), 'cbr' => array('application/x-cbr', null), diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php index 5b69b7cf1a8..26bbca81317 100644 --- a/lib/private/share/helper.php +++ b/lib/private/share/helper.php @@ -28,6 +28,8 @@ namespace OC\Share; +use OC\HintException; + class Helper extends \OC\Share\Constants { /** @@ -217,32 +219,74 @@ class Helper extends \OC\Share\Constants { } /** - * Extracts the necessary remote name from a given link + * Strips away a potential file names and trailing slashes: + * - http://localhost + * - http://localhost/ + * - http://localhost/index.php + * - http://localhost/index.php/s/{shareToken} * - * Strips away a potential file name, to allow - * - user - * - user@localhost - * - user@http://localhost - * - user@http://localhost/ - * - user@http://localhost/index.php - * - user@http://localhost/index.php/s/{shareToken} + * all return: http://localhost * * @param string $shareWith * @return string */ - public static function fixRemoteURLInShareWith($shareWith) { - if (strpos($shareWith, '@')) { - list($user, $remote) = explode('@', $shareWith, 2); + protected static function fixRemoteURL($remote) { + $remote = str_replace('\\', '/', $remote); + if ($fileNamePosition = strpos($remote, '/index.php')) { + $remote = substr($remote, 0, $fileNamePosition); + } + $remote = rtrim($remote, '/'); - $remote = str_replace('\\', '/', $remote); - if ($fileNamePosition = strpos($remote, '/index.php')) { - $remote = substr($remote, 0, $fileNamePosition); - } - $remote = rtrim($remote, '/'); + return $remote; + } + + /** + * split user and remote from federated cloud id + * + * @param string $id + * @return array + * @throws HintException + */ + public static function splitUserRemote($id) { + if (strpos($id, '@') === false) { + $l = \OC::$server->getL10N('core'); + $hint = $l->t('Invalid Federated Cloud ID'); + throw new HintException('Invalid Federated Cloud ID', $hint); + } + + // Find the first character that is not allowed in user names + $id = str_replace('\\', '/', $id); + $posSlash = strpos($id, '/'); + $posColon = strpos($id, ':'); + + if ($posSlash === false && $posColon === false) { + $invalidPos = strlen($id); + } else if ($posSlash === false) { + $invalidPos = $posColon; + } else if ($posColon === false) { + $invalidPos = $posSlash; + } else { + $invalidPos = min($posSlash, $posColon); + } + + // Find the last @ before $invalidPos + $pos = $lastAtPos = 0; + while ($lastAtPos !== false && $lastAtPos <= $invalidPos) { + $pos = $lastAtPos; + $lastAtPos = strpos($id, '@', $pos + 1); + } - $shareWith = $user . '@' . $remote; + if ($pos !== false) { + $user = substr($id, 0, $pos); + $remote = substr($id, $pos + 1); + $remote = self::fixRemoteURL($remote); + if (!empty($user) && !empty($remote)) { + return array($user, $remote); + } } - return rtrim($shareWith, '/'); + $l = \OC::$server->getL10N('core'); + $hint = $l->t('Invalid Federated Cloud ID'); + throw new HintException('Invalid Fededrated Cloud ID', $hint); } } diff --git a/lib/private/share/share.php b/lib/private/share/share.php index 954071fdd6c..71390d99966 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -127,8 +127,8 @@ class Share extends Constants { $cache = false; $view = new \OC\Files\View('/' . $ownerUser . '/files'); - if ($view->file_exists($path)) { - $meta = $view->getFileInfo($path); + $meta = $view->getFileInfo($path); + if ($meta) { $path = substr($meta->getPath(), strlen('/' . $ownerUser . '/files')); } else { // if the file doesn't exists yet we start with the parent folder @@ -554,6 +554,7 @@ class Share extends Constants { * @param string $itemSourceName * @param \DateTime $expirationDate * @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) { @@ -749,7 +750,8 @@ class Share extends Constants { $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(self::TOKEN_LENGTH, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER . \OCP\Security\ISecureRandom::CHAR_DIGITS); - $shareWith = Helper::fixRemoteURLInShareWith($shareWith); + list($user, $remote) = Helper::splitUserRemote($shareWith); + $shareWith = $user . '@' . $remote; $shareId = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, $token, $itemSourceName); $send = false; @@ -1300,8 +1302,8 @@ class Share extends Constants { $hookParams['deletedShares'] = $deletedShares; \OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams); if ((int)$item['share_type'] === \OCP\Share::SHARE_TYPE_REMOTE && \OC::$server->getUserSession()->getUser()) { - $urlParts = explode('@', $item['share_with'], 2); - self::sendRemoteUnshare($urlParts[1], $item['id'], $item['token']); + list(, $remote) = Helper::splitUserRemote($item['share_with']); + self::sendRemoteUnshare($remote, $item['id'], $item['token']); } } @@ -1703,11 +1705,20 @@ class Share extends Constants { $row['permissions'] &= ~\OCP\Constants::PERMISSION_SHARE; } // Add display names to result + $row['share_with_displayname'] = $row['share_with']; if ( isset($row['share_with']) && $row['share_with'] != '' && - isset($row['share_with']) && $row['share_type'] === self::SHARE_TYPE_USER) { + $row['share_type'] === self::SHARE_TYPE_USER) { $row['share_with_displayname'] = \OCP\User::getDisplayName($row['share_with']); - } else { - $row['share_with_displayname'] = $row['share_with']; + } else if(isset($row['share_with']) && $row['share_with'] != '' && + $row['share_type'] === self::SHARE_TYPE_REMOTE) { + $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD']); + foreach ($addressBookEntries as $entry) { + foreach ($entry['CLOUD'] as $cloudID) { + if ($cloudID === $row['share_with']) { + $row['share_with_displayname'] = $entry['FN']; + } + } + } } if ( isset($row['uid_owner']) && $row['uid_owner'] != '') { $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']); @@ -2427,10 +2438,10 @@ class Share extends Constants { */ private static function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner) { - list($user, $remote) = explode('@', $shareWith, 2); + list($user, $remote) = Helper::splitUserRemote($shareWith); if ($user && $remote) { - $url = rtrim($remote, '/') . self::BASE_PATH_TO_SHARE_API . '?format=' . self::RESPONSE_FORMAT; + $url = $remote . self::BASE_PATH_TO_SHARE_API . '?format=' . self::RESPONSE_FORMAT; $local = \OC::$server->getURLGenerator()->getAbsoluteURL('/'); |