wininet: Treat an empty username as NULL in FTP_Connect().

This commit is contained in:
Henri Verbeet 2008-11-18 09:27:59 +01:00 committed by Alexandre Julliard
parent 3a3b75e177
commit 369da3aeb9
2 changed files with 25 additions and 2 deletions

View File

@ -2256,7 +2256,7 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
assert( hIC->hdr.htype == WH_HINIT ); assert( hIC->hdr.htype == WH_HINIT );
if (NULL == lpszUserName && NULL != lpszPassword) if ((!lpszUserName || !strlenW(lpszUserName)) && lpszPassword)
{ {
INTERNET_SetLastError(ERROR_INVALID_PARAMETER); INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
goto lerror; goto lerror;
@ -2302,7 +2302,7 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
if(hIC->lpszProxyBypass) if(hIC->lpszProxyBypass)
FIXME("Proxy bypass is ignored.\n"); FIXME("Proxy bypass is ignored.\n");
} }
if ( !lpszUserName) { if (!lpszUserName || !strlenW(lpszUserName)) {
HKEY key; HKEY key;
WCHAR szPassword[MAX_PATH]; WCHAR szPassword[MAX_PATH];
DWORD len = sizeof(szPassword); DWORD len = sizeof(szPassword);

View File

@ -66,6 +66,8 @@ static void test_connect(HINTERNET hInternet)
* anonymous : NULL * anonymous : NULL
* NULL : IEUser@ * NULL : IEUser@
* NULL : NULL * NULL : NULL
* "" : IEUser@
* "" : NULL
*/ */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
@ -85,6 +87,13 @@ static void test_connect(HINTERNET hInternet)
ok ( GetLastError() == ERROR_INVALID_PARAMETER, ok ( GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", "IEUser@",
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
ok(!hFtp, "Expected InternetConnect to fail\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
/* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password /* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password
* is created via some simple heuristics (see dlls/wininet/ftp.c). * is created via some simple heuristics (see dlls/wininet/ftp.c).
* On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not * On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not
@ -103,6 +112,20 @@ static void test_connect(HINTERNET hInternet)
ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError());
ok ( GetLastError() == ERROR_SUCCESS, ok ( GetLastError() == ERROR_SUCCESS,
"ERROR_SUCCESS, got %d\n", GetLastError()); "ERROR_SUCCESS, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", NULL,
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if (!hFtp)
{
ok(GetLastError() == ERROR_INTERNET_LOGIN_FAILURE,
"Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
}
else
{
ok(GetLastError() == ERROR_SUCCESS,
"Expected ERROR_SUCCESS, got %d\n", GetLastError());
}
} }
static void test_createdir(HINTERNET hFtp, HINTERNET hConnect) static void test_createdir(HINTERNET hFtp, HINTERNET hConnect)