2007-01-22 22:48:51 +01:00
|
|
|
/*
|
|
|
|
* Credentials User Interface
|
|
|
|
*
|
|
|
|
* Copyright 2006 Robert Shearman (for CodeWeavers)
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnt.h"
|
2007-01-22 22:50:12 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "wincred.h"
|
2015-08-14 15:00:23 +02:00
|
|
|
#include "rpc.h"
|
|
|
|
#include "sspi.h"
|
2007-10-25 20:17:45 +02:00
|
|
|
#include "commctrl.h"
|
2007-01-22 22:50:12 +01:00
|
|
|
|
|
|
|
#include "credui_resources.h"
|
2007-01-22 22:48:51 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2007-10-24 17:16:02 +02:00
|
|
|
#include "wine/list.h"
|
2007-01-22 22:48:51 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(credui);
|
|
|
|
|
2007-11-19 19:31:44 +01:00
|
|
|
#define TOOLID_INCORRECTPASSWORD 1
|
|
|
|
#define TOOLID_CAPSLOCKON 2
|
|
|
|
|
|
|
|
#define ID_CAPSLOCKPOP 1
|
|
|
|
|
2007-10-24 17:16:02 +02:00
|
|
|
struct pending_credentials
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
PWSTR pszTargetName;
|
|
|
|
PWSTR pszUsername;
|
|
|
|
PWSTR pszPassword;
|
2007-11-17 18:30:19 +01:00
|
|
|
BOOL generic;
|
2007-10-24 17:16:02 +02:00
|
|
|
};
|
|
|
|
|
2007-01-22 22:50:12 +01:00
|
|
|
static HINSTANCE hinstCredUI;
|
|
|
|
|
2007-11-06 14:38:54 +01:00
|
|
|
static struct list pending_credentials_list = LIST_INIT(pending_credentials_list);
|
2007-10-24 17:16:02 +02:00
|
|
|
|
|
|
|
static CRITICAL_SECTION csPendingCredentials;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &csPendingCredentials,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": csPendingCredentials") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION csPendingCredentials = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
2007-01-22 22:48:51 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
2011-11-16 16:30:18 +01:00
|
|
|
struct pending_credentials *entry, *cursor2;
|
2007-10-24 17:16:02 +02:00
|
|
|
TRACE("(0x%p, %d, %p)\n",hinstDLL,fdwReason,lpvReserved);
|
|
|
|
|
2011-11-16 16:30:18 +01:00
|
|
|
switch (fdwReason)
|
2007-10-24 17:16:02 +02:00
|
|
|
{
|
2011-11-16 16:30:18 +01:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2007-10-24 17:16:02 +02:00
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
hinstCredUI = hinstDLL;
|
2007-10-25 20:17:45 +02:00
|
|
|
InitCommonControls();
|
2011-11-16 16:30:18 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-05-15 10:15:39 +02:00
|
|
|
if (lpvReserved) break;
|
2007-10-24 17:16:02 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, cursor2, &pending_credentials_list, struct pending_credentials, entry)
|
|
|
|
{
|
|
|
|
list_remove(&entry->entry);
|
2007-01-22 22:48:51 +01:00
|
|
|
|
2007-10-24 17:16:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszTargetName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszUsername);
|
2019-05-29 08:50:22 +02:00
|
|
|
SecureZeroMemory(entry->pszPassword, lstrlenW(entry->pszPassword) * sizeof(WCHAR));
|
2007-10-24 17:16:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszPassword);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
}
|
2011-11-16 16:30:18 +01:00
|
|
|
DeleteCriticalSection(&csPendingCredentials);
|
|
|
|
break;
|
2007-10-24 17:16:02 +02:00
|
|
|
}
|
2007-01-22 22:48:51 +01:00
|
|
|
|
2007-10-24 17:16:02 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-22 22:48:51 +01:00
|
|
|
|
2007-10-24 17:16:02 +02:00
|
|
|
static DWORD save_credentials(PCWSTR pszTargetName, PCWSTR pszUsername,
|
2007-11-17 18:30:19 +01:00
|
|
|
PCWSTR pszPassword, BOOL generic)
|
2007-10-24 17:16:02 +02:00
|
|
|
{
|
2007-11-17 18:30:19 +01:00
|
|
|
CREDENTIALW cred;
|
|
|
|
|
|
|
|
TRACE("saving servername %s with username %s\n", debugstr_w(pszTargetName), debugstr_w(pszUsername));
|
|
|
|
|
|
|
|
cred.Flags = 0;
|
|
|
|
cred.Type = generic ? CRED_TYPE_GENERIC : CRED_TYPE_DOMAIN_PASSWORD;
|
|
|
|
cred.TargetName = (LPWSTR)pszTargetName;
|
|
|
|
cred.Comment = NULL;
|
2019-05-29 08:50:22 +02:00
|
|
|
cred.CredentialBlobSize = lstrlenW(pszPassword) * sizeof(WCHAR);
|
2007-11-17 18:30:19 +01:00
|
|
|
cred.CredentialBlob = (LPBYTE)pszPassword;
|
|
|
|
cred.Persist = CRED_PERSIST_ENTERPRISE;
|
|
|
|
cred.AttributeCount = 0;
|
|
|
|
cred.Attributes = NULL;
|
|
|
|
cred.TargetAlias = NULL;
|
|
|
|
cred.UserName = (LPWSTR)pszUsername;
|
|
|
|
|
|
|
|
if (CredWriteW(&cred, 0))
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD ret = GetLastError();
|
|
|
|
ERR("CredWriteW failed with error %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-01-22 22:48:51 +01:00
|
|
|
}
|
2007-01-22 22:50:12 +01:00
|
|
|
|
|
|
|
struct cred_dialog_params
|
|
|
|
{
|
|
|
|
PCWSTR pszTargetName;
|
|
|
|
PCWSTR pszMessageText;
|
|
|
|
PCWSTR pszCaptionText;
|
|
|
|
HBITMAP hbmBanner;
|
|
|
|
PWSTR pszUsername;
|
|
|
|
ULONG ulUsernameMaxChars;
|
|
|
|
PWSTR pszPassword;
|
|
|
|
ULONG ulPasswordMaxChars;
|
|
|
|
BOOL fSave;
|
2007-10-25 20:17:45 +02:00
|
|
|
DWORD dwFlags;
|
2007-11-19 19:20:52 +01:00
|
|
|
HWND hwndBalloonTip;
|
2007-11-19 19:31:44 +01:00
|
|
|
BOOL fBalloonTipActive;
|
2007-01-22 22:50:12 +01:00
|
|
|
};
|
|
|
|
|
2009-06-10 21:54:55 +02:00
|
|
|
static void CredDialogFillUsernameCombo(HWND hwndUsername, const struct cred_dialog_params *params)
|
2007-11-17 18:31:02 +01:00
|
|
|
{
|
|
|
|
DWORD count;
|
|
|
|
DWORD i;
|
|
|
|
PCREDENTIALW *credentials;
|
|
|
|
|
|
|
|
if (!CredEnumerateW(NULL, 0, &count, &credentials))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
COMBOBOXEXITEMW comboitem;
|
2007-11-17 18:31:16 +01:00
|
|
|
DWORD j;
|
|
|
|
BOOL duplicate = FALSE;
|
2007-11-17 18:31:02 +01:00
|
|
|
|
2018-10-12 14:50:25 +02:00
|
|
|
if (!credentials[i]->UserName)
|
|
|
|
continue;
|
|
|
|
|
2007-11-17 18:31:02 +01:00
|
|
|
if (params->dwFlags & CREDUI_FLAGS_GENERIC_CREDENTIALS)
|
|
|
|
{
|
2018-10-12 14:50:25 +02:00
|
|
|
if (credentials[i]->Type != CRED_TYPE_GENERIC)
|
|
|
|
{
|
|
|
|
credentials[i]->UserName = NULL;
|
2007-11-17 18:31:02 +01:00
|
|
|
continue;
|
2018-10-12 14:50:25 +02:00
|
|
|
}
|
2007-11-17 18:31:02 +01:00
|
|
|
}
|
2018-10-12 14:50:25 +02:00
|
|
|
else if (credentials[i]->Type == CRED_TYPE_GENERIC)
|
2007-11-17 18:31:02 +01:00
|
|
|
{
|
2018-10-12 14:50:25 +02:00
|
|
|
credentials[i]->UserName = NULL;
|
|
|
|
continue;
|
2007-11-17 18:31:02 +01:00
|
|
|
}
|
|
|
|
|
2007-11-17 18:31:16 +01:00
|
|
|
/* don't add another item with the same name if we've already added it */
|
|
|
|
for (j = 0; j < i; j++)
|
2018-10-12 14:50:25 +02:00
|
|
|
if (credentials[j]->UserName
|
2019-05-29 08:50:22 +02:00
|
|
|
&& !lstrcmpW(credentials[i]->UserName, credentials[j]->UserName))
|
2007-11-17 18:31:16 +01:00
|
|
|
{
|
|
|
|
duplicate = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (duplicate)
|
|
|
|
continue;
|
|
|
|
|
2007-11-17 18:31:02 +01:00
|
|
|
comboitem.mask = CBEIF_TEXT;
|
|
|
|
comboitem.iItem = -1;
|
|
|
|
comboitem.pszText = credentials[i]->UserName;
|
|
|
|
SendMessageW(hwndUsername, CBEM_INSERTITEMW, 0, (LPARAM)&comboitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
CredFree(credentials);
|
|
|
|
}
|
|
|
|
|
2007-11-19 19:31:44 +01:00
|
|
|
static void CredDialogCreateBalloonTip(HWND hwndDlg, struct cred_dialog_params *params)
|
|
|
|
{
|
|
|
|
TTTOOLINFOW toolinfo;
|
|
|
|
WCHAR wszText[256];
|
|
|
|
|
|
|
|
if (params->hwndBalloonTip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
params->hwndBalloonTip = CreateWindowExW(WS_EX_TOOLWINDOW, TOOLTIPS_CLASSW,
|
|
|
|
NULL, WS_POPUP | TTS_NOPREFIX | TTS_BALLOON, CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndDlg, NULL,
|
|
|
|
hinstCredUI, NULL);
|
|
|
|
SetWindowPos(params->hwndBalloonTip, HWND_TOPMOST, 0, 0, 0, 0,
|
|
|
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
|
|
|
|
2018-07-09 20:59:18 +02:00
|
|
|
if (!LoadStringW(hinstCredUI, IDS_INCORRECTPASSWORD, wszText, ARRAY_SIZE(wszText)))
|
2007-11-19 19:31:44 +01:00
|
|
|
{
|
|
|
|
ERR("failed to load IDS_INCORRECTPASSWORD\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toolinfo.cbSize = sizeof(toolinfo);
|
|
|
|
toolinfo.uFlags = TTF_TRACK;
|
|
|
|
toolinfo.hwnd = hwndDlg;
|
|
|
|
toolinfo.uId = TOOLID_INCORRECTPASSWORD;
|
2017-04-17 21:42:01 +02:00
|
|
|
SetRectEmpty(&toolinfo.rect);
|
2007-11-19 19:31:44 +01:00
|
|
|
toolinfo.hinst = NULL;
|
|
|
|
toolinfo.lpszText = wszText;
|
|
|
|
toolinfo.lParam = 0;
|
|
|
|
toolinfo.lpReserved = NULL;
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
|
|
|
|
|
2018-07-09 20:59:18 +02:00
|
|
|
if (!LoadStringW(hinstCredUI, IDS_CAPSLOCKON, wszText, ARRAY_SIZE(wszText)))
|
2007-11-19 19:31:44 +01:00
|
|
|
{
|
|
|
|
ERR("failed to load IDS_CAPSLOCKON\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toolinfo.uId = TOOLID_CAPSLOCKON;
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
|
|
|
|
}
|
|
|
|
|
2007-11-19 19:20:52 +01:00
|
|
|
static void CredDialogShowIncorrectPasswordBalloon(HWND hwndDlg, struct cred_dialog_params *params)
|
|
|
|
{
|
|
|
|
TTTOOLINFOW toolinfo;
|
|
|
|
RECT rcPassword;
|
|
|
|
INT x;
|
|
|
|
INT y;
|
|
|
|
WCHAR wszTitle[256];
|
|
|
|
|
|
|
|
/* user name likely wrong so balloon would be confusing. focus is also
|
|
|
|
* not set to the password edit box, so more notification would need to be
|
|
|
|
* handled */
|
|
|
|
if (!params->pszUsername[0])
|
|
|
|
return;
|
|
|
|
|
2007-11-19 19:31:44 +01:00
|
|
|
/* don't show two balloon tips at once */
|
|
|
|
if (params->fBalloonTipActive)
|
|
|
|
return;
|
|
|
|
|
2018-07-09 20:59:18 +02:00
|
|
|
if (!LoadStringW(hinstCredUI, IDS_INCORRECTPASSWORDTITLE, wszTitle, ARRAY_SIZE(wszTitle)))
|
2007-11-19 19:20:52 +01:00
|
|
|
{
|
|
|
|
ERR("failed to load IDS_INCORRECTPASSWORDTITLE\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-19 19:31:44 +01:00
|
|
|
CredDialogCreateBalloonTip(hwndDlg, params);
|
2007-11-19 19:20:52 +01:00
|
|
|
|
2007-11-19 19:31:44 +01:00
|
|
|
memset(&toolinfo, 0, sizeof(toolinfo));
|
2007-11-19 19:20:52 +01:00
|
|
|
toolinfo.cbSize = sizeof(toolinfo);
|
|
|
|
toolinfo.hwnd = hwndDlg;
|
2007-11-19 19:31:44 +01:00
|
|
|
toolinfo.uId = TOOLID_INCORRECTPASSWORD;
|
2007-11-19 19:20:52 +01:00
|
|
|
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_SETTITLEW, TTI_ERROR, (LPARAM)wszTitle);
|
|
|
|
|
|
|
|
GetWindowRect(GetDlgItem(hwndDlg, IDC_PASSWORD), &rcPassword);
|
2011-07-30 12:03:08 +02:00
|
|
|
/* centered vertically and in the right side of the password edit control */
|
2007-11-19 19:20:52 +01:00
|
|
|
x = rcPassword.right - 12;
|
|
|
|
y = (rcPassword.top + rcPassword.bottom) / 2;
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_TRACKPOSITION, 0, MAKELONG(x, y));
|
|
|
|
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&toolinfo);
|
2007-11-19 19:31:44 +01:00
|
|
|
|
|
|
|
params->fBalloonTipActive = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CredDialogShowCapsLockBalloon(HWND hwndDlg, struct cred_dialog_params *params)
|
|
|
|
{
|
|
|
|
TTTOOLINFOW toolinfo;
|
|
|
|
RECT rcPassword;
|
|
|
|
INT x;
|
|
|
|
INT y;
|
|
|
|
WCHAR wszTitle[256];
|
|
|
|
|
|
|
|
/* don't show two balloon tips at once */
|
|
|
|
if (params->fBalloonTipActive)
|
|
|
|
return;
|
|
|
|
|
2018-07-09 20:59:18 +02:00
|
|
|
if (!LoadStringW(hinstCredUI, IDS_CAPSLOCKONTITLE, wszTitle, ARRAY_SIZE(wszTitle)))
|
2007-11-19 19:31:44 +01:00
|
|
|
{
|
|
|
|
ERR("failed to load IDS_IDSCAPSLOCKONTITLE\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CredDialogCreateBalloonTip(hwndDlg, params);
|
|
|
|
|
|
|
|
memset(&toolinfo, 0, sizeof(toolinfo));
|
|
|
|
toolinfo.cbSize = sizeof(toolinfo);
|
|
|
|
toolinfo.hwnd = hwndDlg;
|
|
|
|
toolinfo.uId = TOOLID_CAPSLOCKON;
|
|
|
|
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_SETTITLEW, TTI_WARNING, (LPARAM)wszTitle);
|
|
|
|
|
|
|
|
GetWindowRect(GetDlgItem(hwndDlg, IDC_PASSWORD), &rcPassword);
|
|
|
|
/* just inside the left side of the password edit control */
|
|
|
|
x = rcPassword.left + 12;
|
|
|
|
y = rcPassword.bottom - 3;
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_TRACKPOSITION, 0, MAKELONG(x, y));
|
|
|
|
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&toolinfo);
|
|
|
|
|
|
|
|
SetTimer(hwndDlg, ID_CAPSLOCKPOP,
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_GETDELAYTIME, TTDT_AUTOPOP, 0),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
params->fBalloonTipActive = TRUE;
|
2007-11-19 19:20:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CredDialogHideBalloonTip(HWND hwndDlg, struct cred_dialog_params *params)
|
|
|
|
{
|
2007-11-19 19:31:44 +01:00
|
|
|
TTTOOLINFOW toolinfo;
|
|
|
|
|
|
|
|
if (!params->hwndBalloonTip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(&toolinfo, 0, sizeof(toolinfo));
|
|
|
|
|
|
|
|
toolinfo.cbSize = sizeof(toolinfo);
|
|
|
|
toolinfo.hwnd = hwndDlg;
|
|
|
|
toolinfo.uId = 0;
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&toolinfo);
|
|
|
|
toolinfo.uId = 1;
|
|
|
|
SendMessageW(params->hwndBalloonTip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&toolinfo);
|
|
|
|
|
|
|
|
params->fBalloonTipActive = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL CredDialogCapsLockOn(void)
|
|
|
|
{
|
2012-08-08 21:06:42 +02:00
|
|
|
return (GetKeyState(VK_CAPITAL) & 0x1) != 0;
|
2007-11-19 19:31:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK CredDialogPasswordSubclassProc(HWND hwnd, UINT uMsg,
|
|
|
|
WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
|
|
|
{
|
|
|
|
struct cred_dialog_params *params = (struct cred_dialog_params *)dwRefData;
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
if (wParam == VK_CAPITAL)
|
|
|
|
{
|
|
|
|
HWND hwndDlg = GetParent(hwnd);
|
|
|
|
if (CredDialogCapsLockOn())
|
|
|
|
CredDialogShowCapsLockBalloon(hwndDlg, params);
|
|
|
|
else
|
|
|
|
CredDialogHideBalloonTip(hwndDlg, params);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_DESTROY:
|
|
|
|
RemoveWindowSubclass(hwnd, CredDialogPasswordSubclassProc, uIdSubclass);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DefSubclassProc(hwnd, uMsg, wParam, lParam);
|
2007-11-19 19:20:52 +01:00
|
|
|
}
|
|
|
|
|
2007-11-17 18:30:39 +01:00
|
|
|
static BOOL CredDialogInit(HWND hwndDlg, struct cred_dialog_params *params)
|
|
|
|
{
|
2007-11-17 18:31:02 +01:00
|
|
|
HWND hwndUsername = GetDlgItem(hwndDlg, IDC_USERNAME);
|
|
|
|
HWND hwndPassword = GetDlgItem(hwndDlg, IDC_PASSWORD);
|
|
|
|
|
2007-11-17 18:30:39 +01:00
|
|
|
SetWindowLongPtrW(hwndDlg, DWLP_USER, (LONG_PTR)params);
|
2007-11-18 22:08:39 +01:00
|
|
|
|
|
|
|
if (params->hbmBanner)
|
|
|
|
SendMessageW(GetDlgItem(hwndDlg, IDB_BANNER), STM_SETIMAGE,
|
|
|
|
IMAGE_BITMAP, (LPARAM)params->hbmBanner);
|
|
|
|
|
2007-11-17 18:30:39 +01:00
|
|
|
if (params->pszMessageText)
|
|
|
|
SetDlgItemTextW(hwndDlg, IDC_MESSAGE, params->pszMessageText);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR format[256];
|
|
|
|
WCHAR message[256];
|
2018-07-09 20:59:18 +02:00
|
|
|
LoadStringW(hinstCredUI, IDS_MESSAGEFORMAT, format, ARRAY_SIZE(format));
|
2019-05-29 08:50:22 +02:00
|
|
|
swprintf(message, ARRAY_SIZE(message), format, params->pszTargetName);
|
2007-11-17 18:30:39 +01:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_MESSAGE, message);
|
|
|
|
}
|
2007-11-17 18:31:02 +01:00
|
|
|
SetWindowTextW(hwndUsername, params->pszUsername);
|
|
|
|
SetWindowTextW(hwndPassword, params->pszPassword);
|
|
|
|
|
|
|
|
CredDialogFillUsernameCombo(hwndUsername, params);
|
2007-11-17 18:30:39 +01:00
|
|
|
|
|
|
|
if (params->pszUsername[0])
|
2007-11-19 19:31:44 +01:00
|
|
|
{
|
|
|
|
/* prevent showing a balloon tip here */
|
|
|
|
params->fBalloonTipActive = TRUE;
|
2007-11-17 18:31:02 +01:00
|
|
|
SetFocus(hwndPassword);
|
2007-11-19 19:31:44 +01:00
|
|
|
params->fBalloonTipActive = FALSE;
|
|
|
|
}
|
2007-11-17 18:30:39 +01:00
|
|
|
else
|
2007-11-17 18:31:02 +01:00
|
|
|
SetFocus(hwndUsername);
|
2007-11-17 18:30:39 +01:00
|
|
|
|
|
|
|
if (params->pszCaptionText)
|
|
|
|
SetWindowTextW(hwndDlg, params->pszCaptionText);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR format[256];
|
|
|
|
WCHAR title[256];
|
2018-07-09 20:59:18 +02:00
|
|
|
LoadStringW(hinstCredUI, IDS_TITLEFORMAT, format, ARRAY_SIZE(format));
|
2019-05-29 08:50:22 +02:00
|
|
|
swprintf(title, ARRAY_SIZE(title), format, params->pszTargetName);
|
2007-11-17 18:30:39 +01:00
|
|
|
SetWindowTextW(hwndDlg, title);
|
|
|
|
}
|
|
|
|
|
2012-10-18 14:16:05 +02:00
|
|
|
if (params->dwFlags & CREDUI_FLAGS_PERSIST ||
|
|
|
|
(params->dwFlags & CREDUI_FLAGS_DO_NOT_PERSIST &&
|
|
|
|
!(params->dwFlags & CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX)))
|
2007-11-17 18:30:39 +01:00
|
|
|
ShowWindow(GetDlgItem(hwndDlg, IDC_SAVE), SW_HIDE);
|
|
|
|
else if (params->fSave)
|
|
|
|
CheckDlgButton(hwndDlg, IDC_SAVE, BST_CHECKED);
|
|
|
|
|
2007-11-19 19:31:44 +01:00
|
|
|
/* setup subclassing for Caps Lock detection */
|
|
|
|
SetWindowSubclass(hwndPassword, CredDialogPasswordSubclassProc, 1, (DWORD_PTR)params);
|
|
|
|
|
2007-11-19 19:20:52 +01:00
|
|
|
if (params->dwFlags & CREDUI_FLAGS_INCORRECT_PASSWORD)
|
|
|
|
CredDialogShowIncorrectPasswordBalloon(hwndDlg, params);
|
2007-11-19 19:31:44 +01:00
|
|
|
else if ((GetFocus() == hwndPassword) && CredDialogCapsLockOn())
|
|
|
|
CredDialogShowCapsLockBalloon(hwndDlg, params);
|
2007-11-19 19:20:52 +01:00
|
|
|
|
2007-11-17 18:30:39 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CredDialogCommandOk(HWND hwndDlg, struct cred_dialog_params *params)
|
|
|
|
{
|
|
|
|
HWND hwndUsername = GetDlgItem(hwndDlg, IDC_USERNAME);
|
|
|
|
LPWSTR user;
|
|
|
|
INT len;
|
|
|
|
INT len2;
|
|
|
|
|
|
|
|
len = GetWindowTextLengthW(hwndUsername);
|
|
|
|
user = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
|
|
|
GetWindowTextW(hwndUsername, user, len + 1);
|
|
|
|
|
|
|
|
if (!user[0])
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, user);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
if (!wcschr(user, '\\') && !wcschr(user, '@'))
|
2007-11-17 18:30:39 +01:00
|
|
|
{
|
2019-05-29 08:50:22 +02:00
|
|
|
ULONG len_target = lstrlenW(params->pszTargetName);
|
2007-11-17 18:30:39 +01:00
|
|
|
memcpy(params->pszUsername, params->pszTargetName,
|
|
|
|
min(len_target, params->ulUsernameMaxChars) * sizeof(WCHAR));
|
|
|
|
if (len_target + 1 < params->ulUsernameMaxChars)
|
|
|
|
params->pszUsername[len_target] = '\\';
|
|
|
|
if (len_target + 2 < params->ulUsernameMaxChars)
|
|
|
|
params->pszUsername[len_target + 1] = '\0';
|
|
|
|
}
|
|
|
|
else if (params->ulUsernameMaxChars > 0)
|
|
|
|
params->pszUsername[0] = '\0';
|
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
len2 = lstrlenW(params->pszUsername);
|
2007-11-17 18:30:39 +01:00
|
|
|
memcpy(params->pszUsername + len2, user, min(len, params->ulUsernameMaxChars - len2) * sizeof(WCHAR));
|
|
|
|
if (params->ulUsernameMaxChars)
|
|
|
|
params->pszUsername[len2 + min(len, params->ulUsernameMaxChars - len2 - 1)] = '\0';
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, user);
|
|
|
|
|
|
|
|
GetDlgItemTextW(hwndDlg, IDC_PASSWORD, params->pszPassword,
|
|
|
|
params->ulPasswordMaxChars);
|
|
|
|
|
2008-01-23 17:33:13 +01:00
|
|
|
params->fSave = IsDlgButtonChecked(hwndDlg, IDC_SAVE) == BST_CHECKED;
|
|
|
|
|
2007-11-17 18:30:39 +01:00
|
|
|
EndDialog(hwndDlg, IDOK);
|
|
|
|
}
|
|
|
|
|
2007-01-22 22:50:12 +01:00
|
|
|
static INT_PTR CALLBACK CredDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
struct cred_dialog_params *params = (struct cred_dialog_params *)lParam;
|
2007-01-26 20:54:24 +01:00
|
|
|
|
2007-11-17 18:30:39 +01:00
|
|
|
return CredDialogInit(hwndDlg, params);
|
2007-01-22 22:50:12 +01:00
|
|
|
}
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case MAKELONG(IDOK, BN_CLICKED):
|
|
|
|
{
|
|
|
|
struct cred_dialog_params *params =
|
|
|
|
(struct cred_dialog_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
2007-11-17 18:30:39 +01:00
|
|
|
CredDialogCommandOk(hwndDlg, params);
|
2007-01-22 22:50:12 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case MAKELONG(IDCANCEL, BN_CLICKED):
|
|
|
|
EndDialog(hwndDlg, IDCANCEL);
|
|
|
|
return TRUE;
|
2007-11-17 18:31:43 +01:00
|
|
|
case MAKELONG(IDC_PASSWORD, EN_SETFOCUS):
|
2007-11-19 19:31:44 +01:00
|
|
|
if (CredDialogCapsLockOn())
|
|
|
|
{
|
|
|
|
struct cred_dialog_params *params =
|
|
|
|
(struct cred_dialog_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
|
|
|
CredDialogShowCapsLockBalloon(hwndDlg, params);
|
|
|
|
}
|
2007-11-17 18:31:43 +01:00
|
|
|
/* don't allow another window to steal focus while the
|
|
|
|
* user is typing their password */
|
|
|
|
LockSetForegroundWindow(LSFW_LOCK);
|
|
|
|
return TRUE;
|
|
|
|
case MAKELONG(IDC_PASSWORD, EN_KILLFOCUS):
|
2007-11-19 19:20:52 +01:00
|
|
|
{
|
|
|
|
struct cred_dialog_params *params =
|
|
|
|
(struct cred_dialog_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
2007-11-17 18:31:43 +01:00
|
|
|
/* the user is no longer typing their password, so allow
|
|
|
|
* other windows to become foreground ones */
|
|
|
|
LockSetForegroundWindow(LSFW_UNLOCK);
|
2007-11-19 19:20:52 +01:00
|
|
|
CredDialogHideBalloonTip(hwndDlg, params);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case MAKELONG(IDC_PASSWORD, EN_CHANGE):
|
|
|
|
{
|
|
|
|
struct cred_dialog_params *params =
|
|
|
|
(struct cred_dialog_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
|
|
|
CredDialogHideBalloonTip(hwndDlg, params);
|
2007-11-17 18:31:43 +01:00
|
|
|
return TRUE;
|
2007-11-19 19:20:52 +01:00
|
|
|
}
|
2007-01-22 22:50:12 +01:00
|
|
|
}
|
2007-11-19 19:20:52 +01:00
|
|
|
return FALSE;
|
2007-11-19 19:31:44 +01:00
|
|
|
case WM_TIMER:
|
|
|
|
if (wParam == ID_CAPSLOCKPOP)
|
|
|
|
{
|
|
|
|
struct cred_dialog_params *params =
|
|
|
|
(struct cred_dialog_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
|
|
|
CredDialogHideBalloonTip(hwndDlg, params);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2007-11-19 19:20:52 +01:00
|
|
|
case WM_DESTROY:
|
|
|
|
{
|
|
|
|
struct cred_dialog_params *params =
|
|
|
|
(struct cred_dialog_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
|
|
|
if (params->hwndBalloonTip) DestroyWindow(params->hwndBalloonTip);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-22 22:50:12 +01:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-18 14:16:52 +02:00
|
|
|
static BOOL find_existing_credential(const WCHAR *target, WCHAR *username, ULONG len_username,
|
|
|
|
WCHAR *password, ULONG len_password)
|
|
|
|
{
|
|
|
|
DWORD count, i;
|
|
|
|
CREDENTIALW **credentials;
|
|
|
|
|
|
|
|
if (!CredEnumerateW(target, 0, &count, &credentials)) return FALSE;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2015-08-14 15:00:23 +02:00
|
|
|
if (credentials[i]->Type != CRED_TYPE_DOMAIN_PASSWORD &&
|
|
|
|
credentials[i]->Type != CRED_TYPE_GENERIC)
|
2012-10-18 14:16:52 +02:00
|
|
|
{
|
|
|
|
FIXME("no support for type %u credentials\n", credentials[i]->Type);
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-29 08:50:22 +02:00
|
|
|
if ((!*username || !lstrcmpW(username, credentials[i]->UserName)) &&
|
|
|
|
lstrlenW(credentials[i]->UserName) < len_username &&
|
2012-10-18 14:16:52 +02:00
|
|
|
credentials[i]->CredentialBlobSize / sizeof(WCHAR) < len_password)
|
|
|
|
{
|
|
|
|
TRACE("found existing credential for %s\n", debugstr_w(credentials[i]->UserName));
|
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
lstrcpyW(username, credentials[i]->UserName);
|
2012-10-18 14:16:52 +02:00
|
|
|
memcpy(password, credentials[i]->CredentialBlob, credentials[i]->CredentialBlobSize);
|
|
|
|
password[credentials[i]->CredentialBlobSize / sizeof(WCHAR)] = 0;
|
|
|
|
|
|
|
|
CredFree(credentials);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CredFree(credentials);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-01-22 22:50:12 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* CredUIPromptForCredentialsW [CREDUI.@]
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CredUIPromptForCredentialsW(PCREDUI_INFOW pUIInfo,
|
|
|
|
PCWSTR pszTargetName,
|
|
|
|
PCtxtHandle Reserved,
|
|
|
|
DWORD dwAuthError,
|
|
|
|
PWSTR pszUsername,
|
|
|
|
ULONG ulUsernameMaxChars,
|
|
|
|
PWSTR pszPassword,
|
2007-02-07 16:23:38 +01:00
|
|
|
ULONG ulPasswordMaxChars, PBOOL pfSave,
|
2007-01-22 22:50:12 +01:00
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
INT_PTR ret;
|
|
|
|
struct cred_dialog_params params;
|
2007-10-24 17:16:02 +02:00
|
|
|
DWORD result = ERROR_SUCCESS;
|
2007-01-22 22:50:12 +01:00
|
|
|
|
2007-09-16 23:24:43 +02:00
|
|
|
TRACE("(%p, %s, %p, %d, %s, %d, %p, %d, %p, 0x%08x)\n", pUIInfo,
|
|
|
|
debugstr_w(pszTargetName), Reserved, dwAuthError, debugstr_w(pszUsername),
|
2007-01-22 22:50:12 +01:00
|
|
|
ulUsernameMaxChars, pszPassword, ulPasswordMaxChars, pfSave, dwFlags);
|
|
|
|
|
2007-10-24 17:16:27 +02:00
|
|
|
if ((dwFlags & (CREDUI_FLAGS_ALWAYS_SHOW_UI|CREDUI_FLAGS_GENERIC_CREDENTIALS)) == CREDUI_FLAGS_ALWAYS_SHOW_UI)
|
|
|
|
return ERROR_INVALID_FLAGS;
|
|
|
|
|
|
|
|
if (!pszTargetName)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if ((dwFlags & CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX) && !pfSave)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2012-10-18 14:16:52 +02:00
|
|
|
if (!(dwFlags & CREDUI_FLAGS_ALWAYS_SHOW_UI) &&
|
|
|
|
!(dwFlags & CREDUI_FLAGS_INCORRECT_PASSWORD) &&
|
|
|
|
find_existing_credential(pszTargetName, pszUsername, ulUsernameMaxChars, pszPassword, ulPasswordMaxChars))
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2007-01-22 22:50:12 +01:00
|
|
|
params.pszTargetName = pszTargetName;
|
|
|
|
if (pUIInfo)
|
|
|
|
{
|
|
|
|
params.pszMessageText = pUIInfo->pszMessageText;
|
|
|
|
params.pszCaptionText = pUIInfo->pszCaptionText;
|
|
|
|
params.hbmBanner = pUIInfo->hbmBanner;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params.pszMessageText = NULL;
|
|
|
|
params.pszCaptionText = NULL;
|
|
|
|
params.hbmBanner = NULL;
|
|
|
|
}
|
|
|
|
params.pszUsername = pszUsername;
|
|
|
|
params.ulUsernameMaxChars = ulUsernameMaxChars;
|
|
|
|
params.pszPassword = pszPassword;
|
|
|
|
params.ulPasswordMaxChars = ulPasswordMaxChars;
|
2007-03-05 13:05:19 +01:00
|
|
|
params.fSave = pfSave ? *pfSave : FALSE;
|
2007-10-25 20:17:45 +02:00
|
|
|
params.dwFlags = dwFlags;
|
2007-11-19 19:20:52 +01:00
|
|
|
params.hwndBalloonTip = NULL;
|
2007-11-19 19:31:44 +01:00
|
|
|
params.fBalloonTipActive = FALSE;
|
2007-01-22 22:50:12 +01:00
|
|
|
|
|
|
|
ret = DialogBoxParamW(hinstCredUI, MAKEINTRESOURCEW(IDD_CREDDIALOG),
|
2007-10-24 17:16:14 +02:00
|
|
|
pUIInfo ? pUIInfo->hwndParent : NULL,
|
|
|
|
CredDialogProc, (LPARAM)¶ms);
|
2007-01-22 22:50:12 +01:00
|
|
|
if (ret <= 0)
|
|
|
|
return GetLastError();
|
|
|
|
|
|
|
|
if (ret == IDCANCEL)
|
|
|
|
{
|
|
|
|
TRACE("dialog cancelled\n");
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2007-03-05 13:05:19 +01:00
|
|
|
if (pfSave)
|
|
|
|
*pfSave = params.fSave;
|
2007-01-22 22:50:12 +01:00
|
|
|
|
2007-10-24 17:16:02 +02:00
|
|
|
if (params.fSave)
|
|
|
|
{
|
|
|
|
if (dwFlags & CREDUI_FLAGS_EXPECT_CONFIRMATION)
|
|
|
|
{
|
|
|
|
BOOL found = FALSE;
|
|
|
|
struct pending_credentials *entry;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
EnterCriticalSection(&csPendingCredentials);
|
|
|
|
|
|
|
|
/* find existing pending credentials for the same target and overwrite */
|
|
|
|
/* FIXME: is this correct? */
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &pending_credentials_list, struct pending_credentials, entry)
|
2019-05-29 08:50:22 +02:00
|
|
|
if (!lstrcmpW(pszTargetName, entry->pszTargetName))
|
2007-10-24 17:16:02 +02:00
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszUsername);
|
2019-05-29 08:50:22 +02:00
|
|
|
SecureZeroMemory(entry->pszPassword, lstrlenW(entry->pszPassword) * sizeof(WCHAR));
|
2007-10-24 17:16:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
|
2019-05-29 08:50:22 +02:00
|
|
|
len = lstrlenW(pszTargetName);
|
2007-10-24 17:16:02 +02:00
|
|
|
entry->pszTargetName = HeapAlloc(GetProcessHeap(), 0, (len + 1)*sizeof(WCHAR));
|
|
|
|
memcpy(entry->pszTargetName, pszTargetName, (len + 1)*sizeof(WCHAR));
|
2008-01-23 17:33:08 +01:00
|
|
|
list_add_tail(&pending_credentials_list, &entry->entry);
|
2007-10-24 17:16:02 +02:00
|
|
|
}
|
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
len = lstrlenW(params.pszUsername);
|
2007-10-24 17:16:02 +02:00
|
|
|
entry->pszUsername = HeapAlloc(GetProcessHeap(), 0, (len + 1)*sizeof(WCHAR));
|
|
|
|
memcpy(entry->pszUsername, params.pszUsername, (len + 1)*sizeof(WCHAR));
|
2019-05-29 08:50:22 +02:00
|
|
|
len = lstrlenW(params.pszPassword);
|
2007-10-24 17:16:02 +02:00
|
|
|
entry->pszPassword = HeapAlloc(GetProcessHeap(), 0, (len + 1)*sizeof(WCHAR));
|
|
|
|
memcpy(entry->pszPassword, params.pszPassword, (len + 1)*sizeof(WCHAR));
|
2012-08-08 21:06:42 +02:00
|
|
|
entry->generic = (dwFlags & CREDUI_FLAGS_GENERIC_CREDENTIALS) != 0;
|
2007-10-24 17:16:02 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&csPendingCredentials);
|
|
|
|
}
|
2012-10-18 14:16:21 +02:00
|
|
|
else if (!(dwFlags & CREDUI_FLAGS_DO_NOT_PERSIST))
|
2007-11-17 18:30:19 +01:00
|
|
|
result = save_credentials(pszTargetName, pszUsername, pszPassword,
|
2012-08-08 21:06:42 +02:00
|
|
|
(dwFlags & CREDUI_FLAGS_GENERIC_CREDENTIALS) != 0);
|
2007-10-24 17:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2007-01-22 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIConfirmCredentialsW [CREDUI.@]
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CredUIConfirmCredentialsW(PCWSTR pszTargetName, BOOL bConfirm)
|
|
|
|
{
|
2007-10-24 17:16:02 +02:00
|
|
|
struct pending_credentials *entry;
|
|
|
|
DWORD result = ERROR_NOT_FOUND;
|
|
|
|
|
|
|
|
TRACE("(%s, %s)\n", debugstr_w(pszTargetName), bConfirm ? "TRUE" : "FALSE");
|
|
|
|
|
|
|
|
if (!pszTargetName)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&csPendingCredentials);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &pending_credentials_list, struct pending_credentials, entry)
|
|
|
|
{
|
2019-05-29 08:50:22 +02:00
|
|
|
if (!lstrcmpW(pszTargetName, entry->pszTargetName))
|
2007-10-24 17:16:02 +02:00
|
|
|
{
|
|
|
|
if (bConfirm)
|
2007-11-17 18:30:19 +01:00
|
|
|
result = save_credentials(entry->pszTargetName, entry->pszUsername,
|
|
|
|
entry->pszPassword, entry->generic);
|
2007-10-24 17:16:02 +02:00
|
|
|
else
|
|
|
|
result = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
list_remove(&entry->entry);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszTargetName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszUsername);
|
2019-05-29 08:50:22 +02:00
|
|
|
SecureZeroMemory(entry->pszPassword, lstrlenW(entry->pszPassword) * sizeof(WCHAR));
|
2007-10-24 17:16:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, entry->pszPassword);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&csPendingCredentials);
|
|
|
|
|
|
|
|
return result;
|
2007-01-22 22:50:12 +01:00
|
|
|
}
|
2007-01-26 20:54:19 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIParseUserNameW [CREDUI.@]
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CredUIParseUserNameW(PCWSTR pszUserName, PWSTR pszUser,
|
|
|
|
ULONG ulMaxUserChars, PWSTR pszDomain,
|
|
|
|
ULONG ulMaxDomainChars)
|
|
|
|
{
|
|
|
|
PWSTR p;
|
|
|
|
|
|
|
|
TRACE("(%s, %p, %d, %p, %d)\n", debugstr_w(pszUserName), pszUser,
|
|
|
|
ulMaxUserChars, pszDomain, ulMaxDomainChars);
|
|
|
|
|
|
|
|
if (!pszUserName || !pszUser || !ulMaxUserChars || !pszDomain ||
|
|
|
|
!ulMaxDomainChars)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* FIXME: handle marshaled credentials */
|
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
p = wcschr(pszUserName, '\\');
|
2007-01-26 20:54:19 +01:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
if (p - pszUserName > ulMaxDomainChars - 1)
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2019-05-29 08:50:22 +02:00
|
|
|
if (lstrlenW(p + 1) > ulMaxUserChars - 1)
|
2007-01-26 20:54:19 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2019-05-29 08:50:22 +02:00
|
|
|
lstrcpyW(pszUser, p + 1);
|
2007-01-26 20:54:19 +01:00
|
|
|
memcpy(pszDomain, pszUserName, (p - pszUserName)*sizeof(WCHAR));
|
|
|
|
pszDomain[p - pszUserName] = '\0';
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
p = wcsrchr(pszUserName, '@');
|
2007-01-26 20:54:19 +01:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
if (p + 1 - pszUserName > ulMaxUserChars - 1)
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2019-05-29 08:50:22 +02:00
|
|
|
if (lstrlenW(p + 1) > ulMaxDomainChars - 1)
|
2007-01-26 20:54:19 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2019-05-29 08:50:22 +02:00
|
|
|
lstrcpyW(pszDomain, p + 1);
|
2007-01-26 20:54:19 +01:00
|
|
|
memcpy(pszUser, pszUserName, (p - pszUserName)*sizeof(WCHAR));
|
|
|
|
pszUser[p - pszUserName] = '\0';
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
if (lstrlenW(pszUserName) > ulMaxUserChars - 1)
|
2007-01-26 20:54:19 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2019-05-29 08:50:22 +02:00
|
|
|
lstrcpyW(pszUser, pszUserName);
|
2007-01-26 20:54:19 +01:00
|
|
|
pszDomain[0] = '\0';
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2007-10-23 23:19:38 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIStoreSSOCredA [CREDUI.@]
|
|
|
|
*/
|
2007-10-24 18:53:33 +02:00
|
|
|
DWORD WINAPI CredUIStoreSSOCredA(PCSTR pszRealm, PCSTR pszUsername,
|
|
|
|
PCSTR pszPassword, BOOL bPersist)
|
2007-10-23 23:19:38 +02:00
|
|
|
{
|
2007-10-24 18:53:33 +02:00
|
|
|
FIXME("(%s, %s, %p, %d)\n", debugstr_a(pszRealm), debugstr_a(pszUsername),
|
|
|
|
pszPassword, bPersist);
|
|
|
|
return ERROR_SUCCESS;
|
2007-10-23 23:19:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIStoreSSOCredW [CREDUI.@]
|
|
|
|
*/
|
2007-10-24 18:53:33 +02:00
|
|
|
DWORD WINAPI CredUIStoreSSOCredW(PCWSTR pszRealm, PCWSTR pszUsername,
|
|
|
|
PCWSTR pszPassword, BOOL bPersist)
|
2007-10-23 23:19:38 +02:00
|
|
|
{
|
2007-10-24 18:53:33 +02:00
|
|
|
FIXME("(%s, %s, %p, %d)\n", debugstr_w(pszRealm), debugstr_w(pszUsername),
|
|
|
|
pszPassword, bPersist);
|
|
|
|
return ERROR_SUCCESS;
|
2007-10-23 23:19:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIReadSSOCredA [CREDUI.@]
|
|
|
|
*/
|
2007-10-24 18:53:33 +02:00
|
|
|
DWORD WINAPI CredUIReadSSOCredA(PCSTR pszRealm, PSTR *ppszUsername)
|
2007-10-23 23:19:38 +02:00
|
|
|
{
|
2007-10-24 18:53:33 +02:00
|
|
|
FIXME("(%s, %p)\n", debugstr_a(pszRealm), ppszUsername);
|
|
|
|
if (ppszUsername)
|
|
|
|
*ppszUsername = NULL;
|
|
|
|
return ERROR_NOT_FOUND;
|
2007-10-23 23:19:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIReadSSOCredW [CREDUI.@]
|
|
|
|
*/
|
2007-10-24 18:53:33 +02:00
|
|
|
DWORD WINAPI CredUIReadSSOCredW(PCWSTR pszRealm, PWSTR *ppszUsername)
|
2007-10-23 23:19:38 +02:00
|
|
|
{
|
2007-10-24 18:53:33 +02:00
|
|
|
FIXME("(%s, %p)\n", debugstr_w(pszRealm), ppszUsername);
|
|
|
|
if (ppszUsername)
|
|
|
|
*ppszUsername = NULL;
|
|
|
|
return ERROR_NOT_FOUND;
|
2007-10-23 23:19:38 +02:00
|
|
|
}
|
2012-07-06 00:35:36 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIInitControls [CREDUI.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CredUIInitControls(void)
|
|
|
|
{
|
|
|
|
FIXME("() stub\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-08-14 15:00:23 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SspiPromptForCredentialsW [CREDUI.@]
|
|
|
|
*/
|
|
|
|
ULONG SEC_ENTRY SspiPromptForCredentialsW( PCWSTR target, void *info,
|
|
|
|
DWORD error, PCWSTR package,
|
|
|
|
PSEC_WINNT_AUTH_IDENTITY_OPAQUE input_id,
|
|
|
|
PSEC_WINNT_AUTH_IDENTITY_OPAQUE *output_id,
|
|
|
|
BOOL *save, DWORD sspi_flags )
|
|
|
|
{
|
|
|
|
WCHAR username[CREDUI_MAX_USERNAME_LENGTH + 1] = {0};
|
|
|
|
WCHAR password[CREDUI_MAX_PASSWORD_LENGTH + 1] = {0};
|
2018-07-09 20:59:18 +02:00
|
|
|
DWORD len_username = ARRAY_SIZE(username);
|
|
|
|
DWORD len_password = ARRAY_SIZE(password);
|
2015-08-14 15:00:23 +02:00
|
|
|
DWORD ret, flags;
|
|
|
|
CREDUI_INFOW *cred_info = info;
|
2016-07-13 10:30:55 +02:00
|
|
|
SEC_WINNT_AUTH_IDENTITY_W *id = input_id;
|
2015-08-14 15:00:23 +02:00
|
|
|
|
|
|
|
FIXME( "(%s, %p, %u, %s, %p, %p, %p, %x) stub\n", debugstr_w(target), info,
|
|
|
|
error, debugstr_w(package), input_id, output_id, save, sspi_flags );
|
|
|
|
|
|
|
|
if (!target) return ERROR_INVALID_PARAMETER;
|
2020-10-08 23:27:59 +02:00
|
|
|
if (!package || (wcsicmp( package, L"Basic" ) && wcsicmp( package, L"NTLM" ) &&
|
|
|
|
wcsicmp( package, L"Negotiate" )))
|
2015-08-14 15:00:23 +02:00
|
|
|
{
|
|
|
|
FIXME( "package %s not supported\n", debugstr_w(package) );
|
|
|
|
return ERROR_NO_SUCH_PACKAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = CREDUI_FLAGS_ALWAYS_SHOW_UI | CREDUI_FLAGS_GENERIC_CREDENTIALS;
|
|
|
|
|
|
|
|
if (sspi_flags & SSPIPFC_CREDPROV_DO_NOT_SAVE)
|
|
|
|
flags |= CREDUI_FLAGS_DO_NOT_PERSIST;
|
|
|
|
|
|
|
|
if (!(sspi_flags & SSPIPFC_NO_CHECKBOX))
|
|
|
|
flags |= CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX;
|
|
|
|
|
2016-07-13 10:30:55 +02:00
|
|
|
if (!id) find_existing_credential( target, username, len_username, password, len_password );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (id->User && id->UserLength > 0 && id->UserLength <= CREDUI_MAX_USERNAME_LENGTH)
|
|
|
|
{
|
|
|
|
memcpy( username, id->User, id->UserLength * sizeof(WCHAR) );
|
|
|
|
username[id->UserLength] = 0;
|
|
|
|
}
|
|
|
|
if (id->Password && id->PasswordLength > 0 && id->PasswordLength <= CREDUI_MAX_PASSWORD_LENGTH)
|
|
|
|
{
|
|
|
|
memcpy( password, id->Password, id->PasswordLength * sizeof(WCHAR) );
|
|
|
|
password[id->PasswordLength] = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-08-14 15:00:23 +02:00
|
|
|
|
|
|
|
if (!(ret = CredUIPromptForCredentialsW( cred_info, target, NULL, error, username,
|
|
|
|
len_username, password, len_password, save, flags )))
|
|
|
|
{
|
2017-02-01 14:18:48 +01:00
|
|
|
DWORD size = sizeof(*id), len_domain = 0;
|
|
|
|
WCHAR *ptr, *user = username, *domain = NULL;
|
2015-08-14 15:00:23 +02:00
|
|
|
|
2019-05-29 08:50:22 +02:00
|
|
|
if ((ptr = wcschr( username, '\\' )))
|
2017-02-01 14:18:48 +01:00
|
|
|
{
|
|
|
|
user = ptr + 1;
|
2019-05-29 08:50:22 +02:00
|
|
|
len_username = lstrlenW( user );
|
2020-10-08 23:27:59 +02:00
|
|
|
if (!wcsicmp( package, L"NTLM" ) || !wcsicmp( package, L"Negotiate" ))
|
2017-02-01 14:18:48 +01:00
|
|
|
{
|
|
|
|
domain = username;
|
|
|
|
len_domain = ptr - username;
|
|
|
|
}
|
|
|
|
*ptr = 0;
|
|
|
|
}
|
2019-05-29 08:50:22 +02:00
|
|
|
else len_username = lstrlenW( username );
|
|
|
|
len_password = lstrlenW( password );
|
2015-08-14 15:00:23 +02:00
|
|
|
|
|
|
|
size += (len_username + 1) * sizeof(WCHAR);
|
2017-02-01 14:18:48 +01:00
|
|
|
size += (len_domain + 1) * sizeof(WCHAR);
|
2015-08-14 15:00:23 +02:00
|
|
|
size += (len_password + 1) * sizeof(WCHAR);
|
|
|
|
if (!(id = HeapAlloc( GetProcessHeap(), 0, size ))) return ERROR_OUTOFMEMORY;
|
|
|
|
ptr = (WCHAR *)(id + 1);
|
|
|
|
|
2017-02-01 14:18:48 +01:00
|
|
|
memcpy( ptr, user, (len_username + 1) * sizeof(WCHAR) );
|
2015-08-14 15:00:23 +02:00
|
|
|
id->User = ptr;
|
|
|
|
id->UserLength = len_username;
|
|
|
|
ptr += len_username + 1;
|
2017-02-01 14:18:48 +01:00
|
|
|
if (len_domain)
|
|
|
|
{
|
|
|
|
memcpy( ptr, domain, (len_domain + 1) * sizeof(WCHAR) );
|
|
|
|
id->Domain = ptr;
|
|
|
|
id->DomainLength = len_domain;
|
|
|
|
ptr += len_domain + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id->Domain = NULL;
|
|
|
|
id->DomainLength = 0;
|
|
|
|
}
|
2015-08-14 15:00:23 +02:00
|
|
|
memcpy( ptr, password, (len_password + 1) * sizeof(WCHAR) );
|
|
|
|
id->Password = ptr;
|
|
|
|
id->PasswordLength = len_password;
|
|
|
|
id->Flags = 0;
|
|
|
|
|
|
|
|
*output_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-07-13 10:30:53 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUIPromptForWindowsCredentialsW [CREDUI.@]
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CredUIPromptForWindowsCredentialsW( CREDUI_INFOW *info, DWORD error, ULONG *package,
|
|
|
|
const void *in_buf, ULONG in_buf_size, void **out_buf,
|
|
|
|
ULONG *out_buf_size, BOOL *save, DWORD flags )
|
|
|
|
{
|
|
|
|
FIXME( "(%p, %u, %p, %p, %u, %p, %p, %p, %08x) stub\n", info, error, package, in_buf, in_buf_size,
|
|
|
|
out_buf, out_buf_size, save, flags );
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
2016-07-13 10:30:54 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredPackAuthenticationBufferW [CREDUI.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CredPackAuthenticationBufferW( DWORD flags, WCHAR *username, WCHAR *password, BYTE *buf,
|
|
|
|
DWORD *size )
|
|
|
|
{
|
|
|
|
FIXME( "(%08x, %s, %p, %p, %p) stub\n", flags, debugstr_w(username), password, buf, size );
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CredUnPackAuthenticationBufferW [CREDUI.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CredUnPackAuthenticationBufferW( DWORD flags, void *buf, DWORD size, WCHAR *username,
|
|
|
|
DWORD *len_username, WCHAR *domain, DWORD *len_domain,
|
|
|
|
WCHAR *password, DWORD *len_password )
|
|
|
|
{
|
|
|
|
FIXME( "(%08x, %p, %u, %p, %p, %p, %p, %p, %p) stub\n", flags, buf, size, username, len_username,
|
|
|
|
domain, len_domain, password, len_password );
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|