22#include <freerdp/config.h>
29#include <winpr/atexit.h>
30#include <winpr/wtypes.h>
32#include <winpr/synch.h>
33#include <winpr/stream.h>
34#include <winpr/assert.h>
35#include <winpr/cast.h>
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>
47#define TAG FREERDP_TAG("core.server")
49#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
51#define DEBUG_DVC(...) \
57#define DVC_MAX_DATA_PDU_SIZE 1600
67static const DWORD g_err_oom = WINPR_CXX_COMPAT_CAST(DWORD, E_OUTOFMEMORY);
69static DWORD g_SessionId = 1;
70static wHashTable* g_ServerHandles =
nullptr;
71static INIT_ONCE g_HandleInitializer = INIT_ONCE_STATIC_INIT;
76 return HashTable_GetItemValue(vcm->dynamicVirtualChannels, &ChannelId);
79static BOOL wts_queue_receive_data(rdpPeerChannel* channel,
const BYTE* Buffer, UINT32 Length)
81 BYTE* buffer =
nullptr;
82 wtsChannelMessage* messageCtx =
nullptr;
84 WINPR_ASSERT(channel);
85 messageCtx = (wtsChannelMessage*)malloc(
sizeof(wtsChannelMessage) + Length);
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);
99static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
101 BYTE* buffer =
nullptr;
104 WINPR_ASSERT(channel);
105 WINPR_ASSERT(channel->vcm);
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);
115static unsigned wts_read_variable_uint(
wStream* s,
int cbLen, UINT32* val)
122 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
125 Stream_Read_UINT8(s, *val);
129 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
132 Stream_Read_UINT16(s, *val);
136 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
139 Stream_Read_UINT32(s, *val);
143 WLog_ERR(TAG,
"invalid wts variable uint len %d", cbLen);
148static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
152 WINPR_ASSERT(channel);
153 WINPR_ASSERT(channel->vcm);
157 Stream_Seek_UINT8(channel->receiveData);
158 Stream_Read_UINT16(channel->receiveData, Version);
159 DEBUG_DVC(
"Version: %" PRIu16
"", Version);
163 WLog_ERR(TAG,
"invalid version %" PRIu16
" for DRDYNVC", Version);
168 vcm->drdynvc_state = DRDYNVC_STATE_READY;
171 vcm->dvc_spoken_version = MAX(Version, 1);
173 return SetEvent(MessageQueue_Event(vcm->queue));
176static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel,
wStream* s, UINT32 length)
178 UINT32 CreationStatus = 0;
181 WINPR_ASSERT(channel);
186 Stream_Read_UINT32(s, CreationStatus);
188 if ((INT32)CreationStatus < 0)
190 DEBUG_DVC(
"ChannelId %" PRIu32
" creation failed (%" PRId32
")", channel->channelId,
191 (INT32)CreationStatus);
192 channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
196 DEBUG_DVC(
"ChannelId %" PRIu32
" creation succeeded", channel->channelId);
197 channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
200 channel->creationStatus = (INT32)CreationStatus;
201 IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata,
202 channel->channelId, (INT32)CreationStatus);
204 WLog_ERR(TAG,
"vcm->dvc_creation_status failed!");
209static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel,
wStream* s,
int cbLen,
212 WINPR_ASSERT(channel);
214 const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
223 if (length > channel->dvc_total_length)
226 Stream_ResetPosition(channel->receiveData);
228 if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
231 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
235static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel,
wStream* s, UINT32 length)
239 WINPR_ASSERT(channel);
241 if (channel->dvc_total_length > 0)
243 if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
245 channel->dvc_total_length = 0;
246 WLog_ERR(TAG,
"incorrect fragment data, discarded.");
250 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
252 if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
254 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
255 channel->dvc_total_length);
256 channel->dvc_total_length = 0;
263 ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length);
269static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
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);
277static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
282 UINT32 ChannelId = 0;
283 rdpPeerChannel* dvc =
nullptr;
285 WINPR_ASSERT(channel);
286 WINPR_ASSERT(channel->vcm);
288 size_t length = Stream_GetPosition(channel->receiveData);
290 if ((length < 1) || (length > UINT32_MAX))
293 Stream_ResetPosition(channel->receiveData);
294 const UINT8 value = Stream_Get_UINT8(channel->receiveData);
296 Cmd = (value & 0xf0) >> 4;
297 Sp = (value & 0x0c) >> 2;
298 cbChId = (value & 0x03) >> 0;
300 if (Cmd == CAPABILITY_REQUEST_PDU)
301 return wts_read_drdynvc_capabilities_response(channel, (UINT32)length);
303 if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
305 BOOL haveChannelId = 0;
308 case SOFT_SYNC_REQUEST_PDU:
309 case SOFT_SYNC_RESPONSE_PDU:
310 haveChannelId = FALSE;
313 haveChannelId = TRUE;
319 const unsigned val = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId);
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);
330 DEBUG_DVC(
"ChannelId %" PRIu32
" does not exist.", ChannelId);
337 case CREATE_REQUEST_PDU:
338 return wts_read_drdynvc_create_response(dvc, channel->receiveData, (UINT32)length);
341 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
344 "ChannelId %" PRIu32
" did not open successfully. "
345 "Ignoring DYNVC_DATA_FIRST PDU",
350 return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, (UINT32)length);
353 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
356 "ChannelId %" PRIu32
" did not open successfully. "
357 "Ignoring DYNVC_DATA PDU",
362 return wts_read_drdynvc_data(dvc, channel->receiveData, (UINT32)length);
364 case CLOSE_REQUEST_PDU:
365 wts_read_drdynvc_close_response(dvc);
368 case DATA_FIRST_COMPRESSED_PDU:
369 case DATA_COMPRESSED_PDU:
370 WLog_ERR(TAG,
"Compressed data not handled");
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");
378 case SOFT_SYNC_REQUEST_PDU:
379 WLog_ERR(TAG,
"Not expecting a SoftSyncRequest on the server");
383 WLog_ERR(TAG,
"Cmd %d not recognized.", Cmd);
389 WLog_ERR(TAG,
"received Cmd %d but channel is not ready.", Cmd);
395static int wts_write_variable_uint(
wStream* s, UINT32 val)
403 Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val));
405 else if (val <= 0xFFFF)
408 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val));
413 Stream_Write_UINT32(s, val);
419static void wts_write_drdynvc_header(
wStream* s, BYTE Cmd, UINT32 ChannelId)
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;
432static BOOL wts_write_drdynvc_create_request(
wStream* s, UINT32 ChannelId,
const char* ChannelName)
437 WINPR_ASSERT(ChannelName);
439 wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
440 len = strlen(ChannelName) + 1;
442 if (!Stream_EnsureRemainingCapacity(s, len))
445 Stream_Write(s, ChannelName, len);
449static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId,
const BYTE* data,
450 size_t s, UINT32 flags,
size_t t)
453 const size_t size = s;
454 const size_t totalSize = t;
456 WINPR_ASSERT(channel);
457 WINPR_ASSERT(channel->vcm);
458 WINPR_UNUSED(channelId);
460 if (flags & CHANNEL_FLAG_FIRST)
462 Stream_ResetPosition(channel->receiveData);
465 if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
468 Stream_Write(channel->receiveData, data, size);
470 if (flags & CHANNEL_FLAG_LAST)
472 if (Stream_GetPosition(channel->receiveData) != totalSize)
474 WLog_ERR(TAG,
"read error");
477 if (channel == channel->vcm->drdynvc_channel)
479 ret = wts_read_drdynvc_pdu(channel);
483 const size_t pos = Stream_GetPosition(channel->receiveData);
484 if (pos > UINT32_MAX)
487 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
491 Stream_ResetPosition(channel->receiveData);
497static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId,
const BYTE* data,
498 size_t size, UINT32 flags,
size_t totalSize)
500 rdpMcs* mcs =
nullptr;
502 WINPR_ASSERT(client);
503 WINPR_ASSERT(client->context);
504 WINPR_ASSERT(client->context->rdp);
506 mcs = client->context->rdp->mcs;
509 for (UINT32 i = 0; i < mcs->channelCount; i++)
511 rdpMcsChannel* cur = &mcs->channels[i];
512 if (cur->ChannelId == channelId)
514 rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
517 return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
521 WLog_WARN(TAG,
"unknown channelId %" PRIu16
" ignored", channelId);
526#if defined(WITH_FREERDP_DEPRECATED)
527void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer,
void** fds,
int* fds_count)
533 WINPR_ASSERT(fds_count);
535 fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
539 fds[*fds_count] = fd;
545 if (vcm->drdynvc_channel)
547 fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
551 fds[*fds_count] = fd;
560BOOL WTSVirtualChannelManagerOpen(HANDLE hServer)
567 if (vcm->drdynvc_state == DRDYNVC_STATE_NONE)
569 rdpPeerChannel* channel =
nullptr;
572 vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
573 channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
574 DRDYNVC_SVC_CHANNEL_NAME);
578 BYTE capaBuffer[12] = WINPR_C_ARRAY_INIT;
579 wStream staticS = WINPR_C_ARRAY_INIT;
580 wStream* s = Stream_StaticInit(&staticS, capaBuffer,
sizeof(capaBuffer));
582 vcm->drdynvc_channel = channel;
583 vcm->dvc_spoken_version = 1;
584 Stream_Write_UINT8(s, 0x50);
585 Stream_Write_UINT8(s, 0x00);
586 Stream_Write_UINT16(s, 0x0001);
590 const size_t pos = Stream_GetPosition(s);
591 WINPR_ASSERT(pos <= UINT32_MAX);
593 if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written))
601BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
603 wMessage message = WINPR_C_ARRAY_INIT;
607 if (!hServer || hServer == INVALID_HANDLE_VALUE)
614 if (!WTSVirtualChannelManagerOpen(hServer))
618 while (MessageQueue_Peek(vcm->queue, &message, TRUE))
620 BYTE* buffer =
nullptr;
622 UINT16 channelId = 0;
623 channelId = (UINT16)(UINT_PTR)message.context;
624 buffer = (BYTE*)message.wParam;
625 length = (UINT32)(UINT_PTR)message.lParam;
627 WINPR_ASSERT(vcm->client);
628 WINPR_ASSERT(vcm->client->SendChannelData);
629 if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
643BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
645 return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
648HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
652 return MessageQueue_Event(vcm->queue);
655static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs,
const char* channel_name)
657 if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
660 for (UINT32 index = 0; index < mcs->channelCount; index++)
662 rdpMcsChannel* mchannel = &mcs->channels[index];
663 if (mchannel->joined)
665 if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
673static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs,
const UINT16 channel_id)
675 if (!mcs || !channel_id)
678 WINPR_ASSERT(mcs->channels);
679 for (UINT32 index = 0; index < mcs->channelCount; index++)
681 rdpMcsChannel* mchannel = &mcs->channels[index];
682 if (mchannel->joined)
684 if (mchannel->ChannelId == channel_id)
685 return &mcs->channels[index];
692BOOL WTSIsChannelJoinedByName(freerdp_peer* client,
const char* channel_name)
694 if (!client || !client->context || !client->context->rdp)
697 return (wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) !=
nullptr);
700BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
702 if (!client || !client->context || !client->context->rdp)
705 return (wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) !=
nullptr);
708BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer,
const char* name)
712 if (!vcm || !vcm->rdp)
715 return (wts_get_joined_channel_by_name(vcm->rdp->mcs, name) !=
nullptr);
718BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
722 return vcm->drdynvc_state;
725void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
732 vcm->dvc_creation_status = cb;
733 vcm->dvc_creation_status_userdata = userdata;
736UINT16 WTSChannelGetId(freerdp_peer* client,
const char* channel_name)
738 rdpMcsChannel* channel =
nullptr;
740 WINPR_ASSERT(channel_name);
741 if (!client || !client->context || !client->context->rdp)
744 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
749 return channel->ChannelId;
752UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
754 rdpPeerChannel* channel = hChannelHandle;
756 WINPR_ASSERT(channel);
758 return channel->channelId;
761BOOL WTSChannelSetHandleByName(freerdp_peer* client,
const char* channel_name,
void* handle)
763 rdpMcsChannel* channel =
nullptr;
765 WINPR_ASSERT(channel_name);
766 if (!client || !client->context || !client->context->rdp)
769 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
774 channel->handle = handle;
778BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id,
void* handle)
780 rdpMcsChannel* channel =
nullptr;
782 if (!client || !client->context || !client->context->rdp)
785 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
790 channel->handle = handle;
794void* WTSChannelGetHandleByName(freerdp_peer* client,
const char* channel_name)
796 rdpMcsChannel* channel =
nullptr;
798 WINPR_ASSERT(channel_name);
799 if (!client || !client->context || !client->context->rdp)
802 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
807 return channel->handle;
810void* WTSChannelGetHandleById(freerdp_peer* client, UINT16 channel_id)
812 rdpMcsChannel* channel =
nullptr;
814 if (!client || !client->context || !client->context->rdp)
817 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
822 return channel->handle;
825const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
827 rdpMcsChannel* channel =
nullptr;
829 if (!client || !client->context || !client->context->rdp)
832 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
837 return (
const char*)channel->Name;
840char** WTSGetAcceptedChannelNames(freerdp_peer* client,
size_t* count)
842 rdpMcs* mcs =
nullptr;
843 char** names =
nullptr;
845 if (!client || !client->context || !count)
848 WINPR_ASSERT(client->context->rdp);
849 mcs = client->context->rdp->mcs;
851 *count = mcs->channelCount;
853 names = (
char**)calloc(mcs->channelCount,
sizeof(
char*));
857 for (UINT32 index = 0; index < mcs->channelCount; index++)
859 rdpMcsChannel* mchannel = &mcs->channels[index];
860 names[index] = mchannel->Name;
866INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
868 rdpMcsChannel* channel =
nullptr;
870 if (!client || !client->context || !client->context->rdp)
873 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
878 return (INT64)channel->options;
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)
886 WLog_ERR(
"TODO",
"TODO: implement");
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)
895 WLog_ERR(
"TODO",
"TODO: implement");
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)
905 WLog_ERR(
"TODO",
"TODO: implement");
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)
915 WLog_ERR(
"TODO",
"TODO: implement");
919BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId)
921 WLog_ERR(
"TODO",
"TODO: implement");
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)
930 WLog_ERR(
"TODO",
"TODO: implement");
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)
939 WLog_ERR(
"TODO",
"TODO: implement");
943BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName,
944 WINPR_ATTR_UNUSED DWORD Reserved,
945 WINPR_ATTR_UNUSED DWORD Version,
947 WINPR_ATTR_UNUSED DWORD* pCount)
949 WLog_ERR(
"TODO",
"TODO: implement");
953BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName,
954 WINPR_ATTR_UNUSED DWORD Reserved,
955 WINPR_ATTR_UNUSED DWORD Version,
957 WINPR_ATTR_UNUSED DWORD* pCount)
959 WLog_ERR(
"TODO",
"TODO: implement");
963HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName)
965 WLog_ERR(
"TODO",
"TODO: implement");
966 return INVALID_HANDLE_VALUE;
969static void wts_virtual_channel_manager_free_message(
void* obj)
971 wMessage* msg = (wMessage*)obj;
975 BYTE* buffer = (BYTE*)msg->wParam;
982static void channel_free(rdpPeerChannel* channel)
984 server_channel_common_free(channel);
987static void array_channel_free(
void* ptr)
989 rdpPeerChannel* channel = ptr;
990 channel_free(channel);
993static BOOL dynChannelMatch(
const void* v1,
const void* v2)
995 const UINT32* p1 = (
const UINT32*)v1;
996 const UINT32* p2 = (
const UINT32*)v2;
1000static UINT32 channelId_Hash(
const void* key)
1002 const UINT32* v = (
const UINT32*)key;
1006static void clearHandles(
void)
1008 HashTable_Free(g_ServerHandles);
1009 g_ServerHandles =
nullptr;
1012static BOOL CALLBACK initializeHandles(WINPR_ATTR_UNUSED
PINIT_ONCE once,
1013 WINPR_ATTR_UNUSED PVOID param,
1014 WINPR_ATTR_UNUSED PVOID* context)
1016 WINPR_ASSERT(g_ServerHandles ==
nullptr);
1017 g_ServerHandles = HashTable_New(TRUE);
1018 (void)winpr_atexit(clearHandles);
1019 return g_ServerHandles !=
nullptr;
1026 HashTable_Lock(g_ServerHandles);
1030#ifdef __clang_analyzer__
1031 const BOOL valid = vcm !=
nullptr;
1033 const BOOL valid = (vcm !=
nullptr) && (vcm != INVALID_HANDLE_VALUE);
1037 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1039 HashTable_Free(vcm->dynamicVirtualChannels);
1041 if (vcm->drdynvc_channel)
1044 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1045 vcm->drdynvc_channel =
nullptr;
1048 MessageQueue_Free(vcm->queue);
1051 HashTable_Unlock(g_ServerHandles);
1054HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1056 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1058 rdpContext* context = (rdpContext*)pServerName;
1061 return INVALID_HANDLE_VALUE;
1063 freerdp_peer* client = context->peer;
1067 SetLastError(ERROR_INVALID_DATA);
1068 return INVALID_HANDLE_VALUE;
1071 if (!InitOnceExecuteOnce(&g_HandleInitializer, initializeHandles,
nullptr,
nullptr))
1072 return INVALID_HANDLE_VALUE;
1080 vcm->client = client;
1081 vcm->rdp = context->rdp;
1083 queueCallbacks.
fnObjectFree = wts_virtual_channel_manager_free_message;
1084 vcm->queue = MessageQueue_New(&queueCallbacks);
1089 vcm->dvc_channel_id_seq = 0;
1090 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1092 if (!vcm->dynamicVirtualChannels)
1095 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1099 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1103 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1106 client->ReceiveChannelData = WTSReceiveChannelData;
1108 HashTable_Lock(g_ServerHandles);
1109 vcm->SessionId = g_SessionId++;
1111 HashTable_Insert(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId, (
void*)vcm);
1112 HashTable_Unlock(g_ServerHandles);
1117 HANDLE hServer = (HANDLE)vcm;
1121 wtsCloseVCM(vcm,
false);
1122 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1123 return INVALID_HANDLE_VALUE;
1126HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1128 WLog_ERR(
"TODO",
"TODO: implement");
1129 return INVALID_HANDLE_VALUE;
1132HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1134 return FreeRDP_WTSOpenServerA(pServerName);
1137VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1140 wtsCloseVCM(vcm,
true);
1143BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1144 WINPR_ATTR_UNUSED DWORD Reserved,
1145 WINPR_ATTR_UNUSED DWORD Version,
1147 WINPR_ATTR_UNUSED DWORD* pCount)
1149 WLog_ERR(
"TODO",
"TODO: implement");
1153BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1154 WINPR_ATTR_UNUSED DWORD Reserved,
1155 WINPR_ATTR_UNUSED DWORD Version,
1157 WINPR_ATTR_UNUSED DWORD* pCount)
1159 WLog_ERR(
"TODO",
"TODO: implement");
1163BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1164 WINPR_ATTR_UNUSED DWORD* pLevel,
1165 WINPR_ATTR_UNUSED DWORD Filter,
1167 WINPR_ATTR_UNUSED DWORD* pCount)
1169 WLog_ERR(
"TODO",
"TODO: implement");
1173BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1174 WINPR_ATTR_UNUSED DWORD* pLevel,
1175 WINPR_ATTR_UNUSED DWORD Filter,
1177 WINPR_ATTR_UNUSED DWORD* pCount)
1179 WLog_ERR(
"TODO",
"TODO: implement");
1183BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1184 WINPR_ATTR_UNUSED DWORD Reserved,
1185 WINPR_ATTR_UNUSED DWORD Version,
1187 WINPR_ATTR_UNUSED DWORD* pCount)
1189 WLog_ERR(
"TODO",
"TODO: implement");
1193BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1194 WINPR_ATTR_UNUSED DWORD Reserved,
1195 WINPR_ATTR_UNUSED DWORD Version,
1197 WINPR_ATTR_UNUSED DWORD* pCount)
1199 WLog_ERR(
"TODO",
"TODO: implement");
1203BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1204 WINPR_ATTR_UNUSED DWORD ProcessId,
1205 WINPR_ATTR_UNUSED DWORD ExitCode)
1207 WLog_ERR(
"TODO",
"TODO: implement");
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)
1217 WLog_ERR(
"TODO",
"TODO: implement");
1221BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1222 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1223 DWORD* pBytesReturned)
1225 DWORD BytesReturned = 0;
1232 if (WTSInfoClass == WTSSessionId)
1234 ULONG* pBuffer =
nullptr;
1235 BytesReturned =
sizeof(ULONG);
1236 pBuffer = (ULONG*)malloc(
sizeof(BytesReturned));
1240 SetLastError(g_err_oom);
1244 *pBuffer = vcm->SessionId;
1245 *ppBuffer = (LPSTR)pBuffer;
1246 *pBytesReturned = BytesReturned;
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)
1259 WLog_ERR(
"TODO",
"TODO: implement");
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)
1269 WLog_ERR(
"TODO",
"TODO: implement");
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)
1279 WLog_ERR(
"TODO",
"TODO: implement");
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)
1289 WLog_ERR(
"TODO",
"TODO: implement");
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)
1300 WLog_ERR(
"TODO",
"TODO: implement");
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)
1311 WLog_ERR(
"TODO",
"TODO: implement");
1315BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1316 WINPR_ATTR_UNUSED DWORD SessionId,
1317 WINPR_ATTR_UNUSED BOOL bWait)
1319 WLog_ERR(
"TODO",
"TODO: implement");
1323BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1324 WINPR_ATTR_UNUSED DWORD SessionId,
1325 WINPR_ATTR_UNUSED BOOL bWait)
1327 WLog_ERR(
"TODO",
"TODO: implement");
1331BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1332 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1334 WLog_ERR(
"TODO",
"TODO: implement");
1338BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1339 WINPR_ATTR_UNUSED DWORD EventMask,
1340 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1342 WLog_ERR(
"TODO",
"TODO: implement");
1346static void peer_channel_queue_free_message(
void* obj)
1348 wMessage* msg = (wMessage*)obj;
1353 msg->context =
nullptr;
1357 UINT32 ChannelId, UINT16 index, UINT16 type,
size_t chunkSize,
1360 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1361 queueCallbacks.
fnObjectFree = peer_channel_queue_free_message;
1363 rdpPeerChannel* channel =
1364 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1367 WINPR_ASSERT(client);
1373 channel->channelType = type;
1374 channel->creationStatus =
1375 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1379 channel_free(channel);
1383HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1387 rdpMcs* mcs =
nullptr;
1388 rdpMcsChannel* joined_channel =
nullptr;
1389 freerdp_peer* client =
nullptr;
1390 rdpPeerChannel* channel =
nullptr;
1392 HANDLE hChannelHandle =
nullptr;
1393 rdpContext* context =
nullptr;
1398 SetLastError(ERROR_INVALID_DATA);
1402 client = vcm->client;
1403 WINPR_ASSERT(client);
1405 context = client->context;
1406 WINPR_ASSERT(context);
1407 WINPR_ASSERT(context->rdp);
1408 WINPR_ASSERT(context->settings);
1410 mcs = context->rdp->mcs;
1413 length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1415 if (length > CHANNEL_NAME_LEN)
1417 SetLastError(ERROR_NOT_FOUND);
1422 for (; index < mcs->channelCount; index++)
1424 rdpMcsChannel* mchannel = &mcs->channels[index];
1425 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1427 joined_channel = mchannel;
1432 if (!joined_channel)
1434 SetLastError(ERROR_NOT_FOUND);
1438 channel = (rdpPeerChannel*)joined_channel->handle;
1442 const UINT32 VCChunkSize =
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);
1452 joined_channel->handle = channel;
1455 hChannelHandle = (HANDLE)channel;
1456 return hChannelHandle;
1458 channel_free(channel);
1459 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1463HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1466 rdpPeerChannel* channel =
nullptr;
1467 BOOL joined = FALSE;
1470 if (SessionId == WTS_CURRENT_SESSION)
1473 HashTable_Lock(g_ServerHandles);
1475 g_ServerHandles, (
void*)(UINT_PTR)SessionId);
1480 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1482 HashTable_Unlock(g_ServerHandles);
1483 return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
1486 freerdp_peer* client = vcm->client;
1487 WINPR_ASSERT(client);
1488 WINPR_ASSERT(client->context);
1489 WINPR_ASSERT(client->context->rdp);
1491 rdpMcs* mcs = client->context->rdp->mcs;
1494 for (UINT32 index = 0; index < mcs->channelCount; index++)
1496 rdpMcsChannel* mchannel = &mcs->channels[index];
1497 if (mchannel->joined &&
1498 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1507 SetLastError(ERROR_NOT_FOUND);
1511 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1513 SetLastError(ERROR_NOT_READY);
1517 WINPR_ASSERT(client);
1518 WINPR_ASSERT(client->context);
1519 WINPR_ASSERT(client->context->settings);
1521 const UINT32 VCChunkSize =
1523 channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
1527 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1531 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1532 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1534 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1536 channel_free(channel);
1540 s = Stream_New(
nullptr, 64);
1545 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
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,
1557 Stream_Free(s, TRUE);
1558 HashTable_Unlock(g_ServerHandles);
1562 Stream_Free(s, TRUE);
1564 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1565 HashTable_Unlock(g_ServerHandles);
1567 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1571BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1574 rdpMcs* mcs =
nullptr;
1576 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
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;
1589 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1591 if (channel->index < mcs->channelCount)
1593 rdpMcsChannel* cur = &mcs->channels[channel->index];
1594 rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
1595 channel_free(peerChannel);
1596 cur->handle =
nullptr;
1601 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1604 s = Stream_New(
nullptr, 8);
1608 WLog_ERR(TAG,
"Stream_New failed!");
1613 wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
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);
1622 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1629BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut,
1630 PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
1632 BYTE* buffer =
nullptr;
1633 wMessage message = WINPR_C_ARRAY_INIT;
1634 wtsChannelMessage* messageCtx =
nullptr;
1635 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1637 WINPR_ASSERT(channel);
1639 if (!MessageQueue_Peek(channel->queue, &message, FALSE))
1641 SetLastError(ERROR_NO_DATA);
1646 messageCtx = message.context;
1648 if (messageCtx ==
nullptr)
1651 buffer = (BYTE*)(messageCtx + 1);
1652 *pBytesRead = messageCtx->length - messageCtx->offset;
1654 if (Buffer ==
nullptr || BufferSize == 0)
1659 if (*pBytesRead > BufferSize)
1660 *pBytesRead = BufferSize;
1662 CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
1663 messageCtx->offset += *pBytesRead;
1665 if (messageCtx->offset >= messageCtx->length)
1667 const int rc = MessageQueue_Peek(channel->queue, &message, TRUE);
1668 peer_channel_queue_free_message(&message);
1676BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength,
1677 PULONG pBytesWritten)
1683 BYTE* buffer =
nullptr;
1684 size_t totalWritten = 0;
1685 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1691 EnterCriticalSection(&channel->writeLock);
1692 WINPR_ASSERT(channel->vcm);
1693 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1695 buffer = (BYTE*)malloc(uLength);
1699 SetLastError(g_err_oom);
1703 CopyMemory(buffer, Buffer, uLength);
1704 totalWritten = uLength;
1705 if (!wts_queue_send_item(channel, buffer, uLength))
1708 else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
1710 DEBUG_DVC(
"drdynvc not ready");
1717 size_t Length = uLength;
1720 s = Stream_New(
nullptr, DVC_MAX_DATA_PDU_SIZE);
1724 WLog_ERR(TAG,
"Stream_New failed!");
1725 SetLastError(g_err_oom);
1729 buffer = Stream_Buffer(s);
1730 Stream_Seek_UINT8(s);
1731 cbChId = wts_write_variable_uint(s, channel->channelId);
1733 if (first && (Length > Stream_GetRemainingLength(s)))
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;
1740 buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
1744 size_t written = Stream_GetRemainingLength(s);
1746 if (written > Length)
1749 Stream_Write(s, Buffer, written);
1750 const size_t length = Stream_GetPosition(s);
1751 Stream_Free(s, FALSE);
1752 if (length > UINT32_MAX)
1756 totalWritten += written;
1757 if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
1763 *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten);
1767 LeaveCriticalSection(&channel->writeLock);
1771BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1773 WLog_ERR(
"TODO",
"TODO: implement");
1777BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1779 WLog_ERR(
"TODO",
"TODO: implement");
1783BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
1784 PVOID* ppBuffer, DWORD* pBytesReturned)
1786 void* pfd =
nullptr;
1788 void* fds[10] = WINPR_C_ARRAY_INIT;
1789 HANDLE hEvent =
nullptr;
1791 BOOL status = FALSE;
1792 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1794 WINPR_ASSERT(channel);
1796 switch ((UINT32)WtsVirtualClass)
1798 case WTSVirtualFileHandle:
1799 hEvent = MessageQueue_Event(channel->queue);
1800 pfd = GetEventWaitObject(hEvent);
1804 fds[fds_count] = pfd;
1808 *ppBuffer = malloc(
sizeof(
void*));
1812 SetLastError(g_err_oom);
1816 CopyMemory(*ppBuffer, (
void*)&fds[0],
sizeof(
void*));
1817 *pBytesReturned =
sizeof(
void*);
1823 case WTSVirtualEventHandle:
1824 hEvent = MessageQueue_Event(channel->queue);
1826 *ppBuffer = malloc(
sizeof(HANDLE));
1830 SetLastError(g_err_oom);
1834 CopyMemory(*ppBuffer, (
void*)&hEvent,
sizeof(HANDLE));
1835 *pBytesReturned =
sizeof(
void*);
1841 case WTSVirtualChannelReady:
1842 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1849 switch (channel->dvc_open_state)
1851 case DVC_OPEN_STATE_NONE:
1856 case DVC_OPEN_STATE_SUCCEEDED:
1862 *ppBuffer =
nullptr;
1863 *pBytesReturned = 0;
1868 *ppBuffer = malloc(
sizeof(BOOL));
1872 SetLastError(g_err_oom);
1877 CopyMemory(*ppBuffer, &bval,
sizeof(BOOL));
1878 *pBytesReturned =
sizeof(BOOL);
1882 case WTSVirtualChannelOpenStatus:
1884 INT32 value = channel->creationStatus;
1887 *ppBuffer = malloc(
sizeof(value));
1890 SetLastError(g_err_oom);
1895 CopyMemory(*ppBuffer, &value,
sizeof(value));
1896 *pBytesReturned =
sizeof(value);
1907VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
1912BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1913 WINPR_ATTR_UNUSED PVOID pMemory,
1914 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1916 WLog_ERR(
"TODO",
"TODO: implement");
1920BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1921 WINPR_ATTR_UNUSED PVOID pMemory,
1922 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1924 WLog_ERR(
"TODO",
"TODO: implement");
1928BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd,
1929 WINPR_ATTR_UNUSED DWORD dwFlags)
1931 WLog_ERR(
"TODO",
"TODO: implement");
1935BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd)
1937 WLog_ERR(
"TODO",
"TODO: implement");
1941BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1942 WINPR_ATTR_UNUSED HWND hWnd,
1943 WINPR_ATTR_UNUSED DWORD dwFlags)
1945 WLog_ERR(
"TODO",
"TODO: implement");
1949BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1950 WINPR_ATTR_UNUSED HWND hWnd)
1952 WLog_ERR(
"TODO",
"TODO: implement");
1956BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId,
1957 WINPR_ATTR_UNUSED PHANDLE phToken)
1959 WLog_ERR(
"TODO",
"TODO: implement");
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)
1969 WLog_ERR(
"TODO",
"TODO: implement");
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)
1979 WLog_ERR(
"TODO",
"TODO: implement");
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)
1989 WLog_ERR(
"TODO",
"TODO: implement");
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)
1999 WLog_ERR(
"TODO",
"TODO: implement");
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,
2009 WLog_ERR(
"TODO",
"TODO: implement");
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,
2019 WLog_ERR(
"TODO",
"TODO: implement");
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,
2028 WINPR_ATTR_UNUSED DWORD flag)
2030 WLog_ERR(
"TODO",
"TODO: implement");
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,
2039 WINPR_ATTR_UNUSED DWORD flag)
2041 WLog_ERR(
"TODO",
"TODO: implement");
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)
2051 WLog_ERR(
"TODO",
"TODO: implement");
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)
2061 WLog_ERR(
"TODO",
"TODO: implement");
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)
2072 WLog_ERR(
"TODO",
"TODO: implement");
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)
2083 WLog_ERR(
"TODO",
"TODO: implement");
2087BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable)
2089 WLog_ERR(
"TODO",
"TODO: implement");
2093BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled)
2095 WLog_ERR(
"TODO",
"TODO: implement");
2099BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId)
2101 WLog_ERR(
"TODO",
"TODO: implement");
2105DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(
void)
2107 WLog_ERR(
"TODO",
"TODO: implement");
2110BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer)
2112 WLog_ERR(
"TODO",
"TODO: implement");
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)
2120 WLog_ERR(
"TODO",
"TODO: implement");
2124void server_channel_common_free(rdpPeerChannel* channel)
2128 MessageQueue_Free(channel->queue);
2129 Stream_Free(channel->receiveData, TRUE);
2130 DeleteCriticalSection(&channel->writeLock);
2134rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
2135 size_t chunkSize,
const wObject* callback,
2138 rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1,
sizeof(rdpPeerChannel));
2142 InitializeCriticalSection(&channel->writeLock);
2144 channel->receiveData = Stream_New(
nullptr, chunkSize);
2145 if (!channel->receiveData)
2148 channel->queue = MessageQueue_New(callback);
2149 if (!channel->queue)
2152 channel->index = index;
2153 channel->client = client;
2154 channel->channelId = channelId;
2155 strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
2158 WINPR_PRAGMA_DIAG_PUSH
2159 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2160 server_channel_common_free(channel);
2161 WINPR_PRAGMA_DIAG_POP
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.
OBJECT_FREE_FN fnObjectFree
OBJECT_EQUALS_FN fnObjectEquals