`SMBC_server_internal()` (source3/libsmb/libsmb_server.c) ends with ```c /* set the credentials to make DFS work */ smbc_set_credentials_with_fallback(context, workgroup, *pp_username, *pp_password); ``` This also runs on a cache hit (`*in_cache = true; goto done;`). On a cache hit `SMBC_find_server()` does not call the auth function, so `*pp_password` is whatever the caller passed in. Callers that supply the password via the auth callback (e.g. KDE's kio_smb, which uses `smbc_setFunctionAuthDataWithContext`) pass URLs without a password, so `*pp_password` is `""`. `context->internal->creds` is therefore overwritten with an empty password after the first operation on a cached connection. `cli_resolve_path()` uses these context credentials to connect to DFS referral targets, so the first referral to another server succeeds (it happens right after the auth callback filled in the password) but every later new referral connection fails: ``` cli_session_setup_spnego_send: Connect to FS01.example.local as user@EXAMPLE using SPNEGO SPNEGO login failed: The attempted logon is invalid. This is either due to a bad username or authentication information. session setup failed: NT_STATUS_LOGON_FAILURE Unable to follow dfs referral [\FS01\Share$] Could not resolve \Share\* ``` The caller sees ENOENT (stat) / EAGAIN (opendir). Every failing attempt is an empty-password NTLM logon against the domain, which also counts towards account lockout. ## Setup - AD domain EXAMPLE / example.local; domain DFS namespace `\\example.local\shares` - DFS links `\\example.local\shares\<Name>` -> `\\FS01\<Name>$` (FS01 != namespace server) - Client: libsmbclient 4.25.0, NTLM (Kerberos was not used in the verified reproducer) ## Reproducer With a single libsmbclient context and an auth callback that supplies the password: 1. `smbc_opendir("smb://EXAMPLE;user@example.local/shares")` and read it — works. 2. `smbc_stat()` / `smbc_opendir()` on `smb://EXAMPLE;user@example.local/shares/<Name>` — fails with NT_STATUS_LOGON_FAILURE on the referral to FS01. Doing step 2 first in a fresh context works, as does every operation in a fresh process (e.g. `kioclient ls`), which is why this looks intermittent to users. In KDE Dolphin: browse to the DFS root, then open any link → "Unknown error condition: [11] Resource temporarily unavailable" (see KDE bug 525531 and 449255, which are likely this issue). Verified with libsmbclient debug level 5: one successful session setup to FS01 as user@EXAMPLE immediately after the auth callback, then repeated LOGON_FAILURE for the same user on the next referrals, with no auth callback in between. ## Fix Attached patch: remember the workgroup/username/password that were applied when the connection was established (stored on the SMBCSRV, talloc'd on `srv->cli` so they are freed with it) and, on a cache hit where no password was passed in, re-apply those instead of the caller's incomplete values. Behaviour is unchanged when the caller passes an explicit password. Tested on 4.25.0 against the setup above: with the patch, DFS root → link works (0 LOGON_FAILURE); same build without the patch fails every time (8 LOGON_FAILURE, EAGAIN on opendir). Related KDE reports: https://bugs.kde.org/show_bug.cgi?id=525531 https://bugs.kde.org/show_bug.cgi?id=449255
Created attachment 19272 [details] Proposed fix: preserve per-server DFS credentials on cached connections (tested on 4.25.0) Attached the proposed patch tested locally on Samba 4.25.0. Patched DFS root-to-link navigation succeeded; the unpatched control failed with NT_STATUS_LOGON_FAILURE.
Tested-by: Michael Krause <krause@mpib-berlin.mpg.de> --- Disclosure: I used an LLM assistant (Claude 5.5) for the debugging. It helped read the libsmbclient sources, design an A/B test, and write the review notes and this comment. The test results are mine: I built the packages, ran the tests and checked the outcomes on my own systems. The code-path explanation and review notes were checked against the 4.23.6 and master sources but have not been reviewed by a Samba developer, so please treat them as a pointer, not an authoritative analysis. --- Confirmed independently with gvfs (GNOME) instead of kio_smb. Environment: - Ubuntu 26.04, samba 2:4.23.6+dfsg-1ubuntu2.2 rebuilt with this patch (applies cleanly to samba-4.23.6 with a 15-line offset, and to master) - gvfs 1.60.0, NTLM authentication (no Kerberos ticket used) - Domain-based DFS namespace \\<domain>\projects, namespace servers on Windows Server 2022, link targets on other file servers Trigger condition we isolated: the local $USER equals the authenticated username. SMBC_get_cached_server() then hits on the first lookup in SMBC_find_server(), the auth callback is skipped, and SMBC_server() stores the empty password from the URI in context->internal->creds, which cli_resolve_path() later uses for referral targets. A/B test on the unpatched library, same machine and credentials: - USER=<ad user> -> LOGON_FAILURE on the referral target, gvfs reports EAGAIN/ENOENT; repeated access led to account lockouts - USER=no-such-user -> works (cache miss, auth callback supplies the password) With the patch, USER=<ad user> works: referrals to the namespace servers and to the link target authenticate, and no bad logons are counted (badPwdCount checked via LDAP before and after). Review notes (non-blocking): - consider talloc_keep_secret() on srv->dfs_password, as done for cred->password in auth/credentials/credentials.c, so the copy is zeroed on free - the dfs_* strings are talloc children of srv->cli, so they dangle after cli_shutdown(srv->cli). I checked all such sites (libsmb_server.c, libsmb_cache.c, libsmb_context.c): in each, srv is freed or removed from the cache, so the dangling pointers are never used today. Setting them to NULL next to srv->cli = NULL would make that robust against future changes. Likely the same bug: KDE bug 449255 (Dolphin/KIO, DFS link "does not exist" after NT_STATUS_LOGON_FAILURE) and GNOME gvfs #238.