[server,proxy] drop capture plugin

the capture plugin was written for FreeRDP2 proxy, which used a
different approach that is no longer working with FreeRDP3.
Drop the module so that we don´t diffuse people into thinking that this
is working.
This commit is contained in:
Armin Novak 2024-01-18 09:46:39 +01:00 committed by David Fort
parent b4587efad1
commit a4425d945c
6 changed files with 0 additions and 630 deletions

View File

@ -1,56 +0,0 @@
#
# FreeRDP: A Remote Desktop Protocol Implementation
# FreeRDP Proxy Server Capture Module
#
# Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
# Copyright 2021 Armin Novak <anovak@thincast.com>
# Copyright 2021 Thincast Technologies GmbH
#
# 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.
#
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0091 NEW)
if (NOT FREERDP_DEFAULT_PROJECT_VERSION)
set(FREERDP_DEFAULT_PROJECT_VERSION "1.0.0.0")
endif()
project(proxy-capture-plugin
VERSION ${FREERDP_DEFAULT_PROJECT_VERSION}
LANGUAGES C
)
message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake/)
include(CommonConfigOptions)
add_library(${PROJECT_NAME} SHARED
cap_main.c
cap_config.c
cap_config.h
cap_protocol.c
cap_protocol.h
)
target_link_libraries(${PROJECT_NAME} winpr freerdp)
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
set_target_properties(${PROJECT_NAME} PROPERTIES NO_SONAME 1)
install(TARGETS ${PROJECT_NAME} DESTINATION ${FREERDP_PROXY_PLUGINDIR})

View File

@ -1,97 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP Proxy Server Session Capture Module
*
* Copyright 2019 Kobi Mizrachi <kmizrachi18@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.
*/
#include <winpr/environment.h>
#include <freerdp/types.h>
#include <errno.h>
#include "cap_config.h"
BOOL capture_plugin_init_config(captureConfig* config)
{
const char* name = "PROXY_CAPTURE_TARGET";
char* tmp = NULL;
DWORD nSize = GetEnvironmentVariableA(name, NULL, 0);
if (nSize > 0)
{
char* colon;
int addrLen;
unsigned long port;
tmp = (LPSTR)malloc(nSize);
if (!tmp)
return FALSE;
if (GetEnvironmentVariableA(name, tmp, nSize) != nSize - 1)
{
free(tmp);
return FALSE;
}
colon = strchr(tmp, ':');
if (!colon)
{
free(tmp);
return FALSE;
}
addrLen = (int)(colon - tmp);
config->host = malloc(addrLen + 1);
if (!config->host)
{
free(tmp);
return FALSE;
}
strncpy(config->host, tmp, addrLen);
config->host[addrLen] = '\0';
port = strtoul(colon + 1, NULL, 0);
if ((errno != 0) || (port > UINT16_MAX))
{
free(config->host);
config->host = NULL;
free(tmp);
return FALSE;
}
config->port = (UINT16)port;
free(tmp);
}
else
{
config->host = _strdup("127.0.0.1");
if (!config->host)
return FALSE;
config->port = 8889;
}
return TRUE;
}
void capture_plugin_config_free_internal(captureConfig* config)
{
free(config->host);
config->host = NULL;
}

View File

@ -1,29 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP Proxy Server Session Capture Module
*
* Copyright 2019 Kobi Mizrachi <kmizrachi18@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.
*/
#include <freerdp/types.h>
typedef struct capture_config
{
UINT16 port;
char* host;
} captureConfig;
BOOL capture_plugin_init_config(captureConfig* config);
void capture_plugin_config_free_internal(captureConfig* config);

View File

