wininet: Dorectly return error status from NETCON_secure_connect and NETCON_send.
This commit is contained in:
parent
bf1da4c857
commit
b77868cbfd
|
@ -2491,17 +2491,20 @@ done:
|
|||
|
||||
static BOOL HTTPREQ_WriteFile(object_header_t *hdr, const void *buffer, DWORD size, DWORD *written)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD res;
|
||||
http_request_t *lpwhr = (http_request_t*)hdr;
|
||||
|
||||
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
||||
|
||||
*written = 0;
|
||||
if ((ret = NETCON_send(&lpwhr->netConnection, buffer, size, 0, (LPINT)written)))
|
||||
res = NETCON_send(&lpwhr->netConnection, buffer, size, 0, (LPINT)written);
|
||||
if (res == ERROR_SUCCESS)
|
||||
lpwhr->dwBytesWritten += *written;
|
||||
else
|
||||
SetLastError(res);
|
||||
|
||||
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, INTERNET_STATUS_REQUEST_SENT, written, sizeof(DWORD));
|
||||
return ret;
|
||||
return res == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static void HTTPREQ_AsyncQueryDataAvailableProc(WORKREQUEST *workRequest)
|
||||
|
@ -3756,7 +3759,7 @@ static BOOL HTTP_SecureProxyConnect(http_request_t *lpwhr)
|
|||
INT cnt;
|
||||
INT responseLen;
|
||||
char *ascii_req;
|
||||
BOOL ret;
|
||||
DWORD res;
|
||||
static const WCHAR szConnect[] = {'C','O','N','N','E','C','T',0};
|
||||
static const WCHAR szFormat[] = {'%','s',':','%','d',0};
|
||||
http_session_t *lpwhs = lpwhr->lpHttpSession;
|
||||
|
@ -3778,10 +3781,12 @@ static BOOL HTTP_SecureProxyConnect(http_request_t *lpwhr)
|
|||
|
||||
TRACE("full request -> %s\n", debugstr_an( ascii_req, len ) );
|
||||
|
||||
ret = NETCON_send( &lpwhr->netConnection, ascii_req, len, 0, &cnt );
|
||||
res = NETCON_send( &lpwhr->netConnection, ascii_req, len, 0, &cnt );
|
||||
HeapFree( GetProcessHeap(), 0, ascii_req );
|
||||
if (!ret || cnt < 0)
|
||||
if (res != ERROR_SUCCESS || cnt < 0) {
|
||||
INTERNET_SetLastError(res);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
responseLen = HTTP_GetResponseHeaders( lpwhr, TRUE );
|
||||
if (!responseLen)
|
||||
|
@ -4377,7 +4382,8 @@ static BOOL HTTP_OpenConnection(http_request_t *lpwhr)
|
|||
if (hIC->lpszProxy && !HTTP_SecureProxyConnect(lpwhr))
|
||||
goto lend;
|
||||
|
||||
if (!NETCON_secure_connect(&lpwhr->netConnection, lpwhs->lpszHostName))
|
||||
res = NETCON_secure_connect(&lpwhr->netConnection, lpwhs->lpszHostName);
|
||||
if(res != ERROR_SUCCESS)
|
||||
{
|
||||
WARN("Couldn't connect securely to host\n");
|
||||
goto lend;
|
||||
|
|
|
@ -435,8 +435,8 @@ DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
|
|||
BOOL NETCON_close(WININET_NETCONNECTION *connection);
|
||||
DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
|
||||
unsigned int addrlen);
|
||||
BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
|
||||
BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
|
||||
DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
|
||||
DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
|
||||
int *sent /* out */);
|
||||
BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
|
||||
int *recvd /* out */);
|
||||
|
|
|
@ -442,8 +442,9 @@ static BOOL check_hostname(X509 *cert, char *hostname)
|
|||
* NETCON_secure_connect
|
||||
* Initiates a secure connection over an existing plaintext connection.
|
||||
*/
|
||||
BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
||||
DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
||||
{
|
||||
DWORD res = ERROR_NOT_SUPPORTED;
|
||||
#ifdef SONAME_LIBSSL
|
||||
long verify_res;
|
||||
X509 *cert;
|
||||
|
@ -454,7 +455,7 @@ BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
|||
if (connection->useSSL)
|
||||
{
|
||||
ERR("already connected\n");
|
||||
return FALSE;
|
||||
return ERROR_INTERNET_CANNOT_CONNECT;
|
||||
}
|
||||
|
||||
connection->ssl_s = pSSL_new(ctx);
|
||||
|
@ -462,7 +463,7 @@ BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
|||
{
|
||||
ERR("SSL_new failed: %s\n",
|
||||
pERR_error_string(pERR_get_error(), 0));
|
||||
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
||||
res = ERROR_OUTOFMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -470,7 +471,7 @@ BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
|||
{
|
||||
ERR("SSL_set_fd failed: %s\n",
|
||||
pERR_error_string(pERR_get_error(), 0));
|
||||
INTERNET_SetLastError(ERROR_INTERNET_SECURITY_CHANNEL_ERROR);
|
||||
res = ERROR_INTERNET_SECURITY_CHANNEL_ERROR;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -478,7 +479,7 @@ BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
|||
{
|
||||
ERR("SSL_connect failed: %s\n",
|
||||
pERR_error_string(pERR_get_error(), 0));
|
||||
INTERNET_SetLastError(ERROR_INTERNET_SECURITY_CHANNEL_ERROR);
|
||||
res = ERROR_INTERNET_SECURITY_CHANNEL_ERROR;
|
||||
goto fail;
|
||||
}
|
||||
cert = pSSL_get_peer_certificate(connection->ssl_s);
|
||||
|
@ -486,7 +487,7 @@ BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
|||
{
|
||||
ERR("no certificate for server %s\n", debugstr_w(hostname));
|
||||
/* FIXME: is this the best error? */
|
||||
INTERNET_SetLastError(ERROR_INTERNET_INVALID_CA);
|
||||
res = ERROR_INTERNET_INVALID_CA;
|
||||
goto fail;
|
||||
}
|
||||
verify_res = pSSL_get_verify_result(connection->ssl_s);
|
||||
|
@ -501,7 +502,7 @@ BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
|||
hostname_unix = HeapAlloc(GetProcessHeap(), 0, len);
|
||||
if (!hostname_unix)
|
||||
{
|
||||
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
||||
res = ERROR_OUTOFMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
WideCharToMultiByte(CP_UNIXCP, 0, hostname, -1, hostname_unix, len, NULL, NULL);
|
||||
|
@ -509,13 +510,13 @@ BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname)
|
|||
if (!check_hostname(cert, hostname_unix))
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, hostname_unix);
|
||||
INTERNET_SetLastError(ERROR_INTERNET_SEC_CERT_CN_INVALID);
|
||||
res = ERROR_INTERNET_SEC_CERT_CN_INVALID;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, hostname_unix);
|
||||
connection->useSSL = TRUE;
|
||||
return TRUE;
|
||||
return ERROR_SUCCESS;
|
||||
|
||||
fail:
|
||||
if (connection->ssl_s)
|
||||
|
@ -525,7 +526,7 @@ fail:
|
|||
connection->ssl_s = NULL;
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
return res;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -555,19 +556,16 @@ DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *s
|
|||
* Basically calls 'send()' unless we should use SSL
|
||||
* number of chars send is put in *sent
|
||||
*/
|
||||
BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
|
||||
DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
|
||||
int *sent /* out */)
|
||||
{
|
||||
if (!NETCON_connected(connection)) return FALSE;
|
||||
if (!NETCON_connected(connection)) return ERROR_INTERNET_CONNECTION_ABORTED;
|
||||
if (!connection->useSSL)
|
||||
{
|
||||
*sent = send(connection->socketFD, msg, len, flags);
|
||||
if (*sent == -1)
|
||||
{
|
||||
INTERNET_SetLastError(sock_get_error(errno));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
return sock_get_error(errno);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -576,10 +574,10 @@ BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len,
|
|||
FIXME("SSL_write doesn't support any flags (%08x)\n", flags);
|
||||
*sent = pSSL_write(connection->ssl_s, msg, len);
|
||||
if (*sent < 1 && len)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
return ERROR_INTERNET_CONNECTION_ABORTED;
|
||||
return ERROR_SUCCESS;
|
||||
#else
|
||||
return FALSE;
|
||||
return ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue