Cancel previous credential prompt if EapHost wants a new one

(fixes #27)

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2019-08-14 16:02:32 +02:00
parent 24a02e5adf
commit ab3ffc63f7

View File

@ -145,6 +145,26 @@ void eap::peer_ttls_ui::invoke_identity_ui(
_Out_ DWORD *pdwUserDataOutSize,
_Out_ LPWSTR *ppwszIdentity)
{
static HWND volatile hWndCurrent = NULL;
class ui_canceller
{
public:
ui_canceller(_In_ HWND hWnd)
{
HWND hWndPrev = (HWND)InterlockedCompareExchangePointer((PVOID volatile *)&hWndCurrent, hWnd, NULL);
if (hWndPrev) {
PostMessage(hWndPrev, WM_CLOSE, 0, 0);
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Aborted.");
}
}
~ui_canceller()
{
InterlockedExchangePointer((PVOID volatile *)&hWndCurrent, NULL);
}
};
assert(ppwszIdentity);
// Unpack configuration.
@ -178,8 +198,11 @@ void eap::peer_ttls_ui::invoke_identity_ui(
FLASHWINFO fwi = { sizeof(FLASHWINFO), dlg.GetHWND(), FLASHW_ALL | FLASHW_TIMERNOFG };
::FlashWindowEx(&fwi);
}
{
ui_canceller lock(dlg.GetHWND());
if (dlg.ShowModal() != wxID_OK)
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled.");
}
cfg_prov = dlg.GetSelection();
assert(cfg_prov);
@ -244,8 +267,11 @@ void eap::peer_ttls_ui::invoke_identity_ui(
FLASHWINFO fwi = { sizeof(FLASHWINFO), dlg.GetHWND(), FLASHW_ALL | FLASHW_TIMERNOFG };
::FlashWindowEx(&fwi);
}
{
ui_canceller lock(dlg.GetHWND());
if (dlg.ShowModal() != wxID_OK)
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled.");
}
if (panel->GetRemember()) {
// Write credentials to credential manager.
@ -315,8 +341,11 @@ void eap::peer_ttls_ui::invoke_identity_ui(
FLASHWINFO fwi = { sizeof(FLASHWINFO), dlg.GetHWND(), FLASHW_ALL | FLASHW_TIMERNOFG };
::FlashWindowEx(&fwi);
}
{
ui_canceller lock(dlg.GetHWND());
if (dlg.ShowModal() != wxID_OK)
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled.");
}
// Write credentials to credential manager.
if (panel->GetRemember()) {