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
29 #include "credui_resources.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(credui
);
36 static HINSTANCE hinstCredUI
;
38 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
40 TRACE("(0x%p, %d, %p)\n",hinstDLL
,fdwReason
,lpvReserved
);
42 if (fdwReason
== DLL_WINE_PREATTACH
) return FALSE
; /* prefer native version */
44 if (fdwReason
== DLL_PROCESS_ATTACH
)
46 DisableThreadLibraryCalls(hinstDLL
);
47 hinstCredUI
= hinstDLL
;
53 struct cred_dialog_params
56 PCWSTR pszMessageText
;
57 PCWSTR pszCaptionText
;
60 ULONG ulUsernameMaxChars
;
62 ULONG ulPasswordMaxChars
;
66 static INT_PTR CALLBACK
CredDialogProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
,
73 struct cred_dialog_params
*params
= (struct cred_dialog_params
*)lParam
;
78 SetWindowLongPtrW(hwndDlg
, DWLP_USER
, (LONG_PTR
)params
);
79 ret
= CredUIParseUserNameW(params
->pszUsername
, user
, 256, domain
, 256);
80 if (ret
== ERROR_SUCCESS
)
82 SetDlgItemTextW(hwndDlg
, IDC_USERNAME
, user
);
83 SetDlgItemTextW(hwndDlg
, IDC_DOMAIN
, domain
);
85 SetDlgItemTextW(hwndDlg
, IDC_PASSWORD
, params
->pszPassword
);
87 if (ret
== ERROR_SUCCESS
&& user
[0])
88 SetFocus(GetDlgItem(hwndDlg
, IDC_PASSWORD
));
90 SetFocus(GetDlgItem(hwndDlg
, IDC_USERNAME
));
92 if (params
->pszCaptionText
)
93 SetWindowTextW(hwndDlg
, params
->pszCaptionText
);
99 case MAKELONG(IDOK
, BN_CLICKED
):
102 struct cred_dialog_params
*params
=
103 (struct cred_dialog_params
*)GetWindowLongPtrW(hwndDlg
, DWLP_USER
);
105 domainlen
= GetDlgItemTextW(hwndDlg
, IDC_DOMAIN
,
107 params
->ulUsernameMaxChars
);
108 if (domainlen
&& (domainlen
< params
->ulUsernameMaxChars
))
110 params
->pszUsername
[domainlen
++] = '\\';
111 params
->pszUsername
[domainlen
] = '\0';
113 if (domainlen
< params
->ulUsernameMaxChars
)
114 GetDlgItemTextW(hwndDlg
, IDC_USERNAME
,
115 params
->pszUsername
+ domainlen
,
116 params
->ulUsernameMaxChars
- domainlen
);
117 GetDlgItemTextW(hwndDlg
, IDC_PASSWORD
, params
->pszPassword
,
118 params
->ulPasswordMaxChars
);
120 EndDialog(hwndDlg
, IDOK
);
123 case MAKELONG(IDCANCEL
, BN_CLICKED
):
124 EndDialog(hwndDlg
, IDCANCEL
);
133 /******************************************************************************
134 * CredUIPromptForCredentialsW [CREDUI.@]
136 DWORD WINAPI
CredUIPromptForCredentialsW(PCREDUI_INFOW pUIInfo
,
137 PCWSTR pszTargetName
,
138 PCtxtHandle Reserved
,
141 ULONG ulUsernameMaxChars
,
143 ULONG ulPasswordMaxChars
, PBOOL pfSave
,
147 struct cred_dialog_params params
;
149 TRACE("(%p, %s, %p, %d, %p, %d, %p, %d, %p, 0x%08x)\n", pUIInfo
,
150 debugstr_w(pszTargetName
), Reserved
, dwAuthError
, pszUsername
,
151 ulUsernameMaxChars
, pszPassword
, ulPasswordMaxChars
, pfSave
, dwFlags
);
153 params
.pszTargetName
= pszTargetName
;
156 params
.pszMessageText
= pUIInfo
->pszMessageText
;
157 params
.pszCaptionText
= pUIInfo
->pszCaptionText
;
158 params
.hbmBanner
= pUIInfo
->hbmBanner
;
162 params
.pszMessageText
= NULL
;
163 params
.pszCaptionText
= NULL
;
164 params
.hbmBanner
= NULL
;
166 params
.pszUsername
= pszUsername
;
167 params
.ulUsernameMaxChars
= ulUsernameMaxChars
;
168 params
.pszPassword
= pszPassword
;
169 params
.ulPasswordMaxChars
= ulPasswordMaxChars
;
170 params
.fSave
= pfSave
? *pfSave
: FALSE
;
172 ret
= DialogBoxParamW(hinstCredUI
, MAKEINTRESOURCEW(IDD_CREDDIALOG
),
173 pUIInfo
->hwndParent
, CredDialogProc
, (LPARAM
)¶ms
);
175 return GetLastError();
179 TRACE("dialog cancelled\n");
180 return ERROR_CANCELLED
;
184 *pfSave
= params
.fSave
;
186 return ERROR_SUCCESS
;
189 /******************************************************************************
190 * CredUIConfirmCredentialsW [CREDUI.@]
192 DWORD WINAPI
CredUIConfirmCredentialsW(PCWSTR pszTargetName
, BOOL bConfirm
)
194 FIXME("(%s, %s): stub\n", debugstr_w(pszTargetName
),
195 bConfirm
? "TRUE" : "FALSE");
196 return ERROR_SUCCESS
;
199 /******************************************************************************
200 * CredUIParseUserNameW [CREDUI.@]
202 DWORD WINAPI
CredUIParseUserNameW(PCWSTR pszUserName
, PWSTR pszUser
,
203 ULONG ulMaxUserChars
, PWSTR pszDomain
,
204 ULONG ulMaxDomainChars
)
208 TRACE("(%s, %p, %d, %p, %d)\n", debugstr_w(pszUserName
), pszUser
,
209 ulMaxUserChars
, pszDomain
, ulMaxDomainChars
);
211 if (!pszUserName
|| !pszUser
|| !ulMaxUserChars
|| !pszDomain
||
213 return ERROR_INVALID_PARAMETER
;
215 /* FIXME: handle marshaled credentials */
217 p
= strchrW(pszUserName
, '\\');
220 if (p
- pszUserName
> ulMaxDomainChars
- 1)
221 return ERROR_INSUFFICIENT_BUFFER
;
222 if (strlenW(p
+ 1) > ulMaxUserChars
- 1)
223 return ERROR_INSUFFICIENT_BUFFER
;
224 strcpyW(pszUser
, p
+ 1);
225 memcpy(pszDomain
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
226 pszDomain
[p
- pszUserName
] = '\0';
228 return ERROR_SUCCESS
;
231 p
= strrchrW(pszUserName
, '@');
234 if (p
+ 1 - pszUserName
> ulMaxUserChars
- 1)
235 return ERROR_INSUFFICIENT_BUFFER
;
236 if (strlenW(p
+ 1) > ulMaxDomainChars
- 1)
237 return ERROR_INSUFFICIENT_BUFFER
;
238 strcpyW(pszDomain
, p
+ 1);
239 memcpy(pszUser
, pszUserName
, (p
- pszUserName
)*sizeof(WCHAR
));
240 pszUser
[p
- pszUserName
] = '\0';
242 return ERROR_SUCCESS
;
245 if (strlenW(pszUserName
) > ulMaxUserChars
- 1)
246 return ERROR_INSUFFICIENT_BUFFER
;
247 strcpyW(pszUser
, pszUserName
);
250 return ERROR_SUCCESS
;