VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxGINA/Dialog.cpp@ 30829

Last change on this file since 30829 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette