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 = NULL;
74 return HashTable_GetItemValue(vcm->dynamicVirtualChannels, &ChannelId);
77static BOOL wts_queue_receive_data(rdpPeerChannel* channel,
const BYTE* Buffer, UINT32 Length)
80 wtsChannelMessage* messageCtx = NULL;
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, NULL, NULL);
97static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
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 = NULL;
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)
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 = NULL;
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] = { 0 };
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 = { 0 };
605 if (!hServer || hServer == INVALID_HANDLE_VALUE)
612 if (!WTSVirtualChannelManagerOpen(hServer))
616 while (MessageQueue_Peek(vcm->queue, &message, TRUE))
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) == NULL ? FALSE
699BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
701 if (!client || !client->context || !client->context->rdp)
704 return wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) == NULL ? FALSE
708BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer,
const char* name)
712 if (!vcm || !vcm->rdp)
715 return wts_get_joined_channel_by_name(vcm->rdp->mcs, name) == NULL ? FALSE : TRUE;
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 = NULL;
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 = NULL;
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 = NULL;
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 = NULL;
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 = NULL;
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 = NULL;
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)
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 = NULL;
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;
1006HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1008 rdpContext* context = NULL;
1009 freerdp_peer* client = NULL;
1011 HANDLE hServer = INVALID_HANDLE_VALUE;
1012 wObject queueCallbacks = { 0 };
1014 context = (rdpContext*)pServerName;
1017 return INVALID_HANDLE_VALUE;
1019 client = context->peer;
1023 SetLastError(ERROR_INVALID_DATA);
1024 return INVALID_HANDLE_VALUE;
1030 goto error_vcm_alloc;
1032 vcm->client = client;
1033 vcm->rdp = context->rdp;
1034 vcm->SessionId = g_SessionId++;
1036 if (!g_ServerHandles)
1038 g_ServerHandles = HashTable_New(TRUE);
1040 if (!g_ServerHandles)
1044 if (!HashTable_Insert(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId, (
void*)vcm))
1047 queueCallbacks.fnObjectFree = wts_virtual_channel_manager_free_message;
1048 vcm->queue = MessageQueue_New(&queueCallbacks);
1053 vcm->dvc_channel_id_seq = 0;
1054 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1056 if (!vcm->dynamicVirtualChannels)
1057 goto error_dynamicVirtualChannels;
1059 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1060 goto error_hashFunction;
1063 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1065 obj->fnObjectFree = array_channel_free;
1067 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1068 obj->fnObjectEquals = dynChannelMatch;
1070 client->ReceiveChannelData = WTSReceiveChannelData;
1071 hServer = (HANDLE)vcm;
1075 HashTable_Free(vcm->dynamicVirtualChannels);
1076error_dynamicVirtualChannels:
1077 MessageQueue_Free(vcm->queue);
1079 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1083 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1084 return INVALID_HANDLE_VALUE;
1087HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1089 WLog_ERR(
"TODO",
"TODO: implement");
1090 return INVALID_HANDLE_VALUE;
1093HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1095 return FreeRDP_WTSOpenServerA(pServerName);
1098VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1103 if (vcm && (vcm != INVALID_HANDLE_VALUE))
1105 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1107 HashTable_Free(vcm->dynamicVirtualChannels);
1109 if (vcm->drdynvc_channel)
1111 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1112 vcm->drdynvc_channel = NULL;
1115 MessageQueue_Free(vcm->queue);
1120BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1121 WINPR_ATTR_UNUSED DWORD Reserved,
1122 WINPR_ATTR_UNUSED DWORD Version,
1124 WINPR_ATTR_UNUSED DWORD* pCount)
1126 WLog_ERR(
"TODO",
"TODO: implement");
1130BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1131 WINPR_ATTR_UNUSED DWORD Reserved,
1132 WINPR_ATTR_UNUSED DWORD Version,
1134 WINPR_ATTR_UNUSED DWORD* pCount)
1136 WLog_ERR(
"TODO",
"TODO: implement");
1140BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1141 WINPR_ATTR_UNUSED DWORD* pLevel,
1142 WINPR_ATTR_UNUSED DWORD Filter,
1144 WINPR_ATTR_UNUSED DWORD* pCount)
1146 WLog_ERR(
"TODO",
"TODO: implement");
1150BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1151 WINPR_ATTR_UNUSED DWORD* pLevel,
1152 WINPR_ATTR_UNUSED DWORD Filter,
1154 WINPR_ATTR_UNUSED DWORD* pCount)
1156 WLog_ERR(
"TODO",
"TODO: implement");
1160BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1161 WINPR_ATTR_UNUSED DWORD Reserved,
1162 WINPR_ATTR_UNUSED DWORD Version,
1164 WINPR_ATTR_UNUSED DWORD* pCount)
1166 WLog_ERR(
"TODO",
"TODO: implement");
1170BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1171 WINPR_ATTR_UNUSED DWORD Reserved,
1172 WINPR_ATTR_UNUSED DWORD Version,
1174 WINPR_ATTR_UNUSED DWORD* pCount)
1176 WLog_ERR(
"TODO",
"TODO: implement");
1180BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1181 WINPR_ATTR_UNUSED DWORD ProcessId,
1182 WINPR_ATTR_UNUSED DWORD ExitCode)
1184 WLog_ERR(
"TODO",
"TODO: implement");
1188BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1189 WINPR_ATTR_UNUSED DWORD SessionId,
1190 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1191 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1192 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1194 WLog_ERR(
"TODO",
"TODO: implement");
1198BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1199 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1200 DWORD* pBytesReturned)
1202 DWORD BytesReturned = 0;
1209 if (WTSInfoClass == WTSSessionId)
1211 ULONG* pBuffer = NULL;
1212 BytesReturned =
sizeof(ULONG);
1213 pBuffer = (ULONG*)malloc(
sizeof(BytesReturned));
1217 SetLastError(g_err_oom);
1221 *pBuffer = vcm->SessionId;
1222 *ppBuffer = (LPSTR)pBuffer;
1223 *pBytesReturned = BytesReturned;
1230BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1231 WINPR_ATTR_UNUSED LPWSTR pUserName,
1232 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1233 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1234 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1236 WLog_ERR(
"TODO",
"TODO: implement");
1240BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1241 WINPR_ATTR_UNUSED LPSTR pUserName,
1242 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1243 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1244 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1246 WLog_ERR(
"TODO",
"TODO: implement");
1250BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1251 WINPR_ATTR_UNUSED LPWSTR pUserName,
1252 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1253 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1254 WINPR_ATTR_UNUSED DWORD DataLength)
1256 WLog_ERR(
"TODO",
"TODO: implement");
1260BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1261 WINPR_ATTR_UNUSED LPSTR pUserName,
1262 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1263 WINPR_ATTR_UNUSED LPSTR pBuffer,
1264 WINPR_ATTR_UNUSED DWORD DataLength)
1266 WLog_ERR(
"TODO",
"TODO: implement");
1271FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1272 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1273 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1274 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1275 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1277 WLog_ERR(
"TODO",
"TODO: implement");
1282FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1283 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1284 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1285 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1286 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1288 WLog_ERR(
"TODO",
"TODO: implement");
1292BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1293 WINPR_ATTR_UNUSED DWORD SessionId,
1294 WINPR_ATTR_UNUSED BOOL bWait)
1296 WLog_ERR(
"TODO",
"TODO: implement");
1300BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1301 WINPR_ATTR_UNUSED DWORD SessionId,
1302 WINPR_ATTR_UNUSED BOOL bWait)
1304 WLog_ERR(
"TODO",
"TODO: implement");
1308BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1309 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1311 WLog_ERR(
"TODO",
"TODO: implement");
1315BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1316 WINPR_ATTR_UNUSED DWORD EventMask,
1317 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1319 WLog_ERR(
"TODO",
"TODO: implement");
1323static void peer_channel_queue_free_message(
void* obj)
1325 wMessage* msg = (wMessage*)obj;
1330 msg->context = NULL;
1334 UINT32 ChannelId, UINT16 index, UINT16 type,
size_t chunkSize,
1337 wObject queueCallbacks = { 0 };
1338 queueCallbacks.fnObjectFree = peer_channel_queue_free_message;
1340 rdpPeerChannel* channel =
1341 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1344 WINPR_ASSERT(client);
1350 channel->channelType = type;
1351 channel->creationStatus =
1352 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1356 channel_free(channel);
1360HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1365 rdpMcsChannel* joined_channel = NULL;
1366 freerdp_peer* client = NULL;
1367 rdpPeerChannel* channel = NULL;
1369 HANDLE hChannelHandle = NULL;
1370 rdpContext* context = NULL;
1375 SetLastError(ERROR_INVALID_DATA);
1379 client = vcm->client;
1380 WINPR_ASSERT(client);
1382 context = client->context;
1383 WINPR_ASSERT(context);
1384 WINPR_ASSERT(context->rdp);
1385 WINPR_ASSERT(context->settings);
1387 mcs = context->rdp->mcs;
1390 length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1392 if (length > CHANNEL_NAME_LEN)
1394 SetLastError(ERROR_NOT_FOUND);
1399 for (; index < mcs->channelCount; index++)
1401 rdpMcsChannel* mchannel = &mcs->channels[index];
1402 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1404 joined_channel = mchannel;
1409 if (!joined_channel)
1411 SetLastError(ERROR_NOT_FOUND);
1415 channel = (rdpPeerChannel*)joined_channel->handle;
1419 const UINT32 VCChunkSize =
1422 WINPR_ASSERT(index <= UINT16_MAX);
1423 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1424 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName);
1429 joined_channel->handle = channel;
1432 hChannelHandle = (HANDLE)channel;
1433 return hChannelHandle;
1435 channel_free(channel);
1436 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1440HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1444 BOOL joined = FALSE;
1445 freerdp_peer* client = NULL;
1446 rdpPeerChannel* channel = NULL;
1450 if (SessionId == WTS_CURRENT_SESSION)
1454 (
void*)(UINT_PTR)SessionId);
1459 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1461 return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
1464 client = vcm->client;
1465 mcs = client->context->rdp->mcs;
1467 for (UINT32 index = 0; index < mcs->channelCount; index++)
1469 rdpMcsChannel* mchannel = &mcs->channels[index];
1470 if (mchannel->joined &&
1471 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1480 SetLastError(ERROR_NOT_FOUND);
1484 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1486 SetLastError(ERROR_NOT_READY);
1490 WINPR_ASSERT(client);
1491 WINPR_ASSERT(client->context);
1492 WINPR_ASSERT(client->context->settings);
1494 const UINT32 VCChunkSize =
1496 channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
1500 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1504 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1505 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1507 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1509 channel_free(channel);
1513 s = Stream_New(NULL, 64);
1518 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1521 const size_t pos = Stream_GetPosition(s);
1522 WINPR_ASSERT(pos <= UINT32_MAX);
1523 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char), (UINT32)pos,
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)
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);
1568 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1571 s = Stream_New(NULL, 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 = NULL;
1600 wMessage message = { 0 };
1601 wtsChannelMessage* messageCtx = NULL;
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 == NULL)
1618 buffer = (BYTE*)(messageCtx + 1);
1619 *pBytesRead = messageCtx->length - messageCtx->offset;
1621 if (Buffer == NULL || 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 = NULL;
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(NULL, 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)
1753 void* fds[10] = { 0 };
1754 HANDLE hEvent = NULL;
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:
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(NULL, 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
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.