Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMB shares on Windows not working as external storage when using smbclient #30751

Open
erbth opened this issue Jan 19, 2022 · 10 comments
Open

SMB shares on Windows not working as external storage when using smbclient #30751

erbth opened this issue Jan 19, 2022 · 10 comments
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 25-feedback bug feature: external storage needs review Needs review to determine if still applicable

Comments

@erbth
Copy link

erbth commented Jan 19, 2022

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Steps to reproduce

  1. Install nextcloud version 23.0.0 (though older versions might be affected, too) on a fresh Debian 11 Bullseye server
  2. Install the smbclient-package to attach SMB-shares as external storage
  3. Attach external storage backed by a SMB-share on a Windows 2012R2 or Windows 2019 Server (though I believe that other versions might reproduce the behavior, too)

Expected behaviour

As a user logged into nextcloud I should be able to access the external storage-mount from the files app (potentially after entering credentials if configured so). When I click onto the share, I should enter the directory on the Windows server's share that I configured as external storage.

Actual behaviour

If I enter the credentials in the external storage's configuration, the status icon at the beginning of the row shows the red exclamation mark, which indicates that the configuration is problematic. If I configure the share s.t. users have to enter credentials, they simply won't be taken into the share but be asked to re-enter the credentials every time they click on it.

The nextcloud log however shows Icewind\SMB\Exception\Exception: Unknown error (NT_STATUS_OBJECT_NAME_INVALID) for /. (see below for full excerpt).

Description of the underlying issue

nextcloud uses icewind/smb (https://github.com/icewind1991/SMB) to communicate with SMB servers. icewind/smb is a wrapper around either libsmbclient-php or the smbclient command line tool if the former is not available. When entering a directory backed by SMB, NC performs a "stat" on the share's root-directory. For the SMB root directory the "stat" translates to a smbclient allinfo. If that smbclient allinfo fails, icewind retries with smbclient allinfo ., which is answered with STATUS_OBJECT_NAME_INVALID by W2k12r2 and W2k19. However that's only part of the issue, because undoing the changes to src/Share.php made in icewind1991/SMB@286024d is not enough. I managed to get the smbclient implementation working with these changes: erbth@a2afcac. However it's pretty slow.

By the way, I came across this issue because libsmbclient-php, which is usually packaged as php-smbclient by Debian/Ubuntu, is not part of Debian Buster (and recent Ubuntu versions, I think) due to licensing issues. That means one would have to install (and update) it manually or use the version from Debian sid. This motivated me to try the smbclient-approach (and might motivate others ;-)).

Server configuration

Operating system: Debian 11 Bullseye with up-to-date packages

Web server: Apache2

Database: MariaDB

PHP version: 7.4

Nextcloud version: (see Nextcloud admin page) 23.0.0

Updated from an older Nextcloud/ownCloud or fresh install: Updated from an older version

Where did you install Nextcloud from: Originally downloaded zip-archive from nextcloud.com and followed the admin-manual

Signing status:

Signing status
No errors have been found.

List of activated apps:

App list
  - accessibility: 1.9.0
  - activity: 2.15.0
  - calendar: 3.0.5
  - checksum: 1.1.3
  - circles: 23.0.0
  - cloud_federation_api: 1.6.0
  - comments: 1.13.0
  - contactsinteraction: 1.4.0
  - dav: 1.21.0
  - federatedfilesharing: 1.13.0
  - federation: 1.13.0
  - files: 1.18.0
  - files_external: 1.15.0
  - files_markdown: 2.3.5
  - files_pdfviewer: 2.4.0
  - files_rightclick: 1.2.0
  - files_sharing: 1.15.0
  - files_trashbin: 1.13.0
  - files_versions: 1.16.0
  - files_videoplayer: 1.12.0
  - firstrunwizard: 2.12.0
  - logreader: 2.8.0
  - lookup_server_connector: 1.11.0
  - nextcloud_announcements: 1.12.0
  - notifications: 2.11.1
  - oauth2: 1.11.0
  - onlyoffice: 7.3.0
  - password_policy: 1.13.0
  - photos: 1.5.0
  - privacy: 1.7.0
  - provisioning_api: 1.13.0
  - recommendations: 1.2.0
  - richdocuments: 5.0.1
  - serverinfo: 1.13.0
  - settings: 1.5.0
  - sharebymail: 1.13.0
  - spreed: 13.0.1
  - support: 1.6.0
  - survey_client: 1.11.0
  - systemtags: 1.13.0
  - text: 3.4.0
  - theming: 1.14.0
  - twofactor_backupcodes: 1.12.0
  - updatenotification: 1.13.0
  - viewer: 1.7.0
  - workflowengine: 2.5.0
Disabled:
  - admin_audit
  - dashboard
  - encryption
  - files_fulltextsearch
  - fulltextsearch
  - fulltextsearch_elasticsearch
  - user_ldap
  - user_status
  - weather_status

Nextcloud configuration:

Config report
I think it's not relevant... however I am of course willing to provide it if you consider it helpful.

Are you using external storage, if yes which one: smb

Are you using encryption: no

Are you using an external user-backend, if yes which one: ActiveDirectory

