diff --git a/ChangeLog b/ChangeLog index 986f36a8..c1633858 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ New features: ...G...PS. [ZBXNEXT-5839] added SNI in encrypted TCP connections (yurii) ...G...... [ZBXNEXT-6666] added listen socket security fix for Agent 2 on Windows (ssimonenko) ...G...PS. [ZBXNEXT-7120] added support of OpenSSL 3.0 (Andris) +...G...PS. [ZBXNEXT-8273] fixed failures to read relative paths based on current working directory from Include directives in Zabbix Agent config (dgoloscapov) Bug fixes: ..F....... [ZBX-4646] fixed month abbreviation with capital "M" (Sasha) diff --git a/PATCHLIST.md b/PATCHLIST.md index 23fddf08..175b3963 100644 --- a/PATCHLIST.md +++ b/PATCHLIST.md @@ -384,6 +384,7 @@ [ZBXNEXT-6809] changed behavior of the vmware event log, the 'skip' option of the new item resets the VMware event cache (https://support.zabbix.com/browse/ZBXNEXT-6809) [ZBXNEXT-7100] added new LLD macro HV.NETNAME to vmware.hv.discovery (https://support.zabbix.com/browse/ZBXNEXT-7100) [ZBXNEXT-7120] added support of OpenSSL 3.0 (https://support.zabbix.com/browse/ZBXNEXT-7120) +[ZBXNEXT-8273] fixed failures to read relative paths based on current working directory from Include directives in Zabbix Agent config (https://support.zabbix.com/browse/ZBXNEXT-8273) ~~~~ # List of my patches (English) diff --git a/build/win32/project/Makefile_agent b/build/win32/project/Makefile_agent index 866633dd..8f0bdeb5 100644 --- a/build/win32/project/Makefile_agent +++ b/build/win32/project/Makefile_agent @@ -108,7 +108,7 @@ OBJS = \ ..\..\..\src\libs\zbxwin32\fatal.o \ ..\..\..\src\libs\zbxwin32\disk.o -LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib delayimp.lib wevtapi.lib $(LIBS) +LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib delayimp.lib wevtapi.lib shlwapi.lib $(LIBS) !INCLUDE Makefile_pcre.inc !INCLUDE Makefile_tls.inc diff --git a/build/win32/project/Makefile_get b/build/win32/project/Makefile_get index ab910506..f6b1aa5a 100644 --- a/build/win32/project/Makefile_get +++ b/build/win32/project/Makefile_get @@ -45,7 +45,7 @@ OBJS = \ ..\..\..\src\zabbix_get\zabbix_get.o \ ..\..\..\src\libs\zbxwin32\fatal.o -LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib user32.lib $(LIBS) +LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib user32.lib shlwapi.lib $(LIBS) !INCLUDE Makefile_pcre.inc !INCLUDE Makefile_tls.inc diff --git a/build/win32/project/Makefile_sender b/build/win32/project/Makefile_sender index 24e69797..c79dce53 100644 --- a/build/win32/project/Makefile_sender +++ b/build/win32/project/Makefile_sender @@ -53,7 +53,7 @@ OBJS = \ ..\..\..\src\libs\zbxregexp\zbxregexp.o \ ..\..\..\src\zabbix_sender\zabbix_sender.o -LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib user32.lib $(LIBS) +LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib user32.lib shlwapi.lib $(LIBS) !INCLUDE Makefile_pcre.inc !INCLUDE Makefile_tls.inc diff --git a/build/win32/project/Makefile_sender_dll b/build/win32/project/Makefile_sender_dll index 6cbb0b66..6c5c3d74 100644 --- a/build/win32/project/Makefile_sender_dll +++ b/build/win32/project/Makefile_sender_dll @@ -59,7 +59,7 @@ OBJS = \ ..\..\..\src\libs\zbxregexp\zbxregexp.o \ ..\..\..\src\zabbix_sender\win32\zabbix_sender.o -LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib +LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib shlwapi.lib !INCLUDE Makefile_pcre.inc !INCLUDE Makefile_targets.inc diff --git a/src/libs/zbxconf/cfg.c b/src/libs/zbxconf/cfg.c index dad2524c..28a8086b 100644 --- a/src/libs/zbxconf/cfg.c +++ b/src/libs/zbxconf/cfg.c @@ -22,6 +22,12 @@ #include "log.h" #include "comms.h" +#if defined(_WINDOWS) || defined(__MINGW32__) +#include +#else +#include +#endif + extern unsigned char program_type; char *CONFIG_FILE = NULL; @@ -295,6 +301,52 @@ static int parse_cfg_dir(const char *path, const char *pattern, struct cfg_line } #endif +static char *expand_include_path(char *raw_path) +{ +#if defined(_WINDOWS) || defined(__MINGW32__) + wchar_t *wraw_path; + + wraw_path = zbx_utf8_to_unicode(raw_path); + + if (TRUE == PathIsRelativeW(wraw_path)) + { + wchar_t *wconfig_path, dir_buf[_MAX_DIR]; + char *dir_utf8, *result = NULL; + + zbx_free(wraw_path); + + wconfig_path = zbx_utf8_to_unicode(CONFIG_FILE); + _wsplitpath(wconfig_path, NULL, dir_buf, NULL, NULL); + + zbx_free(wconfig_path); + + dir_utf8 = zbx_unicode_to_utf8(dir_buf); + result = zbx_dsprintf(result, "%s%s", dir_utf8, raw_path); + + zbx_free(raw_path); + zbx_free(dir_utf8); + + return result; + } + + zbx_free(wraw_path); +#else + if ('/' != *raw_path) + { + char *cfg_file, *path; + + cfg_file = zbx_strdup(NULL, CONFIG_FILE); + path = zbx_dsprintf(NULL, "%s/%s", dirname(cfg_file), raw_path); + zbx_free(cfg_file); + + zbx_free(raw_path); + + return path; + } +#endif + return raw_path; +} + /****************************************************************************** * * * Purpose: parse "Include=..." line in configuration file * @@ -317,6 +369,8 @@ static int parse_cfg_object(const char *cfg_file, struct cfg_line *cfg, int leve if (SUCCEED != parse_glob(cfg_file, &path, &pattern)) goto clean; + path = expand_include_path(path); + if (0 != zbx_stat(path, &sb)) { zbx_error("%s: %s", path, zbx_strerror(errno)); diff --git a/tests/libs/zbxconf/parse_cfg_file.c b/tests/libs/zbxconf/parse_cfg_file.c index 15c4acdc..4b2a6a0e 100644 --- a/tests/libs/zbxconf/parse_cfg_file.c +++ b/tests/libs/zbxconf/parse_cfg_file.c @@ -229,6 +229,8 @@ void zbx_mock_test_entry(void **state) cfg = zbx_realloc(cfg, (parameter_count + 1) * sizeof(struct cfg_line)); cfg[parameter_count].parameter = NULL; + CONFIG_FILE = cfg_file; + parse_cfg_file(cfg_file, cfg, ZBX_CFG_FILE_REQUIRED, strict); if (ZBX_MOCK_NO_EXIT_CODE != (error = zbx_mock_exit_code(&exit_code))) diff --git a/tests/libs/zbxconf/parse_cfg_file.yaml b/tests/libs/zbxconf/parse_cfg_file.yaml index 5a5c9de2..7f1bc8a1 100644 --- a/tests/libs/zbxconf/parse_cfg_file.yaml +++ b/tests/libs/zbxconf/parse_cfg_file.yaml @@ -32,7 +32,7 @@ files: Include= db.conf LoadModule=smarty.so #LoadModule=beauty.so - db.conf: | + ./db.conf: | DBPassword=r3ally_$tr0ng_pa$$w0rd --- test case: recursive self inclusion @@ -65,23 +65,23 @@ in: files: 1.conf: | Include=2.conf - 2.conf: | + ./2.conf: | Include=3.conf - 3.conf: | + ./3.conf: | Include=4.conf - 4.conf: | + ./4.conf: | Include=5.conf - 5.conf: | + ./5.conf: | Include=6.conf - 6.conf: | + ./6.conf: | Include=7.conf - 7.conf: | + ./7.conf: | Include=8.conf - 8.conf: | + ./8.conf: | Include=9.conf - 9.conf: | + ./9.conf: | Include=10.conf - 10.conf: | + ./10.conf: | --- test case: too many inclusion levels in: