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,
size_t Length1,
80 const BYTE* Buffer2,
size_t Length2)
82 WINPR_ASSERT(channel);
84 if (Length1 > UINT32_MAX -
sizeof(wtsChannelMessage))
86 if (Length2 > UINT32_MAX -
sizeof(wtsChannelMessage) - Length1)
88 const size_t len = Length1 + Length2;
89 const size_t tlen =
sizeof(wtsChannelMessage) + len;
90 wtsChannelMessage* messageCtx = (wtsChannelMessage*)malloc(tlen);
94 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
95 messageCtx->channelId = WINPR_ASSERTING_INT_CAST(UINT16, channel->channelId);
96 messageCtx->length = WINPR_ASSERTING_INT_CAST(UINT32, len);
97 messageCtx->offset = 0;
98 BYTE* buffer = (BYTE*)(&messageCtx[1]);
99 CopyMemory(buffer, Buffer1, Length1);
101 WINPR_ASSERT(Buffer2 || (Length2 == 0));
104 CopyMemory(buffer, Buffer2, Length2);
106 return MessageQueue_Post(channel->queue, messageCtx, 0,
nullptr,
nullptr);
109static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
111 BYTE* buffer =
nullptr;
114 WINPR_ASSERT(channel);
115 WINPR_ASSERT(channel->vcm);
119 WINPR_ASSERT(channel->channelId <= UINT16_MAX);
120 const UINT16 channelId = (UINT16)channel->channelId;
121 return MessageQueue_Post(channel->vcm->queue, (
void*)(UINT_PTR)channelId, 0, (
void*)buffer,
122 (
void*)(UINT_PTR)length);
125static unsigned wts_read_variable_uint(
wStream* s,
int cbLen, UINT32* val)
132 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
135 Stream_Read_UINT8(s, *val);
139 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
142 Stream_Read_UINT16(s, *val);
146 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
149 Stream_Read_UINT32(s, *val);
153 WLog_ERR(TAG,
"invalid wts variable uint len %d", cbLen);
158static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel,
wStream* s)
162 WINPR_ASSERT(channel);
163 WINPR_ASSERT(channel->vcm);
164 const size_t length = Stream_GetRemainingLength(s);
168 Stream_Seek_UINT8(s);
169 Stream_Read_UINT16(s, Version);
170 DEBUG_DVC(
"Version: %" PRIu16
"", Version);
174 WLog_ERR(TAG,
"invalid version %" PRIu16
" for DRDYNVC", Version);
179 vcm->drdynvc_state = DRDYNVC_STATE_READY;
182 vcm->dvc_spoken_version = MAX(Version, 1);
184 return SetEvent(MessageQueue_Event(vcm->queue));
187static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel,
wStream* s)
189 UINT32 CreationStatus = 0;
192 WINPR_ASSERT(channel);
194 const size_t length = Stream_GetRemainingLength(s);
195 if ((length < 4) || (length > UINT32_MAX))
198 Stream_Read_UINT32(s, CreationStatus);
200 if ((INT32)CreationStatus < 0)
202 DEBUG_DVC(
"ChannelId %" PRIu32
" creation failed (%" PRId32
")", channel->channelId,
203 (INT32)CreationStatus);
204 channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
208 DEBUG_DVC(
"ChannelId %" PRIu32
" creation succeeded", channel->channelId);
209 channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
212 channel->creationStatus = (INT32)CreationStatus;
213 IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata,
214 channel->channelId, (INT32)CreationStatus);
216 WLog_ERR(TAG,
"vcm->dvc_creation_status failed!");
221static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel,
wStream* s,
int cbLen)
223 WINPR_ASSERT(channel);
226 const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
231 const size_t length = Stream_GetRemainingLength(s);
232 if (length > channel->dvc_total_length)
235 Stream_ResetPosition(channel->receiveData);
237 if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
240 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
244static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel,
wStream* s)
248 WINPR_ASSERT(channel);
251 const size_t length = Stream_GetRemainingLength(s);
252 if (channel->dvc_total_length > 0)
254 const size_t pos = Stream_GetPosition(channel->receiveData);
255 if (pos > SIZE_MAX - length)
258 if (pos + length > channel->dvc_total_length)
260 channel->dvc_total_length = 0;
261 WLog_ERR(TAG,
"incorrect fragment data, discarded.");
265 Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
267 if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
269 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
270 channel->dvc_total_length,
nullptr, 0);
271 channel->dvc_total_length = 0;
278 ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length,
nullptr, 0);
284static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
286 WINPR_ASSERT(channel);
287 DEBUG_DVC(
"ChannelId %" PRIu32
" close response", channel->channelId);
288 channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
289 MessageQueue_PostQuit(channel->queue, 0);
292static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
297 UINT32 ChannelId = 0;
298 rdpPeerChannel* dvc =
nullptr;
300 WINPR_ASSERT(channel);
301 WINPR_ASSERT(channel->vcm);
303 const size_t slength = Stream_GetPosition(channel->receiveData);
304 if ((slength < 1) || (slength > UINT32_MAX))
307 Stream_ResetPosition(channel->receiveData);
308 wStream buffer = WINPR_C_ARRAY_INIT;
309 wStream* s = Stream_StaticConstInit(&buffer, Stream_Buffer(channel->receiveData), slength);
310 const UINT8 value = Stream_Get_UINT8(s);
311 Cmd = (value & 0xf0) >> 4;
312 Sp = (value & 0x0c) >> 2;
313 cbChId = (value & 0x03) >> 0;
315 if (Cmd == CAPABILITY_REQUEST_PDU)
316 return wts_read_drdynvc_capabilities_response(channel, s);
318 if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
320 BOOL haveChannelId = 0;
323 case SOFT_SYNC_REQUEST_PDU:
324 case SOFT_SYNC_RESPONSE_PDU:
325 haveChannelId = FALSE;
328 haveChannelId = TRUE;
334 const unsigned val = wts_read_variable_uint(s, cbChId, &ChannelId);
338 DEBUG_DVC(
"Cmd %s ChannelId %" PRIu32
" length %" PRIuz
"",
339 drdynvc_get_packet_type(Cmd), ChannelId, length);
340 dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
343 DEBUG_DVC(
"ChannelId %" PRIu32
" does not exist.", ChannelId);
350 case CREATE_REQUEST_PDU:
351 return wts_read_drdynvc_create_response(dvc, s);
354 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
357 "ChannelId %" PRIu32
" did not open successfully. "
358 "Ignoring DYNVC_DATA_FIRST PDU",
363 return wts_read_drdynvc_data_first(dvc, s, Sp);
366 if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
369 "ChannelId %" PRIu32
" did not open successfully. "
370 "Ignoring DYNVC_DATA PDU",
375 return wts_read_drdynvc_data(dvc, s);
377 case CLOSE_REQUEST_PDU:
378 wts_read_drdynvc_close_response(dvc);
381 case DATA_FIRST_COMPRESSED_PDU:
382 case DATA_COMPRESSED_PDU:
383 WLog_ERR(TAG,
"Compressed data not handled");
386 case SOFT_SYNC_RESPONSE_PDU:
387 WLog_ERR(TAG,
"SoftSync response not handled yet(and rather strange to receive "
388 "that packet as our code doesn't send SoftSync requests");
391 case SOFT_SYNC_REQUEST_PDU:
392 WLog_ERR(TAG,
"Not expecting a SoftSyncRequest on the server");
396 WLog_ERR(TAG,
"Cmd %d not recognized.", Cmd);
402 WLog_ERR(TAG,
"received Cmd %d but channel is not ready.", Cmd);
408static int wts_write_variable_uint(
wStream* s, UINT32 val)
416 Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val));
418 else if (val <= 0xFFFF)
421 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val));
426 Stream_Write_UINT32(s, val);
432static void wts_write_drdynvc_header(
wStream* s, BYTE Cmd, UINT32 ChannelId)
436 BYTE* bm = Stream_PointerAs(s, BYTE);
437 Stream_Seek_UINT8(s);
438 const int cbChId = wts_write_variable_uint(s, ChannelId);
439 *bm = (((Cmd & 0x0F) << 4) | cbChId) & 0xFF;
442static BOOL wts_write_drdynvc_create_request(
wStream* s, UINT32 ChannelId,
const char* ChannelName)
447 WINPR_ASSERT(ChannelName);
449 wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
450 len = strlen(ChannelName) + 1;
452 if (!Stream_EnsureRemainingCapacity(s, len))
455 Stream_Write(s, ChannelName, len);
459static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId,
const BYTE* data,
460 size_t s, UINT32 flags,
size_t t)
464 const size_t totalSize = t;
466 WINPR_ASSERT(channel);
467 WINPR_ASSERT(channel->vcm);
468 WINPR_UNUSED(channelId);
470 if (channel->channelFlags & CHANNEL_OPTION_SHOW_PROTOCOL)
472 BOOL firstPass = TRUE;
476 const UINT32 payloadLen = (size > CHANNEL_CHUNK_LENGTH)
477 ? CHANNEL_CHUNK_LENGTH
478 : WINPR_ASSERTING_INT_CAST(UINT32, size);
488 if (flags & CHANNEL_FLAG_FIRST)
489 newFlags = CHANNEL_FLAG_FIRST;
492 if (!size && (flags & CHANNEL_FLAG_LAST))
493 newFlags |= CHANNEL_FLAG_LAST;
496 .length = payloadLen,
500 if (!wts_queue_receive_data(channel, (
const BYTE*)&header,
sizeof(header), data,
509 if ((flags & CHANNEL_FLAG_FIRST) != 0)
511 Stream_ResetPosition(channel->receiveData);
514 if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
517 Stream_Write(channel->receiveData, data, size);
519 if ((flags & CHANNEL_FLAG_LAST) != 0)
521 if (Stream_GetPosition(channel->receiveData) != totalSize)
523 WLog_ERR(TAG,
"read error");
526 if (channel == channel->vcm->drdynvc_channel)
528 ret = wts_read_drdynvc_pdu(channel);
532 const size_t pos = Stream_GetPosition(channel->receiveData);
533 if (pos > UINT32_MAX)
536 ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData), pos,
540 Stream_ResetPosition(channel->receiveData);
546static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId,
const BYTE* data,
547 size_t size, UINT32 flags,
size_t totalSize)
549 rdpMcs* mcs =
nullptr;
551 WINPR_ASSERT(client);
552 WINPR_ASSERT(client->context);
553 WINPR_ASSERT(client->context->rdp);
555 mcs = client->context->rdp->mcs;
558 for (UINT32 i = 0; i < mcs->channelCount; i++)
560 rdpMcsChannel* cur = &mcs->channels[i];
561 if (cur->ChannelId == channelId)
563 rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
566 return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
570 WLog_WARN(TAG,
"unknown channelId %" PRIu16
" ignored", channelId);
575#if defined(WITH_FREERDP_DEPRECATED)
576void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer,
void** fds,
int* fds_count)
582 WINPR_ASSERT(fds_count);
584 fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
588 fds[*fds_count] = fd;
594 if (vcm->drdynvc_channel)
596 fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
600 fds[*fds_count] = fd;
609BOOL WTSVirtualChannelManagerOpen(HANDLE hServer)
616 if (vcm->drdynvc_state == DRDYNVC_STATE_NONE)
618 rdpPeerChannel* channel =
nullptr;
621 vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
622 channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
623 DRDYNVC_SVC_CHANNEL_NAME);
627 BYTE capaBuffer[12] = WINPR_C_ARRAY_INIT;
628 wStream staticS = WINPR_C_ARRAY_INIT;
629 wStream* s = Stream_StaticInit(&staticS, capaBuffer,
sizeof(capaBuffer));
631 vcm->drdynvc_channel = channel;
632 vcm->dvc_spoken_version = 1;
633 Stream_Write_UINT8(s, 0x50);
634 Stream_Write_UINT8(s, 0x00);
635 Stream_Write_UINT16(s, 0x0001);
639 const size_t pos = Stream_GetPosition(s);
640 WINPR_ASSERT(pos <= UINT32_MAX);
642 if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written))
650BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
652 wMessage message = WINPR_C_ARRAY_INIT;
656 if (!hServer || hServer == INVALID_HANDLE_VALUE)
663 if (!WTSVirtualChannelManagerOpen(hServer))
667 while (MessageQueue_Peek(vcm->queue, &message, TRUE))
669 BYTE* buffer =
nullptr;
671 UINT16 channelId = 0;
672 channelId = (UINT16)(UINT_PTR)message.context;
673 buffer = (BYTE*)message.wParam;
674 length = (UINT32)(UINT_PTR)message.lParam;
676 WINPR_ASSERT(vcm->client);
677 WINPR_ASSERT(vcm->client->SendChannelData);
678 if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
692BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
694 return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
697HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
701 return MessageQueue_Event(vcm->queue);
704static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs,
const char* channel_name)
706 if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
709 for (UINT32 index = 0; index < mcs->channelCount; index++)
711 rdpMcsChannel* mchannel = &mcs->channels[index];
712 if (mchannel->joined)
714 if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
722static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs,
const UINT16 channel_id)
724 if (!mcs || !channel_id)
727 WINPR_ASSERT(mcs->channels);
728 for (UINT32 index = 0; index < mcs->channelCount; index++)
730 rdpMcsChannel* mchannel = &mcs->channels[index];
731 if (mchannel->joined)
733 if (mchannel->ChannelId == channel_id)
734 return &mcs->channels[index];
741BOOL WTSIsChannelJoinedByName(freerdp_peer* client,
const char* channel_name)
743 if (!client || !client->context || !client->context->rdp)
746 return (wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) !=
nullptr);
749BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id)
751 if (!client || !client->context || !client->context->rdp)
754 return (wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) !=
nullptr);
757BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer,
const char* name)
761 if (!vcm || !vcm->rdp)
764 return (wts_get_joined_channel_by_name(vcm->rdp->mcs, name) !=
nullptr);
767BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
771 return vcm->drdynvc_state;
774void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
781 vcm->dvc_creation_status = cb;
782 vcm->dvc_creation_status_userdata = userdata;
785UINT16 WTSChannelGetId(freerdp_peer* client,
const char* channel_name)
787 rdpMcsChannel* channel =
nullptr;
789 WINPR_ASSERT(channel_name);
790 if (!client || !client->context || !client->context->rdp)
793 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
798 return channel->ChannelId;
801UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
803 rdpPeerChannel* channel = hChannelHandle;
805 WINPR_ASSERT(channel);
807 return channel->channelId;
810BOOL WTSChannelSetHandleByName(freerdp_peer* client,
const char* channel_name,
void* handle)
812 rdpMcsChannel* channel =
nullptr;
814 WINPR_ASSERT(channel_name);
815 if (!client || !client->context || !client->context->rdp)
818 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
823 channel->handle = handle;
827BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id,
void* handle)
829 rdpMcsChannel* channel =
nullptr;
831 if (!client || !client->context || !client->context->rdp)
834 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
839 channel->handle = handle;
843void* WTSChannelGetHandleByName(freerdp_peer* client,
const char* channel_name)
845 rdpMcsChannel* channel =
nullptr;
847 WINPR_ASSERT(channel_name);
848 if (!client || !client->context || !client->context->rdp)
851 channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
856 return channel->handle;
859void* WTSChannelGetHandleById(freerdp_peer* client, UINT16 channel_id)
861 rdpMcsChannel* channel =
nullptr;
863 if (!client || !client->context || !client->context->rdp)
866 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
871 return channel->handle;
874const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
876 rdpMcsChannel* channel =
nullptr;
878 if (!client || !client->context || !client->context->rdp)
881 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
886 return (
const char*)channel->Name;
889char** WTSGetAcceptedChannelNames(freerdp_peer* client,
size_t* count)
891 rdpMcs* mcs =
nullptr;
892 char** names =
nullptr;
894 if (!client || !client->context || !count)
897 WINPR_ASSERT(client->context->rdp);
898 mcs = client->context->rdp->mcs;
900 *count = mcs->channelCount;
902 names = (
char**)calloc(mcs->channelCount,
sizeof(
char*));
906 for (UINT32 index = 0; index < mcs->channelCount; index++)
908 rdpMcsChannel* mchannel = &mcs->channels[index];
909 names[index] = mchannel->Name;
915INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
917 rdpMcsChannel* channel =
nullptr;
919 if (!client || !client->context || !client->context->rdp)
922 channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
927 return (INT64)channel->options;
930BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
931 WINPR_ATTR_UNUSED ULONG TargetLogonId,
932 WINPR_ATTR_UNUSED BYTE HotkeyVk,
933 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
935 WLog_ERR(
"TODO",
"TODO: implement");
939BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
940 WINPR_ATTR_UNUSED ULONG TargetLogonId,
941 WINPR_ATTR_UNUSED BYTE HotkeyVk,
942 WINPR_ATTR_UNUSED USHORT HotkeyModifiers)
944 WLog_ERR(
"TODO",
"TODO: implement");
948BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName,
949 WINPR_ATTR_UNUSED ULONG TargetLogonId,
950 WINPR_ATTR_UNUSED BYTE HotkeyVk,
951 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
952 WINPR_ATTR_UNUSED DWORD flags)
954 WLog_ERR(
"TODO",
"TODO: implement");
958BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(WINPR_ATTR_UNUSED LPSTR pTargetServerName,
959 WINPR_ATTR_UNUSED ULONG TargetLogonId,
960 WINPR_ATTR_UNUSED BYTE HotkeyVk,
961 WINPR_ATTR_UNUSED USHORT HotkeyModifiers,
962 WINPR_ATTR_UNUSED DWORD flags)
964 WLog_ERR(
"TODO",
"TODO: implement");
968BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId)
970 WLog_ERR(
"TODO",
"TODO: implement");
974BOOL WINAPI FreeRDP_WTSConnectSessionW(WINPR_ATTR_UNUSED ULONG LogonId,
975 WINPR_ATTR_UNUSED ULONG TargetLogonId,
976 WINPR_ATTR_UNUSED PWSTR pPassword,
977 WINPR_ATTR_UNUSED BOOL bWait)
979 WLog_ERR(
"TODO",
"TODO: implement");
983BOOL WINAPI FreeRDP_WTSConnectSessionA(WINPR_ATTR_UNUSED ULONG LogonId,
984 WINPR_ATTR_UNUSED ULONG TargetLogonId,
985 WINPR_ATTR_UNUSED PSTR pPassword,
986 WINPR_ATTR_UNUSED BOOL bWait)
988 WLog_ERR(
"TODO",
"TODO: implement");
992BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName,
993 WINPR_ATTR_UNUSED DWORD Reserved,
994 WINPR_ATTR_UNUSED DWORD Version,
996 WINPR_ATTR_UNUSED DWORD* pCount)
998 WLog_ERR(
"TODO",
"TODO: implement");
1002BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName,
1003 WINPR_ATTR_UNUSED DWORD Reserved,
1004 WINPR_ATTR_UNUSED DWORD Version,
1006 WINPR_ATTR_UNUSED DWORD* pCount)
1008 WLog_ERR(
"TODO",
"TODO: implement");
1012HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1014 WLog_ERR(
"TODO",
"TODO: implement");
1015 return INVALID_HANDLE_VALUE;
1018static void wts_virtual_channel_manager_free_message(
void* obj)
1020 wMessage* msg = (wMessage*)obj;
1024 BYTE* buffer = (BYTE*)msg->wParam;
1031static void channel_free(rdpPeerChannel* channel)
1033 server_channel_common_free(channel);
1036static void array_channel_free(
void* ptr)
1038 rdpPeerChannel* channel = ptr;
1039 channel_free(channel);
1042static BOOL dynChannelMatch(
const void* v1,
const void* v2)
1044 const UINT32* p1 = (
const UINT32*)v1;
1045 const UINT32* p2 = (
const UINT32*)v2;
1049static UINT32 channelId_Hash(
const void* key)
1051 const UINT32* v = (
const UINT32*)key;
1055static void clearHandles(
void)
1057 HashTable_Free(g_ServerHandles);
1058 g_ServerHandles =
nullptr;
1061static BOOL CALLBACK initializeHandles(WINPR_ATTR_UNUSED
PINIT_ONCE once,
1062 WINPR_ATTR_UNUSED PVOID param,
1063 WINPR_ATTR_UNUSED PVOID* context)
1065 WINPR_ASSERT(g_ServerHandles ==
nullptr);
1066 g_ServerHandles = HashTable_New(TRUE);
1067 (void)winpr_atexit(clearHandles);
1068 return g_ServerHandles !=
nullptr;
1071static bool setup(
void)
1073 return InitOnceExecuteOnce(&g_HandleInitializer, initializeHandles,
nullptr,
nullptr);
1080 HashTable_Lock(g_ServerHandles);
1084#ifdef __clang_analyzer__
1085 const BOOL valid = vcm !=
nullptr;
1087 const BOOL valid = (vcm !=
nullptr) && (vcm != INVALID_HANDLE_VALUE);
1091 HashTable_Remove(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId);
1093 HashTable_Free(vcm->dynamicVirtualChannels);
1095 if (vcm->drdynvc_channel)
1098 (void)WTSVirtualChannelClose(vcm->drdynvc_channel);
1099 vcm->drdynvc_channel =
nullptr;
1102 MessageQueue_Free(vcm->queue);
1105 HashTable_Unlock(g_ServerHandles);
1108HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
1110 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1112 rdpContext* context = (rdpContext*)pServerName;
1114 if (!setup() || !context)
1115 return INVALID_HANDLE_VALUE;
1117 freerdp_peer* client = context->peer;
1121 SetLastError(ERROR_INVALID_DATA);
1122 return INVALID_HANDLE_VALUE;
1130 vcm->client = client;
1131 vcm->rdp = context->rdp;
1133 queueCallbacks.
fnObjectFree = wts_virtual_channel_manager_free_message;
1134 vcm->queue = MessageQueue_New(&queueCallbacks);
1139 vcm->dvc_channel_id_seq = 0;
1140 vcm->dynamicVirtualChannels = HashTable_New(TRUE);
1142 if (!vcm->dynamicVirtualChannels)
1145 if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
1149 wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
1153 obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
1156 client->ReceiveChannelData = WTSReceiveChannelData;
1158 HashTable_Lock(g_ServerHandles);
1159 vcm->SessionId = g_SessionId++;
1161 HashTable_Insert(g_ServerHandles, (
void*)(UINT_PTR)vcm->SessionId, (
void*)vcm);
1162 HashTable_Unlock(g_ServerHandles);
1167 HANDLE hServer = (HANDLE)vcm;
1171 wtsCloseVCM(vcm,
false);
1172 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1173 return INVALID_HANDLE_VALUE;
1176HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName)
1178 WLog_ERR(
"TODO",
"TODO: implement");
1179 return INVALID_HANDLE_VALUE;
1182HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
1184 return FreeRDP_WTSOpenServerA(pServerName);
1187VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
1190 wtsCloseVCM(vcm,
true);
1193BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer,
1194 WINPR_ATTR_UNUSED DWORD Reserved,
1195 WINPR_ATTR_UNUSED DWORD Version,
1197 WINPR_ATTR_UNUSED DWORD* pCount)
1199 WLog_ERR(
"TODO",
"TODO: implement");
1203BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer,
1204 WINPR_ATTR_UNUSED DWORD Reserved,
1205 WINPR_ATTR_UNUSED DWORD Version,
1207 WINPR_ATTR_UNUSED DWORD* pCount)
1209 WLog_ERR(
"TODO",
"TODO: implement");
1213BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer,
1214 WINPR_ATTR_UNUSED DWORD* pLevel,
1215 WINPR_ATTR_UNUSED DWORD Filter,
1217 WINPR_ATTR_UNUSED DWORD* pCount)
1219 WLog_ERR(
"TODO",
"TODO: implement");
1223BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer,
1224 WINPR_ATTR_UNUSED DWORD* pLevel,
1225 WINPR_ATTR_UNUSED DWORD Filter,
1227 WINPR_ATTR_UNUSED DWORD* pCount)
1229 WLog_ERR(
"TODO",
"TODO: implement");
1233BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer,
1234 WINPR_ATTR_UNUSED DWORD Reserved,
1235 WINPR_ATTR_UNUSED DWORD Version,
1237 WINPR_ATTR_UNUSED DWORD* pCount)
1239 WLog_ERR(
"TODO",
"TODO: implement");
1243BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer,
1244 WINPR_ATTR_UNUSED DWORD Reserved,
1245 WINPR_ATTR_UNUSED DWORD Version,
1247 WINPR_ATTR_UNUSED DWORD* pCount)
1249 WLog_ERR(
"TODO",
"TODO: implement");
1253BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer,
1254 WINPR_ATTR_UNUSED DWORD ProcessId,
1255 WINPR_ATTR_UNUSED DWORD ExitCode)
1257 WLog_ERR(
"TODO",
"TODO: implement");
1261BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer,
1262 WINPR_ATTR_UNUSED DWORD SessionId,
1263 WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass,
1264 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1265 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1267 WLog_ERR(
"TODO",
"TODO: implement");
1271BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1272 WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
1273 DWORD* pBytesReturned)
1275 DWORD BytesReturned = 0;
1282 if (WTSInfoClass == WTSSessionId)
1284 ULONG* pBuffer =
nullptr;
1285 BytesReturned =
sizeof(ULONG);
1286 pBuffer = (ULONG*)malloc(
sizeof(BytesReturned));
1290 SetLastError(g_err_oom);
1294 *pBuffer = vcm->SessionId;
1295 *ppBuffer = (LPSTR)pBuffer;
1296 *pBytesReturned = BytesReturned;
1303BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1304 WINPR_ATTR_UNUSED LPWSTR pUserName,
1305 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1306 WINPR_ATTR_UNUSED LPWSTR* ppBuffer,
1307 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1309 WLog_ERR(
"TODO",
"TODO: implement");
1313BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1314 WINPR_ATTR_UNUSED LPSTR pUserName,
1315 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1316 WINPR_ATTR_UNUSED LPSTR* ppBuffer,
1317 WINPR_ATTR_UNUSED DWORD* pBytesReturned)
1319 WLog_ERR(
"TODO",
"TODO: implement");
1323BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName,
1324 WINPR_ATTR_UNUSED LPWSTR pUserName,
1325 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1326 WINPR_ATTR_UNUSED LPWSTR pBuffer,
1327 WINPR_ATTR_UNUSED DWORD DataLength)
1329 WLog_ERR(
"TODO",
"TODO: implement");
1333BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName,
1334 WINPR_ATTR_UNUSED LPSTR pUserName,
1335 WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass,
1336 WINPR_ATTR_UNUSED LPSTR pBuffer,
1337 WINPR_ATTR_UNUSED DWORD DataLength)
1339 WLog_ERR(
"TODO",
"TODO: implement");
1344FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1345 WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1346 WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1347 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1348 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1350 WLog_ERR(
"TODO",
"TODO: implement");
1355FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId,
1356 WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength,
1357 WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength,
1358 WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout,
1359 WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait)
1361 WLog_ERR(
"TODO",
"TODO: implement");
1365BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer,
1366 WINPR_ATTR_UNUSED DWORD SessionId,
1367 WINPR_ATTR_UNUSED BOOL bWait)
1369 WLog_ERR(
"TODO",
"TODO: implement");
1373BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer,
1374 WINPR_ATTR_UNUSED DWORD SessionId,
1375 WINPR_ATTR_UNUSED BOOL bWait)
1377 WLog_ERR(
"TODO",
"TODO: implement");
1381BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer,
1382 WINPR_ATTR_UNUSED DWORD ShutdownFlag)
1384 WLog_ERR(
"TODO",
"TODO: implement");
1388BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer,
1389 WINPR_ATTR_UNUSED DWORD EventMask,
1390 WINPR_ATTR_UNUSED DWORD* pEventFlags)
1392 WLog_ERR(
"TODO",
"TODO: implement");
1396static void peer_channel_queue_free_message(
void* obj)
1398 wMessage* msg = (wMessage*)obj;
1403 msg->context =
nullptr;
1407 UINT32 ChannelId, UINT16 index, UINT16 type,
size_t chunkSize,
1408 const char* name, UINT32 flags)
1410 wObject queueCallbacks = WINPR_C_ARRAY_INIT;
1411 queueCallbacks.
fnObjectFree = peer_channel_queue_free_message;
1413 rdpPeerChannel* channel =
1414 server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
1417 WINPR_ASSERT(client);
1423 channel->channelType = type;
1424 channel->creationStatus =
1425 (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
1426 channel->channelFlags = flags;
1430 channel_free(channel);
1434static HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenStatic(HANDLE hServer,
1435 WINPR_ATTR_UNUSED DWORD SessionId,
1436 LPSTR pVirtualName, UINT32 Flags)
1441 SetLastError(ERROR_INVALID_DATA);
1445 freerdp_peer* client = vcm->client;
1446 WINPR_ASSERT(client);
1448 rdpContext* context = client->context;
1449 WINPR_ASSERT(context);
1450 WINPR_ASSERT(context->rdp);
1451 WINPR_ASSERT(context->settings);
1453 rdpMcs* mcs = context->rdp->mcs;
1456 size_t length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
1457 if (length > CHANNEL_NAME_LEN)
1459 SetLastError(ERROR_NOT_FOUND);
1463 rdpMcsChannel* joined_channel =
nullptr;
1465 for (; index < mcs->channelCount; index++)
1467 rdpMcsChannel* mchannel = &mcs->channels[index];
1468 if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
1470 joined_channel = mchannel;
1475 if (!joined_channel)
1477 SetLastError(ERROR_NOT_FOUND);
1481 rdpPeerChannel* channel = (rdpPeerChannel*)joined_channel->handle;
1484 const UINT32 VCChunkSize =
1487 WINPR_ASSERT(index <= UINT16_MAX);
1488 channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
1489 RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName, Flags);
1494 joined_channel->handle = channel;
1497 HANDLE hChannelHandle = (HANDLE)channel;
1498 return hChannelHandle;
1500 channel_free(channel);
1501 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1505HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
1507 return FreeRDP_WTSVirtualChannelOpenStatic(hServer, SessionId, pVirtualName, 0);
1510HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
1513 rdpPeerChannel* channel =
nullptr;
1514 BOOL joined = FALSE;
1520 if (SessionId == WTS_CURRENT_SESSION)
1523 HashTable_Lock(g_ServerHandles);
1525 g_ServerHandles, (
void*)(UINT_PTR)SessionId);
1530 if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
1532 HashTable_Unlock(g_ServerHandles);
1533 return FreeRDP_WTSVirtualChannelOpenStatic((HANDLE)vcm, SessionId, pVirtualName, flags);
1536 freerdp_peer* client = vcm->client;
1537 WINPR_ASSERT(client);
1538 WINPR_ASSERT(client->context);
1539 WINPR_ASSERT(client->context->rdp);
1541 rdpMcs* mcs = client->context->rdp->mcs;
1544 for (UINT32 index = 0; index < mcs->channelCount; index++)
1546 rdpMcsChannel* mchannel = &mcs->channels[index];
1547 if (mchannel->joined &&
1548 (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
1557 SetLastError(ERROR_NOT_FOUND);
1561 if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
1563 SetLastError(ERROR_NOT_READY);
1567 WINPR_ASSERT(client);
1568 WINPR_ASSERT(client->context);
1569 WINPR_ASSERT(client->context->settings);
1571 const UINT32 VCChunkSize =
1574 channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName, flags);
1578 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1582 const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
1583 channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
1585 if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
1587 channel_free(channel);
1591 s = Stream_New(
nullptr, 64);
1596 if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
1600 const size_t pos = Stream_GetPosition(s);
1601 WINPR_ASSERT(pos <= UINT32_MAX);
1602 if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char), (UINT32)pos,
1608 Stream_Free(s, TRUE);
1609 HashTable_Unlock(g_ServerHandles);
1613 Stream_Free(s, TRUE);
1615 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1616 HashTable_Unlock(g_ServerHandles);
1618 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1622BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
1625 rdpMcs* mcs =
nullptr;
1627 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1635 WINPR_ASSERT(vcm->client);
1636 WINPR_ASSERT(vcm->client->context);
1637 WINPR_ASSERT(vcm->client->context->rdp);
1638 mcs = vcm->client->context->rdp->mcs;
1640 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1642 if (channel->index < mcs->channelCount)
1644 rdpMcsChannel* cur = &mcs->channels[channel->index];
1645 rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
1646 channel_free(peerChannel);
1647 cur->handle =
nullptr;
1652 if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
1655 s = Stream_New(
nullptr, 8);
1659 WLog_ERR(TAG,
"Stream_New failed!");
1664 wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
1666 const size_t pos = Stream_GetPosition(s);
1667 WINPR_ASSERT(pos <= UINT32_MAX);
1668 ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s,
char),
1669 (UINT32)pos, &written);
1670 Stream_Free(s, TRUE);
1673 HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
1680BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut,
1681 PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
1683 BYTE* buffer =
nullptr;
1684 wMessage message = WINPR_C_ARRAY_INIT;
1685 wtsChannelMessage* messageCtx =
nullptr;
1686 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1688 WINPR_ASSERT(channel);
1690 if (!MessageQueue_Peek(channel->queue, &message, FALSE))
1692 SetLastError(ERROR_NO_DATA);
1697 messageCtx = message.context;
1699 if (messageCtx ==
nullptr)
1702 buffer = (BYTE*)(messageCtx + 1);
1703 *pBytesRead = messageCtx->length - messageCtx->offset;
1705 if (Buffer ==
nullptr || BufferSize == 0)
1710 if (*pBytesRead > BufferSize)
1711 *pBytesRead = BufferSize;
1713 CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
1714 messageCtx->offset += *pBytesRead;
1716 if (messageCtx->offset >= messageCtx->length)
1718 const int rc = MessageQueue_Peek(channel->queue, &message, TRUE);
1719 peer_channel_queue_free_message(&message);
1727BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength,
1728 PULONG pBytesWritten)
1734 BYTE* buffer =
nullptr;
1735 size_t totalWritten = 0;
1736 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1742 EnterCriticalSection(&channel->writeLock);
1743 WINPR_ASSERT(channel->vcm);
1744 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1746 buffer = (BYTE*)malloc(uLength);
1750 SetLastError(g_err_oom);
1754 CopyMemory(buffer, Buffer, uLength);
1755 totalWritten = uLength;
1756 if (!wts_queue_send_item(channel, buffer, uLength))
1759 else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
1761 DEBUG_DVC(
"drdynvc not ready");
1768 size_t Length = uLength;
1771 s = Stream_New(
nullptr, DVC_MAX_DATA_PDU_SIZE);
1775 WLog_ERR(TAG,
"Stream_New failed!");
1776 SetLastError(g_err_oom);
1780 buffer = Stream_Buffer(s);
1781 Stream_Seek_UINT8(s);
1782 cbChId = wts_write_variable_uint(s, channel->channelId);
1784 if (first && (Length > Stream_GetRemainingLength(s)))
1786 cbLen = wts_write_variable_uint(s, WINPR_ASSERTING_INT_CAST(uint32_t, Length));
1787 buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF;
1791 buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
1795 size_t written = Stream_GetRemainingLength(s);
1797 if (written > Length)
1800 Stream_Write(s, Buffer, written);
1801 const size_t length = Stream_GetPosition(s);
1802 Stream_Free(s, FALSE);
1803 if (length > UINT32_MAX)
1807 totalWritten += written;
1808 if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
1814 *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten);
1818 LeaveCriticalSection(&channel->writeLock);
1822BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1824 WLog_ERR(
"TODO",
"TODO: implement");
1828BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle)
1830 WLog_ERR(
"TODO",
"TODO: implement");
1834BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
1835 PVOID* ppBuffer, DWORD* pBytesReturned)
1837 void* pfd =
nullptr;
1839 void* fds[10] = WINPR_C_ARRAY_INIT;
1840 HANDLE hEvent =
nullptr;
1842 BOOL status = FALSE;
1843 rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
1845 WINPR_ASSERT(channel);
1847 switch ((UINT32)WtsVirtualClass)
1849 case WTSVirtualFileHandle:
1850 hEvent = MessageQueue_Event(channel->queue);
1851 pfd = GetEventWaitObject(hEvent);
1855 fds[fds_count] = pfd;
1859 *ppBuffer = malloc(
sizeof(
void*));
1863 SetLastError(g_err_oom);
1867 CopyMemory(*ppBuffer, (
void*)&fds[0],
sizeof(
void*));
1868 *pBytesReturned =
sizeof(
void*);
1874 case WTSVirtualEventHandle:
1875 hEvent = MessageQueue_Event(channel->queue);
1877 *ppBuffer = malloc(
sizeof(HANDLE));
1881 SetLastError(g_err_oom);
1885 CopyMemory(*ppBuffer, (
void*)&hEvent,
sizeof(HANDLE));
1886 *pBytesReturned =
sizeof(
void*);
1892 case WTSVirtualChannelReady:
1893 if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
1900 switch (channel->dvc_open_state)
1902 case DVC_OPEN_STATE_NONE:
1907 case DVC_OPEN_STATE_SUCCEEDED:
1913 *ppBuffer =
nullptr;
1914 *pBytesReturned = 0;
1919 *ppBuffer = malloc(
sizeof(BOOL));
1923 SetLastError(g_err_oom);
1928 CopyMemory(*ppBuffer, &bval,
sizeof(BOOL));
1929 *pBytesReturned =
sizeof(BOOL);
1933 case WTSVirtualChannelOpenStatus:
1935 INT32 value = channel->creationStatus;
1938 *ppBuffer = malloc(
sizeof(value));
1941 SetLastError(g_err_oom);
1946 CopyMemory(*ppBuffer, &value,
sizeof(value));
1947 *pBytesReturned =
sizeof(value);
1958VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
1963BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1964 WINPR_ATTR_UNUSED PVOID pMemory,
1965 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1967 WLog_ERR(
"TODO",
"TODO: implement");
1971BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass,
1972 WINPR_ATTR_UNUSED PVOID pMemory,
1973 WINPR_ATTR_UNUSED ULONG NumberOfEntries)
1975 WLog_ERR(
"TODO",
"TODO: implement");
1979BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd,
1980 WINPR_ATTR_UNUSED DWORD dwFlags)
1982 WLog_ERR(
"TODO",
"TODO: implement");
1986BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd)
1988 WLog_ERR(
"TODO",
"TODO: implement");
1992BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
1993 WINPR_ATTR_UNUSED HWND hWnd,
1994 WINPR_ATTR_UNUSED DWORD dwFlags)
1996 WLog_ERR(
"TODO",
"TODO: implement");
2000BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer,
2001 WINPR_ATTR_UNUSED HWND hWnd)
2003 WLog_ERR(
"TODO",
"TODO: implement");
2007BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId,
2008 WINPR_ATTR_UNUSED PHANDLE phToken)
2010 WLog_ERR(
"TODO",
"TODO: implement");
2014BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(WINPR_ATTR_UNUSED HANDLE hServer,
2015 WINPR_ATTR_UNUSED DWORD* pLevel,
2016 WINPR_ATTR_UNUSED DWORD SessionId,
2017 WINPR_ATTR_UNUSED LPWSTR* ppProcessInfo,
2018 WINPR_ATTR_UNUSED DWORD* pCount)
2020 WLog_ERR(
"TODO",
"TODO: implement");
2024BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(WINPR_ATTR_UNUSED HANDLE hServer,
2025 WINPR_ATTR_UNUSED DWORD* pLevel,
2026 WINPR_ATTR_UNUSED DWORD SessionId,
2027 WINPR_ATTR_UNUSED LPSTR* ppProcessInfo,
2028 WINPR_ATTR_UNUSED DWORD* pCount)
2030 WLog_ERR(
"TODO",
"TODO: implement");
2034BOOL WINAPI FreeRDP_WTSEnumerateListenersW(WINPR_ATTR_UNUSED HANDLE hServer,
2035 WINPR_ATTR_UNUSED PVOID pReserved,
2036 WINPR_ATTR_UNUSED DWORD Reserved,
2037 WINPR_ATTR_UNUSED PWTSLISTENERNAMEW pListeners,
2038 WINPR_ATTR_UNUSED DWORD* pCount)
2040 WLog_ERR(
"TODO",
"TODO: implement");
2044BOOL WINAPI FreeRDP_WTSEnumerateListenersA(WINPR_ATTR_UNUSED HANDLE hServer,
2045 WINPR_ATTR_UNUSED PVOID pReserved,
2046 WINPR_ATTR_UNUSED DWORD Reserved,
2047 WINPR_ATTR_UNUSED PWTSLISTENERNAMEA pListeners,
2048 WINPR_ATTR_UNUSED DWORD* pCount)
2050 WLog_ERR(
"TODO",
"TODO: implement");
2054BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(WINPR_ATTR_UNUSED HANDLE hServer,
2055 WINPR_ATTR_UNUSED PVOID pReserved,
2056 WINPR_ATTR_UNUSED DWORD Reserved,
2057 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2060 WLog_ERR(
"TODO",
"TODO: implement");
2064BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(WINPR_ATTR_UNUSED HANDLE hServer,
2065 WINPR_ATTR_UNUSED PVOID pReserved,
2066 WINPR_ATTR_UNUSED DWORD Reserved,
2067 WINPR_ATTR_UNUSED LPSTR pListenerName,
2070 WLog_ERR(
"TODO",
"TODO: implement");
2074BOOL WINAPI FreeRDP_WTSCreateListenerW(WINPR_ATTR_UNUSED HANDLE hServer,
2075 WINPR_ATTR_UNUSED PVOID pReserved,
2076 WINPR_ATTR_UNUSED DWORD Reserved,
2077 WINPR_ATTR_UNUSED LPWSTR pListenerName,
2079 WINPR_ATTR_UNUSED DWORD flag)
2081 WLog_ERR(
"TODO",
"TODO: implement");
2085BOOL WINAPI FreeRDP_WTSCreateListenerA(WINPR_ATTR_UNUSED HANDLE hServer,
2086 WINPR_ATTR_UNUSED PVOID pReserved,
2087 WINPR_ATTR_UNUSED DWORD Reserved,
2088 WINPR_ATTR_UNUSED LPSTR pListenerName,
2090 WINPR_ATTR_UNUSED DWORD flag)
2092 WLog_ERR(
"TODO",
"TODO: implement");
2096BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(
2097 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2098 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2099 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2100 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2102 WLog_ERR(
"TODO",
"TODO: implement");
2106BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(
2107 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2108 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2109 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2110 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor)
2112 WLog_ERR(
"TODO",
"TODO: implement");
2116BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(
2117 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2118 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName,
2119 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2120 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2121 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2123 WLog_ERR(
"TODO",
"TODO: implement");
2127BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(
2128 WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved,
2129 WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName,
2130 WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation,
2131 WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength,
2132 WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded)
2134 WLog_ERR(
"TODO",
"TODO: implement");
2138BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable)
2140 WLog_ERR(
"TODO",
"TODO: implement");
2144BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled)
2146 WLog_ERR(
"TODO",
"TODO: implement");
2150BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId)
2152 WLog_ERR(
"TODO",
"TODO: implement");
2156DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(
void)
2158 WLog_ERR(
"TODO",
"TODO: implement");
2161BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer)
2163 WLog_ERR(
"TODO",
"TODO: implement");
2167BOOL WINAPI FreeRDP_WTSLogonUser(WINPR_ATTR_UNUSED HANDLE hServer,
2168 WINPR_ATTR_UNUSED LPCSTR username,
2169 WINPR_ATTR_UNUSED LPCSTR password, WINPR_ATTR_UNUSED LPCSTR domain)
2171 WLog_ERR(
"TODO",
"TODO: implement");
2175void server_channel_common_free(rdpPeerChannel* channel)
2179 MessageQueue_Free(channel->queue);
2180 Stream_Free(channel->receiveData, TRUE);
2181 DeleteCriticalSection(&channel->writeLock);
2185rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
2186 size_t chunkSize,
const wObject* callback,
2189 rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1,
sizeof(rdpPeerChannel));
2193 InitializeCriticalSection(&channel->writeLock);
2195 channel->receiveData = Stream_New(
nullptr, chunkSize);
2196 if (!channel->receiveData)
2199 channel->queue = MessageQueue_New(callback);
2200 if (!channel->queue)
2203 channel->index = index;
2204 channel->client = client;
2205 channel->channelId = channelId;
2206 strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
2209 WINPR_PRAGMA_DIAG_PUSH
2210 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2211 server_channel_common_free(channel);
2212 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