From fd338c3bd465ac564e7c950e2cee78789248b401 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 23 Jun 2023 12:38:24 +0200 Subject: [PATCH] [server,proxy] allow reading arbitrary keys from config Allow the proxy configuration to contain arbitrary section/key/value entries which can be used by plugins for configuration. --- include/freerdp/server/proxy/proxy_config.h | 13 +++++++++++++ server/proxy/pf_config.c | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/freerdp/server/proxy/proxy_config.h b/include/freerdp/server/proxy/proxy_config.h index bafa813ef..dbd255067 100644 --- a/include/freerdp/server/proxy/proxy_config.h +++ b/include/freerdp/server/proxy/proxy_config.h @@ -107,6 +107,8 @@ extern "C" /* Data extracted from PrivateKeyContent or PrivateKeyFile (evaluation in this order) */ char* PrivateKeyPEM; size_t PrivateKeyPEMLength; + + wIniFile* ini; }; /** @@ -213,6 +215,17 @@ extern "C" */ FREERDP_API BOOL pf_config_plugin(proxyPluginsManager* plugins_manager, void* userdata); + /** + * @brief pf_config_get get a value for a section/key + * @param config A pointer to the proxyConfig. Must NOT be NULL. + * @param section The name of the section the key is in, must not be \b NULL + * @param key The name of the key to look for. Must not be \b NULL + * + * @return A pointer to the value for \b section/key or \b NULL if not found + */ + FREERDP_API const char* pf_config_get(const proxyConfig* config, const char* section, + const char* key); + #ifdef __cplusplus } #endif diff --git a/server/proxy/pf_config.c b/server/proxy/pf_config.c index 85ac6ad6b..4be291793 100644 --- a/server/proxy/pf_config.c +++ b/server/proxy/pf_config.c @@ -602,6 +602,9 @@ proxyConfig* server_config_load_ini(wIniFile* ini) if (!pf_config_load_certificates(ini, config)) goto out; + config->ini = IniFile_Clone(ini); + if (!config->ini) + goto out; } return config; out: @@ -897,6 +900,7 @@ void pf_server_config_free(proxyConfig* config) if (config->PrivateKeyPEM) memset(config->PrivateKeyPEM, 0, config->PrivateKeyPEMLength); free(config->PrivateKeyPEM); + IniFile_Free(config->ini); free(config); } @@ -1022,6 +1026,10 @@ BOOL pf_config_clone(proxyConfig** dst, const proxyConfig* config) config->PrivateKeyPEMLength)) goto fail; + tmp->ini = IniFile_Clone(config->ini); + if (!tmp->ini) + goto fail; + *dst = tmp; return TRUE; @@ -1326,3 +1334,13 @@ BOOL pf_config_plugin(proxyPluginsManager* plugins_manager, void* userdata) return plugins_manager->RegisterPlugin(plugins_manager, &plugin); } + +const char* pf_config_get(const proxyConfig* config, const char* section, const char* key) +{ + WINPR_ASSERT(config); + WINPR_ASSERT(config->ini); + WINPR_ASSERT(section); + WINPR_ASSERT(key); + + return IniFile_GetKeyValueString(config->ini, section, key); +}