summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.d
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_curl.d')
-rw-r--r--plugins/check_curl.d/check_curl_helpers.c46
-rw-r--r--plugins/check_curl.d/check_curl_helpers.h6
-rw-r--r--plugins/check_curl.d/config.h6
3 files changed, 38 insertions, 20 deletions
diff --git a/plugins/check_curl.d/check_curl_helpers.c b/plugins/check_curl.d/check_curl_helpers.c
index d49d8f07..5af00973 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;
19check_curl_configure_curl_wrapper 19check_curl_configure_curl_wrapper
20check_curl_configure_curl(const check_curl_static_curl_config config, 20check_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 }
@@ -1200,7 +1214,7 @@ mp_subcheck check_curl_certificate_checks(CURL *curl, X509 *cert, int warn_days_
1200 1214
1201 cert_ptr_union cert_ptr = {0}; 1215 cert_ptr_union cert_ptr = {0};
1202 cert_ptr.to_info = NULL; 1216 cert_ptr.to_info = NULL;
1203 CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_info); 1217 CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_certinfo);
1204 if (!res && cert_ptr.to_info) { 1218 if (!res && cert_ptr.to_info) {
1205# ifdef USE_OPENSSL 1219# ifdef USE_OPENSSL
1206 /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert 1220 /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert
diff --git a/plugins/check_curl.d/check_curl_helpers.h b/plugins/check_curl.d/check_curl_helpers.h
index 87e45a9d..e77b763b 100644
--- a/plugins/check_curl.d/check_curl_helpers.h
+++ b/plugins/check_curl.d/check_curl_helpers.h
@@ -7,6 +7,10 @@
7# include <openssl/opensslv.h> 7# include <openssl/opensslv.h>
8#endif 8#endif
9 9
10enum {
11 MAX_IPV4_HOSTLENGTH = 255,
12};
13
10/* for buffers for header and body */ 14/* for buffers for header and body */
11typedef struct { 15typedef struct {
12 size_t buflen; 16 size_t buflen;
@@ -76,7 +80,7 @@ check_curl_configure_curl_wrapper check_curl_configure_curl(check_curl_static_cu
76 check_curl_working_state working_state, 80 check_curl_working_state working_state,
77 bool check_cert, 81 bool check_cert,
78 bool on_redirect_dependent, 82 bool on_redirect_dependent,
79 int follow_method, int max_depth); 83 int follow_method, long max_depth);
80 84
81void handle_curl_option_return_code(CURLcode res, const char *option); 85void handle_curl_option_return_code(CURLcode res, const char *option);
82 86
diff --git a/plugins/check_curl.d/config.h b/plugins/check_curl.d/config.h
index f51b2ee9..61067d46 100644
--- a/plugins/check_curl.d/config.h
+++ b/plugins/check_curl.d/config.h
@@ -57,10 +57,10 @@ typedef struct {
57 bool haproxy_protocol; 57 bool haproxy_protocol;
58 long socket_timeout; 58 long socket_timeout;
59 sa_family_t sin_family; 59 sa_family_t sin_family;
60 int curl_http_version; 60 long curl_http_version;
61 char **http_opt_headers; 61 char **http_opt_headers;
62 size_t http_opt_headers_count; 62 size_t http_opt_headers_count;
63 int ssl_version; 63 long ssl_version;
64 char *client_cert; 64 char *client_cert;
65 char *client_privkey; 65 char *client_privkey;
66 char *ca_cert; 66 char *ca_cert;
@@ -76,7 +76,7 @@ typedef struct {
76 check_curl_working_state initial_config; 76 check_curl_working_state initial_config;
77 77
78 check_curl_static_curl_config curl_config; 78 check_curl_static_curl_config curl_config;
79 int max_depth; 79 long max_depth;
80 int followmethod; 80 int followmethod;
81 int followsticky; 81 int followsticky;
82 82