int ssh_run(zbx_dc_item_t *item, AGENT_RESULT *result, const char *encoding, const char *options, int timeout,
#include "zbxcacheconfig.h"
#if !defined(HAVE_LIBSSH2_METHOD_KEX) && !defined(HAVE_LIBSSH2_METHOD_HOSTKEY) && \
!defined(HAVE_LIBSSH2_METHOD_CRYPT_CS) && !defined(HAVE_LIBSSH2_METHOD_CRYPT_SC) && \
!defined(HAVE_LIBSSH2_METHOD_MAC_CS) && !defined(HAVE_LIBSSH2_METHOD_MAC_SC)
#define HAVE_NO_LIBSSH2_METHODS 1
static ZBX_THREAD_LOCAL const char *password;
#ifndef HAVE_NO_LIBSSH2_METHODS
static int ssh_set_options(LIBSSH2_SESSION *session, int type, const char *key_str, const char *value,
zabbix_log(LOG_LEVEL_DEBUG, "In %s() key_str:'%s' value:'%s'", __func__, key_str, value);
if (0 > (res = libssh2_session_method_pref(session, type, value)) && res != LIBSSH2_ERROR_EAGAIN)
if (LIBSSH2_ERROR_NONE != libssh2_session_last_error(session, &err, NULL, 0))
*err_msg = zbx_dsprintf(NULL, "Cannot set SSH option \"%s\": %s.", key_str, err);
*err_msg = zbx_dsprintf(NULL, "Cannot set SSH option \"%s\".", key_str);
if (0 < (rc = libssh2_session_supported_algs(session, type, &algs)))
*err_msg = zbx_strdcat(*err_msg, " Supported values are: ");
for (int i = 0; i < rc; i++)
*err_msg = zbx_strdcat(*err_msg, algs[i]);
*err_msg = zbx_strdcat(*err_msg, ", ");
*err_msg = zbx_strdcat(*err_msg, ".");
libssh2_free(session, algs);
if (LIBSSH2_ERROR_NONE != libssh2_session_last_error(session, &err, NULL, 0))
*err_msg = zbx_strdcatf(*err_msg, " Cannot get supported values: %s.", err);
*err_msg = zbx_strdcat(*err_msg, " Cannot get supported values.");
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
static int ssh_parse_options(LIBSSH2_SESSION *session, const char *options, char **err_msg)
char opt_copy[1024] = {0};
zbx_strscpy(opt_copy, options);
for (char *line = strtok_r(opt_copy, ";", &saveptr); NULL != line; line = strtok_r(NULL, ";", &saveptr))