Client configuration

Browser: Firefox ESR 91.5.0

Operating system: Debian 11 Bullseye

Logs

Nextcloud log (data/nextcloud.log)

Nextcloud log
# Relevant parts:
{"reqId":"XfN0QelyMkiocK6BlZSU","level":2,"time":"2022-01-19T02:44:59+00:00","remoteAddr":"****","user":"****","app":"no app in context","method":"GET","url":"/nextcloud/index.php/apps/files_external/userglobalstorages/4?testOnly=false","message":"Unknown error (NT_STATUS_OBJECT_NAME_INVALID) for /","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0","version":"23.0.0.10","exception":{"Exception":"Icewind\\SMB\\Exception\\Exception","Message":"Unknown error (NT_STATUS_OBJECT_NAME_INVALID) for /","Code":0,"Trace":[{"file":"/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Exception/Exception.php","line":49,"function":"unknown","class":"Icewind\\SMB\\Exception\\Exception","type":"::"},{"file":"/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Parser.php","line":92,"function":"fromMap","class":"Icewind\\SMB\\Exception\\Exception","type":"::"},{"file":"/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Share.php","line":471,"function":"checkForError","class":"Icewind\\SMB\\Wrapped\\Parser","type":"->"},{"file":"/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Share.php","line":215,"function":"parseOutput","class":"Icewind\\SMB\\Wrapped\\Share","type":"->"},{"file":"/var/www/nextcloud/apps/files_external/lib/Lib/Storage/SMB.php","line":189,"function":"stat","class":"Icewind\\SMB\\Wrapped\\Share","type":"->"},{"file":"/var/www/nextcloud/apps/files_external/lib/Lib/Storage/SMB.php","line":342,"function":"getFileInfo","class":"OCA\\Files_External\\Lib\\Storage\\SMB","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Storage/Common.php","line":458,"function":"stat","class":"OCA\\Files_External\\Lib\\Storage\\SMB","type":"->"},{"file":"/var/www/nextcloud/apps/files_external/lib/Lib/Storage/SMB.php","line":717,"function":"test","class":"OC\\Files\\Storage\\Common","type":"->"},{"file":"/var/www/nextcloud/apps/files_external/lib/MountConfig.php","line":130,"function":"test","class":"OCA\\Files_External\\Lib\\Storage\\SMB","type":"->"},{"file":"/var/www/nextcloud/apps/files_external/lib/Controller/StoragesController.php","line":270,"function":"getBackendStatus","class":"OCA\\Files_External\\MountConfig","type":"::","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/apps/files_external/lib/Controller/UserGlobalStoragesController.php","line":123,"function":"updateStorageStatus","class":"OCA\\Files_External\\Controller\\StoragesController","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":217,"function":"show","class":"OCA\\Files_External\\Controller\\UserGlobalStoragesController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":126,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":1006,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":36,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Exception/Exception.php","Line":31,"CustomMessage":"--"},"id":"****"}
{"reqId":"XfN0QelyMkiocK6BlZSU","level":2,"time":"2022-01-19T02:44:59+00:00","remoteAddr":"****","user":"****","app":"no app in context","method":"GET","url":"/nextcloud/index.php/apps/files_external/userglobalstorages/4?testOnly=false","message":"External storage not available: Unknown error (NT_STATUS_OBJECT_NAME_INVALID) for /","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0","version":"23.0.0.10","id":"****"}
@erbth erbth added 0. Needs triage Pending check for reproducibility or if it fits our roadmap bug labels Jan 19, 2022
@q-wertz
Copy link

q-wertz commented Feb 7, 2022

Same problem on Ubuntu 20.04 with

  • NC 22.2.3
  • External storage support app 1.13.0

What I don't get is, that the connection is working to another SMB share (created by the institution) but not to a Win10 machine.

Difference is, that on the working host with allinfo \, allinfo / and allinfo . I get the output

smb: \> allinfo /
NT_STATUS_NOT_SUPPORTED getting alt name for \
altname: 
create_time:    Tue May  5 09:21:54 AM 2020 CEST
access_time:    Thu Aug  6 02:06:35 PM 2020 CEST
write_time:     Tue Jul 21 02:28:18 PM 2020 CEST
change_time:    Tue Jul 21 02:28:18 PM 2020 CEST
attributes: D (10)
smb: \> allinfo \
NT_STATUS_NOT_SUPPORTED getting alt name for \
altname: 
create_time:    Tue May  5 09:21:54 AM 2020 CEST
access_time:    Thu Aug  6 02:06:35 PM 2020 CEST
write_time:     Tue Jul 21 02:28:18 PM 2020 CEST
change_time:    Tue Jul 21 02:28:18 PM 2020 CEST
attributes: D (10)
smb: \> allinfo .
NT_STATUS_NOT_SUPPORTED getting alt name for \.
altname: 
create_time:    Tue May  5 09:21:54 AM 2020 CEST
access_time:    Mon Feb  7 05:25:58 PM 2022 CET
write_time:     Tue Jul 21 02:28:18 PM 2020 CEST
change_time:    Tue Jul 21 02:28:18 PM 2020 CEST
attributes: D (10)

instead of

smb: \> allinfo /
NT_STATUS_OBJECT_NAME_NOT_FOUND getting alt name for \
smb: \> allinfo .
NT_STATUS_OBJECT_NAME_INVALID getting alt name for \.

which results in the NC connection error.

@RemiRou
Copy link

RemiRou commented Jun 24, 2022

Same problem here.

NC 24.1 on RHEL 8.5.
External storage using smbclient is working for old windows 2008R2 servers, but not with Win 2012 or Win 2019 servers.
allinfo "" command returns "NT_STATUS_OBJECT_NAME_INVALID getting alt name for ."
I have been able to verify that this error occurs when 8.3 filenames are disabled on the drive where the share resides (which is the default configuration since windows server 2012).
But enabling 8.3 filenames is not a usable solution, because you would need to recreate each existing file or folder to have 8.3 names generated (so basically you would need to put the share offline, make a copy of the whole directory tree, change names, recreate the share...).

I was forced to use smbclient instead of libsmbclient because libsmbclient is not compatible with our entreprise class NAS (Dell/EMC Isilon). And finally smbclient works with our Isilon NAS, but does not work with windows server 2012+ ...

I would be great if @icewind1991 could provide a real solution.

@szaimen
Copy link
Contributor

szaimen commented Jan 23, 2023

Hi, please update to 24.0.9 or better 25.0.3 and report back if it fixes the issue. Thank you!

My goal is to add a label like e.g. 25-feedback to this ticket of an up-to-date major Nextcloud version where the bug could be reproduced. However this is not going to work without your help. So thanks for all your effort!

If you don't manage to reproduce the issue in time and the issue gets closed but you can reproduce the issue afterwards, feel free to create a new bug report with up-to-date information by following this link: https://github.com/nextcloud/server/issues/new?assignees=&labels=bug%2C0.+Needs+triage&template=BUG_REPORT.yml&title=%5BBug%5D%3A+

@sempervictus
Copy link

sempervictus commented Jan 29, 2023

@szaimen - can confirm the issue persists in 25.0.3:

{
  "reqId": "Y9W9tLxGSergDnL49_CWOwAAABE",
  "level": 3,
  "time": "2023-01-29T00:28:37+00:00",
  "remoteAddr": "56.220.245.121",
  "user": "FD4D640E-29AA-4B1D-9378-DDBC90F6C642",
  "app": "PHP",
  "method": "PUT",
  "url": "/index.php/apps/files_external/globalstorages/10",
  "message": "Undefined array key 1 at /usr/share/webapps/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php#46",
  "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
  "version": "25.0.3.2",
  "exception": {
    "Exception": "Error",
    "Message": "Undefined array key 1 at /usr/share/webapps/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php#46",
    "Code": 0,
    "Trace": [
      {
        "file": "/usr/share/webapps/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php",
        "line": 46,
        "function": "onError",
        "class": "OC\\Log\\ErrorHandler",
        "type": "::",
        "args": [
          2,
          "Undefined array key 1",
          "/usr/share/webapps/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php",
          46
        ]
      },

thats on

PHP 8.1.14 (cli) (built: Jan 16 2023 16:34:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.14, Copyright (c), by Zend Technologies

with relevant php-smbclient (1.0.6) and smbclient (4.17.5) components deployed.
Once connected with the CLI smbclient, i get:

Try "help" to get a list of possible commands.
smb: \> allinfo /
NT_STATUS_INVALID_PARAMETER getting alt name for \
smb: \> allinfo \\
NT_STATUS_INVALID_PARAMETER getting alt name for \\

@ultnrg
Copy link

ultnrg commented Feb 17, 2023

Is there a workaround for this? Just updated from 23 to 24 and got this issue. Have now updated to 25 and the issue still persists. As all our data is on windows SMB shares, it means we can't access anything via Nextcloud. Is the only fix to go back to v23?

@q-wertz
Copy link

q-wertz commented Feb 17, 2023

As far as I know this is not a problem that will be solved when you downgrade to v23…

@erbth
Copy link
Author

erbth commented Feb 17, 2023

@ultnrg You could try the php-smbclient approach instead. IIRC that works with NC 24 and I think it should also work with NC 25. Depending on your distribution you might be able to install it via the distribution's package manager or you have to install it from source (https://pecl.php.net/package/smbclient).

@ultnrg
Copy link

ultnrg commented Feb 18, 2023

Okay, looks like issue #36773 was what was causing my error. Downgraded libsmbclient and my SMB shares are working again.

@joshtrichards
Copy link
Member

@sempervictus Your issue looks like #36773

@joshtrichards joshtrichards added the needs review Needs review to determine if still applicable label Sep 6, 2024
@icewind1991
Copy link
Member

Can you check if #50284 fixes the problem.

If you can't apply the PR on the NC version you're using, you can try replacing apps/files_external/3rdparty/icewind with https://github.com/icewind1991/SMB/tree/v3.7.0 instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 25-feedback bug feature: external storage needs review Needs review to determine if still applicable
Projects
None yet
Development

No branches or pull requests

8 participants