diff options
Diffstat (limited to 'apps/files_external/3rdparty/icewind')
5 files changed, 45 insertions, 26 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/AbstractShare.php b/apps/files_external/3rdparty/icewind/smb/src/AbstractShare.php index a5cfe59a3c4..0af03ff5698 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/AbstractShare.php +++ b/apps/files_external/3rdparty/icewind/smb/src/AbstractShare.php @@ -23,4 +23,8 @@ abstract class AbstractShare implements IShare { } } } + + public function setForbiddenChars(array $charList) { + $this->forbiddenCharacters = $charList; + } } diff --git a/apps/files_external/3rdparty/icewind/smb/src/Connection.php b/apps/files_external/3rdparty/icewind/smb/src/Connection.php index c1ebb861711..0196231b082 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Connection.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Connection.php @@ -34,6 +34,15 @@ class Connection extends RawConnection { parent::write($input . PHP_EOL); } + public function clearTillPrompt() { + $this->write(''); + do { + $promptLine = $this->readLine(); + } while (!$this->isPrompt($promptLine)); + $this->write(''); + $this->readLine(); + } + /** * get all unprocessed output from smbclient until the next prompt * diff --git a/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php b/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php index 228d9cd7d2e..9653e6064b2 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php +++ b/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php @@ -34,7 +34,6 @@ class NativeShare extends AbstractShare { parent::__construct(); $this->server = $server; $this->name = $name; - $this->state = new NativeState(); } /** @@ -42,12 +41,14 @@ class NativeShare extends AbstractShare { * @throws \Icewind\SMB\Exception\AuthenticationException * @throws \Icewind\SMB\Exception\InvalidHostException */ - protected function connect() { - if ($this->state and $this->state instanceof NativeShare) { - return; + protected function getState() { + if ($this->state and $this->state instanceof NativeState) { + return $this->state; } + $this->state = new NativeState(); $this->state->init($this->server->getWorkgroup(), $this->server->getUser(), $this->server->getPassword()); + return $this->state; } /** @@ -60,7 +61,6 @@ class NativeShare extends AbstractShare { } private function buildUrl($path) { - $this->connect(); $this->verifyPath($path); $url = sprintf('smb://%s/%s', $this->server->getHost(), $this->name); if ($path) { @@ -83,15 +83,15 @@ class NativeShare extends AbstractShare { public function dir($path) { $files = array(); - $dh = $this->state->opendir($this->buildUrl($path)); - while ($file = $this->state->readdir($dh)) { + $dh = $this->getState()->opendir($this->buildUrl($path)); + while ($file = $this->getState()->readdir($dh)) { $name = $file['name']; if ($name !== '.' and $name !== '..') { $files [] = new NativeFileInfo($this, $path . '/' . $name, $name); } } - $this->state->closedir($dh); + $this->getState()->closedir($dh); return $files; } @@ -104,7 +104,7 @@ class NativeShare extends AbstractShare { } public function getStat($path) { - return $this->state->stat($this->buildUrl($path)); + return $this->getState()->stat($this->buildUrl($path)); } /** @@ -117,7 +117,7 @@ class NativeShare extends AbstractShare { * @throws \Icewind\SMB\Exception\AlreadyExistsException */ public function mkdir($path) { - return $this->state->mkdir($this->buildUrl($path)); + return $this->getState()->mkdir($this->buildUrl($path)); } /** @@ -130,7 +130,7 @@ class NativeShare extends AbstractShare { * @throws \Icewind\SMB\Exception\InvalidTypeException */ public function rmdir($path) { - return $this->state->rmdir($this->buildUrl($path)); + return $this->getState()->rmdir($this->buildUrl($path)); } /** @@ -143,7 +143,7 @@ class NativeShare extends AbstractShare { * @throws \Icewind\SMB\Exception\InvalidTypeException */ public function del($path) { - return $this->state->unlink($this->buildUrl($path)); + return $this->getState()->unlink($this->buildUrl($path)); } /** @@ -157,7 +157,7 @@ class NativeShare extends AbstractShare { * @throws \Icewind\SMB\Exception\AlreadyExistsException */ public function rename($from, $to) { - return $this->state->rename($this->buildUrl($from), $this->buildUrl($to)); + return $this->getState()->rename($this->buildUrl($from), $this->buildUrl($to)); } /** @@ -172,12 +172,12 @@ class NativeShare extends AbstractShare { */ public function put($source, $target) { $sourceHandle = fopen($source, 'rb'); - $targetHandle = $this->state->create($this->buildUrl($target)); + $targetHandle = $this->getState()->create($this->buildUrl($target)); while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) { - $this->state->write($targetHandle, $data); + $this->getState()->write($targetHandle, $data); } - $this->state->close($targetHandle); + $this->getState()->close($targetHandle); return true; } @@ -208,16 +208,16 @@ class NativeShare extends AbstractShare { throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); } - $sourceHandle = $this->state->open($this->buildUrl($source), 'r'); + $sourceHandle = $this->getState()->open($this->buildUrl($source), 'r'); if (!$sourceHandle) { fclose($targetHandle); throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading'); } - while ($data = $this->state->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) { + while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) { fwrite($targetHandle, $data); } - $this->state->close($sourceHandle); + $this->getState()->close($sourceHandle); return true; } @@ -232,8 +232,8 @@ class NativeShare extends AbstractShare { */ public function read($source) { $url = $this->buildUrl($source); - $handle = $this->state->open($url, 'r'); - return NativeReadStream::wrap($this->state, $handle, 'r', $url); + $handle = $this->getState()->open($url, 'r'); + return NativeReadStream::wrap($this->getState(), $handle, 'r', $url); } /** @@ -247,8 +247,8 @@ class NativeShare extends AbstractShare { */ public function write($source) { $url = $this->buildUrl($source); - $handle = $this->state->create($url); - return NativeWriteStream::wrap($this->state, $handle, 'w', $url); + $handle = $this->getState()->create($url); + return NativeWriteStream::wrap($this->getState(), $handle, 'w', $url); } /** @@ -259,7 +259,7 @@ class NativeShare extends AbstractShare { * @return string the attribute value */ public function getAttribute($path, $attribute) { - return $this->state->getxattr($this->buildUrl($path), $attribute); + return $this->getState()->getxattr($this->buildUrl($path), $attribute); } /** @@ -276,7 +276,7 @@ class NativeShare extends AbstractShare { $value = '0x' . dechex($value); } - return $this->state->setxattr($this->buildUrl($path), $attribute, $value); + return $this->getState()->setxattr($this->buildUrl($path), $attribute, $value); } /** diff --git a/apps/files_external/3rdparty/icewind/smb/src/NativeState.php b/apps/files_external/3rdparty/icewind/smb/src/NativeState.php index 45e0441d252..036a0255048 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/NativeState.php +++ b/apps/files_external/3rdparty/icewind/smb/src/NativeState.php @@ -10,7 +10,7 @@ namespace Icewind\SMB; use Icewind\SMB\Exception\Exception; /** - * Low level wrapper for libsmbclient-php for error handling + * Low level wrapper for libsmbclient-php with error handling */ class NativeState { /** @@ -28,9 +28,11 @@ class NativeState { 1 => '\Icewind\SMB\Exception\ForbiddenException', 2 => '\Icewind\SMB\Exception\NotFoundException', 13 => '\Icewind\SMB\Exception\ForbiddenException', + 16 => '\Icewind\SMB\Exception\FileInUseException', 17 => '\Icewind\SMB\Exception\AlreadyExistsException', 20 => '\Icewind\SMB\Exception\InvalidTypeException', 21 => '\Icewind\SMB\Exception\InvalidTypeException', + 22 => '\Icewind\SMB\Exception\InvalidArgumentException', 28 => '\Icewind\SMB\Exception\OutOfSpaceException', 39 => '\Icewind\SMB\Exception\NotEmptyException', 110 => '\Icewind\SMB\Exception\TimedOutException', @@ -71,6 +73,7 @@ class NativeState { return true; } $this->state = smbclient_state_new(); + smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false); $result = @smbclient_state_init($this->state, $workGroup, $user, $password); $this->testResult($result, ''); diff --git a/apps/files_external/3rdparty/icewind/smb/src/Share.php b/apps/files_external/3rdparty/icewind/smb/src/Share.php index 542eaf0887e..8f1dace2be2 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Share.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Share.php @@ -72,6 +72,8 @@ class Share extends AbstractShare { if (!$connection->isValid()) { throw new ConnectionException($connection->readLine()); } + // some versions of smbclient add a help message in first of the first prompt + $connection->clearTillPrompt(); return $connection; } @@ -125,6 +127,7 @@ class Share extends AbstractShare { //check output for errors $this->parseOutput($output, $path); $output = $this->execute('dir'); + $this->execute('cd /'); return $this->parser->parseDir($output, $path); |