Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ZBXNEXT-8273] fixed failures to read relative paths based on current working directory from Include directives in Zabbix Agent config (dgoloscapov) #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions PATCHLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion build/win32/project/Makefile_agent
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/win32/project/Makefile_get
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/win32/project/Makefile_sender
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/win32/project/Makefile_sender_dll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions src/libs/zbxconf/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include "log.h"
#include "comms.h"

#if defined(_WINDOWS) || defined(__MINGW32__)
#include <shlwapi.h>
#else
#include <libgen.h>
#endif

extern unsigned char program_type;

char *CONFIG_FILE = NULL;
Expand Down Expand Up @@ -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 *
Expand All @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions tests/libs/zbxconf/parse_cfg_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
20 changes: 10 additions & 10 deletions tests/libs/zbxconf/parse_cfg_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Loading