icewind1991 / SMB

PHP wrapper for smbclient
MIT License
135 stars 54 forks source link

Malformed state response from server #109

Open MatthiasKuehneEllerhold opened 3 years ago

MatthiasKuehneEllerhold commented 3 years ago

Calling $share->stat('my/directory') returns this error: "Malformed state response from server"

In fact $output is empty here! We're using the smbclient Backend, calling it manually returns correct data:

# smbclient -U USER -W workgroup \\\\server\\share
smb: \> allinfo "my/directory.not-exists"
NT_STATUS_OBJECT_NAME_NOT_FOUND getting alt name for \my/directory.not-exists

We're using the smbclient backend. Neither 4.9.5 (debian buster standard) nor 4.14.8 (van-belle repo) works. The server is an old Mac OS.

This problem only occurs on version 3.5.0 & 3.5.1! Version 3.4.1 is fine!

MatthiasKuehneEllerhold commented 2 years ago

The same error now has occured with a debian server with Samba 4.14.11 auf! Downgrading to 3.4.1 works here too!

An additional error message was logged:

PHP Notice:  Undefined index: attributes in /var/www/vendor/icewind/smb/src/Wrapped/Parser.php on line 155
jd1 commented 2 years ago

Same issue here. I'm using Nextcloud with external storage via SMB. Nextcloud uses icewind to access smbclient. I have smbclient 4.13.13 installed and there is no version 3.4.1 available on Ubuntu 20.04. So I can't downgrade it.

The Samba server is installed on FreeBSD and has version 4.13.17.

I can reproduce the issue if I try to to call stat() on a file which doesn't exist. If the file exists, all information are already present can be fetched by the dir command: https://github.com/icewind1991/SMB/blob/9132f32aa075d94693bd3caf646c92fde48dcfbe/src/Wrapped/Share.php#L195-L204 But if the file doesn't exists, it can't be found in the directory and therefore allinfo is called: https://github.com/icewind1991/SMB/blob/9132f32aa075d94693bd3caf646c92fde48dcfbe/src/Wrapped/Share.php#L207 The result of allinfo is an empy array. I think this is the root cause for the exception.

If I call allinfo with the smbclient, I get an error NT_STATUS_OBJECT_NAME_NOT_FOUND getting alt name for ... I don't know why this error is not propagated into the php code.

davidoe commented 2 years ago

Same problem here, using Nextcloud 23.0.2 on Nextcloudpi

Starkstromkonsument commented 2 years ago

Same problem here, running Nextcloud 24.0.2 on Ubuntu Server 20.04 LTS with PHP 7.4.3

peacepenguin commented 2 years ago

Same issue, only affects a single folder that contains 488 files. All other folders are smaller, and work fine. Also individual files i can open, but if i select multiple then "Download" i get this error.

joschkopf commented 2 years ago

Same issue here. I tracked it down until I found that parseStat bails out, because the dir command returns as a final line e.g. "5860520960 blocks of size 1024. 2099970636 blocks available". I commented out the code trying to get the information via "dir", but just use "allinfo" now, which seems to resolve the issue.

MatthiasKuehneEllerhold commented 2 years ago

Same error with 3.5.4!

NoFrust commented 2 years ago

I had the same problem using the latest docker image. Adding the following commands to the Dockerfile solved the issue for me: RUN apt-get update && apt-get install -y smbclient libsmbclient-dev && rm -rf /var/lib/apt/lists/* RUN pecl install smbclient RUN docker-php-ext-enable smbclient

Before I installed the smbclient only. And with this I had the issue described above. RUN apt-get update && apt-get install -y smbclient && rm -rf /var/lib/apt/lists/*

I got the hint from the following Dockerfile: https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/full/apache/Dockerfile

MatthiasKuehneEllerhold commented 2 years ago

Ive now upgraded to PHP8.0 (from 7.4) and installed php8.0-smbclient (instead of using the the smbclient cli backend). Version 3.5.4 now works correctly. @NoFrust You're doing exactly that: libsmbclient instead of cli smbclient paired with a recent PHP version (presumably).

LevAnni777 commented 3 months ago

I had the same problem using the latest docker image. Adding the following commands to the Dockerfile solved the issue for me: RUN apt-get update && apt-get install -y smbclient libsmbclient-dev && rm -rf /var/lib/apt/lists/* RUN pecl install smbclient RUN docker-php-ext-enable smbclient

Before I installed the smbclient only. And with this I had the issue described above. RUN apt-get update && apt-get install -y smbclient && rm -rf /var/lib/apt/lists/*

I got the hint from the following Dockerfile: https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/full/apache/Dockerfile

I'm entering all these commands (except rm -rf /var/lib/apt/lists/*) and everything installs perfectly, I even see php extension installed by running php -m, but as soon as I restart my nextcloud instance the configuration returns everything back to its previous (native) installation through Truenas and I no longer see smbclient in the php extensions.

Any ideas?

can rm -rf /var/lib/apt/lists/* command somehow damage default installation method?