1 | /* $Id: VBoxGINA.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGINA -- Windows Logon DLL for VirtualBox
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <stdio.h>
|
---|
19 | #include <stdlib.h>
|
---|
20 | #include <iprt/win/windows.h>
|
---|
21 |
|
---|
22 | #include <iprt/buildconfig.h>
|
---|
23 | #include <iprt/initterm.h>
|
---|
24 | #include <iprt/ldr.h>
|
---|
25 | #include <iprt/errcore.h>
|
---|
26 |
|
---|
27 | #include <VBox/VBoxGuestLib.h>
|
---|
28 |
|
---|
29 | #include "winwlx.h"
|
---|
30 | #include "VBoxGINA.h"
|
---|
31 | #include "Helper.h"
|
---|
32 | #include "Dialog.h"
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * Global variables.
|
---|
36 | */
|
---|
37 |
|
---|
38 | /** DLL instance handle. */
|
---|
39 | HINSTANCE hDllInstance;
|
---|
40 |
|
---|
41 | /** Version of Winlogon. */
|
---|
42 | DWORD wlxVersion;
|
---|
43 |
|
---|
44 | /** Handle to Winlogon service. */
|
---|
45 | HANDLE hGinaWlx;
|
---|
46 | /** Winlog function dispatch table. */
|
---|
47 | PWLX_DISPATCH_VERSION_1_1 pWlxFuncs;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Function pointers to MSGINA entry points.
|
---|
51 | */
|
---|
52 | PGWLXNEGOTIATE GWlxNegotiate;
|
---|
53 | PGWLXINITIALIZE GWlxInitialize;
|
---|
54 | PGWLXDISPLAYSASNOTICE GWlxDisplaySASNotice;
|
---|
55 | PGWLXLOGGEDOUTSAS GWlxLoggedOutSAS;
|
---|
56 | PGWLXACTIVATEUSERSHELL GWlxActivateUserShell;
|
---|
57 | PGWLXLOGGEDONSAS GWlxLoggedOnSAS;
|
---|
58 | PGWLXDISPLAYLOCKEDNOTICE GWlxDisplayLockedNotice;
|
---|
59 | PGWLXWKSTALOCKEDSAS GWlxWkstaLockedSAS;
|
---|
60 | PGWLXISLOCKOK GWlxIsLockOk;
|
---|
61 | PGWLXISLOGOFFOK GWlxIsLogoffOk;
|
---|
62 | PGWLXLOGOFF GWlxLogoff;
|
---|
63 | PGWLXSHUTDOWN GWlxShutdown;
|
---|
64 | /* GINA 1.1. */
|
---|
65 | PGWLXSTARTAPPLICATION GWlxStartApplication;
|
---|
66 | PGWLXSCREENSAVERNOTIFY GWlxScreenSaverNotify;
|
---|
67 | /* GINA 1.3. */
|
---|
68 | PGWLXNETWORKPROVIDERLOAD GWlxNetworkProviderLoad;
|
---|
69 | PGWLXDISPLAYSTATUSMESSAGE GWlxDisplayStatusMessage;
|
---|
70 | PGWLXGETSTATUSMESSAGE GWlxGetStatusMessage;
|
---|
71 | PGWLXREMOVESTATUSMESSAGE GWlxRemoveStatusMessage;
|
---|
72 | /* GINA 1.4. */
|
---|
73 | PGWLXGETCONSOLESWITCHCREDENTIALS GWlxGetConsoleSwitchCredentials;
|
---|
74 | PGWLXRECONNECTNOTIFY GWlxReconnectNotify;
|
---|
75 | PGWLXDISCONNECTNOTIFY GWlxDisconnectNotify;
|
---|
76 |
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * DLL entry point.
|
---|
80 | */
|
---|
81 | BOOL WINAPI DllMain(HINSTANCE hInstance,
|
---|
82 | DWORD dwReason,
|
---|
83 | LPVOID pReserved)
|
---|
84 | {
|
---|
85 | RT_NOREF(pReserved);
|
---|
86 | switch (dwReason)
|
---|
87 | {
|
---|
88 | case DLL_PROCESS_ATTACH:
|
---|
89 | {
|
---|
90 | RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
|
---|
91 | VbglR3Init();
|
---|
92 |
|
---|
93 | VBoxGINALoadConfiguration();
|
---|
94 |
|
---|
95 | VBoxGINAVerbose(0, "VBoxGINA: v%s r%s (%s %s) loaded\n",
|
---|
96 | RTBldCfgVersion(), RTBldCfgRevisionStr(),
|
---|
97 | __DATE__, __TIME__);
|
---|
98 |
|
---|
99 | DisableThreadLibraryCalls(hInstance);
|
---|
100 | hDllInstance = hInstance;
|
---|
101 | break;
|
---|
102 | }
|
---|
103 |
|
---|
104 | case DLL_PROCESS_DETACH:
|
---|
105 | {
|
---|
106 | VBoxGINAVerbose(0, "VBoxGINA: Unloaded\n");
|
---|
107 | VbglR3Term();
|
---|
108 | /// @todo RTR3Term();
|
---|
109 | break;
|
---|
110 | }
|
---|
111 |
|
---|
112 | default:
|
---|
113 | break;
|
---|
114 | }
|
---|
115 | return TRUE;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | BOOL WINAPI WlxNegotiate(DWORD dwWinlogonVersion,
|
---|
120 | DWORD *pdwDllVersion)
|
---|
121 | {
|
---|
122 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: dwWinlogonVersion: %ld\n", dwWinlogonVersion);
|
---|
123 |
|
---|
124 | /* Load the standard Microsoft GINA DLL. */
|
---|
125 | RTLDRMOD hLdrMod;
|
---|
126 | int rc = RTLdrLoadSystem("MSGINA.DLL", true /*fNoUnload*/, &hLdrMod);
|
---|
127 | if (RT_FAILURE(rc))
|
---|
128 | {
|
---|
129 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed loading MSGINA! rc=%Rrc\n", rc);
|
---|
130 | return FALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | /*
|
---|
134 | * Now get the entry points of the MSGINA
|
---|
135 | */
|
---|
136 | GWlxNegotiate = (PGWLXNEGOTIATE)RTLdrGetFunction(hLdrMod, "WlxNegotiate");
|
---|
137 | if (!GWlxNegotiate)
|
---|
138 | {
|
---|
139 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxNegotiate\n");
|
---|
140 | return FALSE;
|
---|
141 | }
|
---|
142 | GWlxInitialize = (PGWLXINITIALIZE)RTLdrGetFunction(hLdrMod, "WlxInitialize");
|
---|
143 | if (!GWlxInitialize)
|
---|
144 | {
|
---|
145 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxInitialize\n");
|
---|
146 | return FALSE;
|
---|
147 | }
|
---|
148 | GWlxDisplaySASNotice =
|
---|
149 | (PGWLXDISPLAYSASNOTICE)RTLdrGetFunction(hLdrMod, "WlxDisplaySASNotice");
|
---|
150 | if (!GWlxDisplaySASNotice)
|
---|
151 | {
|
---|
152 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxDisplaySASNotice\n");
|
---|
153 | return FALSE;
|
---|
154 | }
|
---|
155 | GWlxLoggedOutSAS =
|
---|
156 | (PGWLXLOGGEDOUTSAS)RTLdrGetFunction(hLdrMod, "WlxLoggedOutSAS");
|
---|
157 | if (!GWlxLoggedOutSAS)
|
---|
158 | {
|
---|
159 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxLoggedOutSAS\n");
|
---|
160 | return FALSE;
|
---|
161 | }
|
---|
162 | GWlxActivateUserShell =
|
---|
163 | (PGWLXACTIVATEUSERSHELL)RTLdrGetFunction(hLdrMod, "WlxActivateUserShell");
|
---|
164 | if (!GWlxActivateUserShell)
|
---|
165 | {
|
---|
166 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxActivateUserShell\n");
|
---|
167 | return FALSE;
|
---|
168 | }
|
---|
169 | GWlxLoggedOnSAS =
|
---|
170 | (PGWLXLOGGEDONSAS)RTLdrGetFunction(hLdrMod, "WlxLoggedOnSAS");
|
---|
171 | if (!GWlxLoggedOnSAS)
|
---|
172 | {
|
---|
173 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxLoggedOnSAS\n");
|
---|
174 | return FALSE;
|
---|
175 | }
|
---|
176 | GWlxDisplayLockedNotice =
|
---|
177 | (PGWLXDISPLAYLOCKEDNOTICE)RTLdrGetFunction(hLdrMod, "WlxDisplayLockedNotice");
|
---|
178 | if (!GWlxDisplayLockedNotice)
|
---|
179 | {
|
---|
180 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxDisplayLockedNotice\n");
|
---|
181 | return FALSE;
|
---|
182 | }
|
---|
183 | GWlxIsLockOk = (PGWLXISLOCKOK)RTLdrGetFunction(hLdrMod, "WlxIsLockOk");
|
---|
184 | if (!GWlxIsLockOk)
|
---|
185 | {
|
---|
186 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxIsLockOk\n");
|
---|
187 | return FALSE;
|
---|
188 | }
|
---|
189 | GWlxWkstaLockedSAS =
|
---|
190 | (PGWLXWKSTALOCKEDSAS)RTLdrGetFunction(hLdrMod, "WlxWkstaLockedSAS");
|
---|
191 | if (!GWlxWkstaLockedSAS)
|
---|
192 | {
|
---|
193 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxWkstaLockedSAS\n");
|
---|
194 | return FALSE;
|
---|
195 | }
|
---|
196 | GWlxIsLogoffOk = (PGWLXISLOGOFFOK)RTLdrGetFunction(hLdrMod, "WlxIsLogoffOk");
|
---|
197 | if (!GWlxIsLogoffOk)
|
---|
198 | {
|
---|
199 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxIsLogoffOk\n");
|
---|
200 | return FALSE;
|
---|
201 | }
|
---|
202 | GWlxLogoff = (PGWLXLOGOFF)RTLdrGetFunction(hLdrMod, "WlxLogoff");
|
---|
203 | if (!GWlxLogoff)
|
---|
204 | {
|
---|
205 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxLogoff\n");
|
---|
206 | return FALSE;
|
---|
207 | }
|
---|
208 | GWlxShutdown = (PGWLXSHUTDOWN)RTLdrGetFunction(hLdrMod, "WlxShutdown");
|
---|
209 | if (!GWlxShutdown)
|
---|
210 | {
|
---|
211 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed resolving WlxShutdown\n");
|
---|
212 | return FALSE;
|
---|
213 | }
|
---|
214 | /* GINA 1.1, optional */
|
---|
215 | GWlxStartApplication = (PGWLXSTARTAPPLICATION)RTLdrGetFunction(hLdrMod, "WlxStartApplication");
|
---|
216 | GWlxScreenSaverNotify = (PGWLXSCREENSAVERNOTIFY)RTLdrGetFunction(hLdrMod, "WlxScreenSaverNotify");
|
---|
217 | /* GINA 1.3, optional */
|
---|
218 | GWlxNetworkProviderLoad = (PGWLXNETWORKPROVIDERLOAD)RTLdrGetFunction(hLdrMod, "WlxNetworkProviderLoad");
|
---|
219 | GWlxDisplayStatusMessage = (PGWLXDISPLAYSTATUSMESSAGE)RTLdrGetFunction(hLdrMod, "WlxDisplayStatusMessage");
|
---|
220 | GWlxGetStatusMessage = (PGWLXGETSTATUSMESSAGE)RTLdrGetFunction(hLdrMod, "WlxGetStatusMessage");
|
---|
221 | GWlxRemoveStatusMessage = (PGWLXREMOVESTATUSMESSAGE)RTLdrGetFunction(hLdrMod, "WlxRemoveStatusMessage");
|
---|
222 | /* GINA 1.4, optional */
|
---|
223 | GWlxGetConsoleSwitchCredentials =
|
---|
224 | (PGWLXGETCONSOLESWITCHCREDENTIALS)RTLdrGetFunction(hLdrMod, "WlxGetConsoleSwitchCredentials");
|
---|
225 | GWlxReconnectNotify = (PGWLXRECONNECTNOTIFY)RTLdrGetFunction(hLdrMod, "WlxReconnectNotify");
|
---|
226 | GWlxDisconnectNotify = (PGWLXDISCONNECTNOTIFY)RTLdrGetFunction(hLdrMod, "WlxDisconnectNotify");
|
---|
227 | VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: optional function pointers:\n"
|
---|
228 | " WlxStartApplication: %p\n"
|
---|
229 | " WlxScreenSaverNotify: %p\n"
|
---|
230 | " WlxNetworkProviderLoad: %p\n"
|
---|
231 | " WlxDisplayStatusMessage: %p\n"
|
---|
232 | " WlxGetStatusMessage: %p\n"
|
---|
233 | " WlxRemoveStatusMessage: %p\n"
|
---|
234 | " WlxGetConsoleSwitchCredentials: %p\n"
|
---|
235 | " WlxReconnectNotify: %p\n"
|
---|
236 | " WlxDisconnectNotify: %p\n",
|
---|
237 | GWlxStartApplication, GWlxScreenSaverNotify, GWlxNetworkProviderLoad,
|
---|
238 | GWlxDisplayStatusMessage, GWlxGetStatusMessage, GWlxRemoveStatusMessage,
|
---|
239 | GWlxGetConsoleSwitchCredentials, GWlxReconnectNotify, GWlxDisconnectNotify);
|
---|
240 |
|
---|
241 | wlxVersion = dwWinlogonVersion;
|
---|
242 |
|
---|
243 | /* Acknowledge interface version. */
|
---|
244 | if (pdwDllVersion)
|
---|
245 | *pdwDllVersion = dwWinlogonVersion;
|
---|
246 |
|
---|
247 | return TRUE; /* We're ready to rumble! */
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | BOOL WINAPI WlxInitialize(LPWSTR lpWinsta, HANDLE hWlx, PVOID pvReserved,
|
---|
252 | PVOID pWinlogonFunctions, PVOID *pWlxContext)
|
---|
253 | {
|
---|
254 | VBoxGINAVerbose(0, "VBoxGINA::WlxInitialize\n");
|
---|
255 |
|
---|
256 | /* Store Winlogon function table */
|
---|
257 | pWlxFuncs = (PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions;
|
---|
258 |
|
---|
259 | /* Store handle to Winlogon service*/
|
---|
260 | hGinaWlx = hWlx;
|
---|
261 |
|
---|
262 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Init);
|
---|
263 |
|
---|
264 | /* Hook the dialogs */
|
---|
265 | hookDialogBoxes(pWlxFuncs, wlxVersion);
|
---|
266 |
|
---|
267 | /* Forward call */
|
---|
268 | if (GWlxInitialize)
|
---|
269 | return GWlxInitialize(lpWinsta, hWlx, pvReserved, pWinlogonFunctions, pWlxContext);
|
---|
270 | return TRUE;
|
---|
271 | }
|
---|
272 |
|
---|
273 |
|
---|
274 | VOID WINAPI WlxDisplaySASNotice(PVOID pWlxContext)
|
---|
275 | {
|
---|
276 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisplaySASNotice\n");
|
---|
277 |
|
---|
278 | /* Check if there are credentials for us, if so simulate C-A-D */
|
---|
279 | int rc = VbglR3CredentialsQueryAvailability();
|
---|
280 | if (RT_SUCCESS(rc))
|
---|
281 | {
|
---|
282 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisplaySASNotice: simulating C-A-D\n");
|
---|
283 | /* Wutomatic C-A-D */
|
---|
284 | pWlxFuncs->WlxSasNotify(hGinaWlx, WLX_SAS_TYPE_CTRL_ALT_DEL);
|
---|
285 | }
|
---|
286 | else
|
---|
287 | {
|
---|
288 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisplaySASNotice: starting credentials poller\n");
|
---|
289 | /* start the credentials poller thread */
|
---|
290 | VBoxGINACredentialsPollerCreate();
|
---|
291 | /* Forward call to MSGINA. */
|
---|
292 | if (GWlxDisplaySASNotice)
|
---|
293 | GWlxDisplaySASNotice(pWlxContext);
|
---|
294 | }
|
---|
295 | }
|
---|
296 |
|
---|
297 |
|
---|
298 | int WINAPI WlxLoggedOutSAS(PVOID pWlxContext, DWORD dwSasType, PLUID pAuthenticationId,
|
---|
299 | PSID pLogonSid, PDWORD pdwOptions, PHANDLE phToken,
|
---|
300 | PWLX_MPR_NOTIFY_INFO pMprNotifyInfo, PVOID *pProfile)
|
---|
301 | {
|
---|
302 | VBoxGINAVerbose(0, "VBoxGINA::WlxLoggedOutSAS\n");
|
---|
303 |
|
---|
304 | /* When performing a direct logon without C-A-D, our poller might not be running */
|
---|
305 | int rc = VbglR3CredentialsQueryAvailability();
|
---|
306 | if (RT_FAILURE(rc))
|
---|
307 | VBoxGINACredentialsPollerCreate();
|
---|
308 |
|
---|
309 | if (GWlxLoggedOutSAS)
|
---|
310 | {
|
---|
311 | int iRet;
|
---|
312 | iRet = GWlxLoggedOutSAS(pWlxContext, dwSasType, pAuthenticationId, pLogonSid,
|
---|
313 | pdwOptions, phToken, pMprNotifyInfo, pProfile);
|
---|
314 |
|
---|
315 | if (iRet == WLX_SAS_ACTION_LOGON)
|
---|
316 | {
|
---|
317 | //
|
---|
318 | // Copy pMprNotifyInfo and pLogonSid for later use
|
---|
319 | //
|
---|
320 |
|
---|
321 | // pMprNotifyInfo->pszUserName
|
---|
322 | // pMprNotifyInfo->pszDomain
|
---|
323 | // pMprNotifyInfo->pszPassword
|
---|
324 | // pMprNotifyInfo->pszOldPassword
|
---|
325 | }
|
---|
326 |
|
---|
327 | return iRet;
|
---|
328 | }
|
---|
329 |
|
---|
330 | return WLX_SAS_ACTION_NONE;
|
---|
331 | }
|
---|
332 |
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * WinLogon calls this function following a successful logon to request that the GINA activate the user's shell program.
|
---|
336 | */
|
---|
337 | BOOL WINAPI WlxActivateUserShell(PVOID pWlxContext, PWSTR pszDesktopName,
|
---|
338 | PWSTR pszMprLogonScript, PVOID pEnvironment)
|
---|
339 | {
|
---|
340 | VBoxGINAVerbose(0, "VBoxGINA::WlxActivateUserShell\n");
|
---|
341 |
|
---|
342 | /*
|
---|
343 | * Report status "terminated" to the host -- this means that a user
|
---|
344 | * got logged in (either manually or automatically using the provided credentials).
|
---|
345 | */
|
---|
346 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Terminated);
|
---|
347 |
|
---|
348 | /* Forward call to MSGINA. */
|
---|
349 | if (GWlxActivateUserShell)
|
---|
350 | return GWlxActivateUserShell(pWlxContext, pszDesktopName, pszMprLogonScript, pEnvironment);
|
---|
351 | return TRUE; /* Activate the user shell. */
|
---|
352 | }
|
---|
353 |
|
---|
354 |
|
---|
355 | int WINAPI WlxLoggedOnSAS(PVOID pWlxContext, DWORD dwSasType, PVOID pReserved)
|
---|
356 | {
|
---|
357 | VBoxGINAVerbose(0, "VBoxGINA::WlxLoggedOnSAS: dwSasType=%ld\n", dwSasType);
|
---|
358 |
|
---|
359 | /*
|
---|
360 | * We don't want to do anything special here since the OS should behave
|
---|
361 | * as VBoxGINA wouldn't have been installed. So pass all calls down
|
---|
362 | * to the original MSGINA.
|
---|
363 | */
|
---|
364 |
|
---|
365 | /* Forward call to MSGINA. */
|
---|
366 | VBoxGINAVerbose(0, "VBoxGINA::WlxLoggedOnSAS: Forwarding call to MSGINA ...\n");
|
---|
367 | if (GWlxLoggedOnSAS)
|
---|
368 | return GWlxLoggedOnSAS(pWlxContext, dwSasType, pReserved);
|
---|
369 | return WLX_SAS_ACTION_NONE;
|
---|
370 | }
|
---|
371 |
|
---|
372 | VOID WINAPI WlxDisplayLockedNotice(PVOID pWlxContext)
|
---|
373 | {
|
---|
374 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisplayLockedNotice\n");
|
---|
375 |
|
---|
376 | /* Check if there are credentials for us, if so simulate C-A-D */
|
---|
377 | int rc = VbglR3CredentialsQueryAvailability();
|
---|
378 | if (RT_SUCCESS(rc))
|
---|
379 | {
|
---|
380 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisplayLockedNotice: simulating C-A-D\n");
|
---|
381 | /* Automatic C-A-D */
|
---|
382 | pWlxFuncs->WlxSasNotify(hGinaWlx, WLX_SAS_TYPE_CTRL_ALT_DEL);
|
---|
383 | }
|
---|
384 | else
|
---|
385 | {
|
---|
386 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisplayLockedNotice: starting credentials poller\n");
|
---|
387 | /* start the credentials poller thread */
|
---|
388 | VBoxGINACredentialsPollerCreate();
|
---|
389 | /* Forward call to MSGINA. */
|
---|
390 | if (GWlxDisplayLockedNotice)
|
---|
391 | GWlxDisplayLockedNotice(pWlxContext);
|
---|
392 | }
|
---|
393 | }
|
---|
394 |
|
---|
395 |
|
---|
396 | /*
|
---|
397 | * Winlogon calls this function before it attempts to lock the workstation.
|
---|
398 | */
|
---|
399 | BOOL WINAPI WlxIsLockOk(PVOID pWlxContext)
|
---|
400 | {
|
---|
401 | VBoxGINAVerbose(0, "VBoxGINA::WlxIsLockOk\n");
|
---|
402 |
|
---|
403 | /* Forward call to MSGINA. */
|
---|
404 | if (GWlxIsLockOk)
|
---|
405 | return GWlxIsLockOk(pWlxContext);
|
---|
406 | return TRUE; /* Locking is OK. */
|
---|
407 | }
|
---|
408 |
|
---|
409 |
|
---|
410 | int WINAPI WlxWkstaLockedSAS(PVOID pWlxContext, DWORD dwSasType)
|
---|
411 | {
|
---|
412 | VBoxGINAVerbose(0, "VBoxGINA::WlxWkstaLockedSAS, dwSasType=%ld\n", dwSasType);
|
---|
413 |
|
---|
414 | /* When performing a direct logon without C-A-D, our poller might not be running */
|
---|
415 | int rc = VbglR3CredentialsQueryAvailability();
|
---|
416 | if (RT_FAILURE(rc))
|
---|
417 | VBoxGINACredentialsPollerCreate();
|
---|
418 |
|
---|
419 | /* Forward call to MSGINA. */
|
---|
420 | if (GWlxWkstaLockedSAS)
|
---|
421 | return GWlxWkstaLockedSAS(pWlxContext, dwSasType);
|
---|
422 | return WLX_SAS_ACTION_NONE;
|
---|
423 | }
|
---|
424 |
|
---|
425 |
|
---|
426 | BOOL WINAPI WlxIsLogoffOk(PVOID pWlxContext)
|
---|
427 | {
|
---|
428 | VBoxGINAVerbose(0, "VBoxGINA::WlxIsLogoffOk\n");
|
---|
429 |
|
---|
430 | if (GWlxIsLogoffOk)
|
---|
431 | return GWlxIsLogoffOk(pWlxContext);
|
---|
432 | return TRUE; /* Log off is OK. */
|
---|
433 | }
|
---|
434 |
|
---|
435 |
|
---|
436 | /*
|
---|
437 | * Winlogon calls this function to notify the GINA of a logoff operation on this
|
---|
438 | * workstation. This allows the GINA to perform any logoff operations that may be required.
|
---|
439 | */
|
---|
440 | VOID WINAPI WlxLogoff(PVOID pWlxContext)
|
---|
441 | {
|
---|
442 | VBoxGINAVerbose(0, "VBoxGINA::WlxLogoff\n");
|
---|
443 |
|
---|
444 | /* No need to report the "active" status to the host here -- this will be done
|
---|
445 | * when VBoxGINA gets the chance to hook the dialogs (again). */
|
---|
446 |
|
---|
447 | /* Forward call to MSGINA. */
|
---|
448 | if (GWlxLogoff)
|
---|
449 | GWlxLogoff(pWlxContext);
|
---|
450 | }
|
---|
451 |
|
---|
452 |
|
---|
453 | /*
|
---|
454 | * Winlogon calls this function just before shutting down.
|
---|
455 | * This allows the GINA to perform any necessary shutdown tasks.
|
---|
456 | * Will be called *after* WlxLogoff!
|
---|
457 | */
|
---|
458 | VOID WINAPI WlxShutdown(PVOID pWlxContext, DWORD ShutdownType)
|
---|
459 | {
|
---|
460 | VBoxGINAVerbose(0, "VBoxGINA::WlxShutdown\n");
|
---|
461 |
|
---|
462 | /*
|
---|
463 | * Report status "inactive" to the host -- this means the
|
---|
464 | * auto-logon feature won't be active anymore at this point
|
---|
465 | * (until it maybe gets loaded again after a reboot).
|
---|
466 | */
|
---|
467 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Inactive);
|
---|
468 |
|
---|
469 | /* Forward call to MSGINA. */
|
---|
470 | if (GWlxShutdown)
|
---|
471 | GWlxShutdown(pWlxContext, ShutdownType);
|
---|
472 | }
|
---|
473 |
|
---|
474 |
|
---|
475 | /*
|
---|
476 | * GINA 1.1 entry points
|
---|
477 | */
|
---|
478 | BOOL WINAPI WlxScreenSaverNotify(PVOID pWlxContext, BOOL *pSecure)
|
---|
479 | {
|
---|
480 | RT_NOREF(pWlxContext);
|
---|
481 | VBoxGINAVerbose(0, "VBoxGINA::WlxScreenSaverNotify, pSecure=%d\n",
|
---|
482 | pSecure ? *pSecure : 0);
|
---|
483 |
|
---|
484 | /* Report the status to "init" since the screensaver
|
---|
485 | * (Winlogon) does not give VBoxGINA yet the chance to hook into dialogs
|
---|
486 | * which only then in turn would set the status to "active" -- so
|
---|
487 | * at least set some status here. */
|
---|
488 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Init);
|
---|
489 |
|
---|
490 | /* Note: Disabling the screensaver's grace period is necessary to get
|
---|
491 | * VBoxGINA loaded and set the status to "terminated" again properly
|
---|
492 | * after the logging-in handling was done. To do this:
|
---|
493 | * - on a non-domain machine, set:
|
---|
494 | * HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ScreenSaverGracePeriod (REG_SZ)
|
---|
495 | * to "0"
|
---|
496 | * - on a machine joined a domain:
|
---|
497 | * use the group policy preferences and/or the registry key above,
|
---|
498 | * depending on the domain's policies.
|
---|
499 | */
|
---|
500 |
|
---|
501 | /* Indicate that the workstation should be locked. */
|
---|
502 | *pSecure = TRUE;
|
---|
503 |
|
---|
504 | return TRUE; /* Screensaver should be activated. */
|
---|
505 | }
|
---|
506 |
|
---|
507 |
|
---|
508 | BOOL WINAPI WlxStartApplication(PVOID pWlxContext, PWSTR pszDesktopName,
|
---|
509 | PVOID pEnvironment, PWSTR pszCmdLine)
|
---|
510 | {
|
---|
511 | VBoxGINAVerbose(0, "VBoxGINA::WlxStartApplication: pWlxCtx=%p, pszDesktopName=%ls, pEnvironment=%p, pszCmdLine=%ls\n",
|
---|
512 | pWlxContext, pszDesktopName, pEnvironment, pszCmdLine);
|
---|
513 |
|
---|
514 | /* Forward to MSGINA if present. */
|
---|
515 | if (GWlxStartApplication)
|
---|
516 | return GWlxStartApplication(pWlxContext, pszDesktopName, pEnvironment, pszCmdLine);
|
---|
517 | return FALSE;
|
---|
518 | }
|
---|
519 |
|
---|
520 |
|
---|
521 | /*
|
---|
522 | * GINA 1.3 entry points
|
---|
523 | */
|
---|
524 | BOOL WINAPI WlxNetworkProviderLoad(PVOID pWlxContext, PWLX_MPR_NOTIFY_INFO pNprNotifyInfo)
|
---|
525 | {
|
---|
526 | VBoxGINAVerbose(0, "VBoxGINA::WlxNetworkProviderLoad\n");
|
---|
527 |
|
---|
528 | /* Forward to MSGINA if present. */
|
---|
529 | if (GWlxNetworkProviderLoad)
|
---|
530 | return GWlxNetworkProviderLoad(pWlxContext, pNprNotifyInfo);
|
---|
531 | return FALSE;
|
---|
532 | }
|
---|
533 |
|
---|
534 |
|
---|
535 | BOOL WINAPI WlxDisplayStatusMessage(PVOID pWlxContext, HDESK hDesktop, DWORD dwOptions,
|
---|
536 | PWSTR pTitle, PWSTR pMessage)
|
---|
537 | {
|
---|
538 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisplayStatusMessage\n");
|
---|
539 |
|
---|
540 | /* Forward to MSGINA if present. */
|
---|
541 | if (GWlxDisplayStatusMessage)
|
---|
542 | return GWlxDisplayStatusMessage(pWlxContext, hDesktop, dwOptions, pTitle, pMessage);
|
---|
543 | return FALSE;
|
---|
544 | }
|
---|
545 |
|
---|
546 |
|
---|
547 | BOOL WINAPI WlxGetStatusMessage(PVOID pWlxContext, DWORD *pdwOptions,
|
---|
548 | PWSTR pMessage, DWORD dwBufferSize)
|
---|
549 | {
|
---|
550 | VBoxGINAVerbose(0, "VBoxGINA::WlxGetStatusMessage\n");
|
---|
551 |
|
---|
552 | /* Forward to MSGINA if present. */
|
---|
553 | if (GWlxGetStatusMessage)
|
---|
554 | return GWlxGetStatusMessage(pWlxContext, pdwOptions, pMessage, dwBufferSize);
|
---|
555 | return FALSE;
|
---|
556 | }
|
---|
557 |
|
---|
558 |
|
---|
559 | BOOL WINAPI WlxRemoveStatusMessage(PVOID pWlxContext)
|
---|
560 | {
|
---|
561 | VBoxGINAVerbose(0, "VBoxGINA::WlxRemoveStatusMessage\n");
|
---|
562 |
|
---|
563 | /* Forward to MSGINA if present. */
|
---|
564 | if (GWlxRemoveStatusMessage)
|
---|
565 | return GWlxRemoveStatusMessage(pWlxContext);
|
---|
566 | return FALSE;
|
---|
567 | }
|
---|
568 |
|
---|
569 |
|
---|
570 | /*
|
---|
571 | * GINA 1.4 entry points
|
---|
572 | */
|
---|
573 | BOOL WINAPI WlxGetConsoleSwitchCredentials(PVOID pWlxContext,PVOID pCredInfo)
|
---|
574 | {
|
---|
575 | VBoxGINAVerbose(0, "VBoxGINA::WlxGetConsoleSwitchCredentials\n");
|
---|
576 |
|
---|
577 | /* Forward call to MSGINA if present */
|
---|
578 | if (GWlxGetConsoleSwitchCredentials)
|
---|
579 | return GWlxGetConsoleSwitchCredentials(pWlxContext,pCredInfo);
|
---|
580 | return FALSE;
|
---|
581 | }
|
---|
582 |
|
---|
583 |
|
---|
584 | VOID WINAPI WlxReconnectNotify(PVOID pWlxContext)
|
---|
585 | {
|
---|
586 | VBoxGINAVerbose(0, "VBoxGINA::WlxReconnectNotify\n");
|
---|
587 |
|
---|
588 | /* Forward to MSGINA if present. */
|
---|
589 | if (GWlxReconnectNotify)
|
---|
590 | GWlxReconnectNotify(pWlxContext);
|
---|
591 | }
|
---|
592 |
|
---|
593 |
|
---|
594 | VOID WINAPI WlxDisconnectNotify(PVOID pWlxContext)
|
---|
595 | {
|
---|
596 | VBoxGINAVerbose(0, "VBoxGINA::WlxDisconnectNotify\n");
|
---|
597 |
|
---|
598 | /* Forward to MSGINA if present. */
|
---|
599 | if (GWlxDisconnectNotify)
|
---|
600 | GWlxDisconnectNotify(pWlxContext);
|
---|
601 | }
|
---|
602 |
|
---|
603 |
|
---|
604 | /*
|
---|
605 | * Windows Notification Package callbacks
|
---|
606 | */
|
---|
607 | void WnpScreenSaverStop(PWLX_NOTIFICATION_INFO pInfo)
|
---|
608 | {
|
---|
609 | RT_NOREF(pInfo);
|
---|
610 | VBoxGINAVerbose(0, "VBoxGINA::WnpScreenSaverStop\n");
|
---|
611 |
|
---|
612 | /*
|
---|
613 | * Because we set the status to "init" in WlxScreenSaverNotify when
|
---|
614 | * the screensaver becomes active we also have to take into account
|
---|
615 | * that in case the screensaver terminates (either within the grace
|
---|
616 | * period or because the lock screen appears) we have to set the
|
---|
617 | * status accordingly.
|
---|
618 | */
|
---|
619 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Terminated);
|
---|
620 | }
|
---|
621 |
|
---|
622 |
|
---|
623 | DWORD WINAPI VBoxGINADebug(void)
|
---|
624 | {
|
---|
625 | #ifdef DEBUG
|
---|
626 | DWORD dwVersion;
|
---|
627 | BOOL fRes = WlxNegotiate(WLX_VERSION_1_4, &dwVersion);
|
---|
628 | if (!fRes)
|
---|
629 | return 1;
|
---|
630 |
|
---|
631 | void* pWlxContext = NULL;
|
---|
632 | WLX_DISPATCH_VERSION_1_4 wlxDispatch;
|
---|
633 | ZeroMemory(&wlxDispatch, sizeof(WLX_DISPATCH_VERSION_1_4));
|
---|
634 |
|
---|
635 | fRes = WlxInitialize(0, 0,
|
---|
636 | NULL /* Reserved */,
|
---|
637 | NULL /* Winlogon functions */,
|
---|
638 | &pWlxContext);
|
---|
639 | if (!fRes)
|
---|
640 | return 2;
|
---|
641 |
|
---|
642 | WlxDisplaySASNotice(pWlxContext);
|
---|
643 |
|
---|
644 | char szSID[MAX_PATH];
|
---|
645 | LUID luidAuth;
|
---|
646 | DWORD dwOpts;
|
---|
647 | WLX_MPR_NOTIFY_INFO wlxNotifyInfo;
|
---|
648 | void* pvProfile;
|
---|
649 | HANDLE hToken;
|
---|
650 | int iRes = WlxLoggedOutSAS(pWlxContext, WLX_SAS_TYPE_CTRL_ALT_DEL,
|
---|
651 | &luidAuth, szSID,
|
---|
652 | &dwOpts, &hToken, &wlxNotifyInfo, &pvProfile);
|
---|
653 | return iRes;
|
---|
654 | #else
|
---|
655 | return 0;
|
---|
656 | #endif
|
---|
657 | }
|
---|
658 |
|
---|