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