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
30 #include "credui_resources.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
34 #include "wine/list.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(credui
);
38 #define TOOLID_INCORRECTPASSWORD 1
39 #define TOOLID_CAPSLOCKON 2
41 #define ID_CAPSLOCKPOP 1
43 struct pending_credentials
52 static HINSTANCE hinstCredUI
;
54 static struct list pending_credentials_list
= LIST_INIT(pending_credentials_list
);
56 static CRITICAL_SECTION csPendingCredentials
;
57 static CRITICAL_SECTION_DEBUG critsect_debug
=
59 0, 0, &csPendingCredentials
,
60 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
61 0, 0, { (DWORD_PTR
)(__FILE__
": csPendingCredentials") }
63 static CRITICAL_SECTION csPendingCredentials
= { &critsect_debug
, -1, 0, 0, 0, 0 };
66 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
68 TRACE("(0x%p, %d, %p)\n",hinstDLL
,fdwReason
,lpvReserved
);
70 if (fdwReason
== DLL_WINE_PREATTACH
) return FALSE
; /* prefer native version */
72 if (fdwReason
== DLL_PROCESS_ATTACH
)
74 DisableThreadLibraryCalls(hinstDLL
);
75 hinstCredUI
= hinstDLL
;
78 else if (fdwReason
== DLL_PROCESS_DETACH
)
80 struct pending_credentials
*entry
, *cursor2
;
81 LIST_FOR_EACH_ENTRY_SAFE(entry
, cursor2
, &pending_credentials_list
, struct pending_credentials
, entry
)
83 list_remove(&entry
->entry
);
85 HeapFree(GetProcessHeap(), 0, entry
->pszTargetName
);
86 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
87 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
88 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
89 HeapFree(GetProcessHeap(), 0, entry
);
96 static DWORD
save_credentials(PCWSTR pszTargetName
, PCWSTR pszUsername
,
97 PCWSTR pszPassword
, BOOL generic
)
101 TRACE("saving servername %s with username %s\n", debugstr_w(pszTargetName
), debugstr_w(pszUsername
));
104 cred
.Type
= generic
? CRED_TYPE_GENERIC
: CRED_TYPE_DOMAIN_PASSWORD
;
105 cred
.TargetName
= (LPWSTR
)pszTargetName
;
107 cred
.CredentialBlobSize
= strlenW(pszPassword
) * sizeof(WCHAR
);
108 cred
.CredentialBlob
= (LPBYTE
)pszPassword
;
109 cred
.Persist
= CRED_PERSIST_ENTERPRISE
;
110 cred
.AttributeCount
= 0;
111 cred
.Attributes
= NULL
;
112 cred
.TargetAlias
= NULL
;
113 cred
.UserName
= (LPWSTR
)pszUsername
;
115 if (CredWriteW(&cred
, 0))
116 return ERROR_SUCCESS
;
119 DWORD ret
= GetLastError();
120 ERR("CredWriteW failed with error %d\n", ret
);
125 struct cred_dialog_params
127 PCWSTR pszTargetName
;
128 PCWSTR pszMessageText
;
129 PCWSTR pszCaptionText
;
132 ULONG ulUsernameMaxChars
;
134 ULONG ulPasswordMaxChars
;
138 BOOL fBalloonTipActive
;
141 static void CredDialogFillUsernameCombo(HWND hwndUsername
, struct cred_dialog_params
*params
)
145 PCREDENTIALW
*credentials
;
147 if (!CredEnumerateW(NULL
, 0, &count
, &credentials
))
150 for (i
= 0; i
< count
; i
++)
152 COMBOBOXEXITEMW comboitem
;
154 BOOL duplicate
= FALSE
;
156 if (params
->dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
)
158 if ((credentials
[i
]->Type
!= CRED_TYPE_GENERIC
) || !credentials
[i
]->UserName
)
163 if (credentials
[i
]->Type
== CRED_TYPE_GENERIC
)
167 /* don't add another item with the same name if we've already added it */
168 for (j
= 0; j
< i
; j
++)
169 if (!strcmpW(credentials
[i
]->UserName
, credentials
[j
]->UserName
))
178 comboitem
.mask
= CBEIF_TEXT
;
179 comboitem
.iItem
= -1;
180 comboitem
.pszText
= credentials
[i
]->UserName
;
181 SendMessageW(hwndUsername
, CBEM_INSERTITEMW
, 0, (LPARAM
)&comboitem
);
184 CredFree(credentials
);
187 static void CredDialogCreateBalloonTip(HWND hwndDlg
, struct cred_dialog_params
*params
)
189 TTTOOLINFOW toolinfo
;
192 if (params
->hwndBalloonTip
)
195 params
->hwndBalloonTip
= CreateWindowExW(WS_EX_TOOLWINDOW
, TOOLTIPS_CLASSW
,
196 NULL
, WS_POPUP
| TTS_NOPREFIX
| TTS_BALLOON
, CW_USEDEFAULT
,
197 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, hwndDlg
, NULL
,
199 SetWindowPos(params
->hwndBalloonTip
, HWND_TOPMOST
, 0, 0, 0, 0,
200 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
202 if (!LoadStringW(hinstCredUI
, IDS_INCORRECTPASSWORD
, wszText
, sizeof(wszText
)/sizeof(wszText
[0])))
204 ERR("failed to load IDS_INCORRECTPASSWORD\n");
208 toolinfo
.cbSize
= sizeof(toolinfo
);
209 toolinfo
.uFlags
= TTF_TRACK
;
210 toolinfo
.hwnd
= hwndDlg
;
211 toolinfo
.uId
= TOOLID_INCORRECTPASSWORD
;
212 memset(&toolinfo
.rect
, 0, sizeof(toolinfo
.rect
));
213 toolinfo
.hinst
= NULL
;
214 toolinfo
.lpszText
= wszText
;
216 toolinfo
.lpReserved
= NULL
;
217 SendMessageW(params
->hwndBalloonTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&toolinfo
);
219 if (!LoadStringW(hinstCredUI
, IDS_CAPSLOCKON
, wszText
, sizeof(wszText
)/sizeof(wszText
[0])))
221 ERR("failed to load IDS_CAPSLOCKON\n");
225 toolinfo
.uId
= TOOLID_CAPSLOCKON
;
226 SendMessageW(params
->hwndBalloonTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&toolinfo
);
229 static void CredDialogShowIncorrectPasswordBalloon(HWND hwndDlg
, struct cred_dialog_params
*params
)
231 TTTOOLINFOW toolinfo
;
237 /* user name likely wrong so balloon would be confusing. focus is also
238 * not set to the password edit box, so more notification would need to be
240 if (!params
->pszUsername
[0])
243 /* don't show two balloon tips at once */
244 if (params
->fBalloonTipActive
)
247 if (!LoadStringW(hinstCredUI
, IDS_INCORRECTPASSWORDTITLE
, wszTitle
, sizeof(wszTitle
)/sizeof(wszTitle
[0])))
249 ERR("failed to load IDS_INCORRECTPASSWORDTITLE\n");
253 CredDialogCreateBalloonTip(hwndDlg
, params
);
255 memset(&toolinfo
, 0, sizeof(toolinfo
));
256 toolinfo
.cbSize
= sizeof(toolinfo
);
257 toolinfo
.hwnd
= hwndDlg
;
258 toolinfo
.uId
= TOOLID_INCORRECTPASSWORD
;
260 SendMessageW(params
->hwndBalloonTip
, TTM_SETTITLEW
, TTI_ERROR
, (LPARAM
)wszTitle
);
262 GetWindowRect(GetDlgItem(hwndDlg
, IDC_PASSWORD
), &rcPassword
);
263 /* centred vertically and in the right side of the password edit control */
264 x
= rcPassword
.right
- 12;
265 y
= (rcPassword
.top
+ rcPassword
.bottom
) / 2;
266 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKPOSITION
, 0, MAKELONG(x
, y
));
268 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&toolinfo
);
270 params
->fBalloonTipActive
= TRUE
;
273 static void CredDialogShowCapsLockBalloon(HWND hwndDlg
, struct cred_dialog_params
*params
)
275 TTTOOLINFOW toolinfo
;
281 /* don't show two balloon tips at once */
282 if (params
->fBalloonTipActive
)
285 if (!LoadStringW(hinstCredUI
, IDS_CAPSLOCKONTITLE
, wszTitle
, sizeof(wszTitle
)/sizeof(wszTitle
[0])))
287 ERR("failed to load IDS_IDSCAPSLOCKONTITLE\n");
291 CredDialogCreateBalloonTip(hwndDlg
, params
);
293 memset(&toolinfo
, 0, sizeof(toolinfo
));
294 toolinfo
.cbSize
= sizeof(toolinfo
);
295 toolinfo
.hwnd
= hwndDlg
;
296 toolinfo
.uId
= TOOLID_CAPSLOCKON
;
298 SendMessageW(params
->hwndBalloonTip
, TTM_SETTITLEW
, TTI_WARNING
, (LPARAM
)wszTitle
);
300 GetWindowRect(GetDlgItem(hwndDlg
, IDC_PASSWORD
), &rcPassword
);
301 /* just inside the left side of the password edit control */
302 x
= rcPassword
.left
+ 12;
303 y
= rcPassword
.bottom
- 3;
304 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKPOSITION
, 0, MAKELONG(x
, y
));
306 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&toolinfo
);
308 SetTimer(hwndDlg
, ID_CAPSLOCKPOP
,
309 SendMessageW(params
->hwndBalloonTip
, TTM_GETDELAYTIME
, TTDT_AUTOPOP
, 0),
312 params
->fBalloonTipActive
= TRUE
;
315 static void CredDialogHideBalloonTip(HWND hwndDlg
, struct cred_dialog_params
*params
)
317 TTTOOLINFOW toolinfo
;
319 if (!params
->hwndBalloonTip
)
322 memset(&toolinfo
, 0, sizeof(toolinfo
));
324 toolinfo
.cbSize
= sizeof(toolinfo
);
325 toolinfo
.hwnd
= hwndDlg
;
327 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, FALSE
, (LPARAM
)&toolinfo
);
329 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, FALSE
, (LPARAM
)&toolinfo
);
331 params
->fBalloonTipActive
= FALSE
;
334 static inline BOOL
CredDialogCapsLockOn(void)
336 return GetKeyState(VK_CAPITAL
) & 0x1 ? TRUE
: FALSE
;
339 static LRESULT CALLBACK
CredDialogPasswordSubclassProc(HWND hwnd
, UINT uMsg
,
340 WPARAM wParam
, LPARAM lParam
, UINT_PTR uIdSubclass
, DWORD_PTR dwRefData
)
342 struct cred_dialog_params
*params
= (struct cred_dialog_params
*)dwRefData
;
346 if (wParam
== VK_CAPITAL
)
348 HWND hwndDlg
= GetParent(hwnd
);
349 if (CredDialogCapsLockOn())
350 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
352 CredDialogHideBalloonTip(hwndDlg
, params
);
356 RemoveWindowSubclass(hwnd
, CredDialogPasswordSubclassProc
, uIdSubclass
);
359 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
362 static BOOL
CredDialogInit(HWND hwndDlg
, struct cred_dialog_params
*params
)
364 HWND hwndUsername
= GetDlgItem(hwndDlg
, IDC_USERNAME
);
365 HWND hwndPassword
= GetDlgItem(hwndDlg
, IDC_PASSWORD
);
367 SetWindowLongPtrW(hwndDlg
, DWLP_USER
, (LONG_PTR
)params
);
369 if (params
->hbmBanner
)
370 SendMessageW(GetDlgItem(hwndDlg
, IDB_BANNER
), STM_SETIMAGE
,
371 IMAGE_BITMAP
, (LPARAM
)params
->hbmBanner
);
373 if (params
->pszMessageText
)
374 SetDlgItemTextW(hwndDlg
, IDC_MESSAGE
, params
->pszMessageText
);
379 LoadStringW(hinstCredUI
, IDS_MESSAGEFORMAT
, format
, sizeof(format
)/sizeof(format
[0]));
380 snprintfW(message
, sizeof(message
)/sizeof(message
[0]), format
, params
->pszTargetName
);
381 SetDlgItemTextW(hwndDlg
, IDC_MESSAGE
, message
);
383 SetWindowTextW(hwndUsername
, params
->pszUsername
);
384 SetWindowTextW(hwndPassword
, params
->pszPassword
);
386 CredDialogFillUsernameCombo(hwndUsername
, params
);
388 if (params
->pszUsername
[0])
390 /* prevent showing a balloon tip here */
391 params
->fBalloonTipActive
= TRUE
;
392 SetFocus(hwndPassword
);
393 params
->fBalloonTipActive
= FALSE
;
396 SetFocus(hwndUsername
);
398 if (params
->pszCaptionText
)
399 SetWindowTextW(hwndDlg
, params
->pszCaptionText
);
404 LoadStringW(hinstCredUI
, IDS_TITLEFORMAT
, format
, sizeof(format
)/sizeof(format
[0]));
405 snprintfW(title
, sizeof(title
)/sizeof(title
[0]), format
, params
->pszTargetName
);
406 SetWindowTextW(hwndDlg
, title
);
409 if (params
->dwFlags
& (CREDUI_FLAGS_DO_NOT_PERSIST
|CREDUI_FLAGS_PERSIST
))
410 ShowWindow(GetDlgItem(hwndDlg
, IDC_SAVE
), SW_HIDE
);
411 else if (params
->fSave
)
412 CheckDlgButton(hwndDlg
, IDC_SAVE
, BST_CHECKED
);
414 /* setup subclassing for Caps Lock detection */
415 SetWindowSubclass(hwndPassword
, CredDialogPasswordSubclassProc
, 1, (DWORD_PTR
)params
);
417 if (params
->dwFlags
& CREDUI_FLAGS_INCORRECT_PASSWORD
)
418 CredDialogShowIncorrectPasswordBalloon(hwndDlg
, params
);
419 else if ((GetFocus() == hwndPassword
) && CredDialogCapsLockOn())
420 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
425 static void CredDialogCommandOk(HWND hwndDlg
, struct cred_dialog_params
*params
)
427 HWND hwndUsername
= GetDlgItem(hwndDlg
, IDC_USERNAME
);
432 len
= GetWindowTextLengthW(hwndUsername
);
433 user
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
434 GetWindowTextW(hwndUsername
, user
, len
+ 1);
438 HeapFree(GetProcessHeap(), 0, user
);
442 if (!strchrW(user
, '\\') && !strchrW(user
, '@'))
444 INT len_target
= strlenW(params
->pszTargetName
);
445 memcpy(params
->pszUsername
, params
->pszTargetName
,
446 min(len_target
, params
->ulUsernameMaxChars
) * sizeof(WCHAR
));
447 if (len_target
+ 1 < params
->ulUsernameMaxChars
)
448 params
->pszUsername
[len_target
] = '\\';
449 if (len_target
+ 2 < params
->ulUsernameMaxChars
)
450 params
->pszUsername
[len_target
+ 1] = '\0';
452 else if (params
->ulUsernameMaxChars
> 0)
453 params
->pszUsername
[0] = '\0';
455 len2
= strlenW(params
->pszUsername
);
456 memcpy(params
->pszUsername
+ len2
, user
, min(len
, params
->ulUsernameMaxChars
- len2
) * sizeof(WCHAR
));
457 if (params
->ulUsernameMaxChars
)
458 params
->pszUsername
[len2
+ min(len
, params
->ulUsernameMaxChars
- len2
- 1)] = '\0';
460 HeapFree(GetProcessHeap(), 0, user
);
462 GetDlgItemTextW(hwndDlg
, IDC_PASSWORD
, params
->pszPassword
,
463 params
->ulPasswordMaxChars
);
465 params
->fSave
= IsDlgButtonChecked(hwndDlg
, IDC_SAVE
) == BST_CHECKED
;
467 EndDialog(hwndDlg
, IDOK
);
470 static INT_PTR CALLBACK
CredDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
,
477 struct cred_dialog_params
*params
= (struct cred_dialog_params
*)lParam
;
479 return CredDialogInit(hwndDlg
, params
);
484 case MAKELONG(IDOK
, BN_CLICKED
):
486 struct cred_dialog_params
*params
=
487 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
488 CredDialogCommandOk(hwndDlg
, params
);
491 case MAKELONG(IDCANCEL
, BN_CLICKED
):
492 EndDialog(hwndDlg
, IDCANCEL
);
494 case MAKELONG(IDC_PASSWORD
, EN_SETFOCUS
):
495 if (CredDialogCapsLockOn())
497 struct cred_dialog_params
*params
=
498 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
499 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
501 /* don't allow another window to steal focus while the
502 * user is typing their password */
503 LockSetForegroundWindow(LSFW_LOCK
);
505 case MAKELONG(IDC_PASSWORD
, EN_KILLFOCUS
):
507 struct cred_dialog_params
*params
=
508 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
509 /* the user is no longer typing their password, so allow
510 * other windows to become foreground ones */
511 LockSetForegroundWindow(LSFW_UNLOCK
);
512 CredDialogHideBalloonTip(hwndDlg
, params
);
515 case MAKELONG(IDC_PASSWORD
, EN_CHANGE
):
517 struct cred_dialog_params
*params
=
518 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
519 CredDialogHideBalloonTip(hwndDlg
, params
);
525 if (wParam
== ID_CAPSLOCKPOP
)
527 struct cred_dialog_params
*params
=
528 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
529 CredDialogHideBalloonTip(hwndDlg
, params
);
535 struct cred_dialog_params
*params
=
536 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
537 if (params
->hwndBalloonTip
) DestroyWindow(params
->hwndBalloonTip
);
545 /******************************************************************************
546 * CredUIPromptForCredentialsW [CREDUI.@]
548 DWORD WINAPI
CredUIPromptForCredentialsW(PCREDUI_INFOW pUIInfo
,
549 PCWSTR pszTargetName
,
550 PCtxtHandle Reserved
,
553 ULONG ulUsernameMaxChars
,
555 ULONG ulPasswordMaxChars
, PBOOL pfSave
,
559 struct cred_dialog_params params
;
560 DWORD result
= ERROR_SUCCESS
;
562 TRACE("(%p, %s, %p, %d, %s, %d, %p, %d, %p, 0x%08x)\n", pUIInfo
,
563 debugstr_w(pszTargetName
), Reserved
, dwAuthError
, debugstr_w(pszUsername
),
564 ulUsernameMaxChars
, pszPassword
, ulPasswordMaxChars
, pfSave
, dwFlags
);
566 if ((dwFlags
& (CREDUI_FLAGS_ALWAYS_SHOW_UI
|CREDUI_FLAGS_GENERIC_CREDENTIALS
)) == CREDUI_FLAGS_ALWAYS_SHOW_UI
)
567 return ERROR_INVALID_FLAGS
;
570 return ERROR_INVALID_PARAMETER
;
572 if ((dwFlags
& CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX
) && !pfSave
)
573 return ERROR_INVALID_PARAMETER
;
575 params
.pszTargetName
= pszTargetName
;
578 params
.pszMessageText
= pUIInfo
->pszMessageText
;
579 params
.pszCaptionText
= pUIInfo
->pszCaptionText
;
580 params
.hbmBanner
= pUIInfo
->hbmBanner
;
584 params
.pszMessageText
= NULL
;
585 params
.pszCaptionText
= NULL
;
586 params
.hbmBanner
= NULL
;
588 params
.pszUsername
= pszUsername
;
589 params
.ulUsernameMaxChars
= ulUsernameMaxChars
;
590 params
.pszPassword
= pszPassword
;
591 params
.ulPasswordMaxChars
= ulPasswordMaxChars
;
592 params
.fSave
= pfSave
? *pfSave
: FALSE
;
593 params
.dwFlags
= dwFlags
;
594 params
.hwndBalloonTip
= NULL
;
595 params
.fBalloonTipActive
= FALSE
;
597 ret
= DialogBoxParamW(hinstCredUI
, MAKEINTRESOURCEW(IDD_CREDDIALOG
),
598 pUIInfo
? pUIInfo
->hwndParent
: NULL
,
599 CredDialogProc
, (LPARAM
)¶ms
);
601 return GetLastError();
605 TRACE("dialog cancelled\n");
606 return ERROR_CANCELLED
;
610 *pfSave
= params
.fSave
;
614 if (dwFlags
& CREDUI_FLAGS_EXPECT_CONFIRMATION
)
617 struct pending_credentials
*entry
;
620 EnterCriticalSection(&csPendingCredentials
);
622 /* find existing pending credentials for the same target and overwrite */
623 /* FIXME: is this correct? */
624 LIST_FOR_EACH_ENTRY(entry
, &pending_credentials_list
, struct pending_credentials
, entry
)
625 if (!strcmpW(pszTargetName
, entry
->pszTargetName
))
628 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
629 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
630 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
635 entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(*entry
));
636 len
= strlenW(pszTargetName
);
637 entry
->pszTargetName
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
638 memcpy(entry
->pszTargetName
, pszTargetName
, (len
+ 1)*sizeof(WCHAR
));
639 list_add_tail(&pending_credentials_list
, &entry
->entry
);
642 len
= strlenW(params
.pszUsername
);
643 entry
->pszUsername
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
644 memcpy(entry
->pszUsername
, params
.pszUsername
, (len
+ 1)*sizeof(WCHAR
));
645 len
= strlenW(params
.pszPassword
);
646 entry
->pszPassword
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
647 memcpy(entry
->pszPassword
, params
.pszPassword
, (len
+ 1)*sizeof(WCHAR
));
648 entry
->generic
= dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
? TRUE
: FALSE
;
650 LeaveCriticalSection(&csPendingCredentials
);
653 result
= save_credentials(pszTargetName
, pszUsername
, pszPassword
,
654 dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
? TRUE
: FALSE
);
660 /******************************************************************************
661 * CredUIConfirmCredentialsW [CREDUI.@]
663 DWORD WINAPI
CredUIConfirmCredentialsW(PCWSTR pszTargetName
, BOOL bConfirm
)
665 struct pending_credentials
*entry
;
666 DWORD result
= ERROR_NOT_FOUND
;
668 TRACE("(%s, %s)\n", debugstr_w(pszTargetName
), bConfirm
? "TRUE" : "FALSE");
671 return ERROR_INVALID_PARAMETER
;
673 EnterCriticalSection(&csPendingCredentials
);
675 LIST_FOR_EACH_ENTRY(entry
, &pending_credentials_list
, struct pending_credentials
, entry
)
677 if (!strcmpW(pszTargetName
, entry
->pszTargetName
))
680 result
= save_credentials(entry
->pszTargetName
, entry
->pszUsername
,
681 entry
->pszPassword
, entry
->generic
);
683 result
= ERROR_SUCCESS
;
685 list_remove(&entry
->entry
);
687 HeapFree(GetProcessHeap(), 0, entry
->pszTargetName
);
688 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
689 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
690 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
691 HeapFree(GetProcessHeap(), 0, entry
);
697 LeaveCriticalSection(&csPendingCredentials
);
702 /******************************************************************************
703 * CredUIParseUserNameW [CREDUI.@]
705 DWORD WINAPI
CredUIParseUserNameW(PCWSTR pszUserName
, PWSTR pszUser
,
706 ULONG ulMaxUserChars
, PWSTR pszDomain
,
707 ULONG ulMaxDomainChars
)
711 TRACE("(%s, %p, %d, %p, %d)\n", debugstr_w(pszUserName
), pszUser
,
712 ulMaxUserChars
, pszDomain
, ulMaxDomainChars
);
714 if (!pszUserName
|| !pszUser
|| !ulMaxUserChars
|| !pszDomain
||
716 return ERROR_INVALID_PARAMETER
;
718 /* FIXME: handle marshaled credentials */
720 p
= strchrW(pszUserName
, '\\');
723 if (p
- pszUserName
> ulMaxDomainChars
- 1)
724 return ERROR_INSUFFICIENT_BUFFER
;
725 if (strlenW(p
+ 1) > ulMaxUserChars
- 1)
726 return ERROR_INSUFFICIENT_BUFFER
;
727 strcpyW(pszUser
, p
+ 1);
728 memcpy(pszDomain
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
729 pszDomain
[p
- pszUserName
] = '\0';
731 return ERROR_SUCCESS
;
734 p
= strrchrW(pszUserName
, '@');
737 if (p
+ 1 - pszUserName
> ulMaxUserChars
- 1)
738 return ERROR_INSUFFICIENT_BUFFER
;
739 if (strlenW(p
+ 1) > ulMaxDomainChars
- 1)
740 return ERROR_INSUFFICIENT_BUFFER
;
741 strcpyW(pszDomain
, p
+ 1);
742 memcpy(pszUser
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
743 pszUser
[p
- pszUserName
] = '\0';
745 return ERROR_SUCCESS
;
748 if (strlenW(pszUserName
) > ulMaxUserChars
- 1)
749 return ERROR_INSUFFICIENT_BUFFER
;
750 strcpyW(pszUser
, pszUserName
);
753 return ERROR_SUCCESS
;
756 /******************************************************************************
757 * CredUIStoreSSOCredA [CREDUI.@]
759 DWORD WINAPI
CredUIStoreSSOCredA(PCSTR pszRealm
, PCSTR pszUsername
,
760 PCSTR pszPassword
, BOOL bPersist
)
762 FIXME("(%s, %s, %p, %d)\n", debugstr_a(pszRealm
), debugstr_a(pszUsername
),
763 pszPassword
, bPersist
);
764 return ERROR_SUCCESS
;
767 /******************************************************************************
768 * CredUIStoreSSOCredW [CREDUI.@]
770 DWORD WINAPI
CredUIStoreSSOCredW(PCWSTR pszRealm
, PCWSTR pszUsername
,
771 PCWSTR pszPassword
, BOOL bPersist
)
773 FIXME("(%s, %s, %p, %d)\n", debugstr_w(pszRealm
), debugstr_w(pszUsername
),
774 pszPassword
, bPersist
);
775 return ERROR_SUCCESS
;
778 /******************************************************************************
779 * CredUIReadSSOCredA [CREDUI.@]
781 DWORD WINAPI
CredUIReadSSOCredA(PCSTR pszRealm
, PSTR
*ppszUsername
)
783 FIXME("(%s, %p)\n", debugstr_a(pszRealm
), ppszUsername
);
785 *ppszUsername
= NULL
;
786 return ERROR_NOT_FOUND
;
789 /******************************************************************************
790 * CredUIReadSSOCredW [CREDUI.@]
792 DWORD WINAPI
CredUIReadSSOCredW(PCWSTR pszRealm
, PWSTR
*ppszUsername
)
794 FIXME("(%s, %p)\n", debugstr_w(pszRealm
), ppszUsername
);
796 *ppszUsername
= NULL
;
797 return ERROR_NOT_FOUND
;