VirtualBox

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

Last change on this file since 36258 was 36258, checked in by vboxsync, 14 years ago

VBoxGINA: Added support for locked workstations.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.9 KB
Line 
1/** @file
2 *
3 * VBoxGINA -- Windows Logon DLL for VirtualBox
4 *
5 * Copyright (C) 2006-2011 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 <stdio.h>
17#include <stdlib.h>
18#include <windows.h>
19#include "winwlx.h"
20#include "VBoxGINA.h"
21#include "Helper.h"
22#include "Dialog.h"
23#include <VBox/VBoxGuestLib.h>
24
25/*
26 * Global variables.
27 */
28
29/** DLL instance handle. */
30HINSTANCE hDllInstance;
31
32/** Version of Winlogon. */
33DWORD wlxVersion;
34
35/** Handle to Winlogon service. */
36HANDLE hGinaWlx;
37/** Winlog function dispatch table. */
38PWLX_DISPATCH_VERSION_1_1 pWlxFuncs;
39
40/**
41 * Function pointers to MSGINA entry points.
42 */
43PGWLXNEGOTIATE GWlxNegotiate;
44PGWLXINITIALIZE GWlxInitialize;
45PGWLXDISPLAYSASNOTICE GWlxDisplaySASNotice;
46PGWLXLOGGEDOUTSAS GWlxLoggedOutSAS;
47PGWLXACTIVATEUSERSHELL GWlxActivateUserShell;
48PGWLXLOGGEDONSAS GWlxLoggedOnSAS;
49PGWLXDISPLAYLOCKEDNOTICE GWlxDisplayLockedNotice;
50PGWLXWKSTALOCKEDSAS GWlxWkstaLockedSAS;
51PGWLXISLOCKOK GWlxIsLockOk;
52PGWLXISLOGOFFOK GWlxIsLogoffOk;
53PGWLXLOGOFF GWlxLogoff;
54PGWLXSHUTDOWN GWlxShutdown;
55/* GINA 1.1. */
56PGWLXSTARTAPPLICATION GWlxStartApplication;
57PGWLXSCREENSAVERNOTIFY GWlxScreenSaverNotify;
58/* GINA 1.3. */
59PGWLXNETWORKPROVIDERLOAD GWlxNetworkProviderLoad;
60PGWLXDISPLAYSTATUSMESSAGE GWlxDisplayStatusMessage;
61PGWLXGETSTATUSMESSAGE GWlxGetStatusMessage;
62PGWLXREMOVESTATUSMESSAGE GWlxRemoveStatusMessage;
63/* GINA 1.4. */
64PGWLXGETCONSOLESWITCHCREDENTIALS GWlxGetConsoleSwitchCredentials;
65PGWLXRECONNECTNOTIFY GWlxReconnectNotify;
66PGWLXDISCONNECTNOTIFY GWlxDisconnectNotify;
67
68
69/**
70 * DLL entry point.
71 */
72BOOL WINAPI DllMain(HINSTANCE hInstance,
73 DWORD dwReason,
74 LPVOID lpReserved)
75{
76 switch (dwReason)
77 {
78 case DLL_PROCESS_ATTACH:
79 {
80 RTR3Init();
81 VbglR3Init();
82 LogRel(("VBoxGINA: DLL loaded.\n"));
83
84 DisableThreadLibraryCalls(hInstance);
85 hDllInstance = hInstance;
86 break;
87 }
88
89 case DLL_PROCESS_DETACH:
90 {
91 LogRel(("VBoxGINA: DLL unloaded.\n"));
92 VbglR3Term();
93 /// @todo RTR3Term();
94 break;
95 }
96
97 default:
98 break;
99 }
100 return TRUE;
101}
102
103
104BOOL WINAPI WlxNegotiate(DWORD dwWinlogonVersion,
105 DWORD *pdwDllVersion)
106{
107 HINSTANCE hDll;
108
109#ifdef DEBUG
110 /* enable full log output */
111 RTLogGroupSettings(RTLogDefaultInstance(), "all=~0");
112#endif
113
114 Log(("VBoxGINA::WlxNegotiate: dwWinlogonVersion: %d\n", dwWinlogonVersion));
115
116 /* load the standard Microsoft GINA DLL */
117 if (!(hDll = LoadLibrary(TEXT("MSGINA.DLL"))))
118 {
119 Log(("VBoxGINA::WlxNegotiate: failed loading MSGINA! last error = %d\n", GetLastError()));
120 return FALSE;
121 }
122
123 /*
124 * Now get the entry points of the MSGINA
125 */
126 GWlxNegotiate = (PGWLXNEGOTIATE)GetProcAddress(hDll, "WlxNegotiate");
127 if (!GWlxNegotiate)
128 {
129 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxNegotiate\n"));
130 return FALSE;
131 }
132 GWlxInitialize = (PGWLXINITIALIZE)GetProcAddress(hDll, "WlxInitialize");
133 if (!GWlxInitialize)
134 {
135 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxInitialize\n"));
136 return FALSE;
137 }
138 GWlxDisplaySASNotice =
139 (PGWLXDISPLAYSASNOTICE)GetProcAddress(hDll, "WlxDisplaySASNotice");
140 if (!GWlxDisplaySASNotice)
141 {
142 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxDisplaySASNotice\n"));
143 return FALSE;
144 }
145 GWlxLoggedOutSAS =
146 (PGWLXLOGGEDOUTSAS)GetProcAddress(hDll, "WlxLoggedOutSAS");
147 if (!GWlxLoggedOutSAS)
148 {
149 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxLoggedOutSAS\n"));
150 return FALSE;
151 }
152 GWlxActivateUserShell =
153 (PGWLXACTIVATEUSERSHELL)GetProcAddress(hDll, "WlxActivateUserShell");
154 if (!GWlxActivateUserShell)
155 {
156 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxActivateUserShell\n"));
157 return FALSE;
158 }
159 GWlxLoggedOnSAS =
160 (PGWLXLOGGEDONSAS)GetProcAddress(hDll, "WlxLoggedOnSAS");
161 if (!GWlxLoggedOnSAS)
162 {
163 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxLoggedOnSAS\n"));
164 return FALSE;
165 }
166 GWlxDisplayLockedNotice =
167 (PGWLXDISPLAYLOCKEDNOTICE)GetProcAddress(hDll, "WlxDisplayLockedNotice");
168 if (!GWlxDisplayLockedNotice)
169 {
170 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxDisplayLockedNotice\n"));
171 return FALSE;
172 }
173 GWlxIsLockOk = (PGWLXISLOCKOK)GetProcAddress(hDll, "WlxIsLockOk");
174 if (!GWlxIsLockOk)
175 {
176 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxIsLockOk\n"));
177 return FALSE;
178 }
179 GWlxWkstaLockedSAS =
180 (PGWLXWKSTALOCKEDSAS)GetProcAddress(hDll, "WlxWkstaLockedSAS");
181 if (!GWlxWkstaLockedSAS)
182 {
183 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxWkstaLockedSAS\n"));
184 return FALSE;
185 }
186 GWlxIsLogoffOk = (PGWLXISLOGOFFOK)GetProcAddress(hDll, "WlxIsLogoffOk");
187 if (!GWlxIsLogoffOk)
188 {
189 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxIsLogoffOk\n"));
190 return FALSE;
191 }
192 GWlxLogoff = (PGWLXLOGOFF)GetProcAddress(hDll, "WlxLogoff");
193 if (!GWlxLogoff)
194 {
195 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxLogoff\n"));
196 return FALSE;
197 }
198 GWlxShutdown = (PGWLXSHUTDOWN)GetProcAddress(hDll, "WlxShutdown");
199 if (!GWlxShutdown)
200 {
201 Log(("VBoxGINA::WlxNegotiate: failed resolving WlxShutdown\n"));
202 return FALSE;
203 }
204 /* GINA 1.1, optional */
205 GWlxStartApplication = (PGWLXSTARTAPPLICATION)GetProcAddress(hDll, "WlxStartApplication");
206 GWlxScreenSaverNotify = (PGWLXSCREENSAVERNOTIFY)GetProcAddress(hDll, "WlxScreenSaverNotify");
207 /* GINA 1.3, optional */
208 GWlxNetworkProviderLoad = (PGWLXNETWORKPROVIDERLOAD)GetProcAddress( hDll, "WlxNetworkProviderLoad");
209 GWlxDisplayStatusMessage = (PGWLXDISPLAYSTATUSMESSAGE)GetProcAddress( hDll, "WlxDisplayStatusMessage");
210 GWlxGetStatusMessage = (PGWLXGETSTATUSMESSAGE)GetProcAddress( hDll, "WlxGetStatusMessage");
211 GWlxRemoveStatusMessage = (PGWLXREMOVESTATUSMESSAGE)GetProcAddress( hDll, "WlxRemoveStatusMessage");
212 /* GINA 1.4, optional */
213 GWlxGetConsoleSwitchCredentials =
214 (PGWLXGETCONSOLESWITCHCREDENTIALS)GetProcAddress(hDll, "WlxGetConsoleSwitchCredentials");
215 GWlxReconnectNotify = (PGWLXRECONNECTNOTIFY)GetProcAddress(hDll, "WlxReconnectNotify");
216 GWlxDisconnectNotify = (PGWLXDISCONNECTNOTIFY)GetProcAddress(hDll, "WlxDisconnectNotify");
217 Log(("VBoxGINA::WlxNegotiate: optional function pointers:\n"
218 " WlxStartApplication: %p\n"
219 " WlxScreenSaverNotify: %p\n"
220 " WlxNetworkProviderLoad: %p\n"
221 " WlxDisplayStatusMessage: %p\n"
222 " WlxGetStatusMessage: %p\n"
223 " WlxRemoveStatusMessage: %p\n"
224 " WlxGetConsoleSwitchCredentials: %p\n"
225 " WlxReconnectNotify: %p\n"
226 " WlxDisconnectNotify: %p\n",
227 GWlxStartApplication, GWlxScreenSaverNotify, GWlxNetworkProviderLoad,
228 GWlxDisplayStatusMessage, GWlxGetStatusMessage, GWlxRemoveStatusMessage,
229 GWlxGetConsoleSwitchCredentials, GWlxReconnectNotify, GWlxDisconnectNotify));
230
231 wlxVersion = dwWinlogonVersion;
232
233 /* forward call */
234 return GWlxNegotiate(dwWinlogonVersion, pdwDllVersion);
235}
236
237
238BOOL WINAPI WlxInitialize(LPWSTR lpWinsta, HANDLE hWlx, PVOID pvReserved,
239 PVOID pWinlogonFunctions, PVOID *pWlxContext)
240{
241 Log(("VBoxGINA::WlxInitialize\n"));
242
243 /* store Winlogon function table */
244 pWlxFuncs = (PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions;
245
246 /* store handle to Winlogon service*/
247 hGinaWlx = hWlx;
248
249 /* hook the dialogs */
250 hookDialogBoxes(pWlxFuncs, wlxVersion);
251
252 /* forward call */
253 return GWlxInitialize(lpWinsta, hWlx, pvReserved, pWinlogonFunctions, pWlxContext);
254}
255
256
257VOID WINAPI WlxDisplaySASNotice(PVOID pWlxContext)
258{
259 Log(("VBoxGINA::WlxDisplaySASNotice\n"));
260
261 /* check if there are credentials for us, if so simulate C-A-D */
262 if (credentialsAvailable())
263 {
264 Log(("VBoxGINA::WlxDisplaySASNotice: simulating C-A-D\n"));
265 /* automatic C-A-D */
266 pWlxFuncs->WlxSasNotify(hGinaWlx, WLX_SAS_TYPE_CTRL_ALT_DEL);
267 }
268 else
269 {
270 Log(("VBoxGINA::WlxDisplaySASNotice: starting credentials poller\n"));
271 /* start the credentials poller thread */
272 credentialsPollerCreate();
273 /* Forward call to MSGINA. */
274 GWlxDisplaySASNotice(pWlxContext);
275 }
276}
277
278
279int WINAPI WlxLoggedOutSAS(PVOID pWlxContext, DWORD dwSasType, PLUID pAuthenticationId,
280 PSID pLogonSid, PDWORD pdwOptions, PHANDLE phToken,
281 PWLX_MPR_NOTIFY_INFO pMprNotifyInfo, PVOID *pProfile)
282{
283 Log(("VBoxGINA::WlxLoggedOutSAS\n"));
284
285 /* when performing a direct logon without C-A-D, our poller might not be running */
286 if (!credentialsAvailable())
287 credentialsPollerCreate();
288
289 int iRet;
290 iRet = GWlxLoggedOutSAS(pWlxContext, dwSasType, pAuthenticationId, pLogonSid,
291 pdwOptions, phToken, pMprNotifyInfo, pProfile);
292
293 if (iRet == WLX_SAS_ACTION_LOGON)
294 {
295 //
296 // copy pMprNotifyInfo and pLogonSid for later use
297 //
298
299 // pMprNotifyInfo->pszUserName
300 // pMprNotifyInfo->pszDomain
301 // pMprNotifyInfo->pszPassword
302 // pMprNotifyInfo->pszOldPassword
303 }
304
305 return iRet;
306}
307
308
309BOOL WINAPI WlxActivateUserShell(PVOID pWlxContext, PWSTR pszDesktopName,
310 PWSTR pszMprLogonScript, PVOID pEnvironment)
311{
312 Log(("VBoxGINA::WlxActivateUserShell\n"));
313
314 /* Forward call to MSGINA. */
315 return GWlxActivateUserShell(pWlxContext, pszDesktopName, pszMprLogonScript, pEnvironment);
316}
317
318
319int WINAPI WlxLoggedOnSAS(PVOID pWlxContext, DWORD dwSasType, PVOID pReserved)
320{
321 Log(("VBoxGINA::WlxLoggedOnSAS: SaSType = %ld\n", dwSasType));
322
323 /*
324 * We don't want to do anything special here since the OS should behave
325 * as VBoxGINA wouldn't have been installed. So pass all calls down
326 * to the original MSGINA.
327 */
328
329 /* Forward call to MSGINA. */
330 Log(("VBoxGINA::WlxLoggedOnSAS: Forwarding call to MSGINA ...\n"));
331 return GWlxLoggedOnSAS(pWlxContext, dwSasType, pReserved);
332}
333
334VOID WINAPI WlxDisplayLockedNotice(PVOID pWlxContext)
335{
336 Log(("VBoxGINA::WlxDisplayLockedNotice\n"));
337 /* Forward call to MSGINA. */
338 GWlxDisplayLockedNotice(pWlxContext);
339}
340
341
342BOOL WINAPI WlxIsLockOk(PVOID pWlxContext)
343{
344 Log(("VBoxGINA::WlxIsLockOk\n"));
345 /* Forward call to MSGINA. */
346 return GWlxIsLockOk(pWlxContext);
347}
348
349int WINAPI WlxWkstaLockedSAS(PVOID pWlxContext, DWORD dwSasType)
350{
351 Log(("VBoxGINA::WlxWkstaLockedSAS\n"));
352
353 /* when performing a direct logon without C-A-D, our poller might not be running */
354 if (!credentialsAvailable())
355 credentialsPollerCreate();
356
357 /* Forward call to MSGINA. */
358 return GWlxWkstaLockedSAS(pWlxContext, dwSasType);
359}
360
361BOOL WINAPI WlxIsLogoffOk(PVOID pWlxContext)
362{
363 BOOL bSuccess;
364
365 Log(("VBoxGINA::WlxIsLogoffOk\n"));
366
367 bSuccess = GWlxIsLogoffOk(pWlxContext);
368
369 if (bSuccess)
370 {
371 //
372 // if it's ok to logoff, finish with the stored credentials
373 // and scrub the buffers
374 //
375 credentialsReset();
376
377 }
378 return bSuccess;
379}
380
381
382VOID WINAPI WlxLogoff(PVOID pWlxContext)
383{
384 Log(("VBoxGINA::WlxLogoff\n"));
385
386 /* Forward call to MSGINA. */
387 GWlxLogoff(pWlxContext);
388}
389
390
391VOID WINAPI WlxShutdown(PVOID pWlxContext, DWORD ShutdownType)
392{
393 Log(("VBoxGINA::WlxShutdown\n"));
394
395 /* Forward call to MSGINA. */
396 GWlxShutdown(pWlxContext, ShutdownType);
397}
398
399
400/*
401 * GINA 1.1 entry points
402 */
403BOOL WINAPI WlxScreenSaverNotify(PVOID pWlxContext, BOOL *pSecure)
404{
405 Log(("VBoxGINA::WlxScreenSaverNotify\n"));
406
407 /* Forward to MSGINA if present. */
408 if (GWlxScreenSaverNotify)
409 return GWlxScreenSaverNotify(pWlxContext, pSecure);
410 /* return something intelligent */
411 *pSecure = TRUE;
412 return TRUE;
413}
414
415
416BOOL WINAPI WlxStartApplication(PVOID pWlxContext, PWSTR pszDesktopName,
417 PVOID pEnvironment, PWSTR pszCmdLine)
418{
419 Log(("VBoxGINA::WlxStartApplication: pWlxCtx=%p, pszDesktopName=%ls, pEnvironment=%p, pszCmdLine=%ls\n",
420 pWlxContext, pszDesktopName, pEnvironment, pszCmdLine));
421
422 /* Forward to MSGINA if present. */
423 if (GWlxStartApplication)
424 return GWlxStartApplication(pWlxContext, pszDesktopName, pEnvironment, pszCmdLine);
425 return FALSE;
426}
427
428
429/*
430 * GINA 1.3 entry points
431 */
432BOOL WINAPI WlxNetworkProviderLoad (PVOID pWlxContext, PWLX_MPR_NOTIFY_INFO pNprNotifyInfo)
433{
434 Log(("VBoxGINA::WlxNetworkProviderLoad\n"));
435
436 /* Forward to MSGINA if present. */
437 if (GWlxNetworkProviderLoad)
438 return GWlxNetworkProviderLoad(pWlxContext, pNprNotifyInfo);
439 return FALSE;
440}
441
442
443BOOL WINAPI WlxDisplayStatusMessage(PVOID pWlxContext, HDESK hDesktop, DWORD dwOptions,
444 PWSTR pTitle, PWSTR pMessage)
445{
446 Log(("VBoxGINA::WlxDisplayStatusMessage\n"));
447
448 /* Forward to MSGINA if present. */
449 if (GWlxDisplayStatusMessage)
450 return GWlxDisplayStatusMessage(pWlxContext, hDesktop, dwOptions, pTitle, pMessage);
451 return FALSE;
452}
453
454
455BOOL WINAPI WlxGetStatusMessage(PVOID pWlxContext, DWORD *pdwOptions,
456 PWSTR pMessage, DWORD dwBufferSize)
457{
458 Log(("VBoxGINA::WlxGetStatusMessage\n"));
459
460 /* Forward to MSGINA if present. */
461 if (GWlxGetStatusMessage)
462 return GWlxGetStatusMessage(pWlxContext, pdwOptions, pMessage, dwBufferSize);
463 return FALSE;
464}
465
466
467BOOL WINAPI WlxRemoveStatusMessage(PVOID pWlxContext)
468{
469 Log(("VBoxGINA::WlxRemoveStatusMessage\n"));
470
471 /* Forward to MSGINA if present. */
472 if (GWlxRemoveStatusMessage)
473 return GWlxRemoveStatusMessage(pWlxContext);
474 return FALSE;
475}
476
477
478/*
479 * GINA 1.4 entry points
480 */
481BOOL WINAPI WlxGetConsoleSwitchCredentials(PVOID pWlxContext,PVOID pCredInfo)
482{
483 Log(("VBoxGINA::WlxGetConsoleSwitchCredentials\n"));
484
485 /* forward call to MSGINA if present */
486 if (GWlxGetConsoleSwitchCredentials)
487 return GWlxGetConsoleSwitchCredentials(pWlxContext,pCredInfo);
488 return FALSE;
489}
490
491
492VOID WINAPI WlxReconnectNotify(PVOID pWlxContext)
493{
494 Log(("VBoxGINA::WlxReconnectNotify\n"));
495
496 /* Forward to MSGINA if present. */
497 if (GWlxReconnectNotify)
498 GWlxReconnectNotify(pWlxContext);
499}
500
501
502VOID WINAPI WlxDisconnectNotify(PVOID pWlxContext)
503{
504 Log(("VBoxGINA::WlxDisconnectNotify\n"));
505
506 /* Forward to MSGINA if present. */
507 if (GWlxDisconnectNotify)
508 GWlxDisconnectNotify(pWlxContext);
509}
510
Note: See TracBrowser for help on using the repository browser.

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