Commit 78fc21cd authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Allow setting NULL username and password for NTLM, Passport and Negotiate.

parent 368cff7a
...@@ -1668,7 +1668,8 @@ static BOOL do_authorization( request_t *request, DWORD target, DWORD scheme_fla ...@@ -1668,7 +1668,8 @@ static BOOL do_authorization( request_t *request, DWORD target, DWORD scheme_fla
static BOOL set_credentials( request_t *request, DWORD target, DWORD scheme, const WCHAR *username, static BOOL set_credentials( request_t *request, DWORD target, DWORD scheme, const WCHAR *username,
const WCHAR *password ) const WCHAR *password )
{ {
if (!username || !password) if ((scheme == WINHTTP_AUTH_SCHEME_BASIC || scheme == WINHTTP_AUTH_SCHEME_DIGEST) &&
(!username || !password))
{ {
set_last_error( ERROR_INVALID_PARAMETER ); set_last_error( ERROR_INVALID_PARAMETER );
return FALSE; return FALSE;
...@@ -1678,17 +1679,23 @@ static BOOL set_credentials( request_t *request, DWORD target, DWORD scheme, con ...@@ -1678,17 +1679,23 @@ static BOOL set_credentials( request_t *request, DWORD target, DWORD scheme, con
case WINHTTP_AUTH_TARGET_SERVER: case WINHTTP_AUTH_TARGET_SERVER:
{ {
heap_free( request->connect->username ); heap_free( request->connect->username );
if (!(request->connect->username = strdupW( username ))) return FALSE; if (!username) request->connect->username = NULL;
else if (!(request->connect->username = strdupW( username ))) return FALSE;
heap_free( request->connect->password ); heap_free( request->connect->password );
if (!(request->connect->password = strdupW( password ))) return FALSE; if (!password) request->connect->password = NULL;
else if (!(request->connect->password = strdupW( password ))) return FALSE;
break; break;
} }
case WINHTTP_AUTH_TARGET_PROXY: case WINHTTP_AUTH_TARGET_PROXY:
{ {
heap_free( request->connect->session->proxy_username ); heap_free( request->connect->session->proxy_username );
if (!(request->connect->session->proxy_username = strdupW( username ))) return FALSE; if (!username) request->connect->session->proxy_username = NULL;
else if (!(request->connect->session->proxy_username = strdupW( username ))) return FALSE;
heap_free( request->connect->session->proxy_password ); heap_free( request->connect->session->proxy_password );
if (!(request->connect->session->proxy_password = strdupW( password ))) return FALSE; if (!password) request->connect->session->proxy_password = NULL;
else if (!(request->connect->session->proxy_password = strdupW( password ))) return FALSE;
break; break;
} }
default: default:
......
...@@ -1959,6 +1959,27 @@ static void test_basic_authentication(int port) ...@@ -1959,6 +1959,27 @@ static void test_basic_authentication(int port)
ok(ret, "failed to query status code %u\n", GetLastError()); ok(ret, "failed to query status code %u\n", GetLastError());
ok(status == 401, "request failed unexpectedly %u\n", status); ok(status == 401, "request failed unexpectedly %u\n", status);
ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_NTLM, NULL, NULL, NULL);
ok(ret, "failed to set credentials %u\n", GetLastError());
ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_PASSPORT, NULL, NULL, NULL);
ok(ret, "failed to set credentials %u\n", GetLastError());
ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_NEGOTIATE, NULL, NULL, NULL);
ok(ret, "failed to set credentials %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_DIGEST, NULL, NULL, NULL);
error = GetLastError();
ok(!ret, "expected failure\n");
ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
SetLastError(0xdeadbeef);
ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, NULL, NULL, NULL);
error = GetLastError();
ok(!ret, "expected failure\n");
ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, NULL, NULL); ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, NULL, NULL);
error = GetLastError(); error = GetLastError();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment