wininet: Destroy authorization info on failure in HTTP_DoAuthorization.

This makes sure the app can retry authorization, e.g. when username and
password are not supplied upfront and there are no cached credentials.
This commit is contained in:
Hans Leidekker 2009-09-02 11:44:43 +02:00 committed by Alexandre Julliard
parent 05e9a1fce8
commit 50fef74131

View file

@ -503,6 +503,20 @@ static inline BOOL is_basic_auth_value( LPCWSTR pszAuthValue )
((pszAuthValue[ARRAYSIZE(szBasic)] == ' ') || !pszAuthValue[ARRAYSIZE(szBasic)]);
}
static void destroy_authinfo( struct HttpAuthInfo *authinfo )
{
if (!authinfo) return;
if (SecIsValidHandle(&authinfo->ctx))
DeleteSecurityContext(&authinfo->ctx);
if (SecIsValidHandle(&authinfo->cred))
FreeCredentialsHandle(&authinfo->cred);
HeapFree(GetProcessHeap(), 0, authinfo->auth_data);
HeapFree(GetProcessHeap(), 0, authinfo->scheme);
HeapFree(GetProcessHeap(), 0, authinfo);
}
static BOOL HTTP_DoAuthorization( http_request_t *lpwhr, LPCWSTR pszAuthValue,
struct HttpAuthInfo **ppAuthInfo,
LPWSTR domain_and_username, LPWSTR password )
@ -706,8 +720,9 @@ static BOOL HTTP_DoAuthorization( http_request_t *lpwhr, LPCWSTR pszAuthValue,
else
{
ERR("InitializeSecurityContextW returned error 0x%08x\n", sec_status);
pAuthInfo->finished = TRUE;
HeapFree(GetProcessHeap(), 0, out.pvBuffer);
destroy_authinfo(pAuthInfo);
*ppAuthInfo = NULL;
return FALSE;
}
}
@ -1507,31 +1522,8 @@ static void HTTPREQ_Destroy(object_header_t *hdr)
DeleteCriticalSection( &lpwhr->read_section );
WININET_Release(&lpwhr->lpHttpSession->hdr);
if (lpwhr->pAuthInfo)
{
if (SecIsValidHandle(&lpwhr->pAuthInfo->ctx))
DeleteSecurityContext(&lpwhr->pAuthInfo->ctx);
if (SecIsValidHandle(&lpwhr->pAuthInfo->cred))
FreeCredentialsHandle(&lpwhr->pAuthInfo->cred);
HeapFree(GetProcessHeap(), 0, lpwhr->pAuthInfo->auth_data);
HeapFree(GetProcessHeap(), 0, lpwhr->pAuthInfo->scheme);
HeapFree(GetProcessHeap(), 0, lpwhr->pAuthInfo);
lpwhr->pAuthInfo = NULL;
}
if (lpwhr->pProxyAuthInfo)
{
if (SecIsValidHandle(&lpwhr->pProxyAuthInfo->ctx))
DeleteSecurityContext(&lpwhr->pProxyAuthInfo->ctx);
if (SecIsValidHandle(&lpwhr->pProxyAuthInfo->cred))
FreeCredentialsHandle(&lpwhr->pProxyAuthInfo->cred);
HeapFree(GetProcessHeap(), 0, lpwhr->pProxyAuthInfo->auth_data);
HeapFree(GetProcessHeap(), 0, lpwhr->pProxyAuthInfo->scheme);
HeapFree(GetProcessHeap(), 0, lpwhr->pProxyAuthInfo);
lpwhr->pProxyAuthInfo = NULL;
}
destroy_authinfo(lpwhr->pAuthInfo);
destroy_authinfo(lpwhr->pProxyAuthInfo);
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb);