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