diff options
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb')
11 files changed, 107 insertions, 34 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/ErrorCodes.php b/apps/files_external/3rdparty/icewind/smb/src/ErrorCodes.php index 03bd574c185..d36cdaf2c7d 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/ErrorCodes.php +++ b/apps/files_external/3rdparty/icewind/smb/src/ErrorCodes.php @@ -15,7 +15,7 @@ class ErrorCodes { const BadHostName = 'NT_STATUS_BAD_NETWORK_NAME'; const Unsuccessful = 'NT_STATUS_UNSUCCESSFUL'; const ConnectionRefused = 'NT_STATUS_CONNECTION_REFUSED'; - const NoLogonServers = 'NT_STATUS_NO_LOGON_SERVERS'; + const NoLogonServers = 'NT_STATUS_NO_LOGON_SERVERS'; const PathNotFound = 'NT_STATUS_OBJECT_PATH_NOT_FOUND'; const NoSuchFile = 'NT_STATUS_NO_SUCH_FILE'; @@ -26,4 +26,6 @@ class ErrorCodes { const FileIsADirectory = 'NT_STATUS_FILE_IS_A_DIRECTORY'; const NotADirectory = 'NT_STATUS_NOT_A_DIRECTORY'; const SharingViolation = 'NT_STATUS_SHARING_VIOLATION'; + const InvalidParameter = 'NT_STATUS_INVALID_PARAMETER'; + const RevisionMismatch = 'NT_STATUS_REVISION_MISMATCH'; } diff --git a/apps/files_external/3rdparty/icewind/smb/src/Exception/Exception.php b/apps/files_external/3rdparty/icewind/smb/src/Exception/Exception.php index 7ac528198a9..93f2c1b3e2e 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Exception/Exception.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Exception/Exception.php @@ -14,7 +14,7 @@ class Exception extends \Exception { $message .= ' for ' . $path; } - return new Exception($message, $error); + return new Exception($message, is_string($error) ? 0 : $error); } /** diff --git a/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidParameterException.php b/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidParameterException.php new file mode 100644 index 00000000000..163b571183d --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/Exception/InvalidParameterException.php @@ -0,0 +1,10 @@ +<?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 InvalidParameterException extends InvalidRequestException {} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Exception/OutOfSpaceException.php b/apps/files_external/3rdparty/icewind/smb/src/Exception/OutOfSpaceException.php new file mode 100644 index 00000000000..4c5517a1404 --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/Exception/OutOfSpaceException.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 OutOfSpaceException extends InvalidRequestException { +} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Exception/RevisionMismatchException.php b/apps/files_external/3rdparty/icewind/smb/src/Exception/RevisionMismatchException.php new file mode 100644 index 00000000000..e898b5a2347 --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/Exception/RevisionMismatchException.php @@ -0,0 +1,16 @@ +<?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; + +use Throwable; + +class RevisionMismatchException extends Exception { + public function __construct($message = 'Protocol version mismatch', $code = 0, Throwable $previous = null) { + parent::__construct($message, $code, $previous); + } +} diff --git a/apps/files_external/3rdparty/icewind/smb/src/NativeState.php b/apps/files_external/3rdparty/icewind/smb/src/NativeState.php index 7ddce831853..45e0441d252 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/NativeState.php +++ b/apps/files_external/3rdparty/icewind/smb/src/NativeState.php @@ -31,6 +31,7 @@ class NativeState { 17 => '\Icewind\SMB\Exception\AlreadyExistsException', 20 => '\Icewind\SMB\Exception\InvalidTypeException', 21 => '\Icewind\SMB\Exception\InvalidTypeException', + 28 => '\Icewind\SMB\Exception\OutOfSpaceException', 39 => '\Icewind\SMB\Exception\NotEmptyException', 110 => '\Icewind\SMB\Exception\TimedOutException', 111 => '\Icewind\SMB\Exception\ConnectionRefusedException', diff --git a/apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php b/apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php index 6ad565555bf..20ada5cf320 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php +++ b/apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php @@ -9,6 +9,8 @@ namespace Icewind\SMB; +use Icewind\SMB\Exception\Exception; + class NotifyHandler implements INotifyHandler { /** * @var Connection @@ -22,6 +24,12 @@ class NotifyHandler implements INotifyHandler { private $listening = true; + // todo replace with static once <5.6 support is dropped + // see error.h + private static $exceptionMap = [ + ErrorCodes::RevisionMismatch => '\Icewind\SMB\Exception\RevisionMismatchException', + ]; + /** * @param Connection $connection * @param string $path @@ -43,6 +51,7 @@ class NotifyHandler implements INotifyHandler { stream_set_blocking($this->connection->getOutputStream(), 0); $lines = []; while (($line = $this->connection->readLine())) { + $this->checkForError($line); $lines[] = $line; } stream_set_blocking($this->connection->getOutputStream(), 1); @@ -59,6 +68,7 @@ class NotifyHandler implements INotifyHandler { public function listen($callback) { if ($this->listening) { $this->connection->read(function ($line) use ($callback) { + $this->checkForError($line); $change = $this->parseChangeLine($line); if ($change) { return $callback($change); @@ -80,6 +90,13 @@ class NotifyHandler implements INotifyHandler { } } + private function checkForError($line) { + if (substr($line, 0, 16) === 'notify returned ') { + $error = substr($line, 16); + throw Exception::fromMap(self::$exceptionMap, $error, 'Notify is not supported with the used smb version'); + } + } + public function stop() { $this->listening = false; $this->connection->close(); diff --git a/apps/files_external/3rdparty/icewind/smb/src/Parser.php b/apps/files_external/3rdparty/icewind/smb/src/Parser.php index 5cc5acbdf56..3142f9c29e0 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Parser.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Parser.php @@ -30,6 +30,7 @@ class Parser { // todo replace with static once <5.6 support is dropped // see error.h private static $exceptionMap = [ + ErrorCodes::LogonFailure => '\Icewind\SMB\Exception\AuthenticationException', ErrorCodes::PathNotFound => '\Icewind\SMB\Exception\NotFoundException', ErrorCodes::ObjectNotFound => '\Icewind\SMB\Exception\NotFoundException', ErrorCodes::NoSuchFile => '\Icewind\SMB\Exception\NotFoundException', @@ -38,7 +39,8 @@ class Parser { ErrorCodes::DirectoryNotEmpty => '\Icewind\SMB\Exception\NotEmptyException', ErrorCodes::FileIsADirectory => '\Icewind\SMB\Exception\InvalidTypeException', ErrorCodes::NotADirectory => '\Icewind\SMB\Exception\InvalidTypeException', - ErrorCodes::SharingViolation => '\Icewind\SMB\Exception\FileInUseException' + ErrorCodes::SharingViolation => '\Icewind\SMB\Exception\FileInUseException', + ErrorCodes::InvalidParameter => '\Icewind\SMB\Exception\InvalidParameterException' ]; /** diff --git a/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php b/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php index e9349716430..42923f09eda 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php +++ b/apps/files_external/3rdparty/icewind/smb/src/RawConnection.php @@ -7,6 +7,7 @@ namespace Icewind\SMB; +use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\ConnectionException; class RawConnection { @@ -25,6 +26,9 @@ class RawConnection { * * $pipes[0] holds STDIN for smbclient * $pipes[1] holds STDOUT for smbclient + * $pipes[3] holds the authfile for smbclient + * $pipes[4] holds the stream for writing files + * $pipes[5] holds the stream for reading files */ private $pipes; @@ -33,32 +37,44 @@ class RawConnection { */ private $process; - public function __construct($command, $env = array()) { + /** + * @var resource|null $authStream + */ + private $authStream = null; + + private $connected = false; + + public function __construct($command, array $env = []) { $this->command = $command; $this->env = $env; - $this->connect(); } - private function connect() { - $descriptorSpec = array( - 0 => array('pipe', 'r'), // child reads from stdin - 1 => array('pipe', 'w'), // child writes to stdout - 2 => array('pipe', 'w'), // child writes to stderr - 3 => array('pipe', 'r'), // child reads from fd#3 - 4 => array('pipe', 'r'), // child reads from fd#4 - 5 => array('pipe', 'w') // child writes to fd#5 - ); + public function connect() { + if (is_null($this->getAuthStream())) { + throw new ConnectException('Authentication not set before connecting'); + } + + $descriptorSpec = [ + 0 => ['pipe', 'r'], // child reads from stdin + 1 => ['pipe', 'w'], // child writes to stdout + 2 => ['pipe', 'w'], // child writes to stderr + 3 => $this->getAuthStream(), // child reads from fd#3 + 4 => ['pipe', 'r'], // child reads from fd#4 + 5 => ['pipe', 'w'] // child writes to fd#5 + ]; + setlocale(LC_ALL, Server::LOCALE); - $env = array_merge($this->env, array( + $env = array_merge($this->env, [ 'CLI_FORCE_INTERACTIVE' => 'y', // Needed or the prompt isn't displayed!! - 'LC_ALL' => Server::LOCALE, - 'LANG' => Server::LOCALE, - 'COLUMNS' => 8192 // prevent smbclient from line-wrapping it's output - )); + 'LC_ALL' => Server::LOCALE, + 'LANG' => Server::LOCALE, + 'COLUMNS' => 8192 // prevent smbclient from line-wrapping it's output + ]); $this->process = proc_open($this->command, $descriptorSpec, $this->pipes, '/', $env); if (!$this->isValid()) { throw new ConnectionException(); } + $this->connected = true; } /** @@ -129,7 +145,7 @@ class RawConnection { } public function getAuthStream() { - return $this->pipes[3]; + return $this->authStream; } public function getFileInputStream() { @@ -143,14 +159,10 @@ class RawConnection { public function writeAuthentication($user, $password) { $auth = ($password === false) ? "username=$user" - : "username=$user\npassword=$password"; + : "username=$user\npassword=$password\n"; - if (fwrite($this->getAuthStream(), $auth) === false) { - fclose($this->getAuthStream()); - return false; - } - fclose($this->getAuthStream()); - return true; + $this->authStream = fopen('php://temp', 'w+'); + fwrite($this->getAuthStream(), $auth); } public function close($terminate = true) { @@ -163,8 +175,8 @@ class RawConnection { $status = proc_get_status($this->process); $ppid = $status['pid']; $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`); - foreach($pids as $pid) { - if(is_numeric($pid)) { + foreach ($pids as $pid) { + if (is_numeric($pid)) { //9 is the SIGKILL signal posix_kill($pid, 9); } diff --git a/apps/files_external/3rdparty/icewind/smb/src/Server.php b/apps/files_external/3rdparty/icewind/smb/src/Server.php index 12692eb4c6e..21cc605ed1f 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Server.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Server.php @@ -134,6 +134,7 @@ class Server { ); $connection = new RawConnection($command); $connection->writeAuthentication($this->getUser(), $this->getPassword()); + $connection->connect(); $output = $connection->readAll(); $parser = new Parser($this->timezoneProvider); diff --git a/apps/files_external/3rdparty/icewind/smb/src/Share.php b/apps/files_external/3rdparty/icewind/smb/src/Share.php index ba8bbbbb8ca..542eaf0887e 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Share.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Share.php @@ -68,8 +68,9 @@ class Share extends AbstractShare { ); $connection = new Connection($command, $this->parser); $connection->writeAuthentication($this->server->getUser(), $this->server->getPassword()); + $connection->connect(); if (!$connection->isValid()) { - throw new ConnectionException(); + throw new ConnectionException($connection->readLine()); } return $connection; } @@ -88,7 +89,6 @@ class Share extends AbstractShare { protected function reconnect() { $this->connection->reconnect(); - $this->connection->writeAuthentication($this->server->getUser(), $this->server->getPassword()); if (!$this->connection->isValid()) { throw new ConnectionException(); } @@ -318,9 +318,9 @@ class Share extends AbstractShare { $modeString = ''; $modeMap = array( FileInfo::MODE_READONLY => 'r', - FileInfo::MODE_HIDDEN => 'h', - FileInfo::MODE_ARCHIVE => 'a', - FileInfo::MODE_SYSTEM => 's' + FileInfo::MODE_HIDDEN => 'h', + FileInfo::MODE_ARCHIVE => 'a', + FileInfo::MODE_SYSTEM => 's' ); foreach ($modeMap as $modeByte => $string) { if ($mode & $modeByte) { @@ -413,6 +413,7 @@ class Share extends AbstractShare { } $path = str_replace('/', '\\', $path); $path = str_replace('"', '^"', $path); + $path = ltrim($path, '\\'); return '"' . $path . '"'; } |