diff options
Diffstat (limited to 'plugins/check_curl.d/check_curl_helpers.c')
| -rw-r--r-- | plugins/check_curl.d/check_curl_helpers.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/plugins/check_curl.d/check_curl_helpers.c b/plugins/check_curl.d/check_curl_helpers.c index d49d8f07..7be781fc 100644 --- a/plugins/check_curl.d/check_curl_helpers.c +++ b/plugins/check_curl.d/check_curl_helpers.c | |||
| @@ -19,7 +19,7 @@ bool add_sslctx_verify_fun = false; | |||
| 19 | check_curl_configure_curl_wrapper | 19 | check_curl_configure_curl_wrapper |
| 20 | check_curl_configure_curl(const check_curl_static_curl_config config, | 20 | check_curl_configure_curl(const check_curl_static_curl_config config, |
| 21 | check_curl_working_state working_state, bool check_cert, | 21 | check_curl_working_state working_state, bool check_cert, |
| 22 | bool on_redirect_dependent, int follow_method, int max_depth) { | 22 | bool on_redirect_dependent, int follow_method, long max_depth) { |
| 23 | check_curl_configure_curl_wrapper result = { | 23 | check_curl_configure_curl_wrapper result = { |
| 24 | .errorcode = OK, | 24 | .errorcode = OK, |
| 25 | .curl_state = | 25 | .curl_state = |
| @@ -57,7 +57,7 @@ check_curl_configure_curl(const check_curl_static_curl_config config, | |||
| 57 | result.curl_state.curl_easy_initialized = true; | 57 | result.curl_state.curl_easy_initialized = true; |
| 58 | 58 | ||
| 59 | if (verbose >= 1) { | 59 | if (verbose >= 1) { |
| 60 | handle_curl_option_return_code(curl_easy_setopt(result.curl_state.curl, CURLOPT_VERBOSE, 1), | 60 | handle_curl_option_return_code(curl_easy_setopt(result.curl_state.curl, CURLOPT_VERBOSE, 1L), |
| 61 | "CURLOPT_VERBOSE"); | 61 | "CURLOPT_VERBOSE"); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -128,8 +128,20 @@ check_curl_configure_curl(const check_curl_static_curl_config config, | |||
| 128 | char dnscache[DEFAULT_BUFFER_SIZE]; | 128 | char dnscache[DEFAULT_BUFFER_SIZE]; |
| 129 | char addrstr[DEFAULT_BUFFER_SIZE / 2]; | 129 | char addrstr[DEFAULT_BUFFER_SIZE / 2]; |
| 130 | if (working_state.use_ssl && working_state.host_name != NULL) { | 130 | if (working_state.use_ssl && working_state.host_name != NULL) { |
| 131 | char *tmp_mod_address; | ||
| 132 | |||
| 133 | /* lookup_host() requires an IPv6 address without the brackets. */ | ||
| 134 | if ((strnlen(working_state.server_address, MAX_IPV4_HOSTLENGTH) > 2) && | ||
| 135 | (working_state.server_address[0] == '[')) { | ||
| 136 | // Duplicate and strip the leading '[' | ||
| 137 | tmp_mod_address = | ||
| 138 | strndup(working_state.server_address + 1, strlen(working_state.server_address) - 2); | ||
| 139 | } else { | ||
| 140 | tmp_mod_address = working_state.server_address; | ||
| 141 | } | ||
| 142 | |||
| 131 | int res; | 143 | int res; |
| 132 | if ((res = lookup_host(working_state.server_address, addrstr, DEFAULT_BUFFER_SIZE / 2, | 144 | if ((res = lookup_host(tmp_mod_address, addrstr, DEFAULT_BUFFER_SIZE / 2, |
| 133 | config.sin_family)) != 0) { | 145 | config.sin_family)) != 0) { |
| 134 | die(STATE_CRITICAL, | 146 | die(STATE_CRITICAL, |
| 135 | _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), | 147 | _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), |
| @@ -202,10 +214,10 @@ check_curl_configure_curl(const check_curl_static_curl_config config, | |||
| 202 | if (working_state.http_method) { | 214 | if (working_state.http_method) { |
| 203 | if (!strcmp(working_state.http_method, "POST")) { | 215 | if (!strcmp(working_state.http_method, "POST")) { |
| 204 | handle_curl_option_return_code( | 216 | handle_curl_option_return_code( |
| 205 | curl_easy_setopt(result.curl_state.curl, CURLOPT_POST, 1), "CURLOPT_POST"); | 217 | curl_easy_setopt(result.curl_state.curl, CURLOPT_POST, 1L), "CURLOPT_POST"); |
| 206 | } else if (!strcmp(working_state.http_method, "PUT")) { | 218 | } else if (!strcmp(working_state.http_method, "PUT")) { |
| 207 | handle_curl_option_return_code( | 219 | handle_curl_option_return_code( |
| 208 | curl_easy_setopt(result.curl_state.curl, CURLOPT_UPLOAD, 1), "CURLOPT_UPLOAD"); | 220 | curl_easy_setopt(result.curl_state.curl, CURLOPT_UPLOAD, 1L), "CURLOPT_UPLOAD"); |
| 209 | } else { | 221 | } else { |
| 210 | handle_curl_option_return_code(curl_easy_setopt(result.curl_state.curl, | 222 | handle_curl_option_return_code(curl_easy_setopt(result.curl_state.curl, |
| 211 | CURLOPT_CUSTOMREQUEST, | 223 | CURLOPT_CUSTOMREQUEST, |
| @@ -288,10 +300,10 @@ check_curl_configure_curl(const check_curl_static_curl_config config, | |||
| 288 | /* per default if we have a CA verify both the peer and the | 300 | /* per default if we have a CA verify both the peer and the |
| 289 | * hostname in the certificate, can be switched off later */ | 301 | * hostname in the certificate, can be switched off later */ |
| 290 | handle_curl_option_return_code( | 302 | handle_curl_option_return_code( |
| 291 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYPEER, 1), | 303 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYPEER, 1L), |
| 292 | "CURLOPT_SSL_VERIFYPEER"); | 304 | "CURLOPT_SSL_VERIFYPEER"); |
| 293 | handle_curl_option_return_code( | 305 | handle_curl_option_return_code( |
| 294 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYHOST, 2), | 306 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYHOST, 2L), |
| 295 | "CURLOPT_SSL_VERIFYHOST"); | 307 | "CURLOPT_SSL_VERIFYHOST"); |
| 296 | } else { | 308 | } else { |
| 297 | /* backward-compatible behaviour, be tolerant in checks | 309 | /* backward-compatible behaviour, be tolerant in checks |
| @@ -299,10 +311,10 @@ check_curl_configure_curl(const check_curl_static_curl_config config, | |||
| 299 | * to be less tolerant about ssl verfications | 311 | * to be less tolerant about ssl verfications |
| 300 | */ | 312 | */ |
| 301 | handle_curl_option_return_code( | 313 | handle_curl_option_return_code( |
| 302 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYPEER, 0), | 314 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYPEER, 0L), |
| 303 | "CURLOPT_SSL_VERIFYPEER"); | 315 | "CURLOPT_SSL_VERIFYPEER"); |
| 304 | handle_curl_option_return_code( | 316 | handle_curl_option_return_code( |
| 305 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYHOST, 0), | 317 | curl_easy_setopt(result.curl_state.curl, CURLOPT_SSL_VERIFYHOST, 0L), |
| 306 | "CURLOPT_SSL_VERIFYHOST"); | 318 | "CURLOPT_SSL_VERIFYHOST"); |
| 307 | } | 319 | } |
| 308 | 320 | ||
| @@ -426,7 +438,7 @@ check_curl_configure_curl(const check_curl_static_curl_config config, | |||
| 426 | if (on_redirect_dependent) { | 438 | if (on_redirect_dependent) { |
| 427 | if (follow_method == FOLLOW_LIBCURL) { | 439 | if (follow_method == FOLLOW_LIBCURL) { |
| 428 | handle_curl_option_return_code( | 440 | handle_curl_option_return_code( |
| 429 | curl_easy_setopt(result.curl_state.curl, CURLOPT_FOLLOWLOCATION, 1), | 441 | curl_easy_setopt(result.curl_state.curl, CURLOPT_FOLLOWLOCATION, 1L), |
| 430 | "CURLOPT_FOLLOWLOCATION"); | 442 | "CURLOPT_FOLLOWLOCATION"); |
| 431 | 443 | ||
| 432 | /* default -1 is infinite, not good, could lead to zombie plugins! | 444 | /* default -1 is infinite, not good, could lead to zombie plugins! |
| @@ -462,7 +474,7 @@ check_curl_configure_curl(const check_curl_static_curl_config config, | |||
| 462 | } | 474 | } |
| 463 | /* no-body */ | 475 | /* no-body */ |
| 464 | if (working_state.no_body) { | 476 | if (working_state.no_body) { |
| 465 | handle_curl_option_return_code(curl_easy_setopt(result.curl_state.curl, CURLOPT_NOBODY, 1), | 477 | handle_curl_option_return_code(curl_easy_setopt(result.curl_state.curl, CURLOPT_NOBODY, 1L), |
| 466 | "CURLOPT_NOBODY"); | 478 | "CURLOPT_NOBODY"); |
| 467 | } | 479 | } |
| 468 | 480 | ||
| @@ -784,15 +796,17 @@ mp_subcheck check_document_dates(const curlhelp_write_curlbuf *header_buf, const | |||
| 784 | ((float)last_modified) / (60 * 60 * 24)); | 796 | ((float)last_modified) / (60 * 60 * 24)); |
| 785 | sc_document_dates = mp_set_subcheck_state(sc_document_dates, STATE_CRITICAL); | 797 | sc_document_dates = mp_set_subcheck_state(sc_document_dates, STATE_CRITICAL); |
| 786 | } else { | 798 | } else { |
| 787 | xasprintf(&sc_document_dates.output, _("Last modified %ld:%02ld:%02ld ago"), | 799 | xasprintf(&sc_document_dates.output, _("Last modified %lld:%02d:%02d ago"), |
| 788 | last_modified / (60 * 60), (last_modified / 60) % 60, last_modified % 60); | 800 | (long long)last_modified / (60 * 60), (int)(last_modified / 60) % 60, |
| 801 | (int)last_modified % 60); | ||
| 789 | sc_document_dates = mp_set_subcheck_state(sc_document_dates, STATE_CRITICAL); | 802 | sc_document_dates = mp_set_subcheck_state(sc_document_dates, STATE_CRITICAL); |
| 790 | } | 803 | } |
| 791 | } else { | 804 | } else { |
| 792 | // TODO is this the OK case? | 805 | // TODO is this the OK case? |
| 793 | time_t last_modified = (srv_data - doc_data); | 806 | time_t last_modified = (srv_data - doc_data); |
| 794 | xasprintf(&sc_document_dates.output, _("Last modified %ld:%02ld:%02ld ago"), | 807 | xasprintf(&sc_document_dates.output, _("Last modified %lld:%02d:%02d ago"), |
| 795 | last_modified / (60 * 60), (last_modified / 60) % 60, last_modified % 60); | 808 | (long long)last_modified / (60 * 60), (int)(last_modified / 60) % 60, |
| 809 | (int)last_modified % 60); | ||
| 796 | sc_document_dates = mp_set_subcheck_state(sc_document_dates, STATE_OK); | 810 | sc_document_dates = mp_set_subcheck_state(sc_document_dates, STATE_OK); |
| 797 | } | 811 | } |
| 798 | } | 812 | } |
