Source
xxxxxxxxxx
int node_process_command(zbx_socket_t *sock, const char *data, const struct zbx_json_parse *jp, int config_timeout,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**********************************************************************************
* *
* Purpose: replaces occurrence of macro in input string with value given in *
* macrovalue, with memory management *
* *
* Parameters: in - [IN] input string to be processed *
* macro - [IN] macro to replace *
* macrovalue - [IN] value to replace macro with *
* out - [IN/OUT] pointer to memory holding result *
* out_alloc - [IN/OUT] size of memory holding result *
* *
* Return value: SUCCEED - remote command was executed successfully *
* FAIL - error occurred *
* *
**********************************************************************************/
static void substitute_macro(const char *in, const char *macro, const char *macrovalue, char **out,
size_t *out_alloc)
{
zbx_token_t token;
int pos = 0;
size_t out_offset = 0, macrovalue_len;
macrovalue_len = strlen(macrovalue);
zbx_strcpy_alloc(out, out_alloc, &out_offset, in);
out_offset++;
for (; SUCCEED == zbx_token_find(*out, pos, &token, ZBX_TOKEN_SIMPLE_MACRO); pos++)
{
pos = token.loc.r;
if (0 == strncmp(*out + token.loc.l, macro, token.loc.r - token.loc.l + 1))
{
pos += zbx_replace_mem_dyn(out, out_alloc, &out_offset, token.loc.l,
token.loc.r - token.loc.l + 1, macrovalue, macrovalue_len);
}
}
}
/******************************************************************************
* *
* Purpose: executes remote command and waits for result *
* *
* Return value: SUCCEED - remote command was executed successfully *
* FAIL - error occurred *
* *
******************************************************************************/
static int execute_remote_script(const zbx_script_t *script, const zbx_dc_host_t *host, char **info, char *error,
size_t max_error_len)
{
zbx_uint64_t taskid;
zbx_db_result_t result = NULL;
zbx_db_row_t row;
if (0 == host->proxyid)