VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/** @file
2 *
3 * VBoxGINA -- Windows Logon DLL for VirtualBox Dialog Code
4 *
5 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
11 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
12 * distribution. VirtualBox OSE is distributed in the hope that it will
13 * be useful, but WITHOUT ANY WARRANTY of any kind.
14 *
15 * If you received this file as part of a commercial VirtualBox
16 * distribution, then only the terms of your commercial VirtualBox
17 * license agreement apply instead of the previous paragraph.
18 *
19 */
20
21#include <windows.h>
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_PASSWORD 1454
43#define IDC_WLXLOGGEDOUTSAS_DOMAIN 1455
44#define IDC_WLXWKSTALOCKEDSAS_DOMAIN 1856
45
46static DLGPROC pfWlxLoggedOutSASDlgProc = NULL;
47
48static PWLX_DIALOG_BOX_PARAM pfWlxDialogBoxParam = NULL;
49
50int WINAPI MyWlxDialogBoxParam (HANDLE, HANDLE, LPWSTR, HWND, DLGPROC, LPARAM);
51
52void hookDialogBoxes(PVOID pWinlogonFunctions, DWORD dwWlxVersion)
53{
54 Log(("VBoxGINA::hookDialogBoxes\n"));
55
56 /* this is version dependent */
57 switch (dwWlxVersion)
58 {
59 case WLX_VERSION_1_0:
60 {
61 pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam;
62 ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
63 break;
64 }
65
66 case WLX_VERSION_1_1:
67 {
68 pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam;
69 ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
70 break;
71 }
72
73 case WLX_VERSION_1_2:
74 {
75 pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam;
76 ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
77 break;
78 }
79
80 case WLX_VERSION_1_3:
81 {
82 pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam;
83 ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
84 break;
85 }
86
87 case WLX_VERSION_1_4:
88 {
89 pfWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam;
90 ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
91 break;
92 }
93
94 default:
95 {
96 Log(("VBoxGINA::hookDialogBoxes: unrecognized version '%d', nothing hooked!\n", dwWlxVersion));
97 /* not good, don't do anything */
98 break;
99 }
100 }
101}
102
103//
104// Redirected WlxLoggedOutSASDlgProc().
105//
106
107#define CREDPOLL_TIMERID 0x1243
108
109BOOL CALLBACK MyWlxLoggedOutSASDlgProc(HWND hwndDlg, // handle to dialog box
110 UINT uMsg, // message
111 WPARAM wParam, // first message parameter
112 LPARAM lParam) // second message parameter
113{
114 BOOL bResult;
115 static HWND hwndUserId, hwndPassword, hwndDomain = 0;
116 static UINT_PTR timer = 0;
117
118 Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc\n"));
119
120 //
121 // Pass on to MSGINA first.
122 //
123 bResult = pfWlxLoggedOutSASDlgProc(hwndDlg, uMsg, wParam, lParam);
124
125 //
126 // We are only interested in the WM_INITDIALOG message.
127 //
128 switch (uMsg)
129 {
130 case WM_INITDIALOG:
131 {
132 Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: got WM_INITDIALOG\n"));
133
134 /* get the entry fields */
135 hwndUserId = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_USERNAME);
136 hwndPassword = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_PASSWORD);
137 hwndDomain = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_DOMAIN);
138
139 Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: hwndUserId: %x, hwndPassword: %d, hwndDomain: %d\n",
140 hwndUserId, hwndPassword, hwndDomain));
141
142 /* terminate the credentials poller thread, it's done is job */
143 credentialsPollerTerminate();
144
145 if (credentialsAvailable())
146 {
147 /* query the credentials from VBox */
148 if (credentialsRetrieve())
149 {
150 if (hwndUserId)
151 SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)g_Username);
152 if (hwndPassword)
153 SendMessage(hwndPassword, WM_SETTEXT, 0, (LPARAM)g_Password);
154 if (hwndDomain)
155 SendMessage(hwndDomain, WM_SETTEXT, 0, (LPARAM)g_Domain);
156
157 /* we got the credentials, null them out */
158 credentialsReset();
159
160 /* confirm the logon dialog, simulating the user pressing "OK" */
161 WPARAM wParam = MAKEWPARAM(IDOK, BN_CLICKED);
162 PostMessage(hwndDlg, WM_COMMAND, wParam, 0);
163 }
164 }
165 else
166 {
167 /*
168 * The dialog is there but we don't have any credentials.
169 * Create a timer and poll for them.
170 */
171 timer = SetTimer(hwndDlg, CREDPOLL_TIMERID, 200, NULL);
172 if (!timer)
173 {
174 Log(("VBoxGINA::MyWlxLoggedOutSASDlgProc: failed creating timer! last error: %s\n",
175 GetLastError()));
176 }
177 }
178 break;
179 }
180
181 case WM_TIMER:
182 {
183 /* is it our credentials poller timer? */
184 if (wParam == CREDPOLL_TIMERID)
185 {
186 if (credentialsAvailable())
187 {
188 if (credentialsRetrieve())
189 {
190 if (hwndUserId)
191 SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)g_Username);
192 if (hwndPassword)
193 SendMessage(hwndPassword, WM_SETTEXT, 0, (LPARAM)g_Password);
194 if (hwndDomain)
195 SendMessage(hwndDomain, WM_SETTEXT, 0, (LPARAM)g_Domain);
196
197 /* we got the credentials, null them out */
198 credentialsReset();
199
200 /* confirm the logon dialog, simulating the user pressing "OK" */
201 WPARAM wParam = MAKEWPARAM(IDOK, BN_CLICKED);
202 PostMessage(hwndDlg, WM_COMMAND, wParam, 0);
203
204 /* we don't need the timer any longer */
205 /** @todo will we leak the timer when logging in manually? Should we kill it on WM_CLOSE? */
206 KillTimer(hwndDlg, CREDPOLL_TIMERID);
207 }
208 }
209 }
210 break;
211 }
212 }
213 return bResult;
214}
215
216
217int WINAPI MyWlxDialogBoxParam(HANDLE hWlx,
218 HANDLE hInst,
219 LPWSTR lpszTemplate,
220 HWND hwndOwner,
221 DLGPROC dlgprc,
222 LPARAM dwInitParam)
223{
224 Log(("VBoxGINA::MyWlxDialogBoxParam: lpszTemplate = %d\n", lpszTemplate));
225
226 //
227 // We only know MSGINA dialogs by identifiers.
228 //
229 if (!HIWORD((int)(void*)lpszTemplate))
230 {
231 //
232 // Hook appropriate dialog boxes as necessary.
233 //
234 switch ((DWORD) lpszTemplate)
235 {
236 case IDD_WLXLOGGEDOUTSAS_DIALOG:
237 case IDD_WLXLOGGEDOUTSAS_DIALOG2:
238 {
239 Log(("VBoxGINA::MyWlxDialogBoxParam: returning hooked logged out dialog\n"));
240 pfWlxLoggedOutSASDlgProc = dlgprc;
241 return pfWlxDialogBoxParam(hWlx, hInst, lpszTemplate, hwndOwner,
242 MyWlxLoggedOutSASDlgProc, dwInitParam);
243 }
244
245 }
246 }
247
248 //
249 // The rest will not be redirected.
250 //
251 return pfWlxDialogBoxParam(hWlx, hInst, lpszTemplate,
252 hwndOwner, dlgprc, dwInitParam);
253}
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