FreeRDP
Loading...
Searching...
No Matches
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 = nullptr;
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 = nullptr;
80 wtsChannelMessage* messageCtx = nullptr;
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, nullptr, nullptr);
95}
96
97static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
98{
99 BYTE* buffer = nullptr;
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 = nullptr;
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 = nullptr;
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 = nullptr;
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 = nullptr;
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 = nullptr;
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] = WINPR_C_ARRAY_INIT;
577 wStream staticS = WINPR_C_ARRAY_INIT;
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 = WINPR_C_ARRAY_INIT;
602 BOOL status = TRUE;
603 WTSVirtualChannelManager* vcm = nullptr;
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 = nullptr;
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 nullptr;
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 nullptr;
669}
670
671static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs, const UINT16 channel_id)
672{
673 if (!mcs || !channel_id)
674 return nullptr;
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 nullptr;
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) != nullptr);
696}
697
698BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
699{
700 if (!client || !client->context || !client->context->rdp)
701 return FALSE;
702
703 return (wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) != nullptr);
704}
705
706BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
707{
709
710 if (!vcm || !vcm->rdp)
711 return FALSE;
712
713 return (wts_get_joined_channel_by_name(vcm->rdp->mcs, name) != nullptr);
714}
715
716BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
717{
719 WINPR_ASSERT(vcm);
720 return vcm->drdynvc_state;
721}
722
723void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
724 void* userdata)
725{
726 WTSVirtualChannelManager* vcm = hServer;
727
728 WINPR_ASSERT(vcm);
729
730 vcm->dvc_creation_status = cb;
731 vcm->dvc_creation_status_userdata = userdata;
732}
733
734UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name)
735{
736 rdpMcsChannel* channel = nullptr;
737
738 WINPR_ASSERT(channel_name);
739 if (!client || !client->context || !client->context->rdp)
740 return 0;
741
742 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
743
744 if (!channel)
745 return 0;
746
747 return channel->ChannelId;
748}
749
750UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
751{
752 rdpPeerChannel* channel = hChannelHandle;
753
754 WINPR_ASSERT(channel);
755
756 return channel->channelId;
757}
758
759BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, void* handle)
760{
761 rdpMcsChannel* channel = nullptr;
762
763 WINPR_ASSERT(channel_name);
764 if (!client || !client->context || !client->context->rdp)
765 return FALSE;
766
767 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
768
769 if (!channel)
770 return FALSE;
771
772 channel->handle = handle;
773 return TRUE;
774}
775
776BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id, void* handle)
777{
778 rdpMcsChannel* channel = nullptr;
779
780 if (!client || !client->context || !client->context->rdp)
781 return FALSE;
782
783 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
784
785 if (!channel)
786 return FALSE;
787
788 channel->handle = handle;
789 return TRUE;
790}
791
792void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_name)
793{
794 rdpMcsChannel* channel = nullptr;
795
796 WINPR_ASSERT(channel_name);
797 if (!client || !client->context || !client->context->rdp)
798 return nullptr;
799
800 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
801
802 if (!channel)
803 return nullptr;
804
805 return channel->handle;
806}
807
808void* WTSChannelGetHandleById(freerdp_peer* client, UINT16 channel_id)
809{
810 rdpMcsChannel* channel = nullptr;
811
812 if (!client || !client->context || !client->context->rdp)
813 return nullptr;
814
815 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
816
817 if (!channel)
818 return nullptr;
819
820 return channel->handle;
821}
822
823const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
824{
825 rdpMcsChannel* channel = nullptr;
826
827 if (!client || !client->context || !client->context->rdp)
828 return nullptr;
829
830 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
831
832 if (!channel)
833 return nullptr;
834
835 return (const char*)channel->Name;
836}
837
838char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count)
839{
840 rdpMcs* mcs = nullptr;
841 char** names = nullptr;
842
843 if (!client || !client->context || !count)
844 return nullptr;
845
846 WINPR_ASSERT(client->context->rdp);
847 mcs = client->context->rdp->mcs;
848 WINPR_ASSERT(mcs);
849 *count = mcs->channelCount;
850
851 names = (char**)calloc(mcs->channelCount, sizeof(char*));
852 if (!names)
853 return nullptr;
854
855 for (UINT32 index = 0; index < mcs->channelCount; index++)
856 {
857 rdpMcsChannel* mchannel = &mcs->channels[index];
858 names[index] = mchannel->Name;
859 }
860
861 return names;
862}
863
864INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
865{
866 rdpMcsChannel* channel = nullptr;
867
868 if (!client || !client->context || !client->context->rdp)
869 return -1;
870
871 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
872
873 if (!channel)
874 return -1;
875
876 return (INT64)channel->options;
877}
878
879BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
880 WINPR_ATTR_UNUSED ULONG TargetLogonId,
881 WINPR_ATTR_UNUSED BYTE HotkeyVk,
882 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
883{
884 WLog_ERR("TODO", "TODO: implement");
885 return FALSE;
886}
887
888BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
889 WINPR_ATTR_UNUSED ULONG TargetLogonId,
890 WINPR_ATTR_UNUSED BYTE HotkeyVk,
891 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
892{
893 WLog_ERR("TODO", "TODO: implement");
894 return FALSE;
895}
896
897BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
898 WINPR_ATTR_UNUSED ULONG TargetLogonId,
899 WINPR_ATTR_UNUSED BYTE HotkeyVk,
900 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
901 WINPR_ATTR_UNUSED DWORD flags)
902{
903 WLog_ERR("TODO", "TODO: implement");
904 return FALSE;
905}
906
907BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
908 WINPR_ATTR_UNUSED ULONG TargetLogonId,
909 WINPR_ATTR_UNUSED BYTE HotkeyVk,
910 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
911 WINPR_ATTR_UNUSED DWORD flags)
912{
913 WLog_ERR("TODO", "TODO: implement");
914 return FALSE;
915}
916
917BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId)
918{
919 WLog_ERR("TODO", "TODO: implement");
920 return FALSE;
921}
922
923BOOL WINAPI FreeRDP_WTSConnectSessionW(WINPR_ATTR_UNUSED ULONG LogonId,
924 WINPR_ATTR_UNUSED ULONG TargetLogonId,
925 WINPR_ATTR_UNUSED PWSTR pPassword,
926 WINPR_ATTR_UNUSED BOOL bWait)
927{
928 WLog_ERR("TODO", "TODO: implement");
929 return FALSE;
930}
931
932BOOL WINAPI FreeRDP_WTSConnectSessionA(WINPR_ATTR_UNUSED ULONG LogonId,
933 WINPR_ATTR_UNUSED ULONG TargetLogonId,
934 WINPR_ATTR_UNUSED PSTR pPassword,
935 WINPR_ATTR_UNUSED BOOL bWait)
936{
937 WLog_ERR("TODO", "TODO: implement");
938 return FALSE;
939}
940
941BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName,
942 WINPR_ATTR_UNUSED DWORD Reserved,
943 WINPR_ATTR_UNUSED DWORD Version,
944 WINPR_ATTR_UNUSED PWTS_SERVER_INFOW* ppServerInfo,
945 WINPR_ATTR_UNUSED DWORD* pCount)
946{
947 WLog_ERR("TODO", "TODO: implement");
948 return FALSE;
949}
950
951BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName,
952 WINPR_ATTR_UNUSED DWORD Reserved,
953 WINPR_ATTR_UNUSED DWORD Version,
954 WINPR_ATTR_UNUSED PWTS_SERVER_INFOA* ppServerInfo,
955 WINPR_ATTR_UNUSED DWORD* pCount)
956{
957 WLog_ERR("TODO", "TODO: implement");
958 return FALSE;
959}
960
961HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName)
962{
963 WLog_ERR("TODO", "TODO: implement");
964 return INVALID_HANDLE_VALUE;
965}
966
967static void wts_virtual_channel_manager_free_message(void* obj)
968{
969 wMessage* msg = (wMessage*)obj;
970
971 if (msg)
972 {
973 BYTE* buffer = (BYTE*)msg->wParam;
974
975 if (buffer)
976 free(buffer);
977 }
978}
979
980static void channel_free(rdpPeerChannel* channel)
981{
982 server_channel_common_free(channel);
983}
984
985static void array_channel_free(void* ptr)
986{
987 rdpPeerChannel* channel = ptr;
988 channel_free(channel);
989}
990
991static BOOL dynChannelMatch(const void* v1, const void* v2)
992{
993 const UINT32* p1 = (const UINT32*)v1;
994 const UINT32* p2 = (const UINT32*)v2;
995 return *p1 == *p2;
996}
997
998static UINT32 channelId_Hash(const void* key)
999{
1000 const UINT32* v = (const UINT32*)key;
1001 return *v;
1002}
1003
1004HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1005{
1006 rdpContext* context = nullptr;
1007 freerdp_peer* client = nullptr;
1008 WTSVirtualChannelManager* vcm = nullptr;
1009 HANDLE hServer = INVALID_HANDLE_VALUE;
1010 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1011
1012 context = (rdpContext*)pServerName;
1013
1014 if (!context)
1015 return INVALID_HANDLE_VALUE;
1016
1017 client = context->peer;
1018
1019 if (!client)
1020 {
1021 SetLastError(ERROR_INVALID_DATA);
1022 return INVALID_HANDLE_VALUE;
1023 }
1024
1025 vcm = (WTSVirtualChannelManager*)calloc(1, sizeof(WTSVirtualChannelManager));
1026
1027 if (!vcm)
1028 goto error_vcm_alloc;
1029
1030 vcm->client = client;
1031 vcm->rdp = context->rdp;
1032 vcm->SessionId = g_SessionId++;
1033
1034 if (!g_ServerHandles)
1035 {
1036 g_ServerHandles = HashTable_New(TRUE);
1037
1038 if (!g_ServerHandles)
1039 goto error_free;
1040 }
1041
1042 if (!HashTable_Insert(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId, (void*)vcm))
1043 goto error_free;
1044
1045 queueCallbacks.fnObjectFree = wts_virtual_channel_manager_free_message;
1046 vcm->queue = MessageQueue_New(&queueCallbacks);
1047
1048 if (!vcm->queue)
1049 goto error_queue;
1050
1051 vcm->dvc_channel_id_seq = 0;
1052 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1053
1054 if (!vcm->dynamicVirtualChannels)
1055 goto error_dynamicVirtualChannels;
1056
1057 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1058 goto error_hashFunction;
1059
1060 {
1061 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1062 WINPR_ASSERT(obj);
1063 obj->fnObjectFree = array_channel_free;
1064
1065 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1066 obj->fnObjectEquals = dynChannelMatch;
1067 }
1068 client->ReceiveChannelData = WTSReceiveChannelData;
1069 hServer = (HANDLE)vcm;
1070 return hServer;
1071
1072error_hashFunction:
1073 HashTable_Free(vcm->dynamicVirtualChannels);
1074error_dynamicVirtualChannels:
1075 MessageQueue_Free(vcm->queue);
1076error_queue:
1077 HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
1078error_free:
1079 free(vcm);
1080error_vcm_alloc:
1081 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1082 return INVALID_HANDLE_VALUE;
1083}
1084
1085HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1086{
1087 WLog_ERR("TODO", "TODO: implement");
1088 return INVALID_HANDLE_VALUE;
1089}
1090
1091HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1092{
1093 return FreeRDP_WTSOpenServerA(pServerName);
1094}
1095
1096VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1097{
1098 WTSVirtualChannelManager* vcm = nullptr;
1099 vcm = (WTSVirtualChannelManager*)hServer;
1100
1101 if (vcm && (vcm != INVALID_HANDLE_VALUE))
1102 {
1103 HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
1104
1105 HashTable_Free(vcm->dynamicVirtualChannels);
1106
1107 if (vcm->drdynvc_channel)
1108 {
1109 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1110 vcm->drdynvc_channel = nullptr;
1111 }
1112
1113 MessageQueue_Free(vcm->queue);
1114 free(vcm);
1115 }
1116}
1117
1118BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1119 WINPR_ATTR_UNUSED DWORD Reserved,
1120 WINPR_ATTR_UNUSED DWORD Version,
1121 WINPR_ATTR_UNUSED PWTS_SESSION_INFOW* ppSessionInfo,
1122 WINPR_ATTR_UNUSED DWORD* pCount)
1123{
1124 WLog_ERR("TODO", "TODO: implement");
1125 return FALSE;
1126}
1127
1128BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1129 WINPR_ATTR_UNUSED DWORD Reserved,
1130 WINPR_ATTR_UNUSED DWORD Version,
1131 WINPR_ATTR_UNUSED PWTS_SESSION_INFOA* ppSessionInfo,
1132 WINPR_ATTR_UNUSED DWORD* pCount)
1133{
1134 WLog_ERR("TODO", "TODO: implement");
1135 return FALSE;
1136}
1137
1138BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1139 WINPR_ATTR_UNUSED DWORD* pLevel,
1140 WINPR_ATTR_UNUSED DWORD Filter,
1141 WINPR_ATTR_UNUSED PWTS_SESSION_INFO_1W* ppSessionInfo,
1142 WINPR_ATTR_UNUSED DWORD* pCount)
1143{
1144 WLog_ERR("TODO", "TODO: implement");
1145 return FALSE;
1146}
1147
1148BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1149 WINPR_ATTR_UNUSED DWORD* pLevel,
1150 WINPR_ATTR_UNUSED DWORD Filter,
1151 WINPR_ATTR_UNUSED PWTS_SESSION_INFO_1A* ppSessionInfo,
1152 WINPR_ATTR_UNUSED DWORD* pCount)
1153{
1154 WLog_ERR("TODO", "TODO: implement");
1155 return FALSE;
1156}
1157
1158BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1159 WINPR_ATTR_UNUSED DWORD Reserved,
1160 WINPR_ATTR_UNUSED DWORD Version,
1161 WINPR_ATTR_UNUSED PWTS_PROCESS_INFOW* ppProcessInfo,
1162 WINPR_ATTR_UNUSED DWORD* pCount)
1163{
1164 WLog_ERR("TODO", "TODO: implement");
1165 return FALSE;
1166}
1167
1168BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1169 WINPR_ATTR_UNUSED DWORD Reserved,
1170 WINPR_ATTR_UNUSED DWORD Version,
1171 WINPR_ATTR_UNUSED PWTS_PROCESS_INFOA* ppProcessInfo,
1172 WINPR_ATTR_UNUSED DWORD* pCount)
1173{
1174 WLog_ERR("TODO", "TODO: implement");
1175 return FALSE;
1176}
1177
1178BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1179 WINPR_ATTR_UNUSED DWORD ProcessId,
1180 WINPR_ATTR_UNUSED DWORD ExitCode)
1181{
1182 WLog_ERR("TODO", "TODO: implement");
1183 return FALSE;
1184}
1185
1186BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1187 WINPR_ATTR_UNUSED DWORD SessionId,
1188 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1189 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1190 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1191{
1192 WLog_ERR("TODO", "TODO: implement");
1193 return FALSE;
1194}
1195
1196BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1197 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1198 DWORD* pBytesReturned)
1199{
1200 DWORD BytesReturned = 0;
1201 WTSVirtualChannelManager* vcm = nullptr;
1202 vcm = (WTSVirtualChannelManager*)hServer;
1203
1204 if (!vcm)
1205 return FALSE;
1206
1207 if (WTSInfoClass == WTSSessionId)
1208 {
1209 ULONG* pBuffer = nullptr;
1210 BytesReturned = sizeof(ULONG);
1211 pBuffer = (ULONG*)malloc(sizeof(BytesReturned));
1212
1213 if (!pBuffer)
1214 {
1215 SetLastError(g_err_oom);
1216 return FALSE;
1217 }
1218
1219 *pBuffer = vcm->SessionId;
1220 *ppBuffer = (LPSTR)pBuffer;
1221 *pBytesReturned = BytesReturned;
1222 return TRUE;
1223 }
1224
1225 return FALSE;
1226}
1227
1228BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1229 WINPR_ATTR_UNUSED LPWSTR pUserName,
1230 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1231 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1232 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1233{
1234 WLog_ERR("TODO", "TODO: implement");
1235 return FALSE;
1236}
1237
1238BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1239 WINPR_ATTR_UNUSED LPSTR pUserName,
1240 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1241 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1242 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1243{
1244 WLog_ERR("TODO", "TODO: implement");
1245 return FALSE;
1246}
1247
1248BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1249 WINPR_ATTR_UNUSED LPWSTR pUserName,
1250 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1251 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1252 WINPR_ATTR_UNUSED DWORD DataLength)
1253{
1254 WLog_ERR("TODO", "TODO: implement");
1255 return FALSE;
1256}
1257
1258BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1259 WINPR_ATTR_UNUSED LPSTR pUserName,
1260 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1261 WINPR_ATTR_UNUSED LPSTR pBuffer,
1262 WINPR_ATTR_UNUSED DWORD DataLength)
1263{
1264 WLog_ERR("TODO", "TODO: implement");
1265 return FALSE;
1266}
1267
1268BOOL WINAPI
1269FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1270 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1271 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1272 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1273 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1274{
1275 WLog_ERR("TODO", "TODO: implement");
1276 return FALSE;
1277}
1278
1279BOOL WINAPI
1280FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1281 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1282 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1283 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1284 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1285{
1286 WLog_ERR("TODO", "TODO: implement");
1287 return FALSE;
1288}
1289
1290BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1291 WINPR_ATTR_UNUSED DWORD SessionId,
1292 WINPR_ATTR_UNUSED BOOL bWait)
1293{
1294 WLog_ERR("TODO", "TODO: implement");
1295 return FALSE;
1296}
1297
1298BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1299 WINPR_ATTR_UNUSED DWORD SessionId,
1300 WINPR_ATTR_UNUSED BOOL bWait)
1301{
1302 WLog_ERR("TODO", "TODO: implement");
1303 return FALSE;
1304}
1305
1306BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1307 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1308{
1309 WLog_ERR("TODO", "TODO: implement");
1310 return FALSE;
1311}
1312
1313BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1314 WINPR_ATTR_UNUSED DWORD EventMask,
1315 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1316{
1317 WLog_ERR("TODO", "TODO: implement");
1318 return FALSE;
1319}
1320
1321static void peer_channel_queue_free_message(void* obj)
1322{
1323 wMessage* msg = (wMessage*)obj;
1324 if (!msg)
1325 return;
1326
1327 free(msg->context);
1328 msg->context = nullptr;
1329}
1330
1331static rdpPeerChannel* channel_new(WTSVirtualChannelManager* vcm, freerdp_peer* client,
1332 UINT32 ChannelId, UINT16 index, UINT16 type, size_t chunkSize,
1333 const char* name)
1334{
1335 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1336 queueCallbacks.fnObjectFree = peer_channel_queue_free_message;
1337
1338 rdpPeerChannel* channel =
1339 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1340
1341 WINPR_ASSERT(vcm);
1342 WINPR_ASSERT(client);
1343
1344 if (!channel)
1345 goto fail;
1346
1347 channel->vcm = vcm;
1348 channel->channelType = type;
1349 channel->creationStatus =
1350 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1351
1352 return channel;
1353fail:
1354 channel_free(channel);
1355 return nullptr;
1356}
1357
1358HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1359 LPSTR pVirtualName)
1360{
1361 size_t length = 0;
1362 rdpMcs* mcs = nullptr;
1363 rdpMcsChannel* joined_channel = nullptr;
1364 freerdp_peer* client = nullptr;
1365 rdpPeerChannel* channel = nullptr;
1366 WTSVirtualChannelManager* vcm = nullptr;
1367 HANDLE hChannelHandle = nullptr;
1368 rdpContext* context = nullptr;
1369 vcm = (WTSVirtualChannelManager*)hServer;
1370
1371 if (!vcm)
1372 {
1373 SetLastError(ERROR_INVALID_DATA);
1374 return nullptr;
1375 }
1376
1377 client = vcm->client;
1378 WINPR_ASSERT(client);
1379
1380 context = client->context;
1381 WINPR_ASSERT(context);
1382 WINPR_ASSERT(context->rdp);
1383 WINPR_ASSERT(context->settings);
1384
1385 mcs = context->rdp->mcs;
1386 WINPR_ASSERT(mcs);
1387
1388 length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1389
1390 if (length > CHANNEL_NAME_LEN)
1391 {
1392 SetLastError(ERROR_NOT_FOUND);
1393 return nullptr;
1394 }
1395
1396 UINT32 index = 0;
1397 for (; index < mcs->channelCount; index++)
1398 {
1399 rdpMcsChannel* mchannel = &mcs->channels[index];
1400 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1401 {
1402 joined_channel = mchannel;
1403 break;
1404 }
1405 }
1406
1407 if (!joined_channel)
1408 {
1409 SetLastError(ERROR_NOT_FOUND);
1410 return nullptr;
1411 }
1412
1413 channel = (rdpPeerChannel*)joined_channel->handle;
1414
1415 if (!channel)
1416 {
1417 const UINT32 VCChunkSize =
1418 freerdp_settings_get_uint32(context->settings, FreeRDP_VCChunkSize);
1419
1420 WINPR_ASSERT(index <= UINT16_MAX);
1421 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1422 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName);
1423
1424 if (!channel)
1425 goto fail;
1426
1427 joined_channel->handle = channel;
1428 }
1429
1430 hChannelHandle = (HANDLE)channel;
1431 return hChannelHandle;
1432fail:
1433 channel_free(channel);
1434 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1435 return nullptr;
1436}
1437
1438HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1439{
1440 wStream* s = nullptr;
1441 rdpMcs* mcs = nullptr;
1442 BOOL joined = FALSE;
1443 freerdp_peer* client = nullptr;
1444 rdpPeerChannel* channel = nullptr;
1445 ULONG written = 0;
1446 WTSVirtualChannelManager* vcm = nullptr;
1447
1448 if (SessionId == WTS_CURRENT_SESSION)
1449 return nullptr;
1450
1451 vcm = (WTSVirtualChannelManager*)HashTable_GetItemValue(g_ServerHandles,
1452 (void*)(UINT_PTR)SessionId);
1453
1454 if (!vcm)
1455 return nullptr;
1456
1457 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1458 {
1459 return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
1460 }
1461
1462 client = vcm->client;
1463 mcs = client->context->rdp->mcs;
1464
1465 for (UINT32 index = 0; index < mcs->channelCount; index++)
1466 {
1467 rdpMcsChannel* mchannel = &mcs->channels[index];
1468 if (mchannel->joined &&
1469 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1470 {
1471 joined = TRUE;
1472 break;
1473 }
1474 }
1475
1476 if (!joined)
1477 {
1478 SetLastError(ERROR_NOT_FOUND);
1479 return nullptr;
1480 }
1481
1482 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1483 {
1484 SetLastError(ERROR_NOT_READY);
1485 return nullptr;
1486 }
1487
1488 WINPR_ASSERT(client);
1489 WINPR_ASSERT(client->context);
1490 WINPR_ASSERT(client->context->settings);
1491
1492 const UINT32 VCChunkSize =
1493 freerdp_settings_get_uint32(client->context->settings, FreeRDP_VCChunkSize);
1494 channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
1495
1496 if (!channel)
1497 {
1498 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1499 return nullptr;
1500 }
1501
1502 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1503 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1504
1505 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1506 {
1507 channel_free(channel);
1508 channel = nullptr;
1509 goto fail;
1510 }
1511 s = Stream_New(nullptr, 64);
1512
1513 if (!s)
1514 goto fail;
1515
1516 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1517 goto fail;
1518
1519 {
1520 const size_t pos = Stream_GetPosition(s);
1521 WINPR_ASSERT(pos <= UINT32_MAX);
1522 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s, char), (UINT32)pos,
1523 &written))
1524 goto fail;
1525 }
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 nullptr;
1536}
1537
1538BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1539{
1540 wStream* s = nullptr;
1541 rdpMcs* mcs = nullptr;
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 = nullptr;
1564 }
1565 }
1566 else
1567 {
1568 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1569 {
1570 ULONG written = 0;
1571 s = Stream_New(nullptr, 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 = nullptr;
1600 wMessage message = WINPR_C_ARRAY_INIT;
1601 wtsChannelMessage* messageCtx = nullptr;
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 == nullptr)
1616 return FALSE;
1617
1618 buffer = (BYTE*)(messageCtx + 1);
1619 *pBytesRead = messageCtx->length - messageCtx->offset;
1620
1621 if (Buffer == nullptr || 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 = nullptr;
1645 int cbLen = 0;
1646 int cbChId = 0;
1647 int first = 0;
1648 BYTE* buffer = nullptr;
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(nullptr, 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 = nullptr;
1752 BOOL bval = 0;
1753 void* fds[10] = WINPR_C_ARRAY_INIT;
1754 HANDLE hEvent = nullptr;
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 = nullptr;
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 nullptr;
2106
2107 InitializeCriticalSection(&channel->writeLock);
2108
2109 channel->receiveData = Stream_New(nullptr, 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 nullptr;
2128}
WINPR_ATTR_NODISCARD 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:52
OBJECT_FREE_FN fnObjectFree
Definition collections.h:58
OBJECT_EQUALS_FN fnObjectEquals
Definition collections.h:59