static int check_https(const char *host, unsigned short port, int timeout, int *value_int) { CURL *easyhandle; CURLoption opt; CURLcode err; char https_host[MAX_STRING_LEN]; *value_int = 0; if (NULL == (easyhandle = curl_easy_init())) { zabbix_log(LOG_LEVEL_DEBUG, "%s: could not init cURL library", __func__); goto clean; } if (SUCCEED == is_ip6(host)) zbx_snprintf(https_host, sizeof(https_host), "%s[%s]", (0 == strncmp(host, "https://", 8) ? "" : "https://"), host); else zbx_snprintf(https_host, sizeof(https_host), "%s%s", (0 == strncmp(host, "https://", 8) ? "" : "https://"), host); if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_USERAGENT, "Zabbix " ZABBIX_VERSION)) || CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_URL, https_host)) || CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_PORT, (long)port)) || CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_NOBODY, 1L)) || CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_SSL_VERIFYPEER, 0L)) || CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_SSL_VERIFYHOST, 0L)) || CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_TIMEOUT, (long)timeout))) { zabbix_log(LOG_LEVEL_DEBUG, "%s: could not set cURL option [%d]: %s", __func__, (int)opt, curl_easy_strerror(err)); goto clean; } if (NULL != CONFIG_SOURCE_IP) { if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_INTERFACE, CONFIG_SOURCE_IP))) { zabbix_log(LOG_LEVEL_DEBUG, "%s: could not set source interface option [%d]: %s", __func__, (int)opt, curl_easy_strerror(err)); goto clean; } } if (CURLE_OK == (err = curl_easy_perform(easyhandle))) *value_int = 1; else zabbix_log(LOG_LEVEL_DEBUG, "%s: curl_easy_perform failed for [%s:%hu]: %s", __func__, host, port, curl_easy_strerror(err)); clean: curl_easy_cleanup(easyhandle); return SYSINFO_RET_OK; }
static int web_set_ip(AGENT_RESULT *result, struct web *opt, const char *params, int param_id) { char ip_tmp[WEB_MAX_DNS_STRLEN] = {0}; /* RFC1035 */ if (get_param(params, param_id, ip_tmp, WEB_MAX_DNS_STRLEN)) goto failed; zbx_remove_whitespace(ip_tmp); if (strlen(ip_tmp)) { if (!is_ip4(ip_tmp)) { opt->is_ipv6 = (zbx_uint64_t) 0; opt->ip = zbx_strdup(NULL, ip_tmp); return SUCCEED; } #if defined(HAVE_IPV6) else if (!is_ip6(ip_tmp)) { opt->is_ipv6 = (zbx_uint64_t) 1; opt->ip = zbx_strdup(NULL, ip_tmp); return SUCCEED; } #endif /*HAVE_IPV6*/ else if (!(zbx_check_hostname(ip_tmp))) { opt->is_ip_hostname = (zbx_uint64_t) 1; opt->host = zbx_strdup(NULL, ip_tmp); return SUCCEED; } else { goto failed; } } else { if (opt->item->interface.useip) { opt->ip = zbx_strdup(NULL, opt->item->interface.ip_orig); return SUCCEED; } else { opt->host = zbx_strdup(NULL, opt->item->interface.dns_orig); return web_resolv_dns(opt, opt->item->interface.dns_orig); } } failed: SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Invalid IP / DNS parameter", NULL)); return FAIL; }
static bool pred_is_ip6(arguments_t args, SkBuff b) { return is_ip6(b); }