22#include <freerdp/config.h>
29#include <winpr/atexit.h>
30#include <winpr/wtypes.h>
32#include <winpr/synch.h>
33#include <winpr/stream.h>
34#include <winpr/assert.h>
35#include <winpr/cast.h>
37#include <freerdp/log.h>
38#include <freerdp/constants.h>
39#include <freerdp/server/channels.h>
40#include <freerdp/channels/drdynvc.h>
41#include <freerdp/utils/drdynvc.h>
47#define TAG FREERDP_TAG("core.server")
49#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
51#define DEBUG_DVC(...) \
57#define DVC_MAX_DATA_PDU_SIZE 1600
67static const DWORD g_err_oom = WINPR_CXX_COMPAT_CAST(DWORD, E_OUTOFMEMORY);
69static DWORD g_SessionId = 1;
70static wHashTable* g_ServerHandles =
nullptr;
71static INIT_ONCE g_HandleInitializer = INIT_ONCE_STATIC_INIT;
76 return HashTable_GetItemValue(vcm->dynamicVirtualChannels, &ChannelId);
79static BOOL wts_queue_receive_data(rdpPeerChannel* channel,
const BYTE* Buffer, UINT32 Length)
81 BYTE* buffer =
nullptr;
82 wtsChannelMessage* messageCtx =
nullptr;
84 WINPR_ASSERT(channel);
85 messageCtx = (wtsChannelMessage*)malloc(
sizeof(wtsChannelMessage) + Length);
90 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
91 messageCtx->channelId = (UINT16)channel->channelId;
92 messageCtx->length = Length;
93 messageCtx->offset = 0;
94 buffer = (BYTE*)(messageCtx + 1);
95 CopyMemory(buffer, Buffer, Length);
96 return MessageQueue_Post(channel->queue, messageCtx, 0,
nullptr,
nullptr);
99static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
101 BYTE* buffer =
nullptr;
104 WINPR_ASSERT(channel);
105 WINPR_ASSERT(channel->vcm);
109 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
110 const UINT16 channelId = (UINT16)channel->channelId;
111 return MessageQueue_Post(channel->vcm->queue, (
void*)(UINT_PTR)channelId, 0, (
void*)buffer,
112 (
void*)(UINT_PTR)length);
115static unsigned wts_read_variable_uint(
wStream* s,
int cbLen, UINT32* val)
122 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
125 Stream_Read_UINT8(s, *val);
129 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
132 Stream_Read_UINT16(s, *val);
136 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
139 Stream_Read_UINT32(s, *val);
143 WLog_ERR(TAG,
"invalid wts variable uint len %d", cbLen);
148static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
152 WINPR_ASSERT(channel);
153 WINPR_ASSERT(channel->vcm);
157 Stream_Seek_UINT8(channel->receiveData);
158 Stream_Read_UINT16(channel->receiveData, Version);
159 DEBUG_DVC(
"Version: %" PRIu16
"", Version);
163 WLog_ERR(TAG,
"invalid version %" PRIu16
" for DRDYNVC", Version);
168 vcm->drdynvc_state = DRDYNVC_STATE_READY;
171 vcm->dvc_spoken_version = MAX(Version, 1);
173 return SetEvent(MessageQueue_Event(vcm->queue));
176static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel,
wStream* s, UINT32 length)
178 UINT32 CreationStatus = 0;
181 WINPR_ASSERT(channel);
186 Stream_Read_UINT32(s, CreationStatus);
188 if ((INT32)CreationStatus < 0)
190 DEBUG_DVC(
"ChannelId %" PRIu32
" creation failed (%" PRId32
")", channel->channelId,
191 (INT32)CreationStatus);
192 channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
196 DEBUG_DVC(
"ChannelId %" PRIu32
" creation succeeded", channel->channelId);
197 channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
200 channel->creationStatus = (INT32)CreationStatus;
201 IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata,
202 channel->channelId, (INT32)CreationStatus);
204 WLog_ERR(TAG,
"vcm->dvc_creation_status failed!");
209static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel,
wStream* s,
int cbLen,
212 WINPR_ASSERT(channel);
214 const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
223 if (length > channel->dvc_total_length)
226 Stream_ResetPosition(channel->receiveData);
228 if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
231 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
235static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel,
wStream* s, UINT32 length)
239 WINPR_ASSERT(channel);
241 if (channel->dvc_total_length > 0)
243 if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
245 channel->dvc_total_length = 0;
246 WLog_ERR(TAG,
"incorrect fragment data, discarded.");
250 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
252 if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
254 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
255 channel->dvc_total_length);
256 channel->dvc_total_length = 0;
263 ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length);
269static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
271 WINPR_ASSERT(channel);
272 DEBUG_DVC(
"ChannelId %" PRIu32
" close response", channel->channelId);
273 channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
274 MessageQueue_PostQuit(channel->queue, 0);
277static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
282 UINT32 ChannelId = 0;
283 rdpPeerChannel* dvc =
nullptr;
285 WINPR_ASSERT(channel);
286 WINPR_ASSERT(channel->vcm);
288 size_t length = Stream_GetPosition(channel->receiveData);
290 if ((length < 1) || (length > UINT32_MAX))
293 Stream_ResetPosition(channel->receiveData);
294 const UINT8 value = Stream_Get_UINT8(channel->receiveData);
296 Cmd = (value & 0xf0) >> 4;
297 Sp = (value & 0x0c) >> 2;
298 cbChId = (value & 0x03) >> 0;
300 if (Cmd == CAPABILITY_REQUEST_PDU)
301 return wts_read_drdynvc_capabilities_response(channel, (UINT32)length);
303 if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
305 BOOL haveChannelId = 0;
308 case SOFT_SYNC_REQUEST_PDU:
309 case SOFT_SYNC_RESPONSE_PDU:
310 haveChannelId = FALSE;
313 haveChannelId = TRUE;
319 const unsigned val = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId);
325 DEBUG_DVC(
"Cmd %s ChannelId %" PRIu32
" length %" PRIuz
"",
326 drdynvc_get_packet_type(Cmd), ChannelId, length);
327 dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
330 DEBUG_DVC(
"ChannelId %" PRIu32
" does not exist.", ChannelId);
337 case CREATE_REQUEST_PDU:
338 return wts_read_drdynvc_create_response(dvc, channel->receiveData, (UINT32)length);
341 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
344 "ChannelId %" PRIu32
" did not open successfully. "
345 "Ignoring DYNVC_DATA_FIRST PDU",
350 return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, (UINT32)length);
353 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
356 "ChannelId %" PRIu32
" did not open successfully. "
357 "Ignoring DYNVC_DATA PDU",
362 return wts_read_drdynvc_data(dvc, channel->receiveData, (UINT32)length);
364 case CLOSE_REQUEST_PDU:
365 wts_read_drdynvc_close_response(dvc);
368 case DATA_FIRST_COMPRESSED_PDU:
369 case DATA_COMPRESSED_PDU:
370 WLog_ERR(TAG,
"Compressed data not handled");
373 case SOFT_SYNC_RESPONSE_PDU:
374 WLog_ERR(TAG,
"SoftSync response not handled yet(and rather strange to receive "
375 "that packet as our code doesn't send SoftSync requests");
378 case SOFT_SYNC_REQUEST_PDU:
379 WLog_ERR(TAG,
"Not expecting a SoftSyncRequest on the server");
383 WLog_ERR(TAG,
"Cmd %d not recognized.", Cmd);
389 WLog_ERR(TAG,
"received Cmd %d but channel is not ready.", Cmd);
395static int wts_write_variable_uint(
wStream* s, UINT32 val)
403 Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val));
405 else if (val <= 0xFFFF)
408 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val));
413 Stream_Write_UINT32(s, val);
419static void wts_write_drdynvc_header(
wStream* s, BYTE Cmd, UINT32 ChannelId)
423 BYTE* bm = Stream_PointerAs(s, BYTE);
424 Stream_Seek_UINT8(s);
425 const int cbChId = wts_write_variable_uint(s, ChannelId);
426 *bm = (((Cmd & 0x0F) << 4) | cbChId) & 0xFF;
429static BOOL wts_write_drdynvc_create_request(
wStream* s, UINT32 ChannelId,
const char* ChannelName)
434 WINPR_ASSERT(ChannelName);
436 wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
437 len = strlen(ChannelName) + 1;
439 if (!Stream_EnsureRemainingCapacity(s, len))
442 Stream_Write(s, ChannelName, len);
446static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId,
const BYTE* data,
447 size_t s, UINT32 flags,
size_t t)
450 const size_t size = s;
451 const size_t totalSize = t;
453 WINPR_ASSERT(channel);
454 WINPR_ASSERT(channel->vcm);
455 WINPR_UNUSED(channelId);
457 if (flags & CHANNEL_FLAG_FIRST)
459 Stream_ResetPosition(channel->receiveData);
462 if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
465 Stream_Write(channel->receiveData, data, size);
467 if (flags & CHANNEL_FLAG_LAST)
469 if (Stream_GetPosition(channel->receiveData) != totalSize)
471 WLog_ERR(TAG,
"read error");
474 if (channel == channel->vcm->drdynvc_channel)
476 ret = wts_read_drdynvc_pdu(channel);
480 const size_t pos = Stream_GetPosition(channel->receiveData);
481 if (pos > UINT32_MAX)
484 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
488 Stream_ResetPosition(channel->receiveData);
494static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId,
const BYTE* data,
495 size_t size, UINT32 flags,
size_t totalSize)
497 rdpMcs* mcs =
nullptr;
499 WINPR_ASSERT(client);
500 WINPR_ASSERT(client->context);
501 WINPR_ASSERT(client->context->rdp);
503 mcs = client->context->rdp->mcs;
506 for (UINT32 i = 0; i < mcs->channelCount; i++)
508 rdpMcsChannel* cur = &mcs->channels[i];
509 if (cur->ChannelId == channelId)
511 rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
514 return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
518 WLog_WARN(TAG,
"unknown channelId %" PRIu16
" ignored", channelId);
523#if defined(WITH_FREERDP_DEPRECATED)
524void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer,
void** fds,
int* fds_count)
530 WINPR_ASSERT(fds_count);
532 fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
536 fds[*fds_count] = fd;
542 if (vcm->drdynvc_channel)
544 fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
548 fds[*fds_count] = fd;
557BOOL WTSVirtualChannelManagerOpen(HANDLE hServer)
564 if (vcm->drdynvc_state == DRDYNVC_STATE_NONE)
566 rdpPeerChannel* channel =
nullptr;
569 vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
570 channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
571 DRDYNVC_SVC_CHANNEL_NAME);
575 BYTE capaBuffer[12] = WINPR_C_ARRAY_INIT;
576 wStream staticS = WINPR_C_ARRAY_INIT;
577 wStream* s = Stream_StaticInit(&staticS, capaBuffer,
sizeof(capaBuffer));
579 vcm->drdynvc_channel = channel;
580 vcm->dvc_spoken_version = 1;
581 Stream_Write_UINT8(s, 0x50);
582 Stream_Write_UINT8(s, 0x00);
583 Stream_Write_UINT16(s, 0x0001);
587 const size_t pos = Stream_GetPosition(s);
588 WINPR_ASSERT(pos <= UINT32_MAX);
590 if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written))
598BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
600 wMessage message = WINPR_C_ARRAY_INIT;
604 if (!hServer || hServer == INVALID_HANDLE_VALUE)
611 if (!WTSVirtualChannelManagerOpen(hServer))
615 while (MessageQueue_Peek(vcm->queue, &message, TRUE))
617 BYTE* buffer =
nullptr;
619 UINT16 channelId = 0;
620 channelId = (UINT16)(UINT_PTR)message.context;
621 buffer = (BYTE*)message.wParam;
622 length = (UINT32)(UINT_PTR)message.lParam;
624 WINPR_ASSERT(vcm->client);
625 WINPR_ASSERT(vcm->client->SendChannelData);
626 if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
640BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
642 return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
645HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
649 return MessageQueue_Event(vcm->queue);
652static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs,
const char* channel_name)
654 if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
657 for (UINT32 index = 0; index < mcs->channelCount; index++)
659 rdpMcsChannel* mchannel = &mcs->channels[index];
660 if (mchannel->joined)
662 if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
670static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs,
const UINT16 channel_id)
672 if (!mcs || !channel_id)
675 WINPR_ASSERT(mcs->channels);
676 for (UINT32 index = 0; index < mcs->channelCount; index++)
678 rdpMcsChannel* mchannel = &mcs->channels[index];
679 if (mchannel->joined)
681 if (mchannel->ChannelId == channel_id)
682 return &mcs->channels[index];
689BOOL WTSIsChannelJoinedByName(freerdp_peer* client,
const char* channel_name)
691 if (!client || !client->context || !client->context->rdp)
694 return (wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) !=
nullptr);
697BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
699 if (!client || !client->context || !client->context->rdp)
702 return (wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) !=
nullptr);
705BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer,
const char* name)
709 if (!vcm || !vcm->rdp)
712 return (wts_get_joined_channel_by_name(vcm->rdp->mcs, name) !=
nullptr);
715BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
719 return vcm->drdynvc_state;
722void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
729 vcm->dvc_creation_status = cb;
730 vcm->dvc_creation_status_userdata = userdata;
733UINT16 WTSChannelGetId(freerdp_peer* client,
const char* channel_name)
735 rdpMcsChannel* channel =
nullptr;
737 WINPR_ASSERT(channel_name);
738 if (!client || !client->context || !client->context->rdp)
741 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
746 return channel->ChannelId;
749UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
751 rdpPeerChannel* channel = hChannelHandle;
753 WINPR_ASSERT(channel);
755 return channel->channelId;
758BOOL WTSChannelSetHandleByName(freerdp_peer* client,
const char* channel_name,
void* handle)
760 rdpMcsChannel* channel =
nullptr;
762 WINPR_ASSERT(channel_name);
763 if (!client || !client->context || !client->context->rdp)
766 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
771 channel->handle = handle;
775BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id,
void* handle)
777 rdpMcsChannel* channel =
nullptr;
779 if (!client || !client->context || !client->context->rdp)
782 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
787 channel->handle = handle;
791void* WTSChannelGetHandleByName(freerdp_peer* client,
const char* channel_name)
793 rdpMcsChannel* channel =
nullptr;
795 WINPR_ASSERT(channel_name);
796 if (!client || !client->context || !client->context->rdp)
799 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
804 return channel->handle;
807void* WTSChannelGetHandleById(freerdp_peer* client, UINT16 channel_id)
809 rdpMcsChannel* channel =
nullptr;
811 if (!client || !client->context || !client->context->rdp)
814 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
819 return channel->handle;
822const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
824 rdpMcsChannel* channel =
nullptr;
826 if (!client || !client->context || !client->context->rdp)
829 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
834 return (
const char*)channel->Name;
837char** WTSGetAcceptedChannelNames(freerdp_peer* client,
size_t* count)
839 rdpMcs* mcs =
nullptr;
840 char** names =
nullptr;
842 if (!client || !client->context || !count)
845 WINPR_ASSERT(client->context->rdp);
846 mcs = client->context->rdp->mcs;
848 *count = mcs->channelCount;
850 names = (
char**)calloc(mcs->channelCount,
sizeof(
char*));
854 for (UINT32 index = 0; index < mcs->channelCount; index++)
856 rdpMcsChannel* mchannel = &mcs->channels[index];
857 names[index] = mchannel->Name;
863INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
865 rdpMcsChannel* channel =
nullptr;
867 if (!client || !client->context || !client->context->rdp)
870 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
875 return (INT64)channel->options;
878BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
879 WINPR_ATTR_UNUSED ULONG TargetLogonId,
880 WINPR_ATTR_UNUSED BYTE HotkeyVk,
881 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
883 WLog_ERR(
"TODO",
"TODO: implement");
887BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
888 WINPR_ATTR_UNUSED ULONG TargetLogonId,
889 WINPR_ATTR_UNUSED BYTE HotkeyVk,
890 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
892 WLog_ERR(
"TODO",
"TODO: implement");
896BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
897 WINPR_ATTR_UNUSED ULONG TargetLogonId,
898 WINPR_ATTR_UNUSED BYTE HotkeyVk,
899 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
900 WINPR_ATTR_UNUSED DWORD flags)
902 WLog_ERR(
"TODO",
"TODO: implement");
906BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
907 WINPR_ATTR_UNUSED ULONG TargetLogonId,
908 WINPR_ATTR_UNUSED BYTE HotkeyVk,
909 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
910 WINPR_ATTR_UNUSED DWORD flags)
912 WLog_ERR(
"TODO",
"TODO: implement");
916BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId)
918 WLog_ERR(
"TODO",
"TODO: implement");
922BOOL WINAPI FreeRDP_WTSConnectSessionW(WINPR_ATTR_UNUSED ULONG LogonId,
923 WINPR_ATTR_UNUSED ULONG TargetLogonId,
924 WINPR_ATTR_UNUSED PWSTR pPassword,
925 WINPR_ATTR_UNUSED BOOL bWait)
927 WLog_ERR(
"TODO",
"TODO: implement");
931BOOL WINAPI FreeRDP_WTSConnectSessionA(WINPR_ATTR_UNUSED ULONG LogonId,
932 WINPR_ATTR_UNUSED ULONG TargetLogonId,
933 WINPR_ATTR_UNUSED PSTR pPassword,
934 WINPR_ATTR_UNUSED BOOL bWait)
936 WLog_ERR(
"TODO",
"TODO: implement");
940BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName,
941 WINPR_ATTR_UNUSED DWORD Reserved,
942 WINPR_ATTR_UNUSED DWORD Version,
944 WINPR_ATTR_UNUSED DWORD* pCount)
946 WLog_ERR(
"TODO",
"TODO: implement");
950BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName,
951 WINPR_ATTR_UNUSED DWORD Reserved,
952 WINPR_ATTR_UNUSED DWORD Version,
954 WINPR_ATTR_UNUSED DWORD* pCount)
956 WLog_ERR(
"TODO",
"TODO: implement");
960HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName)
962 WLog_ERR(
"TODO",
"TODO: implement");
963 return INVALID_HANDLE_VALUE;
966static void wts_virtual_channel_manager_free_message(
void* obj)
968 wMessage* msg = (wMessage*)obj;
972 BYTE* buffer = (BYTE*)msg->wParam;
979static void channel_free(rdpPeerChannel* channel)
981 server_channel_common_free(channel);
984static void array_channel_free(
void* ptr)
986 rdpPeerChannel* channel = ptr;
987 channel_free(channel);
990static BOOL dynChannelMatch(
const void* v1,
const void* v2)
992 const UINT32* p1 = (
const UINT32*)v1;
993 const UINT32* p2 = (
const UINT32*)v2;
997static UINT32 channelId_Hash(
const void* key)
999 const UINT32* v = (
const UINT32*)key;
1003static void clearHandles(
void)
1005 HashTable_Free(g_ServerHandles);
1006 g_ServerHandles =
nullptr;
1009static BOOL CALLBACK initializeHandles(WINPR_ATTR_UNUSED
PINIT_ONCE once,
1010 WINPR_ATTR_UNUSED PVOID param,
1011 WINPR_ATTR_UNUSED PVOID* context)
1013 WINPR_ASSERT(g_ServerHandles ==
nullptr);
1014 g_ServerHandles = HashTable_New(TRUE);
1015 (void)winpr_atexit(clearHandles);
1016 return g_ServerHandles !=
nullptr;
1019static bool setup(
void)
1021 return InitOnceExecuteOnce(&g_HandleInitializer, initializeHandles,
nullptr,
nullptr);
1028 HashTable_Lock(g_ServerHandles);
1032#ifdef __clang_analyzer__
1033 const BOOL valid = vcm !=
nullptr;
1035 const BOOL valid = (vcm !=
nullptr) && (vcm != INVALID_HANDLE_VALUE);
1039 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1041 HashTable_Free(vcm->dynamicVirtualChannels);
1043 if (vcm->drdynvc_channel)
1046 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1047 vcm->drdynvc_channel =
nullptr;
1050 MessageQueue_Free(vcm->queue);
1053 HashTable_Unlock(g_ServerHandles);
1056HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1058 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1060 rdpContext* context = (rdpContext*)pServerName;
1062 if (!setup() || !context)
1063 return INVALID_HANDLE_VALUE;
1065 freerdp_peer* client = context->peer;
1069 SetLastError(ERROR_INVALID_DATA);
1070 return INVALID_HANDLE_VALUE;
1078 vcm->client = client;
1079 vcm->rdp = context->rdp;
1081 queueCallbacks.
fnObjectFree = wts_virtual_channel_manager_free_message;
1082 vcm->queue = MessageQueue_New(&queueCallbacks);
1087 vcm->dvc_channel_id_seq = 0;
1088 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1090 if (!vcm->dynamicVirtualChannels)
1093 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1097 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1101 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1104 client->ReceiveChannelData = WTSReceiveChannelData;
1106 HashTable_Lock(g_ServerHandles);
1107 vcm->SessionId = g_SessionId++;
1109 HashTable_Insert(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId, (
void*)vcm);
1110 HashTable_Unlock(g_ServerHandles);
1115 HANDLE hServer = (HANDLE)vcm;
1119 wtsCloseVCM(vcm,
false);
1120 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1121 return INVALID_HANDLE_VALUE;
1124HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1126 WLog_ERR(
"TODO",
"TODO: implement");
1127 return INVALID_HANDLE_VALUE;
1130HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1132 return FreeRDP_WTSOpenServerA(pServerName);
1135VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1138 wtsCloseVCM(vcm,
true);
1141BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1142 WINPR_ATTR_UNUSED DWORD Reserved,
1143 WINPR_ATTR_UNUSED DWORD Version,
1145 WINPR_ATTR_UNUSED DWORD* pCount)
1147 WLog_ERR(
"TODO",
"TODO: implement");
1151BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1152 WINPR_ATTR_UNUSED DWORD Reserved,
1153 WINPR_ATTR_UNUSED DWORD Version,
1155 WINPR_ATTR_UNUSED DWORD* pCount)
1157 WLog_ERR(
"TODO",
"TODO: implement");
1161BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1162 WINPR_ATTR_UNUSED DWORD* pLevel,
1163 WINPR_ATTR_UNUSED DWORD Filter,
1165 WINPR_ATTR_UNUSED DWORD* pCount)
1167 WLog_ERR(
"TODO",
"TODO: implement");
1171BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1172 WINPR_ATTR_UNUSED DWORD* pLevel,
1173 WINPR_ATTR_UNUSED DWORD Filter,
1175 WINPR_ATTR_UNUSED DWORD* pCount)
1177 WLog_ERR(
"TODO",
"TODO: implement");
1181BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1182 WINPR_ATTR_UNUSED DWORD Reserved,
1183 WINPR_ATTR_UNUSED DWORD Version,
1185 WINPR_ATTR_UNUSED DWORD* pCount)
1187 WLog_ERR(
"TODO",
"TODO: implement");
1191BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1192 WINPR_ATTR_UNUSED DWORD Reserved,
1193 WINPR_ATTR_UNUSED DWORD Version,
1195 WINPR_ATTR_UNUSED DWORD* pCount)
1197 WLog_ERR(
"TODO",
"TODO: implement");
1201BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1202 WINPR_ATTR_UNUSED DWORD ProcessId,
1203 WINPR_ATTR_UNUSED DWORD ExitCode)
1205 WLog_ERR(
"TODO",
"TODO: implement");
1209BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1210 WINPR_ATTR_UNUSED DWORD SessionId,
1211 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1212 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1213 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1215 WLog_ERR(
"TODO",
"TODO: implement");
1219BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1220 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1221 DWORD* pBytesReturned)
1223 DWORD BytesReturned = 0;
1230 if (WTSInfoClass == WTSSessionId)
1232 ULONG* pBuffer =
nullptr;
1233 BytesReturned =
sizeof(ULONG);
1234 pBuffer = (ULONG*)malloc(
sizeof(BytesReturned));
1238 SetLastError(g_err_oom);
1242 *pBuffer = vcm->SessionId;
1243 *ppBuffer = (LPSTR)pBuffer;
1244 *pBytesReturned = BytesReturned;
1251BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1252 WINPR_ATTR_UNUSED LPWSTR pUserName,
1253 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1254 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1255 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1257 WLog_ERR(
"TODO",
"TODO: implement");
1261BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1262 WINPR_ATTR_UNUSED LPSTR pUserName,
1263 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1264 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1265 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1267 WLog_ERR(
"TODO",
"TODO: implement");
1271BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1272 WINPR_ATTR_UNUSED LPWSTR pUserName,
1273 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1274 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1275 WINPR_ATTR_UNUSED DWORD DataLength)
1277 WLog_ERR(
"TODO",
"TODO: implement");
1281BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1282 WINPR_ATTR_UNUSED LPSTR pUserName,
1283 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1284 WINPR_ATTR_UNUSED LPSTR pBuffer,
1285 WINPR_ATTR_UNUSED DWORD DataLength)
1287 WLog_ERR(
"TODO",
"TODO: implement");
1292FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1293 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1294 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1295 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1296 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1298 WLog_ERR(
"TODO",
"TODO: implement");
1303FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1304 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1305 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1306 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1307 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1309 WLog_ERR(
"TODO",
"TODO: implement");
1313BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1314 WINPR_ATTR_UNUSED DWORD SessionId,
1315 WINPR_ATTR_UNUSED BOOL bWait)
1317 WLog_ERR(
"TODO",
"TODO: implement");
1321BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1322 WINPR_ATTR_UNUSED DWORD SessionId,
1323 WINPR_ATTR_UNUSED BOOL bWait)
1325 WLog_ERR(
"TODO",
"TODO: implement");
1329BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1330 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1332 WLog_ERR(
"TODO",
"TODO: implement");
1336BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1337 WINPR_ATTR_UNUSED DWORD EventMask,
1338 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1340 WLog_ERR(
"TODO",
"TODO: implement");
1344static void peer_channel_queue_free_message(
void* obj)
1346 wMessage* msg = (wMessage*)obj;
1351 msg->context =
nullptr;
1355 UINT32 ChannelId, UINT16 index, UINT16 type,
size_t chunkSize,
1358 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1359 queueCallbacks.
fnObjectFree = peer_channel_queue_free_message;
1361 rdpPeerChannel* channel =
1362 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1365 WINPR_ASSERT(client);
1371 channel->channelType = type;
1372 channel->creationStatus =
1373 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1377 channel_free(channel);
1381HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1385 rdpMcs* mcs =
nullptr;
1386 rdpMcsChannel* joined_channel =
nullptr;
1387 freerdp_peer* client =
nullptr;
1388 rdpPeerChannel* channel =
nullptr;
1390 HANDLE hChannelHandle =
nullptr;
1391 rdpContext* context =
nullptr;
1396 SetLastError(ERROR_INVALID_DATA);
1400 client = vcm->client;
1401 WINPR_ASSERT(client);
1403 context = client->context;
1404 WINPR_ASSERT(context);
1405 WINPR_ASSERT(context->rdp);
1406 WINPR_ASSERT(context->settings);
1408 mcs = context->rdp->mcs;
1411 length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1413 if (length > CHANNEL_NAME_LEN)
1415 SetLastError(ERROR_NOT_FOUND);
1420 for (; index < mcs->channelCount; index++)
1422 rdpMcsChannel* mchannel = &mcs->channels[index];
1423 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1425 joined_channel = mchannel;
1430 if (!joined_channel)
1432 SetLastError(ERROR_NOT_FOUND);
1436 channel = (rdpPeerChannel*)joined_channel->handle;
1440 const UINT32 VCChunkSize =
1443 WINPR_ASSERT(index <= UINT16_MAX);
1444 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1445 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName);
1450 joined_channel->handle = channel;
1453 hChannelHandle = (HANDLE)channel;
1454 return hChannelHandle;
1456 channel_free(channel);
1457 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1461HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1464 rdpPeerChannel* channel =
nullptr;
1465 BOOL joined = FALSE;
1471 if (SessionId == WTS_CURRENT_SESSION)
1474 HashTable_Lock(g_ServerHandles);
1476 g_ServerHandles, (
void*)(UINT_PTR)SessionId);
1481 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1483 HashTable_Unlock(g_ServerHandles);
1484 return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
1487 freerdp_peer* client = vcm->client;
1488 WINPR_ASSERT(client);
1489 WINPR_ASSERT(client->context);
1490 WINPR_ASSERT(client->context->rdp);
1492 rdpMcs* mcs = client->context->rdp->mcs;
1495 for (UINT32 index = 0; index < mcs->channelCount; index++)
1497 rdpMcsChannel* mchannel = &mcs->channels[index];
1498 if (mchannel->joined &&
1499 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1508 SetLastError(ERROR_NOT_FOUND);
1512 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1514 SetLastError(ERROR_NOT_READY);
1518 WINPR_ASSERT(client);
1519 WINPR_ASSERT(client->context);
1520 WINPR_ASSERT(client->context->settings);
1522 const UINT32 VCChunkSize =
1524 channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
1528 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1532 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1533 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1535 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1537 channel_free(channel);
1541 s = Stream_New(
nullptr, 64);
1546 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1550 const size_t pos = Stream_GetPosition(s);
1551 WINPR_ASSERT(pos <= UINT32_MAX);
1552 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char), (UINT32)pos,
1558 Stream_Free(s, TRUE);
1559 HashTable_Unlock(g_ServerHandles);
1563 Stream_Free(s, TRUE);
1565 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1566 HashTable_Unlock(g_ServerHandles);
1568 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1572BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1575 rdpMcs* mcs =
nullptr;
1577 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1585 WINPR_ASSERT(vcm->client);
1586 WINPR_ASSERT(vcm->client->context);
1587 WINPR_ASSERT(vcm->client->context->rdp);
1588 mcs = vcm->client->context->rdp->mcs;
1590 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1592 if (channel->index < mcs->channelCount)
1594 rdpMcsChannel* cur = &mcs->channels[channel->index];
1595 rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
1596 channel_free(peerChannel);
1597 cur->handle =
nullptr;
1602 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1605 s = Stream_New(
nullptr, 8);
1609 WLog_ERR(TAG,
"Stream_New failed!");
1614 wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
1616 const size_t pos = Stream_GetPosition(s);
1617 WINPR_ASSERT(pos <= UINT32_MAX);
1618 ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char),
1619 (UINT32)pos, &written);
1620 Stream_Free(s, TRUE);
1623 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1630BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut,
1631 PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
1633 BYTE* buffer =
nullptr;
1634 wMessage message = WINPR_C_ARRAY_INIT;
1635 wtsChannelMessage* messageCtx =
nullptr;
1636 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1638 WINPR_ASSERT(channel);
1640 if (!MessageQueue_Peek(channel->queue, &message, FALSE))
1642 SetLastError(ERROR_NO_DATA);
1647 messageCtx = message.context;
1649 if (messageCtx ==
nullptr)
1652 buffer = (BYTE*)(messageCtx + 1);
1653 *pBytesRead = messageCtx->length - messageCtx->offset;
1655 if (Buffer ==
nullptr || BufferSize == 0)
1660 if (*pBytesRead > BufferSize)
1661 *pBytesRead = BufferSize;
1663 CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
1664 messageCtx->offset += *pBytesRead;
1666 if (messageCtx->offset >= messageCtx->length)
1668 const int rc = MessageQueue_Peek(channel->queue, &message, TRUE);
1669 peer_channel_queue_free_message(&message);
1677BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength,
1678 PULONG pBytesWritten)
1684 BYTE* buffer =
nullptr;
1685 size_t totalWritten = 0;
1686 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1692 EnterCriticalSection(&channel->writeLock);
1693 WINPR_ASSERT(channel->vcm);
1694 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1696 buffer = (BYTE*)malloc(uLength);
1700 SetLastError(g_err_oom);
1704 CopyMemory(buffer, Buffer, uLength);
1705 totalWritten = uLength;
1706 if (!wts_queue_send_item(channel, buffer, uLength))
1709 else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
1711 DEBUG_DVC(
"drdynvc not ready");
1718 size_t Length = uLength;
1721 s = Stream_New(
nullptr, DVC_MAX_DATA_PDU_SIZE);
1725 WLog_ERR(TAG,
"Stream_New failed!");
1726 SetLastError(g_err_oom);
1730 buffer = Stream_Buffer(s);
1731 Stream_Seek_UINT8(s);
1732 cbChId = wts_write_variable_uint(s, channel->channelId);
1734 if (first && (Length > Stream_GetRemainingLength(s)))
1736 cbLen = wts_write_variable_uint(s, WINPR_ASSERTING_INT_CAST(uint32_t, Length));
1737 buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF;
1741 buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
1745 size_t written = Stream_GetRemainingLength(s);
1747 if (written > Length)
1750 Stream_Write(s, Buffer, written);
1751 const size_t length = Stream_GetPosition(s);
1752 Stream_Free(s, FALSE);
1753 if (length > UINT32_MAX)
1757 totalWritten += written;
1758 if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
1764 *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten);
1768 LeaveCriticalSection(&channel->writeLock);
1772BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1774 WLog_ERR(
"TODO",
"TODO: implement");
1778BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1780 WLog_ERR(
"TODO",
"TODO: implement");
1784BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
1785 PVOID* ppBuffer, DWORD* pBytesReturned)
1787 void* pfd =
nullptr;
1789 void* fds[10] = WINPR_C_ARRAY_INIT;
1790 HANDLE hEvent =
nullptr;
1792 BOOL status = FALSE;
1793 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1795 WINPR_ASSERT(channel);
1797 switch ((UINT32)WtsVirtualClass)
1799 case WTSVirtualFileHandle:
1800 hEvent = MessageQueue_Event(channel->queue);
1801 pfd = GetEventWaitObject(hEvent);
1805 fds[fds_count] = pfd;
1809 *ppBuffer = malloc(
sizeof(
void*));
1813 SetLastError(g_err_oom);
1817 CopyMemory(*ppBuffer, (
void*)&fds[0],
sizeof(
void*));
1818 *pBytesReturned =
sizeof(
void*);
1824 case WTSVirtualEventHandle:
1825 hEvent = MessageQueue_Event(channel->queue);
1827 *ppBuffer = malloc(
sizeof(HANDLE));
1831 SetLastError(g_err_oom);
1835 CopyMemory(*ppBuffer, (
void*)&hEvent,
sizeof(HANDLE));
1836 *pBytesReturned =
sizeof(
void*);
1842 case WTSVirtualChannelReady:
1843 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1850 switch (channel->dvc_open_state)
1852 case DVC_OPEN_STATE_NONE:
1857 case DVC_OPEN_STATE_SUCCEEDED:
1863 *ppBuffer =
nullptr;
1864 *pBytesReturned = 0;
1869 *ppBuffer = malloc(
sizeof(BOOL));
1873 SetLastError(g_err_oom);
1878 CopyMemory(*ppBuffer, &bval,
sizeof(BOOL));
1879 *pBytesReturned =
sizeof(BOOL);
1883 case WTSVirtualChannelOpenStatus:
1885 INT32 value = channel->creationStatus;
1888 *ppBuffer = malloc(
sizeof(value));
1891 SetLastError(g_err_oom);
1896 CopyMemory(*ppBuffer, &value,
sizeof(value));
1897 *pBytesReturned =
sizeof(value);
1908VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
1913BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1914 WINPR_ATTR_UNUSED PVOID pMemory,
1915 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1917 WLog_ERR(
"TODO",
"TODO: implement");
1921BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1922 WINPR_ATTR_UNUSED PVOID pMemory,
1923 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1925 WLog_ERR(
"TODO",
"TODO: implement");
1929BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd,
1930 WINPR_ATTR_UNUSED DWORD dwFlags)
1932 WLog_ERR(
"TODO",
"TODO: implement");
1936BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd)
1938 WLog_ERR(
"TODO",
"TODO: implement");
1942BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1943 WINPR_ATTR_UNUSED HWND hWnd,
1944 WINPR_ATTR_UNUSED DWORD dwFlags)
1946 WLog_ERR(
"TODO",
"TODO: implement");
1950BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1951 WINPR_ATTR_UNUSED HWND hWnd)
1953 WLog_ERR(
"TODO",
"TODO: implement");
1957BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId,
1958 WINPR_ATTR_UNUSED PHANDLE phToken)
1960 WLog_ERR(
"TODO",
"TODO: implement");
1964BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(WINPR_ATTR_UNUSED HANDLE hServer,
1965 WINPR_ATTR_UNUSED DWORD* pLevel,
1966 WINPR_ATTR_UNUSED DWORD SessionId,
1967 WINPR_ATTR_UNUSED LPWSTR* ppProcessInfo,
1968 WINPR_ATTR_UNUSED DWORD* pCount)
1970 WLog_ERR(
"TODO",
"TODO: implement");
1974BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(WINPR_ATTR_UNUSED HANDLE hServer,
1975 WINPR_ATTR_UNUSED DWORD* pLevel,
1976 WINPR_ATTR_UNUSED DWORD SessionId,
1977 WINPR_ATTR_UNUSED LPSTR* ppProcessInfo,
1978 WINPR_ATTR_UNUSED DWORD* pCount)
1980 WLog_ERR(
"TODO",
"TODO: implement");
1984BOOL WINAPI FreeRDP_WTSEnumerateListenersW(WINPR_ATTR_UNUSED HANDLE hServer,
1985 WINPR_ATTR_UNUSED PVOID pReserved,
1986 WINPR_ATTR_UNUSED DWORD Reserved,
1987 WINPR_ATTR_UNUSED PWTSLISTENERNAMEW pListeners,
1988 WINPR_ATTR_UNUSED DWORD* pCount)
1990 WLog_ERR(
"TODO",
"TODO: implement");
1994BOOL WINAPI FreeRDP_WTSEnumerateListenersA(WINPR_ATTR_UNUSED HANDLE hServer,
1995 WINPR_ATTR_UNUSED PVOID pReserved,
1996 WINPR_ATTR_UNUSED DWORD Reserved,
1997 WINPR_ATTR_UNUSED PWTSLISTENERNAMEA pListeners,
1998 WINPR_ATTR_UNUSED DWORD* pCount)
2000 WLog_ERR(
"TODO",
"TODO: implement");
2004BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(WINPR_ATTR_UNUSED HANDLE hServer,
2005 WINPR_ATTR_UNUSED PVOID pReserved,
2006 WINPR_ATTR_UNUSED DWORD Reserved,
2007 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2010 WLog_ERR(
"TODO",
"TODO: implement");
2014BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(WINPR_ATTR_UNUSED HANDLE hServer,
2015 WINPR_ATTR_UNUSED PVOID pReserved,
2016 WINPR_ATTR_UNUSED DWORD Reserved,
2017 WINPR_ATTR_UNUSED LPSTR pListenerName,
2020 WLog_ERR(
"TODO",
"TODO: implement");
2024BOOL WINAPI FreeRDP_WTSCreateListenerW(WINPR_ATTR_UNUSED HANDLE hServer,
2025 WINPR_ATTR_UNUSED PVOID pReserved,
2026 WINPR_ATTR_UNUSED DWORD Reserved,
2027 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2029 WINPR_ATTR_UNUSED DWORD flag)
2031 WLog_ERR(
"TODO",
"TODO: implement");
2035BOOL WINAPI FreeRDP_WTSCreateListenerA(WINPR_ATTR_UNUSED HANDLE hServer,
2036 WINPR_ATTR_UNUSED PVOID pReserved,
2037 WINPR_ATTR_UNUSED DWORD Reserved,
2038 WINPR_ATTR_UNUSED LPSTR pListenerName,
2040 WINPR_ATTR_UNUSED DWORD flag)
2042 WLog_ERR(
"TODO",
"TODO: implement");
2046BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(
2047 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2048 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2049 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2050 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2052 WLog_ERR(
"TODO",
"TODO: implement");
2056BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(
2057 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2058 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2059 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2060 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2062 WLog_ERR(
"TODO",
"TODO: implement");
2066BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(
2067 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2068 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2069 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2070 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2071 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2073 WLog_ERR(
"TODO",
"TODO: implement");
2077BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(
2078 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2079 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2080 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2081 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2082 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2084 WLog_ERR(
"TODO",
"TODO: implement");
2088BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable)
2090 WLog_ERR(
"TODO",
"TODO: implement");
2094BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled)
2096 WLog_ERR(
"TODO",
"TODO: implement");
2100BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId)
2102 WLog_ERR(
"TODO",
"TODO: implement");
2106DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(
void)
2108 WLog_ERR(
"TODO",
"TODO: implement");
2111BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer)
2113 WLog_ERR(
"TODO",
"TODO: implement");
2117BOOL WINAPI FreeRDP_WTSLogonUser(WINPR_ATTR_UNUSED HANDLE hServer,
2118 WINPR_ATTR_UNUSED LPCSTR username,
2119 WINPR_ATTR_UNUSED LPCSTR password, WINPR_ATTR_UNUSED LPCSTR domain)
2121 WLog_ERR(
"TODO",
"TODO: implement");
2125void server_channel_common_free(rdpPeerChannel* channel)
2129 MessageQueue_Free(channel->queue);
2130 Stream_Free(channel->receiveData, TRUE);
2131 DeleteCriticalSection(&channel->writeLock);
2135rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
2136 size_t chunkSize,
const wObject* callback,
2139 rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1,
sizeof(rdpPeerChannel));
2143 InitializeCriticalSection(&channel->writeLock);
2145 channel->receiveData = Stream_New(
nullptr, chunkSize);
2146 if (!channel->receiveData)
2149 channel->queue = MessageQueue_New(callback);
2150 if (!channel->queue)
2153 channel->index = index;
2154 channel->client = client;
2155 channel->channelId = channelId;
2156 strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
2159 WINPR_PRAGMA_DIAG_PUSH
2160 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2161 server_channel_common_free(channel);
2162 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