Module: wine Branch: master Commit: 6b15db8717635170d7a2e52cbe5d56ca6ef1d78c URL: http://source.winehq.org/git/wine.git/?a=commit;h=6b15db8717635170d7a2e52cbe...
Author: Hans Leidekker hans@codeweavers.com Date: Thu Jul 23 12:05:58 2009 +0200
wininet: Add a regular authentication dialog.
---
dlls/wininet/dialogs.c | 136 +++++++++++++++++++++++++++++++++++++++++--- dlls/wininet/resource.h | 2 + dlls/wininet/wininet_En.rc | 20 +++++++ 3 files changed, 149 insertions(+), 9 deletions(-)
diff --git a/dlls/wininet/dialogs.c b/dlls/wininet/dialogs.c index 3325c7b..7f150c7 100644 --- a/dlls/wininet/dialogs.c +++ b/dlls/wininet/dialogs.c @@ -95,6 +95,34 @@ done: }
/*********************************************************************** + * WININET_GetServer + * + * Determine the name of the web server + */ +static BOOL WININET_GetServer( HINTERNET hRequest, LPWSTR szBuf, DWORD sz ) +{ + http_request_t *lpwhr; + http_session_t *lpwhs = NULL; + BOOL ret = FALSE; + + lpwhr = (http_request_t*) WININET_GetObject( hRequest ); + if (NULL == lpwhr) + goto done; + + lpwhs = lpwhr->lpHttpSession; + if (NULL == lpwhs) + goto done; + + lstrcpynW(szBuf, lpwhs->lpszHostName, sz); + + ret = TRUE; + +done: + WININET_Release( &lpwhr->hdr ); + return ret; +} + +/*********************************************************************** * WININET_GetAuthRealm * * Determine the name of the (basic) Authentication realm @@ -349,6 +377,90 @@ static INT_PTR WINAPI WININET_ProxyPasswordDialog( }
/*********************************************************************** + * WININET_PasswordDialog + */ +static INT_PTR WINAPI WININET_PasswordDialog( + HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) +{ + HWND hitem; + struct WININET_ErrorDlgParams *params; + WCHAR szRealm[0x80], szServer[0x80]; + + if( uMsg == WM_INITDIALOG ) + { + TRACE("WM_INITDIALOG (%08lx)\n", lParam); + + /* save the parameter list */ + params = (struct WININET_ErrorDlgParams*) lParam; + SetWindowLongPtrW( hdlg, GWLP_USERDATA, lParam ); + + /* extract the Realm from the response and show it */ + if( WININET_GetAuthRealm( params->hRequest, + szRealm, sizeof szRealm/sizeof(WCHAR), FALSE ) ) + { + hitem = GetDlgItem( hdlg, IDC_REALM ); + SetWindowTextW( hitem, szRealm ); + } + + /* extract the name of the server */ + if( WININET_GetServer( params->hRequest, + szServer, sizeof szServer/sizeof(WCHAR)) ) + { + hitem = GetDlgItem( hdlg, IDC_SERVER ); + SetWindowTextW( hitem, szServer ); + } + + WININET_GetSetPassword( hdlg, szServer, szRealm, FALSE ); + + return TRUE; + } + + params = (struct WININET_ErrorDlgParams*) + GetWindowLongPtrW( hdlg, GWLP_USERDATA ); + + switch( uMsg ) + { + case WM_COMMAND: + if( wParam == IDOK ) + { + WCHAR username[0x20], password[0x20]; + + username[0] = 0; + hitem = GetDlgItem( hdlg, IDC_USERNAME ); + if( hitem ) + GetWindowTextW( hitem, username, sizeof username/sizeof(WCHAR) ); + + password[0] = 0; + hitem = GetDlgItem( hdlg, IDC_PASSWORD ); + if( hitem ) + GetWindowTextW( hitem, password, sizeof password/sizeof(WCHAR) ); + + hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD ); + if( hitem && + SendMessageW( hitem, BM_GETSTATE, 0, 0 ) && + WININET_GetAuthRealm( params->hRequest, + szRealm, sizeof szRealm/sizeof(WCHAR), FALSE ) && + WININET_GetServer( params->hRequest, + szServer, sizeof szServer/sizeof(WCHAR)) ) + { + WININET_GetSetPassword( hdlg, szServer, szRealm, TRUE ); + } + WININET_SetAuthorization( params->hRequest, username, password, FALSE ); + + 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 ) @@ -392,17 +504,23 @@ DWORD WINAPI InternetErrorDlg(HWND hWnd, HINTERNET hRequest, switch( dwError ) { case ERROR_SUCCESS: - if( !(dwFlags & FLAGS_ERROR_UI_FILTER_FOR_ERRORS ) ) + case ERROR_INTERNET_INCORRECT_PASSWORD: + if( !dwError && !(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 ); + dwStatus = WININET_GetConnectionStatus( hRequest ); + switch (dwStatus) + { + case HTTP_STATUS_PROXY_AUTH_REQ: + return DialogBoxParamW( hwininet, MAKEINTRESOURCEW( IDD_PROXYDLG ), + hWnd, WININET_ProxyPasswordDialog, (LPARAM) ¶ms ); + case HTTP_STATUS_DENIED: + return DialogBoxParamW( hwininet, MAKEINTRESOURCEW( IDD_AUTHDLG ), + hWnd, WININET_PasswordDialog, (LPARAM) ¶ms ); + default: + WARN("unhandled status %u\n", dwStatus); + return 0; + }
case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR: case ERROR_INTERNET_INVALID_CA: diff --git a/dlls/wininet/resource.h b/dlls/wininet/resource.h index 6cabaa0..279c112 100644 --- a/dlls/wininet/resource.h +++ b/dlls/wininet/resource.h @@ -21,6 +21,7 @@ #include <windef.h> #include <winuser.h>
+#define IDD_AUTHDLG 0x399 #define IDD_PROXYDLG 0x400
#define IDC_PROXY 0x401 @@ -28,5 +29,6 @@ #define IDC_USERNAME 0x403 #define IDC_PASSWORD 0x404 #define IDC_SAVEPASSWORD 0x405 +#define IDC_SERVER 0x406
#define IDS_LANCONNECTION 0x500 diff --git a/dlls/wininet/wininet_En.rc b/dlls/wininet/wininet_En.rc index b0450af..d22d249 100644 --- a/dlls/wininet/wininet_En.rc +++ b/dlls/wininet/wininet_En.rc @@ -40,6 +40,26 @@ FONT 8, "MS Shell Dlg" PUSHBUTTON "Cancel", IDCANCEL, 158, 126, 56, 14, WS_GROUP | WS_TABSTOP }
+IDD_AUTHDLG DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 250, 154 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Authentication Required" +FONT 8, "MS Shell Dlg" +{ + LTEXT "Please enter your username and password:", -1, 40, 6, 150, 15 + LTEXT "Server", -1, 40, 26, 50, 10 + LTEXT "Realm", -1, 40, 46, 50, 10 + LTEXT "User", -1, 40, 66, 50, 10 + LTEXT "Password", -1, 40, 86, 50, 10 + LTEXT "" IDC_SERVER, 80, 26, 150, 14, 0 + LTEXT "" IDC_REALM, 80, 46, 150, 14, 0 + EDITTEXT IDC_USERNAME, 80, 66, 150, 14, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP + EDITTEXT IDC_PASSWORD, 80, 86, 150, 14, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP | ES_PASSWORD + CHECKBOX "&Save this password (insecure)", IDC_SAVEPASSWORD, + 80, 106, 150, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP + PUSHBUTTON "OK", IDOK, 98, 126, 56, 14, WS_GROUP | WS_TABSTOP | BS_DEFPUSHBUTTON + PUSHBUTTON "Cancel", IDCANCEL, 158, 126, 56, 14, WS_GROUP | WS_TABSTOP +} + STRINGTABLE DISCARDABLE { IDS_LANCONNECTION "LAN Connection"