@ -1,342 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP Proxy Server Session Capture Module
*
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
* Copyright 2021 Armin Novak <anovak@thincast.com>
* Copyright 2021 Thincast Technologies GmbH
*
* 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.
*/
#include <errno.h>
#include <winpr/image.h>
#include <freerdp/gdi/gdi.h>
#include <winpr/winsock.h>
#include <freerdp/server/proxy/proxy_modules_api.h>
#include <freerdp/server/proxy/proxy_log.h>
#include <freerdp/server/proxy/proxy_context.h>
#include "cap_config.h"
#include "cap_protocol.h"
#define TAG MODULE_TAG("capture")
#define PLUGIN_NAME "capture"
#define PLUGIN_DESC "stream egfx connections over tcp"
#define BUFSIZE 8092
static SOCKET capture_plugin_init_socket(const captureConfig* cconfig)
{
int status;
SOCKET sockfd;
struct sockaddr_in addr = { 0 };
WINPR_ASSERT(cconfig);
sockfd = _socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd == (SOCKET)-1)
return -1;
addr.sin_family = AF_INET;
addr.sin_port = htons(cconfig->port);
inet_pton(AF_INET, cconfig->host, &(addr.sin_addr));
status = _connect(sockfd, (const struct sockaddr*)&addr, sizeof(addr));
if (status < 0)
{
closesocket(sockfd);
return -1;
}
return sockfd;
}
static BOOL capture_plugin_send_data(SOCKET sockfd, const BYTE* buffer, size_t len)
{
int nsent;
if (!buffer)
return FALSE;
while (len > 0)
{
int chunk_len = len > BUFSIZE ? BUFSIZE : len;
nsent = _send(sockfd, (const char*)buffer, chunk_len, 0);
if (nsent == -1)
return FALSE;
buffer += nsent;
len -= nsent;
}
return TRUE;
}
static BOOL capture_plugin_send_packet(SOCKET sockfd, wStream* packet)
{
size_t len;
BYTE* buffer;
BOOL result = FALSE;
if (!packet)
return FALSE;
buffer = Stream_Buffer(packet);
len = Stream_Capacity(packet);
if (!capture_plugin_send_data(sockfd, buffer, len))
{
WLog_ERR(TAG, "error while transmitting frame: errno=%d", errno);
goto error;
}
result = TRUE;
error:
Stream_Free(packet, TRUE);
return result;
}
static SOCKET capture_plugin_get_socket(proxyPlugin* plugin, proxyData* pdata)
{
void* custom;
WINPR_ASSERT(plugin);
WINPR_ASSERT(plugin->mgr);
custom = plugin->mgr->GetPluginData(plugin->mgr, PLUGIN_NAME, pdata);
if (!custom)
return -1;
return (SOCKET)custom;
}
static BOOL capture_plugin_session_end(proxyPlugin* plugin, proxyData* pdata, void* custom)
{
SOCKET socket;
BOOL ret;
wStream* s;
WINPR_ASSERT(pdata);
WINPR_ASSERT(custom);
WINPR_ASSERT(plugin);
WINPR_ASSERT(plugin->mgr);
socket = capture_plugin_get_socket(plugin, pdata);
if (socket == INVALID_SOCKET)
return FALSE;
s = capture_plugin_packet_new(SESSION_END_PDU_BASE_SIZE, MESSAGE_TYPE_SESSION_END);
if (!s)
return FALSE;
ret = capture_plugin_send_packet(socket, s);
closesocket(socket);
return ret;
}
static BOOL capture_plugin_send_frame(pClientContext* pc, SOCKET socket, const BYTE* buffer)
{
size_t frame_size;
BOOL ret = FALSE;
wStream* s = NULL;
BYTE* bmp_header = NULL;
rdpSettings* settings;
WINPR_ASSERT(pc);
settings = pc->context.settings;
WINPR_ASSERT(settings);
const size_t DesktopWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
const size_t DesktopHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
frame_size = DesktopWidth * DesktopHeight *
(freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth) / 8ull);
bmp_header = winpr_bitmap_construct_header(
DesktopWidth, DesktopHeight, freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth));
if (!bmp_header)
return FALSE;
/*
* capture frame packet indicates a packet that contains a frame buffer. payload length is
* marked as 0, and receiving side must read `frame_size` bytes, a constant size of
* width*height*(bpp/8) from the socket, to receive the full frame buffer.
*/
s = capture_plugin_packet_new(0, MESSAGE_TYPE_CAPTURED_FRAME);
if (!s)
goto error;
if (!capture_plugin_send_packet(socket, s))
goto error;
ret = capture_plugin_send_data(socket, bmp_header, WINPR_IMAGE_BMP_HEADER_LEN);
if (!ret)
goto error;
ret = capture_plugin_send_data(socket, buffer, frame_size);
error:
free(bmp_header);
return ret;
}
static BOOL capture_plugin_client_end_paint(proxyPlugin* plugin, proxyData* pdata, void* custom)
{
pClientContext* pc = pdata->pc;
rdpGdi* gdi = pc->context.gdi;
SOCKET socket;
WINPR_ASSERT(pdata);
WINPR_ASSERT(custom);
WINPR_ASSERT(plugin);
WINPR_ASSERT(plugin->mgr);
if (gdi->suppressOutput)
return TRUE;
if (gdi->primary->hdc->hwnd->ninvalid < 1)
return TRUE;
socket = capture_plugin_get_socket(plugin, pdata);
if (socket == INVALID_SOCKET)
return FALSE;
if (!capture_plugin_send_frame(pc, socket, gdi->primary_buffer))
{
WLog_ERR(TAG, "capture_plugin_send_frame failed!");
return FALSE;
}
gdi->primary->hdc->hwnd->invalid->null = TRUE;
gdi->primary->hdc->hwnd->ninvalid = 0;
return TRUE;
}
static BOOL capture_plugin_client_post_connect(proxyPlugin* plugin, proxyData* pdata, void* custom)
{
captureConfig* cconfig;
SOCKET socket;
wStream* s;
WINPR_ASSERT(pdata);
WINPR_ASSERT(custom);
WINPR_ASSERT(plugin);
WINPR_ASSERT(plugin->mgr);
cconfig = plugin->custom;
WINPR_ASSERT(cconfig);
socket = capture_plugin_init_socket(cconfig);
if (socket == INVALID_SOCKET)
{
WLog_ERR(TAG, "failed to establish a connection");
return FALSE;
}
plugin->mgr->SetPluginData(plugin->mgr, PLUGIN_NAME, pdata, (void*)socket);
s = capture_plugin_create_session_info_packet(pdata->pc);
if (!s)
return FALSE;
return capture_plugin_send_packet(socket, s);
}
static BOOL capture_plugin_server_post_connect(proxyPlugin* plugin, proxyData* pdata, void* custom)
{
pServerContext* ps;
const proxyConfig* config;
rdpSettings* settings;
WINPR_ASSERT(plugin);
WINPR_ASSERT(pdata);
WINPR_ASSERT(custom);
ps = pdata->ps;
WINPR_ASSERT(ps);
config = pdata->config;
WINPR_ASSERT(config);
settings = ps->context.settings;
WINPR_ASSERT(settings);
if (!config->GFX || !config->DecodeGFX)
{
WLog_ERR(TAG, "config options 'Channels.GFX' and 'GFXSettings.DecodeGFX' options must be "
"set to true!");
return FALSE;
}
if (!freerdp_settings_get_bool(settings, FreeRDP_SupportGraphicsPipeline))
{
WLog_ERR(TAG, "session capture is only supported for GFX clients, denying connection");
return FALSE;
}
return TRUE;
}
static BOOL capture_plugin_unload(proxyPlugin* plugin)
{
if (plugin)
{
captureConfig* cconfig = plugin->custom;
WINPR_ASSERT(cconfig);
capture_plugin_config_free_internal(cconfig);
free(cconfig);
}
return TRUE;
}
#ifdef __cplusplus
extern "C"
{
#endif
FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata);
#ifdef __cplusplus
}
#endif
BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
{
proxyPlugin plugin = { 0 };
plugin.name = PLUGIN_NAME; /* name */
plugin.description = PLUGIN_DESC; /* description */
plugin.PluginUnload = capture_plugin_unload; /* PluginUnload */
plugin.ClientPostConnect = capture_plugin_client_post_connect; /* ClientPostConnect */
plugin.ClientEndPaint = capture_plugin_client_end_paint; /* ClientEndPaint */
plugin.ServerPostConnect = capture_plugin_server_post_connect; /* ServerPostConnect */
plugin.ServerSessionEnd = capture_plugin_session_end; /* Session End */
plugin.userdata = userdata; /* userdata */
captureConfig* cconfig = calloc(1, sizeof(captureConfig));
if (!cconfig)
return FALSE;
plugin.custom = cconfig;
if (!capture_plugin_init_config(cconfig))
{
WLog_ERR(TAG, "failed to load config");
return FALSE;
}
WLog_INFO(TAG, "host: %s, port: %" PRIu16 "", cconfig->host, cconfig->port);
return plugins_manager->RegisterPlugin(plugins_manager, &plugin);
}

