diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-02-09 17:09:30 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-02-09 17:09:30 +0100 |
commit | 3982c8f87a98b58689e1526425ac5d559736fdcd (patch) | |
tree | 4304c871e56f0fb887a9dee74b5fa9503eb8662c /apps/files_external/3rdparty/icewind | |
parent | 29820176825c41acef30fa6942922aeb36cfcec3 (diff) | |
download | nextcloud-server-3982c8f87a98b58689e1526425ac5d559736fdcd.tar.gz nextcloud-server-3982c8f87a98b58689e1526425ac5d559736fdcd.zip |
update icewind/smb to 1.0.5
Diffstat (limited to 'apps/files_external/3rdparty/icewind')
11 files changed, 167 insertions, 23 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/composer.json b/apps/files_external/3rdparty/icewind/smb/composer.json index 593eb728716..2e1fd35f7a6 100644 --- a/apps/files_external/3rdparty/icewind/smb/composer.json +++ b/apps/files_external/3rdparty/icewind/smb/composer.json @@ -13,7 +13,8 @@ "icewind/streams": "0.2.*" }, "require-dev": { - "satooshi/php-coveralls" : "dev-master" + "satooshi/php-coveralls" : "v1.0.0", + "phpunit/phpunit": "^4.8" }, "autoload" : { "psr-4": { diff --git a/apps/files_external/3rdparty/icewind/smb/src/Connection.php b/apps/files_external/3rdparty/icewind/smb/src/Connection.php index c857398c327..f48dcb766e4 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Connection.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Connection.php @@ -39,13 +39,22 @@ class Connection extends RawConnection { if (!$this->isValid()) { throw new ConnectionException('Connection not valid'); } - $line = $this->readLine(); //first line is prompt - $this->checkConnectionError($line); + $promptLine = $this->readLine(); //first line is prompt + $this->checkConnectionError($promptLine); $output = array(); $line = $this->readLine(); if ($line === false) { - throw new ConnectException('Unknown error'); + if ($promptLine) { //maybe we have some error we missed on the previous line + throw new ConnectException('Unknown error (' . $promptLine . ')'); + } else { + $error = $this->readError(); // maybe something on stderr + if ($error) { + throw new ConnectException('Unknown error (' . $error . ')'); + } else { + throw new ConnectException('Unknown error'); + } + } } $length = mb_strlen(self::DELIMITER); while (mb_substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter diff --git a/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidRequestException.php b/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidRequestException.php index 0dccd8b909e..882bf1677bf 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidRequestException.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidRequestException.php @@ -18,7 +18,10 @@ class InvalidRequestException extends Exception { * @param int $code */ public function __construct($path, $code = 0) { - parent::__construct('Invalid request for ' . $path, $code); + $class = get_class($this); + $parts = explode('\\', $class); + $baseName = array_pop($parts); + parent::__construct('Invalid request for ' . $path . ' (' . $baseName . ')', $code); $this->path = $path; } diff --git a/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidResourceException.php b/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidResourceException.php new file mode 100644 index 00000000000..b5fdb851cab --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidResourceException.php @@ -0,0 +1,11 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Licensed under the MIT license: + * http://opensource.org/licenses/MIT + */ + +namespace Icewind\SMB\Exception; + +class InvalidResourceException extends Exception { +} diff --git a/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php b/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php index 1f1d225c00a..0b184fd585c 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php +++ b/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php @@ -7,6 +7,9 @@ namespace Icewind\SMB; +use Icewind\SMB\Exception\InvalidPathException; +use Icewind\SMB\Exception\InvalidResourceException; + class NativeShare extends AbstractShare { /** * @var Server $server @@ -193,11 +196,30 @@ class NativeShare extends AbstractShare { * * @throws \Icewind\SMB\Exception\NotFoundException * @throws \Icewind\SMB\Exception\InvalidTypeException + * @throws \Icewind\SMB\Exception\InvalidPathException + * @throws \Icewind\SMB\Exception\InvalidResourceException */ public function get($source, $target) { + if (!$target) { + throw new InvalidPathException('Invalid target path: Filename cannot be empty'); + } + $targetHandle = @fopen($target, 'wb'); + if (!$targetHandle) { + $error = error_get_last(); + if (is_array($error)) { + $reason = $error['message']; + } else { + $reason = 'Unknown error'; + } + throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); + } + $this->connect(); $sourceHandle = $this->state->open($this->buildUrl($source), 'r'); - $targetHandle = fopen($target, 'wb'); + if (!$sourceHandle) { + fclose($targetHandle); + throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading'); + } while ($data = $this->state->read($sourceHandle, 4096)) { fwrite($targetHandle, $data); diff --git a/apps/files_external/3rdparty/icewind/smb/src/Parser.php b/apps/files_external/3rdparty/icewind/smb/src/Parser.php index 6af70143c52..fc1d7f283a8 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Parser.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Parser.php @@ -11,6 +11,7 @@ use Icewind\SMB\Exception\AccessDeniedException; use Icewind\SMB\Exception\AlreadyExistsException; use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\FileInUseException; +use Icewind\SMB\Exception\InvalidResourceException; use Icewind\SMB\Exception\InvalidTypeException; use Icewind\SMB\Exception\NotEmptyException; use Icewind\SMB\Exception\NotFoundException; @@ -42,6 +43,13 @@ class Parser { $error = $part; } } + + $notFoundMsg = 'Error opening local file '; + if (substr($output[0], 0, strlen($notFoundMsg)) === $notFoundMsg) { + $localPath = substr($output[0], strlen($notFoundMsg)); + throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing'); + } + switch ($error) { case ErrorCodes::PathNotFound: case ErrorCodes::ObjectNotFound: diff --git a/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php b/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php index 15478511a72..88ab046ef38 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php +++ b/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php @@ -95,6 +95,15 @@ class RawConnection { } /** + * read a line of output + * + * @return string + */ + public function readError() { + return trim(stream_get_line($this->getErrorStream(), 4086)); + } + + /** * get all output until the process closes * * @return array diff --git a/apps/files_external/3rdparty/icewind/smb/src/Server.php b/apps/files_external/3rdparty/icewind/smb/src/Server.php index bbc0475d5e4..25f17201397 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Server.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Server.php @@ -11,7 +11,6 @@ use Icewind\SMB\Exception\AuthenticationException; use Icewind\SMB\Exception\InvalidHostException; class Server { - const CLIENT = 'smbclient'; const LOCALE = 'en_US.UTF-8'; /** @@ -35,6 +34,16 @@ class Server { protected $workgroup; /** + * @var \Icewind\SMB\System + */ + private $system; + + /** + * @var TimeZoneProvider + */ + private $timezoneProvider; + + /** * Check if the smbclient php extension is available * * @return bool @@ -54,6 +63,8 @@ class Server { $this->user = $user; $this->workgroup = $workgroup; $this->password = $password; + $this->system = new System(); + $this->timezoneProvider = new TimeZoneProvider($host, $this->system); } /** @@ -115,8 +126,12 @@ class Server { */ public function listShares() { $workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : ''; - $command = Server::CLIENT . $workgroupArgument . ' --authentication-file=/proc/self/fd/3' . - ' -gL ' . escapeshellarg($this->getHost()); + $command = sprintf('%s %s --authentication-file=%s -gL %s', + $this->system->getSmbclientPath(), + $workgroupArgument, + System::getFD(3), + escapeshellarg($this->getHost()) + ); $connection = new RawConnection($command); $connection->writeAuthentication($this->getUser(), $this->getPassword()); $output = $connection->readAll(); @@ -166,7 +181,6 @@ class Server { * @return string */ public function getTimeZone() { - $command = 'net time zone -S ' . escapeshellarg($this->getHost()); - return exec($command); + return $this->timezoneProvider->get(); } } diff --git a/apps/files_external/3rdparty/icewind/smb/src/Share.php b/apps/files_external/3rdparty/icewind/smb/src/Share.php index d9ab729025d..694bd30bd0d 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Share.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Share.php @@ -35,6 +35,11 @@ class Share extends AbstractShare { protected $parser; /** + * @var \Icewind\SMB\System + */ + private $system; + + /** * @param Server $server * @param string $name */ @@ -42,7 +47,8 @@ class Share extends AbstractShare { parent::__construct(); $this->server = $server; $this->name = $name; - $this->parser = new Parser(new TimeZoneProvider($this->server->getHost())); + $this->system = new System(); + $this->parser = new Parser(new TimeZoneProvider($this->server->getHost(), $this->system)); } /** @@ -55,9 +61,10 @@ class Share extends AbstractShare { return; } $workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : ''; - $command = sprintf('%s %s --authentication-file=/proc/self/fd/3 %s', - Server::CLIENT, + $command = sprintf('%s %s --authentication-file=%s %s', + $this->system->getSmbclientPath(), $workgroupArgument, + System::getFD(3), escapeshellarg('//' . $this->server->getHost() . '/' . $this->name) ); $this->connection = new Connection($command); @@ -257,14 +264,15 @@ class Share extends AbstractShare { // since returned stream is closed by the caller we need to create a new instance // since we can't re-use the same file descriptor over multiple calls $workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : ''; - $command = sprintf('%s %s --authentication-file=/proc/self/fd/3 %s', - Server::CLIENT, + $command = sprintf('%s %s --authentication-file=%s %s', + $this->system->getSmbclientPath(), $workgroupArgument, + System::getFD(3), escapeshellarg('//' . $this->server->getHost() . '/' . $this->name) ); $connection = new Connection($command); $connection->writeAuthentication($this->server->getUser(), $this->server->getPassword()); - $connection->write('get ' . $source . ' /proc/self/fd/5'); + $connection->write('get ' . $source . ' ' . System::getFD(5)); $connection->write('exit'); $fh = $connection->getFileOutputStream(); stream_context_set_option($fh, 'file', 'connection', $connection); @@ -285,16 +293,17 @@ class Share extends AbstractShare { // since returned stream is closed by the caller we need to create a new instance // since we can't re-use the same file descriptor over multiple calls $workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : ''; - $command = sprintf('%s %s --authentication-file=/proc/self/fd/3 %s', - Server::CLIENT, + $command = sprintf('%s %s --authentication-file=%s %s', + $this->system->getSmbclientPath(), $workgroupArgument, + System::getFD(3), escapeshellarg('//' . $this->server->getHost() . '/' . $this->name) ); $connection = new Connection($command); $connection->writeAuthentication($this->server->getUser(), $this->server->getPassword()); $fh = $connection->getFileInputStream(); - $connection->write('put /proc/self/fd/4 ' . $target); + $connection->write('put ' . System::getFD(4) . ' ' . $target); $connection->write('exit'); // use a close callback to ensure the upload is finished before continuing diff --git a/apps/files_external/3rdparty/icewind/smb/src/System.php b/apps/files_external/3rdparty/icewind/smb/src/System.php new file mode 100644 index 00000000000..192a0b3877d --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/System.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Licensed under the MIT license: + * http://opensource.org/licenses/MIT + */ + +namespace Icewind\SMB; + +use Icewind\SMB\Exception\Exception; + +class System { + private $smbclient; + + private $net; + + public static function getFD($num) { + $folders = array( + '/proc/self/fd', + '/dev/fd' + ); + foreach ($folders as $folder) { + if (file_exists($folder)) { + return $folder . '/' . $num; + } + } + throw new Exception('Cant find file descriptor path'); + } + + public function getSmbclientPath() { + if (!$this->smbclient) { + $this->smbclient = trim(`which smbclient`); + } + return $this->smbclient; + } + + public function getNetPath() { + if (!$this->net) { + $this->net = trim(`which net`); + } + return $this->net; + } +} diff --git a/apps/files_external/3rdparty/icewind/smb/src/TimeZoneProvider.php b/apps/files_external/3rdparty/icewind/smb/src/TimeZoneProvider.php index 22406a4f956..86d7859a6f7 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/TimeZoneProvider.php +++ b/apps/files_external/3rdparty/icewind/smb/src/TimeZoneProvider.php @@ -19,16 +19,31 @@ class TimeZoneProvider { private $timeZone; /** + * @var System + */ + private $system; + + /** * @param string $host + * @param System $system */ - function __construct($host) { + function __construct($host, System $system) { $this->host = $host; + $this->system = $system; } public function get() { if (!$this->timeZone) { - $command = 'net time zone -S ' . escapeshellarg($this->host); - $this->timeZone = exec($command); + $net = $this->system->getNetPath(); + if ($net) { + $command = sprintf('%s time zone -S %s', + $net, + escapeshellarg($this->host) + ); + $this->timeZone = exec($command); + } else { // fallback to server timezone + $this->timeZone = date_default_timezone_get(); + } } return $this->timeZone; } |