1 | /* $Id: VBoxTray.cpp 45843 2013-04-30 15:39:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxTray - Guest Additions Tray Application
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 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 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #include "VBoxTray.h"
|
---|
23 | #include "VBoxTrayMsg.h"
|
---|
24 | #include "VBoxHelpers.h"
|
---|
25 | #include "VBoxSeamless.h"
|
---|
26 | #include "VBoxClipboard.h"
|
---|
27 | #include "VBoxDisplay.h"
|
---|
28 | #include "VBoxRestore.h"
|
---|
29 | #include "VBoxVRDP.h"
|
---|
30 | #include "VBoxHostVersion.h"
|
---|
31 | #include "VBoxSharedFolders.h"
|
---|
32 | #include "VBoxIPC.h"
|
---|
33 | #include "VBoxLA.h"
|
---|
34 | #include "VBoxMMR.h"
|
---|
35 | #include <VBoxHook.h>
|
---|
36 | #include "resource.h"
|
---|
37 | #include <malloc.h>
|
---|
38 | #include <VBoxGuestInternal.h>
|
---|
39 |
|
---|
40 | #include <sddl.h>
|
---|
41 |
|
---|
42 | #include <iprt/buildconfig.h>
|
---|
43 |
|
---|
44 | /* Default desktop state tracking */
|
---|
45 | #include <Wtsapi32.h>
|
---|
46 |
|
---|
47 | #ifdef DEBUG_misha
|
---|
48 | #define WARN(_m) do { \
|
---|
49 | Assert(0); \
|
---|
50 | Log(_m); \
|
---|
51 | } while (0)
|
---|
52 | #else
|
---|
53 | #define WARN(_m) do { \
|
---|
54 | Log(_m); \
|
---|
55 | } while (0)
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * St (session [state] tracking) functionality API
|
---|
60 | *
|
---|
61 | * !!!NOTE: this API is NOT thread-safe!!!
|
---|
62 | * it is supposed to be called & used from within the window message handler thread
|
---|
63 | * of the window passed to vboxStInit */
|
---|
64 | static int vboxStInit(HWND hWnd);
|
---|
65 | static void vboxStTerm();
|
---|
66 | /* @returns true on "IsActiveConsole" state change */
|
---|
67 | static BOOL vboxStHandleEvent(WPARAM EventID, LPARAM SessionID);
|
---|
68 | static BOOL vboxStIsActiveConsole();
|
---|
69 | static BOOL vboxStCheckTimer(WPARAM wEvent);
|
---|
70 |
|
---|
71 | /*
|
---|
72 | * Dt (desktop [state] tracking) functionality API
|
---|
73 | *
|
---|
74 | * !!!NOTE: this API is NOT thread-safe!!!
|
---|
75 | * */
|
---|
76 | static int vboxDtInit();
|
---|
77 | static void vboxDtTerm();
|
---|
78 | /* @returns true on "IsInputDesktop" state change */
|
---|
79 | static BOOL vboxDtHandleEvent();
|
---|
80 | /* @returns true iff the application (VBoxTray) desktop is input */
|
---|
81 | static BOOL vboxDtIsInputDesktop();
|
---|
82 | static HANDLE vboxDtGetNotifyEvent();
|
---|
83 | static BOOL vboxDtCheckTimer(WPARAM wParam);
|
---|
84 |
|
---|
85 | /* caps API */
|
---|
86 | #define VBOXCAPS_ENTRY_IDX_SEAMLESS 0
|
---|
87 | #define VBOXCAPS_ENTRY_IDX_GRAPHICS 1
|
---|
88 | #define VBOXCAPS_ENTRY_IDX_COUNT 2
|
---|
89 |
|
---|
90 | typedef enum VBOXCAPS_ENTRY_FUNCSTATE
|
---|
91 | {
|
---|
92 | /* the cap is unsupported */
|
---|
93 | VBOXCAPS_ENTRY_FUNCSTATE_UNSUPPORTED = 0,
|
---|
94 | /* the cap is supported */
|
---|
95 | VBOXCAPS_ENTRY_FUNCSTATE_SUPPORTED,
|
---|
96 | /* the cap functionality is started, it can be disabled however if its AcState is not ACQUIRED */
|
---|
97 | VBOXCAPS_ENTRY_FUNCSTATE_STARTED,
|
---|
98 | } VBOXCAPS_ENTRY_FUNCSTATE;
|
---|
99 |
|
---|
100 |
|
---|
101 | static void VBoxCapsEntryFuncStateSet(uint32_t iCup, VBOXCAPS_ENTRY_FUNCSTATE enmFuncState);
|
---|
102 | static int VBoxCapsInit();
|
---|
103 | static int VBoxCapsReleaseAll();
|
---|
104 | static void VBoxCapsTerm();
|
---|
105 | static BOOL VBoxCapsEntryIsAcquired(uint32_t iCap);
|
---|
106 | static BOOL VBoxCapsEntryIsEnabled(uint32_t iCap);
|
---|
107 | static BOOL VBoxCapsCheckTimer(WPARAM wParam);
|
---|
108 | static int VBoxCapsEntryRelease(uint32_t iCap);
|
---|
109 | static int VBoxCapsEntryAcquire(uint32_t iCap);
|
---|
110 | static int VBoxCapsAcquireAllSupported();
|
---|
111 |
|
---|
112 | /* console-related caps API */
|
---|
113 | static BOOL VBoxConsoleIsAllowed();
|
---|
114 | static void VBoxConsoleEnable(BOOL fEnable);
|
---|
115 | static void VBoxConsoleCapSetSupported(uint32_t iCap, BOOL fSupported);
|
---|
116 |
|
---|
117 | static void VBoxGrapicsSetSupported(BOOL fSupported);
|
---|
118 |
|
---|
119 | /*******************************************************************************
|
---|
120 | * Internal Functions *
|
---|
121 | *******************************************************************************/
|
---|
122 | static int vboxTrayCreateTrayIcon(void);
|
---|
123 | static LRESULT CALLBACK vboxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
124 |
|
---|
125 | /* Global message handler prototypes. */
|
---|
126 | static int vboxTrayGlMsgTaskbarCreated(WPARAM lParam, LPARAM wParam);
|
---|
127 | /*static int vboxTrayGlMsgShowBalloonMsg(WPARAM lParam, LPARAM wParam);*/
|
---|
128 |
|
---|
129 |
|
---|
130 | /*******************************************************************************
|
---|
131 | * Global Variables *
|
---|
132 | *******************************************************************************/
|
---|
133 | HANDLE ghVBoxDriver;
|
---|
134 | HANDLE ghStopSem;
|
---|
135 | HANDLE ghSeamlessWtNotifyEvent = 0;
|
---|
136 | SERVICE_STATUS gVBoxServiceStatus;
|
---|
137 | SERVICE_STATUS_HANDLE gVBoxServiceStatusHandle;
|
---|
138 | HINSTANCE ghInstance;
|
---|
139 | HWND ghwndToolWindow;
|
---|
140 | NOTIFYICONDATA gNotifyIconData;
|
---|
141 | DWORD gMajorVersion;
|
---|
142 |
|
---|
143 |
|
---|
144 | /* The service table. */
|
---|
145 | static VBOXSERVICEINFO vboxServiceTable[] =
|
---|
146 | {
|
---|
147 | {
|
---|
148 | "Display",
|
---|
149 | VBoxDisplayInit,
|
---|
150 | VBoxDisplayThread,
|
---|
151 | VBoxDisplayDestroy
|
---|
152 | },
|
---|
153 | {
|
---|
154 | "Shared Clipboard",
|
---|
155 | VBoxClipboardInit,
|
---|
156 | VBoxClipboardThread,
|
---|
157 | VBoxClipboardDestroy
|
---|
158 | },
|
---|
159 | {
|
---|
160 | "Seamless Windows",
|
---|
161 | VBoxSeamlessInit,
|
---|
162 | VBoxSeamlessThread,
|
---|
163 | VBoxSeamlessDestroy
|
---|
164 | },
|
---|
165 | #ifdef VBOX_WITH_VRDP_SESSION_HANDLING
|
---|
166 | {
|
---|
167 | "Restore",
|
---|
168 | VBoxRestoreInit,
|
---|
169 | VBoxRestoreThread,
|
---|
170 | VBoxRestoreDestroy
|
---|
171 | },
|
---|
172 | #endif
|
---|
173 | {
|
---|
174 | "VRDP",
|
---|
175 | VBoxVRDPInit,
|
---|
176 | VBoxVRDPThread,
|
---|
177 | VBoxVRDPDestroy
|
---|
178 | },
|
---|
179 | {
|
---|
180 | "IPC",
|
---|
181 | VBoxIPCInit,
|
---|
182 | VBoxIPCThread,
|
---|
183 | VBoxIPCDestroy
|
---|
184 | },
|
---|
185 | {
|
---|
186 | "Location Awareness",
|
---|
187 | VBoxLAInit,
|
---|
188 | VBoxLAThread,
|
---|
189 | VBoxLADestroy
|
---|
190 | },
|
---|
191 | #ifdef VBOX_WITH_MMR
|
---|
192 | {
|
---|
193 | "Multimedia Redirection",
|
---|
194 | VBoxMMRInit,
|
---|
195 | VBoxMMRThread,
|
---|
196 | VBoxMMRDestroy
|
---|
197 | },
|
---|
198 | #endif
|
---|
199 | {
|
---|
200 | NULL
|
---|
201 | }
|
---|
202 | };
|
---|
203 |
|
---|
204 | /* The global message table. */
|
---|
205 | static VBOXGLOBALMESSAGE s_vboxGlobalMessageTable[] =
|
---|
206 | {
|
---|
207 | /* Windows specific stuff. */
|
---|
208 | {
|
---|
209 | "TaskbarCreated",
|
---|
210 | vboxTrayGlMsgTaskbarCreated
|
---|
211 | },
|
---|
212 |
|
---|
213 | /* VBoxTray specific stuff. */
|
---|
214 | /** @todo Add new messages here! */
|
---|
215 |
|
---|
216 | {
|
---|
217 | NULL
|
---|
218 | }
|
---|
219 | };
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Gets called whenever the Windows main taskbar
|
---|
223 | * get (re-)created. Nice to install our tray icon.
|
---|
224 | *
|
---|
225 | * @return IPRT status code.
|
---|
226 | * @param wParam
|
---|
227 | * @param lParam
|
---|
228 | */
|
---|
229 | static int vboxTrayGlMsgTaskbarCreated(WPARAM wParam, LPARAM lParam)
|
---|
230 | {
|
---|
231 | return vboxTrayCreateTrayIcon();
|
---|
232 | }
|
---|
233 |
|
---|
234 | static int vboxTrayCreateTrayIcon(void)
|
---|
235 | {
|
---|
236 | HICON hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX));
|
---|
237 | if (hIcon == NULL)
|
---|
238 | {
|
---|
239 | DWORD dwErr = GetLastError();
|
---|
240 | Log(("VBoxTray: Could not load tray icon, error %08X\n", dwErr));
|
---|
241 | return RTErrConvertFromWin32(dwErr);
|
---|
242 | }
|
---|
243 |
|
---|
244 | /* Prepare the system tray icon. */
|
---|
245 | RT_ZERO(gNotifyIconData);
|
---|
246 | gNotifyIconData.cbSize = NOTIFYICONDATA_V1_SIZE; // sizeof(NOTIFYICONDATA);
|
---|
247 | gNotifyIconData.hWnd = ghwndToolWindow;
|
---|
248 | gNotifyIconData.uID = ID_TRAYICON;
|
---|
249 | gNotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
---|
250 | gNotifyIconData.uCallbackMessage = WM_VBOXTRAY_TRAY_ICON;
|
---|
251 | gNotifyIconData.hIcon = hIcon;
|
---|
252 |
|
---|
253 | sprintf(gNotifyIconData.szTip, "%s Guest Additions %d.%d.%dr%d",
|
---|
254 | VBOX_PRODUCT, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
|
---|
255 |
|
---|
256 | int rc = VINF_SUCCESS;
|
---|
257 | if (!Shell_NotifyIcon(NIM_ADD, &gNotifyIconData))
|
---|
258 | {
|
---|
259 | DWORD dwErr = GetLastError();
|
---|
260 | Log(("VBoxTray: Could not create tray icon, error = %08X\n", dwErr));
|
---|
261 | rc = RTErrConvertFromWin32(dwErr);
|
---|
262 | RT_ZERO(gNotifyIconData);
|
---|
263 | }
|
---|
264 |
|
---|
265 | if (hIcon)
|
---|
266 | DestroyIcon(hIcon);
|
---|
267 | return rc;
|
---|
268 | }
|
---|
269 |
|
---|
270 | static void vboxTrayRemoveTrayIcon()
|
---|
271 | {
|
---|
272 | if (gNotifyIconData.cbSize > 0)
|
---|
273 | {
|
---|
274 | /* Remove the system tray icon and refresh system tray. */
|
---|
275 | Shell_NotifyIcon(NIM_DELETE, &gNotifyIconData);
|
---|
276 | HWND hTrayWnd = FindWindow("Shell_TrayWnd", NULL); /* We assume we only have one tray atm. */
|
---|
277 | if (hTrayWnd)
|
---|
278 | {
|
---|
279 | HWND hTrayNotifyWnd = FindWindowEx(hTrayWnd, 0, "TrayNotifyWnd", NULL);
|
---|
280 | if (hTrayNotifyWnd)
|
---|
281 | SendMessage(hTrayNotifyWnd, WM_PAINT, 0, NULL);
|
---|
282 | }
|
---|
283 | RT_ZERO(gNotifyIconData);
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | static int vboxTrayStartServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
|
---|
288 | {
|
---|
289 | Log(("VBoxTray: Starting services ...\n"));
|
---|
290 |
|
---|
291 | pEnv->hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
---|
292 |
|
---|
293 | if (!pEnv->hStopEvent)
|
---|
294 | {
|
---|
295 | /* Could not create event. */
|
---|
296 | return VERR_NOT_SUPPORTED;
|
---|
297 | }
|
---|
298 |
|
---|
299 | while (pTable->pszName)
|
---|
300 | {
|
---|
301 | Log(("VBoxTray: Starting %s ...\n", pTable->pszName));
|
---|
302 |
|
---|
303 | int rc = VINF_SUCCESS;
|
---|
304 |
|
---|
305 | bool fStartThread = false;
|
---|
306 |
|
---|
307 | pTable->hThread = (HANDLE)0;
|
---|
308 | pTable->pInstance = NULL;
|
---|
309 | pTable->fStarted = false;
|
---|
310 |
|
---|
311 | if (pTable->pfnInit)
|
---|
312 | rc = pTable->pfnInit (pEnv, &pTable->pInstance, &fStartThread);
|
---|
313 |
|
---|
314 | if (RT_FAILURE(rc))
|
---|
315 | {
|
---|
316 | Log(("VBoxTray: Failed to initialize rc = %Rrc\n", rc));
|
---|
317 | }
|
---|
318 | else
|
---|
319 | {
|
---|
320 | if (pTable->pfnThread && fStartThread)
|
---|
321 | {
|
---|
322 | unsigned threadid;
|
---|
323 | pTable->hThread = (HANDLE)_beginthreadex(NULL, /* security */
|
---|
324 | 0, /* stacksize */
|
---|
325 | pTable->pfnThread,
|
---|
326 | pTable->pInstance,
|
---|
327 | 0, /* initflag */
|
---|
328 | &threadid);
|
---|
329 |
|
---|
330 | if (pTable->hThread == (HANDLE)(0))
|
---|
331 | rc = VERR_NOT_SUPPORTED;
|
---|
332 | }
|
---|
333 |
|
---|
334 | if (RT_SUCCESS(rc))
|
---|
335 | pTable->fStarted = true;
|
---|
336 | else
|
---|
337 | {
|
---|
338 | Log(("VBoxTray: Failed to start the thread\n"));
|
---|
339 | if (pTable->pfnDestroy)
|
---|
340 | pTable->pfnDestroy(pEnv, pTable->pInstance);
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | /* Advance to next table element. */
|
---|
345 | pTable++;
|
---|
346 | }
|
---|
347 |
|
---|
348 | return VINF_SUCCESS;
|
---|
349 | }
|
---|
350 |
|
---|
351 | static void vboxTrayStopServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
|
---|
352 | {
|
---|
353 | if (!pEnv->hStopEvent)
|
---|
354 | return;
|
---|
355 |
|
---|
356 | /* Signal to all threads. */
|
---|
357 | SetEvent(pEnv->hStopEvent);
|
---|
358 |
|
---|
359 | while (pTable->pszName)
|
---|
360 | {
|
---|
361 | if (pTable->fStarted)
|
---|
362 | {
|
---|
363 | if (pTable->pfnThread)
|
---|
364 | {
|
---|
365 | /* There is a thread, wait for termination. */
|
---|
366 | WaitForSingleObject(pTable->hThread, INFINITE);
|
---|
367 |
|
---|
368 | CloseHandle(pTable->hThread);
|
---|
369 | pTable->hThread = 0;
|
---|
370 | }
|
---|
371 |
|
---|
372 | if (pTable->pfnDestroy)
|
---|
373 | pTable->pfnDestroy (pEnv, pTable->pInstance);
|
---|
374 | pTable->fStarted = false;
|
---|
375 | }
|
---|
376 |
|
---|
377 | /* Advance to next table element. */
|
---|
378 | pTable++;
|
---|
379 | }
|
---|
380 |
|
---|
381 | CloseHandle(pEnv->hStopEvent);
|
---|
382 | }
|
---|
383 |
|
---|
384 | static int vboxTrayRegisterGlobalMessages(PVBOXGLOBALMESSAGE pTable)
|
---|
385 | {
|
---|
386 | int rc = VINF_SUCCESS;
|
---|
387 | if (pTable == NULL) /* No table to register? Skip. */
|
---|
388 | return rc;
|
---|
389 | while ( pTable->pszName
|
---|
390 | && RT_SUCCESS(rc))
|
---|
391 | {
|
---|
392 | /* Register global accessible window messages. */
|
---|
393 | pTable->uMsgID = RegisterWindowMessage(TEXT(pTable->pszName));
|
---|
394 | if (!pTable->uMsgID)
|
---|
395 | {
|
---|
396 | DWORD dwErr = GetLastError();
|
---|
397 | Log(("VBoxTray: Registering global message \"%s\" failed, error = %08X\n", dwErr));
|
---|
398 | rc = RTErrConvertFromWin32(dwErr);
|
---|
399 | }
|
---|
400 |
|
---|
401 | /* Advance to next table element. */
|
---|
402 | pTable++;
|
---|
403 | }
|
---|
404 | return rc;
|
---|
405 | }
|
---|
406 |
|
---|
407 | static bool vboxTrayHandleGlobalMessages(PVBOXGLOBALMESSAGE pTable, UINT uMsg,
|
---|
408 | WPARAM wParam, LPARAM lParam)
|
---|
409 | {
|
---|
410 | if (pTable == NULL)
|
---|
411 | return false;
|
---|
412 | while (pTable && pTable->pszName)
|
---|
413 | {
|
---|
414 | if (pTable->uMsgID == uMsg)
|
---|
415 | {
|
---|
416 | if (pTable->pfnHandler)
|
---|
417 | pTable->pfnHandler(wParam, lParam);
|
---|
418 | return true;
|
---|
419 | }
|
---|
420 |
|
---|
421 | /* Advance to next table element. */
|
---|
422 | pTable++;
|
---|
423 | }
|
---|
424 | return false;
|
---|
425 | }
|
---|
426 |
|
---|
427 | static int vboxTrayOpenBaseDriver(void)
|
---|
428 | {
|
---|
429 | /* Open VBox guest driver. */
|
---|
430 | DWORD dwErr = ERROR_SUCCESS;
|
---|
431 | ghVBoxDriver = CreateFile(VBOXGUEST_DEVICE_NAME,
|
---|
432 | GENERIC_READ | GENERIC_WRITE,
|
---|
433 | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
---|
434 | NULL,
|
---|
435 | OPEN_EXISTING,
|
---|
436 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
---|
437 | NULL);
|
---|
438 | if (ghVBoxDriver == INVALID_HANDLE_VALUE)
|
---|
439 | {
|
---|
440 | dwErr = GetLastError();
|
---|
441 | LogRel(("VBoxTray: Could not open VirtualBox Guest Additions driver! Please install / start it first! Error = %08X\n", dwErr));
|
---|
442 | }
|
---|
443 | return RTErrConvertFromWin32(dwErr);
|
---|
444 | }
|
---|
445 |
|
---|
446 | static void vboxTrayCloseBaseDriver(void)
|
---|
447 | {
|
---|
448 | if (ghVBoxDriver)
|
---|
449 | {
|
---|
450 | CloseHandle(ghVBoxDriver);
|
---|
451 | ghVBoxDriver = NULL;
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | static void vboxTrayDestroyToolWindow(void)
|
---|
456 | {
|
---|
457 | if (ghwndToolWindow)
|
---|
458 | {
|
---|
459 | Log(("VBoxTray: Destroying tool window ...\n"));
|
---|
460 |
|
---|
461 | /* Destroy the tool window. */
|
---|
462 | DestroyWindow(ghwndToolWindow);
|
---|
463 | ghwndToolWindow = NULL;
|
---|
464 |
|
---|
465 | UnregisterClass("VBoxTrayToolWndClass", ghInstance);
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | static int vboxTrayCreateToolWindow(void)
|
---|
470 | {
|
---|
471 | DWORD dwErr = ERROR_SUCCESS;
|
---|
472 |
|
---|
473 | /* Create a custom window class. */
|
---|
474 | WNDCLASS windowClass = {0};
|
---|
475 | windowClass.style = CS_NOCLOSE;
|
---|
476 | windowClass.lpfnWndProc = (WNDPROC)vboxToolWndProc;
|
---|
477 | windowClass.hInstance = ghInstance;
|
---|
478 | windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
---|
479 | windowClass.lpszClassName = "VBoxTrayToolWndClass";
|
---|
480 | if (!RegisterClass(&windowClass))
|
---|
481 | {
|
---|
482 | dwErr = GetLastError();
|
---|
483 | Log(("VBoxTray: Registering invisible tool window failed, error = %08X\n", dwErr));
|
---|
484 | }
|
---|
485 | else
|
---|
486 | {
|
---|
487 | /*
|
---|
488 | * Create our (invisible) tool window.
|
---|
489 | * Note: The window name ("VBoxTrayToolWnd") and class ("VBoxTrayToolWndClass") is
|
---|
490 | * needed for posting globally registered messages to VBoxTray and must not be
|
---|
491 | * changed! Otherwise things get broken!
|
---|
492 | *
|
---|
493 | */
|
---|
494 | ghwndToolWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
|
---|
495 | "VBoxTrayToolWndClass", "VBoxTrayToolWnd",
|
---|
496 | WS_POPUPWINDOW,
|
---|
497 | -200, -200, 100, 100, NULL, NULL, ghInstance, NULL);
|
---|
498 | if (!ghwndToolWindow)
|
---|
499 | {
|
---|
500 | dwErr = GetLastError();
|
---|
501 | Log(("VBoxTray: Creating invisible tool window failed, error = %08X\n", dwErr));
|
---|
502 | }
|
---|
503 | else
|
---|
504 | {
|
---|
505 | /* Reload the cursor(s). */
|
---|
506 | hlpReloadCursor();
|
---|
507 |
|
---|
508 | Log(("VBoxTray: Invisible tool window handle = %p\n", ghwndToolWindow));
|
---|
509 | }
|
---|
510 | }
|
---|
511 |
|
---|
512 | if (dwErr != ERROR_SUCCESS)
|
---|
513 | vboxTrayDestroyToolWindow();
|
---|
514 | return RTErrConvertFromWin32(dwErr);
|
---|
515 | }
|
---|
516 |
|
---|
517 | static int vboxTraySetupSeamless(void)
|
---|
518 | {
|
---|
519 | OSVERSIONINFO info;
|
---|
520 | gMajorVersion = 5; /* Default to Windows XP. */
|
---|
521 | info.dwOSVersionInfoSize = sizeof(info);
|
---|
522 | if (GetVersionEx(&info))
|
---|
523 | {
|
---|
524 | Log(("VBoxTray: Windows version %ld.%ld\n", info.dwMajorVersion, info.dwMinorVersion));
|
---|
525 | gMajorVersion = info.dwMajorVersion;
|
---|
526 | }
|
---|
527 |
|
---|
528 | /* We need to setup a security descriptor to allow other processes modify access to the seamless notification event semaphore. */
|
---|
529 | SECURITY_ATTRIBUTES SecAttr;
|
---|
530 | DWORD dwErr = ERROR_SUCCESS;
|
---|
531 | char secDesc[SECURITY_DESCRIPTOR_MIN_LENGTH];
|
---|
532 | BOOL fRC;
|
---|
533 |
|
---|
534 | SecAttr.nLength = sizeof(SecAttr);
|
---|
535 | SecAttr.bInheritHandle = FALSE;
|
---|
536 | SecAttr.lpSecurityDescriptor = &secDesc;
|
---|
537 | InitializeSecurityDescriptor(SecAttr.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
|
---|
538 | fRC = SetSecurityDescriptorDacl(SecAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
|
---|
539 | if (!fRC)
|
---|
540 | {
|
---|
541 | dwErr = GetLastError();
|
---|
542 | Log(("VBoxTray: SetSecurityDescriptorDacl failed with last error = %08X\n", dwErr));
|
---|
543 | }
|
---|
544 | else
|
---|
545 | {
|
---|
546 | /* For Vista and up we need to change the integrity of the security descriptor, too. */
|
---|
547 | if (gMajorVersion >= 6)
|
---|
548 | {
|
---|
549 | BOOL (WINAPI * pfnConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, PSECURITY_DESCRIPTOR *SecurityDescriptor, PULONG SecurityDescriptorSize);
|
---|
550 |
|
---|
551 | HMODULE hModule = LoadLibrary("ADVAPI32.DLL");
|
---|
552 | if (!hModule)
|
---|
553 | {
|
---|
554 | dwErr = GetLastError();
|
---|
555 | Log(("VBoxTray: Loading module ADVAPI32.DLL failed with last error = %08X\n", dwErr));
|
---|
556 | }
|
---|
557 | else
|
---|
558 | {
|
---|
559 | PSECURITY_DESCRIPTOR pSD;
|
---|
560 | PACL pSacl = NULL;
|
---|
561 | BOOL fSaclPresent = FALSE;
|
---|
562 | BOOL fSaclDefaulted = FALSE;
|
---|
563 |
|
---|
564 | *(uintptr_t *)&pfnConvertStringSecurityDescriptorToSecurityDescriptorA = (uintptr_t)GetProcAddress(hModule, "ConvertStringSecurityDescriptorToSecurityDescriptorA");
|
---|
565 |
|
---|
566 | Log(("VBoxTray: pfnConvertStringSecurityDescriptorToSecurityDescriptorA = %x\n", pfnConvertStringSecurityDescriptorToSecurityDescriptorA));
|
---|
567 | if (pfnConvertStringSecurityDescriptorToSecurityDescriptorA)
|
---|
568 | {
|
---|
569 | fRC = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */
|
---|
570 | SDDL_REVISION_1, &pSD, NULL);
|
---|
571 | if (!fRC)
|
---|
572 | {
|
---|
573 | dwErr = GetLastError();
|
---|
574 | Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with last error = %08X\n", dwErr));
|
---|
575 | }
|
---|
576 | else
|
---|
577 | {
|
---|
578 | fRC = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
|
---|
579 | if (!fRC)
|
---|
580 | {
|
---|
581 | dwErr = GetLastError();
|
---|
582 | Log(("VBoxTray: GetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
|
---|
583 | }
|
---|
584 | else
|
---|
585 | {
|
---|
586 | fRC = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
|
---|
587 | if (!fRC)
|
---|
588 | {
|
---|
589 | dwErr = GetLastError();
|
---|
590 | Log(("VBoxTray: SetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
|
---|
591 | }
|
---|
592 | }
|
---|
593 | }
|
---|
594 | }
|
---|
595 | }
|
---|
596 | }
|
---|
597 |
|
---|
598 | if ( dwErr == ERROR_SUCCESS
|
---|
599 | && gMajorVersion >= 5) /* Only for W2K and up ... */
|
---|
600 | {
|
---|
601 | ghSeamlessWtNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_WT_EVENT_NAME);
|
---|
602 | if (ghSeamlessWtNotifyEvent == NULL)
|
---|
603 | {
|
---|
604 | dwErr = GetLastError();
|
---|
605 | Log(("VBoxTray: CreateEvent for Seamless failed, last error = %08X\n", dwErr));
|
---|
606 | }
|
---|
607 | }
|
---|
608 | }
|
---|
609 | return RTErrConvertFromWin32(dwErr);
|
---|
610 | }
|
---|
611 |
|
---|
612 | static void vboxTrayShutdownSeamless(void)
|
---|
613 | {
|
---|
614 | if (ghSeamlessWtNotifyEvent)
|
---|
615 | {
|
---|
616 | CloseHandle(ghSeamlessWtNotifyEvent);
|
---|
617 | ghSeamlessWtNotifyEvent = NULL;
|
---|
618 | }
|
---|
619 | }
|
---|
620 |
|
---|
621 | static void VBoxTrayCheckDt()
|
---|
622 | {
|
---|
623 | BOOL fOldAllowedState = VBoxConsoleIsAllowed();
|
---|
624 | if (vboxDtHandleEvent())
|
---|
625 | {
|
---|
626 | if (!VBoxConsoleIsAllowed() != !fOldAllowedState)
|
---|
627 | VBoxConsoleEnable(!fOldAllowedState);
|
---|
628 | }
|
---|
629 | }
|
---|
630 |
|
---|
631 | static int vboxTrayServiceMain(void)
|
---|
632 | {
|
---|
633 | int rc = VINF_SUCCESS;
|
---|
634 | Log(("VBoxTray: Entering vboxTrayServiceMain\n"));
|
---|
635 |
|
---|
636 | ghStopSem = CreateEvent(NULL, TRUE, FALSE, NULL);
|
---|
637 | if (ghStopSem == NULL)
|
---|
638 | {
|
---|
639 | rc = RTErrConvertFromWin32(GetLastError());
|
---|
640 | Log(("VBoxTray: CreateEvent for stopping VBoxTray failed, rc=%Rrc\n", rc));
|
---|
641 | }
|
---|
642 | else
|
---|
643 | {
|
---|
644 | /*
|
---|
645 | * Start services listed in the vboxServiceTable.
|
---|
646 | */
|
---|
647 | VBOXSERVICEENV svcEnv;
|
---|
648 | svcEnv.hInstance = ghInstance;
|
---|
649 | svcEnv.hDriver = ghVBoxDriver;
|
---|
650 |
|
---|
651 | /* Initializes disp-if to default (XPDM) mode. */
|
---|
652 | VBoxDispIfInit(&svcEnv.dispIf); /* Cannot fail atm. */
|
---|
653 | #ifdef VBOX_WITH_WDDM
|
---|
654 | /*
|
---|
655 | * For now the display mode will be adjusted to WDDM mode if needed
|
---|
656 | * on display service initialization when it detects the display driver type.
|
---|
657 | */
|
---|
658 | #endif
|
---|
659 |
|
---|
660 | /* Finally start all the built-in services! */
|
---|
661 | rc = vboxTrayStartServices(&svcEnv, vboxServiceTable);
|
---|
662 | if (RT_FAILURE(rc))
|
---|
663 | {
|
---|
664 | /* Terminate service if something went wrong. */
|
---|
665 | vboxTrayStopServices(&svcEnv, vboxServiceTable);
|
---|
666 | }
|
---|
667 | else
|
---|
668 | {
|
---|
669 | rc = vboxTrayCreateTrayIcon();
|
---|
670 | if ( RT_SUCCESS(rc)
|
---|
671 | && gMajorVersion >= 5) /* Only for W2K and up ... */
|
---|
672 | {
|
---|
673 | /* We're ready to create the tooltip balloon.
|
---|
674 | Check in 10 seconds (@todo make seconds configurable) ... */
|
---|
675 | SetTimer(ghwndToolWindow,
|
---|
676 | TIMERID_VBOXTRAY_CHECK_HOSTVERSION,
|
---|
677 | 10 * 1000, /* 10 seconds */
|
---|
678 | NULL /* No timerproc */);
|
---|
679 | }
|
---|
680 |
|
---|
681 | if (RT_SUCCESS(rc))
|
---|
682 | {
|
---|
683 | /* Do the Shared Folders auto-mounting stuff. */
|
---|
684 | rc = VBoxSharedFoldersAutoMount();
|
---|
685 | if (RT_SUCCESS(rc))
|
---|
686 | {
|
---|
687 | /* Report the host that we're up and running! */
|
---|
688 | hlpReportStatus(VBoxGuestFacilityStatus_Active);
|
---|
689 | }
|
---|
690 | }
|
---|
691 |
|
---|
692 | if (RT_SUCCESS(rc))
|
---|
693 | {
|
---|
694 | /* Boost thread priority to make sure we wake up early for seamless window notifications
|
---|
695 | * (not sure if it actually makes any difference though). */
|
---|
696 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
---|
697 |
|
---|
698 | /*
|
---|
699 | * Main execution loop
|
---|
700 | * Wait for the stop semaphore to be posted or a window event to arrive
|
---|
701 | */
|
---|
702 |
|
---|
703 | HANDLE hWaitEvent[3] = {0};
|
---|
704 | DWORD dwEventCount = 0;
|
---|
705 |
|
---|
706 | hWaitEvent[dwEventCount++] = ghStopSem;
|
---|
707 |
|
---|
708 | /* Check if seamless mode is not active and add seamless event to the list */
|
---|
709 | if (0 != ghSeamlessWtNotifyEvent)
|
---|
710 | {
|
---|
711 | hWaitEvent[dwEventCount++] = ghSeamlessWtNotifyEvent;
|
---|
712 | }
|
---|
713 |
|
---|
714 | if (0 != vboxDtGetNotifyEvent())
|
---|
715 | {
|
---|
716 | hWaitEvent[dwEventCount++] = vboxDtGetNotifyEvent();
|
---|
717 | }
|
---|
718 |
|
---|
719 | Log(("VBoxTray: Number of events to wait in main loop: %ld\n", dwEventCount));
|
---|
720 | while (true)
|
---|
721 | {
|
---|
722 | DWORD waitResult = MsgWaitForMultipleObjectsEx(dwEventCount, hWaitEvent, 500, QS_ALLINPUT, 0);
|
---|
723 | waitResult = waitResult - WAIT_OBJECT_0;
|
---|
724 |
|
---|
725 | /* Only enable for message debugging, lots of traffic! */
|
---|
726 | //Log(("VBoxTray: Wait result = %ld\n", waitResult));
|
---|
727 |
|
---|
728 | if (waitResult == 0)
|
---|
729 | {
|
---|
730 | Log(("VBoxTray: Event 'Exit' triggered\n"));
|
---|
731 | /* exit */
|
---|
732 | break;
|
---|
733 | }
|
---|
734 | else
|
---|
735 | {
|
---|
736 | BOOL fHandled = FALSE;
|
---|
737 | if (waitResult < RT_ELEMENTS(hWaitEvent))
|
---|
738 | {
|
---|
739 | if (hWaitEvent[waitResult])
|
---|
740 | {
|
---|
741 | if (hWaitEvent[waitResult] == ghSeamlessWtNotifyEvent)
|
---|
742 | {
|
---|
743 | Log(("VBoxTray: Event 'Seamless' triggered\n"));
|
---|
744 |
|
---|
745 | /* seamless window notification */
|
---|
746 | VBoxSeamlessCheckWindows();
|
---|
747 | fHandled = TRUE;
|
---|
748 | }
|
---|
749 | else if (hWaitEvent[waitResult] == vboxDtGetNotifyEvent())
|
---|
750 | {
|
---|
751 | Log(("VBoxTray: Event 'Dt' triggered\n"));
|
---|
752 | VBoxTrayCheckDt();
|
---|
753 | fHandled = TRUE;
|
---|
754 | }
|
---|
755 | }
|
---|
756 | }
|
---|
757 |
|
---|
758 | if (!fHandled)
|
---|
759 | {
|
---|
760 | /* timeout or a window message, handle it */
|
---|
761 | MSG msg;
|
---|
762 | while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
---|
763 | {
|
---|
764 | Log(("VBoxTray: msg %p\n", msg.message));
|
---|
765 | if (msg.message == WM_QUIT)
|
---|
766 | {
|
---|
767 | Log(("VBoxTray: WM_QUIT!\n"));
|
---|
768 | SetEvent(ghStopSem);
|
---|
769 | }
|
---|
770 | TranslateMessage(&msg);
|
---|
771 | DispatchMessage(&msg);
|
---|
772 | }
|
---|
773 | }
|
---|
774 | }
|
---|
775 | }
|
---|
776 | Log(("VBoxTray: Returned from main loop, exiting ...\n"));
|
---|
777 | }
|
---|
778 | Log(("VBoxTray: Waiting for services to stop ...\n"));
|
---|
779 | vboxTrayStopServices(&svcEnv, vboxServiceTable);
|
---|
780 | } /* Services started */
|
---|
781 | CloseHandle(ghStopSem);
|
---|
782 | } /* Stop event created */
|
---|
783 |
|
---|
784 | vboxTrayRemoveTrayIcon();
|
---|
785 |
|
---|
786 | Log(("VBoxTray: Leaving vboxTrayServiceMain with rc=%Rrc\n", rc));
|
---|
787 | return rc;
|
---|
788 | }
|
---|
789 |
|
---|
790 | /**
|
---|
791 | * Main function
|
---|
792 | */
|
---|
793 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
---|
794 | {
|
---|
795 | /* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */
|
---|
796 | HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxTray");
|
---|
797 | if ( hMutexAppRunning != NULL
|
---|
798 | && GetLastError() == ERROR_ALREADY_EXISTS)
|
---|
799 | {
|
---|
800 | /* Close the mutex for this application instance. */
|
---|
801 | CloseHandle (hMutexAppRunning);
|
---|
802 | hMutexAppRunning = NULL;
|
---|
803 | return 0;
|
---|
804 | }
|
---|
805 |
|
---|
806 | LogRel(("VBoxTray: %s r%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr()));
|
---|
807 |
|
---|
808 | int rc = RTR3InitExeNoArguments(0);
|
---|
809 | if (RT_SUCCESS(rc))
|
---|
810 | {
|
---|
811 | rc = VbglR3Init();
|
---|
812 | if (RT_SUCCESS(rc))
|
---|
813 | rc = vboxTrayOpenBaseDriver();
|
---|
814 | }
|
---|
815 |
|
---|
816 | if (RT_SUCCESS(rc))
|
---|
817 | {
|
---|
818 | /* Save instance handle. */
|
---|
819 | ghInstance = hInstance;
|
---|
820 |
|
---|
821 | hlpReportStatus(VBoxGuestFacilityStatus_Init);
|
---|
822 | rc = vboxTrayCreateToolWindow();
|
---|
823 | if (RT_SUCCESS(rc))
|
---|
824 | {
|
---|
825 | VBoxCapsInit();
|
---|
826 |
|
---|
827 | rc = vboxStInit(ghwndToolWindow);
|
---|
828 | if (!RT_SUCCESS(rc))
|
---|
829 | {
|
---|
830 | WARN(("VBoxTray: vboxStInit failed, rc %d"));
|
---|
831 | /* ignore the St Init failure. this can happen for < XP win that do not support WTS API
|
---|
832 | * in that case the session is treated as active connected to the physical console
|
---|
833 | * (i.e. fallback to the old behavior that was before introduction of VBoxSt) */
|
---|
834 | Assert(vboxStIsActiveConsole());
|
---|
835 | }
|
---|
836 |
|
---|
837 | rc = vboxDtInit();
|
---|
838 | if (!RT_SUCCESS(rc))
|
---|
839 | {
|
---|
840 | WARN(("VBoxTray: vboxDtInit failed, rc %d"));
|
---|
841 | /* ignore the Dt Init failure. this can happen for < XP win that do not support WTS API
|
---|
842 | * in that case the session is treated as active connected to the physical console
|
---|
843 | * (i.e. fallback to the old behavior that was before introduction of VBoxSt) */
|
---|
844 | Assert(vboxDtIsInputDesktop());
|
---|
845 | }
|
---|
846 |
|
---|
847 | rc = vboxTraySetupSeamless();
|
---|
848 | if (RT_SUCCESS(rc))
|
---|
849 | {
|
---|
850 | Log(("VBoxTray: Init successful\n"));
|
---|
851 | rc = vboxTrayServiceMain();
|
---|
852 | if (RT_SUCCESS(rc))
|
---|
853 | hlpReportStatus(VBoxGuestFacilityStatus_Terminating);
|
---|
854 | vboxTrayShutdownSeamless();
|
---|
855 | }
|
---|
856 |
|
---|
857 | /* it should be safe to call vboxDtTerm even if vboxStInit above failed */
|
---|
858 | vboxDtTerm();
|
---|
859 |
|
---|
860 | /* it should be safe to call vboxStTerm even if vboxStInit above failed */
|
---|
861 | vboxStTerm();
|
---|
862 |
|
---|
863 | VBoxCapsTerm();
|
---|
864 |
|
---|
865 | vboxTrayDestroyToolWindow();
|
---|
866 | }
|
---|
867 | if (RT_SUCCESS(rc))
|
---|
868 | hlpReportStatus(VBoxGuestFacilityStatus_Terminated);
|
---|
869 | }
|
---|
870 |
|
---|
871 | if (RT_FAILURE(rc))
|
---|
872 | {
|
---|
873 | LogRel(("VBoxTray: Error while starting, rc=%Rrc\n", rc));
|
---|
874 | hlpReportStatus(VBoxGuestFacilityStatus_Failed);
|
---|
875 | }
|
---|
876 | LogRel(("VBoxTray: Ended\n"));
|
---|
877 | vboxTrayCloseBaseDriver();
|
---|
878 |
|
---|
879 | /* Release instance mutex. */
|
---|
880 | if (hMutexAppRunning != NULL)
|
---|
881 | {
|
---|
882 | CloseHandle(hMutexAppRunning);
|
---|
883 | hMutexAppRunning = NULL;
|
---|
884 | }
|
---|
885 |
|
---|
886 | VbglR3Term();
|
---|
887 | return RT_SUCCESS(rc) ? 0 : 1;
|
---|
888 | }
|
---|
889 |
|
---|
890 | /**
|
---|
891 | * Window procedure for our tool window
|
---|
892 | */
|
---|
893 | static LRESULT CALLBACK vboxToolWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
894 | {
|
---|
895 | switch (uMsg)
|
---|
896 | {
|
---|
897 | case WM_CREATE:
|
---|
898 | {
|
---|
899 | Log(("VBoxTray: Tool window created\n"));
|
---|
900 |
|
---|
901 | int rc = vboxTrayRegisterGlobalMessages(&s_vboxGlobalMessageTable[0]);
|
---|
902 | if (RT_FAILURE(rc))
|
---|
903 | Log(("VBoxTray: Error registering global window messages, rc=%Rrc\n", rc));
|
---|
904 | return 0;
|
---|
905 | }
|
---|
906 |
|
---|
907 | case WM_CLOSE:
|
---|
908 | return 0;
|
---|
909 |
|
---|
910 | case WM_DESTROY:
|
---|
911 | Log(("VBoxTray: Tool window destroyed\n"));
|
---|
912 | KillTimer(ghwndToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
|
---|
913 | return 0;
|
---|
914 |
|
---|
915 | case WM_TIMER:
|
---|
916 | if (VBoxCapsCheckTimer(wParam))
|
---|
917 | return 0;
|
---|
918 | if (vboxDtCheckTimer(wParam))
|
---|
919 | return 0;
|
---|
920 | if (vboxStCheckTimer(wParam))
|
---|
921 | return 0;
|
---|
922 |
|
---|
923 | switch (wParam)
|
---|
924 | {
|
---|
925 | case TIMERID_VBOXTRAY_CHECK_HOSTVERSION:
|
---|
926 | if (RT_SUCCESS(VBoxCheckHostVersion()))
|
---|
927 | {
|
---|
928 | /* After successful run we don't need to check again. */
|
---|
929 | KillTimer(ghwndToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
|
---|
930 | }
|
---|
931 | return 0;
|
---|
932 |
|
---|
933 | default:
|
---|
934 | break;
|
---|
935 | }
|
---|
936 | break; /* Make sure other timers get processed the usual way! */
|
---|
937 |
|
---|
938 | case WM_VBOXTRAY_TRAY_ICON:
|
---|
939 | switch (lParam)
|
---|
940 | {
|
---|
941 | case WM_LBUTTONDBLCLK:
|
---|
942 | break;
|
---|
943 |
|
---|
944 | case WM_RBUTTONDOWN:
|
---|
945 | break;
|
---|
946 | }
|
---|
947 | return 0;
|
---|
948 |
|
---|
949 | case WM_VBOX_SEAMLESS_ENABLE:
|
---|
950 | VBoxCapsEntryFuncStateSet(VBOXCAPS_ENTRY_IDX_SEAMLESS, VBOXCAPS_ENTRY_FUNCSTATE_STARTED);
|
---|
951 | return 0;
|
---|
952 |
|
---|
953 | case WM_VBOX_SEAMLESS_DISABLE:
|
---|
954 | VBoxCapsEntryFuncStateSet(VBOXCAPS_ENTRY_IDX_SEAMLESS, VBOXCAPS_ENTRY_FUNCSTATE_SUPPORTED);
|
---|
955 | return 0;
|
---|
956 |
|
---|
957 | case WM_VBOX_SEAMLESS_UPDATE:
|
---|
958 | if (VBoxCapsEntryIsEnabled(VBOXCAPS_ENTRY_IDX_SEAMLESS))
|
---|
959 | VBoxSeamlessCheckWindows();
|
---|
960 | return 0;
|
---|
961 |
|
---|
962 | case WM_VBOX_GRAPHICS_SUPPORTED:
|
---|
963 | VBoxGrapicsSetSupported(TRUE);
|
---|
964 | return 0;
|
---|
965 |
|
---|
966 | case WM_VBOX_GRAPHICS_UNSUPPORTED:
|
---|
967 | VBoxGrapicsSetSupported(FALSE);
|
---|
968 | return 0;
|
---|
969 |
|
---|
970 | case WM_VBOXTRAY_VM_RESTORED:
|
---|
971 | VBoxRestoreSession();
|
---|
972 | return 0;
|
---|
973 |
|
---|
974 | case WM_VBOXTRAY_VRDP_CHECK:
|
---|
975 | VBoxRestoreCheckVRDP();
|
---|
976 | return 0;
|
---|
977 |
|
---|
978 | case WM_WTSSESSION_CHANGE:
|
---|
979 | {
|
---|
980 | BOOL fOldAllowedState = VBoxConsoleIsAllowed();
|
---|
981 | if (vboxStHandleEvent(wParam, lParam))
|
---|
982 | {
|
---|
983 | if (!VBoxConsoleIsAllowed() != !fOldAllowedState)
|
---|
984 | VBoxConsoleEnable(!fOldAllowedState);
|
---|
985 | }
|
---|
986 | return 0;
|
---|
987 | }
|
---|
988 | default:
|
---|
989 |
|
---|
990 | /* Handle all globally registered window messages. */
|
---|
991 | if (vboxTrayHandleGlobalMessages(&s_vboxGlobalMessageTable[0], uMsg,
|
---|
992 | wParam, lParam))
|
---|
993 | {
|
---|
994 | return 0; /* We handled the message. @todo Add return value!*/
|
---|
995 | }
|
---|
996 | break; /* We did not handle the message, dispatch to DefWndProc. */
|
---|
997 | }
|
---|
998 |
|
---|
999 | /* Only if message was *not* handled by our switch above, dispatch
|
---|
1000 | * to DefWindowProc. */
|
---|
1001 | return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | /* St (session [state] tracking) functionality API impl */
|
---|
1005 |
|
---|
1006 | typedef struct VBOXST
|
---|
1007 | {
|
---|
1008 | HWND hWTSAPIWnd;
|
---|
1009 | HMODULE hWTSAPI32;
|
---|
1010 | BOOL fIsConsole;
|
---|
1011 | WTS_CONNECTSTATE_CLASS enmConnectState;
|
---|
1012 | UINT_PTR idDelayedInitTimer;
|
---|
1013 | BOOL (WINAPI * pfnWTSRegisterSessionNotification)(HWND hWnd, DWORD dwFlags);
|
---|
1014 | BOOL (WINAPI * pfnWTSUnRegisterSessionNotification)(HWND hWnd);
|
---|
1015 | BOOL (WINAPI * pfnWTSQuerySessionInformationA)(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPTSTR *ppBuffer, DWORD *pBytesReturned);
|
---|
1016 | } VBOXST;
|
---|
1017 |
|
---|
1018 | static VBOXST gVBoxSt;
|
---|
1019 |
|
---|
1020 | static int vboxStCheckState()
|
---|
1021 | {
|
---|
1022 | int rc = VINF_SUCCESS;
|
---|
1023 | WTS_CONNECTSTATE_CLASS *penmConnectState = NULL;
|
---|
1024 | USHORT *pProtocolType = NULL;
|
---|
1025 | DWORD cbBuf = 0;
|
---|
1026 | if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSConnectState, (LPTSTR *)&penmConnectState, &cbBuf))
|
---|
1027 | {
|
---|
1028 | if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType, (LPTSTR *)&pProtocolType, &cbBuf))
|
---|
1029 | {
|
---|
1030 | gVBoxSt.fIsConsole = (*pProtocolType == 0);
|
---|
1031 | gVBoxSt.enmConnectState = *penmConnectState;
|
---|
1032 | return VINF_SUCCESS;
|
---|
1033 | }
|
---|
1034 | else
|
---|
1035 | {
|
---|
1036 | DWORD dwErr = GetLastError();
|
---|
1037 | WARN(("VBoxTray: WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr));
|
---|
1038 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1039 | }
|
---|
1040 | }
|
---|
1041 | else
|
---|
1042 | {
|
---|
1043 | DWORD dwErr = GetLastError();
|
---|
1044 | WARN(("VBoxTray: WTSQuerySessionInformationA WTSConnectState failed, error = %08X\n", dwErr));
|
---|
1045 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | /* failure branch, set to "console-active" state */
|
---|
1049 | gVBoxSt.fIsConsole = TRUE;
|
---|
1050 | gVBoxSt.enmConnectState = WTSActive;
|
---|
1051 |
|
---|
1052 | return rc;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | static int vboxStInit(HWND hWnd)
|
---|
1056 | {
|
---|
1057 | int rc = VINF_SUCCESS;
|
---|
1058 | memset(&gVBoxSt, 0, sizeof (gVBoxSt));
|
---|
1059 | gVBoxSt.hWTSAPI32 = LoadLibrary("WTSAPI32.DLL");
|
---|
1060 | if (gVBoxSt.hWTSAPI32)
|
---|
1061 | {
|
---|
1062 | *(uintptr_t *)&gVBoxSt.pfnWTSRegisterSessionNotification = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSRegisterSessionNotification");
|
---|
1063 | if (!gVBoxSt.pfnWTSRegisterSessionNotification)
|
---|
1064 | {
|
---|
1065 | WARN(("VBoxTray: WTSRegisterSessionNotification not found\n"));
|
---|
1066 | rc = VERR_NOT_SUPPORTED;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | *(uintptr_t *)&gVBoxSt.pfnWTSUnRegisterSessionNotification = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSUnRegisterSessionNotification");
|
---|
1070 | if (!gVBoxSt.pfnWTSUnRegisterSessionNotification)
|
---|
1071 | {
|
---|
1072 | WARN(("VBoxTray: WTSUnRegisterSessionNotification not found\n"));
|
---|
1073 | rc = VERR_NOT_SUPPORTED;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | *(uintptr_t *)&gVBoxSt.pfnWTSQuerySessionInformationA = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSQuerySessionInformationA");
|
---|
1077 | if (!gVBoxSt.pfnWTSQuerySessionInformationA)
|
---|
1078 | {
|
---|
1079 | WARN(("VBoxTray: WTSQuerySessionInformationA not found\n"));
|
---|
1080 | rc = VERR_NOT_SUPPORTED;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | if (rc == VINF_SUCCESS)
|
---|
1084 | {
|
---|
1085 | gVBoxSt.hWTSAPIWnd = hWnd;
|
---|
1086 | if (!gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION))
|
---|
1087 | {
|
---|
1088 | DWORD dwErr = GetLastError();
|
---|
1089 | WARN(("VBoxTray: WTSRegisterSessionNotification failed, error = %08X\n", dwErr));
|
---|
1090 | if (dwErr == RPC_S_INVALID_BINDING)
|
---|
1091 | {
|
---|
1092 | gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER, 500, (TIMERPROC)NULL);
|
---|
1093 | rc = VINF_SUCCESS;
|
---|
1094 | }
|
---|
1095 | else
|
---|
1096 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | if (RT_SUCCESS(rc))
|
---|
1100 | {
|
---|
1101 | vboxStCheckState();
|
---|
1102 | return VINF_SUCCESS;
|
---|
1103 | }
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | FreeLibrary(gVBoxSt.hWTSAPI32);
|
---|
1107 | }
|
---|
1108 | else
|
---|
1109 | {
|
---|
1110 | DWORD dwErr = GetLastError();
|
---|
1111 | WARN(("VBoxTray: WTSAPI32 load failed, error = %08X\n", dwErr));
|
---|
1112 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | memset(&gVBoxSt, 0, sizeof (gVBoxSt));
|
---|
1116 | gVBoxSt.fIsConsole = TRUE;
|
---|
1117 | gVBoxSt.enmConnectState = WTSActive;
|
---|
1118 | return rc;
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | static void vboxStTerm()
|
---|
1122 | {
|
---|
1123 | if (gVBoxSt.hWTSAPIWnd)
|
---|
1124 | {
|
---|
1125 | WARN(("VBoxTray: vboxStTerm called for non-initialized St\n"));
|
---|
1126 | return;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | if (gVBoxSt.idDelayedInitTimer)
|
---|
1130 | {
|
---|
1131 | /* notification is not registered, just kill timer */
|
---|
1132 | KillTimer(gVBoxSt.hWTSAPIWnd, gVBoxSt.idDelayedInitTimer);
|
---|
1133 | gVBoxSt.idDelayedInitTimer = 0;
|
---|
1134 | }
|
---|
1135 | else
|
---|
1136 | {
|
---|
1137 | if (!gVBoxSt.pfnWTSUnRegisterSessionNotification(gVBoxSt.hWTSAPIWnd))
|
---|
1138 | {
|
---|
1139 | DWORD dwErr = GetLastError();
|
---|
1140 | WARN(("VBoxTray: WTSAPI32 load failed, error = %08X\n", dwErr));
|
---|
1141 | }
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | FreeLibrary(gVBoxSt.hWTSAPI32);
|
---|
1145 | memset(&gVBoxSt, 0, sizeof (gVBoxSt));
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | #define VBOXST_DBG_MAKECASE(_val) case _val: return #_val;
|
---|
1149 |
|
---|
1150 | static const char* vboxStDbgGetString(DWORD val)
|
---|
1151 | {
|
---|
1152 | switch (val)
|
---|
1153 | {
|
---|
1154 | VBOXST_DBG_MAKECASE(WTS_CONSOLE_CONNECT);
|
---|
1155 | VBOXST_DBG_MAKECASE(WTS_CONSOLE_DISCONNECT);
|
---|
1156 | VBOXST_DBG_MAKECASE(WTS_REMOTE_CONNECT);
|
---|
1157 | VBOXST_DBG_MAKECASE(WTS_REMOTE_DISCONNECT);
|
---|
1158 | VBOXST_DBG_MAKECASE(WTS_SESSION_LOGON);
|
---|
1159 | VBOXST_DBG_MAKECASE(WTS_SESSION_LOGOFF);
|
---|
1160 | VBOXST_DBG_MAKECASE(WTS_SESSION_LOCK);
|
---|
1161 | VBOXST_DBG_MAKECASE(WTS_SESSION_UNLOCK);
|
---|
1162 | VBOXST_DBG_MAKECASE(WTS_SESSION_REMOTE_CONTROL);
|
---|
1163 | default:
|
---|
1164 | WARN(("VBoxTray: invalid WTS state %d", val));
|
---|
1165 | return "Unknown";
|
---|
1166 | }
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | static BOOL vboxStCheckTimer(WPARAM wEvent)
|
---|
1170 | {
|
---|
1171 | if (wEvent != gVBoxSt.idDelayedInitTimer)
|
---|
1172 | return FALSE;
|
---|
1173 |
|
---|
1174 | if (gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION))
|
---|
1175 | {
|
---|
1176 | KillTimer(gVBoxSt.hWTSAPIWnd, gVBoxSt.idDelayedInitTimer);
|
---|
1177 | gVBoxSt.idDelayedInitTimer = 0;
|
---|
1178 | }
|
---|
1179 | else
|
---|
1180 | {
|
---|
1181 | DWORD dwErr = GetLastError();
|
---|
1182 | WARN(("VBoxTray: timer WTSRegisterSessionNotification failed, error = %08X\n", dwErr));
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | vboxStCheckState();
|
---|
1186 | }
|
---|
1187 |
|
---|
1188 |
|
---|
1189 | static BOOL vboxStHandleEvent(WPARAM wEvent, LPARAM SessionID)
|
---|
1190 | {
|
---|
1191 | WARN(("VBoxTray: WTS Event: %s\n", vboxStDbgGetString(wEvent)));
|
---|
1192 | BOOL fOldIsActiveConsole = vboxStIsActiveConsole();
|
---|
1193 |
|
---|
1194 | vboxStCheckState();
|
---|
1195 |
|
---|
1196 | return !vboxStIsActiveConsole() != !fOldIsActiveConsole;
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | static BOOL vboxStIsActiveConsole()
|
---|
1200 | {
|
---|
1201 | return (gVBoxSt.enmConnectState == WTSActive && gVBoxSt.fIsConsole);
|
---|
1202 | }
|
---|
1203 |
|
---|
1204 | /*
|
---|
1205 | * Dt (desktop [state] tracking) functionality API impl
|
---|
1206 | *
|
---|
1207 | * !!!NOTE: this API is NOT thread-safe!!!
|
---|
1208 | * */
|
---|
1209 |
|
---|
1210 | typedef struct VBOXDT
|
---|
1211 | {
|
---|
1212 | HANDLE hNotifyEvent;
|
---|
1213 | BOOL fIsInputDesktop;
|
---|
1214 | UINT_PTR idTimer;
|
---|
1215 | HMODULE hHookModule;
|
---|
1216 | BOOL (* pfnVBoxHookInstallActiveDesktopTracker)(HMODULE hDll);
|
---|
1217 | BOOL (* pfnVBoxHookRemoveActiveDesktopTracker)();
|
---|
1218 | HMODULE hUSER32;
|
---|
1219 | HDESK (WINAPI * pfnGetThreadDesktop)(DWORD dwThreadId);
|
---|
1220 | HDESK (WINAPI * pfnOpenInputDesktop)(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);
|
---|
1221 | BOOL (WINAPI * pfnCloseDesktop)(HDESK hDesktop);
|
---|
1222 | } VBOXDT;
|
---|
1223 |
|
---|
1224 | static VBOXDT gVBoxDt;
|
---|
1225 |
|
---|
1226 | static BOOL vboxDtCalculateIsInputDesktop()
|
---|
1227 | {
|
---|
1228 | BOOL fIsInputDt = FALSE;
|
---|
1229 | HDESK hInput = gVBoxDt.pfnOpenInputDesktop(0, FALSE, DESKTOP_CREATEWINDOW);
|
---|
1230 | if (hInput)
|
---|
1231 | {
|
---|
1232 | // DWORD dwThreadId = GetCurrentThreadId();
|
---|
1233 | // HDESK hThreadDt = gVBoxDt.pfnGetThreadDesktop(dwThreadId);
|
---|
1234 | // if (hThreadDt)
|
---|
1235 | // {
|
---|
1236 | fIsInputDt = TRUE;
|
---|
1237 | // }
|
---|
1238 | // else
|
---|
1239 | // {
|
---|
1240 | // DWORD dwErr = GetLastError();
|
---|
1241 | // WARN(("VBoxTray: pfnGetThreadDesktop for Seamless failed, last error = %08X\n", dwErr));
|
---|
1242 | // }
|
---|
1243 |
|
---|
1244 | gVBoxDt.pfnCloseDesktop(hInput);
|
---|
1245 | }
|
---|
1246 | else
|
---|
1247 | {
|
---|
1248 | DWORD dwErr = GetLastError();
|
---|
1249 | // WARN(("VBoxTray: pfnOpenInputDesktop for Seamless failed, last error = %08X\n", dwErr));
|
---|
1250 | }
|
---|
1251 | return fIsInputDt;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | static BOOL vboxDtCheckTimer(WPARAM wParam)
|
---|
1255 | {
|
---|
1256 | if (wParam != gVBoxDt.idTimer)
|
---|
1257 | return FALSE;
|
---|
1258 |
|
---|
1259 | VBoxTrayCheckDt();
|
---|
1260 |
|
---|
1261 | return TRUE;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | static int vboxDtInit()
|
---|
1265 | {
|
---|
1266 | int rc = VINF_SUCCESS;
|
---|
1267 | OSVERSIONINFO info;
|
---|
1268 | gMajorVersion = 5; /* Default to Windows XP. */
|
---|
1269 | info.dwOSVersionInfoSize = sizeof(info);
|
---|
1270 | if (GetVersionEx(&info))
|
---|
1271 | {
|
---|
1272 | WARN(("VBoxTray: Windows version %ld.%ld\n", info.dwMajorVersion, info.dwMinorVersion));
|
---|
1273 | gMajorVersion = info.dwMajorVersion;
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | memset(&gVBoxDt, 0, sizeof (gVBoxDt));
|
---|
1277 |
|
---|
1278 | gVBoxDt.hNotifyEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME);
|
---|
1279 | if (gVBoxDt.hNotifyEvent != NULL)
|
---|
1280 | {
|
---|
1281 | gVBoxDt.hHookModule = LoadLibrary(VBOXHOOK_DLL_NAME);
|
---|
1282 | if (gVBoxDt.hHookModule)
|
---|
1283 | {
|
---|
1284 | *(uintptr_t *)&gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
|
---|
1285 | if (!gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker)
|
---|
1286 | {
|
---|
1287 | WARN(("VBoxTray: VBoxHookInstallActiveDesktopTracker not found\n"));
|
---|
1288 | rc = VERR_NOT_SUPPORTED;
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 | *(uintptr_t *)&gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
|
---|
1292 | if (!gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker)
|
---|
1293 | {
|
---|
1294 | WARN(("VBoxTray: VBoxHookRemoveActiveDesktopTracker not found\n"));
|
---|
1295 | rc = VERR_NOT_SUPPORTED;
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | if (VINF_SUCCESS == rc)
|
---|
1299 | {
|
---|
1300 | gVBoxDt.hUSER32 = LoadLibrary("User32.dll");
|
---|
1301 | if (gVBoxDt.hUSER32)
|
---|
1302 | {
|
---|
1303 | *(uintptr_t *)&gVBoxDt.pfnGetThreadDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "GetThreadDesktop");
|
---|
1304 | if (!gVBoxDt.pfnGetThreadDesktop)
|
---|
1305 | {
|
---|
1306 | WARN(("VBoxTray: GetThreadDesktop not found\n"));
|
---|
1307 | rc = VERR_NOT_SUPPORTED;
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | *(uintptr_t *)&gVBoxDt.pfnOpenInputDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "OpenInputDesktop");
|
---|
1311 | if (!gVBoxDt.pfnOpenInputDesktop)
|
---|
1312 | {
|
---|
1313 | WARN(("VBoxTray: OpenInputDesktop not found\n"));
|
---|
1314 | rc = VERR_NOT_SUPPORTED;
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | *(uintptr_t *)&gVBoxDt.pfnCloseDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "CloseDesktop");
|
---|
1318 | if (!gVBoxDt.pfnCloseDesktop)
|
---|
1319 | {
|
---|
1320 | WARN(("VBoxTray: CloseDesktop not found\n"));
|
---|
1321 | rc = VERR_NOT_SUPPORTED;
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | if (VINF_SUCCESS == rc)
|
---|
1325 | {
|
---|
1326 | BOOL bRc = FALSE;
|
---|
1327 | /* For Vista and up we need to change the integrity of the security descriptor, too. */
|
---|
1328 | if (gMajorVersion >= 6)
|
---|
1329 | {
|
---|
1330 | bRc = gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker(gVBoxDt.hHookModule);
|
---|
1331 | if (!bRc)
|
---|
1332 | {
|
---|
1333 | DWORD dwErr = GetLastError();
|
---|
1334 | WARN(("VBoxTray: pfnVBoxHookInstallActiveDesktopTracker failed, last error = %08X\n", dwErr));
|
---|
1335 | }
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | if (!bRc)
|
---|
1339 | {
|
---|
1340 | gVBoxDt.idTimer = SetTimer(ghwndToolWindow, TIMERID_VBOXTRAY_DT_TIMER, 500, (TIMERPROC)NULL);
|
---|
1341 | if (!gVBoxDt.idTimer)
|
---|
1342 | {
|
---|
1343 | DWORD dwErr = GetLastError();
|
---|
1344 | WARN(("VBoxTray: SetTimer error %08X\n", dwErr));
|
---|
1345 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1346 | }
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | if (RT_SUCCESS(rc))
|
---|
1350 | {
|
---|
1351 | gVBoxDt.fIsInputDesktop = vboxDtCalculateIsInputDesktop();
|
---|
1352 | return VINF_SUCCESS;
|
---|
1353 | }
|
---|
1354 | }
|
---|
1355 | FreeLibrary(gVBoxDt.hUSER32);
|
---|
1356 | }
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | FreeLibrary(gVBoxDt.hHookModule);
|
---|
1360 | }
|
---|
1361 | else
|
---|
1362 | {
|
---|
1363 | DWORD dwErr = GetLastError();
|
---|
1364 | WARN(("VBoxTray: CreateEvent for Seamless failed, last error = %08X\n", dwErr));
|
---|
1365 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | CloseHandle(gVBoxDt.hNotifyEvent);
|
---|
1369 | }
|
---|
1370 | else
|
---|
1371 | {
|
---|
1372 | DWORD dwErr = GetLastError();
|
---|
1373 | WARN(("VBoxTray: CreateEvent for Seamless failed, last error = %08X\n", dwErr));
|
---|
1374 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1375 | }
|
---|
1376 |
|
---|
1377 |
|
---|
1378 | memset(&gVBoxDt, 0, sizeof (gVBoxDt));
|
---|
1379 | gVBoxDt.fIsInputDesktop = TRUE;
|
---|
1380 |
|
---|
1381 | return rc;
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | static void vboxDtTerm()
|
---|
1385 | {
|
---|
1386 | if (!gVBoxDt.hHookModule)
|
---|
1387 | return;
|
---|
1388 |
|
---|
1389 | gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker();
|
---|
1390 |
|
---|
1391 | FreeLibrary(gVBoxDt.hUSER32);
|
---|
1392 | FreeLibrary(gVBoxDt.hHookModule);
|
---|
1393 | CloseHandle(gVBoxDt.hNotifyEvent);
|
---|
1394 |
|
---|
1395 | memset(&gVBoxDt, 0, sizeof (gVBoxDt));
|
---|
1396 | }
|
---|
1397 | /* @returns true on "IsInputDesktop" state change */
|
---|
1398 | static BOOL vboxDtHandleEvent()
|
---|
1399 | {
|
---|
1400 | BOOL fIsInputDesktop = gVBoxDt.fIsInputDesktop;
|
---|
1401 | gVBoxDt.fIsInputDesktop = vboxDtCalculateIsInputDesktop();
|
---|
1402 | return !fIsInputDesktop != !gVBoxDt.fIsInputDesktop;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | static HANDLE vboxDtGetNotifyEvent()
|
---|
1406 | {
|
---|
1407 | return gVBoxDt.hNotifyEvent;
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | /* @returns true iff the application (VBoxTray) desktop is input */
|
---|
1411 | static BOOL vboxDtIsInputDesktop()
|
---|
1412 | {
|
---|
1413 | return gVBoxDt.fIsInputDesktop;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 |
|
---|
1417 | /* we need to perform Acquire/Release using the file handled we use for rewuesting events from VBoxGuest
|
---|
1418 | * otherwise Acquisition mechanism will treat us as different client and will not propagate necessary requests
|
---|
1419 | * */
|
---|
1420 | static int VBoxAcquireGuestCaps(uint32_t fOr, uint32_t fNot)
|
---|
1421 | {
|
---|
1422 | DWORD cbReturned = 0;
|
---|
1423 | VBoxGuestCapsAquire Info;
|
---|
1424 | Info.rc = VERR_NOT_IMPLEMENTED;
|
---|
1425 | Info.u32OrMask = fOr;
|
---|
1426 | Info.u32NotMask = fNot;
|
---|
1427 | if (!DeviceIoControl(ghVBoxDriver, VBOXGUEST_IOCTL_GUEST_CAPS_ACQUIRE, &Info, sizeof(Info), &Info, sizeof(Info), &cbReturned, NULL))
|
---|
1428 | {
|
---|
1429 | DWORD LastErr = GetLastError();
|
---|
1430 | WARN(("DeviceIoControl VBOXGUEST_IOCTL_GUEST_CAPS_ACQUIRE failed LastErr %d", LastErr));
|
---|
1431 | return RTErrConvertFromWin32(LastErr);
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | int rc = Info.rc;
|
---|
1435 | if (!RT_SUCCESS(rc))
|
---|
1436 | {
|
---|
1437 | WARN(("VBOXGUEST_IOCTL_GUEST_CAPS_ACQUIRE failed rc %d", rc));
|
---|
1438 | return rc;
|
---|
1439 | }
|
---|
1440 |
|
---|
1441 | return rc;
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 | typedef enum VBOXCAPS_ENTRY_ACSTATE
|
---|
1445 | {
|
---|
1446 | /* the given cap is released */
|
---|
1447 | VBOXCAPS_ENTRY_ACSTATE_RELEASED = 0,
|
---|
1448 | /* the given cap acquisition is in progress */
|
---|
1449 | VBOXCAPS_ENTRY_ACSTATE_ACQUIRING,
|
---|
1450 | /* the given cap is acquired */
|
---|
1451 | VBOXCAPS_ENTRY_ACSTATE_ACQUIRED
|
---|
1452 | } VBOXCAPS_ENTRY_ACSTATE;
|
---|
1453 |
|
---|
1454 |
|
---|
1455 | struct VBOXCAPS_ENTRY;
|
---|
1456 | struct VBOXCAPS;
|
---|
1457 |
|
---|
1458 | typedef DECLCALLBACKPTR(void, PFNVBOXCAPS_ENTRY_ON_ENABLE)(struct VBOXCAPS *pConsole, struct VBOXCAPS_ENTRY *pCap, BOOL fEnabled);
|
---|
1459 |
|
---|
1460 | typedef struct VBOXCAPS_ENTRY
|
---|
1461 | {
|
---|
1462 | uint32_t fCap;
|
---|
1463 | uint32_t iCap;
|
---|
1464 | VBOXCAPS_ENTRY_FUNCSTATE enmFuncState;
|
---|
1465 | VBOXCAPS_ENTRY_ACSTATE enmAcState;
|
---|
1466 | PFNVBOXCAPS_ENTRY_ON_ENABLE pfnOnEnable;
|
---|
1467 | } VBOXCAPS_ENTRY;
|
---|
1468 |
|
---|
1469 |
|
---|
1470 | typedef struct VBOXCAPS
|
---|
1471 | {
|
---|
1472 | UINT_PTR idTimer;
|
---|
1473 | VBOXCAPS_ENTRY aCaps[VBOXCAPS_ENTRY_IDX_COUNT];
|
---|
1474 | } VBOXCAPS;
|
---|
1475 |
|
---|
1476 | static VBOXCAPS gVBoxCaps;
|
---|
1477 |
|
---|
1478 | static DECLCALLBACK(void) vboxCapsOnEnableSeamles(struct VBOXCAPS *pConsole, struct VBOXCAPS_ENTRY *pCap, BOOL fEnabled)
|
---|
1479 | {
|
---|
1480 | if (fEnabled)
|
---|
1481 | {
|
---|
1482 | Assert(pCap->enmAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED);
|
---|
1483 | Assert(pCap->enmFuncState == VBOXCAPS_ENTRY_FUNCSTATE_STARTED);
|
---|
1484 | VBoxSeamlessInstallHook();
|
---|
1485 | }
|
---|
1486 | else
|
---|
1487 | {
|
---|
1488 | Assert(pCap->enmAcState != VBOXCAPS_ENTRY_ACSTATE_ACQUIRED || pCap->enmFuncState != VBOXCAPS_ENTRY_FUNCSTATE_STARTED);
|
---|
1489 | VBoxSeamlessRemoveHook();
|
---|
1490 | }
|
---|
1491 | }
|
---|
1492 |
|
---|
1493 | static void vboxCapsEntryAcStateSet(VBOXCAPS_ENTRY *pCap, VBOXCAPS_ENTRY_ACSTATE enmAcState)
|
---|
1494 | {
|
---|
1495 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1496 | if (pCap->enmAcState == enmAcState)
|
---|
1497 | return;
|
---|
1498 |
|
---|
1499 | VBOXCAPS_ENTRY_ACSTATE enmOldAcState = pCap->enmAcState;
|
---|
1500 | pCap->enmAcState = enmAcState;
|
---|
1501 |
|
---|
1502 | if (enmAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED)
|
---|
1503 | {
|
---|
1504 | if (pCap->enmFuncState == VBOXCAPS_ENTRY_FUNCSTATE_STARTED)
|
---|
1505 | {
|
---|
1506 | if (pCap->pfnOnEnable)
|
---|
1507 | pCap->pfnOnEnable(pConsole, pCap, TRUE);
|
---|
1508 | }
|
---|
1509 | }
|
---|
1510 | else if (enmOldAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED && pCap->enmFuncState == VBOXCAPS_ENTRY_FUNCSTATE_STARTED)
|
---|
1511 | {
|
---|
1512 | if (pCap->pfnOnEnable)
|
---|
1513 | pCap->pfnOnEnable(pConsole, pCap, FALSE);
|
---|
1514 | }
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | static void vboxCapsEntryFuncStateSet(VBOXCAPS_ENTRY *pCap, VBOXCAPS_ENTRY_FUNCSTATE enmFuncState)
|
---|
1518 | {
|
---|
1519 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1520 | if (pCap->enmFuncState == enmFuncState)
|
---|
1521 | return;
|
---|
1522 |
|
---|
1523 | VBOXCAPS_ENTRY_FUNCSTATE enmOldFuncState = pCap->enmFuncState;
|
---|
1524 |
|
---|
1525 | pCap->enmFuncState = enmFuncState;
|
---|
1526 |
|
---|
1527 | if (enmFuncState == VBOXCAPS_ENTRY_FUNCSTATE_STARTED)
|
---|
1528 | {
|
---|
1529 | Assert(enmOldFuncState == VBOXCAPS_ENTRY_FUNCSTATE_SUPPORTED);
|
---|
1530 | if (pCap->enmAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED)
|
---|
1531 | {
|
---|
1532 | if (pCap->pfnOnEnable)
|
---|
1533 | pCap->pfnOnEnable(pConsole, pCap, TRUE);
|
---|
1534 | }
|
---|
1535 | }
|
---|
1536 | else if (pCap->enmAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED && enmOldFuncState == VBOXCAPS_ENTRY_FUNCSTATE_STARTED)
|
---|
1537 | {
|
---|
1538 | if (pCap->pfnOnEnable)
|
---|
1539 | pCap->pfnOnEnable(pConsole, pCap, FALSE);
|
---|
1540 | }
|
---|
1541 | }
|
---|
1542 |
|
---|
1543 | static void VBoxCapsEntryFuncStateSet(uint32_t iCup, VBOXCAPS_ENTRY_FUNCSTATE enmFuncState)
|
---|
1544 | {
|
---|
1545 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1546 | VBOXCAPS_ENTRY *pCap = &pConsole->aCaps[iCup];
|
---|
1547 | vboxCapsEntryFuncStateSet(pCap, enmFuncState);
|
---|
1548 | }
|
---|
1549 |
|
---|
1550 | static int VBoxCapsInit()
|
---|
1551 | {
|
---|
1552 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1553 | memset(pConsole, 0, sizeof (*pConsole));
|
---|
1554 | pConsole->aCaps[VBOXCAPS_ENTRY_IDX_SEAMLESS].fCap = VMMDEV_GUEST_SUPPORTS_SEAMLESS;
|
---|
1555 | pConsole->aCaps[VBOXCAPS_ENTRY_IDX_SEAMLESS].iCap = VBOXCAPS_ENTRY_IDX_SEAMLESS;
|
---|
1556 | pConsole->aCaps[VBOXCAPS_ENTRY_IDX_SEAMLESS].pfnOnEnable = vboxCapsOnEnableSeamles;
|
---|
1557 | pConsole->aCaps[VBOXCAPS_ENTRY_IDX_GRAPHICS].fCap = VMMDEV_GUEST_SUPPORTS_GRAPHICS;
|
---|
1558 | pConsole->aCaps[VBOXCAPS_ENTRY_IDX_GRAPHICS].iCap = VBOXCAPS_ENTRY_IDX_GRAPHICS;
|
---|
1559 | return VINF_SUCCESS;
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | static int VBoxCapsReleaseAll()
|
---|
1563 | {
|
---|
1564 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1565 | int rc = VBoxAcquireGuestCaps(0, VMMDEV_GUEST_SUPPORTS_SEAMLESS | VMMDEV_GUEST_SUPPORTS_GRAPHICS);
|
---|
1566 | if (!RT_SUCCESS(rc))
|
---|
1567 | {
|
---|
1568 | WARN(("VBoxTray: vboxCapsEntryReleaseAll VBoxAcquireGuestCaps failed rc %d\n", rc));
|
---|
1569 | return rc;
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | if (pConsole->idTimer)
|
---|
1573 | {
|
---|
1574 | KillTimer(ghwndToolWindow, pConsole->idTimer);
|
---|
1575 | pConsole->idTimer = 0;
|
---|
1576 | }
|
---|
1577 |
|
---|
1578 | for (int i = 0; i < RT_ELEMENTS(pConsole->aCaps); ++i)
|
---|
1579 | {
|
---|
1580 | vboxCapsEntryAcStateSet(&pConsole->aCaps[i], VBOXCAPS_ENTRY_ACSTATE_RELEASED);
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | return rc;
|
---|
1584 | }
|
---|
1585 |
|
---|
1586 | static void VBoxCapsTerm()
|
---|
1587 | {
|
---|
1588 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1589 | VBoxCapsReleaseAll();
|
---|
1590 | memset(pConsole, 0, sizeof (*pConsole));
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | static BOOL VBoxCapsEntryIsAcquired(uint32_t iCap)
|
---|
1594 | {
|
---|
1595 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1596 | return pConsole->aCaps[iCap].enmAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED;
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | static BOOL VBoxCapsEntryIsEnabled(uint32_t iCap)
|
---|
1600 | {
|
---|
1601 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1602 | return pConsole->aCaps[iCap].enmAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED
|
---|
1603 | && pConsole->aCaps[iCap].enmFuncState == VBOXCAPS_ENTRY_FUNCSTATE_STARTED;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | static BOOL VBoxCapsCheckTimer(WPARAM wParam)
|
---|
1607 | {
|
---|
1608 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1609 | if (wParam != pConsole->idTimer)
|
---|
1610 | return FALSE;
|
---|
1611 |
|
---|
1612 | uint32_t u32AcquiredCaps = 0;
|
---|
1613 | BOOL fNeedNewTimer = FALSE;
|
---|
1614 |
|
---|
1615 | for (int i = 0; i < RT_ELEMENTS(pConsole->aCaps); ++i)
|
---|
1616 | {
|
---|
1617 | VBOXCAPS_ENTRY *pCap = &pConsole->aCaps[i];
|
---|
1618 | if (pCap->enmAcState != VBOXCAPS_ENTRY_ACSTATE_ACQUIRING)
|
---|
1619 | continue;
|
---|
1620 |
|
---|
1621 | int rc = VBoxAcquireGuestCaps(pCap->fCap, 0);
|
---|
1622 | if (RT_SUCCESS(rc))
|
---|
1623 | {
|
---|
1624 | vboxCapsEntryAcStateSet(&pConsole->aCaps[i], VBOXCAPS_ENTRY_ACSTATE_ACQUIRED);
|
---|
1625 | u32AcquiredCaps |= pCap->fCap;
|
---|
1626 | }
|
---|
1627 | else
|
---|
1628 | {
|
---|
1629 | Assert(rc == VERR_RESOURCE_BUSY);
|
---|
1630 | fNeedNewTimer = TRUE;
|
---|
1631 | }
|
---|
1632 | }
|
---|
1633 |
|
---|
1634 | if (!fNeedNewTimer)
|
---|
1635 | {
|
---|
1636 | KillTimer(ghwndToolWindow, pConsole->idTimer);
|
---|
1637 | /* cleanup timer data */
|
---|
1638 | pConsole->idTimer = 0;
|
---|
1639 | }
|
---|
1640 |
|
---|
1641 | return TRUE;
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | static int VBoxCapsEntryRelease(uint32_t iCap)
|
---|
1645 | {
|
---|
1646 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1647 | VBOXCAPS_ENTRY *pCap = &pConsole->aCaps[iCap];
|
---|
1648 | if (pCap->enmAcState == VBOXCAPS_ENTRY_ACSTATE_RELEASED)
|
---|
1649 | {
|
---|
1650 | WARN(("invalid cap[%d] state[%d] on release\n", iCap, pCap->enmAcState));
|
---|
1651 | return VERR_INVALID_STATE;
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | if (pCap->enmAcState == VBOXCAPS_ENTRY_ACSTATE_ACQUIRED)
|
---|
1655 | {
|
---|
1656 | int rc = VBoxAcquireGuestCaps(0, pCap->fCap);
|
---|
1657 | AssertRC(rc);
|
---|
1658 | }
|
---|
1659 |
|
---|
1660 | vboxCapsEntryAcStateSet(pCap, VBOXCAPS_ENTRY_ACSTATE_RELEASED);
|
---|
1661 |
|
---|
1662 | return VINF_SUCCESS;
|
---|
1663 | }
|
---|
1664 |
|
---|
1665 | static int VBoxCapsEntryAcquire(uint32_t iCap)
|
---|
1666 | {
|
---|
1667 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1668 | Assert(VBoxConsoleIsAllowed());
|
---|
1669 | VBOXCAPS_ENTRY *pCap = &pConsole->aCaps[iCap];
|
---|
1670 | if (pCap->enmAcState != VBOXCAPS_ENTRY_ACSTATE_RELEASED)
|
---|
1671 | {
|
---|
1672 | WARN(("invalid cap[%d] state[%d] on acquire\n", iCap, pCap->enmAcState));
|
---|
1673 | return VERR_INVALID_STATE;
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 | vboxCapsEntryAcStateSet(pCap, VBOXCAPS_ENTRY_ACSTATE_ACQUIRING);
|
---|
1677 | int rc = VBoxAcquireGuestCaps(pCap->fCap, 0);
|
---|
1678 | if (RT_SUCCESS(rc))
|
---|
1679 | {
|
---|
1680 | vboxCapsEntryAcStateSet(pCap, VBOXCAPS_ENTRY_ACSTATE_ACQUIRED);
|
---|
1681 | return VINF_SUCCESS;
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | if (rc != VERR_RESOURCE_BUSY)
|
---|
1685 | {
|
---|
1686 | WARN(("VBoxTray: vboxCapsEntryReleaseAll VBoxAcquireGuestCaps failed rc %d\n", rc));
|
---|
1687 | return rc;
|
---|
1688 | }
|
---|
1689 |
|
---|
1690 | WARN(("VBoxTray: iCap %d is busy!\n", iCap));
|
---|
1691 |
|
---|
1692 | /* the cap was busy, most likely it is still used by other VBoxTray instance running in another session,
|
---|
1693 | * queue the retry timer */
|
---|
1694 | if (!pConsole->idTimer)
|
---|
1695 | {
|
---|
1696 | pConsole->idTimer = SetTimer(ghwndToolWindow, TIMERID_VBOXTRAY_CAPS_TIMER, 100, (TIMERPROC)NULL);
|
---|
1697 | if (!pConsole->idTimer)
|
---|
1698 | {
|
---|
1699 | DWORD dwErr = GetLastError();
|
---|
1700 | WARN(("VBoxTray: SetTimer error %08X\n", dwErr));
|
---|
1701 | return RTErrConvertFromWin32(dwErr);
|
---|
1702 | }
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | return rc;
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 | static int VBoxCapsAcquireAllSupported()
|
---|
1709 | {
|
---|
1710 | VBOXCAPS *pConsole = &gVBoxCaps;
|
---|
1711 | for (int i = 0; i < RT_ELEMENTS(pConsole->aCaps); ++i)
|
---|
1712 | {
|
---|
1713 | if (pConsole->aCaps[i].enmFuncState >= VBOXCAPS_ENTRY_FUNCSTATE_SUPPORTED)
|
---|
1714 | VBoxCapsEntryAcquire(i);
|
---|
1715 | }
|
---|
1716 | return VINF_SUCCESS;
|
---|
1717 | }
|
---|
1718 |
|
---|
1719 | static BOOL VBoxConsoleIsAllowed()
|
---|
1720 | {
|
---|
1721 | return vboxDtIsInputDesktop() && vboxStIsActiveConsole();
|
---|
1722 | }
|
---|
1723 |
|
---|
1724 | static void VBoxConsoleEnable(BOOL fEnable)
|
---|
1725 | {
|
---|
1726 | if (fEnable)
|
---|
1727 | VBoxCapsAcquireAllSupported();
|
---|
1728 | else
|
---|
1729 | VBoxCapsReleaseAll();
|
---|
1730 | }
|
---|
1731 |
|
---|
1732 | static void VBoxConsoleCapSetSupported(uint32_t iCap, BOOL fSupported)
|
---|
1733 | {
|
---|
1734 | if (fSupported)
|
---|
1735 | {
|
---|
1736 | VBoxCapsEntryFuncStateSet(iCap, VBOXCAPS_ENTRY_FUNCSTATE_SUPPORTED);
|
---|
1737 |
|
---|
1738 | if (VBoxConsoleIsAllowed())
|
---|
1739 | VBoxCapsEntryAcquire(iCap);
|
---|
1740 | }
|
---|
1741 | else
|
---|
1742 | {
|
---|
1743 | VBoxCapsEntryFuncStateSet(iCap, VBOXCAPS_ENTRY_FUNCSTATE_UNSUPPORTED);
|
---|
1744 |
|
---|
1745 | VBoxCapsEntryRelease(iCap);
|
---|
1746 | }
|
---|
1747 | }
|
---|
1748 |
|
---|
1749 | void VBoxSeamlessSetSupported(BOOL fSupported)
|
---|
1750 | {
|
---|
1751 | VBoxConsoleCapSetSupported(VBOXCAPS_ENTRY_IDX_SEAMLESS, fSupported);
|
---|
1752 | }
|
---|
1753 |
|
---|
1754 | static void VBoxGrapicsSetSupported(BOOL fSupported)
|
---|
1755 | {
|
---|
1756 | VBoxConsoleCapSetSupported(VBOXCAPS_ENTRY_IDX_GRAPHICS, fSupported);
|
---|
1757 | }
|
---|