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