1 | /* $Id: ConsoleVRDPServer.cpp 22663 2009-09-01 14:02:28Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VBox Console VRDP Helper class
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "ConsoleVRDPServer.h"
|
---|
25 | #include "ConsoleImpl.h"
|
---|
26 | #include "DisplayImpl.h"
|
---|
27 | #include "KeyboardImpl.h"
|
---|
28 | #include "MouseImpl.h"
|
---|
29 |
|
---|
30 | #include "Logging.h"
|
---|
31 |
|
---|
32 | #include <iprt/asm.h>
|
---|
33 | #include <iprt/ldr.h>
|
---|
34 | #include <iprt/param.h>
|
---|
35 | #include <iprt/path.h>
|
---|
36 | #include <iprt/alloca.h>
|
---|
37 |
|
---|
38 | #include <VBox/err.h>
|
---|
39 | #ifdef VBOX_WITH_VRDP
|
---|
40 | #include <VBox/VRDPOrders.h>
|
---|
41 | #endif /* VBOX_WITH_VRDP */
|
---|
42 |
|
---|
43 | class VRDPConsoleCallback :
|
---|
44 | VBOX_SCRIPTABLE_IMPL(IConsoleCallback)
|
---|
45 | {
|
---|
46 | public:
|
---|
47 | VRDPConsoleCallback (ConsoleVRDPServer *server) :
|
---|
48 | m_server(server)
|
---|
49 | {
|
---|
50 | #ifndef VBOX_WITH_XPCOM
|
---|
51 | refcnt = 0;
|
---|
52 | #endif /* !VBOX_WITH_XPCOM */
|
---|
53 | }
|
---|
54 |
|
---|
55 | virtual ~VRDPConsoleCallback() {}
|
---|
56 |
|
---|
57 | NS_DECL_ISUPPORTS
|
---|
58 |
|
---|
59 | #ifndef VBOX_WITH_XPCOM
|
---|
60 | STDMETHOD_(ULONG, AddRef)() {
|
---|
61 | return ::InterlockedIncrement (&refcnt);
|
---|
62 | }
|
---|
63 | STDMETHOD_(ULONG, Release)()
|
---|
64 | {
|
---|
65 | long cnt = ::InterlockedDecrement (&refcnt);
|
---|
66 | if (cnt == 0)
|
---|
67 | delete this;
|
---|
68 | return cnt;
|
---|
69 | }
|
---|
70 | STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
|
---|
71 | {
|
---|
72 | if (riid == IID_IUnknown) {
|
---|
73 | *ppObj = this;
|
---|
74 | AddRef();
|
---|
75 | return S_OK;
|
---|
76 | }
|
---|
77 | if (riid == IID_IConsoleCallback) {
|
---|
78 | *ppObj = this;
|
---|
79 | AddRef();
|
---|
80 | return S_OK;
|
---|
81 | }
|
---|
82 | *ppObj = NULL;
|
---|
83 | return E_NOINTERFACE;
|
---|
84 | }
|
---|
85 | #endif /* !VBOX_WITH_XPCOM */
|
---|
86 |
|
---|
87 |
|
---|
88 | STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
|
---|
89 | ULONG width, ULONG height, BYTE *shape);
|
---|
90 |
|
---|
91 | STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL needsHostCursor)
|
---|
92 | {
|
---|
93 | if (m_server)
|
---|
94 | {
|
---|
95 | m_server->NotifyAbsoluteMouse(!!supportsAbsolute);
|
---|
96 | }
|
---|
97 | return S_OK;
|
---|
98 | }
|
---|
99 |
|
---|
100 | STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
|
---|
101 | {
|
---|
102 | if (m_server)
|
---|
103 | {
|
---|
104 | m_server->NotifyKeyboardLedsChange (fNumLock, fCapsLock, fScrollLock);
|
---|
105 | }
|
---|
106 | return S_OK;
|
---|
107 | }
|
---|
108 |
|
---|
109 | STDMETHOD(OnStateChange)(MachineState_T machineState)
|
---|
110 | {
|
---|
111 | return S_OK;
|
---|
112 | }
|
---|
113 |
|
---|
114 | STDMETHOD(OnAdditionsStateChange)()
|
---|
115 | {
|
---|
116 | return S_OK;
|
---|
117 | }
|
---|
118 |
|
---|
119 | STDMETHOD(OnDVDDriveChange)()
|
---|
120 | {
|
---|
121 | return S_OK;
|
---|
122 | }
|
---|
123 |
|
---|
124 | STDMETHOD(OnFloppyDriveChange)()
|
---|
125 | {
|
---|
126 | return S_OK;
|
---|
127 | }
|
---|
128 |
|
---|
129 | STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
|
---|
130 | {
|
---|
131 | return S_OK;
|
---|
132 | }
|
---|
133 |
|
---|
134 | STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
|
---|
135 | {
|
---|
136 | return S_OK;
|
---|
137 | }
|
---|
138 |
|
---|
139 | STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
|
---|
140 | {
|
---|
141 | return S_OK;
|
---|
142 | }
|
---|
143 |
|
---|
144 | STDMETHOD(OnStorageControllerChange) ()
|
---|
145 | {
|
---|
146 | return S_OK;
|
---|
147 | }
|
---|
148 |
|
---|
149 | STDMETHOD(OnVRDPServerChange)()
|
---|
150 | {
|
---|
151 | return S_OK;
|
---|
152 | }
|
---|
153 |
|
---|
154 | STDMETHOD(OnUSBControllerChange)()
|
---|
155 | {
|
---|
156 | return S_OK;
|
---|
157 | }
|
---|
158 |
|
---|
159 | STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *aDevice, BOOL aAttached,
|
---|
160 | IVirtualBoxErrorInfo *aError)
|
---|
161 | {
|
---|
162 | return S_OK;
|
---|
163 | }
|
---|
164 |
|
---|
165 | STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
|
---|
166 | {
|
---|
167 | return S_OK;
|
---|
168 | }
|
---|
169 |
|
---|
170 | STDMETHOD(OnRuntimeError)(BOOL fatal, IN_BSTR id, IN_BSTR message)
|
---|
171 | {
|
---|
172 | return S_OK;
|
---|
173 | }
|
---|
174 |
|
---|
175 | STDMETHOD(OnCanShowWindow)(BOOL *canShow)
|
---|
176 | {
|
---|
177 | if (!canShow)
|
---|
178 | return E_POINTER;
|
---|
179 | /* we don't manage window activation here: always agree */
|
---|
180 | *canShow = TRUE;
|
---|
181 | return S_OK;
|
---|
182 | }
|
---|
183 |
|
---|
184 | STDMETHOD(OnShowWindow) (ULONG64 *winId)
|
---|
185 | {
|
---|
186 | if (!winId)
|
---|
187 | return E_POINTER;
|
---|
188 | /* we don't manage window activation here */
|
---|
189 | *winId = 0;
|
---|
190 | return S_OK;
|
---|
191 | }
|
---|
192 |
|
---|
193 | private:
|
---|
194 | ConsoleVRDPServer *m_server;
|
---|
195 | #ifndef VBOX_WITH_XPCOM
|
---|
196 | long refcnt;
|
---|
197 | #endif /* !VBOX_WITH_XPCOM */
|
---|
198 | };
|
---|
199 |
|
---|
200 | #ifdef VBOX_WITH_XPCOM
|
---|
201 | #include <nsMemory.h>
|
---|
202 | NS_DECL_CLASSINFO(VRDPConsoleCallback)
|
---|
203 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VRDPConsoleCallback, IConsoleCallback)
|
---|
204 | #endif /* VBOX_WITH_XPCOM */
|
---|
205 |
|
---|
206 | #ifdef DEBUG_sunlover
|
---|
207 | #define LOGDUMPPTR Log
|
---|
208 | void dumpPointer (const uint8_t *pu8Shape, uint32_t width, uint32_t height, bool fXorMaskRGB32)
|
---|
209 | {
|
---|
210 | unsigned i;
|
---|
211 |
|
---|
212 | const uint8_t *pu8And = pu8Shape;
|
---|
213 |
|
---|
214 | for (i = 0; i < height; i++)
|
---|
215 | {
|
---|
216 | unsigned j;
|
---|
217 | LOGDUMPPTR(("%p: ", pu8And));
|
---|
218 | for (j = 0; j < (width + 7) / 8; j++)
|
---|
219 | {
|
---|
220 | unsigned k;
|
---|
221 | for (k = 0; k < 8; k++)
|
---|
222 | {
|
---|
223 | LOGDUMPPTR(("%d", ((*pu8And) & (1 << (7 - k)))? 1: 0));
|
---|
224 | }
|
---|
225 |
|
---|
226 | pu8And++;
|
---|
227 | }
|
---|
228 | LOGDUMPPTR(("\n"));
|
---|
229 | }
|
---|
230 |
|
---|
231 | if (fXorMaskRGB32)
|
---|
232 | {
|
---|
233 | uint32_t *pu32Xor = (uint32_t *)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
|
---|
234 |
|
---|
235 | for (i = 0; i < height; i++)
|
---|
236 | {
|
---|
237 | unsigned j;
|
---|
238 | LOGDUMPPTR(("%p: ", pu32Xor));
|
---|
239 | for (j = 0; j < width; j++)
|
---|
240 | {
|
---|
241 | LOGDUMPPTR(("%08X", *pu32Xor++));
|
---|
242 | }
|
---|
243 | LOGDUMPPTR(("\n"));
|
---|
244 | }
|
---|
245 | }
|
---|
246 | else
|
---|
247 | {
|
---|
248 | /* RDP 24 bit RGB mask. */
|
---|
249 | uint8_t *pu8Xor = (uint8_t *)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
|
---|
250 | for (i = 0; i < height; i++)
|
---|
251 | {
|
---|
252 | unsigned j;
|
---|
253 | LOGDUMPPTR(("%p: ", pu8Xor));
|
---|
254 | for (j = 0; j < width; j++)
|
---|
255 | {
|
---|
256 | LOGDUMPPTR(("%02X%02X%02X", pu8Xor[2], pu8Xor[1], pu8Xor[0]));
|
---|
257 | pu8Xor += 3;
|
---|
258 | }
|
---|
259 | LOGDUMPPTR(("\n"));
|
---|
260 | }
|
---|
261 | }
|
---|
262 | }
|
---|
263 | #else
|
---|
264 | #define dumpPointer(a, b, c, d) do {} while (0)
|
---|
265 | #endif /* DEBUG_sunlover */
|
---|
266 |
|
---|
267 | static void findTopLeftBorder (const uint8_t *pu8AndMask, const uint8_t *pu8XorMask, uint32_t width, uint32_t height, uint32_t *pxSkip, uint32_t *pySkip)
|
---|
268 | {
|
---|
269 | /*
|
---|
270 | * Find the top border of the AND mask. First assign to special value.
|
---|
271 | */
|
---|
272 | uint32_t ySkipAnd = ~0;
|
---|
273 |
|
---|
274 | const uint8_t *pu8And = pu8AndMask;
|
---|
275 | const uint32_t cbAndRow = (width + 7) / 8;
|
---|
276 | const uint8_t maskLastByte = (uint8_t)( 0xFF << (cbAndRow * 8 - width) );
|
---|
277 |
|
---|
278 | Assert(cbAndRow > 0);
|
---|
279 |
|
---|
280 | unsigned y;
|
---|
281 | unsigned x;
|
---|
282 |
|
---|
283 | for (y = 0; y < height && ySkipAnd == ~(uint32_t)0; y++, pu8And += cbAndRow)
|
---|
284 | {
|
---|
285 | /* For each complete byte in the row. */
|
---|
286 | for (x = 0; x < cbAndRow - 1; x++)
|
---|
287 | {
|
---|
288 | if (pu8And[x] != 0xFF)
|
---|
289 | {
|
---|
290 | ySkipAnd = y;
|
---|
291 | break;
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | if (ySkipAnd == ~(uint32_t)0)
|
---|
296 | {
|
---|
297 | /* Last byte. */
|
---|
298 | if ((pu8And[cbAndRow - 1] & maskLastByte) != maskLastByte)
|
---|
299 | {
|
---|
300 | ySkipAnd = y;
|
---|
301 | }
|
---|
302 | }
|
---|
303 | }
|
---|
304 |
|
---|
305 | if (ySkipAnd == ~(uint32_t)0)
|
---|
306 | {
|
---|
307 | ySkipAnd = 0;
|
---|
308 | }
|
---|
309 |
|
---|
310 | /*
|
---|
311 | * Find the left border of the AND mask.
|
---|
312 | */
|
---|
313 | uint32_t xSkipAnd = ~0;
|
---|
314 |
|
---|
315 | /* For all bit columns. */
|
---|
316 | for (x = 0; x < width && xSkipAnd == ~(uint32_t)0; x++)
|
---|
317 | {
|
---|
318 | pu8And = pu8AndMask + x/8; /* Currently checking byte. */
|
---|
319 | uint8_t mask = 1 << (7 - x%8); /* Currently checking bit in the byte. */
|
---|
320 |
|
---|
321 | for (y = ySkipAnd; y < height; y++, pu8And += cbAndRow)
|
---|
322 | {
|
---|
323 | if ((*pu8And & mask) == 0)
|
---|
324 | {
|
---|
325 | xSkipAnd = x;
|
---|
326 | break;
|
---|
327 | }
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | if (xSkipAnd == ~(uint32_t)0)
|
---|
332 | {
|
---|
333 | xSkipAnd = 0;
|
---|
334 | }
|
---|
335 |
|
---|
336 | /*
|
---|
337 | * Find the XOR mask top border.
|
---|
338 | */
|
---|
339 | uint32_t ySkipXor = ~0;
|
---|
340 |
|
---|
341 | uint32_t *pu32XorStart = (uint32_t *)pu8XorMask;
|
---|
342 |
|
---|
343 | uint32_t *pu32Xor = pu32XorStart;
|
---|
344 |
|
---|
345 | for (y = 0; y < height && ySkipXor == ~(uint32_t)0; y++, pu32Xor += width)
|
---|
346 | {
|
---|
347 | for (x = 0; x < width; x++)
|
---|
348 | {
|
---|
349 | if (pu32Xor[x] != 0)
|
---|
350 | {
|
---|
351 | ySkipXor = y;
|
---|
352 | break;
|
---|
353 | }
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | if (ySkipXor == ~(uint32_t)0)
|
---|
358 | {
|
---|
359 | ySkipXor = 0;
|
---|
360 | }
|
---|
361 |
|
---|
362 | /*
|
---|
363 | * Find the left border of the XOR mask.
|
---|
364 | */
|
---|
365 | uint32_t xSkipXor = ~(uint32_t)0;
|
---|
366 |
|
---|
367 | /* For all columns. */
|
---|
368 | for (x = 0; x < width && xSkipXor == ~(uint32_t)0; x++)
|
---|
369 | {
|
---|
370 | pu32Xor = pu32XorStart + x; /* Currently checking dword. */
|
---|
371 |
|
---|
372 | for (y = ySkipXor; y < height; y++, pu32Xor += width)
|
---|
373 | {
|
---|
374 | if (*pu32Xor != 0)
|
---|
375 | {
|
---|
376 | xSkipXor = x;
|
---|
377 | break;
|
---|
378 | }
|
---|
379 | }
|
---|
380 | }
|
---|
381 |
|
---|
382 | if (xSkipXor == ~(uint32_t)0)
|
---|
383 | {
|
---|
384 | xSkipXor = 0;
|
---|
385 | }
|
---|
386 |
|
---|
387 | *pxSkip = RT_MIN (xSkipAnd, xSkipXor);
|
---|
388 | *pySkip = RT_MIN (ySkipAnd, ySkipXor);
|
---|
389 | }
|
---|
390 |
|
---|
391 | /* Generate an AND mask for alpha pointers here, because
|
---|
392 | * guest driver does not do that correctly for Vista pointers.
|
---|
393 | * Similar fix, changing the alpha threshold, could be applied
|
---|
394 | * for the guest driver, but then additions reinstall would be
|
---|
395 | * necessary, which we try to avoid.
|
---|
396 | */
|
---|
397 | static void mousePointerGenerateANDMask (uint8_t *pu8DstAndMask, int cbDstAndMask, const uint8_t *pu8SrcAlpha, int w, int h)
|
---|
398 | {
|
---|
399 | memset (pu8DstAndMask, 0xFF, cbDstAndMask);
|
---|
400 |
|
---|
401 | int y;
|
---|
402 | for (y = 0; y < h; y++)
|
---|
403 | {
|
---|
404 | uint8_t bitmask = 0x80;
|
---|
405 |
|
---|
406 | int x;
|
---|
407 | for (x = 0; x < w; x++, bitmask >>= 1)
|
---|
408 | {
|
---|
409 | if (bitmask == 0)
|
---|
410 | {
|
---|
411 | bitmask = 0x80;
|
---|
412 | }
|
---|
413 |
|
---|
414 | /* Whether alpha channel value is not transparent enough for the pixel to be seen. */
|
---|
415 | if (pu8SrcAlpha[x * 4 + 3] > 0x7f)
|
---|
416 | {
|
---|
417 | pu8DstAndMask[x / 8] &= ~bitmask;
|
---|
418 | }
|
---|
419 | }
|
---|
420 |
|
---|
421 | /* Point to next source and dest scans. */
|
---|
422 | pu8SrcAlpha += w * 4;
|
---|
423 | pu8DstAndMask += (w + 7) / 8;
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | STDMETHODIMP VRDPConsoleCallback::OnMousePointerShapeChange (
|
---|
428 | BOOL visible,
|
---|
429 | BOOL alpha,
|
---|
430 | ULONG xHot,
|
---|
431 | ULONG yHot,
|
---|
432 | ULONG width,
|
---|
433 | ULONG height,
|
---|
434 | BYTE *shape)
|
---|
435 | {
|
---|
436 | LogSunlover(("VRDPConsoleCallback::OnMousePointerShapeChange: %d, %d, %lux%lu, @%lu,%lu\n", visible, alpha, width, height, xHot, yHot));
|
---|
437 |
|
---|
438 | if (m_server)
|
---|
439 | {
|
---|
440 | if (!shape)
|
---|
441 | {
|
---|
442 | if (!visible)
|
---|
443 | {
|
---|
444 | m_server->MousePointerHide ();
|
---|
445 | }
|
---|
446 | }
|
---|
447 | else if (width != 0 && height != 0)
|
---|
448 | {
|
---|
449 | /* Pointer consists of 1 bpp AND and 24 BPP XOR masks.
|
---|
450 | * 'shape' AND mask followed by XOR mask.
|
---|
451 | * XOR mask contains 32 bit (lsb)BGR0(msb) values.
|
---|
452 | *
|
---|
453 | * We convert this to RDP color format which consist of
|
---|
454 | * one bpp AND mask and 24 BPP (BGR) color XOR image.
|
---|
455 | *
|
---|
456 | * RDP clients expect 8 aligned width and height of
|
---|
457 | * pointer (preferably 32x32).
|
---|
458 | *
|
---|
459 | * They even contain bugs which do not appear for
|
---|
460 | * 32x32 pointers but would appear for a 41x32 one.
|
---|
461 | *
|
---|
462 | * So set pointer size to 32x32. This can be done safely
|
---|
463 | * because most pointers are 32x32.
|
---|
464 | */
|
---|
465 |
|
---|
466 | dumpPointer (shape, width, height, true);
|
---|
467 |
|
---|
468 | int cbDstAndMask = (((width + 7) / 8) * height + 3) & ~3;
|
---|
469 |
|
---|
470 | uint8_t *pu8AndMask = shape;
|
---|
471 | uint8_t *pu8XorMask = shape + cbDstAndMask;
|
---|
472 |
|
---|
473 | if (alpha)
|
---|
474 | {
|
---|
475 | pu8AndMask = (uint8_t *)alloca (cbDstAndMask);
|
---|
476 |
|
---|
477 | mousePointerGenerateANDMask (pu8AndMask, cbDstAndMask, pu8XorMask, width, height);
|
---|
478 | }
|
---|
479 |
|
---|
480 | /* Windows guest alpha pointers are wider than 32 pixels.
|
---|
481 | * Try to find out the top-left border of the pointer and
|
---|
482 | * then copy only meaningful bits. All complete top rows
|
---|
483 | * and all complete left columns where (AND == 1 && XOR == 0)
|
---|
484 | * are skipped. Hot spot is adjusted.
|
---|
485 | */
|
---|
486 | uint32_t ySkip = 0; /* How many rows to skip at the top. */
|
---|
487 | uint32_t xSkip = 0; /* How many columns to skip at the left. */
|
---|
488 |
|
---|
489 | findTopLeftBorder (pu8AndMask, pu8XorMask, width, height, &xSkip, &ySkip);
|
---|
490 |
|
---|
491 | /* Must not skip the hot spot. */
|
---|
492 | xSkip = RT_MIN (xSkip, xHot);
|
---|
493 | ySkip = RT_MIN (ySkip, yHot);
|
---|
494 |
|
---|
495 | /*
|
---|
496 | * Compute size and allocate memory for the pointer.
|
---|
497 | */
|
---|
498 | const uint32_t dstwidth = 32;
|
---|
499 | const uint32_t dstheight = 32;
|
---|
500 |
|
---|
501 | VRDPCOLORPOINTER *pointer = NULL;
|
---|
502 |
|
---|
503 | uint32_t dstmaskwidth = (dstwidth + 7) / 8;
|
---|
504 |
|
---|
505 | uint32_t rdpmaskwidth = dstmaskwidth;
|
---|
506 | uint32_t rdpmasklen = dstheight * rdpmaskwidth;
|
---|
507 |
|
---|
508 | uint32_t rdpdatawidth = dstwidth * 3;
|
---|
509 | uint32_t rdpdatalen = dstheight * rdpdatawidth;
|
---|
510 |
|
---|
511 | pointer = (VRDPCOLORPOINTER *)RTMemTmpAlloc (sizeof (VRDPCOLORPOINTER) + rdpmasklen + rdpdatalen);
|
---|
512 |
|
---|
513 | if (pointer)
|
---|
514 | {
|
---|
515 | uint8_t *maskarray = (uint8_t *)pointer + sizeof (VRDPCOLORPOINTER);
|
---|
516 | uint8_t *dataarray = maskarray + rdpmasklen;
|
---|
517 |
|
---|
518 | memset (maskarray, 0xFF, rdpmasklen);
|
---|
519 | memset (dataarray, 0x00, rdpdatalen);
|
---|
520 |
|
---|
521 | uint32_t srcmaskwidth = (width + 7) / 8;
|
---|
522 | uint32_t srcdatawidth = width * 4;
|
---|
523 |
|
---|
524 | /* Copy AND mask. */
|
---|
525 | uint8_t *src = pu8AndMask + ySkip * srcmaskwidth;
|
---|
526 | uint8_t *dst = maskarray + (dstheight - 1) * rdpmaskwidth;
|
---|
527 |
|
---|
528 | uint32_t minheight = RT_MIN (height - ySkip, dstheight);
|
---|
529 | uint32_t minwidth = RT_MIN (width - xSkip, dstwidth);
|
---|
530 |
|
---|
531 | unsigned x, y;
|
---|
532 |
|
---|
533 | for (y = 0; y < minheight; y++)
|
---|
534 | {
|
---|
535 | for (x = 0; x < minwidth; x++)
|
---|
536 | {
|
---|
537 | uint32_t byteIndex = (x + xSkip) / 8;
|
---|
538 | uint32_t bitIndex = (x + xSkip) % 8;
|
---|
539 |
|
---|
540 | bool bit = (src[byteIndex] & (1 << (7 - bitIndex))) != 0;
|
---|
541 |
|
---|
542 | if (!bit)
|
---|
543 | {
|
---|
544 | byteIndex = x / 8;
|
---|
545 | bitIndex = x % 8;
|
---|
546 |
|
---|
547 | dst[byteIndex] &= ~(1 << (7 - bitIndex));
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | src += srcmaskwidth;
|
---|
552 | dst -= rdpmaskwidth;
|
---|
553 | }
|
---|
554 |
|
---|
555 | /* Point src to XOR mask */
|
---|
556 | src = pu8XorMask + ySkip * srcdatawidth;
|
---|
557 | dst = dataarray + (dstheight - 1) * rdpdatawidth;
|
---|
558 |
|
---|
559 | for (y = 0; y < minheight ; y++)
|
---|
560 | {
|
---|
561 | for (x = 0; x < minwidth; x++)
|
---|
562 | {
|
---|
563 | memcpy (dst + x * 3, &src[4 * (x + xSkip)], 3);
|
---|
564 | }
|
---|
565 |
|
---|
566 | src += srcdatawidth;
|
---|
567 | dst -= rdpdatawidth;
|
---|
568 | }
|
---|
569 |
|
---|
570 | pointer->u16HotX = (uint16_t)(xHot - xSkip);
|
---|
571 | pointer->u16HotY = (uint16_t)(yHot - ySkip);
|
---|
572 |
|
---|
573 | pointer->u16Width = (uint16_t)dstwidth;
|
---|
574 | pointer->u16Height = (uint16_t)dstheight;
|
---|
575 |
|
---|
576 | pointer->u16MaskLen = (uint16_t)rdpmasklen;
|
---|
577 | pointer->u16DataLen = (uint16_t)rdpdatalen;
|
---|
578 |
|
---|
579 | dumpPointer ((uint8_t *)pointer + sizeof (*pointer), dstwidth, dstheight, false);
|
---|
580 |
|
---|
581 | m_server->MousePointerUpdate (pointer);
|
---|
582 |
|
---|
583 | RTMemTmpFree (pointer);
|
---|
584 | }
|
---|
585 | }
|
---|
586 | }
|
---|
587 |
|
---|
588 | return S_OK;
|
---|
589 | }
|
---|
590 |
|
---|
591 |
|
---|
592 | // ConsoleVRDPServer
|
---|
593 | ////////////////////////////////////////////////////////////////////////////////
|
---|
594 |
|
---|
595 | #ifdef VBOX_WITH_VRDP
|
---|
596 | RTLDRMOD ConsoleVRDPServer::mVRDPLibrary;
|
---|
597 |
|
---|
598 | PFNVRDPCREATESERVER ConsoleVRDPServer::mpfnVRDPCreateServer = NULL;
|
---|
599 |
|
---|
600 | VRDPENTRYPOINTS_1 *ConsoleVRDPServer::mpEntryPoints = NULL;
|
---|
601 |
|
---|
602 | VRDPCALLBACKS_1 ConsoleVRDPServer::mCallbacks =
|
---|
603 | {
|
---|
604 | { VRDP_INTERFACE_VERSION_1, sizeof (VRDPCALLBACKS_1) },
|
---|
605 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
606 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
607 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
608 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
609 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
610 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
611 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
612 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
613 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
614 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
615 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
616 | ConsoleVRDPServer::VRDPCallbackVideoModeHint
|
---|
617 | };
|
---|
618 |
|
---|
619 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut)
|
---|
620 | {
|
---|
621 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
622 |
|
---|
623 | int rc = VERR_NOT_SUPPORTED;
|
---|
624 |
|
---|
625 | switch (index)
|
---|
626 | {
|
---|
627 | case VRDP_QP_NETWORK_PORT:
|
---|
628 | {
|
---|
629 | ULONG port = 0;
|
---|
630 | server->mConsole->getVRDPServer ()->COMGETTER(Port) (&port);
|
---|
631 | if (port == 0)
|
---|
632 | {
|
---|
633 | port = VRDP_DEFAULT_PORT;
|
---|
634 | }
|
---|
635 |
|
---|
636 | if (cbBuffer >= sizeof (uint32_t))
|
---|
637 | {
|
---|
638 | *(uint32_t *)pvBuffer = (uint32_t)port;
|
---|
639 | rc = VINF_SUCCESS;
|
---|
640 | }
|
---|
641 | else
|
---|
642 | {
|
---|
643 | rc = VINF_BUFFER_OVERFLOW;
|
---|
644 | }
|
---|
645 |
|
---|
646 | *pcbOut = sizeof (uint32_t);
|
---|
647 | } break;
|
---|
648 |
|
---|
649 | case VRDP_QP_NETWORK_ADDRESS:
|
---|
650 | {
|
---|
651 | com::Bstr bstr;
|
---|
652 | server->mConsole->getVRDPServer ()->COMGETTER(NetAddress) (bstr.asOutParam());
|
---|
653 |
|
---|
654 | /* The server expects UTF8. */
|
---|
655 | com::Utf8Str address = bstr;
|
---|
656 |
|
---|
657 | size_t cbAddress = address.length () + 1;
|
---|
658 |
|
---|
659 | if (cbAddress >= 0x10000)
|
---|
660 | {
|
---|
661 | /* More than 64K seems to be an invalid address. */
|
---|
662 | rc = VERR_TOO_MUCH_DATA;
|
---|
663 | break;
|
---|
664 | }
|
---|
665 |
|
---|
666 | if ((size_t)cbBuffer >= cbAddress)
|
---|
667 | {
|
---|
668 | if (cbAddress > 0)
|
---|
669 | {
|
---|
670 | if (address.raw())
|
---|
671 | {
|
---|
672 | memcpy (pvBuffer, address.raw(), cbAddress);
|
---|
673 | }
|
---|
674 | else
|
---|
675 | {
|
---|
676 | /* The value is an empty string. */
|
---|
677 | *(uint8_t *)pvBuffer = 0;
|
---|
678 | }
|
---|
679 | }
|
---|
680 |
|
---|
681 | rc = VINF_SUCCESS;
|
---|
682 | }
|
---|
683 | else
|
---|
684 | {
|
---|
685 | rc = VINF_BUFFER_OVERFLOW;
|
---|
686 | }
|
---|
687 |
|
---|
688 | *pcbOut = (uint32_t)cbAddress;
|
---|
689 | } break;
|
---|
690 |
|
---|
691 | case VRDP_QP_NUMBER_MONITORS:
|
---|
692 | {
|
---|
693 | ULONG cMonitors = 1;
|
---|
694 |
|
---|
695 | server->mConsole->machine ()->COMGETTER(MonitorCount)(&cMonitors);
|
---|
696 |
|
---|
697 | if (cbBuffer >= sizeof (uint32_t))
|
---|
698 | {
|
---|
699 | *(uint32_t *)pvBuffer = (uint32_t)cMonitors;
|
---|
700 | rc = VINF_SUCCESS;
|
---|
701 | }
|
---|
702 | else
|
---|
703 | {
|
---|
704 | rc = VINF_BUFFER_OVERFLOW;
|
---|
705 | }
|
---|
706 |
|
---|
707 | *pcbOut = sizeof (uint32_t);
|
---|
708 | } break;
|
---|
709 |
|
---|
710 | case VRDP_QP_NETWORK_PORT_RANGE:
|
---|
711 | {
|
---|
712 | com::Bstr bstr;
|
---|
713 | HRESULT hrc = server->mConsole->machine ()->GetExtraData(Bstr("VBoxInternal2/VRDPPortRange"), bstr.asOutParam());
|
---|
714 | if (hrc != S_OK)
|
---|
715 | {
|
---|
716 | bstr = "";
|
---|
717 | }
|
---|
718 |
|
---|
719 | /* The server expects UTF8. */
|
---|
720 | com::Utf8Str portRange = bstr;
|
---|
721 |
|
---|
722 | size_t cbPortRange = portRange.length () + 1;
|
---|
723 |
|
---|
724 | if (cbPortRange >= 0x10000)
|
---|
725 | {
|
---|
726 | /* More than 64K seems to be an invalid port range string. */
|
---|
727 | rc = VERR_TOO_MUCH_DATA;
|
---|
728 | break;
|
---|
729 | }
|
---|
730 |
|
---|
731 | if ((size_t)cbBuffer >= cbPortRange)
|
---|
732 | {
|
---|
733 | if (cbPortRange > 0)
|
---|
734 | {
|
---|
735 | if (portRange.raw())
|
---|
736 | {
|
---|
737 | memcpy (pvBuffer, portRange.raw(), cbPortRange);
|
---|
738 | }
|
---|
739 | else
|
---|
740 | {
|
---|
741 | /* The value is an empty string. */
|
---|
742 | *(uint8_t *)pvBuffer = 0;
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | rc = VINF_SUCCESS;
|
---|
747 | }
|
---|
748 | else
|
---|
749 | {
|
---|
750 | rc = VINF_BUFFER_OVERFLOW;
|
---|
751 | }
|
---|
752 |
|
---|
753 | *pcbOut = (uint32_t)cbPortRange;
|
---|
754 | } break;
|
---|
755 |
|
---|
756 | case VRDP_SP_NETWORK_BIND_PORT:
|
---|
757 | {
|
---|
758 | if (cbBuffer != sizeof (uint32_t))
|
---|
759 | {
|
---|
760 | rc = VERR_INVALID_PARAMETER;
|
---|
761 | break;
|
---|
762 | }
|
---|
763 |
|
---|
764 | ULONG port = *(uint32_t *)pvBuffer;
|
---|
765 |
|
---|
766 | com::Bstr bstr = Utf8StrFmt("%d", port);
|
---|
767 |
|
---|
768 | server->mConsole->machine ()->SetExtraData(Bstr("VBoxInternal2/VRDPBindPort"), bstr);
|
---|
769 |
|
---|
770 | rc = VINF_SUCCESS;
|
---|
771 |
|
---|
772 | if (pcbOut)
|
---|
773 | {
|
---|
774 | *pcbOut = sizeof (uint32_t);
|
---|
775 | }
|
---|
776 | } break;
|
---|
777 |
|
---|
778 | default:
|
---|
779 | break;
|
---|
780 | }
|
---|
781 |
|
---|
782 | return rc;
|
---|
783 | }
|
---|
784 |
|
---|
785 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain)
|
---|
786 | {
|
---|
787 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
788 |
|
---|
789 | return server->mConsole->VRDPClientLogon (u32ClientId, pszUser, pszPassword, pszDomain);
|
---|
790 | }
|
---|
791 |
|
---|
792 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId)
|
---|
793 | {
|
---|
794 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
795 |
|
---|
796 | server->mConsole->VRDPClientConnect (u32ClientId);
|
---|
797 | }
|
---|
798 |
|
---|
799 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted)
|
---|
800 | {
|
---|
801 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
802 |
|
---|
803 | server->mConsole->VRDPClientDisconnect (u32ClientId, fu32Intercepted);
|
---|
804 | }
|
---|
805 |
|
---|
806 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept)
|
---|
807 | {
|
---|
808 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
809 |
|
---|
810 | LogFlowFunc(("%x\n", fu32Intercept));
|
---|
811 |
|
---|
812 | int rc = VERR_NOT_SUPPORTED;
|
---|
813 |
|
---|
814 | switch (fu32Intercept)
|
---|
815 | {
|
---|
816 | case VRDP_CLIENT_INTERCEPT_AUDIO:
|
---|
817 | {
|
---|
818 | server->mConsole->VRDPInterceptAudio (u32ClientId);
|
---|
819 | if (ppvIntercept)
|
---|
820 | {
|
---|
821 | *ppvIntercept = server;
|
---|
822 | }
|
---|
823 | rc = VINF_SUCCESS;
|
---|
824 | } break;
|
---|
825 |
|
---|
826 | case VRDP_CLIENT_INTERCEPT_USB:
|
---|
827 | {
|
---|
828 | server->mConsole->VRDPInterceptUSB (u32ClientId, ppvIntercept);
|
---|
829 | rc = VINF_SUCCESS;
|
---|
830 | } break;
|
---|
831 |
|
---|
832 | case VRDP_CLIENT_INTERCEPT_CLIPBOARD:
|
---|
833 | {
|
---|
834 | server->mConsole->VRDPInterceptClipboard (u32ClientId);
|
---|
835 | if (ppvIntercept)
|
---|
836 | {
|
---|
837 | *ppvIntercept = server;
|
---|
838 | }
|
---|
839 | rc = VINF_SUCCESS;
|
---|
840 | } break;
|
---|
841 |
|
---|
842 | default:
|
---|
843 | break;
|
---|
844 | }
|
---|
845 |
|
---|
846 | return rc;
|
---|
847 | }
|
---|
848 |
|
---|
849 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet)
|
---|
850 | {
|
---|
851 | #ifdef VBOX_WITH_USB
|
---|
852 | return USBClientResponseCallback (pvIntercept, u32ClientId, u8Code, pvRet, cbRet);
|
---|
853 | #else
|
---|
854 | return VERR_NOT_SUPPORTED;
|
---|
855 | #endif
|
---|
856 | }
|
---|
857 |
|
---|
858 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData)
|
---|
859 | {
|
---|
860 | return ClipboardCallback (pvIntercept, u32ClientId, u32Function, u32Format, pvData, cbData);
|
---|
861 | }
|
---|
862 |
|
---|
863 | DECLCALLBACK(bool) ConsoleVRDPServer::VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDPFRAMEBUFFERINFO *pInfo)
|
---|
864 | {
|
---|
865 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
866 |
|
---|
867 | bool fAvailable = false;
|
---|
868 |
|
---|
869 | IFramebuffer *pfb = NULL;
|
---|
870 | LONG xOrigin = 0;
|
---|
871 | LONG yOrigin = 0;
|
---|
872 |
|
---|
873 | server->mConsole->getDisplay ()->GetFramebuffer (uScreenId, &pfb, &xOrigin, &yOrigin);
|
---|
874 |
|
---|
875 | if (pfb)
|
---|
876 | {
|
---|
877 | pfb->Lock ();
|
---|
878 |
|
---|
879 | /* Query framebuffer parameters. */
|
---|
880 | ULONG lineSize = 0;
|
---|
881 | pfb->COMGETTER(BytesPerLine) (&lineSize);
|
---|
882 |
|
---|
883 | ULONG bitsPerPixel = 0;
|
---|
884 | pfb->COMGETTER(BitsPerPixel) (&bitsPerPixel);
|
---|
885 |
|
---|
886 | BYTE *address = NULL;
|
---|
887 | pfb->COMGETTER(Address) (&address);
|
---|
888 |
|
---|
889 | ULONG height = 0;
|
---|
890 | pfb->COMGETTER(Height) (&height);
|
---|
891 |
|
---|
892 | ULONG width = 0;
|
---|
893 | pfb->COMGETTER(Width) (&width);
|
---|
894 |
|
---|
895 | /* Now fill the information as requested by the caller. */
|
---|
896 | pInfo->pu8Bits = address;
|
---|
897 | pInfo->xOrigin = xOrigin;
|
---|
898 | pInfo->yOrigin = yOrigin;
|
---|
899 | pInfo->cWidth = width;
|
---|
900 | pInfo->cHeight = height;
|
---|
901 | pInfo->cBitsPerPixel = bitsPerPixel;
|
---|
902 | pInfo->cbLine = lineSize;
|
---|
903 |
|
---|
904 | pfb->Unlock ();
|
---|
905 |
|
---|
906 | fAvailable = true;
|
---|
907 | }
|
---|
908 |
|
---|
909 | if (server->maFramebuffers[uScreenId])
|
---|
910 | {
|
---|
911 | server->maFramebuffers[uScreenId]->Release ();
|
---|
912 | }
|
---|
913 | server->maFramebuffers[uScreenId] = pfb;
|
---|
914 |
|
---|
915 | return fAvailable;
|
---|
916 | }
|
---|
917 |
|
---|
918 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId)
|
---|
919 | {
|
---|
920 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
921 |
|
---|
922 | if (server->maFramebuffers[uScreenId])
|
---|
923 | {
|
---|
924 | server->maFramebuffers[uScreenId]->Lock ();
|
---|
925 | }
|
---|
926 | }
|
---|
927 |
|
---|
928 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId)
|
---|
929 | {
|
---|
930 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
931 |
|
---|
932 | if (server->maFramebuffers[uScreenId])
|
---|
933 | {
|
---|
934 | server->maFramebuffers[uScreenId]->Unlock ();
|
---|
935 | }
|
---|
936 | }
|
---|
937 |
|
---|
938 | static void fixKbdLockStatus (VRDPInputSynch *pInputSynch, IKeyboard *pKeyboard)
|
---|
939 | {
|
---|
940 | if ( pInputSynch->cGuestNumLockAdaptions
|
---|
941 | && (pInputSynch->fGuestNumLock != pInputSynch->fClientNumLock))
|
---|
942 | {
|
---|
943 | pInputSynch->cGuestNumLockAdaptions--;
|
---|
944 | pKeyboard->PutScancode(0x45);
|
---|
945 | pKeyboard->PutScancode(0x45 | 0x80);
|
---|
946 | }
|
---|
947 | if ( pInputSynch->cGuestCapsLockAdaptions
|
---|
948 | && (pInputSynch->fGuestCapsLock != pInputSynch->fClientCapsLock))
|
---|
949 | {
|
---|
950 | pInputSynch->cGuestCapsLockAdaptions--;
|
---|
951 | pKeyboard->PutScancode(0x3a);
|
---|
952 | pKeyboard->PutScancode(0x3a | 0x80);
|
---|
953 | }
|
---|
954 | }
|
---|
955 |
|
---|
956 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput)
|
---|
957 | {
|
---|
958 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
959 | Console *pConsole = server->mConsole;
|
---|
960 |
|
---|
961 | switch (type)
|
---|
962 | {
|
---|
963 | case VRDP_INPUT_SCANCODE:
|
---|
964 | {
|
---|
965 | if (cbInput == sizeof (VRDPINPUTSCANCODE))
|
---|
966 | {
|
---|
967 | IKeyboard *pKeyboard = pConsole->getKeyboard ();
|
---|
968 |
|
---|
969 | const VRDPINPUTSCANCODE *pInputScancode = (VRDPINPUTSCANCODE *)pvInput;
|
---|
970 |
|
---|
971 | /* Track lock keys. */
|
---|
972 | if (pInputScancode->uScancode == 0x45)
|
---|
973 | {
|
---|
974 | server->m_InputSynch.fClientNumLock = !server->m_InputSynch.fClientNumLock;
|
---|
975 | }
|
---|
976 | else if (pInputScancode->uScancode == 0x3a)
|
---|
977 | {
|
---|
978 | server->m_InputSynch.fClientCapsLock = !server->m_InputSynch.fClientCapsLock;
|
---|
979 | }
|
---|
980 | else if (pInputScancode->uScancode == 0x46)
|
---|
981 | {
|
---|
982 | server->m_InputSynch.fClientScrollLock = !server->m_InputSynch.fClientScrollLock;
|
---|
983 | }
|
---|
984 | else if ((pInputScancode->uScancode & 0x80) == 0)
|
---|
985 | {
|
---|
986 | /* Key pressed. */
|
---|
987 | fixKbdLockStatus (&server->m_InputSynch, pKeyboard);
|
---|
988 | }
|
---|
989 |
|
---|
990 | pKeyboard->PutScancode((LONG)pInputScancode->uScancode);
|
---|
991 | }
|
---|
992 | } break;
|
---|
993 |
|
---|
994 | case VRDP_INPUT_POINT:
|
---|
995 | {
|
---|
996 | if (cbInput == sizeof (VRDPINPUTPOINT))
|
---|
997 | {
|
---|
998 | const VRDPINPUTPOINT *pInputPoint = (VRDPINPUTPOINT *)pvInput;
|
---|
999 |
|
---|
1000 | int mouseButtons = 0;
|
---|
1001 | int iWheel = 0;
|
---|
1002 |
|
---|
1003 | if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON1)
|
---|
1004 | {
|
---|
1005 | mouseButtons |= MouseButtonState_LeftButton;
|
---|
1006 | }
|
---|
1007 | if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON2)
|
---|
1008 | {
|
---|
1009 | mouseButtons |= MouseButtonState_RightButton;
|
---|
1010 | }
|
---|
1011 | if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON3)
|
---|
1012 | {
|
---|
1013 | mouseButtons |= MouseButtonState_MiddleButton;
|
---|
1014 | }
|
---|
1015 | if (pInputPoint->uButtons & VRDP_INPUT_POINT_WHEEL_UP)
|
---|
1016 | {
|
---|
1017 | mouseButtons |= MouseButtonState_WheelUp;
|
---|
1018 | iWheel = -1;
|
---|
1019 | }
|
---|
1020 | if (pInputPoint->uButtons & VRDP_INPUT_POINT_WHEEL_DOWN)
|
---|
1021 | {
|
---|
1022 | mouseButtons |= MouseButtonState_WheelDown;
|
---|
1023 | iWheel = 1;
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | if (server->m_fGuestWantsAbsolute)
|
---|
1027 | {
|
---|
1028 | pConsole->getMouse()->PutMouseEventAbsolute (pInputPoint->x + 1, pInputPoint->y + 1, iWheel, mouseButtons);
|
---|
1029 | } else
|
---|
1030 | {
|
---|
1031 | pConsole->getMouse()->PutMouseEvent (pInputPoint->x - server->m_mousex,
|
---|
1032 | pInputPoint->y - server->m_mousey,
|
---|
1033 | iWheel, mouseButtons);
|
---|
1034 | server->m_mousex = pInputPoint->x;
|
---|
1035 | server->m_mousey = pInputPoint->y;
|
---|
1036 | }
|
---|
1037 | }
|
---|
1038 | } break;
|
---|
1039 |
|
---|
1040 | case VRDP_INPUT_CAD:
|
---|
1041 | {
|
---|
1042 | pConsole->getKeyboard ()->PutCAD();
|
---|
1043 | } break;
|
---|
1044 |
|
---|
1045 | case VRDP_INPUT_RESET:
|
---|
1046 | {
|
---|
1047 | pConsole->Reset();
|
---|
1048 | } break;
|
---|
1049 |
|
---|
1050 | case VRDP_INPUT_SYNCH:
|
---|
1051 | {
|
---|
1052 | if (cbInput == sizeof (VRDPINPUTSYNCH))
|
---|
1053 | {
|
---|
1054 | IKeyboard *pKeyboard = pConsole->getKeyboard ();
|
---|
1055 |
|
---|
1056 | const VRDPINPUTSYNCH *pInputSynch = (VRDPINPUTSYNCH *)pvInput;
|
---|
1057 |
|
---|
1058 | server->m_InputSynch.fClientNumLock = (pInputSynch->uLockStatus & VRDP_INPUT_SYNCH_NUMLOCK) != 0;
|
---|
1059 | server->m_InputSynch.fClientCapsLock = (pInputSynch->uLockStatus & VRDP_INPUT_SYNCH_CAPITAL) != 0;
|
---|
1060 | server->m_InputSynch.fClientScrollLock = (pInputSynch->uLockStatus & VRDP_INPUT_SYNCH_SCROLL) != 0;
|
---|
1061 |
|
---|
1062 | /* The client initiated synchronization. Always make the guest to reflect the client state.
|
---|
1063 | * Than means, when the guest changes the state itself, it is forced to return to the client
|
---|
1064 | * state.
|
---|
1065 | */
|
---|
1066 | if (server->m_InputSynch.fClientNumLock != server->m_InputSynch.fGuestNumLock)
|
---|
1067 | {
|
---|
1068 | server->m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | if (server->m_InputSynch.fClientCapsLock != server->m_InputSynch.fGuestCapsLock)
|
---|
1072 | {
|
---|
1073 | server->m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | fixKbdLockStatus (&server->m_InputSynch, pKeyboard);
|
---|
1077 | }
|
---|
1078 | } break;
|
---|
1079 |
|
---|
1080 | default:
|
---|
1081 | break;
|
---|
1082 | }
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId)
|
---|
1086 | {
|
---|
1087 | ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
|
---|
1088 |
|
---|
1089 | server->mConsole->getDisplay ()->SetVideoModeHint(cWidth, cHeight, cBitsPerPixel, uScreenId);
|
---|
1090 | }
|
---|
1091 | #endif /* VBOX_WITH_VRDP */
|
---|
1092 |
|
---|
1093 | ConsoleVRDPServer::ConsoleVRDPServer (Console *console)
|
---|
1094 | {
|
---|
1095 | mConsole = console;
|
---|
1096 |
|
---|
1097 | int rc = RTCritSectInit (&mCritSect);
|
---|
1098 | AssertRC (rc);
|
---|
1099 |
|
---|
1100 | mcClipboardRefs = 0;
|
---|
1101 | mpfnClipboardCallback = NULL;
|
---|
1102 |
|
---|
1103 | #ifdef VBOX_WITH_USB
|
---|
1104 | mUSBBackends.pHead = NULL;
|
---|
1105 | mUSBBackends.pTail = NULL;
|
---|
1106 |
|
---|
1107 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
1108 | mUSBBackends.fThreadRunning = false;
|
---|
1109 | mUSBBackends.event = 0;
|
---|
1110 | #endif
|
---|
1111 |
|
---|
1112 | #ifdef VBOX_WITH_VRDP
|
---|
1113 | mhServer = 0;
|
---|
1114 |
|
---|
1115 | m_fGuestWantsAbsolute = false;
|
---|
1116 | m_mousex = 0;
|
---|
1117 | m_mousey = 0;
|
---|
1118 |
|
---|
1119 | m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
1120 | m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
1121 |
|
---|
1122 | m_InputSynch.fGuestNumLock = false;
|
---|
1123 | m_InputSynch.fGuestCapsLock = false;
|
---|
1124 | m_InputSynch.fGuestScrollLock = false;
|
---|
1125 |
|
---|
1126 | m_InputSynch.fClientNumLock = false;
|
---|
1127 | m_InputSynch.fClientCapsLock = false;
|
---|
1128 | m_InputSynch.fClientScrollLock = false;
|
---|
1129 |
|
---|
1130 | memset (maFramebuffers, 0, sizeof (maFramebuffers));
|
---|
1131 |
|
---|
1132 | mConsoleCallback = new VRDPConsoleCallback(this);
|
---|
1133 | mConsoleCallback->AddRef();
|
---|
1134 | console->RegisterCallback(mConsoleCallback);
|
---|
1135 | #endif /* VBOX_WITH_VRDP */
|
---|
1136 |
|
---|
1137 | mAuthLibrary = 0;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | ConsoleVRDPServer::~ConsoleVRDPServer ()
|
---|
1141 | {
|
---|
1142 | Stop ();
|
---|
1143 |
|
---|
1144 | #ifdef VBOX_WITH_VRDP
|
---|
1145 | if (mConsoleCallback)
|
---|
1146 | {
|
---|
1147 | mConsole->UnregisterCallback(mConsoleCallback);
|
---|
1148 | mConsoleCallback->Release();
|
---|
1149 | mConsoleCallback = NULL;
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | unsigned i;
|
---|
1153 | for (i = 0; i < RT_ELEMENTS(maFramebuffers); i++)
|
---|
1154 | {
|
---|
1155 | if (maFramebuffers[i])
|
---|
1156 | {
|
---|
1157 | maFramebuffers[i]->Release ();
|
---|
1158 | maFramebuffers[i] = NULL;
|
---|
1159 | }
|
---|
1160 | }
|
---|
1161 | #endif /* VBOX_WITH_VRDP */
|
---|
1162 |
|
---|
1163 | if (RTCritSectIsInitialized (&mCritSect))
|
---|
1164 | {
|
---|
1165 | RTCritSectDelete (&mCritSect);
|
---|
1166 | memset (&mCritSect, 0, sizeof (mCritSect));
|
---|
1167 | }
|
---|
1168 | }
|
---|
1169 |
|
---|
1170 | int ConsoleVRDPServer::Launch (void)
|
---|
1171 | {
|
---|
1172 | LogFlowMember(("ConsoleVRDPServer::Launch\n"));
|
---|
1173 | #ifdef VBOX_WITH_VRDP
|
---|
1174 | int rc = VINF_SUCCESS;
|
---|
1175 | IVRDPServer *vrdpserver = mConsole->getVRDPServer ();
|
---|
1176 | Assert(vrdpserver);
|
---|
1177 | BOOL vrdpEnabled = FALSE;
|
---|
1178 |
|
---|
1179 | HRESULT rc2 = vrdpserver->COMGETTER(Enabled) (&vrdpEnabled);
|
---|
1180 | AssertComRC(rc2);
|
---|
1181 |
|
---|
1182 | if (SUCCEEDED(rc2) && vrdpEnabled)
|
---|
1183 | {
|
---|
1184 | if (loadVRDPLibrary ())
|
---|
1185 | {
|
---|
1186 | rc = mpfnVRDPCreateServer (&mCallbacks.header, this, (VRDPINTERFACEHDR **)&mpEntryPoints, &mhServer);
|
---|
1187 |
|
---|
1188 | if (RT_SUCCESS(rc))
|
---|
1189 | {
|
---|
1190 | #ifdef VBOX_WITH_USB
|
---|
1191 | remoteUSBThreadStart ();
|
---|
1192 | #endif /* VBOX_WITH_USB */
|
---|
1193 | }
|
---|
1194 | else
|
---|
1195 | AssertMsgFailed(("Could not start VRDP server: rc = %Rrc\n", rc));
|
---|
1196 | }
|
---|
1197 | else
|
---|
1198 | {
|
---|
1199 | AssertMsgFailed(("Could not load the VRDP library\n"));
|
---|
1200 | rc = VERR_FILE_NOT_FOUND;
|
---|
1201 | }
|
---|
1202 | }
|
---|
1203 | #else
|
---|
1204 | int rc = VERR_NOT_SUPPORTED;
|
---|
1205 | LogRel(("VRDP: this version does not include the VRDP server.\n"));
|
---|
1206 | #endif /* VBOX_WITH_VRDP */
|
---|
1207 | return rc;
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | void ConsoleVRDPServer::EnableConnections (void)
|
---|
1211 | {
|
---|
1212 | #ifdef VBOX_WITH_VRDP
|
---|
1213 | if (mpEntryPoints && mhServer)
|
---|
1214 | {
|
---|
1215 | mpEntryPoints->VRDPEnableConnections (mhServer, true);
|
---|
1216 | }
|
---|
1217 | #endif /* VBOX_WITH_VRDP */
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | void ConsoleVRDPServer::DisconnectClient (uint32_t u32ClientId, bool fReconnect)
|
---|
1221 | {
|
---|
1222 | #ifdef VBOX_WITH_VRDP
|
---|
1223 | if (mpEntryPoints && mhServer)
|
---|
1224 | {
|
---|
1225 | mpEntryPoints->VRDPDisconnect (mhServer, u32ClientId, fReconnect);
|
---|
1226 | }
|
---|
1227 | #endif /* VBOX_WITH_VRDP */
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | void ConsoleVRDPServer::MousePointerUpdate (const VRDPCOLORPOINTER *pPointer)
|
---|
1231 | {
|
---|
1232 | #ifdef VBOX_WITH_VRDP
|
---|
1233 | if (mpEntryPoints && mhServer)
|
---|
1234 | {
|
---|
1235 | mpEntryPoints->VRDPColorPointer (mhServer, pPointer);
|
---|
1236 | }
|
---|
1237 | #endif /* VBOX_WITH_VRDP */
|
---|
1238 | }
|
---|
1239 |
|
---|
1240 | void ConsoleVRDPServer::MousePointerHide (void)
|
---|
1241 | {
|
---|
1242 | #ifdef VBOX_WITH_VRDP
|
---|
1243 | if (mpEntryPoints && mhServer)
|
---|
1244 | {
|
---|
1245 | mpEntryPoints->VRDPHidePointer (mhServer);
|
---|
1246 | }
|
---|
1247 | #endif /* VBOX_WITH_VRDP */
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | void ConsoleVRDPServer::Stop (void)
|
---|
1251 | {
|
---|
1252 | Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
|
---|
1253 | * linux. Just remove this when it's 100% sure that problem has been fixed. */
|
---|
1254 | #ifdef VBOX_WITH_VRDP
|
---|
1255 | if (mhServer)
|
---|
1256 | {
|
---|
1257 | HVRDPSERVER hServer = mhServer;
|
---|
1258 |
|
---|
1259 | /* Reset the handle to avoid further calls to the server. */
|
---|
1260 | mhServer = 0;
|
---|
1261 |
|
---|
1262 | if (mpEntryPoints && hServer)
|
---|
1263 | {
|
---|
1264 | mpEntryPoints->VRDPDestroy (hServer);
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 | #endif /* VBOX_WITH_VRDP */
|
---|
1268 |
|
---|
1269 | #ifdef VBOX_WITH_USB
|
---|
1270 | remoteUSBThreadStop ();
|
---|
1271 | #endif /* VBOX_WITH_USB */
|
---|
1272 |
|
---|
1273 | mpfnAuthEntry = NULL;
|
---|
1274 | mpfnAuthEntry2 = NULL;
|
---|
1275 |
|
---|
1276 | if (mAuthLibrary)
|
---|
1277 | {
|
---|
1278 | RTLdrClose(mAuthLibrary);
|
---|
1279 | mAuthLibrary = 0;
|
---|
1280 | }
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | /* Worker thread for Remote USB. The thread polls the clients for
|
---|
1284 | * the list of attached USB devices.
|
---|
1285 | * The thread is also responsible for attaching/detaching devices
|
---|
1286 | * to/from the VM.
|
---|
1287 | *
|
---|
1288 | * It is expected that attaching/detaching is not a frequent operation.
|
---|
1289 | *
|
---|
1290 | * The thread is always running when the VRDP server is active.
|
---|
1291 | *
|
---|
1292 | * The thread scans backends and requests the device list every 2 seconds.
|
---|
1293 | *
|
---|
1294 | * When device list is available, the thread calls the Console to process it.
|
---|
1295 | *
|
---|
1296 | */
|
---|
1297 | #define VRDP_DEVICE_LIST_PERIOD_MS (2000)
|
---|
1298 |
|
---|
1299 | #ifdef VBOX_WITH_USB
|
---|
1300 | static DECLCALLBACK(int) threadRemoteUSB (RTTHREAD self, void *pvUser)
|
---|
1301 | {
|
---|
1302 | ConsoleVRDPServer *pOwner = (ConsoleVRDPServer *)pvUser;
|
---|
1303 |
|
---|
1304 | LogFlow(("Console::threadRemoteUSB: start. owner = %p.\n", pOwner));
|
---|
1305 |
|
---|
1306 | pOwner->notifyRemoteUSBThreadRunning (self);
|
---|
1307 |
|
---|
1308 | while (pOwner->isRemoteUSBThreadRunning ())
|
---|
1309 | {
|
---|
1310 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
1311 |
|
---|
1312 | while ((pRemoteUSBBackend = pOwner->usbBackendGetNext (pRemoteUSBBackend)) != NULL)
|
---|
1313 | {
|
---|
1314 | pRemoteUSBBackend->PollRemoteDevices ();
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | pOwner->waitRemoteUSBThreadEvent (VRDP_DEVICE_LIST_PERIOD_MS);
|
---|
1318 |
|
---|
1319 | LogFlow(("Console::threadRemoteUSB: iteration. owner = %p.\n", pOwner));
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | return VINF_SUCCESS;
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | void ConsoleVRDPServer::notifyRemoteUSBThreadRunning (RTTHREAD thread)
|
---|
1326 | {
|
---|
1327 | mUSBBackends.thread = thread;
|
---|
1328 | mUSBBackends.fThreadRunning = true;
|
---|
1329 | int rc = RTThreadUserSignal (thread);
|
---|
1330 | AssertRC (rc);
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | bool ConsoleVRDPServer::isRemoteUSBThreadRunning (void)
|
---|
1334 | {
|
---|
1335 | return mUSBBackends.fThreadRunning;
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | void ConsoleVRDPServer::waitRemoteUSBThreadEvent (unsigned cMillies)
|
---|
1339 | {
|
---|
1340 | int rc = RTSemEventWait (mUSBBackends.event, cMillies);
|
---|
1341 | Assert (RT_SUCCESS(rc) || rc == VERR_TIMEOUT);
|
---|
1342 | NOREF(rc);
|
---|
1343 | }
|
---|
1344 |
|
---|
1345 | void ConsoleVRDPServer::remoteUSBThreadStart (void)
|
---|
1346 | {
|
---|
1347 | int rc = RTSemEventCreate (&mUSBBackends.event);
|
---|
1348 |
|
---|
1349 | if (RT_FAILURE(rc))
|
---|
1350 | {
|
---|
1351 | AssertFailed ();
|
---|
1352 | mUSBBackends.event = 0;
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 | if (RT_SUCCESS(rc))
|
---|
1356 | {
|
---|
1357 | rc = RTThreadCreate (&mUSBBackends.thread, threadRemoteUSB, this, 65536,
|
---|
1358 | RTTHREADTYPE_VRDP_IO, RTTHREADFLAGS_WAITABLE, "remote usb");
|
---|
1359 | }
|
---|
1360 |
|
---|
1361 | if (RT_FAILURE(rc))
|
---|
1362 | {
|
---|
1363 | LogRel(("Warning: could not start the remote USB thread, rc = %Rrc!!!\n", rc));
|
---|
1364 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
1365 | }
|
---|
1366 | else
|
---|
1367 | {
|
---|
1368 | /* Wait until the thread is ready. */
|
---|
1369 | rc = RTThreadUserWait (mUSBBackends.thread, 60000);
|
---|
1370 | AssertRC (rc);
|
---|
1371 | Assert (mUSBBackends.fThreadRunning || RT_FAILURE(rc));
|
---|
1372 | }
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 | void ConsoleVRDPServer::remoteUSBThreadStop (void)
|
---|
1376 | {
|
---|
1377 | mUSBBackends.fThreadRunning = false;
|
---|
1378 |
|
---|
1379 | if (mUSBBackends.thread != NIL_RTTHREAD)
|
---|
1380 | {
|
---|
1381 | Assert (mUSBBackends.event != 0);
|
---|
1382 |
|
---|
1383 | RTSemEventSignal (mUSBBackends.event);
|
---|
1384 |
|
---|
1385 | int rc = RTThreadWait (mUSBBackends.thread, 60000, NULL);
|
---|
1386 | AssertRC (rc);
|
---|
1387 |
|
---|
1388 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 | if (mUSBBackends.event)
|
---|
1392 | {
|
---|
1393 | RTSemEventDestroy (mUSBBackends.event);
|
---|
1394 | mUSBBackends.event = 0;
|
---|
1395 | }
|
---|
1396 | }
|
---|
1397 | #endif /* VBOX_WITH_USB */
|
---|
1398 |
|
---|
1399 | VRDPAuthResult ConsoleVRDPServer::Authenticate (const Guid &uuid, VRDPAuthGuestJudgement guestJudgement,
|
---|
1400 | const char *pszUser, const char *pszPassword, const char *pszDomain,
|
---|
1401 | uint32_t u32ClientId)
|
---|
1402 | {
|
---|
1403 | VRDPAUTHUUID rawuuid;
|
---|
1404 |
|
---|
1405 | memcpy (rawuuid, ((Guid &)uuid).ptr (), sizeof (rawuuid));
|
---|
1406 |
|
---|
1407 | LogFlow(("ConsoleVRDPServer::Authenticate: uuid = %RTuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n",
|
---|
1408 | rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId));
|
---|
1409 |
|
---|
1410 | /*
|
---|
1411 | * Called only from VRDP input thread. So thread safety is not required.
|
---|
1412 | */
|
---|
1413 |
|
---|
1414 | if (!mAuthLibrary)
|
---|
1415 | {
|
---|
1416 | /* Load the external authentication library. */
|
---|
1417 |
|
---|
1418 | ComPtr<IMachine> machine;
|
---|
1419 | mConsole->COMGETTER(Machine)(machine.asOutParam());
|
---|
1420 |
|
---|
1421 | ComPtr<IVirtualBox> virtualBox;
|
---|
1422 | machine->COMGETTER(Parent)(virtualBox.asOutParam());
|
---|
1423 |
|
---|
1424 | ComPtr<ISystemProperties> systemProperties;
|
---|
1425 | virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
|
---|
1426 |
|
---|
1427 | Bstr authLibrary;
|
---|
1428 | systemProperties->COMGETTER(RemoteDisplayAuthLibrary)(authLibrary.asOutParam());
|
---|
1429 |
|
---|
1430 | Utf8Str filename = authLibrary;
|
---|
1431 |
|
---|
1432 | LogRel(("VRDPAUTH: ConsoleVRDPServer::Authenticate: loading external authentication library '%ls'\n", authLibrary.raw()));
|
---|
1433 |
|
---|
1434 | int rc = RTLdrLoad (filename.raw(), &mAuthLibrary);
|
---|
1435 | if (RT_FAILURE(rc))
|
---|
1436 | LogRel(("VRDPAUTH: Failed to load external authentication library. Error code: %Rrc\n", rc));
|
---|
1437 |
|
---|
1438 | if (RT_SUCCESS(rc))
|
---|
1439 | {
|
---|
1440 | /* Get the entry point. */
|
---|
1441 | mpfnAuthEntry2 = NULL;
|
---|
1442 | int rc2 = RTLdrGetSymbol(mAuthLibrary, "VRDPAuth2", (void**)&mpfnAuthEntry2);
|
---|
1443 | if (RT_FAILURE(rc2))
|
---|
1444 | {
|
---|
1445 | if (rc2 != VERR_SYMBOL_NOT_FOUND)
|
---|
1446 | {
|
---|
1447 | LogRel(("VRDPAUTH: Could not resolve import '%s'. Error code: %Rrc\n", "VRDPAuth2", rc2));
|
---|
1448 | }
|
---|
1449 | rc = rc2;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | /* Get the entry point. */
|
---|
1453 | mpfnAuthEntry = NULL;
|
---|
1454 | rc2 = RTLdrGetSymbol(mAuthLibrary, "VRDPAuth", (void**)&mpfnAuthEntry);
|
---|
1455 | if (RT_FAILURE(rc2))
|
---|
1456 | {
|
---|
1457 | if (rc2 != VERR_SYMBOL_NOT_FOUND)
|
---|
1458 | {
|
---|
1459 | LogRel(("VRDPAUTH: Could not resolve import '%s'. Error code: %Rrc\n", "VRDPAuth", rc2));
|
---|
1460 | }
|
---|
1461 | rc = rc2;
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 | if (mpfnAuthEntry2 || mpfnAuthEntry)
|
---|
1465 | {
|
---|
1466 | LogRel(("VRDPAUTH: Using entry point '%s'.\n", mpfnAuthEntry2? "VRDPAuth2": "VRDPAuth"));
|
---|
1467 | rc = VINF_SUCCESS;
|
---|
1468 | }
|
---|
1469 | }
|
---|
1470 |
|
---|
1471 | if (RT_FAILURE(rc))
|
---|
1472 | {
|
---|
1473 | mConsole->reportAuthLibraryError (filename.raw(), rc);
|
---|
1474 |
|
---|
1475 | mpfnAuthEntry = NULL;
|
---|
1476 | mpfnAuthEntry2 = NULL;
|
---|
1477 |
|
---|
1478 | if (mAuthLibrary)
|
---|
1479 | {
|
---|
1480 | RTLdrClose(mAuthLibrary);
|
---|
1481 | mAuthLibrary = 0;
|
---|
1482 | }
|
---|
1483 |
|
---|
1484 | return VRDPAuthAccessDenied;
|
---|
1485 | }
|
---|
1486 | }
|
---|
1487 |
|
---|
1488 | Assert (mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2));
|
---|
1489 |
|
---|
1490 | VRDPAuthResult result = mpfnAuthEntry2?
|
---|
1491 | mpfnAuthEntry2 (&rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, true, u32ClientId):
|
---|
1492 | mpfnAuthEntry (&rawuuid, guestJudgement, pszUser, pszPassword, pszDomain);
|
---|
1493 |
|
---|
1494 | switch (result)
|
---|
1495 | {
|
---|
1496 | case VRDPAuthAccessDenied:
|
---|
1497 | LogRel(("VRDPAUTH: external authentication module returned 'access denied'\n"));
|
---|
1498 | break;
|
---|
1499 | case VRDPAuthAccessGranted:
|
---|
1500 | LogRel(("VRDPAUTH: external authentication module returned 'access granted'\n"));
|
---|
1501 | break;
|
---|
1502 | case VRDPAuthDelegateToGuest:
|
---|
1503 | LogRel(("VRDPAUTH: external authentication module returned 'delegate request to guest'\n"));
|
---|
1504 | break;
|
---|
1505 | default:
|
---|
1506 | LogRel(("VRDPAUTH: external authentication module returned incorrect return code %d\n", result));
|
---|
1507 | result = VRDPAuthAccessDenied;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | LogFlow(("ConsoleVRDPServer::Authenticate: result = %d\n", result));
|
---|
1511 |
|
---|
1512 | return result;
|
---|
1513 | }
|
---|
1514 |
|
---|
1515 | void ConsoleVRDPServer::AuthDisconnect (const Guid &uuid, uint32_t u32ClientId)
|
---|
1516 | {
|
---|
1517 | VRDPAUTHUUID rawuuid;
|
---|
1518 |
|
---|
1519 | memcpy (rawuuid, ((Guid &)uuid).ptr (), sizeof (rawuuid));
|
---|
1520 |
|
---|
1521 | LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %RTuuid, u32ClientId = %d\n",
|
---|
1522 | rawuuid, u32ClientId));
|
---|
1523 |
|
---|
1524 | Assert (mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2));
|
---|
1525 |
|
---|
1526 | if (mpfnAuthEntry2)
|
---|
1527 | mpfnAuthEntry2 (&rawuuid, VRDPAuthGuestNotAsked, NULL, NULL, NULL, false, u32ClientId);
|
---|
1528 | }
|
---|
1529 |
|
---|
1530 | int ConsoleVRDPServer::lockConsoleVRDPServer (void)
|
---|
1531 | {
|
---|
1532 | int rc = RTCritSectEnter (&mCritSect);
|
---|
1533 | AssertRC (rc);
|
---|
1534 | return rc;
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 | void ConsoleVRDPServer::unlockConsoleVRDPServer (void)
|
---|
1538 | {
|
---|
1539 | RTCritSectLeave (&mCritSect);
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | DECLCALLBACK(int) ConsoleVRDPServer::ClipboardCallback (void *pvCallback,
|
---|
1543 | uint32_t u32ClientId,
|
---|
1544 | uint32_t u32Function,
|
---|
1545 | uint32_t u32Format,
|
---|
1546 | const void *pvData,
|
---|
1547 | uint32_t cbData)
|
---|
1548 | {
|
---|
1549 | LogFlowFunc(("pvCallback = %p, u32ClientId = %d, u32Function = %d, u32Format = 0x%08X, pvData = %p, cbData = %d\n",
|
---|
1550 | pvCallback, u32ClientId, u32Function, u32Format, pvData, cbData));
|
---|
1551 |
|
---|
1552 | int rc = VINF_SUCCESS;
|
---|
1553 |
|
---|
1554 | ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvCallback);
|
---|
1555 |
|
---|
1556 | NOREF(u32ClientId);
|
---|
1557 |
|
---|
1558 | switch (u32Function)
|
---|
1559 | {
|
---|
1560 | case VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE:
|
---|
1561 | {
|
---|
1562 | if (pServer->mpfnClipboardCallback)
|
---|
1563 | {
|
---|
1564 | pServer->mpfnClipboardCallback (VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
|
---|
1565 | u32Format,
|
---|
1566 | (void *)pvData,
|
---|
1567 | cbData);
|
---|
1568 | }
|
---|
1569 | } break;
|
---|
1570 |
|
---|
1571 | case VRDP_CLIPBOARD_FUNCTION_DATA_READ:
|
---|
1572 | {
|
---|
1573 | if (pServer->mpfnClipboardCallback)
|
---|
1574 | {
|
---|
1575 | pServer->mpfnClipboardCallback (VBOX_CLIPBOARD_EXT_FN_DATA_READ,
|
---|
1576 | u32Format,
|
---|
1577 | (void *)pvData,
|
---|
1578 | cbData);
|
---|
1579 | }
|
---|
1580 | } break;
|
---|
1581 |
|
---|
1582 | default:
|
---|
1583 | rc = VERR_NOT_SUPPORTED;
|
---|
1584 | }
|
---|
1585 |
|
---|
1586 | return rc;
|
---|
1587 | }
|
---|
1588 |
|
---|
1589 | DECLCALLBACK(int) ConsoleVRDPServer::ClipboardServiceExtension (void *pvExtension,
|
---|
1590 | uint32_t u32Function,
|
---|
1591 | void *pvParms,
|
---|
1592 | uint32_t cbParms)
|
---|
1593 | {
|
---|
1594 | LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
|
---|
1595 | pvExtension, u32Function, pvParms, cbParms));
|
---|
1596 |
|
---|
1597 | int rc = VINF_SUCCESS;
|
---|
1598 |
|
---|
1599 | #ifdef VBOX_WITH_VRDP
|
---|
1600 | ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvExtension);
|
---|
1601 |
|
---|
1602 | VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms;
|
---|
1603 |
|
---|
1604 | switch (u32Function)
|
---|
1605 | {
|
---|
1606 | case VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK:
|
---|
1607 | {
|
---|
1608 | pServer->mpfnClipboardCallback = pParms->u.pfnCallback;
|
---|
1609 | } break;
|
---|
1610 |
|
---|
1611 | case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
|
---|
1612 | {
|
---|
1613 | /* The guest announces clipboard formats. This must be delivered to all clients. */
|
---|
1614 | if (mpEntryPoints && pServer->mhServer)
|
---|
1615 | {
|
---|
1616 | mpEntryPoints->VRDPClipboard (pServer->mhServer,
|
---|
1617 | VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
|
---|
1618 | pParms->u32Format,
|
---|
1619 | NULL,
|
---|
1620 | 0,
|
---|
1621 | NULL);
|
---|
1622 | }
|
---|
1623 | } break;
|
---|
1624 |
|
---|
1625 | case VBOX_CLIPBOARD_EXT_FN_DATA_READ:
|
---|
1626 | {
|
---|
1627 | /* The clipboard service expects that the pvData buffer will be filled
|
---|
1628 | * with clipboard data. The server returns the data from the client that
|
---|
1629 | * announced the requested format most recently.
|
---|
1630 | */
|
---|
1631 | if (mpEntryPoints && pServer->mhServer)
|
---|
1632 | {
|
---|
1633 | mpEntryPoints->VRDPClipboard (pServer->mhServer,
|
---|
1634 | VRDP_CLIPBOARD_FUNCTION_DATA_READ,
|
---|
1635 | pParms->u32Format,
|
---|
1636 | pParms->u.pvData,
|
---|
1637 | pParms->cbData,
|
---|
1638 | &pParms->cbData);
|
---|
1639 | }
|
---|
1640 | } break;
|
---|
1641 |
|
---|
1642 | case VBOX_CLIPBOARD_EXT_FN_DATA_WRITE:
|
---|
1643 | {
|
---|
1644 | if (mpEntryPoints && pServer->mhServer)
|
---|
1645 | {
|
---|
1646 | mpEntryPoints->VRDPClipboard (pServer->mhServer,
|
---|
1647 | VRDP_CLIPBOARD_FUNCTION_DATA_WRITE,
|
---|
1648 | pParms->u32Format,
|
---|
1649 | pParms->u.pvData,
|
---|
1650 | pParms->cbData,
|
---|
1651 | NULL);
|
---|
1652 | }
|
---|
1653 | } break;
|
---|
1654 |
|
---|
1655 | default:
|
---|
1656 | rc = VERR_NOT_SUPPORTED;
|
---|
1657 | }
|
---|
1658 | #endif /* VBOX_WITH_VRDP */
|
---|
1659 |
|
---|
1660 | return rc;
|
---|
1661 | }
|
---|
1662 |
|
---|
1663 | void ConsoleVRDPServer::ClipboardCreate (uint32_t u32ClientId)
|
---|
1664 | {
|
---|
1665 | int rc = lockConsoleVRDPServer ();
|
---|
1666 |
|
---|
1667 | if (RT_SUCCESS(rc))
|
---|
1668 | {
|
---|
1669 | if (mcClipboardRefs == 0)
|
---|
1670 | {
|
---|
1671 | rc = HGCMHostRegisterServiceExtension (&mhClipboard, "VBoxSharedClipboard", ClipboardServiceExtension, this);
|
---|
1672 |
|
---|
1673 | if (RT_SUCCESS(rc))
|
---|
1674 | {
|
---|
1675 | mcClipboardRefs++;
|
---|
1676 | }
|
---|
1677 | }
|
---|
1678 |
|
---|
1679 | unlockConsoleVRDPServer ();
|
---|
1680 | }
|
---|
1681 | }
|
---|
1682 |
|
---|
1683 | void ConsoleVRDPServer::ClipboardDelete (uint32_t u32ClientId)
|
---|
1684 | {
|
---|
1685 | int rc = lockConsoleVRDPServer ();
|
---|
1686 |
|
---|
1687 | if (RT_SUCCESS(rc))
|
---|
1688 | {
|
---|
1689 | mcClipboardRefs--;
|
---|
1690 |
|
---|
1691 | if (mcClipboardRefs == 0)
|
---|
1692 | {
|
---|
1693 | HGCMHostUnregisterServiceExtension (mhClipboard);
|
---|
1694 | }
|
---|
1695 |
|
---|
1696 | unlockConsoleVRDPServer ();
|
---|
1697 | }
|
---|
1698 | }
|
---|
1699 |
|
---|
1700 | /* That is called on INPUT thread of the VRDP server.
|
---|
1701 | * The ConsoleVRDPServer keeps a list of created backend instances.
|
---|
1702 | */
|
---|
1703 | void ConsoleVRDPServer::USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept)
|
---|
1704 | {
|
---|
1705 | #ifdef VBOX_WITH_USB
|
---|
1706 | LogFlow(("ConsoleVRDPServer::USBBackendCreate: u32ClientId = %d\n", u32ClientId));
|
---|
1707 |
|
---|
1708 | /* Create a new instance of the USB backend for the new client. */
|
---|
1709 | RemoteUSBBackend *pRemoteUSBBackend = new RemoteUSBBackend (mConsole, this, u32ClientId);
|
---|
1710 |
|
---|
1711 | if (pRemoteUSBBackend)
|
---|
1712 | {
|
---|
1713 | pRemoteUSBBackend->AddRef (); /* 'Release' called in USBBackendDelete. */
|
---|
1714 |
|
---|
1715 | /* Append the new instance in the list. */
|
---|
1716 | int rc = lockConsoleVRDPServer ();
|
---|
1717 |
|
---|
1718 | if (RT_SUCCESS(rc))
|
---|
1719 | {
|
---|
1720 | pRemoteUSBBackend->pNext = mUSBBackends.pHead;
|
---|
1721 | if (mUSBBackends.pHead)
|
---|
1722 | {
|
---|
1723 | mUSBBackends.pHead->pPrev = pRemoteUSBBackend;
|
---|
1724 | }
|
---|
1725 | else
|
---|
1726 | {
|
---|
1727 | mUSBBackends.pTail = pRemoteUSBBackend;
|
---|
1728 | }
|
---|
1729 |
|
---|
1730 | mUSBBackends.pHead = pRemoteUSBBackend;
|
---|
1731 |
|
---|
1732 | unlockConsoleVRDPServer ();
|
---|
1733 |
|
---|
1734 | if (ppvIntercept)
|
---|
1735 | {
|
---|
1736 | *ppvIntercept = pRemoteUSBBackend;
|
---|
1737 | }
|
---|
1738 | }
|
---|
1739 |
|
---|
1740 | if (RT_FAILURE(rc))
|
---|
1741 | {
|
---|
1742 | pRemoteUSBBackend->Release ();
|
---|
1743 | }
|
---|
1744 | }
|
---|
1745 | #endif /* VBOX_WITH_USB */
|
---|
1746 | }
|
---|
1747 |
|
---|
1748 | void ConsoleVRDPServer::USBBackendDelete (uint32_t u32ClientId)
|
---|
1749 | {
|
---|
1750 | #ifdef VBOX_WITH_USB
|
---|
1751 | LogFlow(("ConsoleVRDPServer::USBBackendDelete: u32ClientId = %d\n", u32ClientId));
|
---|
1752 |
|
---|
1753 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
1754 |
|
---|
1755 | /* Find the instance. */
|
---|
1756 | int rc = lockConsoleVRDPServer ();
|
---|
1757 |
|
---|
1758 | if (RT_SUCCESS(rc))
|
---|
1759 | {
|
---|
1760 | pRemoteUSBBackend = usbBackendFind (u32ClientId);
|
---|
1761 |
|
---|
1762 | if (pRemoteUSBBackend)
|
---|
1763 | {
|
---|
1764 | /* Notify that it will be deleted. */
|
---|
1765 | pRemoteUSBBackend->NotifyDelete ();
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | unlockConsoleVRDPServer ();
|
---|
1769 | }
|
---|
1770 |
|
---|
1771 | if (pRemoteUSBBackend)
|
---|
1772 | {
|
---|
1773 | /* Here the instance has been excluded from the list and can be dereferenced. */
|
---|
1774 | pRemoteUSBBackend->Release ();
|
---|
1775 | }
|
---|
1776 | #endif
|
---|
1777 | }
|
---|
1778 |
|
---|
1779 | void *ConsoleVRDPServer::USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid)
|
---|
1780 | {
|
---|
1781 | #ifdef VBOX_WITH_USB
|
---|
1782 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
1783 |
|
---|
1784 | /* Find the instance. */
|
---|
1785 | int rc = lockConsoleVRDPServer ();
|
---|
1786 |
|
---|
1787 | if (RT_SUCCESS(rc))
|
---|
1788 | {
|
---|
1789 | pRemoteUSBBackend = usbBackendFind (u32ClientId);
|
---|
1790 |
|
---|
1791 | if (pRemoteUSBBackend)
|
---|
1792 | {
|
---|
1793 | /* Inform the backend instance that it is referenced by the Guid. */
|
---|
1794 | bool fAdded = pRemoteUSBBackend->addUUID (pGuid);
|
---|
1795 |
|
---|
1796 | if (fAdded)
|
---|
1797 | {
|
---|
1798 | /* Reference the instance because its pointer is being taken. */
|
---|
1799 | pRemoteUSBBackend->AddRef (); /* 'Release' is called in USBBackendReleasePointer. */
|
---|
1800 | }
|
---|
1801 | else
|
---|
1802 | {
|
---|
1803 | pRemoteUSBBackend = NULL;
|
---|
1804 | }
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 | unlockConsoleVRDPServer ();
|
---|
1808 | }
|
---|
1809 |
|
---|
1810 | if (pRemoteUSBBackend)
|
---|
1811 | {
|
---|
1812 | return pRemoteUSBBackend->GetBackendCallbackPointer ();
|
---|
1813 | }
|
---|
1814 |
|
---|
1815 | #endif
|
---|
1816 | return NULL;
|
---|
1817 | }
|
---|
1818 |
|
---|
1819 | void ConsoleVRDPServer::USBBackendReleasePointer (const Guid *pGuid)
|
---|
1820 | {
|
---|
1821 | #ifdef VBOX_WITH_USB
|
---|
1822 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
1823 |
|
---|
1824 | /* Find the instance. */
|
---|
1825 | int rc = lockConsoleVRDPServer ();
|
---|
1826 |
|
---|
1827 | if (RT_SUCCESS(rc))
|
---|
1828 | {
|
---|
1829 | pRemoteUSBBackend = usbBackendFindByUUID (pGuid);
|
---|
1830 |
|
---|
1831 | if (pRemoteUSBBackend)
|
---|
1832 | {
|
---|
1833 | pRemoteUSBBackend->removeUUID (pGuid);
|
---|
1834 | }
|
---|
1835 |
|
---|
1836 | unlockConsoleVRDPServer ();
|
---|
1837 |
|
---|
1838 | if (pRemoteUSBBackend)
|
---|
1839 | {
|
---|
1840 | pRemoteUSBBackend->Release ();
|
---|
1841 | }
|
---|
1842 | }
|
---|
1843 | #endif
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend)
|
---|
1847 | {
|
---|
1848 | LogFlow(("ConsoleVRDPServer::usbBackendGetNext: pBackend = %p\n", pRemoteUSBBackend));
|
---|
1849 |
|
---|
1850 | RemoteUSBBackend *pNextRemoteUSBBackend = NULL;
|
---|
1851 | #ifdef VBOX_WITH_USB
|
---|
1852 |
|
---|
1853 | int rc = lockConsoleVRDPServer ();
|
---|
1854 |
|
---|
1855 | if (RT_SUCCESS(rc))
|
---|
1856 | {
|
---|
1857 | if (pRemoteUSBBackend == NULL)
|
---|
1858 | {
|
---|
1859 | /* The first backend in the list is requested. */
|
---|
1860 | pNextRemoteUSBBackend = mUSBBackends.pHead;
|
---|
1861 | }
|
---|
1862 | else
|
---|
1863 | {
|
---|
1864 | /* Get pointer to the next backend. */
|
---|
1865 | pNextRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
1866 | }
|
---|
1867 |
|
---|
1868 | if (pNextRemoteUSBBackend)
|
---|
1869 | {
|
---|
1870 | pNextRemoteUSBBackend->AddRef ();
|
---|
1871 | }
|
---|
1872 |
|
---|
1873 | unlockConsoleVRDPServer ();
|
---|
1874 |
|
---|
1875 | if (pRemoteUSBBackend)
|
---|
1876 | {
|
---|
1877 | pRemoteUSBBackend->Release ();
|
---|
1878 | }
|
---|
1879 | }
|
---|
1880 | #endif
|
---|
1881 |
|
---|
1882 | return pNextRemoteUSBBackend;
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | #ifdef VBOX_WITH_USB
|
---|
1886 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
1887 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFind (uint32_t u32ClientId)
|
---|
1888 | {
|
---|
1889 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
1890 |
|
---|
1891 | while (pRemoteUSBBackend)
|
---|
1892 | {
|
---|
1893 | if (pRemoteUSBBackend->ClientId () == u32ClientId)
|
---|
1894 | {
|
---|
1895 | break;
|
---|
1896 | }
|
---|
1897 |
|
---|
1898 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
1899 | }
|
---|
1900 |
|
---|
1901 | return pRemoteUSBBackend;
|
---|
1902 | }
|
---|
1903 |
|
---|
1904 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
1905 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFindByUUID (const Guid *pGuid)
|
---|
1906 | {
|
---|
1907 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
1908 |
|
---|
1909 | while (pRemoteUSBBackend)
|
---|
1910 | {
|
---|
1911 | if (pRemoteUSBBackend->findUUID (pGuid))
|
---|
1912 | {
|
---|
1913 | break;
|
---|
1914 | }
|
---|
1915 |
|
---|
1916 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 | return pRemoteUSBBackend;
|
---|
1920 | }
|
---|
1921 | #endif
|
---|
1922 |
|
---|
1923 | /* Internal method. Called by the backend destructor. */
|
---|
1924 | void ConsoleVRDPServer::usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend)
|
---|
1925 | {
|
---|
1926 | #ifdef VBOX_WITH_USB
|
---|
1927 | int rc = lockConsoleVRDPServer ();
|
---|
1928 | AssertRC (rc);
|
---|
1929 |
|
---|
1930 | /* Exclude the found instance from the list. */
|
---|
1931 | if (pRemoteUSBBackend->pNext)
|
---|
1932 | {
|
---|
1933 | pRemoteUSBBackend->pNext->pPrev = pRemoteUSBBackend->pPrev;
|
---|
1934 | }
|
---|
1935 | else
|
---|
1936 | {
|
---|
1937 | mUSBBackends.pTail = (RemoteUSBBackend *)pRemoteUSBBackend->pPrev;
|
---|
1938 | }
|
---|
1939 |
|
---|
1940 | if (pRemoteUSBBackend->pPrev)
|
---|
1941 | {
|
---|
1942 | pRemoteUSBBackend->pPrev->pNext = pRemoteUSBBackend->pNext;
|
---|
1943 | }
|
---|
1944 | else
|
---|
1945 | {
|
---|
1946 | mUSBBackends.pHead = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
1947 | }
|
---|
1948 |
|
---|
1949 | pRemoteUSBBackend->pNext = pRemoteUSBBackend->pPrev = NULL;
|
---|
1950 |
|
---|
1951 | unlockConsoleVRDPServer ();
|
---|
1952 | #endif
|
---|
1953 | }
|
---|
1954 |
|
---|
1955 |
|
---|
1956 | void ConsoleVRDPServer::SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const
|
---|
1957 | {
|
---|
1958 | #ifdef VBOX_WITH_VRDP
|
---|
1959 | if (mpEntryPoints && mhServer)
|
---|
1960 | {
|
---|
1961 | mpEntryPoints->VRDPUpdate (mhServer, uScreenId, pvUpdate, cbUpdate);
|
---|
1962 | }
|
---|
1963 | #endif
|
---|
1964 | }
|
---|
1965 |
|
---|
1966 | void ConsoleVRDPServer::SendResize (void) const
|
---|
1967 | {
|
---|
1968 | #ifdef VBOX_WITH_VRDP
|
---|
1969 | if (mpEntryPoints && mhServer)
|
---|
1970 | {
|
---|
1971 | mpEntryPoints->VRDPResize (mhServer);
|
---|
1972 | }
|
---|
1973 | #endif
|
---|
1974 | }
|
---|
1975 |
|
---|
1976 | void ConsoleVRDPServer::SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const
|
---|
1977 | {
|
---|
1978 | #ifdef VBOX_WITH_VRDP
|
---|
1979 | VRDPORDERHDR update;
|
---|
1980 | update.x = x;
|
---|
1981 | update.y = y;
|
---|
1982 | update.w = w;
|
---|
1983 | update.h = h;
|
---|
1984 | if (mpEntryPoints && mhServer)
|
---|
1985 | {
|
---|
1986 | mpEntryPoints->VRDPUpdate (mhServer, uScreenId, &update, sizeof (update));
|
---|
1987 | }
|
---|
1988 | #endif
|
---|
1989 | }
|
---|
1990 |
|
---|
1991 | void ConsoleVRDPServer::SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format) const
|
---|
1992 | {
|
---|
1993 | #ifdef VBOX_WITH_VRDP
|
---|
1994 | if (mpEntryPoints && mhServer)
|
---|
1995 | {
|
---|
1996 | mpEntryPoints->VRDPAudioSamples (mhServer, pvSamples, cSamples, format);
|
---|
1997 | }
|
---|
1998 | #endif
|
---|
1999 | }
|
---|
2000 |
|
---|
2001 | void ConsoleVRDPServer::SendAudioVolume (uint16_t left, uint16_t right) const
|
---|
2002 | {
|
---|
2003 | #ifdef VBOX_WITH_VRDP
|
---|
2004 | if (mpEntryPoints && mhServer)
|
---|
2005 | {
|
---|
2006 | mpEntryPoints->VRDPAudioVolume (mhServer, left, right);
|
---|
2007 | }
|
---|
2008 | #endif
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | void ConsoleVRDPServer::SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
|
---|
2012 | {
|
---|
2013 | #ifdef VBOX_WITH_VRDP
|
---|
2014 | if (mpEntryPoints && mhServer)
|
---|
2015 | {
|
---|
2016 | mpEntryPoints->VRDPUSBRequest (mhServer, u32ClientId, pvParms, cbParms);
|
---|
2017 | }
|
---|
2018 | #endif
|
---|
2019 | }
|
---|
2020 |
|
---|
2021 | void ConsoleVRDPServer::QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
|
---|
2022 | {
|
---|
2023 | #ifdef VBOX_WITH_VRDP
|
---|
2024 | if (mpEntryPoints && mhServer)
|
---|
2025 | {
|
---|
2026 | mpEntryPoints->VRDPQueryInfo (mhServer, index, pvBuffer, cbBuffer, pcbOut);
|
---|
2027 | }
|
---|
2028 | #endif
|
---|
2029 | }
|
---|
2030 |
|
---|
2031 | #ifdef VBOX_WITH_VRDP
|
---|
2032 | /* note: static function now! */
|
---|
2033 | bool ConsoleVRDPServer::loadVRDPLibrary (void)
|
---|
2034 | {
|
---|
2035 | int rc = VINF_SUCCESS;
|
---|
2036 |
|
---|
2037 | if (!mVRDPLibrary)
|
---|
2038 | {
|
---|
2039 | rc = SUPR3HardenedLdrLoadAppPriv ("VBoxVRDP", &mVRDPLibrary);
|
---|
2040 |
|
---|
2041 | if (RT_SUCCESS(rc))
|
---|
2042 | {
|
---|
2043 | LogFlow(("VRDPServer::loadLibrary(): successfully loaded VRDP library.\n"));
|
---|
2044 |
|
---|
2045 | struct SymbolEntry
|
---|
2046 | {
|
---|
2047 | const char *name;
|
---|
2048 | void **ppfn;
|
---|
2049 | };
|
---|
2050 |
|
---|
2051 | #define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
|
---|
2052 |
|
---|
2053 | static const struct SymbolEntry symbols[] =
|
---|
2054 | {
|
---|
2055 | DEFSYMENTRY(VRDPCreateServer)
|
---|
2056 | };
|
---|
2057 |
|
---|
2058 | #undef DEFSYMENTRY
|
---|
2059 |
|
---|
2060 | for (unsigned i = 0; i < RT_ELEMENTS(symbols); i++)
|
---|
2061 | {
|
---|
2062 | rc = RTLdrGetSymbol(mVRDPLibrary, symbols[i].name, symbols[i].ppfn);
|
---|
2063 |
|
---|
2064 | AssertMsgRC(rc, ("Error resolving VRDP symbol %s\n", symbols[i].name));
|
---|
2065 |
|
---|
2066 | if (RT_FAILURE(rc))
|
---|
2067 | {
|
---|
2068 | break;
|
---|
2069 | }
|
---|
2070 | }
|
---|
2071 | }
|
---|
2072 | else
|
---|
2073 | {
|
---|
2074 | LogRel(("VRDPServer::loadLibrary(): failed to load VRDP library! VRDP not available: rc = %Rrc\n", rc));
|
---|
2075 | mVRDPLibrary = NULL;
|
---|
2076 | }
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | // just to be safe
|
---|
2080 | if (RT_FAILURE(rc))
|
---|
2081 | {
|
---|
2082 | if (mVRDPLibrary)
|
---|
2083 | {
|
---|
2084 | RTLdrClose (mVRDPLibrary);
|
---|
2085 | mVRDPLibrary = NULL;
|
---|
2086 | }
|
---|
2087 | }
|
---|
2088 |
|
---|
2089 | return (mVRDPLibrary != NULL);
|
---|
2090 | }
|
---|
2091 | #endif /* VBOX_WITH_VRDP */
|
---|
2092 |
|
---|
2093 | /*
|
---|
2094 | * IRemoteDisplayInfo implementation.
|
---|
2095 | */
|
---|
2096 | // constructor / destructor
|
---|
2097 | /////////////////////////////////////////////////////////////////////////////
|
---|
2098 |
|
---|
2099 | DEFINE_EMPTY_CTOR_DTOR (RemoteDisplayInfo)
|
---|
2100 |
|
---|
2101 | HRESULT RemoteDisplayInfo::FinalConstruct()
|
---|
2102 | {
|
---|
2103 | return S_OK;
|
---|
2104 | }
|
---|
2105 |
|
---|
2106 | void RemoteDisplayInfo::FinalRelease()
|
---|
2107 | {
|
---|
2108 | uninit ();
|
---|
2109 | }
|
---|
2110 |
|
---|
2111 | // public methods only for internal purposes
|
---|
2112 | /////////////////////////////////////////////////////////////////////////////
|
---|
2113 |
|
---|
2114 | /**
|
---|
2115 | * Initializes the guest object.
|
---|
2116 | */
|
---|
2117 | HRESULT RemoteDisplayInfo::init (Console *aParent)
|
---|
2118 | {
|
---|
2119 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
2120 |
|
---|
2121 | ComAssertRet (aParent, E_INVALIDARG);
|
---|
2122 |
|
---|
2123 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
2124 | AutoInitSpan autoInitSpan(this);
|
---|
2125 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
2126 |
|
---|
2127 | unconst(mParent) = aParent;
|
---|
2128 |
|
---|
2129 | /* Confirm a successful initialization */
|
---|
2130 | autoInitSpan.setSucceeded();
|
---|
2131 |
|
---|
2132 | return S_OK;
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 | /**
|
---|
2136 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
2137 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
2138 | */
|
---|
2139 | void RemoteDisplayInfo::uninit()
|
---|
2140 | {
|
---|
2141 | LogFlowThisFunc(("\n"));
|
---|
2142 |
|
---|
2143 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
2144 | AutoUninitSpan autoUninitSpan(this);
|
---|
2145 | if (autoUninitSpan.uninitDone())
|
---|
2146 | return;
|
---|
2147 |
|
---|
2148 | unconst(mParent).setNull();
|
---|
2149 | }
|
---|
2150 |
|
---|
2151 | // IRemoteDisplayInfo properties
|
---|
2152 | /////////////////////////////////////////////////////////////////////////////
|
---|
2153 |
|
---|
2154 | #define IMPL_GETTER_BOOL(_aType, _aName, _aIndex) \
|
---|
2155 | STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
|
---|
2156 | { \
|
---|
2157 | if (!a##_aName) \
|
---|
2158 | return E_POINTER; \
|
---|
2159 | \
|
---|
2160 | AutoCaller autoCaller(this); \
|
---|
2161 | CheckComRCReturnRC(autoCaller.rc()); \
|
---|
2162 | \
|
---|
2163 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
2164 | AutoWriteLock alock(this); \
|
---|
2165 | \
|
---|
2166 | uint32_t value; \
|
---|
2167 | uint32_t cbOut = 0; \
|
---|
2168 | \
|
---|
2169 | mParent->consoleVRDPServer ()->QueryInfo \
|
---|
2170 | (_aIndex, &value, sizeof (value), &cbOut); \
|
---|
2171 | \
|
---|
2172 | *a##_aName = cbOut? !!value: FALSE; \
|
---|
2173 | \
|
---|
2174 | return S_OK; \
|
---|
2175 | }
|
---|
2176 |
|
---|
2177 | #define IMPL_GETTER_SCALAR(_aType, _aName, _aIndex) \
|
---|
2178 | STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
|
---|
2179 | { \
|
---|
2180 | if (!a##_aName) \
|
---|
2181 | return E_POINTER; \
|
---|
2182 | \
|
---|
2183 | AutoCaller autoCaller(this); \
|
---|
2184 | CheckComRCReturnRC(autoCaller.rc()); \
|
---|
2185 | \
|
---|
2186 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
2187 | AutoWriteLock alock(this); \
|
---|
2188 | \
|
---|
2189 | _aType value; \
|
---|
2190 | uint32_t cbOut = 0; \
|
---|
2191 | \
|
---|
2192 | mParent->consoleVRDPServer ()->QueryInfo \
|
---|
2193 | (_aIndex, &value, sizeof (value), &cbOut); \
|
---|
2194 | \
|
---|
2195 | *a##_aName = cbOut? value: 0; \
|
---|
2196 | \
|
---|
2197 | return S_OK; \
|
---|
2198 | }
|
---|
2199 |
|
---|
2200 | #define IMPL_GETTER_BSTR(_aType, _aName, _aIndex) \
|
---|
2201 | STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
|
---|
2202 | { \
|
---|
2203 | if (!a##_aName) \
|
---|
2204 | return E_POINTER; \
|
---|
2205 | \
|
---|
2206 | AutoCaller autoCaller(this); \
|
---|
2207 | CheckComRCReturnRC(autoCaller.rc()); \
|
---|
2208 | \
|
---|
2209 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
2210 | AutoWriteLock alock(this); \
|
---|
2211 | \
|
---|
2212 | uint32_t cbOut = 0; \
|
---|
2213 | \
|
---|
2214 | mParent->consoleVRDPServer ()->QueryInfo \
|
---|
2215 | (_aIndex, NULL, 0, &cbOut); \
|
---|
2216 | \
|
---|
2217 | if (cbOut == 0) \
|
---|
2218 | { \
|
---|
2219 | Bstr str(""); \
|
---|
2220 | str.cloneTo(a##_aName); \
|
---|
2221 | return S_OK; \
|
---|
2222 | } \
|
---|
2223 | \
|
---|
2224 | char *pchBuffer = (char *)RTMemTmpAlloc (cbOut); \
|
---|
2225 | \
|
---|
2226 | if (!pchBuffer) \
|
---|
2227 | { \
|
---|
2228 | Log(("RemoteDisplayInfo::" \
|
---|
2229 | #_aName \
|
---|
2230 | ": Failed to allocate memory %d bytes\n", cbOut)); \
|
---|
2231 | return E_OUTOFMEMORY; \
|
---|
2232 | } \
|
---|
2233 | \
|
---|
2234 | mParent->consoleVRDPServer ()->QueryInfo \
|
---|
2235 | (_aIndex, pchBuffer, cbOut, &cbOut); \
|
---|
2236 | \
|
---|
2237 | Bstr str(pchBuffer); \
|
---|
2238 | \
|
---|
2239 | str.cloneTo(a##_aName); \
|
---|
2240 | \
|
---|
2241 | RTMemTmpFree (pchBuffer); \
|
---|
2242 | \
|
---|
2243 | return S_OK; \
|
---|
2244 | }
|
---|
2245 |
|
---|
2246 | IMPL_GETTER_BOOL (BOOL, Active, VRDP_QI_ACTIVE);
|
---|
2247 | IMPL_GETTER_SCALAR (ULONG, NumberOfClients, VRDP_QI_NUMBER_OF_CLIENTS);
|
---|
2248 | IMPL_GETTER_SCALAR (LONG64, BeginTime, VRDP_QI_BEGIN_TIME);
|
---|
2249 | IMPL_GETTER_SCALAR (LONG64, EndTime, VRDP_QI_END_TIME);
|
---|
2250 | IMPL_GETTER_SCALAR (ULONG64, BytesSent, VRDP_QI_BYTES_SENT);
|
---|
2251 | IMPL_GETTER_SCALAR (ULONG64, BytesSentTotal, VRDP_QI_BYTES_SENT_TOTAL);
|
---|
2252 | IMPL_GETTER_SCALAR (ULONG64, BytesReceived, VRDP_QI_BYTES_RECEIVED);
|
---|
2253 | IMPL_GETTER_SCALAR (ULONG64, BytesReceivedTotal, VRDP_QI_BYTES_RECEIVED_TOTAL);
|
---|
2254 | IMPL_GETTER_BSTR (BSTR, User, VRDP_QI_USER);
|
---|
2255 | IMPL_GETTER_BSTR (BSTR, Domain, VRDP_QI_DOMAIN);
|
---|
2256 | IMPL_GETTER_BSTR (BSTR, ClientName, VRDP_QI_CLIENT_NAME);
|
---|
2257 | IMPL_GETTER_BSTR (BSTR, ClientIP, VRDP_QI_CLIENT_IP);
|
---|
2258 | IMPL_GETTER_SCALAR (ULONG, ClientVersion, VRDP_QI_CLIENT_VERSION);
|
---|
2259 | IMPL_GETTER_SCALAR (ULONG, EncryptionStyle, VRDP_QI_ENCRYPTION_STYLE);
|
---|
2260 |
|
---|
2261 | #undef IMPL_GETTER_BSTR
|
---|
2262 | #undef IMPL_GETTER_SCALAR
|
---|
2263 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|