VirtualBox

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

Last change on this file since 4071 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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