2014-02-16 02:42:59 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Server Channels
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-05-29 14:46:50 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2014-02-16 02:42:59 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/stream.h>
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-02-16 02:42:59 +04:00
|
|
|
#include <freerdp/constants.h>
|
|
|
|
#include <freerdp/server/channels.h>
|
2021-08-25 11:02:46 +03:00
|
|
|
#include <freerdp/channels/drdynvc.h>
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
#include "rdp.h"
|
|
|
|
|
|
|
|
#include "server.h"
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.server")
|
2014-02-16 02:42:59 +04:00
|
|
|
#ifdef WITH_DEBUG_DVC
|
2016-10-07 15:04:40 +03:00
|
|
|
#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
|
2014-02-16 02:42:59 +04:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
#define DEBUG_DVC(...) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
} while (0)
|
2014-02-16 02:42:59 +04:00
|
|
|
#endif
|
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2014-07-14 16:00:38 +04:00
|
|
|
{
|
|
|
|
UINT16 channelId;
|
|
|
|
UINT16 reserved;
|
|
|
|
UINT32 length;
|
|
|
|
UINT32 offset;
|
2022-02-14 16:59:22 +03:00
|
|
|
} wtsChannelMessage;
|
2014-07-14 16:00:38 +04:00
|
|
|
|
2014-02-17 08:00:58 +04:00
|
|
|
static DWORD g_SessionId = 1;
|
|
|
|
static wHashTable* g_ServerHandles = NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm, UINT32 ChannelId)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-16 04:21:41 +04:00
|
|
|
int index;
|
|
|
|
int count;
|
|
|
|
BOOL found = FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
rdpPeerChannel* channel = NULL;
|
2021-08-24 15:09:40 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(vcm);
|
|
|
|
|
2014-02-16 04:21:41 +04:00
|
|
|
ArrayList_Lock(vcm->dynamicVirtualChannels);
|
|
|
|
count = ArrayList_Count(vcm->dynamicVirtualChannels);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = (rdpPeerChannel*)ArrayList_GetItem(vcm->dynamicVirtualChannels, index);
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
2014-02-16 02:42:59 +04:00
|
|
|
if (channel->channelId == ChannelId)
|
2014-02-16 04:21:41 +04:00
|
|
|
{
|
|
|
|
found = TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
break;
|
2014-02-16 04:21:41 +04:00
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2014-02-16 04:21:41 +04:00
|
|
|
ArrayList_Unlock(vcm->dynamicVirtualChannels);
|
|
|
|
return found ? channel : NULL;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* Buffer, UINT32 Length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-16 04:21:41 +04:00
|
|
|
BYTE* buffer;
|
2014-07-14 16:00:38 +04:00
|
|
|
wtsChannelMessage* messageCtx;
|
2021-08-24 15:09:40 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(channel);
|
2019-11-06 17:24:51 +03:00
|
|
|
messageCtx = (wtsChannelMessage*)malloc(sizeof(wtsChannelMessage) + Length);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-25 23:55:37 +03:00
|
|
|
if (!messageCtx)
|
|
|
|
return FALSE;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
messageCtx->channelId = channel->channelId;
|
|
|
|
messageCtx->length = Length;
|
|
|
|
messageCtx->offset = 0;
|
2016-10-07 15:04:40 +03:00
|
|
|
buffer = (BYTE*)(messageCtx + 1);
|
2014-07-14 16:00:38 +04:00
|
|
|
CopyMemory(buffer, Buffer, Length);
|
2015-05-23 23:47:18 +03:00
|
|
|
return MessageQueue_Post(channel->queue, messageCtx, 0, NULL, NULL);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-16 04:21:41 +04:00
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
UINT16 channelId;
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
WINPR_ASSERT(channel->vcm);
|
2014-02-16 04:21:41 +04:00
|
|
|
buffer = Buffer;
|
|
|
|
length = Length;
|
|
|
|
channelId = channel->channelId;
|
2019-11-06 17:24:51 +03:00
|
|
|
return MessageQueue_Post(channel->vcm->queue, (void*)(UINT_PTR)channelId, 0, (void*)buffer,
|
|
|
|
(void*)(UINT_PTR)length);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int wts_read_variable_uint(wStream* s, int cbLen, UINT32* val)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(val);
|
2014-02-16 02:42:59 +04:00
|
|
|
switch (cbLen)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
|
|
|
return 0;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Read_UINT8(s, *val);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (Stream_GetRemainingLength(s) < 2)
|
|
|
|
return 0;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Read_UINT16(s, *val);
|
|
|
|
return 2;
|
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
case 2:
|
2014-02-16 02:42:59 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
return 0;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Read_UINT32(s, *val);
|
|
|
|
return 4;
|
2022-03-07 15:40:09 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "invalid wts variable uint len %d", cbLen);
|
|
|
|
return 0;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
UINT16 Version;
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
WINPR_ASSERT(channel->vcm);
|
2014-02-16 02:42:59 +04:00
|
|
|
if (length < 3)
|
2015-05-23 23:47:18 +03:00
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
Stream_Seek_UINT8(channel->receiveData); /* Pad (1 byte) */
|
|
|
|
Stream_Read_UINT16(channel->receiveData, Version);
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_DVC("Version: %" PRIu16 "", Version);
|
2014-02-16 02:42:59 +04:00
|
|
|
channel->vcm->drdynvc_state = DRDYNVC_STATE_READY;
|
2015-05-23 23:47:18 +03:00
|
|
|
return TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s, UINT32 length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
UINT32 CreationStatus;
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
WINPR_ASSERT(s);
|
2014-02-16 02:42:59 +04:00
|
|
|
if (length < 4)
|
2015-05-23 23:47:18 +03:00
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, CreationStatus);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((INT32)CreationStatus < 0)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_DVC("ChannelId %" PRIu32 " creation failed (%" PRId32 ")", channel->channelId,
|
|
|
|
(INT32)CreationStatus);
|
2014-02-16 02:42:59 +04:00
|
|
|
channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_DVC("ChannelId %" PRIu32 " creation succeeded", channel->channelId);
|
2014-02-16 02:42:59 +04:00
|
|
|
channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
return TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int cbLen,
|
|
|
|
UINT32 length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
int value;
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
WINPR_ASSERT(s);
|
2014-02-16 02:42:59 +04:00
|
|
|
value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
|
|
|
|
|
|
|
|
if (value == 0)
|
2015-05-23 23:47:18 +03:00
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
length -= value;
|
|
|
|
|
|
|
|
if (length > channel->dvc_total_length)
|
2015-05-23 23:47:18 +03:00
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(channel->receiveData, 0);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2020-04-15 18:47:42 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
|
2015-05-23 23:47:18 +03:00
|
|
|
return FALSE;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Write(channel->receiveData, Stream_Pointer(s), length);
|
2015-05-23 23:47:18 +03:00
|
|
|
return TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2015-06-23 13:08:47 +03:00
|
|
|
BOOL ret = FALSE;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
WINPR_ASSERT(s);
|
2014-02-16 02:42:59 +04:00
|
|
|
if (channel->dvc_total_length > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
channel->dvc_total_length = 0;
|
2015-05-23 23:47:18 +03:00
|
|
|
WLog_ERR(TAG, "incorrect fragment data, discarded.");
|
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Write(channel->receiveData, Stream_Pointer(s), length);
|
|
|
|
|
2019-02-07 16:22:28 +03:00
|
|
|
if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
|
|
|
|
channel->dvc_total_length);
|
2014-02-16 02:42:59 +04:00
|
|
|
channel->dvc_total_length = 0;
|
|
|
|
}
|
2020-03-03 14:27:01 +03:00
|
|
|
else
|
|
|
|
ret = TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-23 23:47:18 +03:00
|
|
|
ret = wts_queue_receive_data(channel, Stream_Pointer(s), length);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
return ret;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_DVC("ChannelId %" PRIu32 " close response", channel->channelId);
|
2014-02-16 02:42:59 +04:00
|
|
|
channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
|
2019-10-25 14:20:28 +03:00
|
|
|
MessageQueue_PostQuit(channel->queue, 0);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
UINT32 length;
|
|
|
|
int value;
|
|
|
|
int Cmd;
|
|
|
|
int Sp;
|
|
|
|
int cbChId;
|
|
|
|
UINT32 ChannelId;
|
|
|
|
rdpPeerChannel* dvc;
|
2021-08-24 15:09:40 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
WINPR_ASSERT(channel->vcm);
|
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
length = Stream_GetPosition(channel->receiveData);
|
|
|
|
|
|
|
|
if (length < 1)
|
2015-05-23 23:47:18 +03:00
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(channel->receiveData, 0);
|
|
|
|
Stream_Read_UINT8(channel->receiveData, value);
|
|
|
|
length--;
|
|
|
|
Cmd = (value & 0xf0) >> 4;
|
|
|
|
Sp = (value & 0x0c) >> 2;
|
|
|
|
cbChId = (value & 0x03) >> 0;
|
|
|
|
|
|
|
|
if (Cmd == CAPABILITY_REQUEST_PDU)
|
2015-05-23 23:47:18 +03:00
|
|
|
return wts_read_drdynvc_capabilities_response(channel, length);
|
2022-03-07 15:40:09 +03:00
|
|
|
|
|
|
|
if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2022-03-07 15:40:09 +03:00
|
|
|
BOOL haveChannelId;
|
|
|
|
switch (Cmd)
|
|
|
|
{
|
|
|
|
case SOFT_SYNC_REQUEST_PDU:
|
|
|
|
case SOFT_SYNC_RESPONSE_PDU:
|
|
|
|
haveChannelId = FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
haveChannelId = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
if (haveChannelId)
|
|
|
|
{
|
|
|
|
value = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId);
|
|
|
|
if (value == 0)
|
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
length -= value;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
DEBUG_DVC("Cmd %d ChannelId %" PRIu32 " length %" PRIu32 "", Cmd, ChannelId, length);
|
|
|
|
dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
|
|
|
|
if (!dvc)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2022-03-07 15:40:09 +03:00
|
|
|
DEBUG_DVC("ChannelId %" PRIu32 " not exists.", ChannelId);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
switch (Cmd)
|
|
|
|
{
|
|
|
|
case CREATE_REQUEST_PDU:
|
|
|
|
return wts_read_drdynvc_create_response(dvc, channel->receiveData, length);
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
case DATA_FIRST_PDU:
|
|
|
|
return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, length);
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
case DATA_PDU:
|
|
|
|
return wts_read_drdynvc_data(dvc, channel->receiveData, length);
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2022-03-07 15:40:09 +03:00
|
|
|
case CLOSE_REQUEST_PDU:
|
|
|
|
wts_read_drdynvc_close_response(dvc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_FIRST_COMPRESSED_PDU:
|
|
|
|
case DATA_COMPRESSED_PDU:
|
|
|
|
WLog_ERR(TAG, "Compressed data not handled");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOFT_SYNC_RESPONSE_PDU:
|
|
|
|
WLog_ERR(TAG, "SoftSync response not handled yet(and rather strange to receive that packet as our code doesn't send SoftSync requests");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOFT_SYNC_REQUEST_PDU:
|
|
|
|
WLog_ERR(TAG, "Not expecting a SoftSyncRequest on the server");
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "Cmd %d not recognized.", Cmd);
|
|
|
|
break;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "received Cmd %d but channel is not ready.", Cmd);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
return TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2014-10-07 22:56:57 +04:00
|
|
|
static int wts_write_variable_uint(wStream* s, UINT32 val)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
int cb;
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(s);
|
2014-02-16 02:42:59 +04:00
|
|
|
if (val <= 0xFF)
|
|
|
|
{
|
|
|
|
cb = 0;
|
2014-10-07 22:56:57 +04:00
|
|
|
Stream_Write_UINT8(s, val);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
else if (val <= 0xFFFF)
|
|
|
|
{
|
|
|
|
cb = 1;
|
2014-10-07 22:56:57 +04:00
|
|
|
Stream_Write_UINT16(s, val);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-29 10:21:37 +04:00
|
|
|
cb = 2;
|
2014-10-07 22:56:57 +04:00
|
|
|
Stream_Write_UINT32(s, val);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
2014-10-07 22:56:57 +04:00
|
|
|
static void wts_write_drdynvc_header(wStream* s, BYTE Cmd, UINT32 ChannelId)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
BYTE* bm;
|
|
|
|
int cbChId;
|
2021-08-24 15:09:40 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_GetPointer(s, bm);
|
|
|
|
Stream_Seek_UINT8(s);
|
|
|
|
cbChId = wts_write_variable_uint(s, ChannelId);
|
|
|
|
*bm = ((Cmd & 0x0F) << 4) | cbChId;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wts_write_drdynvc_create_request(wStream* s, UINT32 ChannelId, const char* ChannelName)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2019-10-29 12:18:09 +03:00
|
|
|
size_t len;
|
2021-08-24 15:09:40 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(ChannelName);
|
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
|
2019-11-11 12:01:19 +03:00
|
|
|
len = strlen(ChannelName) + 1;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2019-10-29 12:18:09 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, len))
|
2015-05-18 12:28:00 +03:00
|
|
|
return FALSE;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Write(s, ChannelName, len);
|
2015-05-18 12:28:00 +03:00
|
|
|
return TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, const BYTE* data,
|
2020-03-04 16:52:19 +03:00
|
|
|
size_t s, UINT32 flags, size_t t)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2015-05-23 23:47:18 +03:00
|
|
|
BOOL ret = TRUE;
|
2019-02-07 16:22:28 +03:00
|
|
|
const size_t size = (size_t)s;
|
|
|
|
const size_t totalSize = (size_t)t;
|
2020-03-04 16:52:19 +03:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
WINPR_ASSERT(channel->vcm);
|
2020-03-04 16:52:19 +03:00
|
|
|
WINPR_UNUSED(channelId);
|
2015-05-23 23:47:18 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
if (flags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
|
|
|
Stream_SetPosition(channel->receiveData, 0);
|
|
|
|
}
|
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
|
|
|
|
return FALSE;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Write(channel->receiveData, data, size);
|
|
|
|
|
|
|
|
if (flags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
2014-02-16 03:41:40 +04:00
|
|
|
if (Stream_GetPosition(channel->receiveData) != totalSize)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2015-05-23 23:47:18 +03:00
|
|
|
WLog_ERR(TAG, "read error");
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
if (channel == channel->vcm->drdynvc_channel)
|
|
|
|
{
|
2015-05-23 23:47:18 +03:00
|
|
|
ret = wts_read_drdynvc_pdu(channel);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
|
|
|
|
Stream_GetPosition(channel->receiveData));
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_SetPosition(channel->receiveData, 0);
|
|
|
|
}
|
2015-05-23 23:47:18 +03:00
|
|
|
|
|
|
|
return ret;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2020-03-09 12:58:02 +03:00
|
|
|
static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const BYTE* data,
|
|
|
|
size_t size, UINT32 flags, size_t totalSize)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-05-10 17:50:36 +04:00
|
|
|
UINT32 i;
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcs* mcs;
|
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->rdp);
|
|
|
|
mcs = client->context->rdp->mcs;
|
|
|
|
WINPR_ASSERT(mcs);
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
for (i = 0; i < mcs->channelCount; i++)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* cur = &mcs->channels[i];
|
|
|
|
if (cur->ChannelId == channelId)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
|
2020-02-21 11:17:00 +03:00
|
|
|
|
|
|
|
if (channel)
|
2021-02-15 12:04:50 +03:00
|
|
|
return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 12:04:50 +03:00
|
|
|
WLog_WARN(TAG, "[%s] unknown channelId %" PRIu16 " ignored", __FUNCTION__, channelId);
|
|
|
|
|
|
|
|
return TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2021-08-24 16:04:58 +03:00
|
|
|
#if defined(WITH_FREERDP_DEPRECATED)
|
2019-11-06 17:24:51 +03:00
|
|
|
void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
void* fd;
|
2019-11-06 17:24:51 +03:00
|
|
|
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(vcm);
|
|
|
|
WINPR_ASSERT(fds);
|
|
|
|
WINPR_ASSERT(fds_count);
|
|
|
|
|
2014-02-16 04:21:41 +04:00
|
|
|
fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
if (fd)
|
|
|
|
{
|
|
|
|
fds[*fds_count] = fd;
|
|
|
|
(*fds_count)++;
|
|
|
|
}
|
|
|
|
|
2014-02-16 03:41:40 +04:00
|
|
|
#if 0
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
if (vcm->drdynvc_channel)
|
|
|
|
{
|
|
|
|
fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
|
|
|
|
|
|
|
|
if (fd)
|
|
|
|
{
|
|
|
|
fds[*fds_count] = fd;
|
|
|
|
(*fds_count)++;
|
|
|
|
}
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-16 03:41:40 +04:00
|
|
|
#endif
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
2021-08-24 16:04:58 +03:00
|
|
|
#endif
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2020-08-09 13:38:50 +03:00
|
|
|
static BOOL WTSVirtualChannelManagerOpen(WTSVirtualChannelManager* vcm)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2020-08-09 13:38:50 +03:00
|
|
|
if (!vcm)
|
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(vcm->client);
|
|
|
|
|
2014-02-16 03:41:40 +04:00
|
|
|
if ((vcm->drdynvc_state == DRDYNVC_STATE_NONE) && vcm->client->activated)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2020-08-09 13:38:50 +03:00
|
|
|
rdpPeerChannel* channel;
|
|
|
|
UINT32 dynvc_caps;
|
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
/* Initialize drdynvc channel once and only once. */
|
|
|
|
vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
|
2021-08-25 11:02:46 +03:00
|
|
|
channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
|
|
|
|
DRDYNVC_SVC_CHANNEL_NAME);
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
if (channel)
|
|
|
|
{
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2014-02-16 02:42:59 +04:00
|
|
|
vcm->drdynvc_channel = channel;
|
|
|
|
dynvc_caps = 0x00010050; /* DYNVC_CAPS_VERSION1 (4 bytes) */
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!WTSVirtualChannelWrite(channel, (PCHAR)&dynvc_caps, sizeof(dynvc_caps), &written))
|
2015-05-29 14:46:50 +03:00
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 13:38:50 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
|
|
|
|
{
|
|
|
|
wMessage message;
|
|
|
|
BOOL status = TRUE;
|
|
|
|
WTSVirtualChannelManager* vcm;
|
|
|
|
|
|
|
|
if (!hServer || hServer == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
vcm = (WTSVirtualChannelManager*)hServer;
|
|
|
|
|
|
|
|
if (autoOpen)
|
|
|
|
{
|
|
|
|
if (!WTSVirtualChannelManagerOpen(vcm))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-16 04:21:41 +04:00
|
|
|
while (MessageQueue_Peek(vcm->queue, &message, TRUE))
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-16 04:21:41 +04:00
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
|
|
|
UINT16 channelId;
|
2019-11-06 17:24:51 +03:00
|
|
|
channelId = (UINT16)(UINT_PTR)message.context;
|
|
|
|
buffer = (BYTE*)message.wParam;
|
|
|
|
length = (UINT32)(UINT_PTR)message.lParam;
|
2014-02-16 03:41:40 +04:00
|
|
|
|
2021-09-17 10:27:01 +03:00
|
|
|
WINPR_ASSERT(vcm->client);
|
|
|
|
WINPR_ASSERT(vcm->client->SendChannelData);
|
2020-03-09 12:33:58 +03:00
|
|
|
if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-16 03:41:40 +04:00
|
|
|
status = FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2014-02-16 04:21:41 +04:00
|
|
|
free(buffer);
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-02-16 03:41:40 +04:00
|
|
|
if (!status)
|
2014-02-16 02:42:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-16 03:41:40 +04:00
|
|
|
return status;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2020-08-09 13:38:50 +03:00
|
|
|
BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
|
|
|
|
{
|
|
|
|
return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
|
|
|
|
}
|
|
|
|
|
2014-02-27 22:30:04 +04:00
|
|
|
HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(vcm);
|
2014-02-16 04:21:41 +04:00
|
|
|
return MessageQueue_Event(vcm->queue);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* channel_name)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
UINT32 index;
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
|
2014-05-07 22:20:02 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* mchannel = &mcs->channels[index];
|
|
|
|
if (mchannel->joined)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
|
|
|
|
return mchannel;
|
2014-10-07 22:56:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2014-05-07 22:20:02 +04:00
|
|
|
}
|
2014-02-27 22:30:04 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs, const UINT16 channel_id)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
|
|
|
UINT32 index;
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!mcs || !channel_id)
|
|
|
|
return NULL;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(mcs->channels);
|
2014-02-16 02:42:59 +04:00
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* mchannel = &mcs->channels[index];
|
|
|
|
if (mchannel->joined)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
if (mchannel->ChannelId == channel_id)
|
2014-05-07 22:20:02 +04:00
|
|
|
return &mcs->channels[index];
|
2014-10-07 22:56:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2014-05-07 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2014-10-07 22:56:57 +04:00
|
|
|
BOOL WTSIsChannelJoinedByName(freerdp_peer* client, const char* channel_name)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) == NULL ? FALSE
|
|
|
|
: TRUE;
|
2014-05-07 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2014-10-07 22:56:57 +04:00
|
|
|
BOOL WTSIsChannelJoinedById(freerdp_peer* client, const UINT16 channel_id)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) == NULL ? FALSE
|
|
|
|
: TRUE;
|
2014-05-07 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
2014-05-07 22:20:02 +04:00
|
|
|
|
|
|
|
if (!vcm || !vcm->rdp)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return wts_get_joined_channel_by_name(vcm->rdp->mcs, name) == NULL ? FALSE : TRUE;
|
2014-05-07 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(vcm);
|
2016-05-03 19:48:59 +03:00
|
|
|
return vcm->drdynvc_state;
|
|
|
|
}
|
|
|
|
|
2014-10-07 22:56:57 +04:00
|
|
|
UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
2014-10-07 22:56:57 +04:00
|
|
|
rdpMcsChannel* channel;
|
2014-05-07 22:20:02 +04:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel_name);
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return 0;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!channel)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return channel->ChannelId;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, void* handle)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
2014-10-07 22:56:57 +04:00
|
|
|
rdpMcsChannel* channel;
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel_name);
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!channel)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
channel->handle = handle;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WTSChannelSetHandleById(freerdp_peer* client, const UINT16 channel_id, void* handle)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
2014-10-07 22:56:57 +04:00
|
|
|
rdpMcsChannel* channel;
|
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!channel)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
channel->handle = handle;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_name)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
2014-10-07 22:56:57 +04:00
|
|
|
rdpMcsChannel* channel;
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel_name);
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!channel)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return channel->handle;
|
|
|
|
}
|
|
|
|
|
2014-10-07 22:56:57 +04:00
|
|
|
void* WTSChannelGetHandleById(freerdp_peer* client, const UINT16 channel_id)
|
2014-05-07 22:20:02 +04:00
|
|
|
{
|
2014-10-07 22:56:57 +04:00
|
|
|
rdpMcsChannel* channel;
|
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
if (!channel)
|
|
|
|
return NULL;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-05-07 22:20:02 +04:00
|
|
|
return channel->handle;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2020-02-02 16:01:38 +03:00
|
|
|
const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
|
|
|
|
{
|
|
|
|
rdpMcsChannel* channel;
|
|
|
|
|
|
|
|
if (!client || !client->context || !client->context->rdp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (const char*)channel->Name;
|
|
|
|
}
|
|
|
|
|
2020-09-21 10:43:23 +03:00
|
|
|
char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count)
|
|
|
|
{
|
|
|
|
rdpMcs* mcs;
|
|
|
|
char** names;
|
|
|
|
UINT32 index;
|
|
|
|
|
|
|
|
if (!client || !client->context || !count)
|
|
|
|
return NULL;
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(client->context->rdp);
|
2020-09-21 10:43:23 +03:00
|
|
|
mcs = client->context->rdp->mcs;
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(mcs);
|
2020-09-21 10:43:23 +03:00
|
|
|
*count = mcs->channelCount;
|
|
|
|
|
|
|
|
names = (char**)calloc(mcs->channelCount, sizeof(char*));
|
|
|
|
if (!names)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
2021-08-24 15:09:40 +03:00
|
|
|
{
|
|
|
|
rdpMcsChannel* mchannel = &mcs->channels[index];
|
|
|
|
names[index] = mchannel->Name;
|
|
|
|
}
|
2020-09-21 10:43:23 +03:00
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId,
|
|
|
|
BYTE HotkeyVk, USHORT HotkeyModifiers)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-17 06:19:25 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(LPSTR pTargetServerName, ULONG TargetLogonId,
|
|
|
|
BYTE HotkeyVk, USHORT HotkeyModifiers)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-16 03:41:40 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(LPWSTR pTargetServerName, ULONG TargetLogonId,
|
|
|
|
BYTE HotkeyVk, USHORT HotkeyModifiers,
|
|
|
|
DWORD flags)
|
2015-02-16 14:16:54 +03:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(LPSTR pTargetServerName, ULONG TargetLogonId,
|
|
|
|
BYTE HotkeyVk, USHORT HotkeyModifiers,
|
|
|
|
DWORD flags)
|
2015-02-16 14:16:54 +03:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(ULONG LogonId)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSConnectSessionW(ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword,
|
|
|
|
BOOL bWait)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSConnectSessionA(ULONG LogonId, ULONG TargetLogonId, PSTR pPassword,
|
|
|
|
BOOL bWait)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version,
|
|
|
|
PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version,
|
|
|
|
PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI FreeRDP_WTSOpenServerW(LPWSTR pServerName)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2020-01-02 16:48:13 +03:00
|
|
|
static void wts_virtual_channel_manager_free_message(void* obj)
|
|
|
|
{
|
|
|
|
wMessage* msg = (wMessage*)obj;
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
BYTE* buffer = (BYTE*)msg->wParam;
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 10:27:01 +03:00
|
|
|
static void channel_free(rdpPeerChannel* channel);
|
|
|
|
|
2021-10-18 12:36:14 +03:00
|
|
|
static void array_channel_free(void* ptr)
|
|
|
|
{
|
|
|
|
rdpPeerChannel* channel = ptr;
|
|
|
|
channel_free(channel);
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
2014-02-17 07:07:00 +04:00
|
|
|
rdpContext* context;
|
|
|
|
freerdp_peer* client;
|
|
|
|
WTSVirtualChannelManager* vcm;
|
|
|
|
HANDLE hServer = INVALID_HANDLE_VALUE;
|
2020-01-02 16:48:13 +03:00
|
|
|
wObject queueCallbacks = { 0 };
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (rdpContext*)pServerName;
|
2014-02-17 07:07:00 +04:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
client = context->peer;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 07:07:00 +04:00
|
|
|
if (!client)
|
2015-05-20 20:19:50 +03:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
2014-02-17 07:07:00 +04:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2015-05-20 20:19:50 +03:00
|
|
|
}
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
vcm = (WTSVirtualChannelManager*)calloc(1, sizeof(WTSVirtualChannelManager));
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!vcm)
|
2015-05-20 20:19:50 +03:00
|
|
|
goto error_vcm_alloc;
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
vcm->client = client;
|
|
|
|
vcm->rdp = context->rdp;
|
|
|
|
vcm->SessionId = g_SessionId++;
|
2014-02-17 08:00:58 +04:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!g_ServerHandles)
|
|
|
|
{
|
|
|
|
g_ServerHandles = HashTable_New(TRUE);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 08:00:58 +04:00
|
|
|
if (!g_ServerHandles)
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_free;
|
|
|
|
}
|
2014-02-17 08:00:58 +04:00
|
|
|
|
2021-06-09 13:31:10 +03:00
|
|
|
if (!HashTable_Insert(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId, (void*)vcm))
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_free;
|
2014-02-17 08:00:58 +04:00
|
|
|
|
2020-01-02 16:48:13 +03:00
|
|
|
queueCallbacks.fnObjectFree = wts_virtual_channel_manager_free_message;
|
|
|
|
vcm->queue = MessageQueue_New(&queueCallbacks);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!vcm->queue)
|
|
|
|
goto error_queue;
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
vcm->dvc_channel_id_seq = 0;
|
|
|
|
vcm->dynamicVirtualChannels = ArrayList_New(TRUE);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!vcm->dynamicVirtualChannels)
|
|
|
|
goto error_dynamicVirtualChannels;
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2021-09-17 10:27:01 +03:00
|
|
|
{
|
|
|
|
wObject* obj = ArrayList_Object(vcm->dynamicVirtualChannels);
|
|
|
|
WINPR_ASSERT(obj);
|
2021-10-18 12:36:14 +03:00
|
|
|
obj->fnObjectFree = array_channel_free;
|
2021-09-17 10:27:01 +03:00
|
|
|
}
|
2015-05-18 12:28:00 +03:00
|
|
|
client->ReceiveChannelData = WTSReceiveChannelData;
|
2019-11-06 17:24:51 +03:00
|
|
|
hServer = (HANDLE)vcm;
|
2014-02-17 07:07:00 +04:00
|
|
|
return hServer;
|
2015-05-18 12:28:00 +03:00
|
|
|
error_dynamicVirtualChannels:
|
|
|
|
MessageQueue_Free(vcm->queue);
|
|
|
|
error_queue:
|
2019-11-06 17:24:51 +03:00
|
|
|
HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
|
2015-05-18 12:28:00 +03:00
|
|
|
error_free:
|
|
|
|
free(vcm);
|
2015-05-20 20:19:50 +03:00
|
|
|
error_vcm_alloc:
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2015-05-18 12:28:00 +03:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2014-02-17 06:19:25 +04:00
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI FreeRDP_WTSOpenServerExW(LPWSTR pServerName)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
2014-02-17 07:07:00 +04:00
|
|
|
return FreeRDP_WTSOpenServerA(pServerName);
|
2014-02-17 06:19:25 +04:00
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
2014-02-17 07:07:00 +04:00
|
|
|
WTSVirtualChannelManager* vcm;
|
2019-11-06 17:24:51 +03:00
|
|
|
vcm = (WTSVirtualChannelManager*)hServer;
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2021-09-17 10:27:01 +03:00
|
|
|
if (vcm && (vcm != INVALID_HANDLE_VALUE))
|
2014-02-17 07:07:00 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
|
2014-02-17 07:07:00 +04:00
|
|
|
|
|
|
|
ArrayList_Free(vcm->dynamicVirtualChannels);
|
|
|
|
|
|
|
|
if (vcm->drdynvc_channel)
|
|
|
|
{
|
|
|
|
WTSVirtualChannelClose(vcm->drdynvc_channel);
|
|
|
|
vcm->drdynvc_channel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueue_Free(vcm->queue);
|
|
|
|
free(vcm);
|
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version,
|
|
|
|
PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-17 06:19:25 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version,
|
|
|
|
PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(HANDLE hServer, DWORD* pLevel, DWORD Filter,
|
|
|
|
PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(HANDLE hServer, DWORD* pLevel, DWORD Filter,
|
|
|
|
PWTS_SESSION_INFO_1A* ppSessionInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version,
|
|
|
|
PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version,
|
|
|
|
PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId,
|
2019-11-06 17:24:51 +03:00
|
|
|
WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer,
|
|
|
|
DWORD* pBytesReturned)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId,
|
2019-11-06 17:24:51 +03:00
|
|
|
WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
|
|
|
|
DWORD* pBytesReturned)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
2014-02-17 08:00:58 +04:00
|
|
|
DWORD BytesReturned;
|
|
|
|
WTSVirtualChannelManager* vcm;
|
2019-11-06 17:24:51 +03:00
|
|
|
vcm = (WTSVirtualChannelManager*)hServer;
|
2014-02-17 08:00:58 +04:00
|
|
|
|
|
|
|
if (!vcm)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (WTSInfoClass == WTSSessionId)
|
|
|
|
{
|
|
|
|
ULONG* pBuffer;
|
|
|
|
BytesReturned = sizeof(ULONG);
|
2019-11-06 17:24:51 +03:00
|
|
|
pBuffer = (ULONG*)malloc(sizeof(BytesReturned));
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!pBuffer)
|
|
|
|
{
|
|
|
|
SetLastError(E_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-17 08:00:58 +04:00
|
|
|
|
|
|
|
*pBuffer = vcm->SessionId;
|
2019-11-06 17:24:51 +03:00
|
|
|
*ppBuffer = (LPSTR)pBuffer;
|
2014-02-17 08:00:58 +04:00
|
|
|
*pBytesReturned = BytesReturned;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-02-17 06:19:25 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName,
|
2019-11-06 17:24:51 +03:00
|
|
|
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer,
|
|
|
|
DWORD* pBytesReturned)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName,
|
2019-11-06 17:24:51 +03:00
|
|
|
WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer,
|
|
|
|
DWORD* pBytesReturned)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName,
|
2019-11-06 17:24:51 +03:00
|
|
|
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer,
|
|
|
|
DWORD DataLength)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName,
|
2019-11-06 17:24:51 +03:00
|
|
|
WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer,
|
|
|
|
DWORD DataLength)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle,
|
|
|
|
DWORD TitleLength, LPWSTR pMessage, DWORD MessageLength,
|
|
|
|
DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle,
|
|
|
|
DWORD TitleLength, LPSTR pMessage, DWORD MessageLength,
|
|
|
|
DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSLogoffSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSShutdownSystem(HANDLE hServer, DWORD ShutdownFlag)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
2020-01-16 12:25:43 +03:00
|
|
|
static void peer_channel_queue_free_message(void* obj)
|
|
|
|
{
|
2020-02-04 15:51:47 +03:00
|
|
|
wMessage* msg = (wMessage*)obj;
|
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free(msg->context);
|
2020-01-16 12:25:43 +03:00
|
|
|
}
|
|
|
|
|
2021-09-17 10:27:01 +03:00
|
|
|
void channel_free(rdpPeerChannel* channel)
|
2020-01-16 13:31:13 +03:00
|
|
|
{
|
|
|
|
if (!channel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MessageQueue_Free(channel->queue);
|
|
|
|
Stream_Free(channel->receiveData, TRUE);
|
|
|
|
free(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static rdpPeerChannel* channel_new(WTSVirtualChannelManager* vcm, freerdp_peer* client,
|
|
|
|
UINT32 ChannelId, UINT16 index, UINT16 type, size_t chunkSize)
|
|
|
|
{
|
|
|
|
wObject queueCallbacks = { 0 };
|
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1, sizeof(rdpPeerChannel));
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(vcm);
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
2020-01-16 13:31:13 +03:00
|
|
|
if (!channel)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
channel->vcm = vcm;
|
|
|
|
channel->client = client;
|
|
|
|
channel->channelId = ChannelId;
|
|
|
|
channel->index = index;
|
|
|
|
channel->channelType = type;
|
|
|
|
channel->receiveData = Stream_New(NULL, chunkSize);
|
|
|
|
|
|
|
|
if (!channel->receiveData)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
queueCallbacks.fnObjectFree = peer_channel_queue_free_message;
|
2021-09-17 10:27:01 +03:00
|
|
|
|
2020-01-16 13:31:13 +03:00
|
|
|
channel->queue = MessageQueue_New(&queueCallbacks);
|
|
|
|
|
|
|
|
if (!channel->queue)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return channel;
|
|
|
|
fail:
|
|
|
|
channel_free(channel);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
|
2014-02-17 05:41:19 +04:00
|
|
|
{
|
2019-10-29 12:18:09 +03:00
|
|
|
size_t length;
|
2014-05-10 17:50:36 +04:00
|
|
|
UINT32 index;
|
2014-02-17 07:07:00 +04:00
|
|
|
rdpMcs* mcs;
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* joined_channel = NULL;
|
2014-02-17 07:07:00 +04:00
|
|
|
freerdp_peer* client;
|
2021-10-18 12:36:14 +03:00
|
|
|
rdpPeerChannel* channel = NULL;
|
2014-02-17 07:07:00 +04:00
|
|
|
WTSVirtualChannelManager* vcm;
|
|
|
|
HANDLE hChannelHandle = NULL;
|
2022-03-23 15:18:35 +03:00
|
|
|
rdpContext* context;
|
2019-11-06 17:24:51 +03:00
|
|
|
vcm = (WTSVirtualChannelManager*)hServer;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 07:07:00 +04:00
|
|
|
if (!vcm)
|
2015-05-20 20:19:50 +03:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
2014-02-17 07:07:00 +04:00
|
|
|
return NULL;
|
2015-05-20 20:19:50 +03:00
|
|
|
}
|
2014-02-17 07:07:00 +04:00
|
|
|
|
|
|
|
client = vcm->client;
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
|
|
|
context = client->context;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->rdp);
|
|
|
|
WINPR_ASSERT(context->settings);
|
|
|
|
|
|
|
|
mcs = context->rdp->mcs;
|
|
|
|
WINPR_ASSERT(mcs);
|
|
|
|
|
2014-02-17 07:07:00 +04:00
|
|
|
length = strlen(pVirtualName);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 07:07:00 +04:00
|
|
|
if (length > 8)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* mchannel = &mcs->channels[index];
|
|
|
|
if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
|
2014-02-17 07:07:00 +04:00
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
joined_channel = mchannel;
|
2014-02-17 07:07:00 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
if (!joined_channel)
|
2014-02-17 07:07:00 +04:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
channel = (rdpPeerChannel*)joined_channel->handle;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 07:07:00 +04:00
|
|
|
if (!channel)
|
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
channel =
|
|
|
|
channel_new(vcm, client, joined_channel->ChannelId, index, RDP_PEER_CHANNEL_TYPE_SVC,
|
|
|
|
context->settings->VirtualChannelChunkSize);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-20 20:19:50 +03:00
|
|
|
if (!channel)
|
2020-01-16 13:31:13 +03:00
|
|
|
goto fail;
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
joined_channel->handle = channel;
|
2014-02-17 07:07:00 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hChannelHandle = (HANDLE)channel;
|
2014-02-17 07:07:00 +04:00
|
|
|
return hChannelHandle;
|
2020-01-16 13:31:13 +03:00
|
|
|
fail:
|
|
|
|
channel_free(channel);
|
2015-05-18 12:28:00 +03:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return NULL;
|
2014-02-17 05:41:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
|
2014-02-17 05:41:19 +04:00
|
|
|
{
|
2014-05-10 17:50:36 +04:00
|
|
|
UINT32 index;
|
2020-01-16 13:31:13 +03:00
|
|
|
wStream* s = NULL;
|
2014-02-17 08:00:58 +04:00
|
|
|
rdpMcs* mcs;
|
|
|
|
BOOL joined = FALSE;
|
|
|
|
freerdp_peer* client;
|
2020-01-16 13:31:13 +03:00
|
|
|
rdpPeerChannel* channel = NULL;
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2020-01-16 13:31:13 +03:00
|
|
|
WTSVirtualChannelManager* vcm = NULL;
|
2014-02-17 08:00:58 +04:00
|
|
|
|
|
|
|
if (SessionId == WTS_CURRENT_SESSION)
|
|
|
|
return NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
vcm = (WTSVirtualChannelManager*)HashTable_GetItemValue(g_ServerHandles,
|
|
|
|
(void*)(UINT_PTR)SessionId);
|
2014-02-17 08:00:58 +04:00
|
|
|
|
|
|
|
if (!vcm)
|
|
|
|
return NULL;
|
|
|
|
|
2014-02-17 07:07:00 +04:00
|
|
|
if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
|
2014-02-17 08:00:58 +04:00
|
|
|
}
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2014-02-17 08:00:58 +04:00
|
|
|
client = vcm->client;
|
|
|
|
mcs = client->context->rdp->mcs;
|
|
|
|
|
|
|
|
for (index = 0; index < mcs->channelCount; index++)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
rdpMcsChannel* mchannel = &mcs->channels[index];
|
2021-08-25 11:02:46 +03:00
|
|
|
if (mchannel->joined &&
|
|
|
|
(strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
|
2014-02-17 08:00:58 +04:00
|
|
|
{
|
|
|
|
joined = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-17 07:07:00 +04:00
|
|
|
}
|
2014-02-17 08:00:58 +04:00
|
|
|
|
|
|
|
if (!joined)
|
2014-02-17 07:07:00 +04:00
|
|
|
{
|
2014-02-17 08:00:58 +04:00
|
|
|
SetLastError(ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-17 07:07:00 +04:00
|
|
|
|
2014-02-17 08:00:58 +04:00
|
|
|
if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_READY);
|
|
|
|
return NULL;
|
2014-02-17 07:07:00 +04:00
|
|
|
}
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->settings);
|
2020-01-16 13:31:13 +03:00
|
|
|
channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC,
|
2022-03-23 15:18:35 +03:00
|
|
|
client->context->settings->VirtualChannelChunkSize);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!channel)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-17 08:00:58 +04:00
|
|
|
|
2014-12-19 06:58:30 +03:00
|
|
|
channel->channelId = InterlockedIncrement(&vcm->dvc_channel_id_seq);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2021-05-17 13:30:18 +03:00
|
|
|
if (!ArrayList_Append(vcm->dynamicVirtualChannels, channel))
|
2020-01-16 13:31:13 +03:00
|
|
|
goto fail;
|
2014-02-17 08:00:58 +04:00
|
|
|
|
|
|
|
s = Stream_New(NULL, 64);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!s)
|
2021-09-17 10:27:01 +03:00
|
|
|
goto fail2;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
|
2021-09-17 10:27:01 +03:00
|
|
|
goto fail2;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR)Stream_Buffer(s),
|
2016-10-07 15:04:40 +03:00
|
|
|
Stream_GetPosition(s), &written))
|
2021-09-17 10:27:01 +03:00
|
|
|
goto fail2;
|
2014-02-17 08:00:58 +04:00
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2014-04-22 15:02:23 +04:00
|
|
|
return channel;
|
2020-01-16 13:31:13 +03:00
|
|
|
fail:
|
|
|
|
channel_free(channel);
|
2021-09-17 10:27:01 +03:00
|
|
|
fail2:
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
ArrayList_Remove(vcm->dynamicVirtualChannels, channel);
|
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return NULL;
|
2014-02-17 05:41:19 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
|
2014-02-17 05:41:19 +04:00
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
rdpMcs* mcs;
|
2021-08-24 15:09:40 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
2015-05-29 14:46:50 +03:00
|
|
|
BOOL ret = TRUE;
|
2014-02-17 05:41:19 +04:00
|
|
|
|
|
|
|
if (channel)
|
|
|
|
{
|
2021-08-24 15:09:40 +03:00
|
|
|
WTSVirtualChannelManager* vcm = channel->vcm;
|
|
|
|
|
|
|
|
WINPR_ASSERT(vcm);
|
|
|
|
WINPR_ASSERT(vcm->client);
|
|
|
|
WINPR_ASSERT(vcm->client->context);
|
|
|
|
WINPR_ASSERT(vcm->client->context->rdp);
|
2014-02-17 05:41:19 +04:00
|
|
|
mcs = vcm->client->context->rdp->mcs;
|
|
|
|
|
|
|
|
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
|
|
|
{
|
|
|
|
if (channel->index < mcs->channelCount)
|
2021-08-24 15:09:40 +03:00
|
|
|
{
|
|
|
|
rdpMcsChannel* cur = &mcs->channels[channel->index];
|
2021-10-18 12:36:14 +03:00
|
|
|
rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
|
|
|
|
if (peerChannel)
|
|
|
|
channel_free(peerChannel);
|
2021-08-24 15:09:40 +03:00
|
|
|
cur->handle = NULL;
|
|
|
|
}
|
2014-02-17 05:41:19 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
|
|
|
|
{
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2014-02-17 05:41:19 +04:00
|
|
|
s = Stream_New(NULL, 8);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-29 14:46:50 +03:00
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
|
2019-11-06 17:24:51 +03:00
|
|
|
ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR)Stream_Buffer(s),
|
2016-10-07 15:04:40 +03:00
|
|
|
Stream_GetPosition(s), &written);
|
2015-05-29 14:46:50 +03:00
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
}
|
2014-02-17 05:41:19 +04:00
|
|
|
}
|
2021-09-23 15:52:03 +03:00
|
|
|
ArrayList_Remove(vcm->dynamicVirtualChannels, channel);
|
2014-02-17 05:41:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 14:46:50 +03:00
|
|
|
return ret;
|
2014-02-17 05:41:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer,
|
|
|
|
ULONG BufferSize, PULONG pBytesRead)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
2014-02-16 04:21:41 +04:00
|
|
|
BYTE* buffer;
|
2014-02-16 03:41:40 +04:00
|
|
|
wMessage message;
|
2014-07-14 16:00:38 +04:00
|
|
|
wtsChannelMessage* messageCtx;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
if (!MessageQueue_Peek(channel->queue, &message, FALSE))
|
2014-02-16 03:41:40 +04:00
|
|
|
{
|
2014-07-14 16:00:38 +04:00
|
|
|
SetLastError(ERROR_NO_DATA);
|
2014-02-16 03:41:40 +04:00
|
|
|
*pBytesRead = 0;
|
2014-07-14 16:00:38 +04:00
|
|
|
return FALSE;
|
2014-02-16 03:41:40 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
messageCtx = (wtsChannelMessage*)(UINT_PTR)message.context;
|
2019-12-10 14:59:10 +03:00
|
|
|
|
|
|
|
if (messageCtx == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
buffer = (BYTE*)(messageCtx + 1);
|
2014-07-14 16:00:38 +04:00
|
|
|
*pBytesRead = messageCtx->length - messageCtx->offset;
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
if (Buffer == NULL || BufferSize == 0)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
if (*pBytesRead > BufferSize)
|
|
|
|
*pBytesRead = BufferSize;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
|
|
|
|
messageCtx->offset += *pBytesRead;
|
2014-10-07 22:56:57 +04:00
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
if (messageCtx->offset >= messageCtx->length)
|
|
|
|
{
|
|
|
|
MessageQueue_Peek(channel->queue, &message, TRUE);
|
2020-02-04 15:51:47 +03:00
|
|
|
peer_channel_queue_free_message(&message);
|
2014-07-14 16:00:38 +04:00
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length,
|
|
|
|
PULONG pBytesWritten)
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
int cbLen;
|
|
|
|
int cbChId;
|
|
|
|
int first;
|
2014-02-16 04:21:41 +04:00
|
|
|
BYTE* buffer;
|
|
|
|
UINT32 length;
|
2014-02-16 02:42:59 +04:00
|
|
|
UINT32 written;
|
2016-05-03 19:48:59 +03:00
|
|
|
UINT32 totalWritten = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
2015-05-23 23:47:18 +03:00
|
|
|
BOOL ret = TRUE;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel->vcm);
|
2014-02-16 02:42:59 +04:00
|
|
|
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
|
|
|
{
|
2014-02-16 04:21:41 +04:00
|
|
|
length = Length;
|
2016-10-07 15:04:40 +03:00
|
|
|
buffer = (BYTE*)malloc(length);
|
|
|
|
|
2015-05-25 23:55:37 +03:00
|
|
|
if (!buffer)
|
2015-06-16 16:42:07 +03:00
|
|
|
{
|
|
|
|
SetLastError(E_OUTOFMEMORY);
|
2015-05-25 23:55:37 +03:00
|
|
|
return FALSE;
|
2015-06-16 16:42:07 +03:00
|
|
|
}
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
CopyMemory(buffer, Buffer, length);
|
2016-05-03 19:48:59 +03:00
|
|
|
totalWritten = Length;
|
2015-05-23 23:47:18 +03:00
|
|
|
ret = wts_queue_send_item(channel, buffer, length);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
DEBUG_DVC("drdynvc not ready");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
rdpContext* context;
|
|
|
|
|
2014-02-16 02:42:59 +04:00
|
|
|
first = TRUE;
|
2021-08-24 15:09:40 +03:00
|
|
|
WINPR_ASSERT(channel->client);
|
2022-03-23 15:18:35 +03:00
|
|
|
context = channel->client->context;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->settings);
|
2014-02-16 02:42:59 +04:00
|
|
|
while (Length > 0)
|
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
s = Stream_New(NULL, context->settings->VirtualChannelChunkSize);
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-05-29 14:46:50 +03:00
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
2015-06-16 16:42:07 +03:00
|
|
|
SetLastError(E_OUTOFMEMORY);
|
2015-05-29 14:46:50 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-05-23 23:47:18 +03:00
|
|
|
|
2014-02-16 04:21:41 +04:00
|
|
|
buffer = Stream_Buffer(s);
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Seek_UINT8(s);
|
|
|
|
cbChId = wts_write_variable_uint(s, channel->channelId);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (first && (Length > (UINT32)Stream_GetRemainingLength(s)))
|
2014-02-16 02:42:59 +04:00
|
|
|
{
|
|
|
|
cbLen = wts_write_variable_uint(s, Length);
|
2014-02-16 04:21:41 +04:00
|
|
|
buffer[0] = (DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-16 04:21:41 +04:00
|
|
|
buffer[0] = (DATA_PDU << 4) | cbChId;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
first = FALSE;
|
|
|
|
written = Stream_GetRemainingLength(s);
|
|
|
|
|
|
|
|
if (written > Length)
|
|
|
|
written = Length;
|
|
|
|
|
|
|
|
Stream_Write(s, Buffer, written);
|
2014-02-16 04:21:41 +04:00
|
|
|
length = Stream_GetPosition(s);
|
2014-02-16 02:42:59 +04:00
|
|
|
Stream_Free(s, FALSE);
|
|
|
|
Length -= written;
|
|
|
|
Buffer += written;
|
2016-05-03 19:48:59 +03:00
|
|
|
totalWritten += written;
|
2015-05-23 23:47:18 +03:00
|
|
|
ret = wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, length);
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-16 04:21:41 +04:00
|
|
|
if (pBytesWritten)
|
2016-05-03 19:48:59 +03:00
|
|
|
*pBytesWritten = totalWritten;
|
2014-02-16 02:42:59 +04:00
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
return ret;
|
2014-02-16 02:42:59 +04:00
|
|
|
}
|
2014-02-17 06:19:25 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(HANDLE hChannelHandle)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
|
|
|
|
PVOID* ppBuffer, DWORD* pBytesReturned)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
void* pfd;
|
|
|
|
BOOL bval;
|
2021-08-24 15:09:40 +03:00
|
|
|
void* fds[10] = { 0 };
|
2014-02-17 06:19:25 +04:00
|
|
|
HANDLE hEvent;
|
|
|
|
int fds_count = 0;
|
|
|
|
BOOL status = FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
2021-08-24 15:09:40 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
|
2014-02-17 06:19:25 +04:00
|
|
|
hEvent = MessageQueue_Event(channel->queue);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
switch ((UINT32)WtsVirtualClass)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
case WTSVirtualFileHandle:
|
|
|
|
pfd = GetEventWaitObject(hEvent);
|
|
|
|
|
|
|
|
if (pfd)
|
|
|
|
{
|
|
|
|
fds[fds_count] = pfd;
|
|
|
|
(fds_count)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppBuffer = malloc(sizeof(void*));
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!*ppBuffer)
|
|
|
|
{
|
|
|
|
SetLastError(E_OUTOFMEMORY);
|
2016-10-07 15:04:40 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
CopyMemory(*ppBuffer, &fds[0], sizeof(void*));
|
|
|
|
*pBytesReturned = sizeof(void*);
|
|
|
|
status = TRUE;
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 06:19:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTSVirtualEventHandle:
|
|
|
|
*ppBuffer = malloc(sizeof(HANDLE));
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!*ppBuffer)
|
|
|
|
{
|
|
|
|
SetLastError(E_OUTOFMEMORY);
|
2016-10-07 15:04:40 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
CopyMemory(*ppBuffer, &(hEvent), sizeof(HANDLE));
|
|
|
|
*pBytesReturned = sizeof(void*);
|
|
|
|
status = TRUE;
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 06:19:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WTSVirtualChannelReady:
|
|
|
|
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
|
|
|
{
|
|
|
|
bval = TRUE;
|
|
|
|
status = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (channel->dvc_open_state)
|
|
|
|
{
|
|
|
|
case DVC_OPEN_STATE_NONE:
|
|
|
|
bval = FALSE;
|
|
|
|
status = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVC_OPEN_STATE_SUCCEEDED:
|
|
|
|
bval = TRUE;
|
|
|
|
status = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
bval = FALSE;
|
|
|
|
status = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppBuffer = malloc(sizeof(BOOL));
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!*ppBuffer)
|
|
|
|
{
|
|
|
|
SetLastError(E_OUTOFMEMORY);
|
|
|
|
status = FALSE;
|
2016-10-07 15:04:40 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
CopyMemory(*ppBuffer, &bval, sizeof(BOOL));
|
|
|
|
*pBytesReturned = sizeof(BOOL);
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 06:19:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-02-17 06:19:25 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
free(pMemory);
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory,
|
|
|
|
ULONG NumberOfEntries)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory,
|
|
|
|
ULONG NumberOfEntries)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(HWND hWnd)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd, DWORD dwFlags)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI FreeRDP_WTSQueryUserToken(ULONG SessionId, PHANDLE phToken)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(HANDLE hServer, DWORD* pLevel, DWORD SessionId,
|
|
|
|
LPWSTR* ppProcessInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(HANDLE hServer, DWORD* pLevel, DWORD SessionId,
|
|
|
|
LPSTR* ppProcessInfo, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateListenersW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
PWTSLISTENERNAMEW pListeners, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSEnumerateListenersA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
PWTSLISTENERNAMEA pListeners, DWORD* pCount)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSCreateListenerW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer,
|
|
|
|
DWORD flag)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSCreateListenerA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
2016-10-07 15:04:40 +03:00
|
|
|
LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer, DWORD flag)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPWSTR pListenerName,
|
|
|
|
SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPSTR pListenerName,
|
|
|
|
SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPWSTR pListenerName,
|
|
|
|
SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength,
|
|
|
|
LPDWORD lpnLengthNeeded)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPSTR pListenerName,
|
|
|
|
SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength,
|
|
|
|
LPDWORD lpnLengthNeeded)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL CDECL FreeRDP_WTSEnableChildSessions(BOOL bEnable)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(PBOOL pbEnabled)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL CDECL FreeRDP_WTSGetChildSessionId(PULONG pSessionId)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(void)
|
2014-02-17 06:19:25 +04:00
|
|
|
{
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
2015-02-12 12:31:00 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSLogoffUser(HANDLE hServer)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL WINAPI FreeRDP_WTSLogonUser(HANDLE hServer, LPCSTR username, LPCSTR password, LPCSTR domain)
|
2015-02-12 12:31:00 +03:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|