View File

@ -1,69 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP Proxy Server Session Capture Module
*
* Copyright 2019 Kobi Mizrachi <kmizrachi18@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.
*/
#include "cap_protocol.h"
wStream* capture_plugin_packet_new(UINT32 payload_size, UINT16 type)
{
wStream* stream = Stream_New(NULL, HEADER_SIZE + payload_size);
if (!stream)
return NULL;
Stream_Write_UINT32(stream, payload_size);
Stream_Write_UINT16(stream, type);
return stream;
}
wStream* capture_plugin_create_session_info_packet(pClientContext* pc)
{
wStream* s = NULL;
if (!pc)
return NULL;
rdpSettings* settings = pc->context.settings;
if (!settings)
return NULL;
const char* Username = freerdp_settings_get_string(settings, FreeRDP_Username);
if (!Username)
return NULL;
const size_t username_length = strlen(Username);
if ((username_length == 0) || (username_length > UINT16_MAX))
return NULL;
const UINT32 DesktopWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
const UINT32 DesktopHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
s = capture_plugin_packet_new(SESSION_INFO_PDU_BASE_SIZE + (UINT32)username_length,
MESSAGE_TYPE_SESSION_INFO);
if (!s)
return NULL;
Stream_Write_UINT16(s, (UINT16)username_length); /* username length (2 bytes) */
Stream_Write(s, Username, username_length); /* username */
Stream_Write_UINT32(s, DesktopWidth); /* desktop width (4 bytes) */
Stream_Write_UINT32(s, DesktopHeight); /* desktop height (4 bytes) */
Stream_Write_UINT32(
s, freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth)); /* color depth (4 bytes) */
Stream_Write(s, pc->pdata->session_id, PROXY_SESSION_ID_LENGTH); /* color depth (32 bytes) */
return s;
}

View File

@ -1,37 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP Proxy Server Session Capture Module
*
* Copyright 2019 Kobi Mizrachi <kmizrachi18@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.
*/
#include <winpr/stream.h>
#include <freerdp/settings.h>
#include <freerdp/server/proxy/proxy_context.h>
/* protocol message sizes */
#define HEADER_SIZE 6
#define SESSION_INFO_PDU_BASE_SIZE 46
#define SESSION_END_PDU_BASE_SIZE 0
#define CAPTURED_FRAME_PDU_BASE_SIZE 0
/* protocol message types */
#define MESSAGE_TYPE_SESSION_INFO 1
#define MESSAGE_TYPE_CAPTURED_FRAME 2
#define MESSAGE_TYPE_SESSION_END 3
wStream* capture_plugin_packet_new(UINT32 payload_size, UINT16 type);
wStream* capture_plugin_create_session_info_packet(pClientContext* pc);