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 "Dialog.h"
|
---|
22 | #include "WinWlx.h"
|
---|
23 | #include "Helper.h"
|
---|
24 | #include "VBoxGINA.h"
|
---|
25 |
|
---|
26 | //
|
---|
27 | // MSGINA dialog box IDs.
|
---|
28 | //
|
---|
29 | #define IDD_WLXDIAPLAYSASNOTICE_DIALOG 1400
|
---|
30 | #define IDD_WLXLOGGEDOUTSAS_DIALOG 1450
|
---|
31 | /* the Windows 2000 ID */
|
---|
32 | #define IDD_WLXLOGGEDOUTSAS_DIALOG2 1500
|
---|
33 | #define IDD_CHANGE_PASSWORD_DIALOG 1550
|
---|
34 | #define IDD_WLXLOGGEDONSAS_DIALOG 1650
|
---|
35 | #define IDD_WLXWKSTALOCKEDSAS_DIALOG 1850
|
---|
36 |
|
---|
37 | //
|
---|
38 | // MSGINA control IDs
|
---|
39 | //
|
---|
40 | #define IDC_WLXLOGGEDOUTSAS_USERNAME 1453
|
---|
41 | #define IDC_WLXLOGGEDOUTSAS_USERNAME2 1502
|
---|
42 | #define IDC_WLXLOGGEDOUTSAS_PASSWORD 1454
|
---|
43 | #define IDC_WLXLOGGEDOUTSAS_PASSWORD2 1503
|
---|
44 | #define IDC_WLXLOGGEDOUTSAS_DOMAIN 1455
|
---|
45 | #define IDC_WLXLOGGEDOUTSAS_DOMAIN2 1504
|
---|
46 | #define IDC_WLXWKSTALOCKEDSAS_DOMAIN 1856
|
---|
47 |
|
---|
48 | static DLGPROC pfWlxLoggedOutSASDlgProc = NULL;
|
---|
49 |
|
---|
50 | static PWLX_DIALOG_BOX_PARAM pfWlxDialogBoxParam = NULL;
|
---|
51 |
|
---|
52 | int WINAPI MyWlxDialogBoxParam (HANDLE, HANDLE, LPWSTR, HWND, DLGPROC, LPARAM);
|
---|
53 |
|
---|
54 | void hookDialogBoxes(PVOID pWinlogonFunctions, DWORD dwWlxVersion)
|
---|
55 | {
|
---|
56 | Log(("VBoxGINA::hookDialogBoxes\n"));
|
---|
57 |
|
---|
58 | /* this is version dependent */
|
---|
59 | switch (dwWlxVersion)
|
---|
60 | {
|
---|
61 | case WLX_VERSION_1_0:
|
---|
62 | {
|
---|
63 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
64 | ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
65 | break;
|
---|
66 | }
|
---|
67 |
|
---|
68 | case WLX_VERSION_1_1:
|
---|
69 | {
|
---|
70 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
71 | ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
72 | break;
|
---|
73 | }
|
---|
74 |
|
---|
75 | case WLX_VERSION_1_2:
|
---|
76 | {
|
---|
77 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
78 | ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
79 | break;
|
---|
80 | }
|
---|
81 |
|
---|
82 | case WLX_VERSION_1_3:
|
---|
83 | {
|
---|
84 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
85 | ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
86 | break;
|
---|
87 | }
|
---|
88 |
|
---|
89 | case WLX_VERSION_1_4:
|
---|
90 | {
|
---|
91 | pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
92 | ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
93 | break;
|
---|
94 | }
|
---|
95 |
|
---|
96 | default:
|
---|
97 | {
|
---|
98 | Log(("VBoxGINA::hookDialogBoxes: unrecognized version '%d', nothing hooked!\n", dwWlxVersion));
|
---|
99 | /* not good, don't do anything */
|
---|
100 | break;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | //
|
---|
106 | // Redirected WlxLoggedOutSASDlgProc().
|
---|
107 | //
|
---|
108 |
|
---|
109 | #define CREDPOLL_TIMERID 0x1243
|
---|
110 |
|
---|
111 | INT_PTR CALLBACK MyWlxLoggedOutSASDlgProc(HWND hwndDlg, // handle to dialog box
|
---|
112 | UINT uMsg, // message
|
---|
113 | WPARAM wParam, // first message parameter
|
---|
114 | LPARAM lParam) // second message parameter
|
---|
115 | {
|
---|
116 | BOOL bResult;
|
---|
117 | static HWND hwndUserId, hwndPassword, hwndDomain = 0;
|
---|
118 | static UINT_PTR timer = 0;
|
---|
119 |
|
---|
120 | /*Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc\n"));*/
|
---|
121 |
|
---|
122 | //
|
---|
123 | // Pass on to MSGINA first.
|
---|
124 | //
|
---|
125 | bResult = pfWlxLoggedOutSASDlgProc(hwndDlg, uMsg, wParam, lParam);
|
---|
126 |
|
---|
127 | //
|
---|
128 | // We are only interested in the WM_INITDIALOG message.
|
---|
129 | //
|
---|
130 | switch (uMsg)
|
---|
131 | {
|
---|
132 | case WM_INITDIALOG:
|
---|
133 | {
|
---|
134 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: got WM_INITDIALOG\n"));
|
---|
135 |
|
---|
136 | /* get the entry fields */
|
---|
137 | hwndUserId = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_USERNAME);
|
---|
138 | if (!hwndUserId)
|
---|
139 | hwndUserId = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_USERNAME2);
|
---|
140 | hwndPassword = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_PASSWORD);
|
---|
141 | if (!hwndPassword)
|
---|
142 | hwndPassword = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_PASSWORD2);
|
---|
143 | hwndDomain = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_DOMAIN);
|
---|
144 | if (!hwndDomain)
|
---|
145 | hwndDomain = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_DOMAIN2);
|
---|
146 |
|
---|
147 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: hwndUserId: %x, hwndPassword: %d, hwndDomain: %d\n",
|
---|
148 | hwndUserId, hwndPassword, hwndDomain));
|
---|
149 |
|
---|
150 | /* terminate the credentials poller thread, it's done is job */
|
---|
151 | credentialsPollerTerminate();
|
---|
152 |
|
---|
153 | if (credentialsAvailable())
|
---|
154 | {
|
---|
155 | /* query the credentials from VBox */
|
---|
156 | if (credentialsRetrieve())
|
---|
157 | {
|
---|
158 | if (hwndUserId)
|
---|
159 | SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)g_Username);
|
---|
160 | if (hwndPassword)
|
---|
161 | SendMessage(hwndPassword, WM_SETTEXT, 0, (LPARAM)g_Password);
|
---|
162 | if (hwndDomain)
|
---|
163 | {
|
---|
164 | /* search the domain combo box for our required domain and select it */
|
---|
165 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Find domain entry ...\n"));
|
---|
166 | DWORD dwIndex = (DWORD) SendMessage(hwndDomain, CB_FINDSTRING,
|
---|
167 | 0, (LPARAM)g_Domain);
|
---|
168 | if (dwIndex != CB_ERR)
|
---|
169 | {
|
---|
170 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Found domain at pos %ld\n", dwIndex));
|
---|
171 | SendMessage(hwndDomain, CB_SETCURSEL, (WPARAM) dwIndex, 0);
|
---|
172 | EnableWindow(hwndDomain, FALSE);
|
---|
173 | }
|
---|
174 | else Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain entry not found!"));
|
---|
175 | }
|
---|
176 |
|
---|
177 | /* we got the credentials, null them out */
|
---|
178 | credentialsReset();
|
---|
179 |
|
---|
180 | /* confirm the logon dialog, simulating the user pressing "OK" */
|
---|
181 | WPARAM wParam = MAKEWPARAM(IDOK, BN_CLICKED);
|
---|
182 | PostMessage(hwndDlg, WM_COMMAND, wParam, 0);
|
---|
183 | }
|
---|
184 | }
|
---|
185 | else
|
---|
186 | {
|
---|
187 | /*
|
---|
188 | * The dialog is there but we don't have any credentials.
|
---|
189 | * Create a timer and poll for them.
|
---|
190 | */
|
---|
191 | timer = SetTimer(hwndDlg, CREDPOLL_TIMERID, 200, NULL);
|
---|
192 | if (!timer)
|
---|
193 | {
|
---|
194 | Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: failed creating timer! last error: %s\n",
|
---|
195 | GetLastError()));
|
---|
196 | }
|
---|
197 | }
|
---|
198 | break;
|
---|
199 | }
|
---|
200 |
|
---|
201 | case WM_TIMER:
|
---|
202 | {
|
---|
203 | /* is it our credentials poller timer? */
|
---|
204 | if (wParam == CREDPOLL_TIMERID)
|
---|
205 | {
|
---|
206 | if (credentialsAvailable())
|
---|
207 | {
|
---|
208 | if (credentialsRetrieve())
|
---|
209 | {
|
---|
210 | if (hwndUserId)
|
---|
211 | SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)g_Username);
|
---|
212 | if (hwndPassword)
|
---|
213 | SendMessage(hwndPassword, WM_SETTEXT, 0, (LPARAM)g_Password);
|
---|
214 | if (hwndDomain)
|
---|
215 | SendMessage(hwndDomain, WM_SETTEXT, 0, (LPARAM)g_Domain);
|
---|
216 |
|
---|
217 | /* we got the credentials, null them out */
|
---|
218 | credentialsReset();
|
---|
219 |
|
---|
220 | /* confirm the logon dialog, simulating the user pressing "OK" */
|
---|
221 | WPARAM wParam = MAKEWPARAM(IDOK, BN_CLICKED);
|
---|
222 | PostMessage(hwndDlg, WM_COMMAND, wParam, 0);
|
---|
223 |
|
---|
224 | /* we don't need the timer any longer */
|
---|
225 | /** @todo will we leak the timer when logging in manually? Should we kill it on WM_CLOSE? */
|
---|
226 | KillTimer(hwndDlg, CREDPOLL_TIMERID);
|
---|
227 | }
|
---|
228 | }
|
---|
229 | }
|
---|
230 | break;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | return bResult;
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | int WINAPI MyWlxDialogBoxParam(HANDLE hWlx,
|
---|
238 | HANDLE hInst,
|
---|
239 | LPWSTR lpszTemplate,
|
---|
240 | HWND hwndOwner,
|
---|
241 | DLGPROC dlgprc,
|
---|
242 | LPARAM dwInitParam)
|
---|
243 | {
|
---|
244 | Log(("VBoxGINA::MyWlxDialogBoxParam: lpszTemplate = %d\n", lpszTemplate));
|
---|
245 |
|
---|
246 | //
|
---|
247 | // We only know MSGINA dialogs by identifiers.
|
---|
248 | //
|
---|
249 | if (!HIWORD((int)(void*)lpszTemplate))
|
---|
250 | {
|
---|
251 | //
|
---|
252 | // Hook appropriate dialog boxes as necessary.
|
---|
253 | //
|
---|
254 | switch ((DWORD) lpszTemplate)
|
---|
255 | {
|
---|
256 | case IDD_WLXLOGGEDOUTSAS_DIALOG:
|
---|
257 | case IDD_WLXLOGGEDOUTSAS_DIALOG2:
|
---|
258 | {
|
---|
259 | Log(("VBoxGINA::MyWlxDialogBoxParam: returning hooked logged out dialog\n"));
|
---|
260 | pfWlxLoggedOutSASDlgProc = dlgprc;
|
---|
261 | return pfWlxDialogBoxParam(hWlx, hInst, lpszTemplate, hwndOwner,
|
---|
262 | MyWlxLoggedOutSASDlgProc, dwInitParam);
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | //
|
---|
268 | // The rest will not be redirected.
|
---|
269 | //
|
---|
270 | return pfWlxDialogBoxParam(hWlx, hInst, lpszTemplate,
|
---|
271 | hwndOwner, dlgprc, dwInitParam);
|
---|
272 | }
|
---|