26#include <winpr/path.h>
27#include <winpr/collections.h>
28#include <winpr/cmdline.h>
31#include <freerdp/server/proxy/proxy_config.h>
33#include <freerdp/server/proxy/proxy_log.h>
35#include <freerdp/crypto/crypto.h>
36#include <freerdp/channels/cliprdr.h>
37#include <freerdp/channels/rdpsnd.h>
38#include <freerdp/channels/audin.h>
39#include <freerdp/channels/rdpdr.h>
40#include <freerdp/channels/disp.h>
41#include <freerdp/channels/rail.h>
42#include <freerdp/channels/rdpei.h>
43#include <freerdp/channels/tsmf.h>
44#include <freerdp/channels/video.h>
45#include <freerdp/channels/rdpecam.h>
49#define TAG PROXY_TAG("config")
51#define CONFIG_PRINT_SECTION(section) WLog_INFO(TAG, "\t%s:", section)
52#define CONFIG_PRINT_SECTION_KEY(section, key) WLog_INFO(TAG, "\t%s/%s:", section, key)
53#define CONFIG_PRINT_STR(config, key) WLog_INFO(TAG, "\t\t%s: %s", #key, (config)->key)
54#define CONFIG_PRINT_STR_CONTENT(config, key) \
55 WLog_INFO(TAG, "\t\t%s: %s", #key, (config)->key ? "set" : nullptr)
56#define CONFIG_PRINT_BOOL(config, key) WLog_INFO(TAG, "\t\t%s: %s", #key, boolstr((config)->key))
57#define CONFIG_PRINT_UINT16(config, key) WLog_INFO(TAG, "\t\t%s: %" PRIu16 "", #key, (config)->key)
58#define CONFIG_PRINT_UINT32(config, key) WLog_INFO(TAG, "\t\t%s: %" PRIu32 "", #key, (config)->key)
60static const char* bool_str_true =
"true";
61static const char* bool_str_false =
"false";
64static const char* boolstr(BOOL rc)
66 return rc ? bool_str_true : bool_str_false;
69static const char* section_server =
"Server";
70static const char* key_host =
"Host";
71static const char* key_port =
"Port";
73static const char* section_target =
"Target";
74static const char* key_target_fixed =
"FixedTarget";
75static const char* key_target_user =
"User";
76static const char* key_target_pwd =
"Password";
77static const char* key_target_domain =
"Domain";
78static const char* key_target_tls_seclevel =
"TlsSecLevel";
80static const char* section_plugins =
"Plugins";
81static const char* key_plugins_modules =
"Modules";
82static const char* key_plugins_required =
"Required";
84static const char* section_codecs =
"Codecs";
85static const char* key_codecs_rfx =
"RFX";
86static const char* key_codecs_nsc =
"NSC";
88static const char* section_channels =
"Channels";
89static const char* key_channels_gfx =
"GFX";
90static const char* key_channels_disp =
"DisplayControl";
91static const char* key_channels_clip =
"Clipboard";
92static const char* key_channels_mic =
"AudioInput";
93static const char* key_channels_sound =
"AudioOutput";
94static const char* key_channels_rdpdr =
"DeviceRedirection";
95static const char* key_channels_video =
"VideoRedirection";
96static const char* key_channels_camera =
"CameraRedirection";
97static const char* key_channels_rails =
"RemoteApp";
98static const char* key_channels_blacklist =
"PassthroughIsBlacklist";
99static const char* key_channels_pass =
"Passthrough";
100static const char* key_channels_intercept =
"Intercept";
102static const char* section_input =
"Input";
103static const char* key_input_kbd =
"Keyboard";
104static const char* key_input_mouse =
"Mouse";
105static const char* key_input_multitouch =
"Multitouch";
107static const char* section_security =
"Security";
108static const char* key_security_server_nla =
"ServerNlaSecurity";
109static const char* key_security_server_tls =
"ServerTlsSecurity";
110static const char* key_security_server_rdp =
"ServerRdpSecurity";
111static const char* key_security_client_nla =
"ClientNlaSecurity";
112static const char* key_security_client_tls =
"ClientTlsSecurity";
113static const char* key_security_client_rdp =
"ClientRdpSecurity";
114static const char* key_security_client_fallback =
"ClientAllowFallbackToTls";
116static const char* section_certificates =
"Certificates";
117static const char* key_private_key_file =
"PrivateKeyFile";
118static const char* key_private_key_content =
"PrivateKeyContent";
119static const char* key_cert_file =
"CertificateFile";
120static const char* key_cert_content =
"CertificateContent";
122WINPR_ATTR_MALLOC(CommandLineParserFree, 1)
124static
char** pf_config_parse_comma_separated_list(const
char* list,
size_t* count)
129 if (strlen(list) == 0)
135 return CommandLineParseCommaSeparatedValues(list, count);
139static BOOL pf_config_get_uint16(wIniFile* ini,
const char* section,
const char* key,
140 UINT16* result, BOOL required)
143 const char* strval =
nullptr;
145 WINPR_ASSERT(result);
147 strval = IniFile_GetKeyValueString(ini, section, key);
148 if (!strval && required)
150 WLog_ERR(TAG,
"key '%s.%s' does not exist.", section, key);
153 val = IniFile_GetKeyValueInt(ini, section, key);
154 if ((val <= 0) || (val > UINT16_MAX))
156 WLog_ERR(TAG,
"invalid value %d for key '%s.%s'.", val, section, key);
160 *result = (UINT16)val;
165static BOOL pf_config_get_uint32(wIniFile* ini,
const char* section,
const char* key,
166 UINT32* result, BOOL required)
168 WINPR_ASSERT(result);
170 const char* strval = IniFile_GetKeyValueString(ini, section, key);
174 WLog_ERR(TAG,
"key '%s.%s' does not exist.", section, key);
178 const int val = IniFile_GetKeyValueInt(ini, section, key);
181 WLog_ERR(TAG,
"invalid value %d for key '%s.%s'.", val, section, key);
185 *result = (UINT32)val;
190static BOOL pf_config_get_bool(wIniFile* ini,
const char* section,
const char* key, BOOL fallback)
193 const char* str_value =
nullptr;
195 str_value = IniFile_GetKeyValueString(ini, section, key);
198 WLog_WARN(TAG,
"key '%s.%s' not found, value defaults to %s.", section, key,
199 fallback ? bool_str_true : bool_str_false);
203 if (_stricmp(str_value, bool_str_true) == 0)
205 if (_stricmp(str_value, bool_str_false) == 0)
208 num_value = IniFile_GetKeyValueInt(ini, section, key);
210 return (num_value != 0);
214static const char* pf_config_get_str(wIniFile* ini,
const char* section,
const char* key,
217 const char* value =
nullptr;
219 value = IniFile_GetKeyValueString(ini, section, key);
224 WLog_ERR(TAG,
"key '%s.%s' not found.", section, key);
232static BOOL pf_config_load_server(wIniFile* ini, proxyConfig* config)
234 WINPR_ASSERT(config);
235 const char* host = pf_config_get_str(ini, section_server, key_host, FALSE);
241 config->Host = _strdup(host);
246 if (!pf_config_get_uint16(ini, section_server, key_port, &config->Port, TRUE))
253static BOOL pf_config_load_target(wIniFile* ini, proxyConfig* config)
255 const char* target_value =
nullptr;
257 WINPR_ASSERT(config);
258 config->FixedTarget = pf_config_get_bool(ini, section_target, key_target_fixed, FALSE);
260 if (!pf_config_get_uint16(ini, section_target, key_port, &config->TargetPort,
261 config->FixedTarget))
264 if (!pf_config_get_uint32(ini, section_target, key_target_tls_seclevel,
265 &config->TargetTlsSecLevel, FALSE))
268 if (config->FixedTarget)
270 target_value = pf_config_get_str(ini, section_target, key_host, TRUE);
274 free(config->TargetHost);
275 config->TargetHost = _strdup(target_value);
276 if (!config->TargetHost)
280 target_value = pf_config_get_str(ini, section_target, key_target_user, FALSE);
283 free(config->TargetUser);
284 config->TargetUser = _strdup(target_value);
285 if (!config->TargetUser)
289 target_value = pf_config_get_str(ini, section_target, key_target_pwd, FALSE);
292 free(config->TargetPassword);
293 config->TargetPassword = _strdup(target_value);
294 if (!config->TargetPassword)
298 target_value = pf_config_get_str(ini, section_target, key_target_domain, FALSE);
301 free(config->TargetDomain);
302 config->TargetDomain = _strdup(target_value);
303 if (!config->TargetDomain)
311static BOOL pf_config_load_codecs(wIniFile* ini, proxyConfig* config)
313 WINPR_ASSERT(config);
314 config->RFX = pf_config_get_bool(ini, section_codecs, key_codecs_rfx, TRUE);
315 config->NSC = pf_config_get_bool(ini, section_codecs, key_codecs_nsc, TRUE);
320static BOOL pf_config_load_channels(wIniFile* ini, proxyConfig* config)
322 WINPR_ASSERT(config);
323 config->GFX = pf_config_get_bool(ini, section_channels, key_channels_gfx, TRUE);
324 config->DisplayControl = pf_config_get_bool(ini, section_channels, key_channels_disp, TRUE);
325 config->Clipboard = pf_config_get_bool(ini, section_channels, key_channels_clip, FALSE);
326 config->AudioOutput = pf_config_get_bool(ini, section_channels, key_channels_mic, TRUE);
327 config->AudioInput = pf_config_get_bool(ini, section_channels, key_channels_sound, TRUE);
328 config->DeviceRedirection = pf_config_get_bool(ini, section_channels, key_channels_rdpdr, TRUE);
329 config->VideoRedirection = pf_config_get_bool(ini, section_channels, key_channels_video, TRUE);
330 config->CameraRedirection =
331 pf_config_get_bool(ini, section_channels, key_channels_camera, TRUE);
332 config->RemoteApp = pf_config_get_bool(ini, section_channels, key_channels_rails, FALSE);
333 config->PassthroughIsBlacklist =
334 pf_config_get_bool(ini, section_channels, key_channels_blacklist, FALSE);
335 config->Passthrough = pf_config_parse_comma_separated_list(
336 pf_config_get_str(ini, section_channels, key_channels_pass, FALSE),
337 &config->PassthroughCount);
338 config->Intercept = pf_config_parse_comma_separated_list(
339 pf_config_get_str(ini, section_channels, key_channels_intercept, FALSE),
340 &config->InterceptCount);
346static BOOL pf_config_load_input(wIniFile* ini, proxyConfig* config)
348 WINPR_ASSERT(config);
349 config->Keyboard = pf_config_get_bool(ini, section_input, key_input_kbd, TRUE);
350 config->Mouse = pf_config_get_bool(ini, section_input, key_input_mouse, TRUE);
351 config->Multitouch = pf_config_get_bool(ini, section_input, key_input_multitouch, TRUE);
356static BOOL pf_config_load_security(wIniFile* ini, proxyConfig* config)
358 WINPR_ASSERT(config);
359 config->ServerTlsSecurity =
360 pf_config_get_bool(ini, section_security, key_security_server_tls, TRUE);
361 config->ServerNlaSecurity =
362 pf_config_get_bool(ini, section_security, key_security_server_nla, FALSE);
363 config->ServerRdpSecurity =
364 pf_config_get_bool(ini, section_security, key_security_server_rdp, TRUE);
366 config->ClientTlsSecurity =
367 pf_config_get_bool(ini, section_security, key_security_client_tls, TRUE);
368 config->ClientNlaSecurity =
369 pf_config_get_bool(ini, section_security, key_security_client_nla, TRUE);
370 config->ClientRdpSecurity =
371 pf_config_get_bool(ini, section_security, key_security_client_rdp, TRUE);
372 config->ClientAllowFallbackToTls =
373 pf_config_get_bool(ini, section_security, key_security_client_fallback, TRUE);
378static BOOL pf_config_load_modules(wIniFile* ini, proxyConfig* config)
380 const char* modules_to_load =
nullptr;
381 const char* required_modules =
nullptr;
383 modules_to_load = pf_config_get_str(ini, section_plugins, key_plugins_modules, FALSE);
384 required_modules = pf_config_get_str(ini, section_plugins, key_plugins_required, FALSE);
386 WINPR_ASSERT(config);
387 config->Modules = pf_config_parse_comma_separated_list(modules_to_load, &config->ModulesCount);
389 config->RequiredPlugins =
390 pf_config_parse_comma_separated_list(required_modules, &config->RequiredPluginsCount);
395static char* pf_config_decode_base64(
const char* data,
const char* name,
size_t* pLength)
397 const char* headers[] = {
"-----BEGIN PUBLIC KEY-----",
"-----BEGIN RSA PUBLIC KEY-----",
398 "-----BEGIN CERTIFICATE-----",
"-----BEGIN PRIVATE KEY-----",
399 "-----BEGIN RSA PRIVATE KEY-----" };
401 size_t decoded_length = 0;
402 char* decoded =
nullptr;
405 WLog_ERR(TAG,
"Invalid base64 data [nullptr] for %s", name);
410 WINPR_ASSERT(pLength);
412 const size_t length = strlen(data);
414 if (strncmp(data,
"-----", 5) == 0)
416 BOOL expected = FALSE;
417 for (
size_t x = 0; x < ARRAYSIZE(headers); x++)
419 const char* header = headers[x];
421 if (strncmp(data, header, strlen(header)) == 0)
430 char hdr[128] = WINPR_C_ARRAY_INIT;
431 const char* end = strchr(&data[5],
'-');
437 const size_t s = MIN(ARRAYSIZE(hdr) - 1ULL, (
size_t)(end - data));
438 memcpy(hdr, data, s);
441 WLog_WARN(TAG,
"PEM has unexpected header '%s'. Known supported headers are:", hdr);
442 for (
size_t x = 0; x < ARRAYSIZE(headers); x++)
444 const char* header = headers[x];
445 WLog_WARN(TAG,
"%s", header);
449 *pLength = length + 1;
450 return _strdup(data);
453 crypto_base64_decode(data, length, (BYTE**)&decoded, &decoded_length);
454 if (!decoded || decoded_length == 0)
456 WLog_ERR(TAG,
"Failed to decode base64 data of length %" PRIuz
" for %s", length, name);
461 *pLength = strnlen(decoded, decoded_length) + 1;
466static BOOL pf_config_load_certificates(wIniFile* ini, proxyConfig* config)
468 const char* tmp1 =
nullptr;
469 const char* tmp2 =
nullptr;
472 WINPR_ASSERT(config);
474 tmp1 = pf_config_get_str(ini, section_certificates, key_cert_file, FALSE);
477 if (!winpr_PathFileExists(tmp1))
479 WLog_ERR(TAG,
"%s/%s file %s does not exist", section_certificates, key_cert_file,
483 config->CertificateFile = _strdup(tmp1);
484 config->CertificatePEM =
485 crypto_read_pem(config->CertificateFile, &config->CertificatePEMLength);
486 if (!config->CertificatePEM)
488 config->CertificatePEMLength += 1;
490 tmp2 = pf_config_get_str(ini, section_certificates, key_cert_content, FALSE);
493 if (strlen(tmp2) < 1)
495 WLog_ERR(TAG,
"%s/%s has invalid empty value", section_certificates, key_cert_content);
498 config->CertificateContent = _strdup(tmp2);
499 config->CertificatePEM = pf_config_decode_base64(
500 config->CertificateContent,
"CertificateContent", &config->CertificatePEMLength);
501 if (!config->CertificatePEM)
507 "%s/%s and %s/%s are "
508 "mutually exclusive options",
509 section_certificates, key_cert_file, section_certificates, key_cert_content);
512 else if (!tmp1 && !tmp2)
515 "%s/%s or %s/%s are "
517 section_certificates, key_cert_file, section_certificates, key_cert_content);
521 tmp1 = pf_config_get_str(ini, section_certificates, key_private_key_file, FALSE);
524 if (!winpr_PathFileExists(tmp1))
526 WLog_ERR(TAG,
"%s/%s file %s does not exist", section_certificates,
527 key_private_key_file, tmp1);
530 config->PrivateKeyFile = _strdup(tmp1);
531 config->PrivateKeyPEM =
532 crypto_read_pem(config->PrivateKeyFile, &config->PrivateKeyPEMLength);
533 if (!config->PrivateKeyPEM)
535 config->PrivateKeyPEMLength += 1;
537 tmp2 = pf_config_get_str(ini, section_certificates, key_private_key_content, FALSE);
540 if (strlen(tmp2) < 1)
542 WLog_ERR(TAG,
"%s/%s has invalid empty value", section_certificates,
543 key_private_key_content);
546 config->PrivateKeyContent = _strdup(tmp2);
547 config->PrivateKeyPEM = pf_config_decode_base64(
548 config->PrivateKeyContent,
"PrivateKeyContent", &config->PrivateKeyPEMLength);
549 if (!config->PrivateKeyPEM)
556 "%s/%s and %s/%s are "
557 "mutually exclusive options",
558 section_certificates, key_private_key_file, section_certificates,
559 key_private_key_content);
562 else if (!tmp1 && !tmp2)
565 "%s/%s or %s/%s are "
566 "are required settings",
567 section_certificates, key_private_key_file, section_certificates,
568 key_private_key_content);
577 proxyConfig* config =
nullptr;
581 config = calloc(1,
sizeof(proxyConfig));
585 config->TargetTlsSecLevel = 1;
588 if (!pf_config_load_server(ini, config))
591 if (!pf_config_load_target(ini, config))
594 if (!pf_config_load_codecs(ini, config))
597 if (!pf_config_load_channels(ini, config))
600 if (!pf_config_load_input(ini, config))
603 if (!pf_config_load_security(ini, config))
606 if (!pf_config_load_modules(ini, config))
609 if (!pf_config_load_certificates(ini, config))
611 config->ini = IniFile_Clone(ini);
617 WINPR_PRAGMA_DIAG_PUSH
618 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
620 WINPR_PRAGMA_DIAG_POP
628 wIniFile* ini = IniFile_New();
633 if (IniFile_SetKeyValueString(ini, section_server, key_host,
"0.0.0.0") < 0)
635 if (IniFile_SetKeyValueInt(ini, section_server, key_port, 3389) < 0)
639 if (IniFile_SetKeyValueString(ini, section_target, key_host,
"somehost.example.com") < 0)
641 if (IniFile_SetKeyValueInt(ini, section_target, key_port, 3389) < 0)
643 if (IniFile_SetKeyValueString(ini, section_target, key_target_fixed, bool_str_true) < 0)
645 if (IniFile_SetKeyValueInt(ini, section_target, key_target_tls_seclevel, 1) < 0)
649 if (IniFile_SetKeyValueString(ini, section_codecs, key_codecs_rfx, bool_str_true) < 0)
651 if (IniFile_SetKeyValueString(ini, section_codecs, key_codecs_nsc, bool_str_true) < 0)
655 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_gfx, bool_str_true) < 0)
657 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_disp, bool_str_true) < 0)
659 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_clip, bool_str_true) < 0)
661 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_mic, bool_str_true) < 0)
663 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_sound, bool_str_true) < 0)
665 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_rdpdr, bool_str_true) < 0)
667 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_video, bool_str_true) < 0)
669 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_camera, bool_str_true) < 0)
671 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_rails, bool_str_false) < 0)
674 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_blacklist, bool_str_true) < 0)
676 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_pass,
"") < 0)
678 if (IniFile_SetKeyValueString(ini, section_channels, key_channels_intercept,
"") < 0)
682 if (IniFile_SetKeyValueString(ini, section_input, key_input_kbd, bool_str_true) < 0)
684 if (IniFile_SetKeyValueString(ini, section_input, key_input_mouse, bool_str_true) < 0)
686 if (IniFile_SetKeyValueString(ini, section_input, key_input_multitouch, bool_str_true) < 0)
690 if (IniFile_SetKeyValueString(ini, section_security, key_security_server_tls, bool_str_true) <
693 if (IniFile_SetKeyValueString(ini, section_security, key_security_server_nla, bool_str_false) <
696 if (IniFile_SetKeyValueString(ini, section_security, key_security_server_rdp, bool_str_true) <
700 if (IniFile_SetKeyValueString(ini, section_security, key_security_client_tls, bool_str_true) <
703 if (IniFile_SetKeyValueString(ini, section_security, key_security_client_nla, bool_str_true) <
706 if (IniFile_SetKeyValueString(ini, section_security, key_security_client_rdp, bool_str_true) <
709 if (IniFile_SetKeyValueString(ini, section_security, key_security_client_fallback,
714 if (IniFile_SetKeyValueString(ini, section_plugins, key_plugins_modules,
715 "module1,module2,...") < 0)
717 if (IniFile_SetKeyValueString(ini, section_plugins, key_plugins_required,
718 "module1,module2,...") < 0)
722 if (IniFile_SetKeyValueString(ini, section_certificates, key_cert_file,
723 "<absolute path to some certificate file> OR") < 0)
725 if (IniFile_SetKeyValueString(ini, section_certificates, key_cert_content,
726 "<Contents of some certificate file in PEM format>") < 0)
729 if (IniFile_SetKeyValueString(ini, section_certificates, key_private_key_file,
730 "<absolute path to some private key file> OR") < 0)
732 if (IniFile_SetKeyValueString(ini, section_certificates, key_private_key_content,
733 "<Contents of some private key file in PEM format>") < 0)
737 if (IniFile_WriteFile(ini, file) < 0)
749 proxyConfig* config =
nullptr;
750 wIniFile* ini =
nullptr;
756 WLog_ERR(TAG,
"IniFile_New() failed!");
760 if (IniFile_ReadBuffer(ini, buffer) < 0)
762 WLog_ERR(TAG,
"failed to parse ini: '%s'", buffer);
774 proxyConfig* config =
nullptr;
775 wIniFile* ini = IniFile_New();
779 WLog_ERR(TAG,
"IniFile_New() failed!");
783 if (IniFile_ReadFile(ini, path) < 0)
785 WLog_ERR(TAG,
"failed to parse ini file: '%s'", path);
795static void pf_server_config_print_list(
char** list,
size_t count)
798 for (
size_t i = 0; i < count; i++)
799 WLog_INFO(TAG,
"\t\t- %s", list[i]);
804 WINPR_ASSERT(config);
805 WLog_INFO(TAG,
"Proxy configuration:");
807 CONFIG_PRINT_SECTION(section_server);
808 CONFIG_PRINT_STR(config, Host);
809 CONFIG_PRINT_UINT16(config, Port);
811 if (config->FixedTarget)
813 CONFIG_PRINT_SECTION(section_target);
814 CONFIG_PRINT_STR(config, TargetHost);
815 CONFIG_PRINT_UINT16(config, TargetPort);
816 CONFIG_PRINT_UINT32(config, TargetTlsSecLevel);
818 if (config->TargetUser)
819 CONFIG_PRINT_STR(config, TargetUser);
820 if (config->TargetDomain)
821 CONFIG_PRINT_STR(config, TargetDomain);
824 CONFIG_PRINT_SECTION(section_input);
825 CONFIG_PRINT_BOOL(config, Keyboard);
826 CONFIG_PRINT_BOOL(config, Mouse);
827 CONFIG_PRINT_BOOL(config, Multitouch);
829 CONFIG_PRINT_SECTION(section_security);
830 CONFIG_PRINT_BOOL(config, ServerNlaSecurity);
831 CONFIG_PRINT_BOOL(config, ServerTlsSecurity);
832 CONFIG_PRINT_BOOL(config, ServerRdpSecurity);
833 CONFIG_PRINT_BOOL(config, ClientNlaSecurity);
834 CONFIG_PRINT_BOOL(config, ClientTlsSecurity);
835 CONFIG_PRINT_BOOL(config, ClientRdpSecurity);
836 CONFIG_PRINT_BOOL(config, ClientAllowFallbackToTls);
838 CONFIG_PRINT_SECTION(section_codecs);
839 CONFIG_PRINT_BOOL(config, RFX);
840 CONFIG_PRINT_BOOL(config, NSC);
842 CONFIG_PRINT_SECTION(section_channels);
843 CONFIG_PRINT_BOOL(config, GFX);
844 CONFIG_PRINT_BOOL(config, DisplayControl);
845 CONFIG_PRINT_BOOL(config, Clipboard);
846 CONFIG_PRINT_BOOL(config, AudioOutput);
847 CONFIG_PRINT_BOOL(config, AudioInput);
848 CONFIG_PRINT_BOOL(config, DeviceRedirection);
849 CONFIG_PRINT_BOOL(config, VideoRedirection);
850 CONFIG_PRINT_BOOL(config, CameraRedirection);
851 CONFIG_PRINT_BOOL(config, RemoteApp);
852 CONFIG_PRINT_BOOL(config, PassthroughIsBlacklist);
854 if (config->PassthroughCount)
856 WLog_INFO(TAG,
"\tStatic Channels Proxy:");
857 pf_server_config_print_list(config->Passthrough, config->PassthroughCount);
860 if (config->InterceptCount)
862 WLog_INFO(TAG,
"\tStatic Channels Proxy-Intercept:");
863 pf_server_config_print_list(config->Intercept, config->InterceptCount);
867 CONFIG_PRINT_SECTION_KEY(section_plugins, key_plugins_modules);
868 for (
size_t x = 0; x < config->ModulesCount; x++)
869 CONFIG_PRINT_STR(config, Modules[x]);
872 CONFIG_PRINT_SECTION_KEY(section_plugins, key_plugins_required);
873 for (
size_t x = 0; x < config->RequiredPluginsCount; x++)
874 CONFIG_PRINT_STR(config, RequiredPlugins[x]);
876 CONFIG_PRINT_SECTION(section_certificates);
877 CONFIG_PRINT_STR(config, CertificateFile);
878 CONFIG_PRINT_STR_CONTENT(config, CertificateContent);
879 CONFIG_PRINT_STR(config, PrivateKeyFile);
880 CONFIG_PRINT_STR_CONTENT(config, PrivateKeyContent);
883static void zfree(
char* str)
887 const size_t len = strlen(str);
892static void znfree(
char* str,
size_t len)
902 if (config ==
nullptr)
906 free(config->TargetHost);
907 free(config->TargetUser);
908 free(config->TargetDomain);
909 free(config->TargetPassword);
911 CommandLineParserFree(config->Passthrough);
912 CommandLineParserFree(config->Intercept);
913 CommandLineParserFree(config->Modules);
914 CommandLineParserFree(config->RequiredPlugins);
916 free(config->CertificateFile);
917 zfree(config->CertificateContent);
918 znfree(config->CertificatePEM, config->CertificatePEMLength);
919 free(config->PrivateKeyFile);
920 zfree(config->PrivateKeyContent);
921 znfree(config->PrivateKeyPEM, config->PrivateKeyPEMLength);
922 IniFile_Free(config->ini);
928 WINPR_ASSERT(config);
929 return config->RequiredPluginsCount;
934 WINPR_ASSERT(config);
935 if (index >= config->RequiredPluginsCount)
938 return config->RequiredPlugins[index];
943 WINPR_ASSERT(config);
944 return config->ModulesCount;
955 WINPR_ASSERT(config);
957 cnv.ppc = config->Modules;
962static BOOL pf_config_copy_string(
char** dst,
const char* src)
971static BOOL pf_config_copy_string_n(
char** dst,
const char* src,
size_t size)
975 if (src && (size > 0))
977 WINPR_ASSERT(strnlen(src, size) == size - 1);
978 *dst = calloc(size,
sizeof(
char));
981 memcpy(*dst, src, size);
988static BOOL pf_config_copy_string_list(
char*** dst,
size_t* size,
char** src,
size_t srcSize)
992 WINPR_ASSERT(src || (srcSize == 0));
996 if (srcSize > INT32_MAX)
1001 char* csv = CommandLineToCommaSeparatedValues((INT32)srcSize, src);
1002 *dst = CommandLineParseCommaSeparatedValues(csv, size);
1011 proxyConfig* tmp = calloc(1,
sizeof(proxyConfig));
1014 WINPR_ASSERT(config);
1021 if (!pf_config_copy_string(&tmp->Host, config->Host))
1023 if (!pf_config_copy_string(&tmp->TargetHost, config->TargetHost))
1025 if (!pf_config_copy_string(&tmp->TargetUser, config->TargetUser))
1027 if (!pf_config_copy_string(&tmp->TargetDomain, config->TargetDomain))
1029 if (!pf_config_copy_string(&tmp->TargetPassword, config->TargetPassword))
1031 if (!pf_config_copy_string_list(&tmp->Passthrough, &tmp->PassthroughCount, config->Passthrough,
1032 config->PassthroughCount))
1034 if (!pf_config_copy_string_list(&tmp->Intercept, &tmp->InterceptCount, config->Intercept,
1035 config->InterceptCount))
1037 if (!pf_config_copy_string_list(&tmp->Modules, &tmp->ModulesCount, config->Modules,
1038 config->ModulesCount))
1040 if (!pf_config_copy_string_list(&tmp->RequiredPlugins, &tmp->RequiredPluginsCount,
1041 config->RequiredPlugins, config->RequiredPluginsCount))
1043 if (!pf_config_copy_string(&tmp->CertificateFile, config->CertificateFile))
1045 if (!pf_config_copy_string(&tmp->CertificateContent, config->CertificateContent))
1047 if (!pf_config_copy_string_n(&tmp->CertificatePEM, config->CertificatePEM,
1048 config->CertificatePEMLength))
1050 if (!pf_config_copy_string(&tmp->PrivateKeyFile, config->PrivateKeyFile))
1052 if (!pf_config_copy_string(&tmp->PrivateKeyContent, config->PrivateKeyContent))
1054 if (!pf_config_copy_string_n(&tmp->PrivateKeyPEM, config->PrivateKeyPEM,
1055 config->PrivateKeyPEMLength))
1058 tmp->ini = IniFile_Clone(config->ini);
1066 WINPR_PRAGMA_DIAG_PUSH
1067 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
1069 WINPR_PRAGMA_DIAG_POP
1073struct config_plugin_data
1075 proxyPluginsManager* mgr;
1076 const proxyConfig* config;
1079static const char config_plugin_name[] =
"config";
1080static const char config_plugin_desc[] =
1081 "A plugin filtering according to proxy configuration file rules";
1084static BOOL config_plugin_unload(proxyPlugin* plugin)
1086 WINPR_ASSERT(plugin);
1091 free(plugin->custom);
1092 plugin->custom =
nullptr;
1099static BOOL config_plugin_keyboard_event(proxyPlugin* plugin, WINPR_ATTR_UNUSED proxyData* pdata,
1103 const struct config_plugin_data* custom =
nullptr;
1104 const proxyConfig* cfg =
nullptr;
1107 WINPR_ASSERT(plugin);
1108 WINPR_ASSERT(pdata);
1109 WINPR_ASSERT(event_data);
1111 WINPR_UNUSED(event_data);
1113 custom = plugin->custom;
1114 WINPR_ASSERT(custom);
1116 cfg = custom->config;
1120 WLog_DBG(TAG,
"%s", boolstr(rc));
1125static BOOL config_plugin_unicode_event(proxyPlugin* plugin, WINPR_ATTR_UNUSED proxyData* pdata,
1129 const struct config_plugin_data* custom =
nullptr;
1130 const proxyConfig* cfg =
nullptr;
1133 WINPR_ASSERT(plugin);
1134 WINPR_ASSERT(pdata);
1135 WINPR_ASSERT(event_data);
1137 WINPR_UNUSED(event_data);
1139 custom = plugin->custom;
1140 WINPR_ASSERT(custom);
1142 cfg = custom->config;
1146 WLog_DBG(TAG,
"%s", boolstr(rc));
1151static BOOL config_plugin_mouse_event(proxyPlugin* plugin, WINPR_ATTR_UNUSED proxyData* pdata,
1155 const struct config_plugin_data* custom =
nullptr;
1156 const proxyConfig* cfg =
nullptr;
1159 WINPR_ASSERT(plugin);
1160 WINPR_ASSERT(pdata);
1161 WINPR_ASSERT(event_data);
1163 WINPR_UNUSED(event_data);
1165 custom = plugin->custom;
1166 WINPR_ASSERT(custom);
1168 cfg = custom->config;
1176static BOOL config_plugin_mouse_ex_event(proxyPlugin* plugin, WINPR_ATTR_UNUSED proxyData* pdata,
1180 const struct config_plugin_data* custom =
nullptr;
1181 const proxyConfig* cfg =
nullptr;
1184 WINPR_ASSERT(plugin);
1185 WINPR_ASSERT(pdata);
1186 WINPR_ASSERT(event_data);
1188 WINPR_UNUSED(event_data);
1190 custom = plugin->custom;
1191 WINPR_ASSERT(custom);
1193 cfg = custom->config;
1201static BOOL config_plugin_client_channel_data(WINPR_ATTR_UNUSED proxyPlugin* plugin,
1202 WINPR_ATTR_UNUSED proxyData* pdata,
void* param)
1206 WINPR_ASSERT(plugin);
1207 WINPR_ASSERT(pdata);
1208 WINPR_ASSERT(channel);
1210 WLog_DBG(TAG,
"%s [0x%04" PRIx16
"] got %" PRIuz, channel->channel_name, channel->channel_id,
1216static BOOL config_plugin_server_channel_data(WINPR_ATTR_UNUSED proxyPlugin* plugin,
1217 WINPR_ATTR_UNUSED proxyData* pdata,
void* param)
1221 WINPR_ASSERT(plugin);
1222 WINPR_ASSERT(pdata);
1223 WINPR_ASSERT(channel);
1225 WLog_DBG(TAG,
"%s [0x%04" PRIx16
"] got %" PRIuz, channel->channel_name, channel->channel_id,
1231static BOOL config_plugin_dynamic_channel_create(proxyPlugin* plugin,
1232 WINPR_ATTR_UNUSED proxyData* pdata,
void* param)
1237 WINPR_ASSERT(plugin);
1238 WINPR_ASSERT(pdata);
1239 WINPR_ASSERT(channel);
1241 const struct config_plugin_data* custom = plugin->custom;
1242 WINPR_ASSERT(custom);
1244 const proxyConfig* cfg = custom->config;
1247 pf_utils_channel_mode rc = pf_utils_get_channel_mode(cfg, channel->channel_name);
1251 case PF_UTILS_CHANNEL_INTERCEPT:
1252 case PF_UTILS_CHANNEL_PASSTHROUGH:
1255 case PF_UTILS_CHANNEL_BLOCK:
1263 if (strncmp(RDPGFX_DVC_CHANNEL_NAME, channel->channel_name,
1264 sizeof(RDPGFX_DVC_CHANNEL_NAME)) == 0)
1266 else if (strncmp(RDPSND_DVC_CHANNEL_NAME, channel->channel_name,
1267 sizeof(RDPSND_DVC_CHANNEL_NAME)) == 0)
1268 accept = cfg->AudioOutput;
1269 else if (strncmp(RDPSND_LOSSY_DVC_CHANNEL_NAME, channel->channel_name,
1270 sizeof(RDPSND_LOSSY_DVC_CHANNEL_NAME)) == 0)
1271 accept = cfg->AudioOutput;
1272 else if (strncmp(AUDIN_DVC_CHANNEL_NAME, channel->channel_name,
1273 sizeof(AUDIN_DVC_CHANNEL_NAME)) == 0)
1274 accept = cfg->AudioInput;
1275 else if (strncmp(RDPEI_DVC_CHANNEL_NAME, channel->channel_name,
1276 sizeof(RDPEI_DVC_CHANNEL_NAME)) == 0)
1277 accept = cfg->Multitouch;
1278 else if (strncmp(TSMF_DVC_CHANNEL_NAME, channel->channel_name,
1279 sizeof(TSMF_DVC_CHANNEL_NAME)) == 0)
1280 accept = cfg->VideoRedirection;
1281 else if (strncmp(VIDEO_CONTROL_DVC_CHANNEL_NAME, channel->channel_name,
1282 sizeof(VIDEO_CONTROL_DVC_CHANNEL_NAME)) == 0)
1283 accept = cfg->VideoRedirection;
1284 else if (strncmp(VIDEO_DATA_DVC_CHANNEL_NAME, channel->channel_name,
1285 sizeof(VIDEO_DATA_DVC_CHANNEL_NAME)) == 0)
1286 accept = cfg->VideoRedirection;
1287 else if (strncmp(RDPECAM_DVC_CHANNEL_NAME, channel->channel_name,
1288 sizeof(RDPECAM_DVC_CHANNEL_NAME)) == 0)
1289 accept = cfg->CameraRedirection;
1292 WLog_DBG(TAG,
"%s [0x%04" PRIx16
"]: %s", channel->channel_name, channel->channel_id,
1298static BOOL config_plugin_channel_create(proxyPlugin* plugin, WINPR_ATTR_UNUSED proxyData* pdata,
1304 WINPR_ASSERT(plugin);
1305 WINPR_ASSERT(pdata);
1306 WINPR_ASSERT(channel);
1308 const struct config_plugin_data* custom = plugin->custom;
1309 WINPR_ASSERT(custom);
1311 const proxyConfig* cfg = custom->config;
1314 pf_utils_channel_mode rc = pf_utils_get_channel_mode(cfg, channel->channel_name);
1317 case PF_UTILS_CHANNEL_INTERCEPT:
1318 case PF_UTILS_CHANNEL_PASSTHROUGH:
1321 case PF_UTILS_CHANNEL_BLOCK:
1328 if (strncmp(CLIPRDR_SVC_CHANNEL_NAME, channel->channel_name,
1329 sizeof(CLIPRDR_SVC_CHANNEL_NAME)) == 0)
1330 accept = cfg->Clipboard;
1331 else if (strncmp(RDPSND_CHANNEL_NAME, channel->channel_name,
sizeof(RDPSND_CHANNEL_NAME)) ==
1333 accept = cfg->AudioOutput;
1334 else if (strncmp(RDPDR_SVC_CHANNEL_NAME, channel->channel_name,
1335 sizeof(RDPDR_SVC_CHANNEL_NAME)) == 0)
1336 accept = cfg->DeviceRedirection;
1337 else if (strncmp(DISP_DVC_CHANNEL_NAME, channel->channel_name,
1338 sizeof(DISP_DVC_CHANNEL_NAME)) == 0)
1339 accept = cfg->DisplayControl;
1340 else if (strncmp(RAIL_SVC_CHANNEL_NAME, channel->channel_name,
1341 sizeof(RAIL_SVC_CHANNEL_NAME)) == 0)
1342 accept = cfg->RemoteApp;
1345 WLog_DBG(TAG,
"%s [static]: %s", channel->channel_name, boolstr(accept));
1351 struct config_plugin_data* custom =
nullptr;
1352 proxyPlugin plugin = WINPR_C_ARRAY_INIT;
1354 plugin.name = config_plugin_name;
1355 plugin.description = config_plugin_desc;
1356 plugin.PluginUnload = config_plugin_unload;
1358 plugin.KeyboardEvent = config_plugin_keyboard_event;
1359 plugin.UnicodeEvent = config_plugin_unicode_event;
1360 plugin.MouseEvent = config_plugin_mouse_event;
1361 plugin.MouseExEvent = config_plugin_mouse_ex_event;
1362 plugin.ClientChannelData = config_plugin_client_channel_data;
1363 plugin.ServerChannelData = config_plugin_server_channel_data;
1364 plugin.ChannelCreate = config_plugin_channel_create;
1365 plugin.DynamicChannelCreate = config_plugin_dynamic_channel_create;
1366 plugin.userdata = userdata;
1368 custom = calloc(1,
sizeof(
struct config_plugin_data));
1372 custom->mgr = plugins_manager;
1373 custom->config = userdata;
1375 plugin.custom = custom;
1376 plugin.userdata = userdata;
1378 return plugins_manager->RegisterPlugin(plugins_manager, &plugin);
1381const char*
pf_config_get(
const proxyConfig* config,
const char* section,
const char* key)
1383 WINPR_ASSERT(config);
1384 WINPR_ASSERT(config->ini);
1385 WINPR_ASSERT(section);
1388 return IniFile_GetKeyValueString(config->ini, section, key);
void pf_server_config_free(proxyConfig *config)
pf_server_config_free Releases all resources associated with proxyConfig
proxyConfig * pf_server_config_load_file(const char *path)
pf_server_config_load_file Create a proxyConfig from a INI file found at path.
void pf_server_config_print(const proxyConfig *config)
pf_server_config_print Print the configuration to stdout
const char ** pf_config_modules(const proxyConfig *config)
pf_config_modules
const char * pf_config_required_plugin(const proxyConfig *config, size_t index)
pf_config_required_plugin
proxyConfig * pf_server_config_load_buffer(const char *buffer)
pf_server_config_load_buffer Create a proxyConfig from a memory string buffer in INI file format
size_t pf_config_modules_count(const proxyConfig *config)
pf_config_modules_count
BOOL pf_config_clone(proxyConfig **dst, const proxyConfig *config)
pf_config_clone Create a copy of the configuration
proxyConfig * server_config_load_ini(wIniFile *ini)
server_config_load_ini Create a proxyConfig from a already loaded INI file.
size_t pf_config_required_plugins_count(const proxyConfig *config)
pf_config_required_plugins_count
BOOL pf_server_config_dump(const char *file)
pf_server_config_dump Dumps a default INI configuration file
BOOL pf_config_plugin(proxyPluginsManager *plugins_manager, void *userdata)
pf_config_plugin Register a proxy plugin handling event filtering defined in the configuration.
const char * pf_config_get(const proxyConfig *config, const char *section, const char *key)
pf_config_get get a value for a section/key