22#include <freerdp/config.h>
29#include <winpr/wtypes.h>
31#include <winpr/synch.h>
32#include <winpr/stream.h>
33#include <winpr/assert.h>
34#include <winpr/cast.h>
36#include <freerdp/log.h>
37#include <freerdp/constants.h>
38#include <freerdp/server/channels.h>
39#include <freerdp/channels/drdynvc.h>
40#include <freerdp/utils/drdynvc.h>
46#define TAG FREERDP_TAG("core.server")
48#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
50#define DEBUG_DVC(...) \
56#define DVC_MAX_DATA_PDU_SIZE 1600
66static const DWORD g_err_oom = WINPR_CXX_COMPAT_CAST(DWORD, E_OUTOFMEMORY);
68static DWORD g_SessionId = 1;
69static wHashTable* g_ServerHandles =
nullptr;
74 return HashTable_GetItemValue(vcm->dynamicVirtualChannels, &ChannelId);
77static BOOL wts_queue_receive_data(rdpPeerChannel* channel,
const BYTE* Buffer, UINT32 Length)
79 BYTE* buffer =
nullptr;
80 wtsChannelMessage* messageCtx =
nullptr;
82 WINPR_ASSERT(channel);
83 messageCtx = (wtsChannelMessage*)malloc(
sizeof(wtsChannelMessage) + Length);
88 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
89 messageCtx->channelId = (UINT16)channel->channelId;
90 messageCtx->length = Length;
91 messageCtx->offset = 0;
92 buffer = (BYTE*)(messageCtx + 1);
93 CopyMemory(buffer, Buffer, Length);
94 return MessageQueue_Post(channel->queue, messageCtx, 0,
nullptr,
nullptr);
97static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
99 BYTE* buffer =
nullptr;
102 WINPR_ASSERT(channel);
103 WINPR_ASSERT(channel->vcm);
107 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
108 const UINT16 channelId = (UINT16)channel->channelId;
109 return MessageQueue_Post(channel->vcm->queue, (
void*)(UINT_PTR)channelId, 0, (
void*)buffer,
110 (
void*)(UINT_PTR)length);
113static unsigned wts_read_variable_uint(
wStream* s,
int cbLen, UINT32* val)
120 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
123 Stream_Read_UINT8(s, *val);
127 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
130 Stream_Read_UINT16(s, *val);
134 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
137 Stream_Read_UINT32(s, *val);
141 WLog_ERR(TAG,
"invalid wts variable uint len %d", cbLen);
146static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
150 WINPR_ASSERT(channel);
151 WINPR_ASSERT(channel->vcm);
155 Stream_Seek_UINT8(channel->receiveData);
156 Stream_Read_UINT16(channel->receiveData, Version);
157 DEBUG_DVC(
"Version: %" PRIu16
"", Version);
161 WLog_ERR(TAG,
"invalid version %" PRIu16
" for DRDYNVC", Version);
166 vcm->drdynvc_state = DRDYNVC_STATE_READY;
169 vcm->dvc_spoken_version = MAX(Version, 1);
171 return SetEvent(MessageQueue_Event(vcm->queue));
174static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel,
wStream* s, UINT32 length)
176 UINT32 CreationStatus = 0;
179 WINPR_ASSERT(channel);
184 Stream_Read_UINT32(s, CreationStatus);
186 if ((INT32)CreationStatus < 0)
188 DEBUG_DVC(
"ChannelId %" PRIu32
" creation failed (%" PRId32
")", channel->channelId,
189 (INT32)CreationStatus);
190 channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
194 DEBUG_DVC(
"ChannelId %" PRIu32
" creation succeeded", channel->channelId);
195 channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
198 channel->creationStatus = (INT32)CreationStatus;
199 IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata,
200 channel->channelId, (INT32)CreationStatus);
202 WLog_ERR(TAG,
"vcm->dvc_creation_status failed!");
207static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel,
wStream* s,
int cbLen,
210 WINPR_ASSERT(channel);
212 const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
221 if (length > channel->dvc_total_length)
224 Stream_SetPosition(channel->receiveData, 0);
226 if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
229 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
233static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel,
wStream* s, UINT32 length)
237 WINPR_ASSERT(channel);
239 if (channel->dvc_total_length > 0)
241 if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
243 channel->dvc_total_length = 0;
244 WLog_ERR(TAG,
"incorrect fragment data, discarded.");
248 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
250 if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
252 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
253 channel->dvc_total_length);
254 channel->dvc_total_length = 0;
261 ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length);
267static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
269 WINPR_ASSERT(channel);
270 DEBUG_DVC(
"ChannelId %" PRIu32
" close response", channel->channelId);
271 channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
272 MessageQueue_PostQuit(channel->queue, 0);
275static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
280 UINT32 ChannelId = 0;
281 rdpPeerChannel* dvc =
nullptr;
283 WINPR_ASSERT(channel);
284 WINPR_ASSERT(channel->vcm);
286 size_t length = Stream_GetPosition(channel->receiveData);
288 if ((length < 1) || (length > UINT32_MAX))
291 Stream_SetPosition(channel->receiveData, 0);
292 const UINT8 value = Stream_Get_UINT8(channel->receiveData);
294 Cmd = (value & 0xf0) >> 4;
295 Sp = (value & 0x0c) >> 2;
296 cbChId = (value & 0x03) >> 0;
298 if (Cmd == CAPABILITY_REQUEST_PDU)
299 return wts_read_drdynvc_capabilities_response(channel, (UINT32)length);
301 if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
303 BOOL haveChannelId = 0;
306 case SOFT_SYNC_REQUEST_PDU:
307 case SOFT_SYNC_RESPONSE_PDU:
308 haveChannelId = FALSE;
311 haveChannelId = TRUE;
317 const unsigned val = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId);
323 DEBUG_DVC(
"Cmd %s ChannelId %" PRIu32
" length %" PRIuz
"",
324 drdynvc_get_packet_type(Cmd), ChannelId, length);
325 dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
328 DEBUG_DVC(
"ChannelId %" PRIu32
" does not exist.", ChannelId);
335 case CREATE_REQUEST_PDU:
336 return wts_read_drdynvc_create_response(dvc, channel->receiveData, (UINT32)length);
339 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
342 "ChannelId %" PRIu32
" did not open successfully. "
343 "Ignoring DYNVC_DATA_FIRST PDU",
348 return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, (UINT32)length);
351 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
354 "ChannelId %" PRIu32
" did not open successfully. "
355 "Ignoring DYNVC_DATA PDU",
360 return wts_read_drdynvc_data(dvc, channel->receiveData, (UINT32)length);
362 case CLOSE_REQUEST_PDU:
363 wts_read_drdynvc_close_response(dvc);
366 case DATA_FIRST_COMPRESSED_PDU:
367 case DATA_COMPRESSED_PDU:
368 WLog_ERR(TAG,
"Compressed data not handled");
371 case SOFT_SYNC_RESPONSE_PDU:
372 WLog_ERR(TAG,
"SoftSync response not handled yet(and rather strange to receive "
373 "that packet as our code doesn't send SoftSync requests");
376 case SOFT_SYNC_REQUEST_PDU:
377 WLog_ERR(TAG,
"Not expecting a SoftSyncRequest on the server");
381 WLog_ERR(TAG,
"Cmd %d not recognized.", Cmd);
387 WLog_ERR(TAG,
"received Cmd %d but channel is not ready.", Cmd);
393static int wts_write_variable_uint(
wStream* s, UINT32 val)
401 Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val));
403 else if (val <= 0xFFFF)
406 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val));
411 Stream_Write_UINT32(s, val);
417static void wts_write_drdynvc_header(
wStream* s, BYTE Cmd, UINT32 ChannelId)
424 Stream_GetPointer(s, bm);
425 Stream_Seek_UINT8(s);
426 cbChId = wts_write_variable_uint(s, ChannelId);
427 *bm = (((Cmd & 0x0F) << 4) | cbChId) & 0xFF;
430static BOOL wts_write_drdynvc_create_request(
wStream* s, UINT32 ChannelId,
const char* ChannelName)
435 WINPR_ASSERT(ChannelName);
437 wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
438 len = strlen(ChannelName) + 1;
440 if (!Stream_EnsureRemainingCapacity(s, len))
443 Stream_Write(s, ChannelName, len);
447static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId,
const BYTE* data,
448 size_t s, UINT32 flags,
size_t t)
451 const size_t size = s;
452 const size_t totalSize = t;
454 WINPR_ASSERT(channel);
455 WINPR_ASSERT(channel->vcm);
456 WINPR_UNUSED(channelId);
458 if (flags & CHANNEL_FLAG_FIRST)
460 Stream_SetPosition(channel->receiveData, 0);
463 if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
466 Stream_Write(channel->receiveData, data, size);
468 if (flags & CHANNEL_FLAG_LAST)
470 if (Stream_GetPosition(channel->receiveData) != totalSize)
472 WLog_ERR(TAG,
"read error");
475 if (channel == channel->vcm->drdynvc_channel)
477 ret = wts_read_drdynvc_pdu(channel);
481 const size_t pos = Stream_GetPosition(channel->receiveData);
482 if (pos > UINT32_MAX)
485 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
489 Stream_SetPosition(channel->receiveData, 0);
495static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId,
const BYTE* data,
496 size_t size, UINT32 flags,
size_t totalSize)
498 rdpMcs* mcs =
nullptr;
500 WINPR_ASSERT(client);
501 WINPR_ASSERT(client->context);
502 WINPR_ASSERT(client->context->rdp);
504 mcs = client->context->rdp->mcs;
507 for (UINT32 i = 0; i < mcs->channelCount; i++)
509 rdpMcsChannel* cur = &mcs->channels[i];
510 if (cur->ChannelId == channelId)
512 rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
515 return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
519 WLog_WARN(TAG,
"unknown channelId %" PRIu16
" ignored", channelId);
524#if defined(WITH_FREERDP_DEPRECATED)
525void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer,
void** fds,
int* fds_count)
531 WINPR_ASSERT(fds_count);
533 fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
537 fds[*fds_count] = fd;
543 if (vcm->drdynvc_channel)
545 fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
549 fds[*fds_count] = fd;
558BOOL WTSVirtualChannelManagerOpen(HANDLE hServer)
565 if (vcm->drdynvc_state == DRDYNVC_STATE_NONE)
567 rdpPeerChannel* channel =
nullptr;
570 vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
571 channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
572 DRDYNVC_SVC_CHANNEL_NAME);
576 BYTE capaBuffer[12] = WINPR_C_ARRAY_INIT;
577 wStream staticS = WINPR_C_ARRAY_INIT;
578 wStream* s = Stream_StaticInit(&staticS, capaBuffer,
sizeof(capaBuffer));
580 vcm->drdynvc_channel = channel;
581 vcm->dvc_spoken_version = 1;
582 Stream_Write_UINT8(s, 0x50);
583 Stream_Write_UINT8(s, 0x00);
584 Stream_Write_UINT16(s, 0x0001);
588 const size_t pos = Stream_GetPosition(s);
589 WINPR_ASSERT(pos <= UINT32_MAX);
591 if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written))
599BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
601 wMessage message = WINPR_C_ARRAY_INIT;
605 if (!hServer || hServer == INVALID_HANDLE_VALUE)
612 if (!WTSVirtualChannelManagerOpen(hServer))
616 while (MessageQueue_Peek(vcm->queue, &message, TRUE))
618 BYTE* buffer =
nullptr;
620 UINT16 channelId = 0;
621 channelId = (UINT16)(UINT_PTR)message.context;
622 buffer = (BYTE*)message.wParam;
623 length = (UINT32)(UINT_PTR)message.lParam;
625 WINPR_ASSERT(vcm->client);
626 WINPR_ASSERT(vcm->client->SendChannelData);
627 if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
641BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
643 return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
646HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
650 return MessageQueue_Event(vcm->queue);
653static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs,
const char* channel_name)
655 if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
658 for (UINT32 index = 0; index < mcs->channelCount; index++)
660 rdpMcsChannel* mchannel = &mcs->channels[index];
661 if (mchannel->joined)
663 if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
671static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs,
const UINT16 channel_id)
673 if (!mcs || !channel_id)
676 WINPR_ASSERT(mcs->channels);
677 for (UINT32 index = 0; index < mcs->channelCount; index++)
679 rdpMcsChannel* mchannel = &mcs->channels[index];
680 if (mchannel->joined)
682 if (mchannel->ChannelId == channel_id)
683 return &mcs->channels[index];
690BOOL WTSIsChannelJoinedByName(freerdp_peer* client,
const char* channel_name)
692 if (!client || !client->context || !client->context->rdp)
695 return (wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) !=
nullptr);
698BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
700 if (!client || !client->context || !client->context->rdp)
703 return (wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) !=
nullptr);
706BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer,
const char* name)
710 if (!vcm || !vcm->rdp)
713 return (wts_get_joined_channel_by_name(vcm->rdp->mcs, name) !=
nullptr);
716BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
720 return vcm->drdynvc_state;
723void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
730 vcm->dvc_creation_status = cb;
731 vcm->dvc_creation_status_userdata = userdata;
734UINT16 WTSChannelGetId(freerdp_peer* client,
const char* channel_name)
736 rdpMcsChannel* channel =
nullptr;
738 WINPR_ASSERT(channel_name);
739 if (!client || !client->context || !client->context->rdp)
742 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
747 return channel->ChannelId;
750UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
752 rdpPeerChannel* channel = hChannelHandle;
754 WINPR_ASSERT(channel);
756 return channel->channelId;
759BOOL WTSChannelSetHandleByName(freerdp_peer* client,
const char* channel_name,
void* handle)
761 rdpMcsChannel* channel =
nullptr;
763 WINPR_ASSERT(channel_name);
764 if (!client || !client->context || !client->context->rdp)
767 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
772 channel->handle = handle;
776BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id,
void* handle)
778 rdpMcsChannel* channel =
nullptr;
780 if (!client || !client->context || !client->context->rdp)
783 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
788 channel->handle = handle;
792void* WTSChannelGetHandleByName(freerdp_peer* client,
const char* channel_name)
794 rdpMcsChannel* channel =
nullptr;
796 WINPR_ASSERT(channel_name);
797 if (!client || !client->context || !client->context->rdp)
800 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
805 return channel->handle;
808void* WTSChannelGetHandleById(freerdp_peer* client, UINT16 channel_id)
810 rdpMcsChannel* channel =
nullptr;
812 if (!client || !client->context || !client->context->rdp)
815 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
820 return channel->handle;
823const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
825 rdpMcsChannel* channel =
nullptr;
827 if (!client || !client->context || !client->context->rdp)
830 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
835 return (
const char*)channel->Name;
838char** WTSGetAcceptedChannelNames(freerdp_peer* client,
size_t* count)
840 rdpMcs* mcs =
nullptr;
841 char** names =
nullptr;
843 if (!client || !client->context || !count)
846 WINPR_ASSERT(client->context->rdp);
847 mcs = client->context->rdp->mcs;
849 *count = mcs->channelCount;
851 names = (
char**)calloc(mcs->channelCount,
sizeof(
char*));
855 for (UINT32 index = 0; index < mcs->channelCount; index++)
857 rdpMcsChannel* mchannel = &mcs->channels[index];
858 names[index] = mchannel->Name;
864INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
866 rdpMcsChannel* channel =
nullptr;
868 if (!client || !client->context || !client->context->rdp)
871 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
876 return (INT64)channel->options;
879BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
880 WINPR_ATTR_UNUSED ULONG TargetLogonId,
881 WINPR_ATTR_UNUSED BYTE HotkeyVk,
882 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
884 WLog_ERR(
"TODO",
"TODO: implement");
888BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
889 WINPR_ATTR_UNUSED ULONG TargetLogonId,
890 WINPR_ATTR_UNUSED BYTE HotkeyVk,
891 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
893 WLog_ERR(
"TODO",
"TODO: implement");
897BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
898 WINPR_ATTR_UNUSED ULONG TargetLogonId,
899 WINPR_ATTR_UNUSED BYTE HotkeyVk,
900 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
901 WINPR_ATTR_UNUSED DWORD flags)
903 WLog_ERR(
"TODO",
"TODO: implement");
907BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
908 WINPR_ATTR_UNUSED ULONG TargetLogonId,
909 WINPR_ATTR_UNUSED BYTE HotkeyVk,
910 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
911 WINPR_ATTR_UNUSED DWORD flags)
913 WLog_ERR(
"TODO",
"TODO: implement");
917BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId)
919 WLog_ERR(
"TODO",
"TODO: implement");
923BOOL WINAPI FreeRDP_WTSConnectSessionW(WINPR_ATTR_UNUSED ULONG LogonId,
924 WINPR_ATTR_UNUSED ULONG TargetLogonId,
925 WINPR_ATTR_UNUSED PWSTR pPassword,
926 WINPR_ATTR_UNUSED BOOL bWait)
928 WLog_ERR(
"TODO",
"TODO: implement");
932BOOL WINAPI FreeRDP_WTSConnectSessionA(WINPR_ATTR_UNUSED ULONG LogonId,
933 WINPR_ATTR_UNUSED ULONG TargetLogonId,
934 WINPR_ATTR_UNUSED PSTR pPassword,
935 WINPR_ATTR_UNUSED BOOL bWait)
937 WLog_ERR(
"TODO",
"TODO: implement");
941BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName,
942 WINPR_ATTR_UNUSED DWORD Reserved,
943 WINPR_ATTR_UNUSED DWORD Version,
945 WINPR_ATTR_UNUSED DWORD* pCount)
947 WLog_ERR(
"TODO",
"TODO: implement");
951BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName,
952 WINPR_ATTR_UNUSED DWORD Reserved,
953 WINPR_ATTR_UNUSED DWORD Version,
955 WINPR_ATTR_UNUSED DWORD* pCount)
957 WLog_ERR(
"TODO",
"TODO: implement");
961HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName)
963 WLog_ERR(
"TODO",
"TODO: implement");
964 return INVALID_HANDLE_VALUE;
967static void wts_virtual_channel_manager_free_message(
void* obj)
969 wMessage* msg = (wMessage*)obj;
973 BYTE* buffer = (BYTE*)msg->wParam;
980static void channel_free(rdpPeerChannel* channel)
982 server_channel_common_free(channel);
985static void array_channel_free(
void* ptr)
987 rdpPeerChannel* channel = ptr;
988 channel_free(channel);
991static BOOL dynChannelMatch(
const void* v1,
const void* v2)
993 const UINT32* p1 = (
const UINT32*)v1;
994 const UINT32* p2 = (
const UINT32*)v2;
998static UINT32 channelId_Hash(
const void* key)
1000 const UINT32* v = (
const UINT32*)key;
1004HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1006 rdpContext* context =
nullptr;
1007 freerdp_peer* client =
nullptr;
1009 HANDLE hServer = INVALID_HANDLE_VALUE;
1010 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1012 context = (rdpContext*)pServerName;
1015 return INVALID_HANDLE_VALUE;
1017 client = context->peer;
1021 SetLastError(ERROR_INVALID_DATA);
1022 return INVALID_HANDLE_VALUE;
1028 goto error_vcm_alloc;
1030 vcm->client = client;
1031 vcm->rdp = context->rdp;
1032 vcm->SessionId = g_SessionId++;
1034 if (!g_ServerHandles)
1036 g_ServerHandles = HashTable_New(TRUE);
1038 if (!g_ServerHandles)
1042 if (!HashTable_Insert(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId, (
void*)vcm))
1045 queueCallbacks.
fnObjectFree = wts_virtual_channel_manager_free_message;
1046 vcm->queue = MessageQueue_New(&queueCallbacks);
1051 vcm->dvc_channel_id_seq = 0;
1052 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1054 if (!vcm->dynamicVirtualChannels)
1055 goto error_dynamicVirtualChannels;
1057 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1058 goto error_hashFunction;
1061 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1065 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1068 client->ReceiveChannelData = WTSReceiveChannelData;
1069 hServer = (HANDLE)vcm;
1073 HashTable_Free(vcm->dynamicVirtualChannels);
1074error_dynamicVirtualChannels:
1075 MessageQueue_Free(vcm->queue);
1077 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1081 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1082 return INVALID_HANDLE_VALUE;
1085HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1087 WLog_ERR(
"TODO",
"TODO: implement");
1088 return INVALID_HANDLE_VALUE;
1091HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1093 return FreeRDP_WTSOpenServerA(pServerName);
1096VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1101 if (vcm && (vcm != INVALID_HANDLE_VALUE))
1103 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1105 HashTable_Free(vcm->dynamicVirtualChannels);
1107 if (vcm->drdynvc_channel)
1109 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1110 vcm->drdynvc_channel =
nullptr;
1113 MessageQueue_Free(vcm->queue);
1118BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1119 WINPR_ATTR_UNUSED DWORD Reserved,
1120 WINPR_ATTR_UNUSED DWORD Version,
1122 WINPR_ATTR_UNUSED DWORD* pCount)
1124 WLog_ERR(
"TODO",
"TODO: implement");
1128BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1129 WINPR_ATTR_UNUSED DWORD Reserved,
1130 WINPR_ATTR_UNUSED DWORD Version,
1132 WINPR_ATTR_UNUSED DWORD* pCount)
1134 WLog_ERR(
"TODO",
"TODO: implement");
1138BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1139 WINPR_ATTR_UNUSED DWORD* pLevel,
1140 WINPR_ATTR_UNUSED DWORD Filter,
1142 WINPR_ATTR_UNUSED DWORD* pCount)
1144 WLog_ERR(
"TODO",
"TODO: implement");
1148BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1149 WINPR_ATTR_UNUSED DWORD* pLevel,
1150 WINPR_ATTR_UNUSED DWORD Filter,
1152 WINPR_ATTR_UNUSED DWORD* pCount)
1154 WLog_ERR(
"TODO",
"TODO: implement");
1158BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1159 WINPR_ATTR_UNUSED DWORD Reserved,
1160 WINPR_ATTR_UNUSED DWORD Version,
1162 WINPR_ATTR_UNUSED DWORD* pCount)
1164 WLog_ERR(
"TODO",
"TODO: implement");
1168BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1169 WINPR_ATTR_UNUSED DWORD Reserved,
1170 WINPR_ATTR_UNUSED DWORD Version,
1172 WINPR_ATTR_UNUSED DWORD* pCount)
1174 WLog_ERR(
"TODO",
"TODO: implement");
1178BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1179 WINPR_ATTR_UNUSED DWORD ProcessId,
1180 WINPR_ATTR_UNUSED DWORD ExitCode)
1182 WLog_ERR(
"TODO",
"TODO: implement");
1186BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1187 WINPR_ATTR_UNUSED DWORD SessionId,
1188 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1189 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1190 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1192 WLog_ERR(
"TODO",
"TODO: implement");
1196BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1197 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1198 DWORD* pBytesReturned)
1200 DWORD BytesReturned = 0;
1207 if (WTSInfoClass == WTSSessionId)
1209 ULONG* pBuffer =
nullptr;
1210 BytesReturned =
sizeof(ULONG);
1211 pBuffer = (ULONG*)malloc(
sizeof(BytesReturned));
1215 SetLastError(g_err_oom);
1219 *pBuffer = vcm->SessionId;
1220 *ppBuffer = (LPSTR)pBuffer;
1221 *pBytesReturned = BytesReturned;
1228BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1229 WINPR_ATTR_UNUSED LPWSTR pUserName,
1230 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1231 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1232 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1234 WLog_ERR(
"TODO",
"TODO: implement");
1238BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1239 WINPR_ATTR_UNUSED LPSTR pUserName,
1240 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1241 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1242 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1244 WLog_ERR(
"TODO",
"TODO: implement");
1248BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1249 WINPR_ATTR_UNUSED LPWSTR pUserName,
1250 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1251 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1252 WINPR_ATTR_UNUSED DWORD DataLength)
1254 WLog_ERR(
"TODO",
"TODO: implement");
1258BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1259 WINPR_ATTR_UNUSED LPSTR pUserName,
1260 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1261 WINPR_ATTR_UNUSED LPSTR pBuffer,
1262 WINPR_ATTR_UNUSED DWORD DataLength)
1264 WLog_ERR(
"TODO",
"TODO: implement");
1269FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1270 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1271 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1272 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1273 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1275 WLog_ERR(
"TODO",
"TODO: implement");
1280FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1281 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1282 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1283 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1284 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1286 WLog_ERR(
"TODO",
"TODO: implement");
1290BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1291 WINPR_ATTR_UNUSED DWORD SessionId,
1292 WINPR_ATTR_UNUSED BOOL bWait)
1294 WLog_ERR(
"TODO",
"TODO: implement");
1298BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1299 WINPR_ATTR_UNUSED DWORD SessionId,
1300 WINPR_ATTR_UNUSED BOOL bWait)
1302 WLog_ERR(
"TODO",
"TODO: implement");
1306BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1307 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1309 WLog_ERR(
"TODO",
"TODO: implement");
1313BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1314 WINPR_ATTR_UNUSED DWORD EventMask,
1315 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1317 WLog_ERR(
"TODO",
"TODO: implement");
1321static void peer_channel_queue_free_message(
void* obj)
1323 wMessage* msg = (wMessage*)obj;
1328 msg->context =
nullptr;
1332 UINT32 ChannelId, UINT16 index, UINT16 type,
size_t chunkSize,
1335 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1336 queueCallbacks.
fnObjectFree = peer_channel_queue_free_message;
1338 rdpPeerChannel* channel =
1339 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1342 WINPR_ASSERT(client);
1348 channel->channelType = type;
1349 channel->creationStatus =
1350 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1354 channel_free(channel);
1358HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1362 rdpMcs* mcs =
nullptr;
1363 rdpMcsChannel* joined_channel =
nullptr;
1364 freerdp_peer* client =
nullptr;
1365 rdpPeerChannel* channel =
nullptr;
1367 HANDLE hChannelHandle =
nullptr;
1368 rdpContext* context =
nullptr;
1373 SetLastError(ERROR_INVALID_DATA);
1377 client = vcm->client;
1378 WINPR_ASSERT(client);
1380 context = client->context;
1381 WINPR_ASSERT(context);
1382 WINPR_ASSERT(context->rdp);
1383 WINPR_ASSERT(context->settings);
1385 mcs = context->rdp->mcs;
1388 length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1390 if (length > CHANNEL_NAME_LEN)
1392 SetLastError(ERROR_NOT_FOUND);
1397 for (; index < mcs->channelCount; index++)
1399 rdpMcsChannel* mchannel = &mcs->channels[index];
1400 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1402 joined_channel = mchannel;
1407 if (!joined_channel)
1409 SetLastError(ERROR_NOT_FOUND);
1413 channel = (rdpPeerChannel*)joined_channel->handle;
1417 const UINT32 VCChunkSize =
1420 WINPR_ASSERT(index <= UINT16_MAX);
1421 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1422 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName);
1427 joined_channel->handle = channel;
1430 hChannelHandle = (HANDLE)channel;
1431 return hChannelHandle;
1433 channel_free(channel);
1434 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1438HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1441 rdpMcs* mcs =
nullptr;
1442 BOOL joined = FALSE;
1443 freerdp_peer* client =
nullptr;
1444 rdpPeerChannel* channel =
nullptr;
1448 if (SessionId == WTS_CURRENT_SESSION)
1452 (
void*)(UINT_PTR)SessionId);
1457 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1459 return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
1462 client = vcm->client;
1463 mcs = client->context->rdp->mcs;
1465 for (UINT32 index = 0; index < mcs->channelCount; index++)
1467 rdpMcsChannel* mchannel = &mcs->channels[index];
1468 if (mchannel->joined &&
1469 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1478 SetLastError(ERROR_NOT_FOUND);
1482 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1484 SetLastError(ERROR_NOT_READY);
1488 WINPR_ASSERT(client);
1489 WINPR_ASSERT(client->context);
1490 WINPR_ASSERT(client->context->settings);
1492 const UINT32 VCChunkSize =
1494 channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
1498 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1502 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1503 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1505 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1507 channel_free(channel);
1511 s = Stream_New(
nullptr, 64);
1516 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1520 const size_t pos = Stream_GetPosition(s);
1521 WINPR_ASSERT(pos <= UINT32_MAX);
1522 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char), (UINT32)pos,
1527 Stream_Free(s, TRUE);
1530 Stream_Free(s, TRUE);
1532 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1534 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1538BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1541 rdpMcs* mcs =
nullptr;
1543 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1551 WINPR_ASSERT(vcm->client);
1552 WINPR_ASSERT(vcm->client->context);
1553 WINPR_ASSERT(vcm->client->context->rdp);
1554 mcs = vcm->client->context->rdp->mcs;
1556 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1558 if (channel->index < mcs->channelCount)
1560 rdpMcsChannel* cur = &mcs->channels[channel->index];
1561 rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
1562 channel_free(peerChannel);
1563 cur->handle =
nullptr;
1568 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1571 s = Stream_New(
nullptr, 8);
1575 WLog_ERR(TAG,
"Stream_New failed!");
1580 wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
1582 const size_t pos = Stream_GetPosition(s);
1583 WINPR_ASSERT(pos <= UINT32_MAX);
1584 ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char),
1585 (UINT32)pos, &written);
1586 Stream_Free(s, TRUE);
1589 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1596BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut,
1597 PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
1599 BYTE* buffer =
nullptr;
1600 wMessage message = WINPR_C_ARRAY_INIT;
1601 wtsChannelMessage* messageCtx =
nullptr;
1602 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1604 WINPR_ASSERT(channel);
1606 if (!MessageQueue_Peek(channel->queue, &message, FALSE))
1608 SetLastError(ERROR_NO_DATA);
1613 messageCtx = message.context;
1615 if (messageCtx ==
nullptr)
1618 buffer = (BYTE*)(messageCtx + 1);
1619 *pBytesRead = messageCtx->length - messageCtx->offset;
1621 if (Buffer ==
nullptr || BufferSize == 0)
1626 if (*pBytesRead > BufferSize)
1627 *pBytesRead = BufferSize;
1629 CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
1630 messageCtx->offset += *pBytesRead;
1632 if (messageCtx->offset >= messageCtx->length)
1634 (void)MessageQueue_Peek(channel->queue, &message, TRUE);
1635 peer_channel_queue_free_message(&message);
1641BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength,
1642 PULONG pBytesWritten)
1648 BYTE* buffer =
nullptr;
1649 size_t totalWritten = 0;
1650 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1656 EnterCriticalSection(&channel->writeLock);
1657 WINPR_ASSERT(channel->vcm);
1658 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1660 buffer = (BYTE*)malloc(uLength);
1664 SetLastError(g_err_oom);
1668 CopyMemory(buffer, Buffer, uLength);
1669 totalWritten = uLength;
1670 if (!wts_queue_send_item(channel, buffer, uLength))
1673 else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
1675 DEBUG_DVC(
"drdynvc not ready");
1682 size_t Length = uLength;
1685 s = Stream_New(
nullptr, DVC_MAX_DATA_PDU_SIZE);
1689 WLog_ERR(TAG,
"Stream_New failed!");
1690 SetLastError(g_err_oom);
1694 buffer = Stream_Buffer(s);
1695 Stream_Seek_UINT8(s);
1696 cbChId = wts_write_variable_uint(s, channel->channelId);
1698 if (first && (Length > Stream_GetRemainingLength(s)))
1700 cbLen = wts_write_variable_uint(s, WINPR_ASSERTING_INT_CAST(uint32_t, Length));
1701 buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF;
1705 buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
1709 size_t written = Stream_GetRemainingLength(s);
1711 if (written > Length)
1714 Stream_Write(s, Buffer, written);
1715 const size_t length = Stream_GetPosition(s);
1716 Stream_Free(s, FALSE);
1717 if (length > UINT32_MAX)
1721 totalWritten += written;
1722 if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
1728 *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten);
1732 LeaveCriticalSection(&channel->writeLock);
1736BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1738 WLog_ERR(
"TODO",
"TODO: implement");
1742BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1744 WLog_ERR(
"TODO",
"TODO: implement");
1748BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
1749 PVOID* ppBuffer, DWORD* pBytesReturned)
1751 void* pfd =
nullptr;
1753 void* fds[10] = WINPR_C_ARRAY_INIT;
1754 HANDLE hEvent =
nullptr;
1756 BOOL status = FALSE;
1757 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1759 WINPR_ASSERT(channel);
1761 switch ((UINT32)WtsVirtualClass)
1763 case WTSVirtualFileHandle:
1764 hEvent = MessageQueue_Event(channel->queue);
1765 pfd = GetEventWaitObject(hEvent);
1769 fds[fds_count] = pfd;
1773 *ppBuffer = malloc(
sizeof(
void*));
1777 SetLastError(g_err_oom);
1781 CopyMemory(*ppBuffer, (
void*)&fds[0],
sizeof(
void*));
1782 *pBytesReturned =
sizeof(
void*);
1788 case WTSVirtualEventHandle:
1789 hEvent = MessageQueue_Event(channel->queue);
1791 *ppBuffer = malloc(
sizeof(HANDLE));
1795 SetLastError(g_err_oom);
1799 CopyMemory(*ppBuffer, (
void*)&hEvent,
sizeof(HANDLE));
1800 *pBytesReturned =
sizeof(
void*);
1806 case WTSVirtualChannelReady:
1807 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1814 switch (channel->dvc_open_state)
1816 case DVC_OPEN_STATE_NONE:
1821 case DVC_OPEN_STATE_SUCCEEDED:
1827 *ppBuffer =
nullptr;
1828 *pBytesReturned = 0;
1833 *ppBuffer = malloc(
sizeof(BOOL));
1837 SetLastError(g_err_oom);
1842 CopyMemory(*ppBuffer, &bval,
sizeof(BOOL));
1843 *pBytesReturned =
sizeof(BOOL);
1847 case WTSVirtualChannelOpenStatus:
1849 INT32 value = channel->creationStatus;
1852 *ppBuffer = malloc(
sizeof(value));
1855 SetLastError(g_err_oom);
1860 CopyMemory(*ppBuffer, &value,
sizeof(value));
1861 *pBytesReturned =
sizeof(value);
1872VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
1877BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1878 WINPR_ATTR_UNUSED PVOID pMemory,
1879 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1881 WLog_ERR(
"TODO",
"TODO: implement");
1885BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1886 WINPR_ATTR_UNUSED PVOID pMemory,
1887 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1889 WLog_ERR(
"TODO",
"TODO: implement");
1893BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd,
1894 WINPR_ATTR_UNUSED DWORD dwFlags)
1896 WLog_ERR(
"TODO",
"TODO: implement");
1900BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd)
1902 WLog_ERR(
"TODO",
"TODO: implement");
1906BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1907 WINPR_ATTR_UNUSED HWND hWnd,
1908 WINPR_ATTR_UNUSED DWORD dwFlags)
1910 WLog_ERR(
"TODO",
"TODO: implement");
1914BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1915 WINPR_ATTR_UNUSED HWND hWnd)
1917 WLog_ERR(
"TODO",
"TODO: implement");
1921BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId,
1922 WINPR_ATTR_UNUSED PHANDLE phToken)
1924 WLog_ERR(
"TODO",
"TODO: implement");
1928BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(WINPR_ATTR_UNUSED HANDLE hServer,
1929 WINPR_ATTR_UNUSED DWORD* pLevel,
1930 WINPR_ATTR_UNUSED DWORD SessionId,
1931 WINPR_ATTR_UNUSED LPWSTR* ppProcessInfo,
1932 WINPR_ATTR_UNUSED DWORD* pCount)
1934 WLog_ERR(
"TODO",
"TODO: implement");
1938BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(WINPR_ATTR_UNUSED HANDLE hServer,
1939 WINPR_ATTR_UNUSED DWORD* pLevel,
1940 WINPR_ATTR_UNUSED DWORD SessionId,
1941 WINPR_ATTR_UNUSED LPSTR* ppProcessInfo,
1942 WINPR_ATTR_UNUSED DWORD* pCount)
1944 WLog_ERR(
"TODO",
"TODO: implement");
1948BOOL WINAPI FreeRDP_WTSEnumerateListenersW(WINPR_ATTR_UNUSED HANDLE hServer,
1949 WINPR_ATTR_UNUSED PVOID pReserved,
1950 WINPR_ATTR_UNUSED DWORD Reserved,
1951 WINPR_ATTR_UNUSED PWTSLISTENERNAMEW pListeners,
1952 WINPR_ATTR_UNUSED DWORD* pCount)
1954 WLog_ERR(
"TODO",
"TODO: implement");
1958BOOL WINAPI FreeRDP_WTSEnumerateListenersA(WINPR_ATTR_UNUSED HANDLE hServer,
1959 WINPR_ATTR_UNUSED PVOID pReserved,
1960 WINPR_ATTR_UNUSED DWORD Reserved,
1961 WINPR_ATTR_UNUSED PWTSLISTENERNAMEA pListeners,
1962 WINPR_ATTR_UNUSED DWORD* pCount)
1964 WLog_ERR(
"TODO",
"TODO: implement");
1968BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(WINPR_ATTR_UNUSED HANDLE hServer,
1969 WINPR_ATTR_UNUSED PVOID pReserved,
1970 WINPR_ATTR_UNUSED DWORD Reserved,
1971 WINPR_ATTR_UNUSED LPWSTR pListenerName,
1974 WLog_ERR(
"TODO",
"TODO: implement");
1978BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(WINPR_ATTR_UNUSED HANDLE hServer,
1979 WINPR_ATTR_UNUSED PVOID pReserved,
1980 WINPR_ATTR_UNUSED DWORD Reserved,
1981 WINPR_ATTR_UNUSED LPSTR pListenerName,
1984 WLog_ERR(
"TODO",
"TODO: implement");
1988BOOL WINAPI FreeRDP_WTSCreateListenerW(WINPR_ATTR_UNUSED HANDLE hServer,
1989 WINPR_ATTR_UNUSED PVOID pReserved,
1990 WINPR_ATTR_UNUSED DWORD Reserved,
1991 WINPR_ATTR_UNUSED LPWSTR pListenerName,
1993 WINPR_ATTR_UNUSED DWORD flag)
1995 WLog_ERR(
"TODO",
"TODO: implement");
1999BOOL WINAPI FreeRDP_WTSCreateListenerA(WINPR_ATTR_UNUSED HANDLE hServer,
2000 WINPR_ATTR_UNUSED PVOID pReserved,
2001 WINPR_ATTR_UNUSED DWORD Reserved,
2002 WINPR_ATTR_UNUSED LPSTR pListenerName,
2004 WINPR_ATTR_UNUSED DWORD flag)
2006 WLog_ERR(
"TODO",
"TODO: implement");
2010BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(
2011 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2012 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2013 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2014 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2016 WLog_ERR(
"TODO",
"TODO: implement");
2020BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(
2021 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2022 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2023 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2024 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2026 WLog_ERR(
"TODO",
"TODO: implement");
2030BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(
2031 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2032 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2033 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2034 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2035 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2037 WLog_ERR(
"TODO",
"TODO: implement");
2041BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(
2042 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2043 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2044 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2045 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2046 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2048 WLog_ERR(
"TODO",
"TODO: implement");
2052BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable)
2054 WLog_ERR(
"TODO",
"TODO: implement");
2058BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled)
2060 WLog_ERR(
"TODO",
"TODO: implement");
2064BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId)
2066 WLog_ERR(
"TODO",
"TODO: implement");
2070DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(
void)
2072 WLog_ERR(
"TODO",
"TODO: implement");
2075BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer)
2077 WLog_ERR(
"TODO",
"TODO: implement");
2081BOOL WINAPI FreeRDP_WTSLogonUser(WINPR_ATTR_UNUSED HANDLE hServer,
2082 WINPR_ATTR_UNUSED LPCSTR username,
2083 WINPR_ATTR_UNUSED LPCSTR password, WINPR_ATTR_UNUSED LPCSTR domain)
2085 WLog_ERR(
"TODO",
"TODO: implement");
2089void server_channel_common_free(rdpPeerChannel* channel)
2093 MessageQueue_Free(channel->queue);
2094 Stream_Free(channel->receiveData, TRUE);
2095 DeleteCriticalSection(&channel->writeLock);
2099rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
2100 size_t chunkSize,
const wObject* callback,
2103 rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1,
sizeof(rdpPeerChannel));
2107 InitializeCriticalSection(&channel->writeLock);
2109 channel->receiveData = Stream_New(
nullptr, chunkSize);
2110 if (!channel->receiveData)
2113 channel->queue = MessageQueue_New(callback);
2114 if (!channel->queue)
2117 channel->index = index;
2118 channel->client = client;
2119 channel->channelId = channelId;
2120 strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
2123 WINPR_PRAGMA_DIAG_PUSH
2124 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2125 server_channel_common_free(channel);
2126 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