diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 953fa9b2..c773e220 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1051,8 +1051,8 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { result.config.curl_config.user_auth[MAX_INPUT_BUFFER - 1] = 0; break; case 'x': /* proxy info*/ - strncpy(result.config.curl_config.proxy, optarg, DEFAULT_BUFFER_SIZE -1); - result.config.curl_config.user_auth[DEFAULT_BUFFER_SIZE -1] = 0; + strncpy(result.config.curl_config.proxy, optarg, DEFAULT_BUFFER_SIZE - 1); + result.config.curl_config.user_auth[DEFAULT_BUFFER_SIZE - 1] = 0; break; case 'b': /* proxy-authorization info */ strncpy(result.config.curl_config.proxy_auth, optarg, MAX_INPUT_BUFFER - 1); @@ -1733,13 +1733,16 @@ void print_help(void) { printf("\n %s\n", "CHECK WEBSERVER CONTENT VIA PROXY:"); printf(" %s\n", _("Proxies are defined checked using the -x or --proxy parameter:")); - printf(" %s\n", _("The environment variables are only checked -x/--proxy arguments are not set:")); - printf(" %s\n", _("Depending on the SSL enablement, either http_proxy or https_proxy environment variable is used.")); - printf(" %s\n", _("These variables can also be given in uppercase, but the lowercase ones will take predence if both are defined.")); + printf(" %s\n", + _("The environment variables are only checked -x/--proxy arguments are not set:")); + printf(" %s\n", _("Depending on the SSL enablement, either http_proxy or https_proxy " + "environment variable is used.")); + printf(" %s\n", _("These variables can also be given in uppercase, but the lowercase ones will " + "take predence if both are defined.")); printf(" %s\n", _("http_proxy=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org")); - printf(" %s\n", - _("HTTPS_PROXY=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org --ssl")); + printf(" %s\n", _("HTTPS_PROXY=http://192.168.100.35:3128 ./check_curl -H " + "www.monitoring-plugins.org --ssl")); printf(" %s\n", _("legacy proxy requests in check_http style still work:")); printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u http://www.monitoring-plugins.org/ " "-H www.monitoring-plugins.org")); @@ -1772,7 +1775,8 @@ void print_usage(void) { printf(" [-J ] [-K ] [--ca-cert ] [-D]\n"); printf(" [-w ] [-c ] [-t ] [-L] [-E] [-x ]\n"); - printf(" [-a auth] [-b proxy_auth] [-f ]\n"); + printf(" [-a auth] [-b proxy_auth] [-f " + "]\n"); printf(" [-e ] [-d string] [-s string] [-l] [-r | -R ]\n"); printf(" [-P string] [-m :] [-4|-6] [-N] [-M ]\n"); diff --git a/plugins/check_curl.d/check_curl_helpers.c b/plugins/check_curl.d/check_curl_helpers.c index 68bd7c09..b0680b8e 100644 --- a/plugins/check_curl.d/check_curl_helpers.c +++ b/plugins/check_curl.d/check_curl_helpers.c @@ -118,16 +118,18 @@ check_curl_configure_curl(const check_curl_static_curl_config config, /* set proxy */ const struct curl_easyoption *curlopt_proxy_easyoption = curl_easy_option_by_id(CURLOPT_PROXY); - handle_curl_easyoption(curlopt_proxy_easyoption,"CURLOPT_PROXY"); + handle_curl_easyoption(curlopt_proxy_easyoption, "CURLOPT_PROXY"); char proxy_option_str[DEFAULT_BUFFER_SIZE]; - if (verbose >= 1 && curlopt_proxy_easyoption != NULL){ - printf("* cURL Easy Option %s\n", format_curl_easyoption(curlopt_proxy_easyoption, proxy_option_str, DEFAULT_BUFFER_SIZE)); + if (verbose >= 1 && curlopt_proxy_easyoption != NULL) { + printf("* cURL Easy Option %s\n", + format_curl_easyoption(curlopt_proxy_easyoption, proxy_option_str, + DEFAULT_BUFFER_SIZE)); } /* proxy can either be given from the command line, or taken from environment variables */ char curlopt_proxy[DEFAULT_BUFFER_SIZE]; - if (config.proxy != NULL && strlen(config.proxy) > 0 ){ + if (strlen(config.proxy) > 0) { strcpy(curlopt_proxy, config.proxy); - }else{ + } else { char *http_proxy_env; http_proxy_env = getenv("http_proxy"); char *http_proxy_uppercase_env; @@ -136,33 +138,37 @@ check_curl_configure_curl(const check_curl_static_curl_config config, https_proxy_env = getenv("https_proxy"); char *https_proxy_uppercase_env; https_proxy_uppercase_env = getenv("HTTPS_PROXY"); - /* lower case proxy environment varialbes are generally more accepted. accept both, but take the lowercase one when both are available*/ - if(working_state.use_ssl){ - if(https_proxy_env != NULL && strlen(https_proxy_env) > 0){ + /* lower case proxy environment variables are generally more accepted. accept both, but take + * the lowercase one when both are available*/ + if (working_state.use_ssl) { + if (https_proxy_env != NULL && strlen(https_proxy_env) > 0) { strcpy(curlopt_proxy, https_proxy_env); - if(https_proxy_uppercase_env != NULL && verbose >=1){ - printf("* cURL ignoring environment variable HTTPS_PROXY as https_proxy is set\n"); + if (https_proxy_uppercase_env != NULL && verbose >= 1) { + printf( + "* cURL ignoring environment variable HTTPS_PROXY as https_proxy is set\n"); } - }else if(https_proxy_uppercase_env != NULL && strlen(https_proxy_uppercase_env) >= 0){ + } else if (https_proxy_uppercase_env != NULL && + strlen(https_proxy_uppercase_env) >= 0) { strcpy(curlopt_proxy, https_proxy_uppercase_env); + } else { + strcpy(curlopt_proxy, ""); } - else{ - strcpy(curlopt_proxy,""); - } - }else{ - if(http_proxy_env != NULL && strlen(http_proxy_env) > 0){ + } else { + if (http_proxy_env != NULL && strlen(http_proxy_env) > 0) { strcpy(curlopt_proxy, http_proxy_env); - if(http_proxy_uppercase_env != NULL && verbose >=1){ - printf("* cURL ignoring environment variable HTTP_PROXY as http_proxy is set\n"); + if (http_proxy_uppercase_env != NULL && verbose >= 1) { + printf( + "* cURL ignoring environment variable HTTP_PROXY as http_proxy is set\n"); } - }else if(http_proxy_uppercase_env != NULL && strlen(http_proxy_uppercase_env) > 0){ + } else if (http_proxy_uppercase_env != NULL && strlen(http_proxy_uppercase_env) > 0) { strcpy(curlopt_proxy, http_proxy_uppercase_env); - }else{ - strcpy(curlopt_proxy,""); + } else { + strcpy(curlopt_proxy, ""); } } } - handle_curl_option_return_code(curl_easy_setopt(result.curl_state.curl, CURLOPT_PROXY, curlopt_proxy), "CURLOPT_PROXY"); + handle_curl_option_return_code( + curl_easy_setopt(result.curl_state.curl, CURLOPT_PROXY, curlopt_proxy), "CURLOPT_PROXY"); /* enable haproxy protocol */ if (config.haproxy_protocol) { @@ -177,7 +183,8 @@ check_curl_configure_curl(const check_curl_static_curl_config config, /* If the proxy should resolve the hostname, socks4h and socks5h scheme is used.*/ char dnscache[DEFAULT_BUFFER_SIZE]; char addrstr[DEFAULT_BUFFER_SIZE / 2]; - if (working_state.use_ssl && working_state.host_name != NULL && (curlopt_proxy != NULL && strlen(curlopt_proxy) == 0)) { + if (working_state.use_ssl && working_state.host_name != NULL && + (strlen(curlopt_proxy) == 0)) { char *tmp_mod_address; /* lookup_host() requires an IPv6 address without the brackets. */ @@ -618,47 +625,47 @@ void handle_curl_option_return_code(CURLcode res, const char *option) { } void handle_curl_easyoption(const struct curl_easyoption *option, const char *name) { - if (option == NULL){ + if (option == NULL) { die(STATE_CRITICAL, _("Error while getting cURL option '%s': cURL option is null"), name); } } -char *format_curl_easyoption(const struct curl_easyoption *option, char *buf, unsigned int buflen){ - if(option == NULL){ +char *format_curl_easyoption(const struct curl_easyoption *option, char *buf, unsigned int buflen) { + if (option == NULL) { die(STATE_CRITICAL, _("Can not print details about an empty cURL option")); } - int offset = snprintf(buf, buflen, "name: %s flags: %s", option->name, option->flags); - switch(option->type){ - case CURLOT_LONG: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_LONG"); - break; - case CURLOT_VALUES: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_VALUES"); - break; - case CURLOT_OFF_T: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_OFF_T"); - break; - case CURLOT_OBJECT: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_OBJECT"); - break; - case CURLOT_STRING: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_STRING"); - break; - case CURLOT_SLIST: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_SLIST"); - break; - case CURLOT_CBPTR: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_CBPTR"); - break; - case CURLOT_BLOB: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_BLOB"); - break; - case CURLOT_FUNCTION: - offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_FUNCTION"); - break; - default: - offset += snprintf(buf + offset, buflen - offset, " type: Unknown"); - break; + int offset = snprintf(buf, buflen, "name: %s flags: %u", option->name, option->flags); + switch (option->type) { + case CURLOT_LONG: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_LONG"); + break; + case CURLOT_VALUES: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_VALUES"); + break; + case CURLOT_OFF_T: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_OFF_T"); + break; + case CURLOT_OBJECT: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_OBJECT"); + break; + case CURLOT_STRING: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_STRING"); + break; + case CURLOT_SLIST: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_SLIST"); + break; + case CURLOT_CBPTR: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_CBPTR"); + break; + case CURLOT_BLOB: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_BLOB"); + break; + case CURLOT_FUNCTION: + offset += snprintf(buf + offset, buflen - offset, " type: CURLOT_FUNCTION"); + break; + default: + offset += snprintf(buf + offset, buflen - offset, " type: Unknown"); + break; } offset += snprintf(buf + offset, buflen - offset, " id: %d", option->id); return buf;