2019-08-19 16:05:59 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* FreeRDP Proxy Server modules API
|
|
|
|
*
|
|
|
|
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
|
|
|
* Copyright 2019 Idan Freiberg <speidy@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-06-09 15:03:34 +03:00
|
|
|
#include <winpr/assert.h>
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
#include <winpr/file.h>
|
2019-08-19 16:05:59 +03:00
|
|
|
#include <winpr/wlog.h>
|
|
|
|
#include <winpr/library.h>
|
|
|
|
#include <freerdp/api.h>
|
2019-12-31 12:16:12 +03:00
|
|
|
#include <freerdp/build-config.h>
|
2019-08-19 16:05:59 +03:00
|
|
|
|
|
|
|
#include "pf_log.h"
|
|
|
|
#include "pf_modules.h"
|
|
|
|
#include "pf_context.h"
|
|
|
|
|
|
|
|
#define TAG PROXY_TAG("modules")
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
#define MODULE_ENTRY_POINT "proxy_module_entry_point"
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
static wArrayList* plugins_list = NULL; /* list of all loaded plugins */
|
|
|
|
static wArrayList* handles_list = NULL; /* list of module handles to free at shutdown */
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
typedef BOOL (*moduleEntryPoint)(proxyPluginsManager* plugins_manager);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-09-08 14:03:56 +03:00
|
|
|
static const char* FILTER_TYPE_STRINGS[] = { "KEYBOARD_EVENT", "MOUSE_EVENT", "CLIENT_CHANNEL_DATA",
|
|
|
|
"SERVER_CHANNEL_DATA", "SERVER_FETCH_TARGET_ADDR" };
|
2019-08-19 16:05:59 +03:00
|
|
|
|
|
|
|
static const char* HOOK_TYPE_STRINGS[] = {
|
2020-05-19 14:57:15 +03:00
|
|
|
"CLIENT_PRE_CONNECT", "CLIENT_POST_CONNECT", "CLIENT_LOGIN_FAILURE", "CLIENT_END_PAINT",
|
|
|
|
"SERVER_POST_CONNECT", "SERVER_CHANNELS_INIT", "SERVER_CHANNELS_FREE", "SERVER_SESSION_END",
|
2019-08-19 16:05:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char* pf_modules_get_filter_type_string(PF_FILTER_TYPE result)
|
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
if (result >= FILTER_TYPE_KEYBOARD && result < FILTER_LAST)
|
2019-08-19 16:05:59 +03:00
|
|
|
return FILTER_TYPE_STRINGS[result];
|
|
|
|
else
|
|
|
|
return "FILTER_UNKNOWN";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* pf_modules_get_hook_type_string(PF_HOOK_TYPE result)
|
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
if (result >= HOOK_TYPE_CLIENT_PRE_CONNECT && result < HOOK_LAST)
|
2019-08-19 16:05:59 +03:00
|
|
|
return HOOK_TYPE_STRINGS[result];
|
|
|
|
else
|
|
|
|
return "HOOK_UNKNOWN";
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static BOOL pf_modules_proxy_ArrayList_ForEachFkt(void* data, size_t index, va_list ap)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
proxyPlugin* plugin = (proxyPlugin*)data;
|
|
|
|
PF_HOOK_TYPE type;
|
|
|
|
proxyData* pdata;
|
|
|
|
BOOL ok = FALSE;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
type = va_arg(ap, PF_HOOK_TYPE);
|
|
|
|
pdata = va_arg(ap, proxyData*);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
WLog_VRB(TAG, "running hook %s.%s", plugin->name, pf_modules_get_hook_type_string(type));
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HOOK_TYPE_CLIENT_PRE_CONNECT:
|
|
|
|
IFCALLRET(plugin->ClientPreConnect, ok, pdata);
|
|
|
|
break;
|
2020-05-19 14:57:15 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case HOOK_TYPE_CLIENT_POST_CONNECT:
|
|
|
|
IFCALLRET(plugin->ClientPostConnect, ok, pdata);
|
|
|
|
break;
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case HOOK_TYPE_CLIENT_LOGIN_FAILURE:
|
|
|
|
IFCALLRET(plugin->ClientLoginFailure, ok, pdata);
|
|
|
|
break;
|
2020-05-19 14:57:15 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case HOOK_TYPE_CLIENT_END_PAINT:
|
|
|
|
IFCALLRET(plugin->ClientEndPaint, ok, pdata);
|
|
|
|
break;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case HOOK_TYPE_SERVER_POST_CONNECT:
|
|
|
|
IFCALLRET(plugin->ServerPostConnect, ok, pdata);
|
|
|
|
break;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case HOOK_TYPE_SERVER_CHANNELS_INIT:
|
|
|
|
IFCALLRET(plugin->ServerChannelsInit, ok, pdata);
|
|
|
|
break;
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case HOOK_TYPE_SERVER_CHANNELS_FREE:
|
|
|
|
IFCALLRET(plugin->ServerChannelsFree, ok, pdata);
|
|
|
|
break;
|
2020-05-19 14:57:15 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case HOOK_TYPE_SERVER_SESSION_END:
|
|
|
|
IFCALLRET(plugin->ServerSessionEnd, ok, pdata);
|
|
|
|
break;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2021-06-16 13:59:25 +03:00
|
|
|
case HOOK_LAST:
|
2020-05-12 18:16:14 +03:00
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "invalid hook called");
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
WLog_INFO(TAG, "plugin %s, hook %s failed!", plugin->name,
|
|
|
|
pf_modules_get_hook_type_string(type));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-08-19 16:05:59 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-05-12 18:16:14 +03:00
|
|
|
* runs all hooks of type `type`.
|
2019-08-19 16:05:59 +03:00
|
|
|
*
|
2020-05-12 18:16:14 +03:00
|
|
|
* @type: hook type to run.
|
2019-08-19 16:05:59 +03:00
|
|
|
* @server: pointer of server's rdpContext struct of the current session.
|
|
|
|
*/
|
2020-05-12 18:16:14 +03:00
|
|
|
BOOL pf_modules_run_hook(PF_HOOK_TYPE type, proxyData* pdata)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
return ArrayList_ForEach(plugins_list, pf_modules_proxy_ArrayList_ForEachFkt, type, pdata);
|
|
|
|
}
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static BOOL pf_modules_ArrayList_ForEachFkt(void* data, size_t index, va_list ap)
|
|
|
|
{
|
|
|
|
proxyPlugin* plugin = (proxyPlugin*)data;
|
2020-11-10 10:14:56 +03:00
|
|
|
PF_FILTER_TYPE type;
|
2020-05-12 18:16:14 +03:00
|
|
|
proxyData* pdata;
|
|
|
|
void* param;
|
|
|
|
BOOL result = FALSE;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-11-10 10:14:56 +03:00
|
|
|
WINPR_UNUSED(index);
|
|
|
|
|
|
|
|
type = va_arg(ap, PF_FILTER_TYPE);
|
2020-05-12 18:16:14 +03:00
|
|
|
pdata = va_arg(ap, proxyData*);
|
|
|
|
param = va_arg(ap, void*);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
WLog_VRB(TAG, "[%s]: running filter: %s", __FUNCTION__, plugin->name);
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case FILTER_TYPE_KEYBOARD:
|
|
|
|
IFCALLRET(plugin->KeyboardEvent, result, pdata, param);
|
|
|
|
break;
|
2020-02-02 16:15:28 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case FILTER_TYPE_MOUSE:
|
|
|
|
IFCALLRET(plugin->MouseEvent, result, pdata, param);
|
|
|
|
break;
|
2020-09-08 14:03:56 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case FILTER_TYPE_CLIENT_PASSTHROUGH_CHANNEL_DATA:
|
|
|
|
IFCALLRET(plugin->ClientChannelData, result, pdata, param);
|
|
|
|
break;
|
2020-09-08 14:03:56 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case FILTER_TYPE_SERVER_PASSTHROUGH_CHANNEL_DATA:
|
|
|
|
IFCALLRET(plugin->ServerChannelData, result, pdata, param);
|
|
|
|
break;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
case FILTER_TYPE_SERVER_FETCH_TARGET_ADDR:
|
|
|
|
IFCALLRET(plugin->ServerFetchTargetAddr, result, pdata, param);
|
|
|
|
break;
|
|
|
|
|
2021-06-16 13:59:25 +03:00
|
|
|
case FILTER_LAST:
|
2020-05-12 18:16:14 +03:00
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "invalid filter called");
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
/* current filter return FALSE, no need to run other filters. */
|
|
|
|
WLog_DBG(TAG, "plugin %s, filter type [%s] returned FALSE", plugin->name,
|
|
|
|
pf_modules_get_filter_type_string(type));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* runs all filters of type `type`.
|
|
|
|
*
|
|
|
|
* @type: filter type to run.
|
|
|
|
* @server: pointer of server's rdpContext struct of the current session.
|
|
|
|
*/
|
|
|
|
BOOL pf_modules_run_filter(PF_FILTER_TYPE type, proxyData* pdata, void* param)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ArrayList_ForEach(plugins_list, pf_modules_ArrayList_ForEachFkt, type, pdata, param);
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
/*
|
|
|
|
* stores per-session data needed by a plugin.
|
|
|
|
*
|
|
|
|
* @context: current session server's rdpContext instance.
|
|
|
|
* @info: pointer to per-session data.
|
|
|
|
*/
|
|
|
|
static BOOL pf_modules_set_plugin_data(const char* plugin_name, proxyData* pdata, void* data)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2021-02-24 15:53:43 +03:00
|
|
|
union {
|
2020-02-19 12:09:32 +03:00
|
|
|
const char* ccp;
|
|
|
|
char* cp;
|
|
|
|
} ccharconv;
|
2020-03-12 09:43:00 +03:00
|
|
|
|
2021-06-09 15:03:34 +03:00
|
|
|
WINPR_ASSERT(plugin_name);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-02-19 12:09:32 +03:00
|
|
|
ccharconv.ccp = plugin_name;
|
2019-12-31 12:16:12 +03:00
|
|
|
if (data == NULL) /* no need to store anything */
|
|
|
|
return FALSE;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2021-06-14 11:02:38 +03:00
|
|
|
if (!HashTable_Insert(pdata->modules_info, ccharconv.cp, data))
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2021-05-17 13:27:42 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: HashTable_Insert failed!");
|
2019-12-31 12:16:12 +03:00
|
|
|
return FALSE;
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
return TRUE;
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
/*
|
|
|
|
* returns per-session data needed a plugin.
|
|
|
|
*
|
|
|
|
* @context: current session server's rdpContext instance.
|
|
|
|
* if there's no data related to `plugin_name` in `context` (current session), a NULL will be
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
static void* pf_modules_get_plugin_data(const char* plugin_name, proxyData* pdata)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2021-02-24 15:53:43 +03:00
|
|
|
union {
|
2020-02-19 12:09:32 +03:00
|
|
|
const char* ccp;
|
|
|
|
char* cp;
|
|
|
|
} ccharconv;
|
2021-06-09 15:03:34 +03:00
|
|
|
WINPR_ASSERT(plugin_name);
|
|
|
|
WINPR_ASSERT(pdata);
|
2020-02-19 12:09:32 +03:00
|
|
|
ccharconv.ccp = plugin_name;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-02-19 12:09:32 +03:00
|
|
|
return HashTable_GetItemValue(pdata->modules_info, ccharconv.cp);
|
2019-12-31 12:16:12 +03:00
|
|
|
}
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
static void pf_modules_abort_connect(proxyData* pdata)
|
|
|
|
{
|
2021-06-09 15:03:34 +03:00
|
|
|
WINPR_ASSERT(pdata);
|
2019-12-31 12:16:12 +03:00
|
|
|
WLog_DBG(TAG, "%s is called!", __FUNCTION__);
|
|
|
|
proxy_data_abort_connect(pdata);
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static BOOL pf_modules_register_ArrayList_ForEachFkt(void* data, size_t index, va_list ap)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
proxyPlugin* plugin = (proxyPlugin*)data;
|
|
|
|
proxyPlugin* plugin_to_register = va_arg(ap, proxyPlugin*);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
WINPR_UNUSED(index);
|
|
|
|
|
|
|
|
if (strcmp(plugin->name, plugin_to_register->name) == 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "can not register plugin '%s', it is already registered!", plugin->name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL pf_modules_register_plugin(proxyPlugin* plugin_to_register)
|
|
|
|
{
|
2020-01-23 10:53:40 +03:00
|
|
|
if (!plugin_to_register)
|
|
|
|
return FALSE;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
/* make sure there's no other loaded plugin with the same name of `plugin_to_register`. */
|
2020-05-12 18:16:14 +03:00
|
|
|
if (!ArrayList_ForEach(plugins_list, pf_modules_register_ArrayList_ForEachFkt,
|
|
|
|
plugin_to_register))
|
|
|
|
return FALSE;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2021-05-17 13:30:18 +03:00
|
|
|
if (!ArrayList_Append(plugins_list, plugin_to_register))
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2020-01-23 10:53:40 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: failed adding plugin to list: %s", __FUNCTION__,
|
|
|
|
plugin_to_register->name);
|
2019-08-19 16:05:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static BOOL pf_modules_load_ArrayList_ForEachFkt(void* data, size_t index, va_list ap)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
proxyPlugin* plugin = (proxyPlugin*)data;
|
|
|
|
const char* plugin_name = va_arg(ap, const char*);
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
WINPR_UNUSED(index);
|
|
|
|
WINPR_UNUSED(ap);
|
|
|
|
|
|
|
|
if (strcmp(plugin->name, plugin_name) == 0)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL pf_modules_is_plugin_loaded(const char* plugin_name)
|
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
if (plugins_list == NULL)
|
|
|
|
return FALSE;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
return ArrayList_ForEach(plugins_list, pf_modules_load_ArrayList_ForEachFkt, plugin_name);
|
|
|
|
}
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static BOOL pf_modules_print_ArrayList_ForEachFkt(void* data, size_t index, va_list ap)
|
|
|
|
{
|
|
|
|
proxyPlugin* plugin = (proxyPlugin*)data;
|
|
|
|
|
|
|
|
WINPR_UNUSED(index);
|
|
|
|
WINPR_UNUSED(ap);
|
|
|
|
|
|
|
|
WLog_INFO(TAG, "\tName: %s", plugin->name);
|
|
|
|
WLog_INFO(TAG, "\tDescription: %s", plugin->description);
|
|
|
|
return TRUE;
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
void pf_modules_list_loaded_plugins(void)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
size_t count;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
if (plugins_list == NULL)
|
|
|
|
return;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
count = (size_t)ArrayList_Count(plugins_list);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
if (count > 0)
|
|
|
|
WLog_INFO(TAG, "Loaded plugins:");
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
ArrayList_ForEach(plugins_list, pf_modules_print_ArrayList_ForEachFkt);
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
static proxyPluginsManager plugins_manager = { pf_modules_register_plugin,
|
|
|
|
pf_modules_set_plugin_data,
|
|
|
|
pf_modules_get_plugin_data,
|
|
|
|
pf_modules_abort_connect };
|
|
|
|
|
|
|
|
static BOOL pf_modules_load_module(const char* module_path)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
|
|
|
HMODULE handle = NULL;
|
2019-12-31 12:16:12 +03:00
|
|
|
moduleEntryPoint pEntryPoint;
|
2019-08-19 16:05:59 +03:00
|
|
|
handle = LoadLibraryA(module_path);
|
|
|
|
|
|
|
|
if (handle == NULL)
|
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: failed loading external library: %s", __FUNCTION__, module_path);
|
2019-08-19 16:05:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
if (!(pEntryPoint = (moduleEntryPoint)GetProcAddress(handle, MODULE_ENTRY_POINT)))
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: GetProcAddress failed while loading %s", __FUNCTION__, module_path);
|
2019-08-19 16:05:59 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
if (!pEntryPoint(&plugins_manager))
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: module %s entry point failed!", __FUNCTION__, module_path);
|
2019-08-19 16:05:59 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
/* save module handle for freeing the module later */
|
2021-05-17 13:30:18 +03:00
|
|
|
if (!ArrayList_Append(handles_list, handle))
|
2019-12-31 12:16:12 +03:00
|
|
|
{
|
2021-05-17 13:30:18 +03:00
|
|
|
WLog_ERR(TAG, "ArrayList_Append failed!");
|
2019-12-31 12:16:12 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
error:
|
|
|
|
FreeLibrary(handle);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-01-21 15:56:49 +03:00
|
|
|
BOOL pf_modules_init(const char* root_dir, const char** modules, size_t count)
|
2019-12-31 12:16:12 +03:00
|
|
|
{
|
2020-01-21 15:56:49 +03:00
|
|
|
size_t i;
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-01-21 15:56:49 +03:00
|
|
|
if (!PathFileExistsA(root_dir))
|
2020-01-21 10:15:46 +03:00
|
|
|
{
|
2020-01-21 15:56:49 +03:00
|
|
|
if (!CreateDirectoryA(root_dir, NULL))
|
2020-01-21 10:15:46 +03:00
|
|
|
{
|
2020-01-21 15:56:49 +03:00
|
|
|
WLog_ERR(TAG, "error occurred while creating modules directory: %s", root_dir);
|
2020-01-21 10:15:46 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-01-21 15:56:49 +03:00
|
|
|
WLog_DBG(TAG, "modules root directory: %s", root_dir);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
plugins_list = ArrayList_New(FALSE);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
if (plugins_list == NULL)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
WLog_ERR(TAG, "[%s]: ArrayList_New failed!", __FUNCTION__);
|
2020-01-14 12:02:04 +03:00
|
|
|
goto error;
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
handles_list = ArrayList_New(FALSE);
|
|
|
|
if (handles_list == NULL)
|
2019-08-19 16:05:59 +03:00
|
|
|
{
|
2019-12-31 12:16:12 +03:00
|
|
|
|
|
|
|
WLog_ERR(TAG, "[%s]: ArrayList_New failed!", __FUNCTION__);
|
2020-01-14 12:02:04 +03:00
|
|
|
goto error;
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2020-01-21 15:56:49 +03:00
|
|
|
for (i = 0; i < count; i++)
|
2019-12-31 12:16:12 +03:00
|
|
|
{
|
2020-01-21 15:56:49 +03:00
|
|
|
char* fullpath = GetCombinedPath(root_dir, modules[i]);
|
|
|
|
pf_modules_load_module(fullpath);
|
|
|
|
free(fullpath);
|
|
|
|
}
|
2019-12-31 12:16:12 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2020-01-14 12:02:04 +03:00
|
|
|
|
|
|
|
error:
|
|
|
|
ArrayList_Free(plugins_list);
|
|
|
|
plugins_list = NULL;
|
|
|
|
ArrayList_Free(handles_list);
|
|
|
|
handles_list = NULL;
|
|
|
|
return FALSE;
|
2019-12-31 12:16:12 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static BOOL pf_modules_free_ArrayList_ForEachFkt(void* data, size_t index, va_list ap)
|
2019-12-31 12:16:12 +03:00
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
proxyPlugin* plugin = (proxyPlugin*)data;
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
WINPR_UNUSED(index);
|
|
|
|
WINPR_UNUSED(ap);
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
if (!IFCALLRESULT(TRUE, plugin->PluginUnload))
|
|
|
|
WLog_WARN(TAG, "PluginUnload failed for plugin '%s'", plugin->name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL pf_modules_free_handles_ArrayList_ForEachFkt(void* data, size_t index, va_list ap)
|
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE)data;
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
WINPR_UNUSED(index);
|
|
|
|
WINPR_UNUSED(ap);
|
|
|
|
if (handle)
|
|
|
|
FreeLibrary(handle);
|
2020-11-09 19:24:27 +03:00
|
|
|
return TRUE;
|
2020-05-12 18:16:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void pf_modules_free(void)
|
|
|
|
{
|
|
|
|
if (plugins_list)
|
|
|
|
{
|
|
|
|
ArrayList_ForEach(plugins_list, pf_modules_free_ArrayList_ForEachFkt);
|
2019-12-31 12:16:12 +03:00
|
|
|
ArrayList_Free(plugins_list);
|
|
|
|
plugins_list = NULL;
|
2019-08-19 16:05:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:16:12 +03:00
|
|
|
if (handles_list)
|
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
ArrayList_ForEach(handles_list, pf_modules_free_handles_ArrayList_ForEachFkt);
|
2019-12-31 12:16:12 +03:00
|
|
|
ArrayList_Free(handles_list);
|
|
|
|
handles_list = NULL;
|
|
|
|
}
|
|
|
|
}
|