From 93c33d22ab51c1d4659c3f92bdc773a99342f707 Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Sat, 17 Apr 2021 20:37:38 +0200 Subject: [PATCH] [Windows] Fix: enables passwordless SMB authentication --- xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp b/xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp index 248e84f7e1547..ab2b083e9a609 100644 --- a/xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp +++ b/xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp @@ -723,10 +723,20 @@ bool CWin32SMBDirectory::ConnectAndAuthenticate(CURL& url, bool allowPromptForCr connInfo.dwType = RESOURCETYPE_ANY; connInfo.lpRemoteName = (LPWSTR)serverShareNameW.c_str(); DWORD connRes; + for (int i = 0; i < 3; i++) // make up to three attempts to connect { + // try with provided user/password or NULL user/password (NULL = current Windows user/password) connRes = WNetAddConnection2W(&connInfo, passwordW.empty() ? NULL : (LPWSTR)passwordW.c_str(), usernameW.empty() ? NULL : (LPWSTR)usernameW.c_str(), CONNECT_TEMPORARY); + + // try with passwordless access (guest user and no password) + if (usernameW.empty() && passwordW.empty() && + (connRes == ERROR_ACCESS_DENIED || connRes == ERROR_BAD_USERNAME || + connRes == ERROR_INVALID_PASSWORD || connRes == ERROR_LOGON_FAILURE || + connRes == ERROR_LOGON_TYPE_NOT_GRANTED || connRes == ERROR_LOGON_NOT_GRANTED)) + connRes = WNetAddConnection2W(&connInfo, L"", L"guest", CONNECT_TEMPORARY); + if (connRes == NO_ERROR) { CLog::LogF(LOGDEBUG, "Connected to \"%s\" %s", serverShareName.c_str(), loginDescr.c_str());