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* Buffer1, UINT32 Length1,
80 const BYTE* Buffer2, UINT32 Length2)
82 WINPR_ASSERT(channel);
84 wtsChannelMessage* messageCtx =
85 (wtsChannelMessage*)malloc(
sizeof(wtsChannelMessage) + Length1 + Length2);
89 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
90 messageCtx->channelId = WINPR_ASSERTING_INT_CAST(UINT16, channel->channelId);
91 messageCtx->length = Length1 + Length2;
92 messageCtx->offset = 0;
93 BYTE* buffer = (BYTE*)(&messageCtx[1]);
94 CopyMemory(buffer, Buffer1, Length1);
96 WINPR_ASSERT(Buffer2 || (Length2 == 0));
99 CopyMemory(buffer, Buffer2, Length2);
101 return MessageQueue_Post(channel->queue, messageCtx, 0,
nullptr,
nullptr);
104static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
106 BYTE* buffer =
nullptr;
109 WINPR_ASSERT(channel);
110 WINPR_ASSERT(channel->vcm);
114 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
115 const UINT16 channelId = (UINT16)channel->channelId;
116 return MessageQueue_Post(channel->vcm->queue, (
void*)(UINT_PTR)channelId, 0, (
void*)buffer,
117 (
void*)(UINT_PTR)length);
120static unsigned wts_read_variable_uint(
wStream* s,
int cbLen, UINT32* val)
127 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
130 Stream_Read_UINT8(s, *val);
134 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
137 Stream_Read_UINT16(s, *val);
141 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
144 Stream_Read_UINT32(s, *val);
148 WLog_ERR(TAG,
"invalid wts variable uint len %d", cbLen);
153static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
157 WINPR_ASSERT(channel);
158 WINPR_ASSERT(channel->vcm);
162 Stream_Seek_UINT8(channel->receiveData);
163 Stream_Read_UINT16(channel->receiveData, Version);
164 DEBUG_DVC(
"Version: %" PRIu16
"", Version);
168 WLog_ERR(TAG,
"invalid version %" PRIu16
" for DRDYNVC", Version);
173 vcm->drdynvc_state = DRDYNVC_STATE_READY;
176 vcm->dvc_spoken_version = MAX(Version, 1);
178 return SetEvent(MessageQueue_Event(vcm->queue));
181static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel,
wStream* s, UINT32 length)
183 UINT32 CreationStatus = 0;
186 WINPR_ASSERT(channel);
191 Stream_Read_UINT32(s, CreationStatus);
193 if ((INT32)CreationStatus < 0)
195 DEBUG_DVC(
"ChannelId %" PRIu32
" creation failed (%" PRId32
")", channel->channelId,
196 (INT32)CreationStatus);
197 channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
201 DEBUG_DVC(
"ChannelId %" PRIu32
" creation succeeded", channel->channelId);
202 channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
205 channel->creationStatus = (INT32)CreationStatus;
206 IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata,
207 channel->channelId, (INT32)CreationStatus);
209 WLog_ERR(TAG,
"vcm->dvc_creation_status failed!");
214static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel,
wStream* s,
int cbLen,
217 WINPR_ASSERT(channel);
219 const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
228 if (length > channel->dvc_total_length)
231 Stream_ResetPosition(channel->receiveData);
233 if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
236 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
240static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel,
wStream* s, UINT32 length)
244 WINPR_ASSERT(channel);
246 if (channel->dvc_total_length > 0)
248 if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
250 channel->dvc_total_length = 0;
251 WLog_ERR(TAG,
"incorrect fragment data, discarded.");
255 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
257 if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
259 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
260 channel->dvc_total_length,
nullptr, 0);
261 channel->dvc_total_length = 0;
268 ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length,
nullptr, 0);
274static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
276 WINPR_ASSERT(channel);
277 DEBUG_DVC(
"ChannelId %" PRIu32
" close response", channel->channelId);
278 channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
279 MessageQueue_PostQuit(channel->queue, 0);
282static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
287 UINT32 ChannelId = 0;
288 rdpPeerChannel* dvc =
nullptr;
290 WINPR_ASSERT(channel);
291 WINPR_ASSERT(channel->vcm);
293 size_t length = Stream_GetPosition(channel->receiveData);
295 if ((length < 1) || (length > UINT32_MAX))
298 Stream_ResetPosition(channel->receiveData);
299 const UINT8 value = Stream_Get_UINT8(channel->receiveData);
301 Cmd = (value & 0xf0) >> 4;
302 Sp = (value & 0x0c) >> 2;
303 cbChId = (value & 0x03) >> 0;
305 if (Cmd == CAPABILITY_REQUEST_PDU)
306 return wts_read_drdynvc_capabilities_response(channel, (UINT32)length);
308 if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
310 BOOL haveChannelId = 0;
313 case SOFT_SYNC_REQUEST_PDU:
314 case SOFT_SYNC_RESPONSE_PDU:
315 haveChannelId = FALSE;
318 haveChannelId = TRUE;
324 const unsigned val = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId);
330 DEBUG_DVC(
"Cmd %s ChannelId %" PRIu32
" length %" PRIuz
"",
331 drdynvc_get_packet_type(Cmd), ChannelId, length);
332 dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
335 DEBUG_DVC(
"ChannelId %" PRIu32
" does not exist.", ChannelId);
342 case CREATE_REQUEST_PDU:
343 return wts_read_drdynvc_create_response(dvc, channel->receiveData, (UINT32)length);
346 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
349 "ChannelId %" PRIu32
" did not open successfully. "
350 "Ignoring DYNVC_DATA_FIRST PDU",
355 return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, (UINT32)length);
358 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
361 "ChannelId %" PRIu32
" did not open successfully. "
362 "Ignoring DYNVC_DATA PDU",
367 return wts_read_drdynvc_data(dvc, channel->receiveData, (UINT32)length);
369 case CLOSE_REQUEST_PDU:
370 wts_read_drdynvc_close_response(dvc);
373 case DATA_FIRST_COMPRESSED_PDU:
374 case DATA_COMPRESSED_PDU:
375 WLog_ERR(TAG,
"Compressed data not handled");
378 case SOFT_SYNC_RESPONSE_PDU:
379 WLog_ERR(TAG,
"SoftSync response not handled yet(and rather strange to receive "
380 "that packet as our code doesn't send SoftSync requests");
383 case SOFT_SYNC_REQUEST_PDU:
384 WLog_ERR(TAG,
"Not expecting a SoftSyncRequest on the server");
388 WLog_ERR(TAG,
"Cmd %d not recognized.", Cmd);
394 WLog_ERR(TAG,
"received Cmd %d but channel is not ready.", Cmd);
400static int wts_write_variable_uint(
wStream* s, UINT32 val)
408 Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val));
410 else if (val <= 0xFFFF)
413 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val));
418 Stream_Write_UINT32(s, val);
424static void wts_write_drdynvc_header(
wStream* s, BYTE Cmd, UINT32 ChannelId)
428 BYTE* bm = Stream_PointerAs(s, BYTE);
429 Stream_Seek_UINT8(s);
430 const int cbChId = wts_write_variable_uint(s, ChannelId);
431 *bm = (((Cmd & 0x0F) << 4) | cbChId) & 0xFF;
434static BOOL wts_write_drdynvc_create_request(
wStream* s, UINT32 ChannelId,
const char* ChannelName)
439 WINPR_ASSERT(ChannelName);
441 wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
442 len = strlen(ChannelName) + 1;
444 if (!Stream_EnsureRemainingCapacity(s, len))
447 Stream_Write(s, ChannelName, len);
451static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId,
const BYTE* data,
452 size_t s, UINT32 flags,
size_t t)
455 const size_t size = s;
456 const size_t totalSize = t;
458 WINPR_ASSERT(channel);
459 WINPR_ASSERT(channel->vcm);
460 WINPR_UNUSED(channelId);
462 if (channel->channelFlags & CHANNEL_OPTION_SHOW_PROTOCOL)
465 .length = WINPR_ASSERTING_INT_CAST(UINT32, size),
469 return wts_queue_receive_data(channel, (
const BYTE*)&header,
sizeof(header), data,
473 if ((flags & CHANNEL_FLAG_FIRST) != 0)
475 Stream_ResetPosition(channel->receiveData);
478 if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
481 Stream_Write(channel->receiveData, data, size);
483 if ((flags & CHANNEL_FLAG_LAST) != 0)
485 if (Stream_GetPosition(channel->receiveData) != totalSize)
487 WLog_ERR(TAG,
"read error");
490 if (channel == channel->vcm->drdynvc_channel)
492 ret = wts_read_drdynvc_pdu(channel);
496 const size_t pos = Stream_GetPosition(channel->receiveData);
497 if (pos > UINT32_MAX)
500 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
501 WINPR_ASSERTING_INT_CAST(UINT32, pos),
nullptr, 0);
504 Stream_ResetPosition(channel->receiveData);
510static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId,
const BYTE* data,
511 size_t size, UINT32 flags,
size_t totalSize)
513 rdpMcs* mcs =
nullptr;
515 WINPR_ASSERT(client);
516 WINPR_ASSERT(client->context);
517 WINPR_ASSERT(client->context->rdp);
519 mcs = client->context->rdp->mcs;
522 for (UINT32 i = 0; i < mcs->channelCount; i++)
524 rdpMcsChannel* cur = &mcs->channels[i];
525 if (cur->ChannelId == channelId)
527 rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
530 return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
534 WLog_WARN(TAG,
"unknown channelId %" PRIu16
" ignored", channelId);
539#if defined(WITH_FREERDP_DEPRECATED)
540void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer,
void** fds,
int* fds_count)
546 WINPR_ASSERT(fds_count);
548 fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
552 fds[*fds_count] = fd;
558 if (vcm->drdynvc_channel)
560 fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
564 fds[*fds_count] = fd;
573BOOL WTSVirtualChannelManagerOpen(HANDLE hServer)
580 if (vcm->drdynvc_state == DRDYNVC_STATE_NONE)
582 rdpPeerChannel* channel =
nullptr;
585 vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
586 channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
587 DRDYNVC_SVC_CHANNEL_NAME);
591 BYTE capaBuffer[12] = WINPR_C_ARRAY_INIT;
592 wStream staticS = WINPR_C_ARRAY_INIT;
593 wStream* s = Stream_StaticInit(&staticS, capaBuffer,
sizeof(capaBuffer));
595 vcm->drdynvc_channel = channel;
596 vcm->dvc_spoken_version = 1;
597 Stream_Write_UINT8(s, 0x50);
598 Stream_Write_UINT8(s, 0x00);
599 Stream_Write_UINT16(s, 0x0001);
603 const size_t pos = Stream_GetPosition(s);
604 WINPR_ASSERT(pos <= UINT32_MAX);
606 if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written))
614BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
616 wMessage message = WINPR_C_ARRAY_INIT;
620 if (!hServer || hServer == INVALID_HANDLE_VALUE)
627 if (!WTSVirtualChannelManagerOpen(hServer))
631 while (MessageQueue_Peek(vcm->queue, &message, TRUE))
633 BYTE* buffer =
nullptr;
635 UINT16 channelId = 0;
636 channelId = (UINT16)(UINT_PTR)message.context;
637 buffer = (BYTE*)message.wParam;
638 length = (UINT32)(UINT_PTR)message.lParam;
640 WINPR_ASSERT(vcm->client);
641 WINPR_ASSERT(vcm->client->SendChannelData);
642 if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
656BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
658 return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
661HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
665 return MessageQueue_Event(vcm->queue);
668static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs,
const char* channel_name)
670 if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
673 for (UINT32 index = 0; index < mcs->channelCount; index++)
675 rdpMcsChannel* mchannel = &mcs->channels[index];
676 if (mchannel->joined)
678 if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
686static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs,
const UINT16 channel_id)
688 if (!mcs || !channel_id)
691 WINPR_ASSERT(mcs->channels);
692 for (UINT32 index = 0; index < mcs->channelCount; index++)
694 rdpMcsChannel* mchannel = &mcs->channels[index];
695 if (mchannel->joined)
697 if (mchannel->ChannelId == channel_id)
698 return &mcs->channels[index];
705BOOL WTSIsChannelJoinedByName(freerdp_peer* client,
const char* channel_name)
707 if (!client || !client->context || !client->context->rdp)
710 return (wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) !=
nullptr);
713BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
715 if (!client || !client->context || !client->context->rdp)
718 return (wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) !=
nullptr);
721BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer,
const char* name)
725 if (!vcm || !vcm->rdp)
728 return (wts_get_joined_channel_by_name(vcm->rdp->mcs, name) !=
nullptr);
731BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
735 return vcm->drdynvc_state;
738void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
745 vcm->dvc_creation_status = cb;
746 vcm->dvc_creation_status_userdata = userdata;
749UINT16 WTSChannelGetId(freerdp_peer* client,
const char* channel_name)
751 rdpMcsChannel* channel =
nullptr;
753 WINPR_ASSERT(channel_name);
754 if (!client || !client->context || !client->context->rdp)
757 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
762 return channel->ChannelId;
765UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
767 rdpPeerChannel* channel = hChannelHandle;
769 WINPR_ASSERT(channel);
771 return channel->channelId;
774BOOL WTSChannelSetHandleByName(freerdp_peer* client,
const char* channel_name,
void* handle)
776 rdpMcsChannel* channel =
nullptr;
778 WINPR_ASSERT(channel_name);
779 if (!client || !client->context || !client->context->rdp)
782 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
787 channel->handle = handle;
791BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id,
void* handle)
793 rdpMcsChannel* channel =
nullptr;
795 if (!client || !client->context || !client->context->rdp)
798 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
803 channel->handle = handle;
807void* WTSChannelGetHandleByName(freerdp_peer* client,
const char* channel_name)
809 rdpMcsChannel* channel =
nullptr;
811 WINPR_ASSERT(channel_name);
812 if (!client || !client->context || !client->context->rdp)
815 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
820 return channel->handle;
823void* WTSChannelGetHandleById(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 channel->handle;
838const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
840 rdpMcsChannel* channel =
nullptr;
842 if (!client || !client->context || !client->context->rdp)
845 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
850 return (
const char*)channel->Name;
853char** WTSGetAcceptedChannelNames(freerdp_peer* client,
size_t* count)
855 rdpMcs* mcs =
nullptr;
856 char** names =
nullptr;
858 if (!client || !client->context || !count)
861 WINPR_ASSERT(client->context->rdp);
862 mcs = client->context->rdp->mcs;
864 *count = mcs->channelCount;
866 names = (
char**)calloc(mcs->channelCount,
sizeof(
char*));
870 for (UINT32 index = 0; index < mcs->channelCount; index++)
872 rdpMcsChannel* mchannel = &mcs->channels[index];
873 names[index] = mchannel->Name;
879INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
881 rdpMcsChannel* channel =
nullptr;
883 if (!client || !client->context || !client->context->rdp)
886 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
891 return (INT64)channel->options;
894BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
895 WINPR_ATTR_UNUSED ULONG TargetLogonId,
896 WINPR_ATTR_UNUSED BYTE HotkeyVk,
897 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
899 WLog_ERR(
"TODO",
"TODO: implement");
903BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
904 WINPR_ATTR_UNUSED ULONG TargetLogonId,
905 WINPR_ATTR_UNUSED BYTE HotkeyVk,
906 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
908 WLog_ERR(
"TODO",
"TODO: implement");
912BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
913 WINPR_ATTR_UNUSED ULONG TargetLogonId,
914 WINPR_ATTR_UNUSED BYTE HotkeyVk,
915 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
916 WINPR_ATTR_UNUSED DWORD flags)
918 WLog_ERR(
"TODO",
"TODO: implement");
922BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
923 WINPR_ATTR_UNUSED ULONG TargetLogonId,
924 WINPR_ATTR_UNUSED BYTE HotkeyVk,
925 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
926 WINPR_ATTR_UNUSED DWORD flags)
928 WLog_ERR(
"TODO",
"TODO: implement");
932BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId)
934 WLog_ERR(
"TODO",
"TODO: implement");
938BOOL WINAPI FreeRDP_WTSConnectSessionW(WINPR_ATTR_UNUSED ULONG LogonId,
939 WINPR_ATTR_UNUSED ULONG TargetLogonId,
940 WINPR_ATTR_UNUSED PWSTR pPassword,
941 WINPR_ATTR_UNUSED BOOL bWait)
943 WLog_ERR(
"TODO",
"TODO: implement");
947BOOL WINAPI FreeRDP_WTSConnectSessionA(WINPR_ATTR_UNUSED ULONG LogonId,
948 WINPR_ATTR_UNUSED ULONG TargetLogonId,
949 WINPR_ATTR_UNUSED PSTR pPassword,
950 WINPR_ATTR_UNUSED BOOL bWait)
952 WLog_ERR(
"TODO",
"TODO: implement");
956BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName,
957 WINPR_ATTR_UNUSED DWORD Reserved,
958 WINPR_ATTR_UNUSED DWORD Version,
960 WINPR_ATTR_UNUSED DWORD* pCount)
962 WLog_ERR(
"TODO",
"TODO: implement");
966BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName,
967 WINPR_ATTR_UNUSED DWORD Reserved,
968 WINPR_ATTR_UNUSED DWORD Version,
970 WINPR_ATTR_UNUSED DWORD* pCount)
972 WLog_ERR(
"TODO",
"TODO: implement");
976HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName)
978 WLog_ERR(
"TODO",
"TODO: implement");
979 return INVALID_HANDLE_VALUE;
982static void wts_virtual_channel_manager_free_message(
void* obj)
984 wMessage* msg = (wMessage*)obj;
988 BYTE* buffer = (BYTE*)msg->wParam;
995static void channel_free(rdpPeerChannel* channel)
997 server_channel_common_free(channel);
1000static void array_channel_free(
void* ptr)
1002 rdpPeerChannel* channel = ptr;
1003 channel_free(channel);
1006static BOOL dynChannelMatch(
const void* v1,
const void* v2)
1008 const UINT32* p1 = (
const UINT32*)v1;
1009 const UINT32* p2 = (
const UINT32*)v2;
1013static UINT32 channelId_Hash(
const void* key)
1015 const UINT32* v = (
const UINT32*)key;
1019static void clearHandles(
void)
1021 HashTable_Free(g_ServerHandles);
1022 g_ServerHandles =
nullptr;
1025static BOOL CALLBACK initializeHandles(WINPR_ATTR_UNUSED
PINIT_ONCE once,
1026 WINPR_ATTR_UNUSED PVOID param,
1027 WINPR_ATTR_UNUSED PVOID* context)
1029 WINPR_ASSERT(g_ServerHandles ==
nullptr);
1030 g_ServerHandles = HashTable_New(TRUE);
1031 (void)winpr_atexit(clearHandles);
1032 return g_ServerHandles !=
nullptr;
1035static bool setup(
void)
1037 return InitOnceExecuteOnce(&g_HandleInitializer, initializeHandles,
nullptr,
nullptr);
1044 HashTable_Lock(g_ServerHandles);
1048#ifdef __clang_analyzer__
1049 const BOOL valid = vcm !=
nullptr;
1051 const BOOL valid = (vcm !=
nullptr) && (vcm != INVALID_HANDLE_VALUE);
1055 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1057 HashTable_Free(vcm->dynamicVirtualChannels);
1059 if (vcm->drdynvc_channel)
1062 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1063 vcm->drdynvc_channel =
nullptr;
1066 MessageQueue_Free(vcm->queue);
1069 HashTable_Unlock(g_ServerHandles);
1072HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1074 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1076 rdpContext* context = (rdpContext*)pServerName;
1078 if (!setup() || !context)
1079 return INVALID_HANDLE_VALUE;
1081 freerdp_peer* client = context->peer;
1085 SetLastError(ERROR_INVALID_DATA);
1086 return INVALID_HANDLE_VALUE;
1094 vcm->client = client;
1095 vcm->rdp = context->rdp;
1097 queueCallbacks.
fnObjectFree = wts_virtual_channel_manager_free_message;
1098 vcm->queue = MessageQueue_New(&queueCallbacks);
1103 vcm->dvc_channel_id_seq = 0;
1104 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1106 if (!vcm->dynamicVirtualChannels)
1109 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1113 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1117 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1120 client->ReceiveChannelData = WTSReceiveChannelData;
1122 HashTable_Lock(g_ServerHandles);
1123 vcm->SessionId = g_SessionId++;
1125 HashTable_Insert(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId, (
void*)vcm);
1126 HashTable_Unlock(g_ServerHandles);
1131 HANDLE hServer = (HANDLE)vcm;
1135 wtsCloseVCM(vcm,
false);
1136 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1137 return INVALID_HANDLE_VALUE;
1140HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1142 WLog_ERR(
"TODO",
"TODO: implement");
1143 return INVALID_HANDLE_VALUE;
1146HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1148 return FreeRDP_WTSOpenServerA(pServerName);
1151VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1154 wtsCloseVCM(vcm,
true);
1157BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1158 WINPR_ATTR_UNUSED DWORD Reserved,
1159 WINPR_ATTR_UNUSED DWORD Version,
1161 WINPR_ATTR_UNUSED DWORD* pCount)
1163 WLog_ERR(
"TODO",
"TODO: implement");
1167BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1168 WINPR_ATTR_UNUSED DWORD Reserved,
1169 WINPR_ATTR_UNUSED DWORD Version,
1171 WINPR_ATTR_UNUSED DWORD* pCount)
1173 WLog_ERR(
"TODO",
"TODO: implement");
1177BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1178 WINPR_ATTR_UNUSED DWORD* pLevel,
1179 WINPR_ATTR_UNUSED DWORD Filter,
1181 WINPR_ATTR_UNUSED DWORD* pCount)
1183 WLog_ERR(
"TODO",
"TODO: implement");
1187BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1188 WINPR_ATTR_UNUSED DWORD* pLevel,
1189 WINPR_ATTR_UNUSED DWORD Filter,
1191 WINPR_ATTR_UNUSED DWORD* pCount)
1193 WLog_ERR(
"TODO",
"TODO: implement");
1197BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1198 WINPR_ATTR_UNUSED DWORD Reserved,
1199 WINPR_ATTR_UNUSED DWORD Version,
1201 WINPR_ATTR_UNUSED DWORD* pCount)
1203 WLog_ERR(
"TODO",
"TODO: implement");
1207BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1208 WINPR_ATTR_UNUSED DWORD Reserved,
1209 WINPR_ATTR_UNUSED DWORD Version,
1211 WINPR_ATTR_UNUSED DWORD* pCount)
1213 WLog_ERR(
"TODO",
"TODO: implement");
1217BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1218 WINPR_ATTR_UNUSED DWORD ProcessId,
1219 WINPR_ATTR_UNUSED DWORD ExitCode)
1221 WLog_ERR(
"TODO",
"TODO: implement");
1225BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1226 WINPR_ATTR_UNUSED DWORD SessionId,
1227 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1228 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1229 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1231 WLog_ERR(
"TODO",
"TODO: implement");
1235BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1236 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1237 DWORD* pBytesReturned)
1239 DWORD BytesReturned = 0;
1246 if (WTSInfoClass == WTSSessionId)
1248 ULONG* pBuffer =
nullptr;
1249 BytesReturned =
sizeof(ULONG);
1250 pBuffer = (ULONG*)malloc(
sizeof(BytesReturned));
1254 SetLastError(g_err_oom);
1258 *pBuffer = vcm->SessionId;
1259 *ppBuffer = (LPSTR)pBuffer;
1260 *pBytesReturned = BytesReturned;
1267BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1268 WINPR_ATTR_UNUSED LPWSTR pUserName,
1269 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1270 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1271 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1273 WLog_ERR(
"TODO",
"TODO: implement");
1277BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1278 WINPR_ATTR_UNUSED LPSTR pUserName,
1279 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1280 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1281 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1283 WLog_ERR(
"TODO",
"TODO: implement");
1287BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1288 WINPR_ATTR_UNUSED LPWSTR pUserName,
1289 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1290 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1291 WINPR_ATTR_UNUSED DWORD DataLength)
1293 WLog_ERR(
"TODO",
"TODO: implement");
1297BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1298 WINPR_ATTR_UNUSED LPSTR pUserName,
1299 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1300 WINPR_ATTR_UNUSED LPSTR pBuffer,
1301 WINPR_ATTR_UNUSED DWORD DataLength)
1303 WLog_ERR(
"TODO",
"TODO: implement");
1308FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1309 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1310 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1311 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1312 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1314 WLog_ERR(
"TODO",
"TODO: implement");
1319FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1320 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1321 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1322 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1323 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1325 WLog_ERR(
"TODO",
"TODO: implement");
1329BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1330 WINPR_ATTR_UNUSED DWORD SessionId,
1331 WINPR_ATTR_UNUSED BOOL bWait)
1333 WLog_ERR(
"TODO",
"TODO: implement");
1337BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1338 WINPR_ATTR_UNUSED DWORD SessionId,
1339 WINPR_ATTR_UNUSED BOOL bWait)
1341 WLog_ERR(
"TODO",
"TODO: implement");
1345BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1346 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1348 WLog_ERR(
"TODO",
"TODO: implement");
1352BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1353 WINPR_ATTR_UNUSED DWORD EventMask,
1354 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1356 WLog_ERR(
"TODO",
"TODO: implement");
1360static void peer_channel_queue_free_message(
void* obj)
1362 wMessage* msg = (wMessage*)obj;
1367 msg->context =
nullptr;
1371 UINT32 ChannelId, UINT16 index, UINT16 type,
size_t chunkSize,
1372 const char* name, UINT32 flags)
1374 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1375 queueCallbacks.
fnObjectFree = peer_channel_queue_free_message;
1377 rdpPeerChannel* channel =
1378 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1381 WINPR_ASSERT(client);
1387 channel->channelType = type;
1388 channel->creationStatus =
1389 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1390 channel->channelFlags = flags;
1394 channel_free(channel);
1398static HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenStatic(HANDLE hServer,
1399 WINPR_ATTR_UNUSED DWORD SessionId,
1400 LPSTR pVirtualName, UINT32 Flags)
1405 SetLastError(ERROR_INVALID_DATA);
1409 freerdp_peer* client = vcm->client;
1410 WINPR_ASSERT(client);
1412 rdpContext* context = client->context;
1413 WINPR_ASSERT(context);
1414 WINPR_ASSERT(context->rdp);
1415 WINPR_ASSERT(context->settings);
1417 rdpMcs* mcs = context->rdp->mcs;
1420 size_t length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1421 if (length > CHANNEL_NAME_LEN)
1423 SetLastError(ERROR_NOT_FOUND);
1427 rdpMcsChannel* joined_channel =
nullptr;
1429 for (; index < mcs->channelCount; index++)
1431 rdpMcsChannel* mchannel = &mcs->channels[index];
1432 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1434 joined_channel = mchannel;
1439 if (!joined_channel)
1441 SetLastError(ERROR_NOT_FOUND);
1445 rdpPeerChannel* channel = (rdpPeerChannel*)joined_channel->handle;
1448 const UINT32 VCChunkSize =
1451 WINPR_ASSERT(index <= UINT16_MAX);
1452 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1453 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName, Flags);
1458 joined_channel->handle = channel;
1461 HANDLE hChannelHandle = (HANDLE)channel;
1462 return hChannelHandle;
1464 channel_free(channel);
1465 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1469HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
1471 return FreeRDP_WTSVirtualChannelOpenStatic(hServer, SessionId, pVirtualName, 0);
1474HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1477 rdpPeerChannel* channel =
nullptr;
1478 BOOL joined = FALSE;
1484 if (SessionId == WTS_CURRENT_SESSION)
1487 HashTable_Lock(g_ServerHandles);
1489 g_ServerHandles, (
void*)(UINT_PTR)SessionId);
1494 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1496 HashTable_Unlock(g_ServerHandles);
1497 return FreeRDP_WTSVirtualChannelOpenStatic((HANDLE)vcm, SessionId, pVirtualName, flags);
1500 freerdp_peer* client = vcm->client;
1501 WINPR_ASSERT(client);
1502 WINPR_ASSERT(client->context);
1503 WINPR_ASSERT(client->context->rdp);
1505 rdpMcs* mcs = client->context->rdp->mcs;
1508 for (UINT32 index = 0; index < mcs->channelCount; index++)
1510 rdpMcsChannel* mchannel = &mcs->channels[index];
1511 if (mchannel->joined &&
1512 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1521 SetLastError(ERROR_NOT_FOUND);
1525 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1527 SetLastError(ERROR_NOT_READY);
1531 WINPR_ASSERT(client);
1532 WINPR_ASSERT(client->context);
1533 WINPR_ASSERT(client->context->settings);
1535 const UINT32 VCChunkSize =
1538 channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName, flags);
1542 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1546 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1547 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1549 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1551 channel_free(channel);
1555 s = Stream_New(
nullptr, 64);
1560 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1564 const size_t pos = Stream_GetPosition(s);
1565 WINPR_ASSERT(pos <= UINT32_MAX);
1566 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char), (UINT32)pos,
1572 Stream_Free(s, TRUE);
1573 HashTable_Unlock(g_ServerHandles);
1577 Stream_Free(s, TRUE);
1579 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1580 HashTable_Unlock(g_ServerHandles);
1582 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1586BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1589 rdpMcs* mcs =
nullptr;
1591 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1599 WINPR_ASSERT(vcm->client);
1600 WINPR_ASSERT(vcm->client->context);
1601 WINPR_ASSERT(vcm->client->context->rdp);
1602 mcs = vcm->client->context->rdp->mcs;
1604 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1606 if (channel->index < mcs->channelCount)
1608 rdpMcsChannel* cur = &mcs->channels[channel->index];
1609 rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
1610 channel_free(peerChannel);
1611 cur->handle =
nullptr;
1616 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1619 s = Stream_New(
nullptr, 8);
1623 WLog_ERR(TAG,
"Stream_New failed!");
1628 wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
1630 const size_t pos = Stream_GetPosition(s);
1631 WINPR_ASSERT(pos <= UINT32_MAX);
1632 ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char),
1633 (UINT32)pos, &written);
1634 Stream_Free(s, TRUE);
1637 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1644BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut,
1645 PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
1647 BYTE* buffer =
nullptr;
1648 wMessage message = WINPR_C_ARRAY_INIT;
1649 wtsChannelMessage* messageCtx =
nullptr;
1650 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1652 WINPR_ASSERT(channel);
1654 if (!MessageQueue_Peek(channel->queue, &message, FALSE))
1656 SetLastError(ERROR_NO_DATA);
1661 messageCtx = message.context;
1663 if (messageCtx ==
nullptr)
1666 buffer = (BYTE*)(messageCtx + 1);
1667 *pBytesRead = messageCtx->length - messageCtx->offset;
1669 if (Buffer ==
nullptr || BufferSize == 0)
1674 if (*pBytesRead > BufferSize)
1675 *pBytesRead = BufferSize;
1677 CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
1678 messageCtx->offset += *pBytesRead;
1680 if (messageCtx->offset >= messageCtx->length)
1682 const int rc = MessageQueue_Peek(channel->queue, &message, TRUE);
1683 peer_channel_queue_free_message(&message);
1691BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength,
1692 PULONG pBytesWritten)
1698 BYTE* buffer =
nullptr;
1699 size_t totalWritten = 0;
1700 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1706 EnterCriticalSection(&channel->writeLock);
1707 WINPR_ASSERT(channel->vcm);
1708 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1710 buffer = (BYTE*)malloc(uLength);
1714 SetLastError(g_err_oom);
1718 CopyMemory(buffer, Buffer, uLength);
1719 totalWritten = uLength;
1720 if (!wts_queue_send_item(channel, buffer, uLength))
1723 else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
1725 DEBUG_DVC(
"drdynvc not ready");
1732 size_t Length = uLength;
1735 s = Stream_New(
nullptr, DVC_MAX_DATA_PDU_SIZE);
1739 WLog_ERR(TAG,
"Stream_New failed!");
1740 SetLastError(g_err_oom);
1744 buffer = Stream_Buffer(s);
1745 Stream_Seek_UINT8(s);
1746 cbChId = wts_write_variable_uint(s, channel->channelId);
1748 if (first && (Length > Stream_GetRemainingLength(s)))
1750 cbLen = wts_write_variable_uint(s, WINPR_ASSERTING_INT_CAST(uint32_t, Length));
1751 buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF;
1755 buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
1759 size_t written = Stream_GetRemainingLength(s);
1761 if (written > Length)
1764 Stream_Write(s, Buffer, written);
1765 const size_t length = Stream_GetPosition(s);
1766 Stream_Free(s, FALSE);
1767 if (length > UINT32_MAX)
1771 totalWritten += written;
1772 if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
1778 *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten);
1782 LeaveCriticalSection(&channel->writeLock);
1786BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1788 WLog_ERR(
"TODO",
"TODO: implement");
1792BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1794 WLog_ERR(
"TODO",
"TODO: implement");
1798BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
1799 PVOID* ppBuffer, DWORD* pBytesReturned)
1801 void* pfd =
nullptr;
1803 void* fds[10] = WINPR_C_ARRAY_INIT;
1804 HANDLE hEvent =
nullptr;
1806 BOOL status = FALSE;
1807 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1809 WINPR_ASSERT(channel);
1811 switch ((UINT32)WtsVirtualClass)
1813 case WTSVirtualFileHandle:
1814 hEvent = MessageQueue_Event(channel->queue);
1815 pfd = GetEventWaitObject(hEvent);
1819 fds[fds_count] = pfd;
1823 *ppBuffer = malloc(
sizeof(
void*));
1827 SetLastError(g_err_oom);
1831 CopyMemory(*ppBuffer, (
void*)&fds[0],
sizeof(
void*));
1832 *pBytesReturned =
sizeof(
void*);
1838 case WTSVirtualEventHandle:
1839 hEvent = MessageQueue_Event(channel->queue);
1841 *ppBuffer = malloc(
sizeof(HANDLE));
1845 SetLastError(g_err_oom);
1849 CopyMemory(*ppBuffer, (
void*)&hEvent,
sizeof(HANDLE));
1850 *pBytesReturned =
sizeof(
void*);
1856 case WTSVirtualChannelReady:
1857 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1864 switch (channel->dvc_open_state)
1866 case DVC_OPEN_STATE_NONE:
1871 case DVC_OPEN_STATE_SUCCEEDED:
1877 *ppBuffer =
nullptr;
1878 *pBytesReturned = 0;
1883 *ppBuffer = malloc(
sizeof(BOOL));
1887 SetLastError(g_err_oom);
1892 CopyMemory(*ppBuffer, &bval,
sizeof(BOOL));
1893 *pBytesReturned =
sizeof(BOOL);
1897 case WTSVirtualChannelOpenStatus:
1899 INT32 value = channel->creationStatus;
1902 *ppBuffer = malloc(
sizeof(value));
1905 SetLastError(g_err_oom);
1910 CopyMemory(*ppBuffer, &value,
sizeof(value));
1911 *pBytesReturned =
sizeof(value);
1922VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
1927BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1928 WINPR_ATTR_UNUSED PVOID pMemory,
1929 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1931 WLog_ERR(
"TODO",
"TODO: implement");
1935BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1936 WINPR_ATTR_UNUSED PVOID pMemory,
1937 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1939 WLog_ERR(
"TODO",
"TODO: implement");
1943BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd,
1944 WINPR_ATTR_UNUSED DWORD dwFlags)
1946 WLog_ERR(
"TODO",
"TODO: implement");
1950BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd)
1952 WLog_ERR(
"TODO",
"TODO: implement");
1956BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1957 WINPR_ATTR_UNUSED HWND hWnd,
1958 WINPR_ATTR_UNUSED DWORD dwFlags)
1960 WLog_ERR(
"TODO",
"TODO: implement");
1964BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1965 WINPR_ATTR_UNUSED HWND hWnd)
1967 WLog_ERR(
"TODO",
"TODO: implement");
1971BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId,
1972 WINPR_ATTR_UNUSED PHANDLE phToken)
1974 WLog_ERR(
"TODO",
"TODO: implement");
1978BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(WINPR_ATTR_UNUSED HANDLE hServer,
1979 WINPR_ATTR_UNUSED DWORD* pLevel,
1980 WINPR_ATTR_UNUSED DWORD SessionId,
1981 WINPR_ATTR_UNUSED LPWSTR* ppProcessInfo,
1982 WINPR_ATTR_UNUSED DWORD* pCount)
1984 WLog_ERR(
"TODO",
"TODO: implement");
1988BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(WINPR_ATTR_UNUSED HANDLE hServer,
1989 WINPR_ATTR_UNUSED DWORD* pLevel,
1990 WINPR_ATTR_UNUSED DWORD SessionId,
1991 WINPR_ATTR_UNUSED LPSTR* ppProcessInfo,
1992 WINPR_ATTR_UNUSED DWORD* pCount)
1994 WLog_ERR(
"TODO",
"TODO: implement");
1998BOOL WINAPI FreeRDP_WTSEnumerateListenersW(WINPR_ATTR_UNUSED HANDLE hServer,
1999 WINPR_ATTR_UNUSED PVOID pReserved,
2000 WINPR_ATTR_UNUSED DWORD Reserved,
2001 WINPR_ATTR_UNUSED PWTSLISTENERNAMEW pListeners,
2002 WINPR_ATTR_UNUSED DWORD* pCount)
2004 WLog_ERR(
"TODO",
"TODO: implement");
2008BOOL WINAPI FreeRDP_WTSEnumerateListenersA(WINPR_ATTR_UNUSED HANDLE hServer,
2009 WINPR_ATTR_UNUSED PVOID pReserved,
2010 WINPR_ATTR_UNUSED DWORD Reserved,
2011 WINPR_ATTR_UNUSED PWTSLISTENERNAMEA pListeners,
2012 WINPR_ATTR_UNUSED DWORD* pCount)
2014 WLog_ERR(
"TODO",
"TODO: implement");
2018BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(WINPR_ATTR_UNUSED HANDLE hServer,
2019 WINPR_ATTR_UNUSED PVOID pReserved,
2020 WINPR_ATTR_UNUSED DWORD Reserved,
2021 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2024 WLog_ERR(
"TODO",
"TODO: implement");
2028BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(WINPR_ATTR_UNUSED HANDLE hServer,
2029 WINPR_ATTR_UNUSED PVOID pReserved,
2030 WINPR_ATTR_UNUSED DWORD Reserved,
2031 WINPR_ATTR_UNUSED LPSTR pListenerName,
2034 WLog_ERR(
"TODO",
"TODO: implement");
2038BOOL WINAPI FreeRDP_WTSCreateListenerW(WINPR_ATTR_UNUSED HANDLE hServer,
2039 WINPR_ATTR_UNUSED PVOID pReserved,
2040 WINPR_ATTR_UNUSED DWORD Reserved,
2041 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2043 WINPR_ATTR_UNUSED DWORD flag)
2045 WLog_ERR(
"TODO",
"TODO: implement");
2049BOOL WINAPI FreeRDP_WTSCreateListenerA(WINPR_ATTR_UNUSED HANDLE hServer,
2050 WINPR_ATTR_UNUSED PVOID pReserved,
2051 WINPR_ATTR_UNUSED DWORD Reserved,
2052 WINPR_ATTR_UNUSED LPSTR pListenerName,
2054 WINPR_ATTR_UNUSED DWORD flag)
2056 WLog_ERR(
"TODO",
"TODO: implement");
2060BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(
2061 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2062 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2063 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2064 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2066 WLog_ERR(
"TODO",
"TODO: implement");
2070BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(
2071 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2072 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2073 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2074 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2076 WLog_ERR(
"TODO",
"TODO: implement");
2080BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(
2081 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2082 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2083 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2084 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2085 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2087 WLog_ERR(
"TODO",
"TODO: implement");
2091BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(
2092 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2093 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2094 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2095 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2096 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2098 WLog_ERR(
"TODO",
"TODO: implement");
2102BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable)
2104 WLog_ERR(
"TODO",
"TODO: implement");
2108BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled)
2110 WLog_ERR(
"TODO",
"TODO: implement");
2114BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId)
2116 WLog_ERR(
"TODO",
"TODO: implement");
2120DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(
void)
2122 WLog_ERR(
"TODO",
"TODO: implement");
2125BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer)
2127 WLog_ERR(
"TODO",
"TODO: implement");
2131BOOL WINAPI FreeRDP_WTSLogonUser(WINPR_ATTR_UNUSED HANDLE hServer,
2132 WINPR_ATTR_UNUSED LPCSTR username,
2133 WINPR_ATTR_UNUSED LPCSTR password, WINPR_ATTR_UNUSED LPCSTR domain)
2135 WLog_ERR(
"TODO",
"TODO: implement");
2139void server_channel_common_free(rdpPeerChannel* channel)
2143 MessageQueue_Free(channel->queue);
2144 Stream_Free(channel->receiveData, TRUE);
2145 DeleteCriticalSection(&channel->writeLock);
2149rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
2150 size_t chunkSize,
const wObject* callback,
2153 rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1,
sizeof(rdpPeerChannel));
2157 InitializeCriticalSection(&channel->writeLock);
2159 channel->receiveData = Stream_New(
nullptr, chunkSize);
2160 if (!channel->receiveData)
2163 channel->queue = MessageQueue_New(callback);
2164 if (!channel->queue)
2167 channel->index = index;
2168 channel->client = client;
2169 channel->channelId = channelId;
2170 strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
2173 WINPR_PRAGMA_DIAG_PUSH
2174 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2175 server_channel_common_free(channel);
2176 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
WINPR_ATTR_NODISCARD OBJECT_EQUALS_FN fnObjectEquals