diff options
Diffstat (limited to 'plugins/check_curl.c')
| -rw-r--r-- | plugins/check_curl.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index e7737c7c..95e45282 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -120,6 +120,14 @@ mp_state_enum np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_ | |||
| 120 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | 120 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ |
| 121 | 121 | ||
| 122 | int main(int argc, char **argv) { | 122 | int main(int argc, char **argv) { |
| 123 | #ifdef __OpenBSD__ | ||
| 124 | /* - rpath is required to read --extra-opts, CA and/or client certs | ||
| 125 | * - wpath is required to write --cookie-jar (possibly given up later) | ||
| 126 | * - inet is required for sockets | ||
| 127 | * - dns is required for name lookups */ | ||
| 128 | pledge("stdio rpath wpath inet dns", NULL); | ||
| 129 | #endif // __OpenBSD__ | ||
| 130 | |||
| 123 | setlocale(LC_ALL, ""); | 131 | setlocale(LC_ALL, ""); |
| 124 | bindtextdomain(PACKAGE, LOCALEDIR); | 132 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 125 | textdomain(PACKAGE); | 133 | textdomain(PACKAGE); |
| @@ -135,6 +143,15 @@ int main(int argc, char **argv) { | |||
| 135 | 143 | ||
| 136 | const check_curl_config config = tmp_config.config; | 144 | const check_curl_config config = tmp_config.config; |
| 137 | 145 | ||
| 146 | #ifdef __OpenBSD__ | ||
| 147 | if (!config.curl_config.cookie_jar_file) { | ||
| 148 | if (verbose >= 2) { | ||
| 149 | printf(_("* No \"--cookie-jar\" is used, giving up \"wpath\" pledge(2)\n")); | ||
| 150 | } | ||
| 151 | pledge("stdio rpath inet dns", NULL); | ||
| 152 | } | ||
| 153 | #endif // __OpenBSD__ | ||
| 154 | |||
| 138 | if (config.output_format_is_set) { | 155 | if (config.output_format_is_set) { |
| 139 | mp_set_format(config.output_format); | 156 | mp_set_format(config.output_format); |
| 140 | } | 157 | } |
| @@ -775,19 +792,23 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config | |||
| 775 | /* missing components have null,null in their UriTextRangeA | 792 | /* missing components have null,null in their UriTextRangeA |
| 776 | * add query parameters if they exist. | 793 | * add query parameters if they exist. |
| 777 | */ | 794 | */ |
| 778 | if (uri.query.first && uri.query.afterLast){ | 795 | if (uri.query.first && uri.query.afterLast) { |
| 779 | // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat twice | 796 | // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat |
| 797 | // twice | ||
| 780 | size_t current_len = strlen(new_url); | 798 | size_t current_len = strlen(new_url); |
| 781 | size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1; | 799 | size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1; |
| 782 | 800 | ||
| 783 | const char* query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE); | 801 | const char *query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE); |
| 784 | size_t query_str_len = strlen(query_str); | 802 | size_t query_str_len = strlen(query_str); |
| 785 | 803 | ||
| 786 | if (remaining_space >= query_str_len + 1) { | 804 | if (remaining_space >= query_str_len + 1) { |
| 787 | strcat(new_url, "?"); | 805 | strcat(new_url, "?"); |
| 788 | strcat(new_url, query_str); | 806 | strcat(new_url, query_str); |
| 789 | }else{ | 807 | } else { |
| 790 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - No space to add query part of size %d to the buffer, buffer has remaining size %d"), query_str_len , current_len ); | 808 | die(STATE_UNKNOWN, |
| 809 | _("HTTP UNKNOWN - No space to add query part of size %zu to the buffer, buffer has " | ||
| 810 | "remaining size %zu"), | ||
| 811 | query_str_len, current_len); | ||
| 791 | } | 812 | } |
| 792 | } | 813 | } |
| 793 | 814 | ||
| @@ -1244,7 +1265,7 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { | |||
| 1244 | result.config.curl_config.sin_family = AF_INET; | 1265 | result.config.curl_config.sin_family = AF_INET; |
| 1245 | break; | 1266 | break; |
| 1246 | case '6': | 1267 | case '6': |
| 1247 | #if defined(USE_IPV6) && defined(LIBCURL_FEATURE_IPV6) | 1268 | #if defined(LIBCURL_FEATURE_IPV6) |
| 1248 | result.config.curl_config.sin_family = AF_INET6; | 1269 | result.config.curl_config.sin_family = AF_INET6; |
| 1249 | #else | 1270 | #else |
| 1250 | usage4(_("IPv6 support not available")); | 1271 | usage4(_("IPv6 support not available")); |
| @@ -1501,8 +1522,8 @@ void print_help(void) { | |||
| 1501 | printf(" %s\n", "-I, --IP-address=ADDRESS"); | 1522 | printf(" %s\n", "-I, --IP-address=ADDRESS"); |
| 1502 | printf(" %s\n", | 1523 | printf(" %s\n", |
| 1503 | "IP address or name (use numeric address if possible to bypass DNS lookup)."); | 1524 | "IP address or name (use numeric address if possible to bypass DNS lookup)."); |
| 1504 | printf(" %s\n", | 1525 | printf(" %s\n", "This overwrites the network address of the target while leaving everything " |
| 1505 | "This overwrites the network address of the target while leaving everything else (HTTP headers) as they are"); | 1526 | "else (HTTP headers) as they are"); |
| 1506 | printf(" %s\n", "-p, --port=INTEGER"); | 1527 | printf(" %s\n", "-p, --port=INTEGER"); |
| 1507 | printf(" %s", _("Port number (default: ")); | 1528 | printf(" %s", _("Port number (default: ")); |
| 1508 | printf("%d)\n", HTTP_PORT); | 1529 | printf("%d)\n", HTTP_PORT); |
| @@ -1566,7 +1587,8 @@ void print_help(void) { | |||
| 1566 | printf(" %s\n", _("String to expect in the content")); | 1587 | printf(" %s\n", _("String to expect in the content")); |
| 1567 | printf(" %s\n", "-u, --url=PATH"); | 1588 | printf(" %s\n", "-u, --url=PATH"); |
| 1568 | printf(" %s\n", _("URL to GET or POST (default: /)")); | 1589 | printf(" %s\n", _("URL to GET or POST (default: /)")); |
| 1569 | printf(" %s\n", _("This is the part after the address in a URL, so for \"https://example.com/index.html\" it would be '-u /index.html'")); | 1590 | printf(" %s\n", _("This is the part after the address in a URL, so for " |
| 1591 | "\"https://example.com/index.html\" it would be '-u /index.html'")); | ||
| 1570 | printf(" %s\n", "-P, --post=STRING"); | 1592 | printf(" %s\n", "-P, --post=STRING"); |
| 1571 | printf(" %s\n", _("URL decoded http POST data")); | 1593 | printf(" %s\n", _("URL decoded http POST data")); |
| 1572 | printf(" %s\n", | 1594 | printf(" %s\n", |
| @@ -1712,7 +1734,8 @@ void print_help(void) { | |||
| 1712 | printf(" %s\n", _("It is recommended to use an environment proxy like:")); | 1734 | printf(" %s\n", _("It is recommended to use an environment proxy like:")); |
| 1713 | printf(" %s\n", | 1735 | printf(" %s\n", |
| 1714 | _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S")); | 1736 | _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S")); |
| 1715 | printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned upon, so DONT:")); | 1737 | printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned " |
| 1738 | "upon, so DONT:")); | ||
| 1716 | printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j " | 1739 | printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j " |
| 1717 | "CONNECT -H www.verisign.com ")); | 1740 | "CONNECT -H www.verisign.com ")); |
| 1718 | printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> " | 1741 | printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> " |
