mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
fixes
This commit is contained in:
parent
abfd1eb360
commit
9d57f5aad9
4 changed files with 317 additions and 19 deletions
4
.github/workflows/ci.yaml
vendored
4
.github/workflows/ci.yaml
vendored
|
|
@ -197,7 +197,7 @@ jobs:
|
|||
run: |
|
||||
DC_IP=$(docker inspect dc --format '{{.NetworkSettings.IPAddress}}')
|
||||
LIST=$(docker run --rm --name client -v /tmp/shared:/shared --dns $DC_IP --hostname client.domain.test icewind1991/samba-krb-test-client \
|
||||
curl -s --negotiate -u testuser@DOMAIN.TEST: --delegation always http://httpd.domain.test/example-apache-kerberos.php)
|
||||
curl -s --negotiate -u testuser@DOMAIN.TEST: --delegation always http://httpd.domain.test/example-sso-kerberos.php)
|
||||
echo $LIST
|
||||
LIST=$(echo $LIST | tr -d '[:space:]')
|
||||
[[ $LIST == "test.txt" ]]
|
||||
|
|
@ -218,6 +218,8 @@ jobs:
|
|||
- "7.3"
|
||||
- "7.4"
|
||||
- "8.0"
|
||||
- "8.1"
|
||||
- "8.2"
|
||||
|
||||
steps:
|
||||
- name: krb5-dev
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
>
|
||||
<stubs>
|
||||
<file name="tests/krb.phpstub" preloadClasses="true"/>
|
||||
<file name="tests/smbclient.phpstub" preloadClasses="true"/>
|
||||
</stubs>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
namespace Icewind\SMB\Native;
|
||||
|
||||
use Icewind\SMB\Exception\AlreadyExistsException;
|
||||
use Icewind\SMB\Exception\ConnectionException;
|
||||
use Icewind\SMB\Exception\ConnectionRefusedException;
|
||||
use Icewind\SMB\Exception\ConnectionResetException;
|
||||
use Icewind\SMB\Exception\Exception;
|
||||
|
|
@ -32,9 +33,6 @@ class NativeState {
|
|||
/** @var resource|null */
|
||||
protected $state = null;
|
||||
|
||||
/** @var bool */
|
||||
protected $handlerSet = false;
|
||||
|
||||
/** @var bool */
|
||||
protected $connected = false;
|
||||
|
||||
|
|
@ -67,7 +65,9 @@ class NativeState {
|
|||
];
|
||||
|
||||
protected function handleError(?string $path): void {
|
||||
/** @var int $error */
|
||||
if (!$this->state) {
|
||||
return;
|
||||
}
|
||||
$error = smbclient_state_errno($this->state);
|
||||
if ($error === 0) {
|
||||
return;
|
||||
|
|
@ -120,7 +120,6 @@ class NativeState {
|
|||
// __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, '');
|
||||
|
|
@ -133,6 +132,9 @@ class NativeState {
|
|||
* @return resource
|
||||
*/
|
||||
public function opendir(string $uri) {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var resource $result */
|
||||
$result = @smbclient_opendir($this->state, $uri);
|
||||
|
||||
|
|
@ -146,6 +148,9 @@ class NativeState {
|
|||
* @return array{"type": string, "comment": string, "name": string}|false
|
||||
*/
|
||||
public function readdir($dir, string $path) {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var array{"type": string, "comment": string, "name": string}|false $result */
|
||||
$result = @smbclient_readdir($this->state, $dir);
|
||||
|
||||
|
|
@ -159,8 +164,10 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function closedir($dir, string $path): bool {
|
||||
/** @var bool $result */
|
||||
$result = smbclient_closedir($this->state, $dir);
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
$result = @smbclient_closedir($this->state, $dir);
|
||||
|
||||
$this->testResult($result, $path);
|
||||
return $result;
|
||||
|
|
@ -172,7 +179,9 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function rename(string $old, string $new): bool {
|
||||
/** @var bool $result */
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
$result = @smbclient_rename($this->state, $old, $this->state, $new);
|
||||
|
||||
$this->testResult($result, $new);
|
||||
|
|
@ -184,7 +193,9 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function unlink(string $uri): bool {
|
||||
/** @var bool $result */
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
$result = @smbclient_unlink($this->state, $uri);
|
||||
|
||||
$this->testResult($result, $uri);
|
||||
|
|
@ -197,7 +208,9 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function mkdir(string $uri, int $mask = 0777): bool {
|
||||
/** @var bool $result */
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
$result = @smbclient_mkdir($this->state, $uri, $mask);
|
||||
|
||||
$this->testResult($result, $uri);
|
||||
|
|
@ -209,7 +222,9 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function rmdir(string $uri): bool {
|
||||
/** @var bool $result */
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
$result = @smbclient_rmdir($this->state, $uri);
|
||||
|
||||
$this->testResult($result, $uri);
|
||||
|
|
@ -221,6 +236,9 @@ class NativeState {
|
|||
* @return array{"mtime": int, "size": int, "mode": int}
|
||||
*/
|
||||
public function stat(string $uri): array {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var array{"mtime": int, "size": int, "mode": int} $result */
|
||||
$result = @smbclient_stat($this->state, $uri);
|
||||
|
||||
|
|
@ -234,6 +252,9 @@ class NativeState {
|
|||
* @return array{"mtime": int, "size": int, "mode": int}
|
||||
*/
|
||||
public function fstat($file, string $path): array {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var array{"mtime": int, "size": int, "mode": int} $result */
|
||||
$result = @smbclient_fstat($this->state, $file);
|
||||
|
||||
|
|
@ -248,6 +269,9 @@ class NativeState {
|
|||
* @return resource
|
||||
*/
|
||||
public function open(string $uri, string $mode, int $mask = 0666) {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var resource $result */
|
||||
$result = @smbclient_open($this->state, $uri, $mode, $mask);
|
||||
|
||||
|
|
@ -261,6 +285,9 @@ class NativeState {
|
|||
* @return resource
|
||||
*/
|
||||
public function create(string $uri, int $mask = 0666) {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var resource $result */
|
||||
$result = @smbclient_creat($this->state, $uri, $mask);
|
||||
|
||||
|
|
@ -275,6 +302,9 @@ class NativeState {
|
|||
* @return string
|
||||
*/
|
||||
public function read($file, int $bytes, string $path): string {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var string $result */
|
||||
$result = @smbclient_read($this->state, $file, $bytes);
|
||||
|
||||
|
|
@ -290,10 +320,19 @@ class NativeState {
|
|||
* @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);
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
if ($length) {
|
||||
$result = @smbclient_write($this->state, $file, $data, $length);
|
||||
} else {
|
||||
$result = @smbclient_write($this->state, $file, $data);
|
||||
}
|
||||
|
||||
$this->testResult($result, $path);
|
||||
if ($result === false) {
|
||||
return 0;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -302,10 +341,18 @@ class NativeState {
|
|||
* @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.
|
||||
*
|
||||
* @return false|int 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 */
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
// psalm doesn't think int|false == int|false for some reason, so we do a needless annotation to help it out
|
||||
/**
|
||||
* @psalm-suppress UnnecessaryVarAnnotation
|
||||
* @var int|false $result
|
||||
*/
|
||||
$result = @smbclient_lseek($this->state, $file, $offset, $whence);
|
||||
|
||||
$this->testResult($result, $path);
|
||||
|
|
@ -319,7 +366,9 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function ftruncate($file, int $size, string $path): bool {
|
||||
/** @var bool $result */
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
$result = @smbclient_ftruncate($this->state, $file, $size);
|
||||
|
||||
$this->testResult($result, $path);
|
||||
|
|
@ -332,7 +381,9 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function close($file, string $path): bool {
|
||||
/** @var bool $result */
|
||||
if (!$this->state) {
|
||||
return false;
|
||||
}
|
||||
$result = @smbclient_close($this->state, $file);
|
||||
|
||||
$this->testResult($result, $path);
|
||||
|
|
@ -345,6 +396,9 @@ class NativeState {
|
|||
* @return string
|
||||
*/
|
||||
public function getxattr(string $uri, string $key) {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var string $result */
|
||||
$result = @smbclient_getxattr($this->state, $uri, $key);
|
||||
|
||||
|
|
@ -360,6 +414,9 @@ class NativeState {
|
|||
* @return bool
|
||||
*/
|
||||
public function setxattr(string $uri, string $key, string $value, int $flags = 0) {
|
||||
if (!$this->state) {
|
||||
throw new ConnectionException("Not connected");
|
||||
}
|
||||
/** @var bool $result */
|
||||
$result = @smbclient_setxattr($this->state, $uri, $key, $value, $flags);
|
||||
|
||||
|
|
@ -368,7 +425,7 @@ class NativeState {
|
|||
}
|
||||
|
||||
public function __destruct() {
|
||||
if ($this->connected) {
|
||||
if ($this->connected && $this->state) {
|
||||
if (smbclient_state_free($this->state) === false) {
|
||||
throw new Exception("Failed to free smb state");
|
||||
}
|
||||
|
|
|
|||
238
tests/smbclient.phpstub
Normal file
238
tests/smbclient.phpstub
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @generate-function-entries
|
||||
* @generate-legacy-arginfo
|
||||
*/
|
||||
|
||||
function smbclient_version(): string {
|
||||
}
|
||||
|
||||
function smbclient_library_version(): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|resource
|
||||
*/
|
||||
function smbclient_state_new() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_state_init($state, string $workgroup = null, string $user = null, string $password = null): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_state_errno($state): int {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_state_free($state): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @return mixed
|
||||
*/
|
||||
function smbclient_option_get($state, int $option) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function smbclient_option_set($state, int $option, $value) {
|
||||
}
|
||||
|
||||
|
||||
#if HAVE_SMBC_SETOPTIONPROTOCOLS
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function smbclient_client_protocols($state, string $minproto = null, string $maxproto = null): bool {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @return false|resource
|
||||
*/
|
||||
function smbclient_opendir($state, string $path) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $dir
|
||||
*/
|
||||
function smbclient_readdir($state, $dir): false|array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $dir
|
||||
*/
|
||||
function smbclient_closedir($state, $dir): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @return false|resource
|
||||
*/
|
||||
function smbclient_stat($state, string $path): false|array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $file
|
||||
*/
|
||||
function smbclient_fstat($state, $file): false|array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @return false|resource
|
||||
*/
|
||||
function smbclient_open($state, string $path, string $flags, int $mode = 0666) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @return false|resource
|
||||
*/
|
||||
function smbclient_creat($state, string $path, int $mode = 0666) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $file
|
||||
*/
|
||||
function smbclient_read($state, $file, int $count): false|string {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $file
|
||||
*/
|
||||
function smbclient_close($state, $file): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_mkdir($state, string $path, int $mode = 0666): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_rmdir($state, string $path): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $oldstate
|
||||
* @param resource $newstate
|
||||
*/
|
||||
function smbclient_rename($oldstate, string $oldpath, $newstate, string $newpath): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $file
|
||||
*/
|
||||
function smbclient_write($state, $file, string $buffer, int $count = 0): false|int {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_unlink($state, string $path): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $file
|
||||
*/
|
||||
function smbclient_lseek($state, $file, int $offset, int $whence): false|int {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $file
|
||||
*/
|
||||
function smbclient_ftruncate($state, $file, int $offset): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_chmod($state, string $path, int $mode): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_utimes($state, string $path, int $mtime = -1, int $atime = -1): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_listxattr($state, string $path): false|array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_getxattr($state, string $path, string $name): false|string {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_setxattr($state, string $path, string $name, string $value, int $flags = 0): false|string {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
*/
|
||||
function smbclient_removexattr($state, string $path, string $name): bool {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @return false|resource
|
||||
*/
|
||||
function smbclient_statvfs($state, string $path): false|array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $state
|
||||
* @param resource $file
|
||||
*/
|
||||
function smbclient_fstatvfs($state, $file): false|array {
|
||||
}
|
||||
|
||||
const SMBCLIENT_OPT_OPEN_SHAREMODE = 1;
|
||||
const SMBCLIENT_OPT_ENCRYPT_LEVEL = 2;
|
||||
const SMBCLIENT_OPT_CASE_SENSITIVE = 3;
|
||||
const SMBCLIENT_OPT_BROWSE_MAX_LMB_COUNT = 4;
|
||||
const SMBCLIENT_OPT_URLENCODE_READDIR_ENTRIES = 5;
|
||||
const SMBCLIENT_OPT_USE_KERBEROS = 6;
|
||||
const SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS = 7;
|
||||
const SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN = 8;
|
||||
const SMBCLIENT_OPT_USE_CCACHE = 9;
|
||||
const SMBCLIENT_OPT_USE_NT_HASH = 10;
|
||||
const SMBCLIENT_OPT_NETBIOS_NAME = 11;
|
||||
const SMBCLIENT_OPT_WORKGROUP = 12;
|
||||
const SMBCLIENT_OPT_USER = 13;
|
||||
const SMBCLIENT_OPT_PORT = 14;
|
||||
const SMBCLIENT_OPT_TIMEOUT = 15;
|
||||
Loading…
Add table
Add a link
Reference in a new issue