FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
libfreerdp/core/server.c
1
22#include <freerdp/config.h>
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <stdint.h>
28
29#include <winpr/wtypes.h>
30#include <winpr/crt.h>
31#include <winpr/synch.h>
32#include <winpr/stream.h>
33#include <winpr/assert.h>
34#include <winpr/cast.h>
35
36#include <freerdp/log.h>
37#include <freerdp/constants.h>
38#include <freerdp/server/channels.h>
39#include <freerdp/channels/drdynvc.h>
40#include <freerdp/utils/drdynvc.h>
41
42#include "rdp.h"
43
44#include "server.h"
45
46#define TAG FREERDP_TAG("core.server")
47#ifdef WITH_DEBUG_DVC
48#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
49#else
50#define DEBUG_DVC(...) \
51 do \
52 { \
53 } while (0)
54#endif
55
56#define DVC_MAX_DATA_PDU_SIZE 1600
57
58typedef struct
59{
60 UINT16 channelId;
61 UINT16 reserved;
62 UINT32 length;
63 UINT32 offset;
64} wtsChannelMessage;
65
66static const DWORD g_err_oom = WINPR_CXX_COMPAT_CAST(DWORD, E_OUTOFMEMORY);
67
68static DWORD g_SessionId = 1;
69static wHashTable* g_ServerHandles = NULL;
70
71static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm, UINT32 ChannelId)
72{
73 WINPR_ASSERT(vcm);
74 return HashTable_GetItemValue(vcm->dynamicVirtualChannels, &ChannelId);
75}
76
77static BOOL wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* Buffer, UINT32 Length)
78{
79 BYTE* buffer = NULL;
80 wtsChannelMessage* messageCtx = NULL;
81
82 WINPR_ASSERT(channel);
83 messageCtx = (wtsChannelMessage*)malloc(sizeof(wtsChannelMessage) + Length);
84
85 if (!messageCtx)
86 return FALSE;
87
88 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
89 messageCtx->channelId = (UINT16)channel->channelId;
90 messageCtx->length = Length;
91 messageCtx->offset = 0;
92 buffer = (BYTE*)(messageCtx + 1);
93 CopyMemory(buffer, Buffer, Length);
94 return MessageQueue_Post(channel->queue, messageCtx, 0, NULL, NULL);
95}
96
97static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
98{
99 BYTE* buffer = NULL;
100 UINT32 length = 0;
101
102 WINPR_ASSERT(channel);
103 WINPR_ASSERT(channel->vcm);
104 buffer = Buffer;
105 length = Length;
106
107 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
108 const UINT16 channelId = (UINT16)channel->channelId;
109 return MessageQueue_Post(channel->vcm->queue, (void*)(UINT_PTR)channelId, 0, (void*)buffer,
110 (void*)(UINT_PTR)length);
111}
112
113static unsigned wts_read_variable_uint(wStream* s, int cbLen, UINT32* val)
114{
115 WINPR_ASSERT(s);
116 WINPR_ASSERT(val);
117 switch (cbLen)
118 {
119 case 0:
120 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
121 return 0;
122
123 Stream_Read_UINT8(s, *val);
124 return 1;
125
126 case 1:
127 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
128 return 0;
129
130 Stream_Read_UINT16(s, *val);
131 return 2;
132
133 case 2:
134 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
135 return 0;
136
137 Stream_Read_UINT32(s, *val);
138 return 4;
139
140 default:
141 WLog_ERR(TAG, "invalid wts variable uint len %d", cbLen);
142 return 0;
143 }
144}
145
146static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
147{
148 UINT16 Version = 0;
149
150 WINPR_ASSERT(channel);
151 WINPR_ASSERT(channel->vcm);
152 if (length < 3)
153 return FALSE;
154
155 Stream_Seek_UINT8(channel->receiveData); /* Pad (1 byte) */
156 Stream_Read_UINT16(channel->receiveData, Version);
157 DEBUG_DVC("Version: %" PRIu16 "", Version);
158
159 if (Version < 1)
160 {
161 WLog_ERR(TAG, "invalid version %" PRIu16 " for DRDYNVC", Version);
162 return FALSE;
163 }
164
165 WTSVirtualChannelManager* vcm = channel->vcm;
166 vcm->drdynvc_state = DRDYNVC_STATE_READY;
167
168 /* we only support version 1 for now (no compression yet) */
169 vcm->dvc_spoken_version = MAX(Version, 1);
170
171 return SetEvent(MessageQueue_Event(vcm->queue));
172}
173
174static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s, UINT32 length)
175{
176 UINT32 CreationStatus = 0;
177 BOOL status = TRUE;
178
179 WINPR_ASSERT(channel);
180 WINPR_ASSERT(s);
181 if (length < 4)
182 return FALSE;
183
184 Stream_Read_UINT32(s, CreationStatus);
185
186 if ((INT32)CreationStatus < 0)
187 {
188 DEBUG_DVC("ChannelId %" PRIu32 " creation failed (%" PRId32 ")", channel->channelId,
189 (INT32)CreationStatus);
190 channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
191 }
192 else
193 {
194 DEBUG_DVC("ChannelId %" PRIu32 " creation succeeded", channel->channelId);
195 channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
196 }
197
198 channel->creationStatus = (INT32)CreationStatus;
199 IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata,
200 channel->channelId, (INT32)CreationStatus);
201 if (!status)
202 WLog_ERR(TAG, "vcm->dvc_creation_status failed!");
203
204 return status;
205}
206
207static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int cbLen,
208 UINT32 length)
209{
210 WINPR_ASSERT(channel);
211 WINPR_ASSERT(s);
212 const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
213
214 if (value == 0)
215 return FALSE;
216 if (value > length)
217 length = 0;
218 else
219 length -= value;
220
221 if (length > channel->dvc_total_length)
222 return FALSE;
223
224 Stream_SetPosition(channel->receiveData, 0);
225
226 if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
227 return FALSE;
228
229 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
230 return TRUE;
231}
232
233static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 length)
234{
235 BOOL ret = FALSE;
236
237 WINPR_ASSERT(channel);
238 WINPR_ASSERT(s);
239 if (channel->dvc_total_length > 0)
240 {
241 if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
242 {
243 channel->dvc_total_length = 0;
244 WLog_ERR(TAG, "incorrect fragment data, discarded.");
245 return FALSE;
246 }
247
248 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
249
250 if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
251 {
252 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
253 channel->dvc_total_length);
254 channel->dvc_total_length = 0;
255 }
256 else
257 ret = TRUE;
258 }
259 else
260 {
261 ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length);
262 }
263
264 return ret;
265}
266
267static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
268{
269 WINPR_ASSERT(channel);
270 DEBUG_DVC("ChannelId %" PRIu32 " close response", channel->channelId);
271 channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
272 MessageQueue_PostQuit(channel->queue, 0);
273}
274
275static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
276{
277 UINT8 Cmd = 0;
278 UINT8 Sp = 0;
279 UINT8 cbChId = 0;
280 UINT32 ChannelId = 0;
281 rdpPeerChannel* dvc = NULL;
282
283 WINPR_ASSERT(channel);
284 WINPR_ASSERT(channel->vcm);
285
286 size_t length = Stream_GetPosition(channel->receiveData);
287
288 if ((length < 1) || (length > UINT32_MAX))
289 return FALSE;
290
291 Stream_SetPosition(channel->receiveData, 0);
292 const UINT8 value = Stream_Get_UINT8(channel->receiveData);
293 length--;
294 Cmd = (value & 0xf0) >> 4;
295 Sp = (value & 0x0c) >> 2;
296 cbChId = (value & 0x03) >> 0;
297
298 if (Cmd == CAPABILITY_REQUEST_PDU)
299 return wts_read_drdynvc_capabilities_response(channel, (UINT32)length);
300
301 if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
302 {
303 BOOL haveChannelId = 0;
304 switch (Cmd)
305 {
306 case SOFT_SYNC_REQUEST_PDU:
307 case SOFT_SYNC_RESPONSE_PDU:
308 haveChannelId = FALSE;
309 break;
310 default:
311 haveChannelId = TRUE;
312 break;
313 }
314
315 if (haveChannelId)
316 {
317 const unsigned val = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId);
318 if (val == 0)
319 return FALSE;
320
321 length -= val;
322
323 DEBUG_DVC("Cmd %s ChannelId %" PRIu32 " length %" PRIuz "",
324 drdynvc_get_packet_type(Cmd), ChannelId, length);
325 dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
326 if (!dvc)
327 {
328 DEBUG_DVC("ChannelId %" PRIu32 " does not exist.", ChannelId);
329 return TRUE;
330 }
331 }
332
333 switch (Cmd)
334 {
335 case CREATE_REQUEST_PDU:
336 return wts_read_drdynvc_create_response(dvc, channel->receiveData, (UINT32)length);
337
338 case DATA_FIRST_PDU:
339 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
340 {
341 WLog_ERR(TAG,
342 "ChannelId %" PRIu32 " did not open successfully. "
343 "Ignoring DYNVC_DATA_FIRST PDU",
344 ChannelId);
345 return TRUE;
346 }
347
348 return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, (UINT32)length);
349
350 case DATA_PDU:
351 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
352 {
353 WLog_ERR(TAG,
354 "ChannelId %" PRIu32 " did not open successfully. "
355 "Ignoring DYNVC_DATA PDU",
356 ChannelId);
357 return TRUE;
358 }
359
360 return wts_read_drdynvc_data(dvc, channel->receiveData, (UINT32)length);
361
362 case CLOSE_REQUEST_PDU:
363 wts_read_drdynvc_close_response(dvc);
364 break;
365
366 case DATA_FIRST_COMPRESSED_PDU:
367 case DATA_COMPRESSED_PDU:
368 WLog_ERR(TAG, "Compressed data not handled");
369 break;
370
371 case SOFT_SYNC_RESPONSE_PDU:
372 WLog_ERR(TAG, "SoftSync response not handled yet(and rather strange to receive "
373 "that packet as our code doesn't send SoftSync requests");
374 break;
375
376 case SOFT_SYNC_REQUEST_PDU:
377 WLog_ERR(TAG, "Not expecting a SoftSyncRequest on the server");
378 return FALSE;
379
380 default:
381 WLog_ERR(TAG, "Cmd %d not recognized.", Cmd);
382 break;
383 }
384 }
385 else
386 {
387 WLog_ERR(TAG, "received Cmd %d but channel is not ready.", Cmd);
388 }
389
390 return TRUE;
391}
392
393static int wts_write_variable_uint(wStream* s, UINT32 val)
394{
395 int cb = 0;
396
397 WINPR_ASSERT(s);
398 if (val <= 0xFF)
399 {
400 cb = 0;
401 Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val));
402 }
403 else if (val <= 0xFFFF)
404 {
405 cb = 1;
406 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val));
407 }
408 else
409 {
410 cb = 2;
411 Stream_Write_UINT32(s, val);
412 }
413
414 return cb;
415}
416
417static void wts_write_drdynvc_header(wStream* s, BYTE Cmd, UINT32 ChannelId)
418{
419 BYTE* bm = NULL;
420 int cbChId = 0;
421
422 WINPR_ASSERT(s);
423
424 Stream_GetPointer(s, bm);
425 Stream_Seek_UINT8(s);
426 cbChId = wts_write_variable_uint(s, ChannelId);
427 *bm = (((Cmd & 0x0F) << 4) | cbChId) & 0xFF;
428}
429
430static BOOL wts_write_drdynvc_create_request(wStream* s, UINT32 ChannelId, const char* ChannelName)
431{
432 size_t len = 0;
433
434 WINPR_ASSERT(s);
435 WINPR_ASSERT(ChannelName);
436
437 wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
438 len = strlen(ChannelName) + 1;
439
440 if (!Stream_EnsureRemainingCapacity(s, len))
441 return FALSE;
442
443 Stream_Write(s, ChannelName, len);
444 return TRUE;
445}
446
447static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, const BYTE* data,
448 size_t s, UINT32 flags, size_t t)
449{
450 BOOL ret = TRUE;
451 const size_t size = s;
452 const size_t totalSize = t;
453
454 WINPR_ASSERT(channel);
455 WINPR_ASSERT(channel->vcm);
456 WINPR_UNUSED(channelId);
457
458 if (flags & CHANNEL_FLAG_FIRST)
459 {
460 Stream_SetPosition(channel->receiveData, 0);
461 }
462
463 if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
464 return FALSE;
465
466 Stream_Write(channel->receiveData, data, size);
467
468 if (flags & CHANNEL_FLAG_LAST)
469 {
470 if (Stream_GetPosition(channel->receiveData) != totalSize)
471 {
472 WLog_ERR(TAG, "read error");
473 }
474
475 if (channel == channel->vcm->drdynvc_channel)
476 {
477 ret = wts_read_drdynvc_pdu(channel);
478 }
479 else
480 {
481 const size_t pos = Stream_GetPosition(channel->receiveData);
482 if (pos > UINT32_MAX)
483 ret = FALSE;
484 else
485 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
486 (UINT32)pos);
487 }
488
489 Stream_SetPosition(channel->receiveData, 0);
490 }
491
492 return ret;
493}
494
495static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const BYTE* data,
496 size_t size, UINT32 flags, size_t totalSize)
497{
498 rdpMcs* mcs = NULL;
499
500 WINPR_ASSERT(client);
501 WINPR_ASSERT(client->context);
502 WINPR_ASSERT(client->context->rdp);
503
504 mcs = client->context->rdp->mcs;
505 WINPR_ASSERT(mcs);
506
507 for (UINT32 i = 0; i < mcs->channelCount; i++)
508 {
509 rdpMcsChannel* cur = &mcs->channels[i];
510 if (cur->ChannelId == channelId)
511 {
512 rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
513
514 if (channel)
515 return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
516 }
517 }
518
519 WLog_WARN(TAG, "unknown channelId %" PRIu16 " ignored", channelId);
520
521 return TRUE;
522}
523
524#if defined(WITH_FREERDP_DEPRECATED)
525void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count)
526{
527 void* fd = NULL;
529 WINPR_ASSERT(vcm);
530 WINPR_ASSERT(fds);
531 WINPR_ASSERT(fds_count);
532
533 fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
534
535 if (fd)
536 {
537 fds[*fds_count] = fd;
538 (*fds_count)++;
539 }
540
541#if 0
542
543 if (vcm->drdynvc_channel)
544 {
545 fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
546
547 if (fd)
548 {
549 fds[*fds_count] = fd;
550 (*fds_count)++;
551 }
552 }
553
554#endif
555}
556#endif
557
558BOOL WTSVirtualChannelManagerOpen(HANDLE hServer)
559{
561
562 if (!vcm)
563 return FALSE;
564
565 if (vcm->drdynvc_state == DRDYNVC_STATE_NONE)
566 {
567 rdpPeerChannel* channel = NULL;
568
569 /* Initialize drdynvc channel once and only once. */
570 vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
571 channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
572 DRDYNVC_SVC_CHANNEL_NAME);
573
574 if (channel)
575 {
576 BYTE capaBuffer[12] = { 0 };
577 wStream staticS = { 0 };
578 wStream* s = Stream_StaticInit(&staticS, capaBuffer, sizeof(capaBuffer));
579
580 vcm->drdynvc_channel = channel;
581 vcm->dvc_spoken_version = 1;
582 Stream_Write_UINT8(s, 0x50); /* Cmd=5 sp=0 cbId=0 */
583 Stream_Write_UINT8(s, 0x00); /* Pad */
584 Stream_Write_UINT16(s, 0x0001); /* Version */
585
586 /* TODO: shall implement version 2 and 3 */
587
588 const size_t pos = Stream_GetPosition(s);
589 WINPR_ASSERT(pos <= UINT32_MAX);
590 ULONG written = 0;
591 if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written))
592 return FALSE;
593 }
594 }
595
596 return TRUE;
597}
598
599BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
600{
601 wMessage message = { 0 };
602 BOOL status = TRUE;
603 WTSVirtualChannelManager* vcm = NULL;
604
605 if (!hServer || hServer == INVALID_HANDLE_VALUE)
606 return FALSE;
607
608 vcm = (WTSVirtualChannelManager*)hServer;
609
610 if (autoOpen)
611 {
612 if (!WTSVirtualChannelManagerOpen(hServer))
613 return FALSE;
614 }
615
616 while (MessageQueue_Peek(vcm->queue, &message, TRUE))
617 {
618 BYTE* buffer = NULL;
619 UINT32 length = 0;
620 UINT16 channelId = 0;
621 channelId = (UINT16)(UINT_PTR)message.context;
622 buffer = (BYTE*)message.wParam;
623 length = (UINT32)(UINT_PTR)message.lParam;
624
625 WINPR_ASSERT(vcm->client);
626 WINPR_ASSERT(vcm->client->SendChannelData);
627 if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
628 {
629 status = FALSE;
630 }
631
632 free(buffer);
633
634 if (!status)
635 break;
636 }
637
638 return status;
639}
640
641BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
642{
643 return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
644}
645
646HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
647{
649 WINPR_ASSERT(vcm);
650 return MessageQueue_Event(vcm->queue);
651}
652
653static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* channel_name)
654{
655 if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
656 return NULL;
657
658 for (UINT32 index = 0; index < mcs->channelCount; index++)
659 {
660 rdpMcsChannel* mchannel = &mcs->channels[index];
661 if (mchannel->joined)
662 {
663 if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
664 return mchannel;
665 }
666 }
667
668 return NULL;
669}
670
671static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs, const UINT16 channel_id)
672{
673 if (!mcs || !channel_id)
674 return NULL;
675
676 WINPR_ASSERT(mcs->channels);
677 for (UINT32 index = 0; index < mcs->channelCount; index++)
678 {
679 rdpMcsChannel* mchannel = &mcs->channels[index];
680 if (mchannel->joined)
681 {
682 if (mchannel->ChannelId == channel_id)
683 return &mcs->channels[index];
684 }
685 }
686
687 return NULL;
688}
689
690BOOL WTSIsChannelJoinedByName(freerdp_peer* client, const char* channel_name)
691{
692 if (!client || !client->context || !client->context->rdp)
693 return FALSE;
694
695 return wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) == NULL ? FALSE
696 : TRUE;
697}
698
699BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
700{
701 if (!client || !client->context || !client->context->rdp)
702 return FALSE;
703
704 return wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) == NULL ? FALSE
705 : TRUE;
706}
707
708BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
709{
711
712 if (!vcm || !vcm->rdp)
713 return FALSE;
714
715 return wts_get_joined_channel_by_name(vcm->rdp->mcs, name) == NULL ? FALSE : TRUE;
716}
717
718BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
719{
721 WINPR_ASSERT(vcm);
722 return vcm->drdynvc_state;
723}
724
725void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
726 void* userdata)
727{
728 WTSVirtualChannelManager* vcm = hServer;
729
730 WINPR_ASSERT(vcm);
731
732 vcm->dvc_creation_status = cb;
733 vcm->dvc_creation_status_userdata = userdata;
734}
735
736UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name)
737{
738 rdpMcsChannel* channel = NULL;
739
740 WINPR_ASSERT(channel_name);
741 if (!client || !client->context || !client->context->rdp)
742 return 0;
743
744 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
745
746 if (!channel)
747 return 0;
748
749 return channel->ChannelId;
750}
751
752UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
753{
754 rdpPeerChannel* channel = hChannelHandle;
755
756 WINPR_ASSERT(channel);
757
758 return channel->channelId;
759}
760
761BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, void* handle)
762{
763 rdpMcsChannel* channel = NULL;
764
765 WINPR_ASSERT(channel_name);
766 if (!client || !client->context || !client->context->rdp)
767 return FALSE;
768
769 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
770
771 if (!channel)
772 return FALSE;
773
774 channel->handle = handle;
775 return TRUE;
776}
777
778BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id, void* handle)
779{
780 rdpMcsChannel* channel = NULL;
781
782 if (!client || !client->context || !client->context->rdp)
783 return FALSE;
784
785 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
786
787 if (!channel)
788 return FALSE;
789
790 channel->handle = handle;
791 return TRUE;
792}
793
794void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_name)
795{
796 rdpMcsChannel* channel = NULL;
797
798 WINPR_ASSERT(channel_name);
799 if (!client || !client->context || !client->context->rdp)
800 return NULL;
801
802 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
803
804 if (!channel)
805 return NULL;
806
807 return channel->handle;
808}
809
810void* WTSChannelGetHandleById(freerdp_peer* client, UINT16 channel_id)
811{
812 rdpMcsChannel* channel = NULL;
813
814 if (!client || !client->context || !client->context->rdp)
815 return NULL;
816
817 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
818
819 if (!channel)
820 return NULL;
821
822 return channel->handle;
823}
824
825const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
826{
827 rdpMcsChannel* channel = NULL;
828
829 if (!client || !client->context || !client->context->rdp)
830 return NULL;
831
832 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
833
834 if (!channel)
835 return NULL;
836
837 return (const char*)channel->Name;
838}
839
840char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count)
841{
842 rdpMcs* mcs = NULL;
843 char** names = NULL;
844
845 if (!client || !client->context || !count)
846 return NULL;
847
848 WINPR_ASSERT(client->context->rdp);
849 mcs = client->context->rdp->mcs;
850 WINPR_ASSERT(mcs);
851 *count = mcs->channelCount;
852
853 names = (char**)calloc(mcs->channelCount, sizeof(char*));
854 if (!names)
855 return NULL;
856
857 for (UINT32 index = 0; index < mcs->channelCount; index++)
858 {
859 rdpMcsChannel* mchannel = &mcs->channels[index];
860 names[index] = mchannel->Name;
861 }
862
863 return names;
864}
865
866INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
867{
868 rdpMcsChannel* channel = NULL;
869
870 if (!client || !client->context || !client->context->rdp)
871 return -1;
872
873 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
874
875 if (!channel)
876 return -1;
877
878 return (INT64)channel->options;
879}
880
881BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
882 WINPR_ATTR_UNUSED ULONG TargetLogonId,
883 WINPR_ATTR_UNUSED BYTE HotkeyVk,
884 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
885{
886 WLog_ERR("TODO", "TODO: implement");
887 return FALSE;
888}
889
890BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
891 WINPR_ATTR_UNUSED ULONG TargetLogonId,
892 WINPR_ATTR_UNUSED BYTE HotkeyVk,
893 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
894{
895 WLog_ERR("TODO", "TODO: implement");
896 return FALSE;
897}
898
899BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
900 WINPR_ATTR_UNUSED ULONG TargetLogonId,
901 WINPR_ATTR_UNUSED BYTE HotkeyVk,
902 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
903 WINPR_ATTR_UNUSED DWORD flags)
904{
905 WLog_ERR("TODO", "TODO: implement");
906 return FALSE;
907}
908
909BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
910 WINPR_ATTR_UNUSED ULONG TargetLogonId,
911 WINPR_ATTR_UNUSED BYTE HotkeyVk,
912 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
913 WINPR_ATTR_UNUSED DWORD flags)
914{
915 WLog_ERR("TODO", "TODO: implement");
916 return FALSE;
917}
918
919BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId)
920{
921 WLog_ERR("TODO", "TODO: implement");
922 return FALSE;
923}
924
925BOOL WINAPI FreeRDP_WTSConnectSessionW(WINPR_ATTR_UNUSED ULONG LogonId,
926 WINPR_ATTR_UNUSED ULONG TargetLogonId,
927 WINPR_ATTR_UNUSED PWSTR pPassword,
928 WINPR_ATTR_UNUSED BOOL bWait)
929{
930 WLog_ERR("TODO", "TODO: implement");
931 return FALSE;
932}
933
934BOOL WINAPI FreeRDP_WTSConnectSessionA(WINPR_ATTR_UNUSED ULONG LogonId,
935 WINPR_ATTR_UNUSED ULONG TargetLogonId,
936 WINPR_ATTR_UNUSED PSTR pPassword,
937 WINPR_ATTR_UNUSED BOOL bWait)
938{
939 WLog_ERR("TODO", "TODO: implement");
940 return FALSE;
941}
942
943BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName,
944 WINPR_ATTR_UNUSED DWORD Reserved,
945 WINPR_ATTR_UNUSED DWORD Version,
946 WINPR_ATTR_UNUSED PWTS_SERVER_INFOW* ppServerInfo,
947 WINPR_ATTR_UNUSED DWORD* pCount)
948{
949 WLog_ERR("TODO", "TODO: implement");
950 return FALSE;
951}
952
953BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName,
954 WINPR_ATTR_UNUSED DWORD Reserved,
955 WINPR_ATTR_UNUSED DWORD Version,
956 WINPR_ATTR_UNUSED PWTS_SERVER_INFOA* ppServerInfo,
957 WINPR_ATTR_UNUSED DWORD* pCount)
958{
959 WLog_ERR("TODO", "TODO: implement");
960 return FALSE;
961}
962
963HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName)
964{
965 WLog_ERR("TODO", "TODO: implement");
966 return INVALID_HANDLE_VALUE;
967}
968
969static void wts_virtual_channel_manager_free_message(void* obj)
970{
971 wMessage* msg = (wMessage*)obj;
972
973 if (msg)
974 {
975 BYTE* buffer = (BYTE*)msg->wParam;
976
977 if (buffer)
978 free(buffer);
979 }
980}
981
982static void channel_free(rdpPeerChannel* channel)
983{
984 server_channel_common_free(channel);
985}
986
987static void array_channel_free(void* ptr)
988{
989 rdpPeerChannel* channel = ptr;
990 channel_free(channel);
991}
992
993static BOOL dynChannelMatch(const void* v1, const void* v2)
994{
995 const UINT32* p1 = (const UINT32*)v1;
996 const UINT32* p2 = (const UINT32*)v2;
997 return *p1 == *p2;
998}
999
1000static UINT32 channelId_Hash(const void* key)
1001{
1002 const UINT32* v = (const UINT32*)key;
1003 return *v;
1004}
1005
1006HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1007{
1008 rdpContext* context = NULL;
1009 freerdp_peer* client = NULL;
1010 WTSVirtualChannelManager* vcm = NULL;
1011 HANDLE hServer = INVALID_HANDLE_VALUE;
1012 wObject queueCallbacks = { 0 };
1013
1014 context = (rdpContext*)pServerName;
1015
1016 if (!context)
1017 return INVALID_HANDLE_VALUE;
1018
1019 client = context->peer;
1020
1021 if (!client)
1022 {
1023 SetLastError(ERROR_INVALID_DATA);
1024 return INVALID_HANDLE_VALUE;
1025 }
1026
1027 vcm = (WTSVirtualChannelManager*)calloc(1, sizeof(WTSVirtualChannelManager));
1028
1029 if (!vcm)
1030 goto error_vcm_alloc;
1031
1032 vcm->client = client;
1033 vcm->rdp = context->rdp;
1034 vcm->SessionId = g_SessionId++;
1035
1036 if (!g_ServerHandles)
1037 {
1038 g_ServerHandles = HashTable_New(TRUE);
1039
1040 if (!g_ServerHandles)
1041 goto error_free;
1042 }
1043
1044 if (!HashTable_Insert(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId, (void*)vcm))
1045 goto error_free;
1046
1047 queueCallbacks.fnObjectFree = wts_virtual_channel_manager_free_message;
1048 vcm->queue = MessageQueue_New(&queueCallbacks);
1049
1050 if (!vcm->queue)
1051 goto error_queue;
1052
1053 vcm->dvc_channel_id_seq = 0;
1054 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1055
1056 if (!vcm->dynamicVirtualChannels)
1057 goto error_dynamicVirtualChannels;
1058
1059 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1060 goto error_hashFunction;
1061
1062 {
1063 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1064 WINPR_ASSERT(obj);
1065 obj->fnObjectFree = array_channel_free;
1066
1067 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1068 obj->fnObjectEquals = dynChannelMatch;
1069 }
1070 client->ReceiveChannelData = WTSReceiveChannelData;
1071 hServer = (HANDLE)vcm;
1072 return hServer;
1073
1074error_hashFunction:
1075 HashTable_Free(vcm->dynamicVirtualChannels);
1076error_dynamicVirtualChannels:
1077 MessageQueue_Free(vcm->queue);
1078error_queue:
1079 HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
1080error_free:
1081 free(vcm);
1082error_vcm_alloc:
1083 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1084 return INVALID_HANDLE_VALUE;
1085}
1086
1087HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1088{
1089 WLog_ERR("TODO", "TODO: implement");
1090 return INVALID_HANDLE_VALUE;
1091}
1092
1093HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1094{
1095 return FreeRDP_WTSOpenServerA(pServerName);
1096}
1097
1098VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1099{
1100 WTSVirtualChannelManager* vcm = NULL;
1101 vcm = (WTSVirtualChannelManager*)hServer;
1102
1103 if (vcm && (vcm != INVALID_HANDLE_VALUE))
1104 {
1105 HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
1106
1107 HashTable_Free(vcm->dynamicVirtualChannels);
1108
1109 if (vcm->drdynvc_channel)
1110 {
1111 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1112 vcm->drdynvc_channel = NULL;
1113 }
1114
1115 MessageQueue_Free(vcm->queue);
1116 free(vcm);
1117 }
1118}
1119
1120BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1121 WINPR_ATTR_UNUSED DWORD Reserved,
1122 WINPR_ATTR_UNUSED DWORD Version,
1123 WINPR_ATTR_UNUSED PWTS_SESSION_INFOW* ppSessionInfo,
1124 WINPR_ATTR_UNUSED DWORD* pCount)
1125{
1126 WLog_ERR("TODO", "TODO: implement");
1127 return FALSE;
1128}
1129
1130BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1131 WINPR_ATTR_UNUSED DWORD Reserved,
1132 WINPR_ATTR_UNUSED DWORD Version,
1133 WINPR_ATTR_UNUSED PWTS_SESSION_INFOA* ppSessionInfo,
1134 WINPR_ATTR_UNUSED DWORD* pCount)
1135{
1136 WLog_ERR("TODO", "TODO: implement");
1137 return FALSE;
1138}
1139
1140BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1141 WINPR_ATTR_UNUSED DWORD* pLevel,
1142 WINPR_ATTR_UNUSED DWORD Filter,
1143 WINPR_ATTR_UNUSED PWTS_SESSION_INFO_1W* ppSessionInfo,
1144 WINPR_ATTR_UNUSED DWORD* pCount)
1145{
1146 WLog_ERR("TODO", "TODO: implement");
1147 return FALSE;
1148}
1149
1150BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1151 WINPR_ATTR_UNUSED DWORD* pLevel,
1152 WINPR_ATTR_UNUSED DWORD Filter,
1153 WINPR_ATTR_UNUSED PWTS_SESSION_INFO_1A* ppSessionInfo,
1154 WINPR_ATTR_UNUSED DWORD* pCount)
1155{
1156 WLog_ERR("TODO", "TODO: implement");
1157 return FALSE;
1158}
1159
1160BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1161 WINPR_ATTR_UNUSED DWORD Reserved,
1162 WINPR_ATTR_UNUSED DWORD Version,
1163 WINPR_ATTR_UNUSED PWTS_PROCESS_INFOW* ppProcessInfo,
1164 WINPR_ATTR_UNUSED DWORD* pCount)
1165{
1166 WLog_ERR("TODO", "TODO: implement");
1167 return FALSE;
1168}
1169
1170BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1171 WINPR_ATTR_UNUSED DWORD Reserved,
1172 WINPR_ATTR_UNUSED DWORD Version,
1173 WINPR_ATTR_UNUSED PWTS_PROCESS_INFOA* ppProcessInfo,
1174 WINPR_ATTR_UNUSED DWORD* pCount)
1175{
1176 WLog_ERR("TODO", "TODO: implement");
1177 return FALSE;
1178}
1179
1180BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1181 WINPR_ATTR_UNUSED DWORD ProcessId,
1182 WINPR_ATTR_UNUSED DWORD ExitCode)
1183{
1184 WLog_ERR("TODO", "TODO: implement");
1185 return FALSE;
1186}
1187
1188BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1189 WINPR_ATTR_UNUSED DWORD SessionId,
1190 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1191 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1192 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1193{
1194 WLog_ERR("TODO", "TODO: implement");
1195 return FALSE;
1196}
1197
1198BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1199 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1200 DWORD* pBytesReturned)
1201{
1202 DWORD BytesReturned = 0;
1203 WTSVirtualChannelManager* vcm = NULL;
1204 vcm = (WTSVirtualChannelManager*)hServer;
1205
1206 if (!vcm)
1207 return FALSE;
1208
1209 if (WTSInfoClass == WTSSessionId)
1210 {
1211 ULONG* pBuffer = NULL;
1212 BytesReturned = sizeof(ULONG);
1213 pBuffer = (ULONG*)malloc(sizeof(BytesReturned));
1214
1215 if (!pBuffer)
1216 {
1217 SetLastError(g_err_oom);
1218 return FALSE;
1219 }
1220
1221 *pBuffer = vcm->SessionId;
1222 *ppBuffer = (LPSTR)pBuffer;
1223 *pBytesReturned = BytesReturned;
1224 return TRUE;
1225 }
1226
1227 return FALSE;
1228}
1229
1230BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1231 WINPR_ATTR_UNUSED LPWSTR pUserName,
1232 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1233 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1234 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1235{
1236 WLog_ERR("TODO", "TODO: implement");
1237 return FALSE;
1238}
1239
1240BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1241 WINPR_ATTR_UNUSED LPSTR pUserName,
1242 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1243 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1244 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1245{
1246 WLog_ERR("TODO", "TODO: implement");
1247 return FALSE;
1248}
1249
1250BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1251 WINPR_ATTR_UNUSED LPWSTR pUserName,
1252 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1253 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1254 WINPR_ATTR_UNUSED DWORD DataLength)
1255{
1256 WLog_ERR("TODO", "TODO: implement");
1257 return FALSE;
1258}
1259
1260BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1261 WINPR_ATTR_UNUSED LPSTR pUserName,
1262 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1263 WINPR_ATTR_UNUSED LPSTR pBuffer,
1264 WINPR_ATTR_UNUSED DWORD DataLength)
1265{
1266 WLog_ERR("TODO", "TODO: implement");
1267 return FALSE;
1268}
1269
1270BOOL WINAPI
1271FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1272 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1273 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1274 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1275 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1276{
1277 WLog_ERR("TODO", "TODO: implement");
1278 return FALSE;
1279}
1280
1281BOOL WINAPI
1282FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1283 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1284 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1285 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1286 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1287{
1288 WLog_ERR("TODO", "TODO: implement");
1289 return FALSE;
1290}
1291
1292BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1293 WINPR_ATTR_UNUSED DWORD SessionId,
1294 WINPR_ATTR_UNUSED BOOL bWait)
1295{
1296 WLog_ERR("TODO", "TODO: implement");
1297 return FALSE;
1298}
1299
1300BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1301 WINPR_ATTR_UNUSED DWORD SessionId,
1302 WINPR_ATTR_UNUSED BOOL bWait)
1303{
1304 WLog_ERR("TODO", "TODO: implement");
1305 return FALSE;
1306}
1307
1308BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1309 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1310{
1311 WLog_ERR("TODO", "TODO: implement");
1312 return FALSE;
1313}
1314
1315BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1316 WINPR_ATTR_UNUSED DWORD EventMask,
1317 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1318{
1319 WLog_ERR("TODO", "TODO: implement");
1320 return FALSE;
1321}
1322
1323static void peer_channel_queue_free_message(void* obj)
1324{
1325 wMessage* msg = (wMessage*)obj;
1326 if (!msg)
1327 return;
1328
1329 free(msg->context);
1330 msg->context = NULL;
1331}
1332
1333static rdpPeerChannel* channel_new(WTSVirtualChannelManager* vcm, freerdp_peer* client,
1334 UINT32 ChannelId, UINT16 index, UINT16 type, size_t chunkSize,
1335 const char* name)
1336{
1337 wObject queueCallbacks = { 0 };
1338 queueCallbacks.fnObjectFree = peer_channel_queue_free_message;
1339
1340 rdpPeerChannel* channel =
1341 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1342
1343 WINPR_ASSERT(vcm);
1344 WINPR_ASSERT(client);
1345
1346 if (!channel)
1347 goto fail;
1348
1349 channel->vcm = vcm;
1350 channel->channelType = type;
1351 channel->creationStatus =
1352 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1353
1354 return channel;
1355fail:
1356 channel_free(channel);
1357 return NULL;
1358}
1359
1360HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1361 LPSTR pVirtualName)
1362{
1363 size_t length = 0;
1364 rdpMcs* mcs = NULL;
1365 rdpMcsChannel* joined_channel = NULL;
1366 freerdp_peer* client = NULL;
1367 rdpPeerChannel* channel = NULL;
1368 WTSVirtualChannelManager* vcm = NULL;
1369 HANDLE hChannelHandle = NULL;
1370 rdpContext* context = NULL;
1371 vcm = (WTSVirtualChannelManager*)hServer;
1372
1373 if (!vcm)
1374 {
1375 SetLastError(ERROR_INVALID_DATA);
1376 return NULL;
1377 }
1378
1379 client = vcm->client;
1380 WINPR_ASSERT(client);
1381
1382 context = client->context;
1383 WINPR_ASSERT(context);
1384 WINPR_ASSERT(context->rdp);
1385 WINPR_ASSERT(context->settings);
1386
1387 mcs = context->rdp->mcs;
1388 WINPR_ASSERT(mcs);
1389
1390 length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1391
1392 if (length > CHANNEL_NAME_LEN)
1393 {
1394 SetLastError(ERROR_NOT_FOUND);
1395 return NULL;
1396 }
1397
1398 UINT32 index = 0;
1399 for (; index < mcs->channelCount; index++)
1400 {
1401 rdpMcsChannel* mchannel = &mcs->channels[index];
1402 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1403 {
1404 joined_channel = mchannel;
1405 break;
1406 }
1407 }
1408
1409 if (!joined_channel)
1410 {
1411 SetLastError(ERROR_NOT_FOUND);
1412 return NULL;
1413 }
1414
1415 channel = (rdpPeerChannel*)joined_channel->handle;
1416
1417 if (!channel)
1418 {
1419 const UINT32 VCChunkSize =
1420 freerdp_settings_get_uint32(context->settings, FreeRDP_VCChunkSize);
1421
1422 WINPR_ASSERT(index <= UINT16_MAX);
1423 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1424 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName);
1425
1426 if (!channel)
1427 goto fail;
1428
1429 joined_channel->handle = channel;
1430 }
1431
1432 hChannelHandle = (HANDLE)channel;
1433 return hChannelHandle;
1434fail:
1435 channel_free(channel);
1436 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1437 return NULL;
1438}
1439
1440HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1441{
1442 wStream* s = NULL;
1443 rdpMcs* mcs = NULL;
1444 BOOL joined = FALSE;
1445 freerdp_peer* client = NULL;
1446 rdpPeerChannel* channel = NULL;
1447 ULONG written = 0;
1448 WTSVirtualChannelManager* vcm = NULL;
1449
1450 if (SessionId == WTS_CURRENT_SESSION)
1451 return NULL;
1452
1453 vcm = (WTSVirtualChannelManager*)HashTable_GetItemValue(g_ServerHandles,
1454 (void*)(UINT_PTR)SessionId);
1455
1456 if (!vcm)
1457 return NULL;
1458
1459 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1460 {
1461 return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
1462 }
1463
1464 client = vcm->client;
1465 mcs = client->context->rdp->mcs;
1466
1467 for (UINT32 index = 0; index < mcs->channelCount; index++)
1468 {
1469 rdpMcsChannel* mchannel = &mcs->channels[index];
1470 if (mchannel->joined &&
1471 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1472 {
1473 joined = TRUE;
1474 break;
1475 }
1476 }
1477
1478 if (!joined)
1479 {
1480 SetLastError(ERROR_NOT_FOUND);
1481 return NULL;
1482 }
1483
1484 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1485 {
1486 SetLastError(ERROR_NOT_READY);
1487 return NULL;
1488 }
1489
1490 WINPR_ASSERT(client);
1491 WINPR_ASSERT(client->context);
1492 WINPR_ASSERT(client->context->settings);
1493
1494 const UINT32 VCChunkSize =
1495 freerdp_settings_get_uint32(client->context->settings, FreeRDP_VCChunkSize);
1496 channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
1497
1498 if (!channel)
1499 {
1500 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1501 return NULL;
1502 }
1503
1504 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1505 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1506
1507 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1508 {
1509 channel_free(channel);
1510 channel = NULL;
1511 goto fail;
1512 }
1513 s = Stream_New(NULL, 64);
1514
1515 if (!s)
1516 goto fail;
1517
1518 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1519 goto fail;
1520
1521 const size_t pos = Stream_GetPosition(s);
1522 WINPR_ASSERT(pos <= UINT32_MAX);
1523 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s, char), (UINT32)pos,
1524 &written))
1525 goto fail;
1526
1527 Stream_Free(s, TRUE);
1528 return channel;
1529fail:
1530 Stream_Free(s, TRUE);
1531 if (channel)
1532 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1533
1534 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1535 return NULL;
1536}
1537
1538BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1539{
1540 wStream* s = NULL;
1541 rdpMcs* mcs = NULL;
1542
1543 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1544 BOOL ret = TRUE;
1545
1546 if (channel)
1547 {
1548 WTSVirtualChannelManager* vcm = channel->vcm;
1549
1550 WINPR_ASSERT(vcm);
1551 WINPR_ASSERT(vcm->client);
1552 WINPR_ASSERT(vcm->client->context);
1553 WINPR_ASSERT(vcm->client->context->rdp);
1554 mcs = vcm->client->context->rdp->mcs;
1555
1556 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1557 {
1558 if (channel->index < mcs->channelCount)
1559 {
1560 rdpMcsChannel* cur = &mcs->channels[channel->index];
1561 rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
1562 channel_free(peerChannel);
1563 cur->handle = NULL;
1564 }
1565 }
1566 else
1567 {
1568 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1569 {
1570 ULONG written = 0;
1571 s = Stream_New(NULL, 8);
1572
1573 if (!s)
1574 {
1575 WLog_ERR(TAG, "Stream_New failed!");
1576 ret = FALSE;
1577 }
1578 else
1579 {
1580 wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
1581
1582 const size_t pos = Stream_GetPosition(s);
1583 WINPR_ASSERT(pos <= UINT32_MAX);
1584 ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s, char),
1585 (UINT32)pos, &written);
1586 Stream_Free(s, TRUE);
1587 }
1588 }
1589 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1590 }
1591 }
1592
1593 return ret;
1594}
1595
1596BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut,
1597 PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
1598{
1599 BYTE* buffer = NULL;
1600 wMessage message = { 0 };
1601 wtsChannelMessage* messageCtx = NULL;
1602 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1603
1604 WINPR_ASSERT(channel);
1605
1606 if (!MessageQueue_Peek(channel->queue, &message, FALSE))
1607 {
1608 SetLastError(ERROR_NO_DATA);
1609 *pBytesRead = 0;
1610 return FALSE;
1611 }
1612
1613 messageCtx = message.context;
1614
1615 if (messageCtx == NULL)
1616 return FALSE;
1617
1618 buffer = (BYTE*)(messageCtx + 1);
1619 *pBytesRead = messageCtx->length - messageCtx->offset;
1620
1621 if (Buffer == NULL || BufferSize == 0)
1622 {
1623 return TRUE;
1624 }
1625
1626 if (*pBytesRead > BufferSize)
1627 *pBytesRead = BufferSize;
1628
1629 CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
1630 messageCtx->offset += *pBytesRead;
1631
1632 if (messageCtx->offset >= messageCtx->length)
1633 {
1634 (void)MessageQueue_Peek(channel->queue, &message, TRUE);
1635 peer_channel_queue_free_message(&message);
1636 }
1637
1638 return TRUE;
1639}
1640
1641BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength,
1642 PULONG pBytesWritten)
1643{
1644 wStream* s = NULL;
1645 int cbLen = 0;
1646 int cbChId = 0;
1647 int first = 0;
1648 BYTE* buffer = NULL;
1649 size_t totalWritten = 0;
1650 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1651 BOOL ret = FALSE;
1652
1653 if (!channel)
1654 return FALSE;
1655
1656 EnterCriticalSection(&channel->writeLock);
1657 WINPR_ASSERT(channel->vcm);
1658 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1659 {
1660 buffer = (BYTE*)malloc(uLength);
1661
1662 if (!buffer)
1663 {
1664 SetLastError(g_err_oom);
1665 goto fail;
1666 }
1667
1668 CopyMemory(buffer, Buffer, uLength);
1669 totalWritten = uLength;
1670 if (!wts_queue_send_item(channel, buffer, uLength))
1671 goto fail;
1672 }
1673 else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
1674 {
1675 DEBUG_DVC("drdynvc not ready");
1676 goto fail;
1677 }
1678 else
1679 {
1680 first = TRUE;
1681
1682 size_t Length = uLength;
1683 while (Length > 0)
1684 {
1685 s = Stream_New(NULL, DVC_MAX_DATA_PDU_SIZE);
1686
1687 if (!s)
1688 {
1689 WLog_ERR(TAG, "Stream_New failed!");
1690 SetLastError(g_err_oom);
1691 goto fail;
1692 }
1693
1694 buffer = Stream_Buffer(s);
1695 Stream_Seek_UINT8(s);
1696 cbChId = wts_write_variable_uint(s, channel->channelId);
1697
1698 if (first && (Length > Stream_GetRemainingLength(s)))
1699 {
1700 cbLen = wts_write_variable_uint(s, WINPR_ASSERTING_INT_CAST(uint32_t, Length));
1701 buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF;
1702 }
1703 else
1704 {
1705 buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
1706 }
1707
1708 first = FALSE;
1709 size_t written = Stream_GetRemainingLength(s);
1710
1711 if (written > Length)
1712 written = Length;
1713
1714 Stream_Write(s, Buffer, written);
1715 const size_t length = Stream_GetPosition(s);
1716 Stream_Free(s, FALSE);
1717 if (length > UINT32_MAX)
1718 goto fail;
1719 Length -= written;
1720 Buffer += written;
1721 totalWritten += written;
1722 if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
1723 goto fail;
1724 }
1725 }
1726
1727 if (pBytesWritten)
1728 *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten);
1729
1730 ret = TRUE;
1731fail:
1732 LeaveCriticalSection(&channel->writeLock);
1733 return ret;
1734}
1735
1736BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1737{
1738 WLog_ERR("TODO", "TODO: implement");
1739 return TRUE;
1740}
1741
1742BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1743{
1744 WLog_ERR("TODO", "TODO: implement");
1745 return TRUE;
1746}
1747
1748BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
1749 PVOID* ppBuffer, DWORD* pBytesReturned)
1750{
1751 void* pfd = NULL;
1752 BOOL bval = 0;
1753 void* fds[10] = { 0 };
1754 HANDLE hEvent = NULL;
1755 int fds_count = 0;
1756 BOOL status = FALSE;
1757 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1758
1759 WINPR_ASSERT(channel);
1760
1761 switch ((UINT32)WtsVirtualClass)
1762 {
1763 case WTSVirtualFileHandle:
1764 hEvent = MessageQueue_Event(channel->queue);
1765 pfd = GetEventWaitObject(hEvent);
1766
1767 if (pfd)
1768 {
1769 fds[fds_count] = pfd;
1770 (fds_count)++;
1771 }
1772
1773 *ppBuffer = malloc(sizeof(void*));
1774
1775 if (!*ppBuffer)
1776 {
1777 SetLastError(g_err_oom);
1778 }
1779 else
1780 {
1781 CopyMemory(*ppBuffer, (void*)&fds[0], sizeof(void*));
1782 *pBytesReturned = sizeof(void*);
1783 status = TRUE;
1784 }
1785
1786 break;
1787
1788 case WTSVirtualEventHandle:
1789 hEvent = MessageQueue_Event(channel->queue);
1790
1791 *ppBuffer = malloc(sizeof(HANDLE));
1792
1793 if (!*ppBuffer)
1794 {
1795 SetLastError(g_err_oom);
1796 }
1797 else
1798 {
1799 CopyMemory(*ppBuffer, (void*)&hEvent, sizeof(HANDLE));
1800 *pBytesReturned = sizeof(void*);
1801 status = TRUE;
1802 }
1803
1804 break;
1805
1806 case WTSVirtualChannelReady:
1807 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1808 {
1809 bval = TRUE;
1810 status = TRUE;
1811 }
1812 else
1813 {
1814 switch (channel->dvc_open_state)
1815 {
1816 case DVC_OPEN_STATE_NONE:
1817 bval = FALSE;
1818 status = TRUE;
1819 break;
1820
1821 case DVC_OPEN_STATE_SUCCEEDED:
1822 bval = TRUE;
1823 status = TRUE;
1824 break;
1825
1826 default:
1827 *ppBuffer = NULL;
1828 *pBytesReturned = 0;
1829 return FALSE;
1830 }
1831 }
1832
1833 *ppBuffer = malloc(sizeof(BOOL));
1834
1835 if (!*ppBuffer)
1836 {
1837 SetLastError(g_err_oom);
1838 status = FALSE;
1839 }
1840 else
1841 {
1842 CopyMemory(*ppBuffer, &bval, sizeof(BOOL));
1843 *pBytesReturned = sizeof(BOOL);
1844 }
1845
1846 break;
1847 case WTSVirtualChannelOpenStatus:
1848 {
1849 INT32 value = channel->creationStatus;
1850 status = TRUE;
1851
1852 *ppBuffer = malloc(sizeof(value));
1853 if (!*ppBuffer)
1854 {
1855 SetLastError(g_err_oom);
1856 status = FALSE;
1857 }
1858 else
1859 {
1860 CopyMemory(*ppBuffer, &value, sizeof(value));
1861 *pBytesReturned = sizeof(value);
1862 }
1863 break;
1864 }
1865 default:
1866 break;
1867 }
1868
1869 return status;
1870}
1871
1872VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
1873{
1874 free(pMemory);
1875}
1876
1877BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1878 WINPR_ATTR_UNUSED PVOID pMemory,
1879 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1880{
1881 WLog_ERR("TODO", "TODO: implement");
1882 return FALSE;
1883}
1884
1885BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1886 WINPR_ATTR_UNUSED PVOID pMemory,
1887 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1888{
1889 WLog_ERR("TODO", "TODO: implement");
1890 return FALSE;
1891}
1892
1893BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd,
1894 WINPR_ATTR_UNUSED DWORD dwFlags)
1895{
1896 WLog_ERR("TODO", "TODO: implement");
1897 return FALSE;
1898}
1899
1900BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd)
1901{
1902 WLog_ERR("TODO", "TODO: implement");
1903 return FALSE;
1904}
1905
1906BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1907 WINPR_ATTR_UNUSED HWND hWnd,
1908 WINPR_ATTR_UNUSED DWORD dwFlags)
1909{
1910 WLog_ERR("TODO", "TODO: implement");
1911 return FALSE;
1912}
1913
1914BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1915 WINPR_ATTR_UNUSED HWND hWnd)
1916{
1917 WLog_ERR("TODO", "TODO: implement");
1918 return FALSE;
1919}
1920
1921BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId,
1922 WINPR_ATTR_UNUSED PHANDLE phToken)
1923{
1924 WLog_ERR("TODO", "TODO: implement");
1925 return FALSE;
1926}
1927
1928BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(WINPR_ATTR_UNUSED HANDLE hServer,
1929 WINPR_ATTR_UNUSED DWORD* pLevel,
1930 WINPR_ATTR_UNUSED DWORD SessionId,
1931 WINPR_ATTR_UNUSED LPWSTR* ppProcessInfo,
1932 WINPR_ATTR_UNUSED DWORD* pCount)
1933{
1934 WLog_ERR("TODO", "TODO: implement");
1935 return FALSE;
1936}
1937
1938BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(WINPR_ATTR_UNUSED HANDLE hServer,
1939 WINPR_ATTR_UNUSED DWORD* pLevel,
1940 WINPR_ATTR_UNUSED DWORD SessionId,
1941 WINPR_ATTR_UNUSED LPSTR* ppProcessInfo,
1942 WINPR_ATTR_UNUSED DWORD* pCount)
1943{
1944 WLog_ERR("TODO", "TODO: implement");
1945 return FALSE;
1946}
1947
1948BOOL WINAPI FreeRDP_WTSEnumerateListenersW(WINPR_ATTR_UNUSED HANDLE hServer,
1949 WINPR_ATTR_UNUSED PVOID pReserved,
1950 WINPR_ATTR_UNUSED DWORD Reserved,
1951 WINPR_ATTR_UNUSED PWTSLISTENERNAMEW pListeners,
1952 WINPR_ATTR_UNUSED DWORD* pCount)
1953{
1954 WLog_ERR("TODO", "TODO: implement");
1955 return FALSE;
1956}
1957
1958BOOL WINAPI FreeRDP_WTSEnumerateListenersA(WINPR_ATTR_UNUSED HANDLE hServer,
1959 WINPR_ATTR_UNUSED PVOID pReserved,
1960 WINPR_ATTR_UNUSED DWORD Reserved,
1961 WINPR_ATTR_UNUSED PWTSLISTENERNAMEA pListeners,
1962 WINPR_ATTR_UNUSED DWORD* pCount)
1963{
1964 WLog_ERR("TODO", "TODO: implement");
1965 return FALSE;
1966}
1967
1968BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(WINPR_ATTR_UNUSED HANDLE hServer,
1969 WINPR_ATTR_UNUSED PVOID pReserved,
1970 WINPR_ATTR_UNUSED DWORD Reserved,
1971 WINPR_ATTR_UNUSED LPWSTR pListenerName,
1972 WINPR_ATTR_UNUSED PWTSLISTENERCONFIGW pBuffer)
1973{
1974 WLog_ERR("TODO", "TODO: implement");
1975 return FALSE;
1976}
1977
1978BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(WINPR_ATTR_UNUSED HANDLE hServer,
1979 WINPR_ATTR_UNUSED PVOID pReserved,
1980 WINPR_ATTR_UNUSED DWORD Reserved,
1981 WINPR_ATTR_UNUSED LPSTR pListenerName,
1982 WINPR_ATTR_UNUSED PWTSLISTENERCONFIGA pBuffer)
1983{
1984 WLog_ERR("TODO", "TODO: implement");
1985 return FALSE;
1986}
1987
1988BOOL WINAPI FreeRDP_WTSCreateListenerW(WINPR_ATTR_UNUSED HANDLE hServer,
1989 WINPR_ATTR_UNUSED PVOID pReserved,
1990 WINPR_ATTR_UNUSED DWORD Reserved,
1991 WINPR_ATTR_UNUSED LPWSTR pListenerName,
1992 WINPR_ATTR_UNUSED PWTSLISTENERCONFIGW pBuffer,
1993 WINPR_ATTR_UNUSED DWORD flag)
1994{
1995 WLog_ERR("TODO", "TODO: implement");
1996 return FALSE;
1997}
1998
1999BOOL WINAPI FreeRDP_WTSCreateListenerA(WINPR_ATTR_UNUSED HANDLE hServer,
2000 WINPR_ATTR_UNUSED PVOID pReserved,
2001 WINPR_ATTR_UNUSED DWORD Reserved,
2002 WINPR_ATTR_UNUSED LPSTR pListenerName,
2003 WINPR_ATTR_UNUSED PWTSLISTENERCONFIGA pBuffer,
2004 WINPR_ATTR_UNUSED DWORD flag)
2005{
2006 WLog_ERR("TODO", "TODO: implement");
2007 return FALSE;
2008}
2009
2010BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(
2011 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2012 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2013 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2014 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2015{
2016 WLog_ERR("TODO", "TODO: implement");
2017 return FALSE;
2018}
2019
2020BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(
2021 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2022 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2023 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2024 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2025{
2026 WLog_ERR("TODO", "TODO: implement");
2027 return FALSE;
2028}
2029
2030BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(
2031 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2032 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2033 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2034 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2035 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2036{
2037 WLog_ERR("TODO", "TODO: implement");
2038 return FALSE;
2039}
2040
2041BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(
2042 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2043 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2044 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2045 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2046 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2047{
2048 WLog_ERR("TODO", "TODO: implement");
2049 return FALSE;
2050}
2051
2052BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable)
2053{
2054 WLog_ERR("TODO", "TODO: implement");
2055 return FALSE;
2056}
2057
2058BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled)
2059{
2060 WLog_ERR("TODO", "TODO: implement");
2061 return FALSE;
2062}
2063
2064BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId)
2065{
2066 WLog_ERR("TODO", "TODO: implement");
2067 return FALSE;
2068}
2069
2070DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(void)
2071{
2072 WLog_ERR("TODO", "TODO: implement");
2073 return 0xFFFFFFFF;
2074}
2075BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer)
2076{
2077 WLog_ERR("TODO", "TODO: implement");
2078 return FALSE;
2079}
2080
2081BOOL WINAPI FreeRDP_WTSLogonUser(WINPR_ATTR_UNUSED HANDLE hServer,
2082 WINPR_ATTR_UNUSED LPCSTR username,
2083 WINPR_ATTR_UNUSED LPCSTR password, WINPR_ATTR_UNUSED LPCSTR domain)
2084{
2085 WLog_ERR("TODO", "TODO: implement");
2086 return FALSE;
2087}
2088
2089void server_channel_common_free(rdpPeerChannel* channel)
2090{
2091 if (!channel)
2092 return;
2093 MessageQueue_Free(channel->queue);
2094 Stream_Free(channel->receiveData, TRUE);
2095 DeleteCriticalSection(&channel->writeLock);
2096 free(channel);
2097}
2098
2099rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
2100 size_t chunkSize, const wObject* callback,
2101 const char* name)
2102{
2103 rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1, sizeof(rdpPeerChannel));
2104 if (!channel)
2105 return NULL;
2106
2107 InitializeCriticalSection(&channel->writeLock);
2108
2109 channel->receiveData = Stream_New(NULL, chunkSize);
2110 if (!channel->receiveData)
2111 goto fail;
2112
2113 channel->queue = MessageQueue_New(callback);
2114 if (!channel->queue)
2115 goto fail;
2116
2117 channel->index = index;
2118 channel->client = client;
2119 channel->channelId = channelId;
2120 strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
2121 return channel;
2122fail:
2123 WINPR_PRAGMA_DIAG_PUSH
2124 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2125 server_channel_common_free(channel);
2126 WINPR_PRAGMA_DIAG_POP
2127 return NULL;
2128}
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
This struct contains function pointer to initialize/free objects.
Definition collections.h:57