1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxGINA -- Windows Logon DLL for VirtualBox Dialog Code
|
---|
4 | *
|
---|
5 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
6 | *
|
---|
7 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | * available from http://www.virtualbox.org. This file is free software;
|
---|
9 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | * General Public License (GPL) as published by the Free Software
|
---|
11 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | *
|
---|
15 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
16 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
17 | * additional information or have any questions.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include <windows.h>
|
---|
21 | #include <stdio.h> /* Needed for swprintf() */
|
---|
22 | #include "Dialog.h"
|
---|
23 | #include "WinWlx.h"
|
---|
24 | #include "Helper.h"
|
---|
25 | #include "VBoxGINA.h"
|
---|
26 |
|
---|
27 | //
|
---|
28 | // MSGINA dialog box IDs.
|
---|
29 | //
|
---|
30 | #define IDD_WLXDIAPLAYSASNOTICE_DIALOG 1400
|
---|
31 | #define IDD_WLXLOGGEDOUTSAS_DIALOG 1450
|
---|
32 | /* the Windows 2000 ID */
|
---|
33 | #define IDD_WLXLOGGEDOUTSAS_DIALOG2 1500
|
---|
34 | #define IDD_CHANGE_PASSWORD_DIALOG 1550
|
---|
35 | #define IDD_WLXLOGGEDONSAS_DIALOG 1650
|
---|
36 | #define IDD_WLXWKSTALOCKEDSAS_DIALOG 1850
|
---|
37 |
|
---|
38 | //
|
---|
39 | // MSGINA control IDs
|
---|
40 | //
|
---|
41 | #define IDC_WLXLOGGEDOUTSAS_USERNAME 1453
|
---|
42 | #define IDC_WLXLOGGEDOUTSAS_USERNAME2 1502
|
---|
43 | #define IDC_WLXLOGGEDOUTSAS_PASSWORD 1454
|
---|
44 | #define IDC_WLXLOGGEDOUTSAS_PASSWORD2 1503
|
---|
45 | #define IDC_WLXLOGGEDOUTSAS_DOMAIN 1455
|
---|
46 | #define IDC_WLXLOGGEDOUTSAS_DOMAIN2 1504
|
---|
47 | #define IDC_WLXWKSTALOCKEDSAS_DOMAIN 1856
|
---|
48 |
|
---|
49 | static DLGPROC pfWlxLoggedOutSASDlgProc = NULL;
|
---|
50 |
|
---|
51 | static PWLX_DIALOG_BOX_PARAM pfWlxDialogBoxParam = NULL;
|
---|
52 |
|
---|
53 | int WINAPI MyWlxDialogBoxParam (HANDLE, HANDLE, LPWSTR, HWND, DLGPROC, LPARAM);
|
---|
54 |
|
---|
55 | void hookDialogBoxes(PVOID pWinlogonFunctions, DWORD dwWlxVersion)
|
---|
56 | {
|
---|
57 | Log(("VBoxGINA::hookDialogBoxes\n"));
|
---|
58 |
|
---|
59 | /* this is version dependent */
|
---|
60 | switch (dwWlxVersion)
|
---|
61 | {
|
---|
62 | case WLX_VERSION_1_0:
|
---|
63 | {
|
---|
64 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
65 | ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
66 | break;
|
---|
67 | }
|
---|
68 |
|
---|
69 | case WLX_VERSION_1_1:
|
---|
70 | {
|
---|
71 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
72 | ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
73 | break;
|
---|
74 | }
|
---|
75 |
|
---|
76 | case WLX_VERSION_1_2:
|
---|
77 | {
|
---|
78 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
79 | ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
80 | break;
|
---|
81 | }
|
---|
82 |
|
---|
83 | case WLX_VERSION_1_3:
|
---|
84 | {
|
---|
85 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
86 | ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
87 | break;
|
---|
88 | }
|
---|
89 |
|
---|
90 | case WLX_VERSION_1_4:
|
---|
91 | {
|
---|
92 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
93 | ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
94 | break;
|
---|
95 | }
|
---|
96 |
|
---|
97 | default:
|
---|
98 | {
|
---|
99 | Log(("VBoxGINA::hookDialogBoxes: unrecognized version '%d', nothing hooked!\n", dwWlxVersion));
|
---|
100 | /* not good, don't do anything */
|
---|
101 | break;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | //
|
---|
107 | // Redirected WlxLoggedOutSASDlgProc().
|
---|
108 | //
|
---|
109 |
|
---|
110 | #define CREDPOLL_TIMERID 0x1243
|
---|
111 |
|
---|
112 | BOOL credentialsToUI(HWND hwndUserId, HWND hwndPassword, HWND hwndDomain)
|
---|
113 | {
|
---|
114 | BOOL bIsFQDN = FALSE;
|
---|
115 | wchar_t szUserFQDN[512]; /* VMMDEV_CREDENTIALS_STRLEN + 255 bytes max. for FQDN */
|
---|
116 | if (hwndDomain)
|
---|
117 | {
|
---|
118 | /* search the domain combo box for our required domain and select it */
|
---|
119 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Trying to find domain entry in combo box ...\n"));
|
---|
120 | DWORD dwIndex = (DWORD) SendMessage(hwndDomain, CB_FINDSTRING,
|
---|
121 | 0, (LPARAM)g_Domain);
|
---|
122 | if (dwIndex != CB_ERR)
|
---|
123 | {
|
---|
124 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Found domain at combo box pos %ld\n", dwIndex));
|
---|
125 | SendMessage(hwndDomain, CB_SETCURSEL, (WPARAM) dwIndex, 0);
|
---|
126 | EnableWindow(hwndDomain, FALSE);
|
---|
127 | }
|
---|
128 | else
|
---|
129 | {
|
---|
130 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain not found in combo box ...\n"));
|
---|
131 |
|
---|
132 | /* If the domain value has a dot (.) in it, it is a FQDN (Fully Qualified Domain Name)
|
---|
133 | * which will not work with the combo box selection because Windows only keeps the
|
---|
134 | * NETBIOS names to the left most part of the domain name there. Of course a FQDN
|
---|
135 | * then will not be found by the search in the block above.
|
---|
136 | *
|
---|
137 | * To solve this problem the FQDN domain value will be appended at the user name value
|
---|
138 | * (Kerberos style) using an "@", e.g. "<user-name>@full.qualified.domain".
|
---|
139 | *
|
---|
140 | */
|
---|
141 | size_t l = wcslen(g_Domain);
|
---|
142 | if (l > 255)
|
---|
143 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Warning! FQDN is too long (max 255 bytes), will be truncated!\n"));
|
---|
144 |
|
---|
145 | if (wcslen(g_Username) > 0) /* We need a user name that we can use in caes of a FQDN */
|
---|
146 | {
|
---|
147 | if (l > 16) /* Domain name is longer than 16 chars, cannot be a NetBIOS name anymore */
|
---|
148 | {
|
---|
149 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain seems to be a FQDN (length)!\n"));
|
---|
150 | bIsFQDN = TRUE;
|
---|
151 | }
|
---|
152 | else if ( l > 0
|
---|
153 | && wcsstr(g_Domain, L".") != NULL) /* if we found a dot (.) in the domain name, this has to be a FQDN */
|
---|
154 | {
|
---|
155 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain seems to be a FQDN (dot)!\n"));
|
---|
156 | bIsFQDN = TRUE;
|
---|
157 | }
|
---|
158 |
|
---|
159 | if (bIsFQDN)
|
---|
160 | {
|
---|
161 | swprintf(szUserFQDN, sizeof(szUserFQDN) / sizeof(wchar_t), L"%s@%s", g_Username, g_Domain);
|
---|
162 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: FQDN user name is now: %s!\n", szUserFQDN));
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|
167 | if (hwndUserId)
|
---|
168 | {
|
---|
169 | if (!bIsFQDN)
|
---|
170 | SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)g_Username);
|
---|
171 | else
|
---|
172 | SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)szUserFQDN);
|
---|
173 | }
|
---|
174 | if (hwndPassword)
|
---|
175 | SendMessage(hwndPassword, WM_SETTEXT, 0, (LPARAM)g_Password);
|
---|
176 |
|
---|
177 | return TRUE;
|
---|
178 | }
|
---|
179 |
|
---|
180 | INT_PTR CALLBACK MyWlxLoggedOutSASDlgProc(HWND hwndDlg, // handle to dialog box
|
---|
181 | UINT uMsg, // message
|
---|
182 | WPARAM wParam, // first message parameter
|
---|
183 | LPARAM lParam) // second message parameter
|
---|
184 | {
|
---|
185 | BOOL bResult;
|
---|
186 | static HWND hwndUserId, hwndPassword, hwndDomain = 0;
|
---|
187 | static UINT_PTR timer = 0;
|
---|
188 |
|
---|
189 | /*Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc\n"));*/
|
---|
190 |
|
---|
191 | //
|
---|
192 | // Pass on to MSGINA first.
|
---|
193 | //
|
---|
194 | bResult = pfWlxLoggedOutSASDlgProc(hwndDlg, uMsg, wParam, lParam);
|
---|
195 |
|
---|
196 | //
|
---|
197 | // We are only interested in the WM_INITDIALOG message.
|
---|
198 | //
|
---|
199 | switch (uMsg)
|
---|
200 | {
|
---|
201 | case WM_INITDIALOG:
|
---|
202 | {
|
---|
203 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: got WM_INITDIALOG\n"));
|
---|
204 |
|
---|
205 | /* get the entry fields */
|
---|
206 | hwndUserId = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_USERNAME);
|
---|
207 | if (!hwndUserId)
|
---|
208 | hwndUserId = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_USERNAME2);
|
---|
209 | hwndPassword = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_PASSWORD);
|
---|
210 | if (!hwndPassword)
|
---|
211 | hwndPassword = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_PASSWORD2);
|
---|
212 | hwndDomain = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_DOMAIN);
|
---|
213 | if (!hwndDomain)
|
---|
214 | hwndDomain = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_DOMAIN2);
|
---|
215 |
|
---|
216 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: hwndUserId: %x, hwndPassword: %d, hwndDomain: %d\n",
|
---|
217 | hwndUserId, hwndPassword, hwndDomain));
|
---|
218 |
|
---|
219 | /* terminate the credentials poller thread, it's done is job */
|
---|
220 | credentialsPollerTerminate();
|
---|
221 |
|
---|
222 | if (credentialsAvailable())
|
---|
223 | {
|
---|
224 | /* query the credentials from VBox */
|
---|
225 | if (credentialsRetrieve())
|
---|
226 | {
|
---|
227 | /* fill in credentials to appropriate UI elements */
|
---|
228 | credentialsToUI(hwndUserId, hwndPassword, hwndDomain);
|
---|
229 |
|
---|
230 | /* we got the credentials, null them out */
|
---|
231 | credentialsReset();
|
---|
232 |
|
---|
233 | /* confirm the logon dialog, simulating the user pressing "OK" */
|
---|
234 | WPARAM wParam = MAKEWPARAM(IDOK, BN_CLICKED);
|
---|
235 | PostMessage(hwndDlg, WM_COMMAND, wParam, 0);
|
---|
236 | }
|
---|
237 | }
|
---|
238 | else
|
---|
239 | {
|
---|
240 | /*
|
---|
241 | * The dialog is there but we don't have any credentials.
|
---|
242 | * Create a timer and poll for them.
|
---|
243 | */
|
---|
244 | timer = SetTimer(hwndDlg, CREDPOLL_TIMERID, 200, NULL);
|
---|
245 | if (!timer)
|
---|
246 | {
|
---|
247 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: failed creating timer! last error: %s\n",
|
---|
248 | GetLastError()));
|
---|
249 | }
|
---|
250 | }
|
---|
251 | break;
|
---|
252 | }
|
---|
253 |
|
---|
254 | case WM_TIMER:
|
---|
255 | {
|
---|
256 | /* is it our credentials poller timer? */
|
---|
257 | if (wParam == CREDPOLL_TIMERID)
|
---|
258 | {
|
---|
259 | if (credentialsAvailable())
|
---|
260 | {
|
---|
261 | if (credentialsRetrieve())
|
---|
262 | {
|
---|
263 | /* fill in credentials to appropriate UI elements */
|
---|
264 | credentialsToUI(hwndUserId, hwndPassword, hwndDomain);
|
---|
265 |
|
---|
266 | /* we got the credentials, null them out */
|
---|
267 | credentialsReset();
|
---|
268 |
|
---|
269 | /* confirm the logon dialog, simulating the user pressing "OK" */
|
---|
270 | WPARAM wParam = MAKEWPARAM(IDOK, BN_CLICKED);
|
---|
271 | PostMessage(hwndDlg, WM_COMMAND, wParam, 0);
|
---|
272 |
|
---|
273 | /* we don't need the timer any longer */
|
---|
274 | /** @todo will we leak the timer when logging in manually? Should we kill it on WM_CLOSE? */
|
---|
275 | KillTimer(hwndDlg, CREDPOLL_TIMERID);
|
---|
276 | }
|
---|
277 | }
|
---|
278 | }
|
---|
279 | break;
|
---|
280 | }
|
---|
281 | }
|
---|
282 | return bResult;
|
---|
283 | }
|
---|
284 |
|
---|
285 |
|
---|
286 | int WINAPI MyWlxDialogBoxParam(HANDLE hWlx,
|
---|
287 | HANDLE hInst,
|
---|
288 | LPWSTR lpszTemplate,
|
---|
289 | HWND hwndOwner,
|
---|
290 | DLGPROC dlgprc,
|
---|
291 | LPARAM dwInitParam)
|
---|
292 | {
|
---|
293 | Log(("VBoxGINA::MyWlxDialogBoxParam: lpszTemplate = %d\n", lpszTemplate));
|
---|
294 |
|
---|
295 | //
|
---|
296 | // We only know MSGINA dialogs by identifiers.
|
---|
297 | //
|
---|
298 | if (!HIWORD((int)(void*)lpszTemplate))
|
---|
299 | {
|
---|
300 | //
|
---|
301 | // Hook appropriate dialog boxes as necessary.
|
---|
302 | //
|
---|
303 | switch ((DWORD) lpszTemplate)
|
---|
304 | {
|
---|
305 | case IDD_WLXLOGGEDOUTSAS_DIALOG:
|
---|
306 | case IDD_WLXLOGGEDOUTSAS_DIALOG2:
|
---|
307 | {
|
---|
308 | Log(("VBoxGINA::MyWlxDialogBoxParam: returning hooked logged out dialog\n"));
|
---|
309 | pfWlxLoggedOutSASDlgProc = dlgprc;
|
---|
310 | return pfWlxDialogBoxParam(hWlx, hInst, lpszTemplate, hwndOwner,
|
---|
311 | MyWlxLoggedOutSASDlgProc, dwInitParam);
|
---|
312 | }
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | //
|
---|
317 | // The rest will not be redirected.
|
---|
318 | //
|
---|
319 | return pfWlxDialogBoxParam(hWlx, hInst, lpszTemplate,
|
---|
320 | hwndOwner, dlgprc, dwInitParam);
|
---|
321 | }
|
---|