2 * Credentials User Interface
4 * Copyright 2006 Robert Shearman (for CodeWeavers)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_NO_STATUS
32 #include "credui_resources.h"
34 #include <wine/debug.h>
35 #include <wine/unicode.h>
36 #include <wine/list.h>
38 WINE_DEFAULT_DEBUG_CHANNEL(credui
);
40 #define TOOLID_INCORRECTPASSWORD 1
41 #define TOOLID_CAPSLOCKON 2
43 #define ID_CAPSLOCKPOP 1
45 struct pending_credentials
54 static HINSTANCE hinstCredUI
;
56 static struct list pending_credentials_list
= LIST_INIT(pending_credentials_list
);
58 static CRITICAL_SECTION csPendingCredentials
;
59 static CRITICAL_SECTION_DEBUG critsect_debug
=
61 0, 0, &csPendingCredentials
,
62 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
63 0, 0, { (DWORD_PTR
)(__FILE__
": csPendingCredentials") }
65 static CRITICAL_SECTION csPendingCredentials
= { &critsect_debug
, -1, 0, 0, 0, 0 };
68 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
70 struct pending_credentials
*entry
, *cursor2
;
71 TRACE("(0x%p, %d, %p)\n",hinstDLL
,fdwReason
,lpvReserved
);
75 case DLL_WINE_PREATTACH
:
76 return FALSE
; /* prefer native version */
78 case DLL_PROCESS_ATTACH
:
79 DisableThreadLibraryCalls(hinstDLL
);
80 hinstCredUI
= hinstDLL
;
84 case DLL_PROCESS_DETACH
:
85 if (lpvReserved
) break;
86 LIST_FOR_EACH_ENTRY_SAFE(entry
, cursor2
, &pending_credentials_list
, struct pending_credentials
, entry
)
88 list_remove(&entry
->entry
);
90 HeapFree(GetProcessHeap(), 0, entry
->pszTargetName
);
91 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
92 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
93 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
94 HeapFree(GetProcessHeap(), 0, entry
);
96 DeleteCriticalSection(&csPendingCredentials
);
103 static DWORD
save_credentials(PCWSTR pszTargetName
, PCWSTR pszUsername
,
104 PCWSTR pszPassword
, BOOL generic
)
108 TRACE("saving servername %s with username %s\n", debugstr_w(pszTargetName
), debugstr_w(pszUsername
));
111 cred
.Type
= generic
? CRED_TYPE_GENERIC
: CRED_TYPE_DOMAIN_PASSWORD
;
112 cred
.TargetName
= (LPWSTR
)pszTargetName
;
114 cred
.CredentialBlobSize
= strlenW(pszPassword
) * sizeof(WCHAR
);
115 cred
.CredentialBlob
= (LPBYTE
)pszPassword
;
116 cred
.Persist
= CRED_PERSIST_ENTERPRISE
;
117 cred
.AttributeCount
= 0;
118 cred
.Attributes
= NULL
;
119 cred
.TargetAlias
= NULL
;
120 cred
.UserName
= (LPWSTR
)pszUsername
;
122 if (CredWriteW(&cred
, 0))
123 return ERROR_SUCCESS
;
126 DWORD ret
= GetLastError();
127 ERR("CredWriteW failed with error %d\n", ret
);
132 struct cred_dialog_params
134 PCWSTR pszTargetName
;
135 PCWSTR pszMessageText
;
136 PCWSTR pszCaptionText
;
139 ULONG ulUsernameMaxChars
;
141 ULONG ulPasswordMaxChars
;
145 BOOL fBalloonTipActive
;
148 static void CredDialogFillUsernameCombo(HWND hwndUsername
, const struct cred_dialog_params
*params
)
152 PCREDENTIALW
*credentials
;
154 if (!CredEnumerateW(NULL
, 0, &count
, &credentials
))
157 for (i
= 0; i
< count
; i
++)
159 COMBOBOXEXITEMW comboitem
;
161 BOOL duplicate
= FALSE
;
163 if (params
->dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
)
165 if ((credentials
[i
]->Type
!= CRED_TYPE_GENERIC
) || !credentials
[i
]->UserName
)
170 if (credentials
[i
]->Type
== CRED_TYPE_GENERIC
)
174 /* don't add another item with the same name if we've already added it */
175 for (j
= 0; j
< i
; j
++)
176 if (!strcmpW(credentials
[i
]->UserName
, credentials
[j
]->UserName
))
185 comboitem
.mask
= CBEIF_TEXT
;
186 comboitem
.iItem
= -1;
187 comboitem
.pszText
= credentials
[i
]->UserName
;
188 SendMessageW(hwndUsername
, CBEM_INSERTITEMW
, 0, (LPARAM
)&comboitem
);
191 CredFree(credentials
);
194 static void CredDialogCreateBalloonTip(HWND hwndDlg
, struct cred_dialog_params
*params
)
196 TTTOOLINFOW toolinfo
;
199 if (params
->hwndBalloonTip
)
202 params
->hwndBalloonTip
= CreateWindowExW(WS_EX_TOOLWINDOW
, TOOLTIPS_CLASSW
,
203 NULL
, WS_POPUP
| TTS_NOPREFIX
| TTS_BALLOON
, CW_USEDEFAULT
,
204 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, hwndDlg
, NULL
,
206 SetWindowPos(params
->hwndBalloonTip
, HWND_TOPMOST
, 0, 0, 0, 0,
207 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
209 if (!LoadStringW(hinstCredUI
, IDS_INCORRECTPASSWORD
, wszText
, sizeof(wszText
)/sizeof(wszText
[0])))
211 ERR("failed to load IDS_INCORRECTPASSWORD\n");
215 toolinfo
.cbSize
= sizeof(toolinfo
);
216 toolinfo
.uFlags
= TTF_TRACK
;
217 toolinfo
.hwnd
= hwndDlg
;
218 toolinfo
.uId
= TOOLID_INCORRECTPASSWORD
;
219 memset(&toolinfo
.rect
, 0, sizeof(toolinfo
.rect
));
220 toolinfo
.hinst
= NULL
;
221 toolinfo
.lpszText
= wszText
;
223 toolinfo
.lpReserved
= NULL
;
224 SendMessageW(params
->hwndBalloonTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&toolinfo
);
226 if (!LoadStringW(hinstCredUI
, IDS_CAPSLOCKON
, wszText
, sizeof(wszText
)/sizeof(wszText
[0])))
228 ERR("failed to load IDS_CAPSLOCKON\n");
232 toolinfo
.uId
= TOOLID_CAPSLOCKON
;
233 SendMessageW(params
->hwndBalloonTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&toolinfo
);
236 static void CredDialogShowIncorrectPasswordBalloon(HWND hwndDlg
, struct cred_dialog_params
*params
)
238 TTTOOLINFOW toolinfo
;
244 /* user name likely wrong so balloon would be confusing. focus is also
245 * not set to the password edit box, so more notification would need to be
247 if (!params
->pszUsername
[0])
250 /* don't show two balloon tips at once */
251 if (params
->fBalloonTipActive
)
254 if (!LoadStringW(hinstCredUI
, IDS_INCORRECTPASSWORDTITLE
, wszTitle
, sizeof(wszTitle
)/sizeof(wszTitle
[0])))
256 ERR("failed to load IDS_INCORRECTPASSWORDTITLE\n");
260 CredDialogCreateBalloonTip(hwndDlg
, params
);
262 memset(&toolinfo
, 0, sizeof(toolinfo
));
263 toolinfo
.cbSize
= sizeof(toolinfo
);
264 toolinfo
.hwnd
= hwndDlg
;
265 toolinfo
.uId
= TOOLID_INCORRECTPASSWORD
;
267 SendMessageW(params
->hwndBalloonTip
, TTM_SETTITLEW
, TTI_ERROR
, (LPARAM
)wszTitle
);
269 GetWindowRect(GetDlgItem(hwndDlg
, IDC_PASSWORD
), &rcPassword
);
270 /* centered vertically and in the right side of the password edit control */
271 x
= rcPassword
.right
- 12;
272 y
= (rcPassword
.top
+ rcPassword
.bottom
) / 2;
273 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKPOSITION
, 0, MAKELONG(x
, y
));
275 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&toolinfo
);
277 params
->fBalloonTipActive
= TRUE
;
280 static void CredDialogShowCapsLockBalloon(HWND hwndDlg
, struct cred_dialog_params
*params
)
282 TTTOOLINFOW toolinfo
;
288 /* don't show two balloon tips at once */
289 if (params
->fBalloonTipActive
)
292 if (!LoadStringW(hinstCredUI
, IDS_CAPSLOCKONTITLE
, wszTitle
, sizeof(wszTitle
)/sizeof(wszTitle
[0])))
294 ERR("failed to load IDS_IDSCAPSLOCKONTITLE\n");
298 CredDialogCreateBalloonTip(hwndDlg
, params
);
300 memset(&toolinfo
, 0, sizeof(toolinfo
));
301 toolinfo
.cbSize
= sizeof(toolinfo
);
302 toolinfo
.hwnd
= hwndDlg
;
303 toolinfo
.uId
= TOOLID_CAPSLOCKON
;
305 SendMessageW(params
->hwndBalloonTip
, TTM_SETTITLEW
, TTI_WARNING
, (LPARAM
)wszTitle
);
307 GetWindowRect(GetDlgItem(hwndDlg
, IDC_PASSWORD
), &rcPassword
);
308 /* just inside the left side of the password edit control */
309 x
= rcPassword
.left
+ 12;
310 y
= rcPassword
.bottom
- 3;
311 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKPOSITION
, 0, MAKELONG(x
, y
));
313 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&toolinfo
);
315 SetTimer(hwndDlg
, ID_CAPSLOCKPOP
,
316 SendMessageW(params
->hwndBalloonTip
, TTM_GETDELAYTIME
, TTDT_AUTOPOP
, 0),
319 params
->fBalloonTipActive
= TRUE
;
322 static void CredDialogHideBalloonTip(HWND hwndDlg
, struct cred_dialog_params
*params
)
324 TTTOOLINFOW toolinfo
;
326 if (!params
->hwndBalloonTip
)
329 memset(&toolinfo
, 0, sizeof(toolinfo
));
331 toolinfo
.cbSize
= sizeof(toolinfo
);
332 toolinfo
.hwnd
= hwndDlg
;
334 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, FALSE
, (LPARAM
)&toolinfo
);
336 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, FALSE
, (LPARAM
)&toolinfo
);
338 params
->fBalloonTipActive
= FALSE
;
341 static inline BOOL
CredDialogCapsLockOn(void)
343 return (GetKeyState(VK_CAPITAL
) & 0x1) != 0;
346 static LRESULT CALLBACK
CredDialogPasswordSubclassProc(HWND hwnd
, UINT uMsg
,
347 WPARAM wParam
, LPARAM lParam
, UINT_PTR uIdSubclass
, DWORD_PTR dwRefData
)
349 struct cred_dialog_params
*params
= (struct cred_dialog_params
*)dwRefData
;
353 if (wParam
== VK_CAPITAL
)
355 HWND hwndDlg
= GetParent(hwnd
);
356 if (CredDialogCapsLockOn())
357 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
359 CredDialogHideBalloonTip(hwndDlg
, params
);
363 RemoveWindowSubclass(hwnd
, CredDialogPasswordSubclassProc
, uIdSubclass
);
366 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
369 static BOOL
CredDialogInit(HWND hwndDlg
, struct cred_dialog_params
*params
)
371 HWND hwndUsername
= GetDlgItem(hwndDlg
, IDC_USERNAME
);
372 HWND hwndPassword
= GetDlgItem(hwndDlg
, IDC_PASSWORD
);
374 SetWindowLongPtrW(hwndDlg
, DWLP_USER
, (LONG_PTR
)params
);
376 if (params
->hbmBanner
)
377 SendMessageW(GetDlgItem(hwndDlg
, IDB_BANNER
), STM_SETIMAGE
,
378 IMAGE_BITMAP
, (LPARAM
)params
->hbmBanner
);
380 if (params
->pszMessageText
)
381 SetDlgItemTextW(hwndDlg
, IDC_MESSAGE
, params
->pszMessageText
);
386 LoadStringW(hinstCredUI
, IDS_MESSAGEFORMAT
, format
, sizeof(format
)/sizeof(format
[0]));
387 snprintfW(message
, sizeof(message
)/sizeof(message
[0]), format
, params
->pszTargetName
);
388 SetDlgItemTextW(hwndDlg
, IDC_MESSAGE
, message
);
390 SetWindowTextW(hwndUsername
, params
->pszUsername
);
391 SetWindowTextW(hwndPassword
, params
->pszPassword
);
393 CredDialogFillUsernameCombo(hwndUsername
, params
);
395 if (params
->pszUsername
[0])
397 /* prevent showing a balloon tip here */
398 params
->fBalloonTipActive
= TRUE
;
399 SetFocus(hwndPassword
);
400 params
->fBalloonTipActive
= FALSE
;
403 SetFocus(hwndUsername
);
405 if (params
->pszCaptionText
)
406 SetWindowTextW(hwndDlg
, params
->pszCaptionText
);
411 LoadStringW(hinstCredUI
, IDS_TITLEFORMAT
, format
, sizeof(format
)/sizeof(format
[0]));
412 snprintfW(title
, sizeof(title
)/sizeof(title
[0]), format
, params
->pszTargetName
);
413 SetWindowTextW(hwndDlg
, title
);
416 if (params
->dwFlags
& CREDUI_FLAGS_PERSIST
||
417 (params
->dwFlags
& CREDUI_FLAGS_DO_NOT_PERSIST
&&
418 !(params
->dwFlags
& CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX
)))
419 ShowWindow(GetDlgItem(hwndDlg
, IDC_SAVE
), SW_HIDE
);
420 else if (params
->fSave
)
421 CheckDlgButton(hwndDlg
, IDC_SAVE
, BST_CHECKED
);
423 /* setup subclassing for Caps Lock detection */
424 SetWindowSubclass(hwndPassword
, CredDialogPasswordSubclassProc
, 1, (DWORD_PTR
)params
);
426 if (params
->dwFlags
& CREDUI_FLAGS_INCORRECT_PASSWORD
)
427 CredDialogShowIncorrectPasswordBalloon(hwndDlg
, params
);
428 else if ((GetFocus() == hwndPassword
) && CredDialogCapsLockOn())
429 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
434 static void CredDialogCommandOk(HWND hwndDlg
, struct cred_dialog_params
*params
)
436 HWND hwndUsername
= GetDlgItem(hwndDlg
, IDC_USERNAME
);
441 len
= GetWindowTextLengthW(hwndUsername
);
442 user
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
443 GetWindowTextW(hwndUsername
, user
, len
+ 1);
447 HeapFree(GetProcessHeap(), 0, user
);
451 if (!strchrW(user
, '\\') && !strchrW(user
, '@'))
453 ULONG len_target
= strlenW(params
->pszTargetName
);
454 memcpy(params
->pszUsername
, params
->pszTargetName
,
455 min(len_target
, params
->ulUsernameMaxChars
) * sizeof(WCHAR
));
456 if (len_target
+ 1 < params
->ulUsernameMaxChars
)
457 params
->pszUsername
[len_target
] = '\\';
458 if (len_target
+ 2 < params
->ulUsernameMaxChars
)
459 params
->pszUsername
[len_target
+ 1] = '\0';
461 else if (params
->ulUsernameMaxChars
> 0)
462 params
->pszUsername
[0] = '\0';
464 len2
= strlenW(params
->pszUsername
);
465 memcpy(params
->pszUsername
+ len2
, user
, min(len
, params
->ulUsernameMaxChars
- len2
) * sizeof(WCHAR
));
466 if (params
->ulUsernameMaxChars
)
467 params
->pszUsername
[len2
+ min(len
, params
->ulUsernameMaxChars
- len2
- 1)] = '\0';
469 HeapFree(GetProcessHeap(), 0, user
);
471 GetDlgItemTextW(hwndDlg
, IDC_PASSWORD
, params
->pszPassword
,
472 params
->ulPasswordMaxChars
);
474 params
->fSave
= IsDlgButtonChecked(hwndDlg
, IDC_SAVE
) == BST_CHECKED
;
476 EndDialog(hwndDlg
, IDOK
);
479 static INT_PTR CALLBACK
CredDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
,
486 struct cred_dialog_params
*params
= (struct cred_dialog_params
*)lParam
;
488 return CredDialogInit(hwndDlg
, params
);
493 case MAKELONG(IDOK
, BN_CLICKED
):
495 struct cred_dialog_params
*params
=
496 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
497 CredDialogCommandOk(hwndDlg
, params
);
500 case MAKELONG(IDCANCEL
, BN_CLICKED
):
501 EndDialog(hwndDlg
, IDCANCEL
);
503 case MAKELONG(IDC_PASSWORD
, EN_SETFOCUS
):
504 if (CredDialogCapsLockOn())
506 struct cred_dialog_params
*params
=
507 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
508 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
510 /* don't allow another window to steal focus while the
511 * user is typing their password */
512 LockSetForegroundWindow(LSFW_LOCK
);
514 case MAKELONG(IDC_PASSWORD
, EN_KILLFOCUS
):
516 struct cred_dialog_params
*params
=
517 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
518 /* the user is no longer typing their password, so allow
519 * other windows to become foreground ones */
520 LockSetForegroundWindow(LSFW_UNLOCK
);
521 CredDialogHideBalloonTip(hwndDlg
, params
);
524 case MAKELONG(IDC_PASSWORD
, EN_CHANGE
):
526 struct cred_dialog_params
*params
=
527 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
528 CredDialogHideBalloonTip(hwndDlg
, params
);
534 if (wParam
== ID_CAPSLOCKPOP
)
536 struct cred_dialog_params
*params
=
537 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
538 CredDialogHideBalloonTip(hwndDlg
, params
);
544 struct cred_dialog_params
*params
=
545 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
546 if (params
->hwndBalloonTip
) DestroyWindow(params
->hwndBalloonTip
);
554 static BOOL
find_existing_credential(const WCHAR
*target
, WCHAR
*username
, ULONG len_username
,
555 WCHAR
*password
, ULONG len_password
)
558 CREDENTIALW
**credentials
;
560 if (!CredEnumerateW(target
, 0, &count
, &credentials
)) return FALSE
;
561 for (i
= 0; i
< count
; i
++)
563 if (credentials
[i
]->Type
!= CRED_TYPE_DOMAIN_PASSWORD
)
565 FIXME("no support for type %u credentials\n", credentials
[i
]->Type
);
568 if ((!*username
|| !strcmpW(username
, credentials
[i
]->UserName
)) &&
569 strlenW(credentials
[i
]->UserName
) < len_username
&&
570 credentials
[i
]->CredentialBlobSize
/ sizeof(WCHAR
) < len_password
)
572 TRACE("found existing credential for %s\n", debugstr_w(credentials
[i
]->UserName
));
574 strcpyW(username
, credentials
[i
]->UserName
);
575 memcpy(password
, credentials
[i
]->CredentialBlob
, credentials
[i
]->CredentialBlobSize
);
576 password
[credentials
[i
]->CredentialBlobSize
/ sizeof(WCHAR
)] = 0;
578 CredFree(credentials
);
582 CredFree(credentials
);
586 /******************************************************************************
587 * CredUIPromptForCredentialsW [CREDUI.@]
589 DWORD WINAPI
CredUIPromptForCredentialsW(PCREDUI_INFOW pUIInfo
,
590 PCWSTR pszTargetName
,
591 PCtxtHandle Reserved
,
594 ULONG ulUsernameMaxChars
,
596 ULONG ulPasswordMaxChars
, PBOOL pfSave
,
600 struct cred_dialog_params params
;
601 DWORD result
= ERROR_SUCCESS
;
603 TRACE("(%p, %s, %p, %d, %s, %d, %p, %d, %p, 0x%08x)\n", pUIInfo
,
604 debugstr_w(pszTargetName
), Reserved
, dwAuthError
, debugstr_w(pszUsername
),
605 ulUsernameMaxChars
, pszPassword
, ulPasswordMaxChars
, pfSave
, dwFlags
);
607 if ((dwFlags
& (CREDUI_FLAGS_ALWAYS_SHOW_UI
|CREDUI_FLAGS_GENERIC_CREDENTIALS
)) == CREDUI_FLAGS_ALWAYS_SHOW_UI
)
608 return ERROR_INVALID_FLAGS
;
611 return ERROR_INVALID_PARAMETER
;
613 if ((dwFlags
& CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX
) && !pfSave
)
614 return ERROR_INVALID_PARAMETER
;
616 if (!(dwFlags
& CREDUI_FLAGS_ALWAYS_SHOW_UI
) &&
617 !(dwFlags
& CREDUI_FLAGS_INCORRECT_PASSWORD
) &&
618 find_existing_credential(pszTargetName
, pszUsername
, ulUsernameMaxChars
, pszPassword
, ulPasswordMaxChars
))
619 return ERROR_SUCCESS
;
621 params
.pszTargetName
= pszTargetName
;
624 params
.pszMessageText
= pUIInfo
->pszMessageText
;
625 params
.pszCaptionText
= pUIInfo
->pszCaptionText
;
626 params
.hbmBanner
= pUIInfo
->hbmBanner
;
630 params
.pszMessageText
= NULL
;
631 params
.pszCaptionText
= NULL
;
632 params
.hbmBanner
= NULL
;
634 params
.pszUsername
= pszUsername
;
635 params
.ulUsernameMaxChars
= ulUsernameMaxChars
;
636 params
.pszPassword
= pszPassword
;
637 params
.ulPasswordMaxChars
= ulPasswordMaxChars
;
638 params
.fSave
= pfSave
? *pfSave
: FALSE
;
639 params
.dwFlags
= dwFlags
;
640 params
.hwndBalloonTip
= NULL
;
641 params
.fBalloonTipActive
= FALSE
;
643 ret
= DialogBoxParamW(hinstCredUI
, MAKEINTRESOURCEW(IDD_CREDDIALOG
),
644 pUIInfo
? pUIInfo
->hwndParent
: NULL
,
645 CredDialogProc
, (LPARAM
)¶ms
);
647 return GetLastError();
651 TRACE("dialog cancelled\n");
652 return ERROR_CANCELLED
;
656 *pfSave
= params
.fSave
;
660 if (dwFlags
& CREDUI_FLAGS_EXPECT_CONFIRMATION
)
663 struct pending_credentials
*entry
;
666 EnterCriticalSection(&csPendingCredentials
);
668 /* find existing pending credentials for the same target and overwrite */
669 /* FIXME: is this correct? */
670 LIST_FOR_EACH_ENTRY(entry
, &pending_credentials_list
, struct pending_credentials
, entry
)
671 if (!strcmpW(pszTargetName
, entry
->pszTargetName
))
674 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
675 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
676 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
681 entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(*entry
));
682 len
= strlenW(pszTargetName
);
683 entry
->pszTargetName
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
684 memcpy(entry
->pszTargetName
, pszTargetName
, (len
+ 1)*sizeof(WCHAR
));
685 list_add_tail(&pending_credentials_list
, &entry
->entry
);
688 len
= strlenW(params
.pszUsername
);
689 entry
->pszUsername
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
690 memcpy(entry
->pszUsername
, params
.pszUsername
, (len
+ 1)*sizeof(WCHAR
));
691 len
= strlenW(params
.pszPassword
);
692 entry
->pszPassword
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
693 memcpy(entry
->pszPassword
, params
.pszPassword
, (len
+ 1)*sizeof(WCHAR
));
694 entry
->generic
= (dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
) != 0;
696 LeaveCriticalSection(&csPendingCredentials
);
698 else if (!(dwFlags
& CREDUI_FLAGS_DO_NOT_PERSIST
))
699 result
= save_credentials(pszTargetName
, pszUsername
, pszPassword
,
700 (dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
) != 0);
706 /******************************************************************************
707 * CredUIConfirmCredentialsW [CREDUI.@]
709 DWORD WINAPI
CredUIConfirmCredentialsW(PCWSTR pszTargetName
, BOOL bConfirm
)
711 struct pending_credentials
*entry
;
712 DWORD result
= ERROR_NOT_FOUND
;
714 TRACE("(%s, %s)\n", debugstr_w(pszTargetName
), bConfirm
? "TRUE" : "FALSE");
717 return ERROR_INVALID_PARAMETER
;
719 EnterCriticalSection(&csPendingCredentials
);
721 LIST_FOR_EACH_ENTRY(entry
, &pending_credentials_list
, struct pending_credentials
, entry
)
723 if (!strcmpW(pszTargetName
, entry
->pszTargetName
))
726 result
= save_credentials(entry
->pszTargetName
, entry
->pszUsername
,
727 entry
->pszPassword
, entry
->generic
);
729 result
= ERROR_SUCCESS
;
731 list_remove(&entry
->entry
);
733 HeapFree(GetProcessHeap(), 0, entry
->pszTargetName
);
734 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
735 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
736 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
737 HeapFree(GetProcessHeap(), 0, entry
);
743 LeaveCriticalSection(&csPendingCredentials
);
748 /******************************************************************************
749 * CredUIParseUserNameW [CREDUI.@]
751 DWORD WINAPI
CredUIParseUserNameW(PCWSTR pszUserName
, PWSTR pszUser
,
752 ULONG ulMaxUserChars
, PWSTR pszDomain
,
753 ULONG ulMaxDomainChars
)
757 TRACE("(%s, %p, %d, %p, %d)\n", debugstr_w(pszUserName
), pszUser
,
758 ulMaxUserChars
, pszDomain
, ulMaxDomainChars
);
760 if (!pszUserName
|| !pszUser
|| !ulMaxUserChars
|| !pszDomain
||
762 return ERROR_INVALID_PARAMETER
;
764 /* FIXME: handle marshaled credentials */
766 p
= strchrW(pszUserName
, '\\');
769 if (p
- pszUserName
> ulMaxDomainChars
- 1)
770 return ERROR_INSUFFICIENT_BUFFER
;
771 if (strlenW(p
+ 1) > ulMaxUserChars
- 1)
772 return ERROR_INSUFFICIENT_BUFFER
;
773 strcpyW(pszUser
, p
+ 1);
774 memcpy(pszDomain
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
775 pszDomain
[p
- pszUserName
] = '\0';
777 return ERROR_SUCCESS
;
780 p
= strrchrW(pszUserName
, '@');
783 if (p
+ 1 - pszUserName
> ulMaxUserChars
- 1)
784 return ERROR_INSUFFICIENT_BUFFER
;
785 if (strlenW(p
+ 1) > ulMaxDomainChars
- 1)
786 return ERROR_INSUFFICIENT_BUFFER
;
787 strcpyW(pszDomain
, p
+ 1);
788 memcpy(pszUser
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
789 pszUser
[p
- pszUserName
] = '\0';
791 return ERROR_SUCCESS
;
794 if (strlenW(pszUserName
) > ulMaxUserChars
- 1)
795 return ERROR_INSUFFICIENT_BUFFER
;
796 strcpyW(pszUser
, pszUserName
);
799 return ERROR_SUCCESS
;
802 /******************************************************************************
803 * CredUIStoreSSOCredA [CREDUI.@]
805 DWORD WINAPI
CredUIStoreSSOCredA(PCSTR pszRealm
, PCSTR pszUsername
,
806 PCSTR pszPassword
, BOOL bPersist
)
808 FIXME("(%s, %s, %p, %d)\n", debugstr_a(pszRealm
), debugstr_a(pszUsername
),
809 pszPassword
, bPersist
);
810 return ERROR_SUCCESS
;
813 /******************************************************************************
814 * CredUIStoreSSOCredW [CREDUI.@]
816 DWORD WINAPI
CredUIStoreSSOCredW(PCWSTR pszRealm
, PCWSTR pszUsername
,
817 PCWSTR pszPassword
, BOOL bPersist
)
819 FIXME("(%s, %s, %p, %d)\n", debugstr_w(pszRealm
), debugstr_w(pszUsername
),
820 pszPassword
, bPersist
);
821 return ERROR_SUCCESS
;
824 /******************************************************************************
825 * CredUIReadSSOCredA [CREDUI.@]
827 DWORD WINAPI
CredUIReadSSOCredA(PCSTR pszRealm
, PSTR
*ppszUsername
)
829 FIXME("(%s, %p)\n", debugstr_a(pszRealm
), ppszUsername
);
831 *ppszUsername
= NULL
;
832 return ERROR_NOT_FOUND
;
835 /******************************************************************************
836 * CredUIReadSSOCredW [CREDUI.@]
838 DWORD WINAPI
CredUIReadSSOCredW(PCWSTR pszRealm
, PWSTR
*ppszUsername
)
840 FIXME("(%s, %p)\n", debugstr_w(pszRealm
), ppszUsername
);
842 *ppszUsername
= NULL
;
843 return ERROR_NOT_FOUND
;
846 /******************************************************************************
847 * CredUIInitControls [CREDUI.@]
849 BOOL WINAPI
CredUIInitControls(void)