2003-07-22 05:17:52 +02:00
|
|
|
/*
|
|
|
|
* Wininet
|
|
|
|
*
|
|
|
|
* Copyright 2003 Mike McCormack for CodeWeavers Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
#include "winnetwk.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#define NO_SHLWAPI_STREAM
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
|
|
|
#include "internet.h"
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
|
|
|
|
|
|
|
struct WININET_ErrorDlgParams
|
|
|
|
{
|
|
|
|
HWND hWnd;
|
|
|
|
HINTERNET hRequest;
|
|
|
|
DWORD dwError;
|
|
|
|
DWORD dwFlags;
|
|
|
|
LPVOID* lppvData;
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WININET_GetProxyServer
|
|
|
|
*
|
|
|
|
* Determine the name of the proxy server the request is using
|
|
|
|
*/
|
2004-03-25 06:29:47 +01:00
|
|
|
static BOOL WININET_GetProxyServer( HINTERNET hRequest, LPWSTR szBuf, DWORD sz )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
2004-06-01 22:19:56 +02:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = NULL;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
|
|
|
LPWSTR p;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2004-06-01 22:19:56 +02:00
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest );
|
2003-07-22 05:17:52 +02:00
|
|
|
if (NULL == lpwhr)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
|
2003-07-22 05:17:52 +02:00
|
|
|
if (NULL == lpwhs)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2003-07-22 05:17:52 +02:00
|
|
|
if (NULL == hIC)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
strncpyW(szBuf, hIC->lpszProxy, sz);
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
/* FIXME: perhaps it would be better to use InternetCrackUrl here */
|
2004-03-25 06:29:47 +01:00
|
|
|
p = strchrW(szBuf, ':');
|
2003-07-22 05:17:52 +02:00
|
|
|
if(*p)
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WININET_GetAuthRealm
|
|
|
|
*
|
|
|
|
* Determine the name of the (basic) Authentication realm
|
|
|
|
*/
|
2004-03-25 06:29:47 +01:00
|
|
|
static BOOL WININET_GetAuthRealm( HINTERNET hRequest, LPWSTR szBuf, DWORD sz )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWSTR p, q;
|
2003-07-22 05:17:52 +02:00
|
|
|
DWORD index;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szRealm[] = { 'r','e','a','l','m','=',0 };
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
/* extract the Realm from the proxy response and show it */
|
|
|
|
index = 0;
|
2004-03-25 06:29:47 +01:00
|
|
|
if( !HttpQueryInfoW( hRequest, HTTP_QUERY_PROXY_AUTHENTICATE,
|
2003-07-22 05:17:52 +02:00
|
|
|
szBuf, &sz, &index) )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: maybe we should check that we're
|
|
|
|
* dealing with 'Basic' Authentication
|
|
|
|
*/
|
2004-03-25 06:29:47 +01:00
|
|
|
p = strchrW( szBuf, ' ' );
|
|
|
|
if( p && !strncmpW( p+1, szRealm, strlenW(szRealm) ) )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
/* remove quotes */
|
|
|
|
p += 7;
|
|
|
|
if( *p == '"' )
|
|
|
|
{
|
|
|
|
p++;
|
2004-03-25 06:29:47 +01:00
|
|
|
q = strrchrW( p, '"' );
|
2003-07-22 05:17:52 +02:00
|
|
|
if( q )
|
|
|
|
*q = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
strcpyW( szBuf, p );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WININET_GetSetPassword
|
|
|
|
*/
|
2004-03-25 06:29:47 +01:00
|
|
|
static BOOL WININET_GetSetPassword( HWND hdlg, LPCWSTR szServer,
|
|
|
|
LPCWSTR szRealm, BOOL bSet )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
2004-03-25 06:29:47 +01:00
|
|
|
WCHAR szResource[0x80], szUserPass[0x40];
|
|
|
|
LPWSTR p;
|
2003-07-22 05:17:52 +02:00
|
|
|
HWND hUserItem, hPassItem;
|
|
|
|
DWORD r, dwMagic = 19;
|
2004-03-25 06:29:47 +01:00
|
|
|
UINT r_len, u_len;
|
2003-07-22 05:17:52 +02:00
|
|
|
WORD sz;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szColon[] = { ':',0 };
|
|
|
|
static const WCHAR szbs[] = { '/', 0 };
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
hUserItem = GetDlgItem( hdlg, IDC_USERNAME );
|
|
|
|
hPassItem = GetDlgItem( hdlg, IDC_PASSWORD );
|
|
|
|
|
|
|
|
/* now try fetch the username and password */
|
2004-03-25 06:29:47 +01:00
|
|
|
lstrcpyW( szResource, szServer);
|
|
|
|
lstrcatW( szResource, szbs);
|
|
|
|
lstrcatW( szResource, szRealm);
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
/*
|
|
|
|
* WNetCachePassword is only concerned with the length
|
|
|
|
* of the data stored (which we tell it) and it does
|
|
|
|
* not use strlen() internally so we can add WCHAR data
|
|
|
|
* instead of ASCII data and get it back the same way.
|
|
|
|
*/
|
2003-07-22 05:17:52 +02:00
|
|
|
if( bSet )
|
|
|
|
{
|
|
|
|
szUserPass[0] = 0;
|
2004-03-25 06:29:47 +01:00
|
|
|
GetWindowTextW( hUserItem, szUserPass,
|
|
|
|
(sizeof szUserPass-1)/sizeof(WCHAR) );
|
|
|
|
lstrcatW(szUserPass, szColon);
|
|
|
|
u_len = strlenW( szUserPass );
|
|
|
|
GetWindowTextW( hPassItem, szUserPass+u_len,
|
|
|
|
(sizeof szUserPass)/sizeof(WCHAR)-u_len );
|
|
|
|
|
|
|
|
r_len = (strlenW( szResource ) + 1)*sizeof(WCHAR);
|
|
|
|
u_len = (strlenW( szUserPass ) + 1)*sizeof(WCHAR);
|
|
|
|
r = WNetCachePassword( (CHAR*)szResource, r_len,
|
|
|
|
(CHAR*)szUserPass, u_len, dwMagic, 0 );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
return ( r == WN_SUCCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = sizeof szUserPass;
|
2004-03-25 06:29:47 +01:00
|
|
|
r_len = (strlenW( szResource ) + 1)*sizeof(WCHAR);
|
|
|
|
r = WNetGetCachedPassword( (CHAR*)szResource, r_len,
|
|
|
|
(CHAR*)szUserPass, &sz, dwMagic );
|
2003-07-22 05:17:52 +02:00
|
|
|
if( r != WN_SUCCESS )
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
p = strchrW( szUserPass, ':' );
|
2003-07-22 05:17:52 +02:00
|
|
|
if( p )
|
|
|
|
{
|
|
|
|
*p = 0;
|
2004-03-25 06:29:47 +01:00
|
|
|
SetWindowTextW( hUserItem, szUserPass );
|
|
|
|
SetWindowTextW( hPassItem, p+1 );
|
2003-07-22 05:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WININET_SetProxyAuthorization
|
|
|
|
*/
|
|
|
|
static BOOL WININET_SetProxyAuthorization( HINTERNET hRequest,
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWSTR username, LPWSTR password )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
2004-06-01 22:19:56 +02:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC;
|
|
|
|
LPWSTR p;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2004-06-01 22:19:56 +02:00
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest );
|
|
|
|
if( !lpwhr )
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
|
2003-07-22 05:17:52 +02:00
|
|
|
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
p = HeapAlloc( GetProcessHeap(), 0, (strlenW( username ) + 1)*sizeof(WCHAR) );
|
2003-07-22 05:17:52 +02:00
|
|
|
if( !p )
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
lstrcpyW( p, username );
|
2003-07-22 05:17:52 +02:00
|
|
|
hIC->lpszProxyUsername = p;
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
p = HeapAlloc( GetProcessHeap(), 0, (strlenW( password ) + 1)*sizeof(WCHAR) );
|
2003-07-22 05:17:52 +02:00
|
|
|
if( !p )
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
lstrcpyW( p, password );
|
2003-07-22 05:17:52 +02:00
|
|
|
hIC->lpszProxyPassword = p;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WININET_ProxyPasswordDialog
|
|
|
|
*/
|
|
|
|
static INT_PTR WINAPI WININET_ProxyPasswordDialog(
|
|
|
|
HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
|
|
|
HWND hitem;
|
|
|
|
struct WININET_ErrorDlgParams *params;
|
2004-03-25 06:29:47 +01:00
|
|
|
WCHAR szRealm[0x80], szServer[0x80];
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
if( uMsg == WM_INITDIALOG )
|
|
|
|
{
|
|
|
|
TRACE("WM_INITDIALOG (%08lx)\n", lParam);
|
|
|
|
|
|
|
|
/* save the parameter list */
|
|
|
|
params = (struct WININET_ErrorDlgParams*) lParam;
|
|
|
|
SetWindowLongW( hdlg, GWL_USERDATA, lParam );
|
|
|
|
|
|
|
|
/* extract the Realm from the proxy response and show it */
|
|
|
|
if( WININET_GetAuthRealm( params->hRequest,
|
2004-03-25 06:29:47 +01:00
|
|
|
szRealm, sizeof szRealm/sizeof(WCHAR)) )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
hitem = GetDlgItem( hdlg, IDC_REALM );
|
2004-03-25 06:29:47 +01:00
|
|
|
SetWindowTextW( hitem, szRealm );
|
2003-07-22 05:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* extract the name of the proxy server */
|
|
|
|
if( WININET_GetProxyServer( params->hRequest,
|
2004-03-25 06:29:47 +01:00
|
|
|
szServer, sizeof szServer/sizeof(WCHAR)) )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
hitem = GetDlgItem( hdlg, IDC_PROXY );
|
2004-03-25 06:29:47 +01:00
|
|
|
SetWindowTextW( hitem, szServer );
|
2003-07-22 05:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WININET_GetSetPassword( hdlg, szServer, szRealm, FALSE );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
params = (struct WININET_ErrorDlgParams*)
|
|
|
|
GetWindowLongW( hdlg, GWL_USERDATA );
|
|
|
|
|
|
|
|
switch( uMsg )
|
|
|
|
{
|
|
|
|
case WM_COMMAND:
|
|
|
|
if( wParam == IDOK )
|
|
|
|
{
|
2004-03-25 06:29:47 +01:00
|
|
|
WCHAR username[0x20], password[0x20];
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
username[0] = 0;
|
|
|
|
hitem = GetDlgItem( hdlg, IDC_USERNAME );
|
|
|
|
if( hitem )
|
2004-03-25 06:29:47 +01:00
|
|
|
GetWindowTextW( hitem, username, sizeof username/sizeof(WCHAR) );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
password[0] = 0;
|
|
|
|
hitem = GetDlgItem( hdlg, IDC_PASSWORD );
|
|
|
|
if( hitem )
|
2004-03-25 06:29:47 +01:00
|
|
|
GetWindowTextW( hitem, password, sizeof password/sizeof(WCHAR) );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD );
|
|
|
|
if( hitem &&
|
2004-03-25 06:29:47 +01:00
|
|
|
SendMessageW( hitem, BM_GETSTATE, 0, 0 ) &&
|
2003-07-22 05:17:52 +02:00
|
|
|
WININET_GetAuthRealm( params->hRequest,
|
2004-03-25 06:29:47 +01:00
|
|
|
szRealm, sizeof szRealm/sizeof(WCHAR)) &&
|
2003-07-22 05:17:52 +02:00
|
|
|
WININET_GetProxyServer( params->hRequest,
|
2004-03-25 06:29:47 +01:00
|
|
|
szServer, sizeof szServer/sizeof(WCHAR)) )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
WININET_GetSetPassword( hdlg, szServer, szRealm, TRUE );
|
|
|
|
}
|
2004-06-01 22:19:56 +02:00
|
|
|
WININET_SetProxyAuthorization( params->hRequest, username, password );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
EndDialog( hdlg, ERROR_INTERNET_FORCE_RETRY );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if( wParam == IDCANCEL )
|
|
|
|
{
|
|
|
|
EndDialog( hdlg, 0 );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WININET_GetConnectionStatus
|
|
|
|
*/
|
|
|
|
static INT WININET_GetConnectionStatus( HINTERNET hRequest )
|
|
|
|
{
|
2004-03-25 06:29:47 +01:00
|
|
|
WCHAR szStatus[0x20];
|
2003-07-22 05:17:52 +02:00
|
|
|
DWORD sz, index, dwStatus;
|
|
|
|
|
|
|
|
TRACE("%p\n", hRequest );
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
sz = sizeof szStatus;
|
2003-07-22 05:17:52 +02:00
|
|
|
index = 0;
|
2004-03-25 06:29:47 +01:00
|
|
|
if( !HttpQueryInfoW( hRequest, HTTP_QUERY_STATUS_CODE,
|
2003-07-22 05:17:52 +02:00
|
|
|
szStatus, &sz, &index))
|
|
|
|
return -1;
|
2004-03-25 06:29:47 +01:00
|
|
|
dwStatus = atoiW( szStatus );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
TRACE("request %p status = %ld\n", hRequest, dwStatus );
|
|
|
|
|
|
|
|
return dwStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InternetErrorDlg
|
|
|
|
*/
|
|
|
|
DWORD WINAPI InternetErrorDlg(HWND hWnd, HINTERNET hRequest,
|
|
|
|
DWORD dwError, DWORD dwFlags, LPVOID* lppvData)
|
|
|
|
{
|
|
|
|
struct WININET_ErrorDlgParams params;
|
|
|
|
HMODULE hwininet = GetModuleHandleA( "wininet.dll" );
|
|
|
|
INT dwStatus;
|
|
|
|
|
|
|
|
TRACE("%p %p %ld %08lx %p\n", hWnd, hRequest, dwError, dwFlags, lppvData);
|
|
|
|
|
|
|
|
params.hWnd = hWnd;
|
|
|
|
params.hRequest = hRequest;
|
|
|
|
params.dwError = dwError;
|
|
|
|
params.dwFlags = dwFlags;
|
|
|
|
params.lppvData = lppvData;
|
|
|
|
|
|
|
|
switch( dwError )
|
|
|
|
{
|
|
|
|
case ERROR_SUCCESS:
|
|
|
|
if( !(dwFlags & FLAGS_ERROR_UI_FILTER_FOR_ERRORS ) )
|
|
|
|
return 0;
|
|
|
|
dwStatus = WININET_GetConnectionStatus( hRequest );
|
|
|
|
if( HTTP_STATUS_PROXY_AUTH_REQ != dwStatus )
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
return DialogBoxParamW( hwininet, MAKEINTRESOURCEW( IDD_PROXYDLG ),
|
|
|
|
hWnd, WININET_ProxyPasswordDialog, (LPARAM) ¶ms );
|
|
|
|
|
|
|
|
case ERROR_INTERNET_INCORRECT_PASSWORD:
|
|
|
|
return DialogBoxParamW( hwininet, MAKEINTRESOURCEW( IDD_PROXYDLG ),
|
|
|
|
hWnd, WININET_ProxyPasswordDialog, (LPARAM) ¶ms );
|
|
|
|
|
|
|
|
case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
|
|
|
|
case ERROR_INTERNET_INVALID_CA:
|
|
|
|
case ERROR_INTERNET_POST_IS_NON_SECURE:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_CN_INVALID:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_DATE_INVALID:
|
|
|
|
FIXME("Need to display dialog for error %ld\n", dwError);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|