diff options
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/src/Native')
7 files changed, 0 insertions, 1308 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php deleted file mode 100644 index 0f28c534404..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php +++ /dev/null @@ -1,161 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2014 Robin Appelman <robin@icewind.nl> - * SPDX-License-Identifier: MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\ACL; -use Icewind\SMB\Exception\Exception; -use Icewind\SMB\IFileInfo; - -class NativeFileInfo implements IFileInfo { - /** @var string */ - protected $path; - /** @var string */ - protected $name; - /** @var NativeShare */ - protected $share; - /** @var array{"mode": int, "size": int, "write_time": int}|null */ - protected $attributeCache = null; - - public function __construct(NativeShare $share, string $path, string $name) { - $this->share = $share; - $this->path = $path; - $this->name = $name; - } - - public function getPath(): string { - return $this->path; - } - - public function getName(): string { - return $this->name; - } - - /** - * @return array{"mode": int, "size": int, "write_time": int} - */ - protected function stat(): array { - if (is_null($this->attributeCache)) { - $rawAttributes = explode(',', $this->share->getAttribute($this->path, 'system.dos_attr.*')); - $attributes = []; - foreach ($rawAttributes as $rawAttribute) { - list($name, $value) = explode(':', $rawAttribute); - $name = strtolower($name); - if ($name == 'mode') { - $attributes[$name] = (int)hexdec(substr($value, 2)); - } else { - $attributes[$name] = (int)$value; - } - } - if (!isset($attributes['mode'])) { - throw new Exception("Invalid attribute response"); - } - if (!isset($attributes['size'])) { - throw new Exception("Invalid attribute response"); - } - if (!isset($attributes['write_time'])) { - throw new Exception("Invalid attribute response"); - } - $this->attributeCache = $attributes; - } - return $this->attributeCache; - } - - public function getSize(): int { - $stat = $this->stat(); - return $stat['size']; - } - - public function getMTime(): int { - $stat = $this->stat(); - return $stat['write_time']; - } - - /** - * On "mode": - * - * different smbclient versions seem to return different mode values for 'system.dos_attr.mode' - * - * older versions return the dos permissions mask as defined in `IFileInfo::MODE_*` while - * newer versions return the equivalent unix permission mask. - * - * Since the unix mask doesn't contain the proper hidden/archive/system flags we have to assume them - * as false (except for `hidden` where we use the unix dotfile convention) - */ - - protected function getMode(): int { - $mode = $this->stat()['mode']; - - // Let us ignore the ATTR_NOT_CONTENT_INDEXED for now - $mode &= ~0x00002000; - - return $mode; - } - - public function isDirectory(): bool { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return ($mode & 0x4000 && !($mode & 0x8000)); // 0x4000: unix directory flag shares bits with 0xC000: socket - } else { - return (bool)($mode & IFileInfo::MODE_DIRECTORY); - } - } - - public function isReadOnly(): bool { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return !(bool)($mode & 0x80); // 0x80: owner write permissions - } else { - return (bool)($mode & IFileInfo::MODE_READONLY); - } - } - - public function isHidden(): bool { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return strlen($this->name) > 0 && $this->name[0] === '.'; - } else { - return (bool)($mode & IFileInfo::MODE_HIDDEN); - } - } - - public function isSystem(): bool { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return false; - } else { - return (bool)($mode & IFileInfo::MODE_SYSTEM); - } - } - - public function isArchived(): bool { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return false; - } else { - return (bool)($mode & IFileInfo::MODE_ARCHIVE); - } - } - - /** - * @return ACL[] - */ - public function getAcls(): array { - $acls = []; - $attribute = $this->share->getAttribute($this->path, 'system.nt_sec_desc.acl.*+'); - - foreach (explode(',', $attribute) as $acl) { - list($user, $permissions) = explode(':', $acl, 2); - $user = trim($user, '\\'); - list($type, $flags, $mask) = explode('/', $permissions); - $mask = hexdec($mask); - - $acls[$user] = new ACL((int)$type, (int)$flags, (int)$mask); - } - - return $acls; - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeReadStream.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeReadStream.php deleted file mode 100644 index af1aa49613e..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeReadStream.php +++ /dev/null @@ -1,92 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2014 Robin Appelman <robin@icewind.nl> - * SPDX-License-Identifier: MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\StringBuffer; - -/** - * Stream optimized for read only usage - */ -class NativeReadStream extends NativeStream { - const CHUNK_SIZE = 1048576; // 1MB chunks - - /** @var StringBuffer */ - private $readBuffer; - - public function __construct() { - $this->readBuffer = new StringBuffer(); - } - - /** @var int */ - private $pos = 0; - - public function stream_open($path, $mode, $options, &$opened_path) { - return parent::stream_open($path, $mode, $options, $opened_path); - } - - /** - * Wrap a stream from libsmbclient-php into a regular php stream - * - * @param NativeState $state - * @param resource $smbStream - * @param string $mode - * @param string $url - * @return resource - */ - public static function wrap(NativeState $state, $smbStream, string $mode, string $url) { - return parent::wrapClass($state, $smbStream, $mode, $url, NativeReadStream::class); - } - - public function stream_read($count) { - // php reads 8192 bytes at once - // however due to network latency etc, it's faster to read in larger chunks - // and buffer the result - if (!parent::stream_eof() && $this->readBuffer->remaining() < $count) { - $chunk = parent::stream_read(self::CHUNK_SIZE); - if ($chunk === false) { - return false; - } - $this->readBuffer->push($chunk); - } - - $result = $this->readBuffer->read($count); - - $read = strlen($result); - $this->pos += $read; - - return $result; - } - - public function stream_seek($offset, $whence = SEEK_SET) { - $result = parent::stream_seek($offset, $whence); - if ($result) { - $this->readBuffer->clear(); - $pos = parent::stream_tell(); - if ($pos === false) { - return false; - } - $this->pos = $pos; - } - return $result; - } - - public function stream_eof() { - return $this->readBuffer->remaining() <= 0 && parent::stream_eof(); - } - - public function stream_tell() { - return $this->pos; - } - - public function stream_write($data) { - return false; - } - - public function stream_truncate($size) { - return false; - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeServer.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeServer.php deleted file mode 100644 index 2a9153ad549..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeServer.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2014 Robin Appelman <robin@icewind.nl> - * SPDX-License-Identifier: MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\AbstractServer; -use Icewind\SMB\Exception\AuthenticationException; -use Icewind\SMB\Exception\InvalidHostException; -use Icewind\SMB\IAuth; -use Icewind\SMB\IOptions; -use Icewind\SMB\IShare; -use Icewind\SMB\ISystem; -use Icewind\SMB\ITimeZoneProvider; - -class NativeServer extends AbstractServer { - /** - * @var NativeState - */ - protected $state; - - public function __construct(string $host, IAuth $auth, ISystem $system, ITimeZoneProvider $timeZoneProvider, IOptions $options) { - parent::__construct($host, $auth, $system, $timeZoneProvider, $options); - $this->state = new NativeState(); - } - - protected function connect(): void { - $this->state->init($this->getAuth(), $this->getOptions()); - } - - /** - * @return IShare[] - * @throws AuthenticationException - * @throws InvalidHostException - */ - public function listShares(): array { - $this->connect(); - $shares = []; - $dh = $this->state->opendir('smb://' . $this->getHost()); - while ($share = $this->state->readdir($dh, '')) { - if ($share['type'] === 'file share') { - $shares[] = $this->getShare($share['name']); - } - } - $this->state->closedir($dh, ''); - return $shares; - } - - public function getShare(string $name): IShare { - return new NativeShare($this, $name); - } - - /** - * Check if the smbclient php extension is available - * - * @param ISystem $system - * @return bool - */ - public static function available(ISystem $system): bool { - return $system->libSmbclientAvailable(); - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php deleted file mode 100644 index 50f3bb77305..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php +++ /dev/null @@ -1,362 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2014 Robin Appelman <robin@icewind.nl> - * SPDX-License-Identifier: MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\AbstractShare; -use Icewind\SMB\Exception\AlreadyExistsException; -use Icewind\SMB\Exception\AuthenticationException; -use Icewind\SMB\Exception\ConnectionException; -use Icewind\SMB\Exception\DependencyException; -use Icewind\SMB\Exception\InvalidHostException; -use Icewind\SMB\Exception\InvalidPathException; -use Icewind\SMB\Exception\InvalidResourceException; -use Icewind\SMB\Exception\InvalidTypeException; -use Icewind\SMB\Exception\NotFoundException; -use Icewind\SMB\IFileInfo; -use Icewind\SMB\INotifyHandler; -use Icewind\SMB\IServer; -use Icewind\SMB\Wrapped\Server; -use Icewind\SMB\Wrapped\Share; - -class NativeShare extends AbstractShare { - /** - * @var IServer $server - */ - private $server; - - /** - * @var string $name - */ - private $name; - - /** @var NativeState|null $state */ - private $state = null; - - public function __construct(IServer $server, string $name) { - parent::__construct(); - $this->server = $server; - $this->name = $name; - } - - /** - * @throws ConnectionException - * @throws AuthenticationException - * @throws InvalidHostException - */ - protected function getState(): NativeState { - if ($this->state) { - return $this->state; - } - - $this->state = new NativeState(); - $this->state->init($this->server->getAuth(), $this->server->getOptions()); - return $this->state; - } - - /** - * Get the name of the share - * - * @return string - */ - public function getName(): string { - return $this->name; - } - - private function buildUrl(string $path): string { - $this->verifyPath($path); - $url = sprintf('smb://%s/%s', $this->server->getHost(), $this->name); - if ($path) { - $path = trim($path, '/'); - $url .= '/'; - $url .= implode('/', array_map('rawurlencode', explode('/', $path))); - } - return $url; - } - - /** - * List the content of a remote folder - * - * @param string $path - * @return IFileInfo[] - * - * @throws NotFoundException - * @throws InvalidTypeException - */ - public function dir(string $path): array { - $files = []; - - $dh = $this->getState()->opendir($this->buildUrl($path)); - while ($file = $this->getState()->readdir($dh, $path)) { - $name = $file['name']; - if ($name !== '.' and $name !== '..') { - $fullPath = $path . '/' . $name; - $files [] = new NativeFileInfo($this, $fullPath, $name); - } - } - - $this->getState()->closedir($dh, $path); - return $files; - } - - /** - * @param string $path - * @return IFileInfo - */ - public function stat(string $path): IFileInfo { - $info = new NativeFileInfo($this, $path, self::mb_basename($path)); - - // trigger attribute loading - $info->getSize(); - - return $info; - } - - /** - * Multibyte unicode safe version of basename() - * - * @param string $path - * @link http://php.net/manual/en/function.basename.php#121405 - * @return string - */ - protected static function mb_basename(string $path): string { - if (preg_match('@^.*[\\\\/]([^\\\\/]+)$@s', $path, $matches)) { - return $matches[1]; - } elseif (preg_match('@^([^\\\\/]+)$@s', $path, $matches)) { - return $matches[1]; - } - - return ''; - } - - /** - * Create a folder on the share - * - * @param string $path - * @return bool - * - * @throws NotFoundException - * @throws AlreadyExistsException - */ - public function mkdir(string $path): bool { - return $this->getState()->mkdir($this->buildUrl($path)); - } - - /** - * Remove a folder on the share - * - * @param string $path - * @return bool - * - * @throws NotFoundException - * @throws InvalidTypeException - */ - public function rmdir(string $path): bool { - return $this->getState()->rmdir($this->buildUrl($path)); - } - - /** - * Delete a file on the share - * - * @param string $path - * @return bool - * - * @throws NotFoundException - * @throws InvalidTypeException - */ - public function del(string $path): bool { - return $this->getState()->unlink($this->buildUrl($path)); - } - - /** - * Rename a remote file - * - * @param string $from - * @param string $to - * @return bool - * - * @throws NotFoundException - * @throws AlreadyExistsException - */ - public function rename(string $from, string $to): bool { - return $this->getState()->rename($this->buildUrl($from), $this->buildUrl($to)); - } - - /** - * Upload a local file - * - * @param string $source local file - * @param string $target remove file - * @return bool - * - * @throws NotFoundException - * @throws InvalidTypeException - */ - public function put(string $source, string $target): bool { - $sourceHandle = fopen($source, 'rb'); - $targetUrl = $this->buildUrl($target); - - $targetHandle = $this->getState()->create($targetUrl); - - while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) { - $this->getState()->write($targetHandle, $data, $targetUrl); - } - $this->getState()->close($targetHandle, $targetUrl); - return true; - } - - /** - * Download a remote file - * - * @param string $source remove file - * @param string $target local file - * @return bool - * - * @throws AuthenticationException - * @throws ConnectionException - * @throws InvalidHostException - * @throws InvalidPathException - * @throws InvalidResourceException - */ - public function get(string $source, string $target): bool { - if (!$target) { - throw new InvalidPathException('Invalid target path: Filename cannot be empty'); - } - - $sourceHandle = $this->getState()->open($this->buildUrl($source), 'r'); - - $targetHandle = @fopen($target, 'wb'); - if (!$targetHandle) { - $error = error_get_last(); - if (is_array($error)) { - $reason = $error['message']; - } else { - $reason = 'Unknown error'; - } - $this->getState()->close($sourceHandle, $this->buildUrl($source)); - throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); - } - - while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE, $source)) { - fwrite($targetHandle, $data); - } - $this->getState()->close($sourceHandle, $this->buildUrl($source)); - return true; - } - - /** - * Open a readable stream to a remote file - * - * @param string $source - * @return resource a read only stream with the contents of the remote file - * - * @throws NotFoundException - * @throws InvalidTypeException - */ - public function read(string $source) { - $url = $this->buildUrl($source); - $handle = $this->getState()->open($url, 'r'); - return NativeReadStream::wrap($this->getState(), $handle, 'r', $url); - } - - /** - * Open a writeable stream to a remote file - * Note: This method will truncate the file to 0bytes first - * - * @param string $target - * @return resource a writeable stream - * - * @throws NotFoundException - * @throws InvalidTypeException - */ - public function write(string $target) { - $url = $this->buildUrl($target); - $handle = $this->getState()->create($url); - return NativeWriteStream::wrap($this->getState(), $handle, 'w', $url); - } - - /** - * Open a writeable stream and set the cursor to the end of the stream - * - * @param string $target - * @return resource a writeable stream - * - * @throws NotFoundException - * @throws InvalidTypeException - */ - public function append(string $target) { - $url = $this->buildUrl($target); - $handle = $this->getState()->open($url, "a+"); - return NativeWriteStream::wrap($this->getState(), $handle, "a", $url); - } - - /** - * Get extended attributes for the path - * - * @param string $path - * @param string $attribute attribute to get the info - * @return string the attribute value - */ - public function getAttribute(string $path, string $attribute): string { - return $this->getState()->getxattr($this->buildUrl($path), $attribute); - } - - /** - * Set extended attributes for the given path - * - * @param string $path - * @param string $attribute attribute to get the info - * @param string|int $value - * @return mixed the attribute value - */ - public function setAttribute(string $path, string $attribute, $value) { - if (is_int($value)) { - if ($attribute === 'system.dos_attr.mode') { - $value = '0x' . dechex($value); - } else { - throw new \InvalidArgumentException("Invalid value for attribute"); - } - } - - return $this->getState()->setxattr($this->buildUrl($path), $attribute, $value); - } - - /** - * Set DOS comaptible node mode - * - * @param string $path - * @param int $mode a combination of FileInfo::MODE_READONLY, FileInfo::MODE_ARCHIVE, FileInfo::MODE_SYSTEM and FileInfo::MODE_HIDDEN, FileInfo::NORMAL - * @return mixed - */ - public function setMode(string $path, int $mode) { - return $this->setAttribute($path, 'system.dos_attr.mode', $mode); - } - - /** - * Start smb notify listener - * Note: This is a blocking call - * - * @param string $path - * @return INotifyHandler - */ - public function notify(string $path): INotifyHandler { - // php-smbclient does not support notify (https://github.com/eduardok/libsmbclient-php/issues/29) - // so we use the smbclient based backend for this - if (!Server::available($this->server->getSystem())) { - throw new DependencyException('smbclient not found in path for notify command'); - } - $share = new Share($this->server, $this->getName(), $this->server->getSystem()); - return $share->notify($path); - } - - public function getServer(): IServer { - return $this->server; - } - - public function __destruct() { - unset($this->state); - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php deleted file mode 100644 index 0476f1953a2..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php +++ /dev/null @@ -1,376 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2014 Robin Appelman <robin@icewind.nl> - * SPDX-License-Identifier: MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\Exception\AlreadyExistsException; -use Icewind\SMB\Exception\ConnectionRefusedException; -use Icewind\SMB\Exception\ConnectionResetException; -use Icewind\SMB\Exception\Exception; -use Icewind\SMB\Exception\FileInUseException; -use Icewind\SMB\Exception\ForbiddenException; -use Icewind\SMB\Exception\HostDownException; -use Icewind\SMB\Exception\InvalidArgumentException; -use Icewind\SMB\Exception\InvalidTypeException; -use Icewind\SMB\Exception\ConnectionAbortedException; -use Icewind\SMB\Exception\NoRouteToHostException; -use Icewind\SMB\Exception\NotEmptyException; -use Icewind\SMB\Exception\NotFoundException; -use Icewind\SMB\Exception\OutOfSpaceException; -use Icewind\SMB\Exception\TimedOutException; -use Icewind\SMB\IAuth; -use Icewind\SMB\IOptions; - -/** - * Low level wrapper for libsmbclient-php with error handling - */ -class NativeState { - /** @var resource|null */ - protected $state = null; - - /** @var bool */ - protected $handlerSet = false; - - /** @var bool */ - protected $connected = false; - - /** - * sync the garbage collection cycle - * __deconstruct() of KerberosAuth should not called too soon - * - * @var IAuth|null $auth - */ - protected $auth = null; - - // see error.h - const EXCEPTION_MAP = [ - 1 => ForbiddenException::class, - 2 => NotFoundException::class, - 13 => ForbiddenException::class, - 16 => FileInUseException::class, - 17 => AlreadyExistsException::class, - 20 => InvalidTypeException::class, - 21 => InvalidTypeException::class, - 22 => InvalidArgumentException::class, - 28 => OutOfSpaceException::class, - 39 => NotEmptyException::class, - 103 => ConnectionAbortedException::class, - 104 => ConnectionResetException::class, - 110 => TimedOutException::class, - 111 => ConnectionRefusedException::class, - 112 => HostDownException::class, - 113 => NoRouteToHostException::class - ]; - - protected function handleError(?string $path): void { - /** @var int $error */ - $error = smbclient_state_errno($this->state); - if ($error === 0) { - return; - } - throw Exception::fromMap(self::EXCEPTION_MAP, $error, $path); - } - - /** - * @param mixed $result - * @param string|null $uri - * @throws Exception - */ - protected function testResult($result, ?string $uri): void { - if ($result === false or $result === null) { - // smb://host/share/path - if (is_string($uri) && count(explode('/', $uri, 5)) > 4) { - list(, , , , $path) = explode('/', $uri, 5); - $path = '/' . $path; - } else { - $path = $uri; - } - $this->handleError($path); - } - } - - /** - * @param IAuth $auth - * @param IOptions $options - * @return bool - */ - public function init(IAuth $auth, IOptions $options) { - if ($this->connected) { - return true; - } - /** @var resource $state */ - $state = smbclient_state_new(); - $this->state = $state; - /** @psalm-suppress UnusedFunctionCall */ - smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false); - /** @psalm-suppress UnusedFunctionCall */ - smbclient_option_set($this->state, SMBCLIENT_OPT_TIMEOUT, $options->getTimeout() * 1000); - - if (function_exists('smbclient_client_protocols')) { - smbclient_client_protocols($this->state, $options->getMinProtocol(), $options->getMaxProtocol()); - } - - $auth->setExtraSmbClientOptions($this->state); - - // sync the garbage collection cycle - // __deconstruct() of KerberosAuth should not caled too soon - $this->auth = $auth; - - /** @var bool $result */ - $result = @smbclient_state_init($this->state, $auth->getWorkgroup(), $auth->getUsername(), $auth->getPassword()); - - $this->testResult($result, ''); - $this->connected = true; - return $result; - } - - /** - * @param string $uri - * @return resource - */ - public function opendir(string $uri) { - /** @var resource $result */ - $result = @smbclient_opendir($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param resource $dir - * @param string $path - * @return array{"type": string, "comment": string, "name": string}|false - */ - public function readdir($dir, string $path) { - /** @var array{"type": string, "comment": string, "name": string}|false $result */ - $result = @smbclient_readdir($this->state, $dir); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param resource $dir - * @param string $path - * @return bool - */ - public function closedir($dir, string $path): bool { - /** @var bool $result */ - $result = smbclient_closedir($this->state, $dir); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param string $old - * @param string $new - * @return bool - */ - public function rename(string $old, string $new): bool { - /** @var bool $result */ - $result = @smbclient_rename($this->state, $old, $this->state, $new); - - $this->testResult($result, $new); - return $result; - } - - /** - * @param string $uri - * @return bool - */ - public function unlink(string $uri): bool { - /** @var bool $result */ - $result = @smbclient_unlink($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @param int $mask - * @return bool - */ - public function mkdir(string $uri, int $mask = 0777): bool { - /** @var bool $result */ - $result = @smbclient_mkdir($this->state, $uri, $mask); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @return bool - */ - public function rmdir(string $uri): bool { - /** @var bool $result */ - $result = @smbclient_rmdir($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @return array{"mtime": int, "size": int, "mode": int} - */ - public function stat(string $uri): array { - /** @var array{"mtime": int, "size": int, "mode": int} $result */ - $result = @smbclient_stat($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param resource $file - * @param string $path - * @return array{"mtime": int, "size": int, "mode": int} - */ - public function fstat($file, string $path): array { - /** @var array{"mtime": int, "size": int, "mode": int} $result */ - $result = @smbclient_fstat($this->state, $file); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param string $uri - * @param string $mode - * @param int $mask - * @return resource - */ - public function open(string $uri, string $mode, int $mask = 0666) { - /** @var resource $result */ - $result = @smbclient_open($this->state, $uri, $mode, $mask); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @param int $mask - * @return resource - */ - public function create(string $uri, int $mask = 0666) { - /** @var resource $result */ - $result = @smbclient_creat($this->state, $uri, $mask); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param resource $file - * @param int $bytes - * @param string $path - * @return string - */ - public function read($file, int $bytes, string $path): string { - /** @var string $result */ - $result = @smbclient_read($this->state, $file, $bytes); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param resource $file - * @param string $data - * @param string $path - * @param int|null $length - * @return int - */ - public function write($file, string $data, string $path, ?int $length = null): int { - /** @var int $result */ - $result = @smbclient_write($this->state, $file, $data, $length); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param resource $file - * @param int $offset - * @param int $whence SEEK_SET | SEEK_CUR | SEEK_END - * @param string|null $path - * @return int|false new file offset as measured from the start of the file on success. - */ - public function lseek($file, int $offset, int $whence = SEEK_SET, string $path = null) { - /** @var int|false $result */ - $result = @smbclient_lseek($this->state, $file, $offset, $whence); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param resource $file - * @param int $size - * @param string $path - * @return bool - */ - public function ftruncate($file, int $size, string $path): bool { - /** @var bool $result */ - $result = @smbclient_ftruncate($this->state, $file, $size); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param resource $file - * @param string $path - * @return bool - */ - public function close($file, string $path): bool { - /** @var bool $result */ - $result = @smbclient_close($this->state, $file); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param string $uri - * @param string $key - * @return string - */ - public function getxattr(string $uri, string $key) { - /** @var string $result */ - $result = @smbclient_getxattr($this->state, $uri, $key); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @param string $key - * @param string $value - * @param int $flags - * @return bool - */ - public function setxattr(string $uri, string $key, string $value, int $flags = 0) { - /** @var bool $result */ - $result = @smbclient_setxattr($this->state, $uri, $key, $value, $flags); - - $this->testResult($result, $uri); - return $result; - } - - public function __destruct() { - if ($this->connected) { - if (smbclient_state_free($this->state) === false) { - throw new Exception("Failed to free smb state"); - } - } - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeStream.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeStream.php deleted file mode 100644 index 634b1e39497..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeStream.php +++ /dev/null @@ -1,158 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2014 Robin Appelman <robin@icewind.nl> - * SPDX-License-Identifier: MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\Exception\Exception; -use Icewind\SMB\Exception\InvalidRequestException; -use Icewind\Streams\File; -use InvalidArgumentException; - -abstract class NativeStream implements File { - /** - * @var resource - * @psalm-suppress PropertyNotSetInConstructor - */ - public $context; - - /** - * @var NativeState - * @psalm-suppress PropertyNotSetInConstructor - */ - protected $state; - - /** - * @var resource - * @psalm-suppress PropertyNotSetInConstructor - */ - protected $handle; - - /** - * @var bool - */ - protected $eof = false; - - /** - * @var string - */ - protected $url = ''; - - /** - * Wrap a stream from libsmbclient-php into a regular php stream - * - * @param NativeState $state - * @param resource $smbStream - * @param string $mode - * @param string $url - * @param class-string<NativeStream> $class - * @return resource - */ - protected static function wrapClass(NativeState $state, $smbStream, string $mode, string $url, string $class) { - if (stream_wrapper_register('nativesmb', $class) === false) { - throw new Exception("Failed to register stream wrapper"); - } - $context = stream_context_create([ - 'nativesmb' => [ - 'state' => $state, - 'handle' => $smbStream, - 'url' => $url - ] - ]); - $fh = fopen('nativesmb://', $mode, false, $context); - if (stream_wrapper_unregister('nativesmb') === false) { - throw new Exception("Failed to unregister stream wrapper"); - } - return $fh; - } - - public function stream_close() { - try { - return $this->state->close($this->handle, $this->url); - } catch (\Exception $e) { - return false; - } - } - - public function stream_eof() { - return $this->eof; - } - - public function stream_flush() { - return false; - } - - - public function stream_open($path, $mode, $options, &$opened_path) { - $context = stream_context_get_options($this->context); - if (!isset($context['nativesmb']) || !is_array($context['nativesmb'])) { - throw new InvalidArgumentException("context not set"); - } - $state = $context['nativesmb']['state']; - if (!$state instanceof NativeState) { - throw new InvalidArgumentException("invalid context set"); - } - $this->state = $state; - $handle = $context['nativesmb']['handle']; - if (!is_resource($handle)) { - throw new InvalidArgumentException("invalid context set"); - } - $this->handle = $handle; - $url = $context['nativesmb']['url']; - if (!is_string($url)) { - throw new InvalidArgumentException("invalid context set"); - } - $this->url = $url; - return true; - } - - public function stream_read($count) { - $result = $this->state->read($this->handle, $count, $this->url); - if (strlen($result) < $count) { - $this->eof = true; - } - return $result; - } - - public function stream_seek($offset, $whence = SEEK_SET) { - $this->eof = false; - try { - return $this->state->lseek($this->handle, $offset, $whence, $this->url) !== false; - } catch (InvalidRequestException $e) { - return false; - } - } - - /** - * @return array{"mtime": int, "size": int, "mode": int}|false - */ - public function stream_stat() { - try { - return $this->state->stat($this->url); - } catch (Exception $e) { - return false; - } - } - - public function stream_tell() { - return $this->state->lseek($this->handle, 0, SEEK_CUR, $this->url); - } - - public function stream_write($data) { - return $this->state->write($this->handle, $data, $this->url); - } - - public function stream_truncate($size) { - return $this->state->ftruncate($this->handle, $size, $this->url); - } - - public function stream_set_option($option, $arg1, $arg2) { - return false; - } - - public function stream_lock($operation) { - return false; - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeWriteStream.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeWriteStream.php deleted file mode 100644 index f09c80eec7c..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeWriteStream.php +++ /dev/null @@ -1,95 +0,0 @@ -<?php -/** - * SPDX-FileCopyrightText: 2014 Robin Appelman <robin@icewind.nl> - * SPDX-License-Identifier: MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\StringBuffer; - -/** - * Stream optimized for write only usage - */ -class NativeWriteStream extends NativeStream { - const CHUNK_SIZE = 1048576; // 1MB chunks - - /** @var StringBuffer */ - private $writeBuffer; - - /** @var int */ - private $pos = 0; - - public function __construct() { - $this->writeBuffer = new StringBuffer(); - } - - public function stream_open($path, $mode, $options, &$opened_path): bool { - return parent::stream_open($path, $mode, $options, $opened_path); - } - - /** - * Wrap a stream from libsmbclient-php into a regular php stream - * - * @param NativeState $state - * @param resource $smbStream - * @param string $mode - * @param string $url - * @return resource - */ - public static function wrap(NativeState $state, $smbStream, string $mode, string $url) { - return parent::wrapClass($state, $smbStream, $mode, $url, NativeWriteStream::class); - } - - public function stream_seek($offset, $whence = SEEK_SET) { - $this->flushWrite(); - $result = parent::stream_seek($offset, $whence); - if ($result) { - $pos = parent::stream_tell(); - if ($pos === false) { - return false; - } - $this->pos = $pos; - } - return $result; - } - - private function flushWrite(): void { - parent::stream_write($this->writeBuffer->flush()); - } - - public function stream_write($data) { - $written = $this->writeBuffer->push($data); - $this->pos += $written; - - if ($this->writeBuffer->remaining() >= self::CHUNK_SIZE) { - $this->flushWrite(); - } - - return $written; - } - - public function stream_close() { - try { - $this->flushWrite(); - $flushResult = true; - } catch (\Exception $e) { - $flushResult = false; - } - return parent::stream_close() && $flushResult; - } - - public function stream_tell() { - return $this->pos; - } - - public function stream_read($count) { - return false; - } - - public function stream_truncate($size) { - $this->flushWrite(); - $this->pos = $size; - return parent::stream_truncate($size); - } -} |