2011-07-19 10:07:15 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-19 10:07:15 +04:00
|
|
|
* Dynamic Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
2015-05-29 15:02:31 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2011-07-19 10:07:15 +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>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-10-09 04:26:11 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-05-14 01:39:53 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2021-08-25 11:02:46 +03:00
|
|
|
#include <freerdp/channels/drdynvc.h>
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
#include "drdynvc_main.h"
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
#define TAG CHANNELS_TAG("drdynvc.client")
|
|
|
|
|
2020-08-12 11:10:18 +03:00
|
|
|
static UINT dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId,
|
|
|
|
BOOL bSendClosePDU);
|
2020-05-12 11:21:06 +03:00
|
|
|
static void dvcman_free(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr);
|
2015-01-26 21:26:38 +03:00
|
|
|
static void dvcman_channel_free(void* channel);
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const BYTE* data,
|
2020-08-12 11:10:18 +03:00
|
|
|
UINT32 dataSize, BOOL* close);
|
2020-03-03 20:18:00 +03:00
|
|
|
static UINT drdynvc_send(drdynvcPlugin* drdynvc, wStream* s);
|
2015-01-21 14:58:18 +03:00
|
|
|
|
2019-12-03 16:50:07 +03:00
|
|
|
static void dvcman_wtslistener_free(DVCMAN_LISTENER* listener)
|
|
|
|
{
|
|
|
|
if (listener)
|
|
|
|
free(listener->channel_name);
|
|
|
|
free(listener);
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT dvcman_get_configuration(IWTSListener* pListener, void** ppPropertyBag)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-01-29 14:07:05 +03:00
|
|
|
WINPR_UNUSED(pListener);
|
2014-12-27 23:20:29 +03:00
|
|
|
*ppPropertyBag = NULL;
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT dvcman_create_listener(IWTSVirtualChannelManager* pChannelMgr,
|
2016-09-26 13:12:37 +03:00
|
|
|
const char* pszChannelName, ULONG ulFlags,
|
2019-11-06 17:24:51 +03:00
|
|
|
IWTSListenerCallback* pListenerCallback,
|
|
|
|
IWTSListener** ppListener)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
|
2014-12-27 23:20:29 +03:00
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
WLog_DBG(TAG, "create_listener: %d.%s.", HashTable_Count(dvcman->listeners) + 1,
|
2020-05-12 11:21:06 +03:00
|
|
|
pszChannelName);
|
|
|
|
listener = (DVCMAN_LISTENER*)calloc(1, sizeof(DVCMAN_LISTENER));
|
2015-06-29 21:47:46 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
if (!listener)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
listener->iface.GetConfiguration = dvcman_get_configuration;
|
|
|
|
listener->iface.pInterface = NULL;
|
|
|
|
listener->dvcman = dvcman;
|
|
|
|
listener->channel_name = _strdup(pszChannelName);
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
if (!listener->channel_name)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "_strdup failed!");
|
|
|
|
dvcman_wtslistener_free(listener);
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
listener->flags = ulFlags;
|
|
|
|
listener->listener_callback = pListenerCallback;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
if (ppListener)
|
|
|
|
*ppListener = (IWTSListener*)listener;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
if (!HashTable_Insert(dvcman->listeners, listener->channel_name, listener))
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2020-05-12 11:21:06 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2019-12-03 16:50:07 +03:00
|
|
|
static UINT dvcman_destroy_listener(IWTSVirtualChannelManager* pChannelMgr, IWTSListener* pListener)
|
|
|
|
{
|
|
|
|
DVCMAN_LISTENER* listener = (DVCMAN_LISTENER*)pListener;
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
WINPR_UNUSED(pChannelMgr);
|
|
|
|
|
2019-12-03 16:50:07 +03:00
|
|
|
if (listener)
|
|
|
|
{
|
|
|
|
DVCMAN* dvcman = listener->dvcman;
|
2020-05-12 11:21:06 +03:00
|
|
|
if (dvcman)
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Remove(dvcman->listeners, listener->channel_name);
|
2019-12-03 16:50:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT dvcman_register_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name,
|
|
|
|
IWTSPlugin* pPlugin)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->dvcman;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2021-05-17 13:30:18 +03:00
|
|
|
if (!ArrayList_Append(dvcman->plugin_names, _strdup(name)))
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2021-05-17 13:30:18 +03:00
|
|
|
if (!ArrayList_Append(dvcman->plugins, pPlugin))
|
2020-05-12 11:21:06 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
WLog_DBG(TAG, "register_plugin: num_plugins %d", ArrayList_Count(dvcman->plugins));
|
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static IWTSPlugin* dvcman_get_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
IWTSPlugin* plugin = NULL;
|
|
|
|
size_t i, nc, pc;
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->dvcman;
|
2020-05-12 11:21:06 +03:00
|
|
|
if (!dvcman || !pEntryPoints || !name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nc = ArrayList_Count(dvcman->plugin_names);
|
|
|
|
pc = ArrayList_Count(dvcman->plugins);
|
|
|
|
if (nc != pc)
|
|
|
|
return NULL;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
ArrayList_Lock(dvcman->plugin_names);
|
|
|
|
ArrayList_Lock(dvcman->plugins);
|
|
|
|
for (i = 0; i < pc; i++)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
const char* cur = ArrayList_GetItem(dvcman->plugin_names, i);
|
|
|
|
if (strcmp(cur, name) == 0)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
plugin = ArrayList_GetItem(dvcman->plugins, i);
|
|
|
|
break;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
}
|
2020-05-12 11:21:06 +03:00
|
|
|
ArrayList_Unlock(dvcman->plugin_names);
|
|
|
|
ArrayList_Unlock(dvcman->plugins);
|
|
|
|
return plugin;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2020-11-18 09:51:45 +03:00
|
|
|
static const ADDIN_ARGV* dvcman_get_plugin_data(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->args;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2022-06-22 13:54:58 +03:00
|
|
|
static rdpContext* dvcman_get_rdp_context(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2022-06-22 13:54:58 +03:00
|
|
|
DVCMAN_ENTRY_POINTS* entry = (DVCMAN_ENTRY_POINTS*)pEntryPoints;
|
|
|
|
WINPR_ASSERT(entry);
|
|
|
|
return entry->context;
|
|
|
|
}
|
|
|
|
|
|
|
|
static rdpSettings* dvcman_get_rdp_settings(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
|
|
|
rdpContext* context = dvcman_get_rdp_context(pEntryPoints);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
return context->settings;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2016-07-14 13:44:17 +03:00
|
|
|
static UINT32 dvcman_get_channel_id(IWTSVirtualChannel* channel)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-12-03 16:50:07 +03:00
|
|
|
DVCMAN_CHANNEL* dvc = (DVCMAN_CHANNEL*)channel;
|
|
|
|
return dvc->channel_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* dvcman_get_channel_name(IWTSVirtualChannel* channel)
|
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* dvc = (DVCMAN_CHANNEL*)channel;
|
|
|
|
return dvc->channel_name;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static IWTSVirtualChannel* dvcman_find_channel_by_id(IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
IWTSVirtualChannel* channel = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
|
2022-07-26 13:53:41 +03:00
|
|
|
DVCMAN_CHANNEL* dvcChannel;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Lock(dvcman->channelsById);
|
|
|
|
dvcChannel = HashTable_GetItemValue(dvcman->channelsById, &ChannelId);
|
|
|
|
if (dvcChannel)
|
|
|
|
channel = &dvcChannel->iface;
|
|
|
|
|
|
|
|
HashTable_Unlock(dvcman->channelsById);
|
2020-05-12 11:21:06 +03:00
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dvcman_plugin_terminate(void* plugin)
|
|
|
|
{
|
|
|
|
IWTSPlugin* pPlugin = plugin;
|
|
|
|
|
|
|
|
UINT error = IFCALLRESULT(CHANNEL_RC_OK, pPlugin->Terminated, pPlugin);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
WLog_ERR(TAG, "Terminated failed with error %" PRIu32 "!", error);
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 15:26:45 +03:00
|
|
|
static void wts_listener_free(void* arg)
|
|
|
|
{
|
|
|
|
DVCMAN_LISTENER* listener = (DVCMAN_LISTENER*)arg;
|
|
|
|
dvcman_wtslistener_free(listener);
|
|
|
|
}
|
2022-07-26 13:53:41 +03:00
|
|
|
|
|
|
|
static BOOL channelIdMatch(const void* k1, const void* k2)
|
|
|
|
{
|
|
|
|
return *((UINT32*)k1) == *((UINT32*)k2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 channelIdHash(const void* id)
|
|
|
|
{
|
|
|
|
return *((UINT32*)id);
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static IWTSVirtualChannelManager* dvcman_new(drdynvcPlugin* plugin)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
wObject* obj;
|
2014-12-27 23:20:29 +03:00
|
|
|
DVCMAN* dvcman;
|
2019-11-06 17:24:51 +03:00
|
|
|
dvcman = (DVCMAN*)calloc(1, sizeof(DVCMAN));
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!dvcman)
|
|
|
|
return NULL;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
dvcman->iface.CreateListener = dvcman_create_listener;
|
2019-12-03 16:50:07 +03:00
|
|
|
dvcman->iface.DestroyListener = dvcman_destroy_listener;
|
2014-12-27 23:20:29 +03:00
|
|
|
dvcman->iface.FindChannelById = dvcman_find_channel_by_id;
|
|
|
|
dvcman->iface.GetChannelId = dvcman_get_channel_id;
|
2019-12-03 16:50:07 +03:00
|
|
|
dvcman->iface.GetChannelName = dvcman_get_channel_name;
|
2014-12-27 23:20:29 +03:00
|
|
|
dvcman->drdynvc = plugin;
|
2022-07-26 13:53:41 +03:00
|
|
|
dvcman->channelsById = HashTable_New(TRUE);
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
if (!dvcman->channelsById)
|
2020-05-12 11:21:06 +03:00
|
|
|
goto fail;
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_SetHashFunction(dvcman->channelsById, channelIdHash);
|
|
|
|
obj = HashTable_KeyObject(dvcman->channelsById);
|
|
|
|
obj->fnObjectEquals = channelIdMatch;
|
|
|
|
|
|
|
|
obj = HashTable_ValueObject(dvcman->channelsById);
|
2020-05-12 11:21:06 +03:00
|
|
|
obj->fnObjectFree = dvcman_channel_free;
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
dvcman->pool = StreamPool_New(TRUE, 10);
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!dvcman->pool)
|
2020-05-12 11:21:06 +03:00
|
|
|
goto fail;
|
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
dvcman->listeners = HashTable_New(TRUE);
|
2020-05-12 11:21:06 +03:00
|
|
|
if (!dvcman->listeners)
|
|
|
|
goto fail;
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_SetHashFunction(dvcman->listeners, HashTable_StringHash);
|
|
|
|
|
|
|
|
obj = HashTable_KeyObject(dvcman->listeners);
|
|
|
|
obj->fnObjectEquals = HashTable_StringCompare;
|
|
|
|
|
|
|
|
obj = HashTable_ValueObject(dvcman->listeners);
|
2020-05-12 15:26:45 +03:00
|
|
|
obj->fnObjectFree = wts_listener_free;
|
2020-05-12 11:21:06 +03:00
|
|
|
|
|
|
|
dvcman->plugin_names = ArrayList_New(TRUE);
|
|
|
|
if (!dvcman->plugin_names)
|
|
|
|
goto fail;
|
|
|
|
obj = ArrayList_Object(dvcman->plugin_names);
|
|
|
|
obj->fnObjectFree = free;
|
|
|
|
|
|
|
|
dvcman->plugins = ArrayList_New(TRUE);
|
|
|
|
if (!dvcman->plugins)
|
|
|
|
goto fail;
|
|
|
|
obj = ArrayList_Object(dvcman->plugins);
|
|
|
|
obj->fnObjectFree = dvcman_plugin_terminate;
|
|
|
|
return &dvcman->iface;
|
|
|
|
fail:
|
|
|
|
dvcman_free(plugin, &dvcman->iface);
|
|
|
|
return NULL;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT dvcman_load_addin(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr,
|
2022-06-22 13:54:58 +03:00
|
|
|
const ADDIN_ARGV* args, rdpContext* context)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
PDVC_PLUGIN_ENTRY pDVCPluginEntry = NULL;
|
2022-06-27 10:40:14 +03:00
|
|
|
|
2022-06-22 13:54:58 +03:00
|
|
|
WINPR_ASSERT(drdynvc);
|
|
|
|
WINPR_ASSERT(pChannelMgr);
|
|
|
|
WINPR_ASSERT(args);
|
|
|
|
WINPR_ASSERT(context);
|
2022-06-27 10:40:14 +03:00
|
|
|
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_INFO, "Loading Dynamic Virtual Channel %s", args->argv[0]);
|
2019-11-06 17:24:51 +03:00
|
|
|
pDVCPluginEntry = (PDVC_PLUGIN_ENTRY)freerdp_load_channel_addin_entry(
|
|
|
|
args->argv[0], NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
if (pDVCPluginEntry)
|
|
|
|
{
|
2022-06-22 13:54:58 +03:00
|
|
|
DVCMAN_ENTRY_POINTS entryPoints = { 0 };
|
2022-06-27 10:40:14 +03:00
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
entryPoints.iface.RegisterPlugin = dvcman_register_plugin;
|
|
|
|
entryPoints.iface.GetPlugin = dvcman_get_plugin;
|
|
|
|
entryPoints.iface.GetPluginData = dvcman_get_plugin_data;
|
|
|
|
entryPoints.iface.GetRdpSettings = dvcman_get_rdp_settings;
|
2022-06-22 13:54:58 +03:00
|
|
|
entryPoints.iface.GetRdpContext = dvcman_get_rdp_context;
|
2019-11-06 17:24:51 +03:00
|
|
|
entryPoints.dvcman = (DVCMAN*)pChannelMgr;
|
2014-12-27 23:20:29 +03:00
|
|
|
entryPoints.args = args;
|
2022-06-22 13:54:58 +03:00
|
|
|
entryPoints.context = context;
|
2020-03-09 18:21:43 +03:00
|
|
|
return pDVCPluginEntry(&entryPoints.iface);
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2016-10-27 15:41:05 +03:00
|
|
|
return ERROR_INVALID_FUNCTION;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 15:13:16 +03:00
|
|
|
static DVCMAN_CHANNEL* dvcman_channel_new(drdynvcPlugin* drdynvc,
|
2019-11-06 17:24:51 +03:00
|
|
|
IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId,
|
|
|
|
const char* ChannelName)
|
2014-12-28 19:13:51 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
|
2015-01-26 21:26:38 +03:00
|
|
|
if (dvcman_find_channel_by_id(pChannelMgr, ChannelId))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"Protocol error: Duplicated ChannelId %" PRIu32 " (%s)!", ChannelId,
|
2018-02-09 15:13:16 +03:00
|
|
|
ChannelName);
|
2015-01-26 21:26:38 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = (DVCMAN_CHANNEL*)calloc(1, sizeof(DVCMAN_CHANNEL));
|
2014-12-28 19:13:51 +03:00
|
|
|
|
|
|
|
if (!channel)
|
2020-05-12 11:21:06 +03:00
|
|
|
goto fail;
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
channel->dvcman = (DVCMAN*)pChannelMgr;
|
2014-12-28 19:13:51 +03:00
|
|
|
channel->channel_id = ChannelId;
|
|
|
|
channel->channel_name = _strdup(ChannelName);
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!channel->channel_name)
|
2020-05-12 11:21:06 +03:00
|
|
|
goto fail;
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2018-02-09 12:29:31 +03:00
|
|
|
if (!InitializeCriticalSectionEx(&(channel->lock), 0, 0))
|
2020-05-12 11:21:06 +03:00
|
|
|
goto fail;
|
2014-12-28 19:13:51 +03:00
|
|
|
|
|
|
|
return channel;
|
2020-05-12 11:21:06 +03:00
|
|
|
fail:
|
|
|
|
dvcman_channel_free(channel);
|
|
|
|
return NULL;
|
2014-12-28 19:13:51 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static void dvcman_channel_free(void* arg)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*)arg;
|
2017-08-31 10:06:59 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2015-01-26 21:26:38 +03:00
|
|
|
|
2017-08-31 10:06:59 +03:00
|
|
|
if (channel)
|
2015-01-21 14:58:18 +03:00
|
|
|
{
|
2017-08-31 10:06:59 +03:00
|
|
|
if (channel->channel_callback)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALL(channel->channel_callback->OnClose, channel->channel_callback);
|
2020-05-19 16:18:55 +03:00
|
|
|
channel->channel_callback = NULL;
|
2017-08-31 10:06:59 +03:00
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2017-08-31 10:06:59 +03:00
|
|
|
if (channel->status == CHANNEL_RC_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
IWTSVirtualChannel* ichannel = (IWTSVirtualChannel*)channel;
|
2017-08-31 10:06:59 +03:00
|
|
|
|
|
|
|
if (channel->dvcman && channel->dvcman->drdynvc)
|
2018-02-09 12:29:31 +03:00
|
|
|
{
|
2017-08-31 10:06:59 +03:00
|
|
|
DrdynvcClientContext* context = channel->dvcman->drdynvc->context;
|
2018-02-09 12:29:31 +03:00
|
|
|
|
2017-08-31 10:06:59 +03:00
|
|
|
if (context)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALLRET(context->OnChannelDisconnected, error, context, channel->channel_name,
|
2018-02-09 12:29:31 +03:00
|
|
|
channel->pInterface);
|
2017-08-31 10:06:59 +03:00
|
|
|
}
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2017-08-31 10:06:59 +03:00
|
|
|
error = IFCALLRESULT(CHANNEL_RC_OK, ichannel->Close, ichannel);
|
2018-02-09 12:29:31 +03:00
|
|
|
|
2017-08-31 10:06:59 +03:00
|
|
|
if (error != CHANNEL_RC_OK)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Close failed with error %" PRIu32 "!", error);
|
2017-08-31 10:06:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->dvc_data)
|
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
|
|
|
|
DeleteCriticalSection(&(channel->lock));
|
2015-01-21 14:58:18 +03:00
|
|
|
free(channel->channel_name);
|
|
|
|
}
|
2018-02-09 12:29:31 +03:00
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
free(channel);
|
|
|
|
}
|
|
|
|
|
2020-05-19 14:11:32 +03:00
|
|
|
static void dvcman_clear(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr)
|
|
|
|
{
|
|
|
|
DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
|
|
|
|
|
|
|
|
WINPR_UNUSED(drdynvc);
|
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Clear(dvcman->channelsById);
|
2022-06-27 10:40:14 +03:00
|
|
|
ArrayList_Clear(dvcman->plugins);
|
2020-05-19 14:11:32 +03:00
|
|
|
ArrayList_Clear(dvcman->plugin_names);
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Clear(dvcman->listeners);
|
2020-05-19 14:11:32 +03:00
|
|
|
}
|
2018-02-09 15:13:16 +03:00
|
|
|
static void dvcman_free(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2020-05-19 14:11:32 +03:00
|
|
|
WINPR_UNUSED(drdynvc);
|
|
|
|
|
2020-05-12 15:26:45 +03:00
|
|
|
ArrayList_Free(dvcman->plugins);
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Free(dvcman->channelsById);
|
2020-05-12 11:21:06 +03:00
|
|
|
ArrayList_Free(dvcman->plugin_names);
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Free(dvcman->listeners);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
StreamPool_Free(dvcman->pool);
|
|
|
|
free(dvcman);
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2018-02-09 15:13:16 +03:00
|
|
|
static UINT dvcman_init(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-11-10 10:14:56 +03:00
|
|
|
size_t i;
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
|
2020-05-12 11:21:06 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
ArrayList_Lock(dvcman->plugins);
|
|
|
|
for (i = 0; i < ArrayList_Count(dvcman->plugins); i++)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
IWTSPlugin* pPlugin = ArrayList_GetItem(dvcman->plugins, i);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
error = IFCALLRESULT(CHANNEL_RC_OK, pPlugin->Initialize, pPlugin, pChannelMgr);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "Initialize failed with error %" PRIu32 "!",
|
|
|
|
error);
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
fail:
|
|
|
|
ArrayList_Unlock(dvcman->plugins);
|
|
|
|
return error;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT dvcman_write_channel(IWTSVirtualChannel* pChannel, ULONG cbSize, const BYTE* pBuffer,
|
|
|
|
void* pReserved)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2020-08-12 11:10:18 +03:00
|
|
|
BOOL close = FALSE;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*)pChannel;
|
2017-01-17 18:02:13 +03:00
|
|
|
|
2019-01-29 14:07:05 +03:00
|
|
|
WINPR_UNUSED(pReserved);
|
2017-01-17 18:02:13 +03:00
|
|
|
if (!channel || !channel->dvcman)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL;
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
EnterCriticalSection(&(channel->lock));
|
2020-08-12 11:10:18 +03:00
|
|
|
status =
|
|
|
|
drdynvc_write_data(channel->dvcman->drdynvc, channel->channel_id, pBuffer, cbSize, &close);
|
2014-12-27 23:20:29 +03:00
|
|
|
LeaveCriticalSection(&(channel->lock));
|
2020-08-12 11:10:18 +03:00
|
|
|
/* Close delayed, it removes the channel struct */
|
|
|
|
if (close)
|
|
|
|
dvcman_close_channel(channel->dvcman->drdynvc->channel_mgr, channel->channel_id, TRUE);
|
2014-12-27 23:20:29 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT dvcman_close_channel_iface(IWTSVirtualChannel* pChannel)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*)pChannel;
|
2017-01-17 18:02:13 +03:00
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_DBG(TAG, "close_channel_iface: id=%" PRIu32 "", channel->channel_id);
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT dvcman_create_channel(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr,
|
2016-09-26 13:12:37 +03:00
|
|
|
UINT32 ChannelId, const char* ChannelName)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2015-09-07 14:54:19 +03:00
|
|
|
BOOL bAccept;
|
2014-12-27 23:20:29 +03:00
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
DrdynvcClientContext* context;
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
|
2022-07-26 13:53:41 +03:00
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
IWTSVirtualChannelCallback* pCallback = NULL;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Lock(dvcman->listeners);
|
|
|
|
listener = (DVCMAN_LISTENER*)HashTable_GetItemValue(dvcman->listeners, ChannelName);
|
|
|
|
if (!listener)
|
|
|
|
{
|
|
|
|
error = ERROR_NOT_FOUND;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:13:16 +03:00
|
|
|
if (!(channel = dvcman_channel_new(drdynvc, pChannelMgr, ChannelId, ChannelName)))
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "dvcman_channel_new failed!");
|
2022-07-26 13:53:41 +03:00
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
goto out;
|
2015-05-29 15:02:31 +03:00
|
|
|
}
|
2015-01-26 21:26:38 +03:00
|
|
|
|
2017-08-31 10:06:59 +03:00
|
|
|
channel->status = ERROR_NOT_CONNECTED;
|
2022-07-26 13:53:41 +03:00
|
|
|
if (!HashTable_Insert(dvcman->channelsById, &channel->channel_id, channel))
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "unable to register channel in our channel list");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel->iface.Write = dvcman_write_channel;
|
|
|
|
channel->iface.Close = dvcman_close_channel_iface;
|
|
|
|
bAccept = TRUE;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
error = listener->listener_callback->OnNewChannelConnection(
|
|
|
|
listener->listener_callback, &channel->iface, NULL, &bAccept, &pCallback);
|
|
|
|
|
|
|
|
if (error != CHANNEL_RC_OK)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2022-07-26 13:53:41 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"OnNewChannelConnection failed with error %" PRIu32 "!", error);
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
if (!bAccept)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "OnNewChannelConnection returned with bAccept FALSE!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
goto out;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
2022-07-26 13:53:41 +03:00
|
|
|
|
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "listener %s created new channel %" PRIu32 "",
|
|
|
|
listener->channel_name, channel->channel_id);
|
|
|
|
channel->status = CHANNEL_RC_OK;
|
|
|
|
channel->channel_callback = pCallback;
|
|
|
|
channel->pInterface = listener->iface.pInterface;
|
|
|
|
context = dvcman->drdynvc->context;
|
|
|
|
|
|
|
|
IFCALLRET(context->OnChannelConnected, error, context, ChannelName, listener->iface.pInterface);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"context.OnChannelConnected failed with error %" PRIu32 "", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
HashTable_Unlock(dvcman->listeners);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
return error;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT dvcman_open_channel(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr,
|
2016-09-26 13:12:37 +03:00
|
|
|
UINT32 ChannelId)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
IWTSVirtualChannelCallback* pCallback;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = (DVCMAN_CHANNEL*)dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
2018-02-09 12:29:31 +03:00
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
if (!channel)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "ChannelId %" PRIu32 " not found!", ChannelId);
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (channel->status == CHANNEL_RC_OK)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
pCallback = channel->channel_callback;
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2020-05-25 15:04:17 +03:00
|
|
|
if (pCallback->OnOpen)
|
2015-07-30 16:49:21 +03:00
|
|
|
{
|
2020-05-25 15:04:17 +03:00
|
|
|
error = pCallback->OnOpen(pCallback);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "OnOpen failed with error %" PRIu32 "!",
|
|
|
|
error);
|
|
|
|
return error;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
}
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "open_channel: ChannelId %" PRIu32 "", ChannelId);
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2020-08-12 11:10:18 +03:00
|
|
|
UINT dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId,
|
|
|
|
BOOL bSendClosePDU)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
|
2020-03-03 20:18:00 +03:00
|
|
|
drdynvcPlugin* drdynvc = dvcman->drdynvc;
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
channel = (DVCMAN_CHANNEL*)dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
2014-12-27 23:20:29 +03:00
|
|
|
if (!channel)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
// WLog_Print(drdynvc->log, WLOG_ERROR, "ChannelId %"PRIu32" not found!", ChannelId);
|
2015-06-29 21:47:46 +03:00
|
|
|
/**
|
2019-11-06 17:24:51 +03:00
|
|
|
* Windows 8 / Windows Server 2012 send close requests for channels that failed to be
|
|
|
|
* created. Do not warn, simply return success here.
|
2015-06-29 21:47:46 +03:00
|
|
|
*/
|
2015-08-25 10:07:04 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2020-03-03 20:18:00 +03:00
|
|
|
if (drdynvc && bSendClosePDU)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
wStream* s = StreamPool_Take(dvcman->pool, 5);
|
2020-03-03 20:18:00 +03:00
|
|
|
if (!s)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "StreamPool_Take failed!");
|
2020-03-03 20:18:00 +03:00
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Stream_Write_UINT8(s, (CLOSE_REQUEST_PDU << 4) | 0x02);
|
|
|
|
Stream_Write_UINT32(s, ChannelId);
|
|
|
|
error = drdynvc_send(drdynvc, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Remove(dvcman->channelsById, &ChannelId);
|
2017-08-31 10:06:59 +03:00
|
|
|
return error;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2018-02-09 15:13:16 +03:00
|
|
|
static UINT dvcman_receive_channel_data_first(drdynvcPlugin* drdynvc,
|
2019-11-06 17:24:51 +03:00
|
|
|
IWTSVirtualChannelManager* pChannelMgr,
|
|
|
|
UINT32 ChannelId, UINT32 length)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = (DVCMAN_CHANNEL*)dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
2016-11-03 17:12:48 +03:00
|
|
|
/**
|
2019-11-06 17:24:51 +03:00
|
|
|
* Windows Server 2012 R2 can send some messages over
|
|
|
|
* Microsoft::Windows::RDS::Geometry::v08.01 even if the dynamic virtual channel wasn't
|
|
|
|
* registered on our side. Ignoring it works.
|
2016-11-03 17:12:48 +03:00
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "ChannelId %" PRIu32 " not found!", ChannelId);
|
2016-11-03 17:12:48 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->dvc_data)
|
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
|
|
|
|
channel->dvc_data = StreamPool_Take(channel->dvcman->pool, length);
|
2015-06-29 21:47:46 +03:00
|
|
|
|
2015-03-26 19:09:47 +03:00
|
|
|
if (!channel->dvc_data)
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "StreamPool_Take failed!");
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2016-07-14 13:44:17 +03:00
|
|
|
channel->dvc_data_length = length;
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2018-02-09 15:13:16 +03:00
|
|
|
static UINT dvcman_receive_channel_data(drdynvcPlugin* drdynvc,
|
2019-11-06 17:24:51 +03:00
|
|
|
IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId,
|
2021-03-12 18:54:45 +03:00
|
|
|
wStream* data, UINT32 ThreadingFlags)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
DVCMAN_CHANNEL* channel;
|
2015-05-29 15:02:31 +03:00
|
|
|
size_t dataSize = Stream_GetRemainingLength(data);
|
2019-11-06 17:24:51 +03:00
|
|
|
channel = (DVCMAN_CHANNEL*)dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
2016-07-14 13:44:17 +03:00
|
|
|
/* Windows 8.1 tries to open channels not created.
|
2019-11-06 17:24:51 +03:00
|
|
|
* Ignore cases like this. */
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "ChannelId %" PRIu32 " not found!", ChannelId);
|
2016-07-14 13:44:17 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->dvc_data)
|
|
|
|
{
|
|
|
|
/* Fragmented data */
|
2020-05-12 11:21:06 +03:00
|
|
|
if (Stream_GetPosition(channel->dvc_data) + dataSize > channel->dvc_data_length)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "data exceeding declared length!");
|
2014-12-27 23:20:29 +03:00
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
channel->dvc_data = NULL;
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
2018-09-20 10:06:01 +03:00
|
|
|
Stream_Copy(data, channel->dvc_data, dataSize);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
if (Stream_GetPosition(channel->dvc_data) >= channel->dvc_data_length)
|
2014-12-27 23:20:29 +03:00
|
|
|
{
|
|
|
|
Stream_SealLength(channel->dvc_data);
|
|
|
|
Stream_SetPosition(channel->dvc_data, 0);
|
2016-07-14 13:44:17 +03:00
|
|
|
status = channel->channel_callback->OnDataReceived(channel->channel_callback,
|
2019-11-06 17:24:51 +03:00
|
|
|
channel->dvc_data);
|
2014-12-27 23:20:29 +03:00
|
|
|
Stream_Release(channel->dvc_data);
|
|
|
|
channel->dvc_data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
status = channel->channel_callback->OnDataReceived(channel->channel_callback, data);
|
2014-12-27 23:20:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-01-29 14:07:05 +03:00
|
|
|
static UINT8 drdynvc_write_variable_uint(wStream* s, UINT32 val)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2019-01-29 14:07:05 +03:00
|
|
|
UINT8 cb;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
if (val <= 0xFF)
|
|
|
|
{
|
|
|
|
cb = 0;
|
2019-01-29 14:07:05 +03:00
|
|
|
Stream_Write_UINT8(s, (UINT8)val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else if (val <= 0xFFFF)
|
|
|
|
{
|
|
|
|
cb = 1;
|
2019-01-29 14:07:05 +03:00
|
|
|
Stream_Write_UINT16(s, (UINT16)val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-25 22:27:38 +04:00
|
|
|
cb = 2;
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT32(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-26 10:35:54 +03:00
|
|
|
static UINT drdynvc_send(drdynvcPlugin* drdynvc, wStream* s)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
if (!drdynvc)
|
2017-01-17 18:02:13 +03:00
|
|
|
status = CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
2014-11-12 21:34:07 +03:00
|
|
|
else
|
|
|
|
{
|
2021-09-06 17:46:01 +03:00
|
|
|
WINPR_ASSERT(drdynvc->channelEntryPoints.pVirtualChannelWriteEx);
|
2019-11-06 17:24:51 +03:00
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelWriteEx(
|
|
|
|
drdynvc->InitHandle, drdynvc->OpenHandle, Stream_Buffer(s),
|
|
|
|
(UINT32)Stream_GetPosition(s), s);
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2017-01-17 18:02:13 +03:00
|
|
|
switch (status)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2017-01-17 18:02:13 +03:00
|
|
|
case CHANNEL_RC_OK:
|
2018-01-30 13:36:17 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2018-04-09 12:09:56 +03:00
|
|
|
|
2017-01-17 18:02:13 +03:00
|
|
|
case CHANNEL_RC_NOT_CONNECTED:
|
2020-05-12 17:34:01 +03:00
|
|
|
Stream_Release(s);
|
2017-01-17 18:02:13 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2018-04-09 12:09:56 +03:00
|
|
|
|
2018-03-06 18:03:13 +03:00
|
|
|
case CHANNEL_RC_BAD_CHANNEL_HANDLE:
|
2020-05-12 17:34:01 +03:00
|
|
|
Stream_Release(s);
|
2018-03-06 18:03:13 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWriteEx failed with CHANNEL_RC_BAD_CHANNEL_HANDLE");
|
|
|
|
return status;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2017-01-17 18:02:13 +03:00
|
|
|
default:
|
2020-05-12 17:34:01 +03:00
|
|
|
Stream_Release(s);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"VirtualChannelWriteEx failed with %s [%08" PRIX32 "]",
|
|
|
|
WTSErrorToString(status), status);
|
2017-01-18 17:41:50 +03:00
|
|
|
return status;
|
2017-01-17 18:02:13 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, const BYTE* data,
|
2020-08-12 11:10:18 +03:00
|
|
|
UINT32 dataSize, BOOL* close)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* data_out;
|
2017-12-11 12:25:21 +03:00
|
|
|
size_t pos;
|
2019-01-29 14:07:05 +03:00
|
|
|
UINT8 cbChId;
|
|
|
|
UINT8 cbLen;
|
2015-05-29 15:02:31 +03:00
|
|
|
unsigned long chunkLength;
|
2020-03-04 11:15:31 +03:00
|
|
|
UINT status = CHANNEL_RC_BAD_INIT_HANDLE;
|
2020-05-12 11:21:06 +03:00
|
|
|
DVCMAN* dvcman;
|
2017-01-17 18:02:13 +03:00
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
dvcman = (DVCMAN*)drdynvc->channel_mgr;
|
|
|
|
|
2022-03-08 17:58:34 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_TRACE, "write_data: ChannelId=%" PRIu32 " size=%" PRIu32 "",
|
2019-11-06 17:24:51 +03:00
|
|
|
ChannelId, dataSize);
|
2020-05-12 11:21:06 +03:00
|
|
|
data_out = StreamPool_Take(dvcman->pool, CHANNEL_CHUNK_LENGTH);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
|
|
|
if (!data_out)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "StreamPool_Take failed!");
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 1);
|
2011-07-19 10:07:15 +04:00
|
|
|
cbChId = drdynvc_write_variable_uint(data_out, ChannelId);
|
2016-01-28 13:45:06 +03:00
|
|
|
pos = Stream_GetPosition(data_out);
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (dataSize == 0)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-08-12 11:10:18 +03:00
|
|
|
*close = TRUE;
|
2020-05-12 17:34:01 +03:00
|
|
|
Stream_Release(data_out);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2014-06-17 21:34:23 +04:00
|
|
|
else if (dataSize <= CHANNEL_CHUNK_LENGTH - pos)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 0);
|
2019-02-26 17:29:30 +03:00
|
|
|
Stream_Write_UINT8(data_out, (DATA_PDU << 4) | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, dataSize);
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Fragment the data */
|
2014-06-17 21:34:23 +04:00
|
|
|
cbLen = drdynvc_write_variable_uint(data_out, dataSize);
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2019-02-26 17:29:30 +03:00
|
|
|
Stream_Write_UINT8(data_out, (DATA_FIRST_PDU << 4) | cbChId | (cbLen << 2));
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-06-17 21:34:23 +04:00
|
|
|
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
|
|
|
|
Stream_Write(data_out, data, chunkLength);
|
|
|
|
data += chunkLength;
|
|
|
|
dataSize -= chunkLength;
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
while (status == CHANNEL_RC_OK && dataSize > 0)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
data_out = StreamPool_Take(dvcman->pool, CHANNEL_CHUNK_LENGTH);
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (!data_out)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "StreamPool_Take failed!");
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, 1);
|
2011-07-19 10:07:15 +04:00
|
|
|
cbChId = drdynvc_write_variable_uint(data_out, ChannelId);
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(data_out);
|
|
|
|
Stream_SetPosition(data_out, 0);
|
2019-02-26 17:29:30 +03:00
|
|
|
Stream_Write_UINT8(data_out, (DATA_PDU << 4) | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(data_out, pos);
|
2014-06-17 21:34:23 +04:00
|
|
|
chunkLength = dataSize;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (chunkLength > CHANNEL_CHUNK_LENGTH - pos)
|
|
|
|
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write(data_out, data, chunkLength);
|
|
|
|
data += chunkLength;
|
|
|
|
dataSize -= chunkLength;
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "VirtualChannelWriteEx failed with %s [%08" PRIX32 "]",
|
2017-01-17 18:02:13 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_send_capability_response(drdynvcPlugin* drdynvc)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-06-17 21:34:23 +04:00
|
|
|
wStream* s;
|
2020-05-12 11:21:06 +03:00
|
|
|
DVCMAN* dvcman;
|
2017-01-17 18:02:13 +03:00
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
dvcman = (DVCMAN*)drdynvc->channel_mgr;
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_TRACE, "capability_response");
|
2020-05-12 11:21:06 +03:00
|
|
|
s = StreamPool_Take(dvcman->pool, 4);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
{
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "Stream_Ndrdynvc_write_variable_uintew failed!");
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 0x0050); /* Cmd+Sp+cbChId+Pad. Note: MSTSC sends 0x005c */
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Write_UINT16(s, drdynvc->version);
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, s);
|
2014-06-03 21:00:03 +04:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "VirtualChannelWriteEx failed with %s [%08" PRIX32 "]",
|
2017-01-17 18:02:13 +03:00
|
|
|
WTSErrorToString(status), status);
|
2014-06-03 21:00:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT drdynvc_process_capability_request(drdynvcPlugin* drdynvc, int Sp, int cbChId,
|
|
|
|
wStream* s)
|
2014-06-03 21:00:03 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2017-01-17 18:02:13 +03:00
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 3))
|
2018-09-20 10:06:01 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_TRACE, "capability_request Sp=%d cbChId=%d", Sp, cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 1); /* pad */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, drdynvc->version);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2013-05-10 23:57:22 +04:00
|
|
|
/* RDP8 servers offer version 3, though Microsoft forgot to document it
|
|
|
|
* in their early documents. It behaves the same as version 2.
|
|
|
|
*/
|
|
|
|
if ((drdynvc->version == 2) || (drdynvc->version == 3))
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
2018-09-20 10:06:01 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge0);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge1);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge2);
|
|
|
|
Stream_Read_UINT16(s, drdynvc->PriorityCharge3);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
status = drdynvc_send_capability_response(drdynvc);
|
|
|
|
drdynvc->state = DRDYNVC_STATE_READY;
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2018-09-20 10:06:01 +03:00
|
|
|
static UINT32 drdynvc_cblen_to_bytes(int cbLen)
|
|
|
|
{
|
|
|
|
switch (cbLen)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
static UINT32 drdynvc_read_variable_uint(wStream* s, int cbLen)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 val;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
switch (cbLen)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT8(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case 1:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT16(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
default:
|
2014-06-17 21:34:23 +04:00
|
|
|
Stream_Read_UINT32(s, val);
|
2011-07-19 10:07:15 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2017-12-11 12:25:21 +03:00
|
|
|
size_t pos;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ChannelId;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* data_out;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT channel_status;
|
2018-09-20 10:06:01 +03:00
|
|
|
char* name;
|
|
|
|
size_t length;
|
2020-05-12 11:21:06 +03:00
|
|
|
DVCMAN* dvcman;
|
2022-07-26 13:53:41 +03:00
|
|
|
UINT32 retStatus;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2019-01-29 14:07:05 +03:00
|
|
|
WINPR_UNUSED(Sp);
|
2017-01-17 18:02:13 +03:00
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
dvcman = (DVCMAN*)drdynvc->channel_mgr;
|
2014-06-03 21:00:03 +04:00
|
|
|
if (drdynvc->state == DRDYNVC_STATE_CAPABILITIES)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* For some reason the server does not always send the
|
|
|
|
* capabilities pdu as it should. When this happens,
|
|
|
|
* send a capabilities response.
|
|
|
|
*/
|
|
|
|
drdynvc->version = 3;
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if ((status = drdynvc_send_capability_response(drdynvc)))
|
|
|
|
{
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "drdynvc_send_capability_response failed!");
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
|
|
|
}
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2014-06-03 21:00:03 +04:00
|
|
|
drdynvc->state = DRDYNVC_STATE_READY;
|
|
|
|
}
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, drdynvc_cblen_to_bytes(cbChId)))
|
2018-09-20 10:06:01 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s);
|
2018-10-03 16:16:59 +03:00
|
|
|
name = (char*)Stream_Pointer(s);
|
2018-09-20 10:06:01 +03:00
|
|
|
length = Stream_GetRemainingLength(s);
|
|
|
|
|
|
|
|
if (strnlen(name, length) >= length)
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG,
|
|
|
|
"process_create_request: ChannelId=%" PRIu32 " ChannelName=%s", ChannelId, name);
|
2018-09-20 10:06:01 +03:00
|
|
|
channel_status = dvcman_create_channel(drdynvc, drdynvc->channel_mgr, ChannelId, name);
|
2018-02-09 12:29:31 +03:00
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
data_out = StreamPool_Take(dvcman->pool, pos + 4);
|
2017-11-28 17:32:15 +03:00
|
|
|
if (!data_out)
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "StreamPool_Take failed!");
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2019-02-26 17:29:30 +03:00
|
|
|
Stream_Write_UINT8(data_out, (CREATE_REQUEST_PDU << 4) | cbChId);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 1);
|
2016-03-01 13:39:21 +03:00
|
|
|
Stream_Copy(s, data_out, pos - 1);
|
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
switch (channel_status)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2022-07-26 13:53:41 +03:00
|
|
|
case CHANNEL_RC_OK:
|
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "channel created");
|
|
|
|
retStatus = 0;
|
|
|
|
break;
|
|
|
|
case CHANNEL_RC_NO_MEMORY:
|
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "not enough memory for channel creation");
|
|
|
|
retStatus = STATUS_NO_MEMORY;
|
|
|
|
break;
|
|
|
|
case ERROR_NOT_FOUND:
|
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "no listener for '%s'", name);
|
|
|
|
retStatus = (UINT32)0xC0000001; /* same code used by mstsc, STATUS_UNSUCCESSFUL */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "channel creation error");
|
|
|
|
retStatus = (UINT32)0xC0000001; /* same code used by mstsc, STATUS_UNSUCCESSFUL */
|
|
|
|
break;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2022-07-26 13:53:41 +03:00
|
|
|
Stream_Write_UINT32(data_out, retStatus);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
status = drdynvc_send(drdynvc, data_out);
|
2018-02-09 12:29:31 +03:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "VirtualChannelWriteEx failed with %s [%08" PRIX32 "]",
|
2018-02-09 15:13:16 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
if (channel_status == CHANNEL_RC_OK)
|
2014-06-03 17:49:00 +04:00
|
|
|
{
|
2018-02-09 15:13:16 +03:00
|
|
|
if ((status = dvcman_open_channel(drdynvc, drdynvc->channel_mgr, ChannelId)))
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"dvcman_open_channel failed with error %" PRIu32 "!", status);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
|
|
|
}
|
2014-06-03 17:49:00 +04:00
|
|
|
}
|
2015-06-29 21:47:46 +03:00
|
|
|
else
|
|
|
|
{
|
2020-03-03 20:18:00 +03:00
|
|
|
if ((status = dvcman_close_channel(drdynvc->channel_mgr, ChannelId, FALSE)))
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"dvcman_close_channel failed with error %" PRIu32 "!", status);
|
2015-06-29 21:47:46 +03:00
|
|
|
}
|
2014-06-03 17:49:00 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2021-03-12 18:54:45 +03:00
|
|
|
static UINT drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s,
|
|
|
|
UINT32 ThreadingFlags)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2012-11-20 07:31:15 +04:00
|
|
|
UINT32 Length;
|
|
|
|
UINT32 ChannelId;
|
2018-09-20 10:06:01 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(
|
|
|
|
TAG, s, drdynvc_cblen_to_bytes(cbChId) + drdynvc_cblen_to_bytes(Sp)))
|
2018-09-20 10:06:01 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
|
|
|
Length = drdynvc_read_variable_uint(s, Sp);
|
2022-03-08 17:58:34 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_TRACE,
|
2019-11-06 17:24:51 +03:00
|
|
|
"process_data_first: Sp=%d cbChId=%d, ChannelId=%" PRIu32 " Length=%" PRIu32 "", Sp,
|
2018-02-09 15:13:16 +03:00
|
|
|
cbChId, ChannelId, Length);
|
2019-11-06 17:24:51 +03:00
|
|
|
status = dvcman_receive_channel_data_first(drdynvc, drdynvc->channel_mgr, ChannelId, Length);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2020-03-03 20:18:00 +03:00
|
|
|
if (status == CHANNEL_RC_OK)
|
2021-03-12 18:54:45 +03:00
|
|
|
status = dvcman_receive_channel_data(drdynvc, drdynvc->channel_mgr, ChannelId, s,
|
|
|
|
ThreadingFlags);
|
2020-03-03 20:18:00 +03:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
status = dvcman_close_channel(drdynvc->channel_mgr, ChannelId, TRUE);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2020-03-03 20:18:00 +03:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2021-03-12 18:54:45 +03:00
|
|
|
static UINT drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s,
|
|
|
|
UINT32 ThreadingFlags)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 ChannelId;
|
2020-03-03 20:18:00 +03:00
|
|
|
UINT status;
|
2018-09-20 10:06:01 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, drdynvc_cblen_to_bytes(cbChId)))
|
2018-09-20 10:06:01 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_TRACE, "process_data: Sp=%d cbChId=%d, ChannelId=%" PRIu32 "", Sp,
|
|
|
|
cbChId, ChannelId);
|
2021-03-12 18:54:45 +03:00
|
|
|
status =
|
|
|
|
dvcman_receive_channel_data(drdynvc, drdynvc->channel_mgr, ChannelId, s, ThreadingFlags);
|
2020-03-03 20:18:00 +03:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
status = dvcman_close_channel(drdynvc->channel_mgr, ChannelId, TRUE);
|
|
|
|
|
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-11-12 21:34:07 +03:00
|
|
|
UINT32 ChannelId;
|
2018-09-20 10:06:01 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, drdynvc_cblen_to_bytes(cbChId)))
|
2018-09-20 10:06:01 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2011-09-19 18:53:00 +04:00
|
|
|
ChannelId = drdynvc_read_variable_uint(s, cbChId);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG,
|
|
|
|
"process_close_request: Sp=%d cbChId=%d, ChannelId=%" PRIu32 "", Sp, cbChId,
|
|
|
|
ChannelId);
|
2014-12-28 19:13:51 +03:00
|
|
|
|
2020-03-03 20:18:00 +03:00
|
|
|
if ((error = dvcman_close_channel(drdynvc->channel_mgr, ChannelId, TRUE)))
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "dvcman_close_channel failed with error %" PRIu32 "!",
|
|
|
|
error);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return error;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2021-03-12 18:54:45 +03:00
|
|
|
static UINT drdynvc_order_recv(drdynvcPlugin* drdynvc, wStream* s, UINT32 ThreadingFlags)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
int value;
|
|
|
|
int Cmd;
|
|
|
|
int Sp;
|
|
|
|
int cbChId;
|
2018-09-20 10:06:01 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2018-09-20 10:06:01 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, value);
|
2011-07-19 10:07:15 +04:00
|
|
|
Cmd = (value & 0xf0) >> 4;
|
|
|
|
Sp = (value & 0x0c) >> 2;
|
|
|
|
cbChId = (value & 0x03) >> 0;
|
2022-03-08 17:58:34 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_TRACE, "order_recv: Cmd=0x%x, Sp=%d cbChId=%d", Cmd, Sp, cbChId);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
switch (Cmd)
|
|
|
|
{
|
|
|
|
case CAPABILITY_REQUEST_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_capability_request(drdynvc, Sp, cbChId, s);
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case CREATE_REQUEST_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_create_request(drdynvc, Sp, cbChId, s);
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case DATA_FIRST_PDU:
|
2021-03-12 18:54:45 +03:00
|
|
|
return drdynvc_process_data_first(drdynvc, Sp, cbChId, s, ThreadingFlags);
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case DATA_PDU:
|
2021-03-12 18:54:45 +03:00
|
|
|
return drdynvc_process_data(drdynvc, Sp, cbChId, s, ThreadingFlags);
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
case CLOSE_REQUEST_PDU:
|
2015-05-29 15:02:31 +03:00
|
|
|
return drdynvc_process_close_request(drdynvc, Sp, cbChId, s);
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
default:
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "unknown drdynvc cmd 0x%x", Cmd);
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT drdynvc_virtual_channel_event_data_received(drdynvcPlugin* drdynvc, void* pData,
|
|
|
|
UINT32 dataLength, UINT32 totalLength,
|
|
|
|
UINT32 dataFlags)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
|
|
|
wStream* data_in;
|
|
|
|
|
|
|
|
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
|
|
|
|
{
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
DVCMAN* mgr = (DVCMAN*)drdynvc->channel_mgr;
|
2014-11-12 21:34:07 +03:00
|
|
|
if (drdynvc->data_in)
|
2020-05-12 11:21:06 +03:00
|
|
|
Stream_Release(drdynvc->data_in);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
drdynvc->data_in = StreamPool_Take(mgr->pool, totalLength);
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2015-03-30 18:23:22 +03:00
|
|
|
if (!(data_in = drdynvc->data_in))
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "StreamPool_Take failed!");
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-03-30 18:23:22 +03:00
|
|
|
|
2018-09-20 10:06:01 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(data_in, dataLength))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!");
|
2020-05-12 11:21:06 +03:00
|
|
|
Stream_Release(drdynvc->data_in);
|
2015-03-26 19:09:47 +03:00
|
|
|
drdynvc->data_in = NULL;
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-03-26 19:09:47 +03:00
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
Stream_Write(data_in, pData, dataLength);
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
const size_t cap = Stream_Capacity(data_in);
|
|
|
|
const size_t pos = Stream_GetPosition(data_in);
|
|
|
|
if (cap < pos)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "drdynvc_plugin_process_received: read error");
|
2015-05-29 15:02:31 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
drdynvc->data_in = NULL;
|
|
|
|
Stream_SealLength(data_in);
|
|
|
|
Stream_SetPosition(data_in, 0);
|
|
|
|
|
2022-06-27 10:40:14 +03:00
|
|
|
if (drdynvc->async)
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
2022-06-27 10:40:14 +03:00
|
|
|
if (!MessageQueue_Post(drdynvc->queue, NULL, 0, (void*)data_in, NULL))
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "MessageQueue_Post failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT error = drdynvc_order_recv(drdynvc, data_in, TRUE);
|
|
|
|
Stream_Release(data_in);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_WARN,
|
|
|
|
"drdynvc_order_recv failed with error %" PRIu32 "!", error);
|
|
|
|
}
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 18:58:38 +03:00
|
|
|
static void VCAPITYPE drdynvc_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT event, LPVOID pData,
|
|
|
|
UINT32 dataLength, UINT32 totalLength,
|
|
|
|
UINT32 dataFlags)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*)lpUserParam;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_DATA_RECEIVED:
|
2020-01-29 10:52:25 +03:00
|
|
|
if (!drdynvc || (drdynvc->OpenHandle != openHandle))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_open_event: error no match");
|
|
|
|
return;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_data_received(drdynvc, pData, dataLength,
|
|
|
|
totalLength, dataFlags)))
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
2019-11-06 17:24:51 +03:00
|
|
|
"drdynvc_virtual_channel_event_data_received failed with error %" PRIu32
|
|
|
|
"",
|
|
|
|
error);
|
2016-11-23 15:17:56 +03:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
|
|
|
|
2019-10-28 17:13:42 +03:00
|
|
|
case CHANNEL_EVENT_WRITE_CANCELLED:
|
2014-11-12 21:34:07 +03:00
|
|
|
case CHANNEL_EVENT_WRITE_COMPLETE:
|
2019-10-28 16:57:39 +03:00
|
|
|
{
|
2019-10-28 18:43:47 +03:00
|
|
|
wStream* s = (wStream*)pData;
|
2020-05-12 11:21:06 +03:00
|
|
|
Stream_Release(s);
|
2019-10-28 16:57:39 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2015-01-20 13:58:04 +03:00
|
|
|
|
|
|
|
case CHANNEL_EVENT_USER:
|
|
|
|
break;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
2015-07-15 10:50:35 +03:00
|
|
|
|
2020-01-29 10:52:25 +03:00
|
|
|
if (error && drdynvc && drdynvc->rdpcontext)
|
2019-11-06 17:24:51 +03:00
|
|
|
setChannelError(drdynvc->rdpcontext, error,
|
|
|
|
"drdynvc_virtual_channel_open_event reported an error");
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
static BOOL channelByIdCleanerFn(const void* key, void* value, void* arg)
|
|
|
|
{
|
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*)arg;
|
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*)value;
|
|
|
|
|
|
|
|
dvcman_close_channel(drdynvc->channel_mgr, channel->channel_id, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-03-07 14:03:10 +03:00
|
|
|
static DWORD WINAPI drdynvc_virtual_channel_client_thread(LPVOID arg)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2021-03-12 18:54:45 +03:00
|
|
|
/* TODO: rewrite this */
|
2014-11-12 21:34:07 +03:00
|
|
|
wStream* data;
|
|
|
|
wMessage message;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*)arg;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2017-01-17 18:02:13 +03:00
|
|
|
if (!drdynvc)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ExitThread((DWORD)CHANNEL_RC_BAD_CHANNEL_HANDLE);
|
2018-03-07 14:03:10 +03:00
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
2017-01-17 18:02:13 +03:00
|
|
|
}
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
while (1)
|
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
if (!MessageQueue_Wait(drdynvc->queue))
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "MessageQueue_Wait failed!");
|
2015-07-15 10:50:35 +03:00
|
|
|
error = ERROR_INTERNAL_ERROR;
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (!MessageQueue_Peek(drdynvc->queue, &message, TRUE))
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "MessageQueue_Peek failed!");
|
2015-07-15 10:50:35 +03:00
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (message.id == 0)
|
|
|
|
{
|
2021-03-12 18:54:45 +03:00
|
|
|
UINT32 ThreadingFlags = TRUE;
|
2019-11-06 17:24:51 +03:00
|
|
|
data = (wStream*)message.wParam;
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2021-03-12 18:54:45 +03:00
|
|
|
if ((error = drdynvc_order_recv(drdynvc, data, ThreadingFlags)))
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2020-01-13 14:23:30 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_WARN,
|
2019-11-06 17:24:51 +03:00
|
|
|
"drdynvc_order_recv failed with error %" PRIu32 "!", error);
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
Stream_Release(data);
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 17:34:12 +03:00
|
|
|
{
|
|
|
|
/* Disconnect remaining dynamic channels that the server did not.
|
2019-11-06 17:24:51 +03:00
|
|
|
* This is required to properly shut down channels by calling the appropriate
|
|
|
|
* event handlers. */
|
2017-02-15 17:34:12 +03:00
|
|
|
DVCMAN* drdynvcMgr = (DVCMAN*)drdynvc->channel_mgr;
|
|
|
|
|
2022-07-26 13:53:41 +03:00
|
|
|
HashTable_Foreach(drdynvcMgr->channelsById, channelByIdCleanerFn, drdynvc);
|
2017-02-15 17:34:12 +03:00
|
|
|
}
|
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && drdynvc->rdpcontext)
|
2016-11-23 15:17:56 +03:00
|
|
|
setChannelError(drdynvc->rdpcontext, error,
|
|
|
|
"drdynvc_virtual_channel_client_thread reported an error");
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
ExitThread((DWORD)error);
|
2018-03-07 14:03:10 +03:00
|
|
|
return error;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 12:29:31 +03:00
|
|
|
static void drdynvc_queue_object_free(void* obj)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
wMessage* msg = (wMessage*)obj;
|
|
|
|
|
|
|
|
if (!msg || (msg->id != 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = (wStream*)msg->wParam;
|
|
|
|
|
|
|
|
if (s)
|
2020-05-12 11:21:06 +03:00
|
|
|
Stream_Release(s);
|
2018-02-09 12:29:31 +03:00
|
|
|
}
|
|
|
|
|
2020-05-18 15:20:11 +03:00
|
|
|
static UINT drdynvc_virtual_channel_event_initialized(drdynvcPlugin* drdynvc, LPVOID pData,
|
|
|
|
UINT32 dataLength)
|
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
wObject* obj;
|
2020-05-18 15:20:11 +03:00
|
|
|
WINPR_UNUSED(pData);
|
|
|
|
WINPR_UNUSED(dataLength);
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
drdynvc->queue = MessageQueue_New(NULL);
|
|
|
|
|
|
|
|
if (!drdynvc->queue)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "MessageQueue_New failed!");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
obj = MessageQueue_Object(drdynvc->queue);
|
|
|
|
obj->fnObjectFree = drdynvc_queue_object_free;
|
2020-05-18 15:20:11 +03:00
|
|
|
drdynvc->channel_mgr = dvcman_new(drdynvc);
|
|
|
|
|
|
|
|
if (!drdynvc->channel_mgr)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "dvcman_new failed!");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
error:
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-11-23 15:17:56 +03:00
|
|
|
static UINT drdynvc_virtual_channel_event_connected(drdynvcPlugin* drdynvc, LPVOID pData,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 dataLength)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2016-11-15 18:58:38 +03:00
|
|
|
UINT error;
|
2014-11-12 21:34:07 +03:00
|
|
|
UINT32 status;
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2012-11-20 07:31:15 +04:00
|
|
|
rdpSettings* settings;
|
2017-01-17 18:02:13 +03:00
|
|
|
|
2022-03-24 15:37:46 +03:00
|
|
|
WINPR_ASSERT(drdynvc);
|
2019-01-29 14:07:05 +03:00
|
|
|
WINPR_UNUSED(pData);
|
|
|
|
WINPR_UNUSED(dataLength);
|
|
|
|
|
2017-01-17 18:02:13 +03:00
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2021-09-06 17:46:01 +03:00
|
|
|
WINPR_ASSERT(drdynvc->channelEntryPoints.pVirtualChannelOpenEx);
|
2019-11-06 17:24:51 +03:00
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelOpenEx(
|
|
|
|
drdynvc->InitHandle, &drdynvc->OpenHandle, drdynvc->channelDef.name,
|
|
|
|
drdynvc_virtual_channel_open_event_ex);
|
2014-11-12 21:34:07 +03:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "pVirtualChannelOpen failed with %s [%08" PRIX32 "]",
|
2017-01-17 18:02:13 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2022-03-24 15:37:46 +03:00
|
|
|
WINPR_ASSERT(drdynvc->rdpcontext);
|
2022-03-24 13:04:30 +03:00
|
|
|
settings = drdynvc->rdpcontext->settings;
|
2022-03-24 15:37:46 +03:00
|
|
|
WINPR_ASSERT(settings);
|
2012-11-20 07:31:15 +04:00
|
|
|
|
2022-03-24 13:04:30 +03:00
|
|
|
for (index = 0; index < freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount);
|
|
|
|
index++)
|
2012-11-20 07:31:15 +04:00
|
|
|
{
|
2020-11-18 09:51:45 +03:00
|
|
|
const ADDIN_ARGV* args = settings->DynamicChannelArray[index];
|
2022-06-22 13:54:58 +03:00
|
|
|
error = dvcman_load_addin(drdynvc, drdynvc->channel_mgr, args, drdynvc->rdpcontext);
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
if (CHANNEL_RC_OK != error)
|
|
|
|
goto error;
|
2012-11-20 07:31:15 +04:00
|
|
|
}
|
|
|
|
|
2018-02-09 15:13:16 +03:00
|
|
|
if ((error = dvcman_init(drdynvc, drdynvc->channel_mgr)))
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "dvcman_init failed with error %" PRIu32 "!", error);
|
2015-05-29 15:02:31 +03:00
|
|
|
goto error;
|
|
|
|
}
|
2014-06-03 21:00:03 +04:00
|
|
|
|
|
|
|
drdynvc->state = DRDYNVC_STATE_CAPABILITIES;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2022-06-27 10:40:14 +03:00
|
|
|
if (drdynvc->async)
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2022-06-27 10:40:14 +03:00
|
|
|
if (!(drdynvc->thread = CreateThread(NULL, 0, drdynvc_virtual_channel_client_thread,
|
|
|
|
(void*)drdynvc, 0, NULL)))
|
|
|
|
{
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "CreateThread failed!");
|
|
|
|
goto error;
|
|
|
|
}
|
2015-05-29 15:02:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
return error;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_virtual_channel_event_disconnected(drdynvcPlugin* drdynvc)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-12-27 21:50:50 +03:00
|
|
|
|
2017-01-17 18:02:13 +03:00
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2019-01-02 18:35:24 +03:00
|
|
|
if (drdynvc->OpenHandle == 0)
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
|
2021-09-06 17:46:01 +03:00
|
|
|
if (drdynvc->queue)
|
2016-03-07 14:54:49 +03:00
|
|
|
{
|
2021-09-06 17:46:01 +03:00
|
|
|
if (!MessageQueue_PostQuit(drdynvc->queue, 0))
|
|
|
|
{
|
|
|
|
status = GetLastError();
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"MessageQueue_PostQuit failed with error %" PRIu32 "", status);
|
|
|
|
return status;
|
|
|
|
}
|
2017-01-17 18:02:13 +03:00
|
|
|
}
|
|
|
|
|
2021-09-06 17:46:01 +03:00
|
|
|
if (drdynvc->thread)
|
2017-01-17 18:02:13 +03:00
|
|
|
{
|
2021-09-06 17:46:01 +03:00
|
|
|
if (WaitForSingleObject(drdynvc->thread, INFINITE) != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
status = GetLastError();
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
|
|
|
"WaitForSingleObject failed with error %" PRIu32 "", status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(drdynvc->thread);
|
|
|
|
drdynvc->thread = NULL;
|
2016-03-07 14:54:49 +03:00
|
|
|
}
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2021-09-06 17:46:01 +03:00
|
|
|
WINPR_ASSERT(drdynvc->channelEntryPoints.pVirtualChannelCloseEx);
|
2016-11-23 15:17:56 +03:00
|
|
|
status = drdynvc->channelEntryPoints.pVirtualChannelCloseEx(drdynvc->InitHandle,
|
2019-11-06 17:24:51 +03:00
|
|
|
drdynvc->OpenHandle);
|
2015-02-07 01:35:14 +03:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
2015-01-20 13:58:04 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "pVirtualChannelClose failed with %s [%08" PRIX32 "]",
|
2017-01-17 18:02:13 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-01-20 13:58:04 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2020-05-19 14:11:32 +03:00
|
|
|
dvcman_clear(drdynvc, drdynvc->channel_mgr);
|
2021-09-06 17:46:01 +03:00
|
|
|
if (drdynvc->queue)
|
|
|
|
MessageQueue_Clear(drdynvc->queue);
|
2016-08-09 13:04:06 +03:00
|
|
|
drdynvc->OpenHandle = 0;
|
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
if (drdynvc->data_in)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
Stream_Release(drdynvc->data_in);
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->data_in = NULL;
|
|
|
|
}
|
2014-06-20 01:08:50 +04:00
|
|
|
|
2015-05-29 15:02:31 +03:00
|
|
|
return status;
|
2015-01-20 13:58:04 +03:00
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT drdynvc_virtual_channel_event_terminated(drdynvcPlugin* drdynvc)
|
2015-01-20 13:58:04 +03:00
|
|
|
{
|
2017-01-17 18:02:13 +03:00
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-06-03 19:45:18 +03:00
|
|
|
MessageQueue_Free(drdynvc->queue);
|
|
|
|
drdynvc->queue = NULL;
|
|
|
|
|
2020-05-18 15:20:11 +03:00
|
|
|
if (drdynvc->channel_mgr)
|
|
|
|
{
|
|
|
|
dvcman_free(drdynvc, drdynvc->channel_mgr);
|
|
|
|
drdynvc->channel_mgr = NULL;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
drdynvc->InitHandle = 0;
|
2017-07-18 15:37:46 +03:00
|
|
|
free(drdynvc->context);
|
2014-12-27 23:20:29 +03:00
|
|
|
free(drdynvc);
|
2015-05-29 15:02:31 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 19:07:01 +03:00
|
|
|
static UINT drdynvc_virtual_channel_event_attached(drdynvcPlugin* drdynvc)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2020-11-10 10:14:56 +03:00
|
|
|
size_t i;
|
2016-12-19 19:07:01 +03:00
|
|
|
DVCMAN* dvcman;
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
dvcman = (DVCMAN*)drdynvc->channel_mgr;
|
2016-12-19 19:07:01 +03:00
|
|
|
|
|
|
|
if (!dvcman)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
ArrayList_Lock(dvcman->plugins);
|
|
|
|
for (i = 0; i < ArrayList_Count(dvcman->plugins); i++)
|
2016-12-19 19:07:01 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
IWTSPlugin* pPlugin = ArrayList_GetItem(dvcman->plugins, i);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
error = IFCALLRESULT(CHANNEL_RC_OK, pPlugin->Attached, pPlugin);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "Attach failed with error %" PRIu32 "!", error);
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
fail:
|
|
|
|
ArrayList_Unlock(dvcman->plugins);
|
|
|
|
return error;
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT drdynvc_virtual_channel_event_detached(drdynvcPlugin* drdynvc)
|
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2020-11-10 10:14:56 +03:00
|
|
|
size_t i;
|
2016-12-19 19:07:01 +03:00
|
|
|
DVCMAN* dvcman;
|
|
|
|
|
|
|
|
if (!drdynvc)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
dvcman = (DVCMAN*)drdynvc->channel_mgr;
|
2016-12-19 19:07:01 +03:00
|
|
|
|
|
|
|
if (!dvcman)
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL_HANDLE;
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
ArrayList_Lock(dvcman->plugins);
|
|
|
|
for (i = 0; i < ArrayList_Count(dvcman->plugins); i++)
|
2016-12-19 19:07:01 +03:00
|
|
|
{
|
2020-05-12 11:21:06 +03:00
|
|
|
IWTSPlugin* pPlugin = ArrayList_GetItem(dvcman->plugins, i);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
error = IFCALLRESULT(CHANNEL_RC_OK, pPlugin->Detached, pPlugin);
|
|
|
|
if (error != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "Detach failed with error %" PRIu32 "!", error);
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 11:21:06 +03:00
|
|
|
fail:
|
|
|
|
ArrayList_Unlock(dvcman->plugins);
|
|
|
|
|
|
|
|
return error;
|
2016-12-19 19:07:01 +03:00
|
|
|
}
|
|
|
|
|
2016-11-23 15:17:56 +03:00
|
|
|
static VOID VCAPITYPE drdynvc_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT event, LPVOID pData,
|
|
|
|
UINT dataLength)
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*)lpUserParam;
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if (!drdynvc || (drdynvc->InitHandle != pInitHandle))
|
2014-11-12 21:34:07 +03:00
|
|
|
{
|
2018-03-06 18:03:13 +03:00
|
|
|
WLog_ERR(TAG, "drdynvc_virtual_channel_init_event: error no match");
|
2016-03-14 15:19:08 +03:00
|
|
|
return;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
2020-05-18 15:20:11 +03:00
|
|
|
case CHANNEL_EVENT_INITIALIZED:
|
|
|
|
error = drdynvc_virtual_channel_event_initialized(drdynvc, pData, dataLength);
|
|
|
|
break;
|
2014-11-12 21:34:07 +03:00
|
|
|
case CHANNEL_EVENT_CONNECTED:
|
2016-11-15 18:58:38 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_connected(drdynvc, pData, dataLength)))
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
2019-11-06 17:24:51 +03:00
|
|
|
"drdynvc_virtual_channel_event_connected failed with error %" PRIu32 "",
|
|
|
|
error);
|
2016-11-23 15:17:56 +03:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_DISCONNECTED:
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_disconnected(drdynvc)))
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
2019-11-06 17:24:51 +03:00
|
|
|
"drdynvc_virtual_channel_event_disconnected failed with error %" PRIu32
|
|
|
|
"",
|
|
|
|
error);
|
2016-11-23 15:17:56 +03:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_TERMINATED:
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_terminated(drdynvc)))
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
2019-11-06 17:24:51 +03:00
|
|
|
"drdynvc_virtual_channel_event_terminated failed with error %" PRIu32 "",
|
|
|
|
error);
|
2016-11-23 15:17:56 +03:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
break;
|
2016-12-19 19:07:01 +03:00
|
|
|
|
|
|
|
case CHANNEL_EVENT_ATTACHED:
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_attached(drdynvc)))
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
2019-11-06 17:24:51 +03:00
|
|
|
"drdynvc_virtual_channel_event_attached failed with error %" PRIu32 "",
|
|
|
|
error);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_DETACHED:
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((error = drdynvc_virtual_channel_event_detached(drdynvc)))
|
2017-01-17 18:02:13 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR,
|
2019-11-06 17:24:51 +03:00
|
|
|
"drdynvc_virtual_channel_event_detached failed with error %" PRIu32 "",
|
|
|
|
error);
|
2016-12-19 19:07:01 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-11-12 21:34:07 +03:00
|
|
|
}
|
2016-07-14 13:44:17 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && drdynvc->rdpcontext)
|
2016-11-23 15:17:56 +03:00
|
|
|
setChannelError(drdynvc->rdpcontext, error,
|
|
|
|
"drdynvc_virtual_channel_init_event_ex reported an error");
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
/**
|
|
|
|
* Channel Client Interface
|
|
|
|
*/
|
|
|
|
|
2016-04-26 10:35:54 +03:00
|
|
|
static int drdynvc_get_version(DrdynvcClientContext* context)
|
2013-05-14 00:07:42 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
drdynvcPlugin* drdynvc = (drdynvcPlugin*)context->handle;
|
2013-05-14 00:07:42 +04:00
|
|
|
return drdynvc->version;
|
|
|
|
}
|
|
|
|
|
2012-10-09 06:48:17 +04:00
|
|
|
/* drdynvc is always built-in */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define VirtualChannelEntryEx drdynvc_VirtualChannelEntryEx
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2016-11-16 17:52:24 +03:00
|
|
|
BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS_EX pEntryPoints, PVOID pInitHandle)
|
2012-10-09 04:26:11 +04:00
|
|
|
{
|
2015-01-20 13:58:04 +03:00
|
|
|
UINT rc;
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvcPlugin* drdynvc;
|
2016-09-26 13:12:14 +03:00
|
|
|
DrdynvcClientContext* context = NULL;
|
2016-11-15 18:58:38 +03:00
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx;
|
2019-11-06 17:24:51 +03:00
|
|
|
drdynvc = (drdynvcPlugin*)calloc(1, sizeof(drdynvcPlugin));
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
if (!drdynvc)
|
2015-05-29 15:02:31 +03:00
|
|
|
{
|
2018-03-06 18:03:13 +03:00
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2014-06-17 21:34:23 +04:00
|
|
|
return FALSE;
|
2015-05-29 15:02:31 +03:00
|
|
|
}
|
2014-06-17 21:34:23 +04:00
|
|
|
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->channelDef.options =
|
2019-11-06 17:24:51 +03:00
|
|
|
CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP;
|
2021-08-25 11:02:46 +03:00
|
|
|
sprintf_s(drdynvc->channelDef.name, ARRAYSIZE(drdynvc->channelDef.name),
|
|
|
|
DRDYNVC_SVC_CHANNEL_NAME);
|
2014-11-12 21:34:07 +03:00
|
|
|
drdynvc->state = DRDYNVC_STATE_INITIAL;
|
2019-11-06 17:24:51 +03:00
|
|
|
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints;
|
2016-11-15 18:58:38 +03:00
|
|
|
|
|
|
|
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) &&
|
2016-07-14 13:44:17 +03:00
|
|
|
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
|
2013-05-14 00:07:42 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (DrdynvcClientContext*)calloc(1, sizeof(DrdynvcClientContext));
|
2014-06-17 21:34:23 +04:00
|
|
|
|
|
|
|
if (!context)
|
2014-11-16 18:02:28 +03:00
|
|
|
{
|
2018-02-09 15:13:16 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "calloc failed!");
|
2014-11-16 18:02:28 +03:00
|
|
|
free(drdynvc);
|
2015-05-29 15:02:31 +03:00
|
|
|
return FALSE;
|
2014-11-16 18:02:28 +03:00
|
|
|
}
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
context->handle = (void*)drdynvc;
|
2014-11-12 21:34:07 +03:00
|
|
|
context->custom = NULL;
|
|
|
|
drdynvc->context = context;
|
2013-05-14 00:07:42 +04:00
|
|
|
context->GetVersion = drdynvc_get_version;
|
2015-07-15 10:50:35 +03:00
|
|
|
drdynvc->rdpcontext = pEntryPointsEx->context;
|
2022-06-27 10:40:14 +03:00
|
|
|
if (!freerdp_settings_get_bool(drdynvc->rdpcontext->settings, FreeRDP_TransportDumpReplay))
|
|
|
|
drdynvc->async = TRUE;
|
2013-05-14 00:07:42 +04:00
|
|
|
}
|
|
|
|
|
2018-02-09 15:13:16 +03:00
|
|
|
drdynvc->log = WLog_Get(TAG);
|
2016-11-15 18:58:38 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_DEBUG, "VirtualChannelEntryEx");
|
2019-11-06 17:24:51 +03:00
|
|
|
CopyMemory(&(drdynvc->channelEntryPoints), pEntryPoints,
|
|
|
|
sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX));
|
2016-11-15 18:58:38 +03:00
|
|
|
drdynvc->InitHandle = pInitHandle;
|
2021-09-06 17:46:01 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(drdynvc->channelEntryPoints.pVirtualChannelInitEx);
|
2019-11-06 17:24:51 +03:00
|
|
|
rc = drdynvc->channelEntryPoints.pVirtualChannelInitEx(
|
|
|
|
drdynvc, context, pInitHandle, &drdynvc->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
|
|
|
|
drdynvc_virtual_channel_init_event_ex);
|
2015-05-29 15:02:31 +03:00
|
|
|
|
2015-01-20 13:58:04 +03:00
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(drdynvc->log, WLOG_ERROR, "pVirtualChannelInit failed with %s [%08" PRIX32 "]",
|
2017-01-17 18:02:13 +03:00
|
|
|
WTSErrorToString(rc), rc);
|
2016-08-09 13:04:06 +03:00
|
|
|
free(drdynvc->context);
|
2015-01-20 13:58:04 +03:00
|
|
|
free(drdynvc);
|
2015-05-29 15:02:31 +03:00
|
|
|
return FALSE;
|
2015-01-20 13:58:04 +03:00
|
|
|
}
|
2014-11-12 21:34:07 +03:00
|
|
|
|
2016-11-23 15:17:56 +03:00
|
|
|
drdynvc->channelEntryPoints.pInterface = context;
|
2015-05-29 15:02:31 +03:00
|
|
|
return TRUE;
|
2012-10-09 04:26:11 +04:00
|
|
|
}
|