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;
1023 HashTable_Lock(g_ServerHandles);
1027#ifdef __clang_analyzer__
1028 const BOOL valid = vcm !=
nullptr;
1030 const BOOL valid = (vcm !=
nullptr) && (vcm != INVALID_HANDLE_VALUE);
1034 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1036 HashTable_Free(vcm->dynamicVirtualChannels);
1038 if (vcm->drdynvc_channel)
1041 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1042 vcm->drdynvc_channel =
nullptr;
1045 MessageQueue_Free(vcm->queue);
1048 HashTable_Unlock(g_ServerHandles);
1051HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1053 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1055 rdpContext* context = (rdpContext*)pServerName;
1058 return INVALID_HANDLE_VALUE;
1060 freerdp_peer* client = context->peer;
1064 SetLastError(ERROR_INVALID_DATA);
1065 return INVALID_HANDLE_VALUE;
1068 if (!InitOnceExecuteOnce(&g_HandleInitializer, initializeHandles,
nullptr,
nullptr))
1069 return INVALID_HANDLE_VALUE;
1077 vcm->client = client;
1078 vcm->rdp = context->rdp;
1080 queueCallbacks.
fnObjectFree = wts_virtual_channel_manager_free_message;
1081 vcm->queue = MessageQueue_New(&queueCallbacks);
1086 vcm->dvc_channel_id_seq = 0;
1087 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1089 if (!vcm->dynamicVirtualChannels)
1092 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1096 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1100 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1103 client->ReceiveChannelData = WTSReceiveChannelData;
1105 HashTable_Lock(g_ServerHandles);
1106 vcm->SessionId = g_SessionId++;
1108 HashTable_Insert(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId, (
void*)vcm);
1109 HashTable_Unlock(g_ServerHandles);
1114 HANDLE hServer = (HANDLE)vcm;
1118 wtsCloseVCM(vcm,
false);
1119 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1120 return INVALID_HANDLE_VALUE;
1123HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1125 WLog_ERR(
"TODO",
"TODO: implement");
1126 return INVALID_HANDLE_VALUE;
1129HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1131 return FreeRDP_WTSOpenServerA(pServerName);
1134VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1137 wtsCloseVCM(vcm,
true);
1140BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1141 WINPR_ATTR_UNUSED DWORD Reserved,
1142 WINPR_ATTR_UNUSED DWORD Version,
1144 WINPR_ATTR_UNUSED DWORD* pCount)
1146 WLog_ERR(
"TODO",
"TODO: implement");
1150BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1151 WINPR_ATTR_UNUSED DWORD Reserved,
1152 WINPR_ATTR_UNUSED DWORD Version,
1154 WINPR_ATTR_UNUSED DWORD* pCount)
1156 WLog_ERR(
"TODO",
"TODO: implement");
1160BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1161 WINPR_ATTR_UNUSED DWORD* pLevel,
1162 WINPR_ATTR_UNUSED DWORD Filter,
1164 WINPR_ATTR_UNUSED DWORD* pCount)
1166 WLog_ERR(
"TODO",
"TODO: implement");
1170BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1171 WINPR_ATTR_UNUSED DWORD* pLevel,
1172 WINPR_ATTR_UNUSED DWORD Filter,
1174 WINPR_ATTR_UNUSED DWORD* pCount)
1176 WLog_ERR(
"TODO",
"TODO: implement");
1180BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1181 WINPR_ATTR_UNUSED DWORD Reserved,
1182 WINPR_ATTR_UNUSED DWORD Version,
1184 WINPR_ATTR_UNUSED DWORD* pCount)
1186 WLog_ERR(
"TODO",
"TODO: implement");
1190BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1191 WINPR_ATTR_UNUSED DWORD Reserved,
1192 WINPR_ATTR_UNUSED DWORD Version,
1194 WINPR_ATTR_UNUSED DWORD* pCount)
1196 WLog_ERR(
"TODO",
"TODO: implement");
1200BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1201 WINPR_ATTR_UNUSED DWORD ProcessId,
1202 WINPR_ATTR_UNUSED DWORD ExitCode)
1204 WLog_ERR(
"TODO",
"TODO: implement");
1208BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1209 WINPR_ATTR_UNUSED DWORD SessionId,
1210 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1211 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1212 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1214 WLog_ERR(
"TODO",
"TODO: implement");
1218BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1219 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1220 DWORD* pBytesReturned)
1222 DWORD BytesReturned = 0;
1229 if (WTSInfoClass == WTSSessionId)
1231 ULONG* pBuffer =
nullptr;
1232 BytesReturned =
sizeof(ULONG);
1233 pBuffer = (ULONG*)malloc(
sizeof(BytesReturned));
1237 SetLastError(g_err_oom);
1241 *pBuffer = vcm->SessionId;
1242 *ppBuffer = (LPSTR)pBuffer;
1243 *pBytesReturned = BytesReturned;
1250BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1251 WINPR_ATTR_UNUSED LPWSTR pUserName,
1252 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1253 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1254 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1256 WLog_ERR(
"TODO",
"TODO: implement");
1260BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1261 WINPR_ATTR_UNUSED LPSTR pUserName,
1262 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1263 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1264 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1266 WLog_ERR(
"TODO",
"TODO: implement");
1270BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1271 WINPR_ATTR_UNUSED LPWSTR pUserName,
1272 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1273 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1274 WINPR_ATTR_UNUSED DWORD DataLength)
1276 WLog_ERR(
"TODO",
"TODO: implement");
1280BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1281 WINPR_ATTR_UNUSED LPSTR pUserName,
1282 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1283 WINPR_ATTR_UNUSED LPSTR pBuffer,
1284 WINPR_ATTR_UNUSED DWORD DataLength)
1286 WLog_ERR(
"TODO",
"TODO: implement");
1291FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1292 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1293 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1294 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1295 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1297 WLog_ERR(
"TODO",
"TODO: implement");
1302FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1303 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1304 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1305 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1306 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1308 WLog_ERR(
"TODO",
"TODO: implement");
1312BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1313 WINPR_ATTR_UNUSED DWORD SessionId,
1314 WINPR_ATTR_UNUSED BOOL bWait)
1316 WLog_ERR(
"TODO",
"TODO: implement");
1320BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1321 WINPR_ATTR_UNUSED DWORD SessionId,
1322 WINPR_ATTR_UNUSED BOOL bWait)
1324 WLog_ERR(
"TODO",
"TODO: implement");
1328BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1329 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1331 WLog_ERR(
"TODO",
"TODO: implement");
1335BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1336 WINPR_ATTR_UNUSED DWORD EventMask,
1337 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1339 WLog_ERR(
"TODO",
"TODO: implement");
1343static void peer_channel_queue_free_message(
void* obj)
1345 wMessage* msg = (wMessage*)obj;
1350 msg->context =
nullptr;
1354 UINT32 ChannelId, UINT16 index, UINT16 type,
size_t chunkSize,
1357 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1358 queueCallbacks.
fnObjectFree = peer_channel_queue_free_message;
1360 rdpPeerChannel* channel =
1361 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1364 WINPR_ASSERT(client);
1370 channel->channelType = type;
1371 channel->creationStatus =
1372 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1376 channel_free(channel);
1380HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1384 rdpMcs* mcs =
nullptr;
1385 rdpMcsChannel* joined_channel =
nullptr;
1386 freerdp_peer* client =
nullptr;
1387 rdpPeerChannel* channel =
nullptr;
1389 HANDLE hChannelHandle =
nullptr;
1390 rdpContext* context =
nullptr;
1395 SetLastError(ERROR_INVALID_DATA);
1399 client = vcm->client;
1400 WINPR_ASSERT(client);
1402 context = client->context;
1403 WINPR_ASSERT(context);
1404 WINPR_ASSERT(context->rdp);
1405 WINPR_ASSERT(context->settings);
1407 mcs = context->rdp->mcs;
1410 length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1412 if (length > CHANNEL_NAME_LEN)
1414 SetLastError(ERROR_NOT_FOUND);
1419 for (; index < mcs->channelCount; index++)
1421 rdpMcsChannel* mchannel = &mcs->channels[index];
1422 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1424 joined_channel = mchannel;
1429 if (!joined_channel)
1431 SetLastError(ERROR_NOT_FOUND);
1435 channel = (rdpPeerChannel*)joined_channel->handle;
1439 const UINT32 VCChunkSize =
1442 WINPR_ASSERT(index <= UINT16_MAX);
1443 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1444 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName);
1449 joined_channel->handle = channel;
1452 hChannelHandle = (HANDLE)channel;
1453 return hChannelHandle;
1455 channel_free(channel);
1456 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1460HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1463 rdpPeerChannel* channel =
nullptr;
1464 BOOL joined = FALSE;
1467 if (SessionId == WTS_CURRENT_SESSION)
1470 HashTable_Lock(g_ServerHandles);
1472 g_ServerHandles, (
void*)(UINT_PTR)SessionId);
1477 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1479 HashTable_Unlock(g_ServerHandles);
1480 return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
1483 freerdp_peer* client = vcm->client;
1484 WINPR_ASSERT(client);
1485 WINPR_ASSERT(client->context);
1486 WINPR_ASSERT(client->context->rdp);
1488 rdpMcs* mcs = client->context->rdp->mcs;
1491 for (UINT32 index = 0; index < mcs->channelCount; index++)
1493 rdpMcsChannel* mchannel = &mcs->channels[index];
1494 if (mchannel->joined &&
1495 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1504 SetLastError(ERROR_NOT_FOUND);
1508 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1510 SetLastError(ERROR_NOT_READY);
1514 WINPR_ASSERT(client);
1515 WINPR_ASSERT(client->context);
1516 WINPR_ASSERT(client->context->settings);
1518 const UINT32 VCChunkSize =
1520 channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
1524 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1528 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1529 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1531 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1533 channel_free(channel);
1537 s = Stream_New(
nullptr, 64);
1542 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1546 const size_t pos = Stream_GetPosition(s);
1547 WINPR_ASSERT(pos <= UINT32_MAX);
1548 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char), (UINT32)pos,
1554 Stream_Free(s, TRUE);
1555 HashTable_Unlock(g_ServerHandles);
1559 Stream_Free(s, TRUE);
1561 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1562 HashTable_Unlock(g_ServerHandles);
1564 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1568BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1571 rdpMcs* mcs =
nullptr;
1573 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1581 WINPR_ASSERT(vcm->client);
1582 WINPR_ASSERT(vcm->client->context);
1583 WINPR_ASSERT(vcm->client->context->rdp);
1584 mcs = vcm->client->context->rdp->mcs;
1586 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1588 if (channel->index < mcs->channelCount)
1590 rdpMcsChannel* cur = &mcs->channels[channel->index];
1591 rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
1592 channel_free(peerChannel);
1593 cur->handle =
nullptr;
1598 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1601 s = Stream_New(
nullptr, 8);
1605 WLog_ERR(TAG,
"Stream_New failed!");
1610 wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
1612 const size_t pos = Stream_GetPosition(s);
1613 WINPR_ASSERT(pos <= UINT32_MAX);
1614 ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char),
1615 (UINT32)pos, &written);
1616 Stream_Free(s, TRUE);
1619 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1626BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut,
1627 PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
1629 BYTE* buffer =
nullptr;
1630 wMessage message = WINPR_C_ARRAY_INIT;
1631 wtsChannelMessage* messageCtx =
nullptr;
1632 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1634 WINPR_ASSERT(channel);
1636 if (!MessageQueue_Peek(channel->queue, &message, FALSE))
1638 SetLastError(ERROR_NO_DATA);
1643 messageCtx = message.context;
1645 if (messageCtx ==
nullptr)
1648 buffer = (BYTE*)(messageCtx + 1);
1649 *pBytesRead = messageCtx->length - messageCtx->offset;
1651 if (Buffer ==
nullptr || BufferSize == 0)
1656 if (*pBytesRead > BufferSize)
1657 *pBytesRead = BufferSize;
1659 CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
1660 messageCtx->offset += *pBytesRead;
1662 if (messageCtx->offset >= messageCtx->length)
1664 const int rc = MessageQueue_Peek(channel->queue, &message, TRUE);
1665 peer_channel_queue_free_message(&message);
1673BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength,
1674 PULONG pBytesWritten)
1680 BYTE* buffer =
nullptr;
1681 size_t totalWritten = 0;
1682 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1688 EnterCriticalSection(&channel->writeLock);
1689 WINPR_ASSERT(channel->vcm);
1690 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1692 buffer = (BYTE*)malloc(uLength);
1696 SetLastError(g_err_oom);
1700 CopyMemory(buffer, Buffer, uLength);
1701 totalWritten = uLength;
1702 if (!wts_queue_send_item(channel, buffer, uLength))
1705 else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
1707 DEBUG_DVC(
"drdynvc not ready");
1714 size_t Length = uLength;
1717 s = Stream_New(
nullptr, DVC_MAX_DATA_PDU_SIZE);
1721 WLog_ERR(TAG,
"Stream_New failed!");
1722 SetLastError(g_err_oom);
1726 buffer = Stream_Buffer(s);
1727 Stream_Seek_UINT8(s);
1728 cbChId = wts_write_variable_uint(s, channel->channelId);
1730 if (first && (Length > Stream_GetRemainingLength(s)))
1732 cbLen = wts_write_variable_uint(s, WINPR_ASSERTING_INT_CAST(uint32_t, Length));
1733 buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF;
1737 buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
1741 size_t written = Stream_GetRemainingLength(s);
1743 if (written > Length)
1746 Stream_Write(s, Buffer, written);
1747 const size_t length = Stream_GetPosition(s);
1748 Stream_Free(s, FALSE);
1749 if (length > UINT32_MAX)
1753 totalWritten += written;
1754 if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
1760 *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten);
1764 LeaveCriticalSection(&channel->writeLock);
1768BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1770 WLog_ERR(
"TODO",
"TODO: implement");
1774BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1776 WLog_ERR(
"TODO",
"TODO: implement");
1780BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
1781 PVOID* ppBuffer, DWORD* pBytesReturned)
1783 void* pfd =
nullptr;
1785 void* fds[10] = WINPR_C_ARRAY_INIT;
1786 HANDLE hEvent =
nullptr;
1788 BOOL status = FALSE;
1789 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1791 WINPR_ASSERT(channel);
1793 switch ((UINT32)WtsVirtualClass)
1795 case WTSVirtualFileHandle:
1796 hEvent = MessageQueue_Event(channel->queue);
1797 pfd = GetEventWaitObject(hEvent);
1801 fds[fds_count] = pfd;
1805 *ppBuffer = malloc(
sizeof(
void*));
1809 SetLastError(g_err_oom);
1813 CopyMemory(*ppBuffer, (
void*)&fds[0],
sizeof(
void*));
1814 *pBytesReturned =
sizeof(
void*);
1820 case WTSVirtualEventHandle:
1821 hEvent = MessageQueue_Event(channel->queue);
1823 *ppBuffer = malloc(
sizeof(HANDLE));
1827 SetLastError(g_err_oom);
1831 CopyMemory(*ppBuffer, (
void*)&hEvent,
sizeof(HANDLE));
1832 *pBytesReturned =
sizeof(
void*);
1838 case WTSVirtualChannelReady:
1839 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1846 switch (channel->dvc_open_state)
1848 case DVC_OPEN_STATE_NONE:
1853 case DVC_OPEN_STATE_SUCCEEDED:
1859 *ppBuffer =
nullptr;
1860 *pBytesReturned = 0;
1865 *ppBuffer = malloc(
sizeof(BOOL));
1869 SetLastError(g_err_oom);
1874 CopyMemory(*ppBuffer, &bval,
sizeof(BOOL));
1875 *pBytesReturned =
sizeof(BOOL);
1879 case WTSVirtualChannelOpenStatus:
1881 INT32 value = channel->creationStatus;
1884 *ppBuffer = malloc(
sizeof(value));
1887 SetLastError(g_err_oom);
1892 CopyMemory(*ppBuffer, &value,
sizeof(value));
1893 *pBytesReturned =
sizeof(value);
1904VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
1909BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1910 WINPR_ATTR_UNUSED PVOID pMemory,
1911 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1913 WLog_ERR(
"TODO",
"TODO: implement");
1917BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1918 WINPR_ATTR_UNUSED PVOID pMemory,
1919 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1921 WLog_ERR(
"TODO",
"TODO: implement");
1925BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd,
1926 WINPR_ATTR_UNUSED DWORD dwFlags)
1928 WLog_ERR(
"TODO",
"TODO: implement");
1932BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd)
1934 WLog_ERR(
"TODO",
"TODO: implement");
1938BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1939 WINPR_ATTR_UNUSED HWND hWnd,
1940 WINPR_ATTR_UNUSED DWORD dwFlags)
1942 WLog_ERR(
"TODO",
"TODO: implement");
1946BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1947 WINPR_ATTR_UNUSED HWND hWnd)
1949 WLog_ERR(
"TODO",
"TODO: implement");
1953BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId,
1954 WINPR_ATTR_UNUSED PHANDLE phToken)
1956 WLog_ERR(
"TODO",
"TODO: implement");
1960BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(WINPR_ATTR_UNUSED HANDLE hServer,
1961 WINPR_ATTR_UNUSED DWORD* pLevel,
1962 WINPR_ATTR_UNUSED DWORD SessionId,
1963 WINPR_ATTR_UNUSED LPWSTR* ppProcessInfo,
1964 WINPR_ATTR_UNUSED DWORD* pCount)
1966 WLog_ERR(
"TODO",
"TODO: implement");
1970BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(WINPR_ATTR_UNUSED HANDLE hServer,
1971 WINPR_ATTR_UNUSED DWORD* pLevel,
1972 WINPR_ATTR_UNUSED DWORD SessionId,
1973 WINPR_ATTR_UNUSED LPSTR* ppProcessInfo,
1974 WINPR_ATTR_UNUSED DWORD* pCount)
1976 WLog_ERR(
"TODO",
"TODO: implement");
1980BOOL WINAPI FreeRDP_WTSEnumerateListenersW(WINPR_ATTR_UNUSED HANDLE hServer,
1981 WINPR_ATTR_UNUSED PVOID pReserved,
1982 WINPR_ATTR_UNUSED DWORD Reserved,
1983 WINPR_ATTR_UNUSED PWTSLISTENERNAMEW pListeners,
1984 WINPR_ATTR_UNUSED DWORD* pCount)
1986 WLog_ERR(
"TODO",
"TODO: implement");
1990BOOL WINAPI FreeRDP_WTSEnumerateListenersA(WINPR_ATTR_UNUSED HANDLE hServer,
1991 WINPR_ATTR_UNUSED PVOID pReserved,
1992 WINPR_ATTR_UNUSED DWORD Reserved,
1993 WINPR_ATTR_UNUSED PWTSLISTENERNAMEA pListeners,
1994 WINPR_ATTR_UNUSED DWORD* pCount)
1996 WLog_ERR(
"TODO",
"TODO: implement");
2000BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(WINPR_ATTR_UNUSED HANDLE hServer,
2001 WINPR_ATTR_UNUSED PVOID pReserved,
2002 WINPR_ATTR_UNUSED DWORD Reserved,
2003 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2006 WLog_ERR(
"TODO",
"TODO: implement");
2010BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(WINPR_ATTR_UNUSED HANDLE hServer,
2011 WINPR_ATTR_UNUSED PVOID pReserved,
2012 WINPR_ATTR_UNUSED DWORD Reserved,
2013 WINPR_ATTR_UNUSED LPSTR pListenerName,
2016 WLog_ERR(
"TODO",
"TODO: implement");
2020BOOL WINAPI FreeRDP_WTSCreateListenerW(WINPR_ATTR_UNUSED HANDLE hServer,
2021 WINPR_ATTR_UNUSED PVOID pReserved,
2022 WINPR_ATTR_UNUSED DWORD Reserved,
2023 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2025 WINPR_ATTR_UNUSED DWORD flag)
2027 WLog_ERR(
"TODO",
"TODO: implement");
2031BOOL WINAPI FreeRDP_WTSCreateListenerA(WINPR_ATTR_UNUSED HANDLE hServer,
2032 WINPR_ATTR_UNUSED PVOID pReserved,
2033 WINPR_ATTR_UNUSED DWORD Reserved,
2034 WINPR_ATTR_UNUSED LPSTR pListenerName,
2036 WINPR_ATTR_UNUSED DWORD flag)
2038 WLog_ERR(
"TODO",
"TODO: implement");
2042BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(
2043 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2044 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2045 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2046 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2048 WLog_ERR(
"TODO",
"TODO: implement");
2052BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(
2053 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2054 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2055 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2056 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2058 WLog_ERR(
"TODO",
"TODO: implement");
2062BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(
2063 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2064 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2065 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2066 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2067 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2069 WLog_ERR(
"TODO",
"TODO: implement");
2073BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(
2074 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2075 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2076 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2077 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2078 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2080 WLog_ERR(
"TODO",
"TODO: implement");
2084BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable)
2086 WLog_ERR(
"TODO",
"TODO: implement");
2090BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled)
2092 WLog_ERR(
"TODO",
"TODO: implement");
2096BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId)
2098 WLog_ERR(
"TODO",
"TODO: implement");
2102DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(
void)
2104 WLog_ERR(
"TODO",
"TODO: implement");
2107BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer)
2109 WLog_ERR(
"TODO",
"TODO: implement");
2113BOOL WINAPI FreeRDP_WTSLogonUser(WINPR_ATTR_UNUSED HANDLE hServer,
2114 WINPR_ATTR_UNUSED LPCSTR username,
2115 WINPR_ATTR_UNUSED LPCSTR password, WINPR_ATTR_UNUSED LPCSTR domain)
2117 WLog_ERR(
"TODO",
"TODO: implement");
2121void server_channel_common_free(rdpPeerChannel* channel)
2125 MessageQueue_Free(channel->queue);
2126 Stream_Free(channel->receiveData, TRUE);
2127 DeleteCriticalSection(&channel->writeLock);
2131rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
2132 size_t chunkSize,
const wObject* callback,
2135 rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1,
sizeof(rdpPeerChannel));
2139 InitializeCriticalSection(&channel->writeLock);
2141 channel->receiveData = Stream_New(
nullptr, chunkSize);
2142 if (!channel->receiveData)
2145 channel->queue = MessageQueue_New(callback);
2146 if (!channel->queue)
2149 channel->index = index;
2150 channel->client = client;
2151 channel->channelId = channelId;
2152 strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
2155 WINPR_PRAGMA_DIAG_PUSH
2156 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2157 server_channel_common_free(channel);
2158 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