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 LIST_FOR_EACH_ENTRY_SAFE(entry
, cursor2
, &pending_credentials_list
, struct pending_credentials
, entry
)
87 list_remove(&entry
->entry
);
89 HeapFree(GetProcessHeap(), 0, entry
->pszTargetName
);
90 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
91 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
92 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
93 HeapFree(GetProcessHeap(), 0, entry
);
95 DeleteCriticalSection(&csPendingCredentials
);
102 static DWORD
save_credentials(PCWSTR pszTargetName
, PCWSTR pszUsername
,
103 PCWSTR pszPassword
, BOOL generic
)
107 TRACE("saving servername %s with username %s\n", debugstr_w(pszTargetName
), debugstr_w(pszUsername
));
110 cred
.Type
= generic
? CRED_TYPE_GENERIC
: CRED_TYPE_DOMAIN_PASSWORD
;
111 cred
.TargetName
= (LPWSTR
)pszTargetName
;
113 cred
.CredentialBlobSize
= strlenW(pszPassword
) * sizeof(WCHAR
);
114 cred
.CredentialBlob
= (LPBYTE
)pszPassword
;
115 cred
.Persist
= CRED_PERSIST_ENTERPRISE
;
116 cred
.AttributeCount
= 0;
117 cred
.Attributes
= NULL
;
118 cred
.TargetAlias
= NULL
;
119 cred
.UserName
= (LPWSTR
)pszUsername
;
121 if (CredWriteW(&cred
, 0))
122 return ERROR_SUCCESS
;
125 DWORD ret
= GetLastError();
126 ERR("CredWriteW failed with error %d\n", ret
);
131 struct cred_dialog_params
133 PCWSTR pszTargetName
;
134 PCWSTR pszMessageText
;
135 PCWSTR pszCaptionText
;
138 ULONG ulUsernameMaxChars
;
140 ULONG ulPasswordMaxChars
;
144 BOOL fBalloonTipActive
;
147 static void CredDialogFillUsernameCombo(HWND hwndUsername
, const struct cred_dialog_params
*params
)
151 PCREDENTIALW
*credentials
;
153 if (!CredEnumerateW(NULL
, 0, &count
, &credentials
))
156 for (i
= 0; i
< count
; i
++)
158 COMBOBOXEXITEMW comboitem
;
160 BOOL duplicate
= FALSE
;
162 if (params
->dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
)
164 if ((credentials
[i
]->Type
!= CRED_TYPE_GENERIC
) || !credentials
[i
]->UserName
)
169 if (credentials
[i
]->Type
== CRED_TYPE_GENERIC
)
173 /* don't add another item with the same name if we've already added it */
174 for (j
= 0; j
< i
; j
++)
175 if (!strcmpW(credentials
[i
]->UserName
, credentials
[j
]->UserName
))
184 comboitem
.mask
= CBEIF_TEXT
;
185 comboitem
.iItem
= -1;
186 comboitem
.pszText
= credentials
[i
]->UserName
;
187 SendMessageW(hwndUsername
, CBEM_INSERTITEMW
, 0, (LPARAM
)&comboitem
);
190 CredFree(credentials
);
193 static void CredDialogCreateBalloonTip(HWND hwndDlg
, struct cred_dialog_params
*params
)
195 TTTOOLINFOW toolinfo
;
198 if (params
->hwndBalloonTip
)
201 params
->hwndBalloonTip
= CreateWindowExW(WS_EX_TOOLWINDOW
, TOOLTIPS_CLASSW
,
202 NULL
, WS_POPUP
| TTS_NOPREFIX
| TTS_BALLOON
, CW_USEDEFAULT
,
203 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, hwndDlg
, NULL
,
205 SetWindowPos(params
->hwndBalloonTip
, HWND_TOPMOST
, 0, 0, 0, 0,
206 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
208 if (!LoadStringW(hinstCredUI
, IDS_INCORRECTPASSWORD
, wszText
, sizeof(wszText
)/sizeof(wszText
[0])))
210 ERR("failed to load IDS_INCORRECTPASSWORD\n");
214 toolinfo
.cbSize
= sizeof(toolinfo
);
215 toolinfo
.uFlags
= TTF_TRACK
;
216 toolinfo
.hwnd
= hwndDlg
;
217 toolinfo
.uId
= TOOLID_INCORRECTPASSWORD
;
218 memset(&toolinfo
.rect
, 0, sizeof(toolinfo
.rect
));
219 toolinfo
.hinst
= NULL
;
220 toolinfo
.lpszText
= wszText
;
222 toolinfo
.lpReserved
= NULL
;
223 SendMessageW(params
->hwndBalloonTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&toolinfo
);
225 if (!LoadStringW(hinstCredUI
, IDS_CAPSLOCKON
, wszText
, sizeof(wszText
)/sizeof(wszText
[0])))
227 ERR("failed to load IDS_CAPSLOCKON\n");
231 toolinfo
.uId
= TOOLID_CAPSLOCKON
;
232 SendMessageW(params
->hwndBalloonTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&toolinfo
);
235 static void CredDialogShowIncorrectPasswordBalloon(HWND hwndDlg
, struct cred_dialog_params
*params
)
237 TTTOOLINFOW toolinfo
;
243 /* user name likely wrong so balloon would be confusing. focus is also
244 * not set to the password edit box, so more notification would need to be
246 if (!params
->pszUsername
[0])
249 /* don't show two balloon tips at once */
250 if (params
->fBalloonTipActive
)
253 if (!LoadStringW(hinstCredUI
, IDS_INCORRECTPASSWORDTITLE
, wszTitle
, sizeof(wszTitle
)/sizeof(wszTitle
[0])))
255 ERR("failed to load IDS_INCORRECTPASSWORDTITLE\n");
259 CredDialogCreateBalloonTip(hwndDlg
, params
);
261 memset(&toolinfo
, 0, sizeof(toolinfo
));
262 toolinfo
.cbSize
= sizeof(toolinfo
);
263 toolinfo
.hwnd
= hwndDlg
;
264 toolinfo
.uId
= TOOLID_INCORRECTPASSWORD
;
266 SendMessageW(params
->hwndBalloonTip
, TTM_SETTITLEW
, TTI_ERROR
, (LPARAM
)wszTitle
);
268 GetWindowRect(GetDlgItem(hwndDlg
, IDC_PASSWORD
), &rcPassword
);
269 /* centered vertically and in the right side of the password edit control */
270 x
= rcPassword
.right
- 12;
271 y
= (rcPassword
.top
+ rcPassword
.bottom
) / 2;
272 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKPOSITION
, 0, MAKELONG(x
, y
));
274 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&toolinfo
);
276 params
->fBalloonTipActive
= TRUE
;
279 static void CredDialogShowCapsLockBalloon(HWND hwndDlg
, struct cred_dialog_params
*params
)
281 TTTOOLINFOW toolinfo
;
287 /* don't show two balloon tips at once */
288 if (params
->fBalloonTipActive
)
291 if (!LoadStringW(hinstCredUI
, IDS_CAPSLOCKONTITLE
, wszTitle
, sizeof(wszTitle
)/sizeof(wszTitle
[0])))
293 ERR("failed to load IDS_IDSCAPSLOCKONTITLE\n");
297 CredDialogCreateBalloonTip(hwndDlg
, params
);
299 memset(&toolinfo
, 0, sizeof(toolinfo
));
300 toolinfo
.cbSize
= sizeof(toolinfo
);
301 toolinfo
.hwnd
= hwndDlg
;
302 toolinfo
.uId
= TOOLID_CAPSLOCKON
;
304 SendMessageW(params
->hwndBalloonTip
, TTM_SETTITLEW
, TTI_WARNING
, (LPARAM
)wszTitle
);
306 GetWindowRect(GetDlgItem(hwndDlg
, IDC_PASSWORD
), &rcPassword
);
307 /* just inside the left side of the password edit control */
308 x
= rcPassword
.left
+ 12;
309 y
= rcPassword
.bottom
- 3;
310 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKPOSITION
, 0, MAKELONG(x
, y
));
312 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&toolinfo
);
314 SetTimer(hwndDlg
, ID_CAPSLOCKPOP
,
315 SendMessageW(params
->hwndBalloonTip
, TTM_GETDELAYTIME
, TTDT_AUTOPOP
, 0),
318 params
->fBalloonTipActive
= TRUE
;
321 static void CredDialogHideBalloonTip(HWND hwndDlg
, struct cred_dialog_params
*params
)
323 TTTOOLINFOW toolinfo
;
325 if (!params
->hwndBalloonTip
)
328 memset(&toolinfo
, 0, sizeof(toolinfo
));
330 toolinfo
.cbSize
= sizeof(toolinfo
);
331 toolinfo
.hwnd
= hwndDlg
;
333 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, FALSE
, (LPARAM
)&toolinfo
);
335 SendMessageW(params
->hwndBalloonTip
, TTM_TRACKACTIVATE
, FALSE
, (LPARAM
)&toolinfo
);
337 params
->fBalloonTipActive
= FALSE
;
340 static inline BOOL
CredDialogCapsLockOn(void)
342 return GetKeyState(VK_CAPITAL
) & 0x1 ? TRUE
: FALSE
;
345 static LRESULT CALLBACK
CredDialogPasswordSubclassProc(HWND hwnd
, UINT uMsg
,
346 WPARAM wParam
, LPARAM lParam
, UINT_PTR uIdSubclass
, DWORD_PTR dwRefData
)
348 struct cred_dialog_params
*params
= (struct cred_dialog_params
*)dwRefData
;
352 if (wParam
== VK_CAPITAL
)
354 HWND hwndDlg
= GetParent(hwnd
);
355 if (CredDialogCapsLockOn())
356 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
358 CredDialogHideBalloonTip(hwndDlg
, params
);
362 RemoveWindowSubclass(hwnd
, CredDialogPasswordSubclassProc
, uIdSubclass
);
365 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
368 static BOOL
CredDialogInit(HWND hwndDlg
, struct cred_dialog_params
*params
)
370 HWND hwndUsername
= GetDlgItem(hwndDlg
, IDC_USERNAME
);
371 HWND hwndPassword
= GetDlgItem(hwndDlg
, IDC_PASSWORD
);
373 SetWindowLongPtrW(hwndDlg
, DWLP_USER
, (LONG_PTR
)params
);
375 if (params
->hbmBanner
)
376 SendMessageW(GetDlgItem(hwndDlg
, IDB_BANNER
), STM_SETIMAGE
,
377 IMAGE_BITMAP
, (LPARAM
)params
->hbmBanner
);
379 if (params
->pszMessageText
)
380 SetDlgItemTextW(hwndDlg
, IDC_MESSAGE
, params
->pszMessageText
);
385 LoadStringW(hinstCredUI
, IDS_MESSAGEFORMAT
, format
, sizeof(format
)/sizeof(format
[0]));
386 snprintfW(message
, sizeof(message
)/sizeof(message
[0]), format
, params
->pszTargetName
);
387 SetDlgItemTextW(hwndDlg
, IDC_MESSAGE
, message
);
389 SetWindowTextW(hwndUsername
, params
->pszUsername
);
390 SetWindowTextW(hwndPassword
, params
->pszPassword
);
392 CredDialogFillUsernameCombo(hwndUsername
, params
);
394 if (params
->pszUsername
[0])
396 /* prevent showing a balloon tip here */
397 params
->fBalloonTipActive
= TRUE
;
398 SetFocus(hwndPassword
);
399 params
->fBalloonTipActive
= FALSE
;
402 SetFocus(hwndUsername
);
404 if (params
->pszCaptionText
)
405 SetWindowTextW(hwndDlg
, params
->pszCaptionText
);
410 LoadStringW(hinstCredUI
, IDS_TITLEFORMAT
, format
, sizeof(format
)/sizeof(format
[0]));
411 snprintfW(title
, sizeof(title
)/sizeof(title
[0]), format
, params
->pszTargetName
);
412 SetWindowTextW(hwndDlg
, title
);
415 if (params
->dwFlags
& (CREDUI_FLAGS_DO_NOT_PERSIST
|CREDUI_FLAGS_PERSIST
))
416 ShowWindow(GetDlgItem(hwndDlg
, IDC_SAVE
), SW_HIDE
);
417 else if (params
->fSave
)
418 CheckDlgButton(hwndDlg
, IDC_SAVE
, BST_CHECKED
);
420 /* setup subclassing for Caps Lock detection */
421 SetWindowSubclass(hwndPassword
, CredDialogPasswordSubclassProc
, 1, (DWORD_PTR
)params
);
423 if (params
->dwFlags
& CREDUI_FLAGS_INCORRECT_PASSWORD
)
424 CredDialogShowIncorrectPasswordBalloon(hwndDlg
, params
);
425 else if ((GetFocus() == hwndPassword
) && CredDialogCapsLockOn())
426 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
431 static void CredDialogCommandOk(HWND hwndDlg
, struct cred_dialog_params
*params
)
433 HWND hwndUsername
= GetDlgItem(hwndDlg
, IDC_USERNAME
);
438 len
= GetWindowTextLengthW(hwndUsername
);
439 user
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
440 GetWindowTextW(hwndUsername
, user
, len
+ 1);
444 HeapFree(GetProcessHeap(), 0, user
);
448 if (!strchrW(user
, '\\') && !strchrW(user
, '@'))
450 ULONG len_target
= strlenW(params
->pszTargetName
);
451 memcpy(params
->pszUsername
, params
->pszTargetName
,
452 min(len_target
, params
->ulUsernameMaxChars
) * sizeof(WCHAR
));
453 if (len_target
+ 1 < params
->ulUsernameMaxChars
)
454 params
->pszUsername
[len_target
] = '\\';
455 if (len_target
+ 2 < params
->ulUsernameMaxChars
)
456 params
->pszUsername
[len_target
+ 1] = '\0';
458 else if (params
->ulUsernameMaxChars
> 0)
459 params
->pszUsername
[0] = '\0';
461 len2
= strlenW(params
->pszUsername
);
462 memcpy(params
->pszUsername
+ len2
, user
, min(len
, params
->ulUsernameMaxChars
- len2
) * sizeof(WCHAR
));
463 if (params
->ulUsernameMaxChars
)
464 params
->pszUsername
[len2
+ min(len
, params
->ulUsernameMaxChars
- len2
- 1)] = '\0';
466 HeapFree(GetProcessHeap(), 0, user
);
468 GetDlgItemTextW(hwndDlg
, IDC_PASSWORD
, params
->pszPassword
,
469 params
->ulPasswordMaxChars
);
471 params
->fSave
= IsDlgButtonChecked(hwndDlg
, IDC_SAVE
) == BST_CHECKED
;
473 EndDialog(hwndDlg
, IDOK
);
476 static INT_PTR CALLBACK
CredDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
,
483 struct cred_dialog_params
*params
= (struct cred_dialog_params
*)lParam
;
485 return CredDialogInit(hwndDlg
, params
);
490 case MAKELONG(IDOK
, BN_CLICKED
):
492 struct cred_dialog_params
*params
=
493 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
494 CredDialogCommandOk(hwndDlg
, params
);
497 case MAKELONG(IDCANCEL
, BN_CLICKED
):
498 EndDialog(hwndDlg
, IDCANCEL
);
500 case MAKELONG(IDC_PASSWORD
, EN_SETFOCUS
):
501 if (CredDialogCapsLockOn())
503 struct cred_dialog_params
*params
=
504 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
505 CredDialogShowCapsLockBalloon(hwndDlg
, params
);
507 /* don't allow another window to steal focus while the
508 * user is typing their password */
509 LockSetForegroundWindow(LSFW_LOCK
);
511 case MAKELONG(IDC_PASSWORD
, EN_KILLFOCUS
):
513 struct cred_dialog_params
*params
=
514 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
515 /* the user is no longer typing their password, so allow
516 * other windows to become foreground ones */
517 LockSetForegroundWindow(LSFW_UNLOCK
);
518 CredDialogHideBalloonTip(hwndDlg
, params
);
521 case MAKELONG(IDC_PASSWORD
, EN_CHANGE
):
523 struct cred_dialog_params
*params
=
524 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
525 CredDialogHideBalloonTip(hwndDlg
, params
);
531 if (wParam
== ID_CAPSLOCKPOP
)
533 struct cred_dialog_params
*params
=
534 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
535 CredDialogHideBalloonTip(hwndDlg
, params
);
541 struct cred_dialog_params
*params
=
542 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
543 if (params
->hwndBalloonTip
) DestroyWindow(params
->hwndBalloonTip
);
551 /******************************************************************************
552 * CredUIPromptForCredentialsW [CREDUI.@]
554 DWORD WINAPI
CredUIPromptForCredentialsW(PCREDUI_INFOW pUIInfo
,
555 PCWSTR pszTargetName
,
556 PCtxtHandle Reserved
,
559 ULONG ulUsernameMaxChars
,
561 ULONG ulPasswordMaxChars
, PBOOL pfSave
,
565 struct cred_dialog_params params
;
566 DWORD result
= ERROR_SUCCESS
;
568 TRACE("(%p, %s, %p, %d, %s, %d, %p, %d, %p, 0x%08x)\n", pUIInfo
,
569 debugstr_w(pszTargetName
), Reserved
, dwAuthError
, debugstr_w(pszUsername
),
570 ulUsernameMaxChars
, pszPassword
, ulPasswordMaxChars
, pfSave
, dwFlags
);
572 if ((dwFlags
& (CREDUI_FLAGS_ALWAYS_SHOW_UI
|CREDUI_FLAGS_GENERIC_CREDENTIALS
)) == CREDUI_FLAGS_ALWAYS_SHOW_UI
)
573 return ERROR_INVALID_FLAGS
;
576 return ERROR_INVALID_PARAMETER
;
578 if ((dwFlags
& CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX
) && !pfSave
)
579 return ERROR_INVALID_PARAMETER
;
581 params
.pszTargetName
= pszTargetName
;
584 params
.pszMessageText
= pUIInfo
->pszMessageText
;
585 params
.pszCaptionText
= pUIInfo
->pszCaptionText
;
586 params
.hbmBanner
= pUIInfo
->hbmBanner
;
590 params
.pszMessageText
= NULL
;
591 params
.pszCaptionText
= NULL
;
592 params
.hbmBanner
= NULL
;
594 params
.pszUsername
= pszUsername
;
595 params
.ulUsernameMaxChars
= ulUsernameMaxChars
;
596 params
.pszPassword
= pszPassword
;
597 params
.ulPasswordMaxChars
= ulPasswordMaxChars
;
598 params
.fSave
= pfSave
? *pfSave
: FALSE
;
599 params
.dwFlags
= dwFlags
;
600 params
.hwndBalloonTip
= NULL
;
601 params
.fBalloonTipActive
= FALSE
;
603 ret
= DialogBoxParamW(hinstCredUI
, MAKEINTRESOURCEW(IDD_CREDDIALOG
),
604 pUIInfo
? pUIInfo
->hwndParent
: NULL
,
605 CredDialogProc
, (LPARAM
)¶ms
);
607 return GetLastError();
611 TRACE("dialog cancelled\n");
612 return ERROR_CANCELLED
;
616 *pfSave
= params
.fSave
;
620 if (dwFlags
& CREDUI_FLAGS_EXPECT_CONFIRMATION
)
623 struct pending_credentials
*entry
;
626 EnterCriticalSection(&csPendingCredentials
);
628 /* find existing pending credentials for the same target and overwrite */
629 /* FIXME: is this correct? */
630 LIST_FOR_EACH_ENTRY(entry
, &pending_credentials_list
, struct pending_credentials
, entry
)
631 if (!strcmpW(pszTargetName
, entry
->pszTargetName
))
634 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
635 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
636 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
641 entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(*entry
));
642 len
= strlenW(pszTargetName
);
643 entry
->pszTargetName
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
644 memcpy(entry
->pszTargetName
, pszTargetName
, (len
+ 1)*sizeof(WCHAR
));
645 list_add_tail(&pending_credentials_list
, &entry
->entry
);
648 len
= strlenW(params
.pszUsername
);
649 entry
->pszUsername
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
650 memcpy(entry
->pszUsername
, params
.pszUsername
, (len
+ 1)*sizeof(WCHAR
));
651 len
= strlenW(params
.pszPassword
);
652 entry
->pszPassword
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1)*sizeof(WCHAR
));
653 memcpy(entry
->pszPassword
, params
.pszPassword
, (len
+ 1)*sizeof(WCHAR
));
654 entry
->generic
= dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
? TRUE
: FALSE
;
656 LeaveCriticalSection(&csPendingCredentials
);
659 result
= save_credentials(pszTargetName
, pszUsername
, pszPassword
,
660 dwFlags
& CREDUI_FLAGS_GENERIC_CREDENTIALS
? TRUE
: FALSE
);
666 /******************************************************************************
667 * CredUIConfirmCredentialsW [CREDUI.@]
669 DWORD WINAPI
CredUIConfirmCredentialsW(PCWSTR pszTargetName
, BOOL bConfirm
)
671 struct pending_credentials
*entry
;
672 DWORD result
= ERROR_NOT_FOUND
;
674 TRACE("(%s, %s)\n", debugstr_w(pszTargetName
), bConfirm
? "TRUE" : "FALSE");
677 return ERROR_INVALID_PARAMETER
;
679 EnterCriticalSection(&csPendingCredentials
);
681 LIST_FOR_EACH_ENTRY(entry
, &pending_credentials_list
, struct pending_credentials
, entry
)
683 if (!strcmpW(pszTargetName
, entry
->pszTargetName
))
686 result
= save_credentials(entry
->pszTargetName
, entry
->pszUsername
,
687 entry
->pszPassword
, entry
->generic
);
689 result
= ERROR_SUCCESS
;
691 list_remove(&entry
->entry
);
693 HeapFree(GetProcessHeap(), 0, entry
->pszTargetName
);
694 HeapFree(GetProcessHeap(), 0, entry
->pszUsername
);
695 ZeroMemory(entry
->pszPassword
, (strlenW(entry
->pszPassword
) + 1) * sizeof(WCHAR
));
696 HeapFree(GetProcessHeap(), 0, entry
->pszPassword
);
697 HeapFree(GetProcessHeap(), 0, entry
);
703 LeaveCriticalSection(&csPendingCredentials
);
708 /******************************************************************************
709 * CredUIParseUserNameW [CREDUI.@]
711 DWORD WINAPI
CredUIParseUserNameW(PCWSTR pszUserName
, PWSTR pszUser
,
712 ULONG ulMaxUserChars
, PWSTR pszDomain
,
713 ULONG ulMaxDomainChars
)
717 TRACE("(%s, %p, %d, %p, %d)\n", debugstr_w(pszUserName
), pszUser
,
718 ulMaxUserChars
, pszDomain
, ulMaxDomainChars
);
720 if (!pszUserName
|| !pszUser
|| !ulMaxUserChars
|| !pszDomain
||
722 return ERROR_INVALID_PARAMETER
;
724 /* FIXME: handle marshaled credentials */
726 p
= strchrW(pszUserName
, '\\');
729 if (p
- pszUserName
> ulMaxDomainChars
- 1)
730 return ERROR_INSUFFICIENT_BUFFER
;
731 if (strlenW(p
+ 1) > ulMaxUserChars
- 1)
732 return ERROR_INSUFFICIENT_BUFFER
;
733 strcpyW(pszUser
, p
+ 1);
734 memcpy(pszDomain
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
735 pszDomain
[p
- pszUserName
] = '\0';
737 return ERROR_SUCCESS
;
740 p
= strrchrW(pszUserName
, '@');
743 if (p
+ 1 - pszUserName
> ulMaxUserChars
- 1)
744 return ERROR_INSUFFICIENT_BUFFER
;
745 if (strlenW(p
+ 1) > ulMaxDomainChars
- 1)
746 return ERROR_INSUFFICIENT_BUFFER
;
747 strcpyW(pszDomain
, p
+ 1);
748 memcpy(pszUser
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
749 pszUser
[p
- pszUserName
] = '\0';
751 return ERROR_SUCCESS
;
754 if (strlenW(pszUserName
) > ulMaxUserChars
- 1)
755 return ERROR_INSUFFICIENT_BUFFER
;
756 strcpyW(pszUser
, pszUserName
);
759 return ERROR_SUCCESS
;
762 /******************************************************************************
763 * CredUIStoreSSOCredA [CREDUI.@]
765 DWORD WINAPI
CredUIStoreSSOCredA(PCSTR pszRealm
, PCSTR pszUsername
,
766 PCSTR pszPassword
, BOOL bPersist
)
768 FIXME("(%s, %s, %p, %d)\n", debugstr_a(pszRealm
), debugstr_a(pszUsername
),
769 pszPassword
, bPersist
);
770 return ERROR_SUCCESS
;
773 /******************************************************************************
774 * CredUIStoreSSOCredW [CREDUI.@]
776 DWORD WINAPI
CredUIStoreSSOCredW(PCWSTR pszRealm
, PCWSTR pszUsername
,
777 PCWSTR pszPassword
, BOOL bPersist
)
779 FIXME("(%s, %s, %p, %d)\n", debugstr_w(pszRealm
), debugstr_w(pszUsername
),
780 pszPassword
, bPersist
);
781 return ERROR_SUCCESS
;
784 /******************************************************************************
785 * CredUIReadSSOCredA [CREDUI.@]
787 DWORD WINAPI
CredUIReadSSOCredA(PCSTR pszRealm
, PSTR
*ppszUsername
)
789 FIXME("(%s, %p)\n", debugstr_a(pszRealm
), ppszUsername
);
791 *ppszUsername
= NULL
;
792 return ERROR_NOT_FOUND
;
795 /******************************************************************************
796 * CredUIReadSSOCredW [CREDUI.@]
798 DWORD WINAPI
CredUIReadSSOCredW(PCWSTR pszRealm
, PWSTR
*ppszUsername
)
800 FIXME("(%s, %p)\n", debugstr_w(pszRealm
), ppszUsername
);
802 *ppszUsername
= NULL
;
803 return ERROR_NOT_FOUND
;