summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c252
1 files changed, 159 insertions, 93 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index c6593df1..e5be1ad5 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -37,6 +37,7 @@ const char *progname = "check_curl";
37const char *copyright = "2006-2019"; 37const char *copyright = "2006-2019";
38const char *email = "devel@monitoring-plugins.org"; 38const char *email = "devel@monitoring-plugins.org";
39 39
40#include <stdbool.h>
40#include <ctype.h> 41#include <ctype.h>
41 42
42#include "common.h" 43#include "common.h"
@@ -131,14 +132,14 @@ regmatch_t pmatch[REGS];
131char regexp[MAX_RE_SIZE]; 132char regexp[MAX_RE_SIZE];
132int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; 133int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE;
133int errcode; 134int errcode;
134int invert_regex = 0; 135bool invert_regex = false;
135 136
136char *server_address = NULL; 137char *server_address = NULL;
137char *host_name = NULL; 138char *host_name = NULL;
138char *server_url = 0; 139char *server_url = 0;
139char server_ip[DEFAULT_BUFFER_SIZE]; 140char server_ip[DEFAULT_BUFFER_SIZE];
140struct curl_slist *server_ips = NULL; 141struct curl_slist *server_ips = NULL;
141int specify_port = FALSE; 142bool specify_port = false;
142unsigned short server_port = HTTP_PORT; 143unsigned short server_port = HTTP_PORT;
143unsigned short virtual_port = 0; 144unsigned short virtual_port = 0;
144int host_name_length; 145int host_name_length;
@@ -150,8 +151,8 @@ int days_till_exp_warn, days_till_exp_crit;
150thresholds *thlds; 151thresholds *thlds;
151char user_agent[DEFAULT_BUFFER_SIZE]; 152char user_agent[DEFAULT_BUFFER_SIZE];
152int verbose = 0; 153int verbose = 0;
153int show_extended_perfdata = FALSE; 154bool show_extended_perfdata = false;
154int show_body = FALSE; 155bool show_body = false;
155int min_page_len = 0; 156int min_page_len = 0;
156int max_page_len = 0; 157int max_page_len = 0;
157int redir_depth = 0; 158int redir_depth = 0;
@@ -160,10 +161,16 @@ char *http_method = NULL;
160char *http_post_data = NULL; 161char *http_post_data = NULL;
161char *http_content_type = NULL; 162char *http_content_type = NULL;
162CURL *curl; 163CURL *curl;
164bool curl_global_initialized = false;
165bool curl_easy_initialized = false;
163struct curl_slist *header_list = NULL; 166struct curl_slist *header_list = NULL;
167bool body_buf_initialized = false;
164curlhelp_write_curlbuf body_buf; 168curlhelp_write_curlbuf body_buf;
169bool header_buf_initialized = false;
165curlhelp_write_curlbuf header_buf; 170curlhelp_write_curlbuf header_buf;
171bool status_line_initialized = false;
166curlhelp_statusline status_line; 172curlhelp_statusline status_line;
173bool put_buf_initialized = false;
167curlhelp_read_curlbuf put_buf; 174curlhelp_read_curlbuf put_buf;
168char http_header[DEFAULT_BUFFER_SIZE]; 175char http_header[DEFAULT_BUFFER_SIZE];
169long code; 176long code;
@@ -173,7 +180,7 @@ double time_connect;
173double time_appconnect; 180double time_appconnect;
174double time_headers; 181double time_headers;
175double time_firstbyte; 182double time_firstbyte;
176char errbuf[CURL_ERROR_SIZE+1]; 183char errbuf[MAX_INPUT_BUFFER];
177CURLcode res; 184CURLcode res;
178char url[DEFAULT_BUFFER_SIZE]; 185char url[DEFAULT_BUFFER_SIZE];
179char msg[DEFAULT_BUFFER_SIZE]; 186char msg[DEFAULT_BUFFER_SIZE];
@@ -186,14 +193,14 @@ char user_auth[MAX_INPUT_BUFFER] = "";
186char proxy_auth[MAX_INPUT_BUFFER] = ""; 193char proxy_auth[MAX_INPUT_BUFFER] = "";
187char **http_opt_headers; 194char **http_opt_headers;
188int http_opt_headers_count = 0; 195int http_opt_headers_count = 0;
189int display_html = FALSE; 196bool display_html = false;
190int onredirect = STATE_OK; 197int onredirect = STATE_OK;
191int followmethod = FOLLOW_HTTP_CURL; 198int followmethod = FOLLOW_HTTP_CURL;
192int followsticky = STICKY_NONE; 199int followsticky = STICKY_NONE;
193int use_ssl = FALSE; 200bool use_ssl = false;
194int use_sni = TRUE; 201bool use_sni = true;
195int check_cert = FALSE; 202bool check_cert = false;
196int continue_after_check_cert = FALSE; 203bool continue_after_check_cert = false;
197typedef union { 204typedef union {
198 struct curl_slist* to_info; 205 struct curl_slist* to_info;
199 struct curl_certinfo* to_certinfo; 206 struct curl_certinfo* to_certinfo;
@@ -203,19 +210,20 @@ int ssl_version = CURL_SSLVERSION_DEFAULT;
203char *client_cert = NULL; 210char *client_cert = NULL;
204char *client_privkey = NULL; 211char *client_privkey = NULL;
205char *ca_cert = NULL; 212char *ca_cert = NULL;
206int verify_peer_and_host = FALSE; 213bool verify_peer_and_host = false;
207int is_openssl_callback = FALSE; 214bool is_openssl_callback = false;
208#if defined(HAVE_SSL) && defined(USE_OPENSSL) 215#if defined(HAVE_SSL) && defined(USE_OPENSSL)
209X509 *cert = NULL; 216X509 *cert = NULL;
210#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ 217#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */
211int no_body = FALSE; 218bool no_body = false;
212int maximum_age = -1; 219int maximum_age = -1;
213int address_family = AF_UNSPEC; 220int address_family = AF_UNSPEC;
214curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; 221curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
215int curl_http_version = CURL_HTTP_VERSION_NONE; 222int curl_http_version = CURL_HTTP_VERSION_NONE;
216int automatic_decompression = FALSE; 223bool automatic_decompression = false;
224char *cookie_jar_file = NULL;
217 225
218int process_arguments (int, char**); 226bool process_arguments (int, char**);
219void handle_curl_option_return_code (CURLcode res, const char* option); 227void handle_curl_option_return_code (CURLcode res, const char* option);
220int check_http (void); 228int check_http (void);
221void redir (curlhelp_write_curlbuf*); 229void redir (curlhelp_write_curlbuf*);
@@ -269,10 +277,10 @@ main (int argc, char **argv)
269 progname, NP_VERSION, VERSION, curl_version()); 277 progname, NP_VERSION, VERSION, curl_version());
270 278
271 /* parse arguments */ 279 /* parse arguments */
272 if (process_arguments (argc, argv) == ERROR) 280 if (process_arguments (argc, argv) == false)
273 usage4 (_("Could not parse arguments")); 281 usage4 (_("Could not parse arguments"));
274 282
275 if (display_html == TRUE) 283 if (display_html)
276 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", 284 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
277 use_ssl ? "https" : "http", 285 use_ssl ? "https" : "http",
278 host_name ? host_name : server_address, 286 host_name ? host_name : server_address,
@@ -376,8 +384,11 @@ int
376lookup_host (const char *host, char *buf, size_t buflen) 384lookup_host (const char *host, char *buf, size_t buflen)
377{ 385{
378 struct addrinfo hints, *res, *result; 386 struct addrinfo hints, *res, *result;
387 char addrstr[100];
388 size_t addrstr_len;
379 int errcode; 389 int errcode;
380 void *ptr; 390 void *ptr;
391 size_t buflen_remaining = buflen - 1;
381 392
382 memset (&hints, 0, sizeof (hints)); 393 memset (&hints, 0, sizeof (hints));
383 hints.ai_family = address_family; 394 hints.ai_family = address_family;
@@ -387,31 +398,62 @@ lookup_host (const char *host, char *buf, size_t buflen)
387 errcode = getaddrinfo (host, NULL, &hints, &result); 398 errcode = getaddrinfo (host, NULL, &hints, &result);
388 if (errcode != 0) 399 if (errcode != 0)
389 return errcode; 400 return errcode;
390 401
402 strcpy(buf, "");
391 res = result; 403 res = result;
392 404
393 while (res) { 405 while (res) {
394 inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); 406 switch (res->ai_family) {
395 switch (res->ai_family) { 407 case AF_INET:
396 case AF_INET: 408 ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
397 ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; 409 break;
398 break; 410 case AF_INET6:
399 case AF_INET6: 411 ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
400 ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; 412 break;
401 break;
402 } 413 }
403 inet_ntop (res->ai_family, ptr, buf, buflen); 414
404 if (verbose >= 1) 415 inet_ntop (res->ai_family, ptr, addrstr, 100);
416 if (verbose >= 1) {
405 printf ("* getaddrinfo IPv%d address: %s\n", 417 printf ("* getaddrinfo IPv%d address: %s\n",
406 res->ai_family == PF_INET6 ? 6 : 4, buf); 418 res->ai_family == PF_INET6 ? 6 : 4, addrstr);
419 }
420
421 // Append all IPs to buf as a comma-separated string
422 addrstr_len = strlen(addrstr);
423 if (buflen_remaining > addrstr_len + 1) {
424 if (buf[0] != '\0') {
425 strncat(buf, ",", buflen_remaining);
426 buflen_remaining -= 1;
427 }
428 strncat(buf, addrstr, buflen_remaining);
429 buflen_remaining -= addrstr_len;
430 }
431
407 res = res->ai_next; 432 res = res->ai_next;
408 } 433 }
409 434
410 freeaddrinfo(result); 435 freeaddrinfo(result);
411 436
412 return 0; 437 return 0;
413} 438}
414 439
440static void
441cleanup (void)
442{
443 if (status_line_initialized) curlhelp_free_statusline(&status_line);
444 status_line_initialized = false;
445 if (curl_easy_initialized) curl_easy_cleanup (curl);
446 curl_easy_initialized = false;
447 if (curl_global_initialized) curl_global_cleanup ();
448 curl_global_initialized = false;
449 if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf);
450 body_buf_initialized = false;
451 if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf);
452 header_buf_initialized = false;
453 if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf);
454 put_buf_initialized = false;
455}
456
415int 457int
416check_http (void) 458check_http (void)
417{ 459{
@@ -420,18 +462,24 @@ check_http (void)
420 int i; 462 int i;
421 char *force_host_header = NULL; 463 char *force_host_header = NULL;
422 struct curl_slist *host = NULL; 464 struct curl_slist *host = NULL;
423 char addrstr[100]; 465 char addrstr[DEFAULT_BUFFER_SIZE/2];
424 char dnscache[DEFAULT_BUFFER_SIZE]; 466 char dnscache[DEFAULT_BUFFER_SIZE];
425 467
426 /* initialize curl */ 468 /* initialize curl */
427 if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) 469 if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK)
428 die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); 470 die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n");
471 curl_global_initialized = true;
429 472
430 if ((curl = curl_easy_init()) == NULL) 473 if ((curl = curl_easy_init()) == NULL) {
431 die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); 474 die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n");
475 }
476 curl_easy_initialized = true;
432 477
478 /* register cleanup function to shut down libcurl properly */
479 atexit (cleanup);
480
433 if (verbose >= 1) 481 if (verbose >= 1)
434 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, TRUE), "CURLOPT_VERBOSE"); 482 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, 1), "CURLOPT_VERBOSE");
435 483
436 /* print everything on stdout like check_http would do */ 484 /* print everything on stdout like check_http would do */
437 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); 485 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR");
@@ -446,12 +494,14 @@ check_http (void)
446 /* initialize buffer for body of the answer */ 494 /* initialize buffer for body of the answer */
447 if (curlhelp_initwritebuffer(&body_buf) < 0) 495 if (curlhelp_initwritebuffer(&body_buf) < 0)
448 die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); 496 die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n");
497 body_buf_initialized = true;
449 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION"); 498 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION");
450 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA"); 499 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA");
451 500
452 /* initialize buffer for header of the answer */ 501 /* initialize buffer for header of the answer */
453 if (curlhelp_initwritebuffer( &header_buf ) < 0) 502 if (curlhelp_initwritebuffer( &header_buf ) < 0)
454 die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); 503 die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" );
504 header_buf_initialized = true;
455 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION"); 505 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION");
456 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER"); 506 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER");
457 507
@@ -464,7 +514,7 @@ check_http (void)
464 514
465 // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy 515 // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy
466 if(use_ssl && host_name != NULL) { 516 if(use_ssl && host_name != NULL) {
467 if ( (res=lookup_host (server_address, addrstr, 100)) != 0) { 517 if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) {
468 snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), 518 snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"),
469 server_address, res, gai_strerror (res)); 519 server_address, res, gai_strerror (res));
470 die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); 520 die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
@@ -512,7 +562,7 @@ check_http (void)
512 562
513 /* disable body for HEAD request */ 563 /* disable body for HEAD request */
514 if (http_method && !strcmp (http_method, "HEAD" )) { 564 if (http_method && !strcmp (http_method, "HEAD" )) {
515 no_body = TRUE; 565 no_body = true;
516 } 566 }
517 567
518 /* set HTTP protocol version */ 568 /* set HTTP protocol version */
@@ -609,7 +659,7 @@ check_http (void)
609#ifdef USE_OPENSSL 659#ifdef USE_OPENSSL
610 /* libcurl and monitoring plugins built with OpenSSL, good */ 660 /* libcurl and monitoring plugins built with OpenSSL, good */
611 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); 661 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION");
612 is_openssl_callback = TRUE; 662 is_openssl_callback = true;
613#else /* USE_OPENSSL */ 663#else /* USE_OPENSSL */
614#endif /* USE_OPENSSL */ 664#endif /* USE_OPENSSL */
615 /* libcurl is built with OpenSSL, monitoring plugins, so falling 665 /* libcurl is built with OpenSSL, monitoring plugins, so falling
@@ -688,9 +738,11 @@ check_http (void)
688 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); 738 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS");
689 739
690 /* for now allow only http and https (we are a http(s) check plugin in the end) */ 740 /* for now allow only http and https (we are a http(s) check plugin in the end) */
691#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) 741#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 0)
742 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https"), "CURLOPT_REDIR_PROTOCOLS_STR");
743#elif LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4)
692 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS"); 744 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS");
693#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) */ 745#endif
694 746
695 /* TODO: handle the following aspects of redirection, make them 747 /* TODO: handle the following aspects of redirection, make them
696 * command line options too later: 748 * command line options too later:
@@ -734,11 +786,19 @@ check_http (void)
734 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); 786 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS");
735 } else if (!strcmp(http_method, "PUT")) { 787 } else if (!strcmp(http_method, "PUT")) {
736 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION"); 788 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION");
737 curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)); 789 if (curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)) < 0)
790 die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating read buffer for PUT\n");
791 put_buf_initialized = true;
738 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA"); 792 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA");
739 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); 793 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE");
740 } 794 }
741 } 795 }
796
797 /* cookie handling */
798 if (cookie_jar_file != NULL) {
799 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR");
800 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE");
801 }
742 802
743 /* do the request */ 803 /* do the request */
744 res = curl_easy_perform(curl); 804 res = curl_easy_perform(curl);
@@ -749,6 +809,9 @@ check_http (void)
749 /* free header and server IP resolve lists, we don't need it anymore */ 809 /* free header and server IP resolve lists, we don't need it anymore */
750 curl_slist_free_all (header_list); header_list = NULL; 810 curl_slist_free_all (header_list); header_list = NULL;
751 curl_slist_free_all (server_ips); server_ips = NULL; 811 curl_slist_free_all (server_ips); server_ips = NULL;
812 if (host) {
813 curl_slist_free_all (host); host = NULL;
814 }
752 815
753 /* Curl errors, result in critical Nagios state */ 816 /* Curl errors, result in critical Nagios state */
754 if (res != CURLE_OK) { 817 if (res != CURLE_OK) {
@@ -759,15 +822,15 @@ check_http (void)
759 822
760 /* certificate checks */ 823 /* certificate checks */
761#ifdef LIBCURL_FEATURE_SSL 824#ifdef LIBCURL_FEATURE_SSL
762 if (use_ssl == TRUE) { 825 if (use_ssl) {
763 if (check_cert == TRUE) { 826 if (check_cert) {
764 if (is_openssl_callback) { 827 if (is_openssl_callback) {
765#ifdef USE_OPENSSL 828#ifdef USE_OPENSSL
766 /* check certificate with OpenSSL functions, curl has been built against OpenSSL 829 /* check certificate with OpenSSL functions, curl has been built against OpenSSL
767 * and we actually have OpenSSL in the monitoring tools 830 * and we actually have OpenSSL in the monitoring tools
768 */ 831 */
769 result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); 832 result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit);
770 if (continue_after_check_cert == FALSE) { 833 if (!continue_after_check_cert) {
771 return result; 834 return result;
772 } 835 }
773#else /* USE_OPENSSL */ 836#else /* USE_OPENSSL */
@@ -809,7 +872,7 @@ GOT_FIRST_CERT:
809 } 872 }
810 BIO_free (cert_BIO); 873 BIO_free (cert_BIO);
811 result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); 874 result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit);
812 if (continue_after_check_cert == FALSE) { 875 if (!continue_after_check_cert) {
813 return result; 876 return result;
814 } 877 }
815#else /* USE_OPENSSL */ 878#else /* USE_OPENSSL */
@@ -817,7 +880,7 @@ GOT_FIRST_CERT:
817 * so we use the libcurl CURLINFO data 880 * so we use the libcurl CURLINFO data
818 */ 881 */
819 result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); 882 result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit);
820 if (continue_after_check_cert == FALSE) { 883 if (!continue_after_check_cert) {
821 return result; 884 return result;
822 } 885 }
823#endif /* USE_OPENSSL */ 886#endif /* USE_OPENSSL */
@@ -845,7 +908,7 @@ GOT_FIRST_CERT:
845 perfd_time(total_time), 908 perfd_time(total_time),
846 perfd_size(page_len), 909 perfd_size(page_len),
847 perfd_time_connect(time_connect), 910 perfd_time_connect(time_connect),
848 use_ssl == TRUE ? perfd_time_ssl (time_appconnect-time_connect) : "", 911 use_ssl ? perfd_time_ssl (time_appconnect-time_connect) : "",
849 perfd_time_headers(time_headers - time_appconnect), 912 perfd_time_headers(time_headers - time_appconnect),
850 perfd_time_firstbyte(time_firstbyte - time_headers), 913 perfd_time_firstbyte(time_firstbyte - time_headers),
851 perfd_time_transfer(total_time-time_firstbyte) 914 perfd_time_transfer(total_time-time_firstbyte)
@@ -868,6 +931,7 @@ GOT_FIRST_CERT:
868 /* we cannot know the major/minor version here for sure as we cannot parse the first line */ 931 /* we cannot know the major/minor version here for sure as we cannot parse the first line */
869 die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); 932 die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg);
870 } 933 }
934 status_line_initialized = true;
871 935
872 /* get result code from cURL */ 936 /* get result code from cURL */
873 handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); 937 handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE");
@@ -980,12 +1044,12 @@ GOT_FIRST_CERT:
980 1044
981 if (strlen (regexp)) { 1045 if (strlen (regexp)) {
982 errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); 1046 errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0);
983 if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) { 1047 if ((errcode == 0 && !invert_regex) || (errcode == REG_NOMATCH && invert_regex)) {
984 /* OK - No-op to avoid changing the logic around it */ 1048 /* OK - No-op to avoid changing the logic around it */
985 result = max_state_alt(STATE_OK, result); 1049 result = max_state_alt(STATE_OK, result);
986 } 1050 }
987 else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { 1051 else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) {
988 if (invert_regex == 0) 1052 if (!invert_regex)
989 snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); 1053 snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg);
990 else 1054 else
991 snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); 1055 snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg);
@@ -1017,7 +1081,7 @@ GOT_FIRST_CERT:
1017 else 1081 else
1018 msg[strlen(msg)-3] = '\0'; 1082 msg[strlen(msg)-3] = '\0';
1019 } 1083 }
1020 1084
1021 /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ 1085 /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */
1022 die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", 1086 die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s",
1023 state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), 1087 state_text(result), string_statuscode (status_line.http_major, status_line.http_minor),
@@ -1029,16 +1093,6 @@ GOT_FIRST_CERT:
1029 (show_body ? body_buf.buf : ""), 1093 (show_body ? body_buf.buf : ""),
1030 (show_body ? "\n" : "") ); 1094 (show_body ? "\n" : "") );
1031 1095
1032 /* proper cleanup after die? */
1033 curlhelp_free_statusline(&status_line);
1034 curl_easy_cleanup (curl);
1035 curl_global_cleanup ();
1036 curlhelp_freewritebuffer (&body_buf);
1037 curlhelp_freewritebuffer (&header_buf);
1038 if (!strcmp (http_method, "PUT")) {
1039 curlhelp_freereadbuffer (&put_buf);
1040 }
1041
1042 return result; 1096 return result;
1043} 1097}
1044 1098
@@ -1134,7 +1188,10 @@ redir (curlhelp_write_curlbuf* header_buf)
1134 } 1188 }
1135 } 1189 }
1136 1190
1137 use_ssl = !uri_strcmp (uri.scheme, "https"); 1191 if (!uri_strcmp (uri.scheme, "https"))
1192 use_ssl = true;
1193 else
1194 use_ssl = false;
1138 1195
1139 /* we do a sloppy test here only, because uriparser would have failed 1196 /* we do a sloppy test here only, because uriparser would have failed
1140 * above, if the port would be invalid, we just check for MAX_PORT 1197 * above, if the port would be invalid, we just check for MAX_PORT
@@ -1209,6 +1266,7 @@ redir (curlhelp_write_curlbuf* header_buf)
1209 * attached to the URL in Location 1266 * attached to the URL in Location
1210 */ 1267 */
1211 1268
1269 cleanup ();
1212 check_http (); 1270 check_http ();
1213} 1271}
1214 1272
@@ -1221,7 +1279,7 @@ test_file (char *path)
1221 usage2 (_("file does not exist or is not readable"), path); 1279 usage2 (_("file does not exist or is not readable"), path);
1222} 1280}
1223 1281
1224int 1282bool
1225process_arguments (int argc, char **argv) 1283process_arguments (int argc, char **argv)
1226{ 1284{
1227 char *p; 1285 char *p;
@@ -1235,7 +1293,8 @@ process_arguments (int argc, char **argv)
1235 CONTINUE_AFTER_CHECK_CERT, 1293 CONTINUE_AFTER_CHECK_CERT,
1236 CA_CERT_OPTION, 1294 CA_CERT_OPTION,
1237 HTTP_VERSION_OPTION, 1295 HTTP_VERSION_OPTION,
1238 AUTOMATIC_DECOMPRESSION 1296 AUTOMATIC_DECOMPRESSION,
1297 COOKIE_JAR
1239 }; 1298 };
1240 1299
1241 int option = 0; 1300 int option = 0;
@@ -1281,11 +1340,12 @@ process_arguments (int argc, char **argv)
1281 {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, 1340 {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION},
1282 {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, 1341 {"http-version", required_argument, 0, HTTP_VERSION_OPTION},
1283 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, 1342 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
1343 {"cookie-jar", required_argument, 0, COOKIE_JAR},
1284 {0, 0, 0, 0} 1344 {0, 0, 0, 0}
1285 }; 1345 };
1286 1346
1287 if (argc < 2) 1347 if (argc < 2)
1288 return ERROR; 1348 return false;
1289 1349
1290 /* support check_http compatible arguments */ 1350 /* support check_http compatible arguments */
1291 for (c = 1; c < argc; c++) { 1351 for (c = 1; c < argc; c++) {
@@ -1365,7 +1425,7 @@ process_arguments (int argc, char **argv)
1365 if( strtol(optarg, NULL, 10) > MAX_PORT) 1425 if( strtol(optarg, NULL, 10) > MAX_PORT)
1366 usage2 (_("Invalid port number, supplied port number is too big"), optarg); 1426 usage2 (_("Invalid port number, supplied port number is too big"), optarg);
1367 server_port = (unsigned short)strtol(optarg, NULL, 10); 1427 server_port = (unsigned short)strtol(optarg, NULL, 10);
1368 specify_port = TRUE; 1428 specify_port = true;
1369 } 1429 }
1370 break; 1430 break;
1371 case 'a': /* authorization info */ 1431 case 'a': /* authorization info */
@@ -1399,10 +1459,10 @@ process_arguments (int argc, char **argv)
1399 http_opt_headers[http_opt_headers_count - 1] = optarg; 1459 http_opt_headers[http_opt_headers_count - 1] = optarg;
1400 break; 1460 break;
1401 case 'L': /* show html link */ 1461 case 'L': /* show html link */
1402 display_html = TRUE; 1462 display_html = true;
1403 break; 1463 break;
1404 case 'n': /* do not show html link */ 1464 case 'n': /* do not show html link */
1405 display_html = FALSE; 1465 display_html = false;
1406 break; 1466 break;
1407 case 'C': /* Check SSL cert validity */ 1467 case 'C': /* Check SSL cert validity */
1408#ifdef LIBCURL_FEATURE_SSL 1468#ifdef LIBCURL_FEATURE_SSL
@@ -1423,12 +1483,12 @@ process_arguments (int argc, char **argv)
1423 usage2 (_("Invalid certificate expiration period"), optarg); 1483 usage2 (_("Invalid certificate expiration period"), optarg);
1424 days_till_exp_warn = atoi (optarg); 1484 days_till_exp_warn = atoi (optarg);
1425 } 1485 }
1426 check_cert = TRUE; 1486 check_cert = true;
1427 goto enable_ssl; 1487 goto enable_ssl;
1428#endif 1488#endif
1429 case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ 1489 case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */
1430#ifdef HAVE_SSL 1490#ifdef HAVE_SSL
1431 continue_after_check_cert = TRUE; 1491 continue_after_check_cert = true;
1432 break; 1492 break;
1433#endif 1493#endif
1434 case 'J': /* use client certificate */ 1494 case 'J': /* use client certificate */
@@ -1451,13 +1511,13 @@ process_arguments (int argc, char **argv)
1451#endif 1511#endif
1452#ifdef LIBCURL_FEATURE_SSL 1512#ifdef LIBCURL_FEATURE_SSL
1453 case 'D': /* verify peer certificate & host */ 1513 case 'D': /* verify peer certificate & host */
1454 verify_peer_and_host = TRUE; 1514 verify_peer_and_host = true;
1455 break; 1515 break;
1456#endif 1516#endif
1457 case 'S': /* use SSL */ 1517 case 'S': /* use SSL */
1458#ifdef LIBCURL_FEATURE_SSL 1518#ifdef LIBCURL_FEATURE_SSL
1459 enable_ssl: 1519 enable_ssl:
1460 use_ssl = TRUE; 1520 use_ssl = true;
1461 /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. 1521 /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default.
1462 * Only set if it's non-zero. This helps when we include multiple 1522 * Only set if it's non-zero. This helps when we include multiple
1463 * parameters, like -S and -C combinations */ 1523 * parameters, like -S and -C combinations */
@@ -1531,15 +1591,15 @@ process_arguments (int argc, char **argv)
1531#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ 1591#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */
1532 if (verbose >= 2) 1592 if (verbose >= 2)
1533 printf(_("* Set SSL/TLS version to %d\n"), ssl_version); 1593 printf(_("* Set SSL/TLS version to %d\n"), ssl_version);
1534 if (specify_port == FALSE) 1594 if (!specify_port)
1535 server_port = HTTPS_PORT; 1595 server_port = HTTPS_PORT;
1536 break; 1596 break;
1537#else /* LIBCURL_FEATURE_SSL */ 1597#else /* LIBCURL_FEATURE_SSL */
1538 /* -C -J and -K fall through to here without SSL */ 1598 /* -C -J and -K fall through to here without SSL */
1539 usage4 (_("Invalid option - SSL is not available")); 1599 usage4 (_("Invalid option - SSL is not available"));
1540 break; 1600 break;
1541 case SNI_OPTION: /* --sni is parsed, but ignored, the default is TRUE with libcurl */ 1601 case SNI_OPTION: /* --sni is parsed, but ignored, the default is true with libcurl */
1542 use_sni = TRUE; 1602 use_sni = true;
1543 break; 1603 break;
1544#endif /* LIBCURL_FEATURE_SSL */ 1604#endif /* LIBCURL_FEATURE_SSL */
1545 case MAX_REDIRS_OPTION: 1605 case MAX_REDIRS_OPTION:
@@ -1600,11 +1660,11 @@ process_arguments (int argc, char **argv)
1600 if (errcode != 0) { 1660 if (errcode != 0) {
1601 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 1661 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
1602 printf (_("Could Not Compile Regular Expression: %s"), errbuf); 1662 printf (_("Could Not Compile Regular Expression: %s"), errbuf);
1603 return ERROR; 1663 return false;
1604 } 1664 }
1605 break; 1665 break;
1606 case INVERT_REGEX: 1666 case INVERT_REGEX:
1607 invert_regex = 1; 1667 invert_regex = true;
1608 break; 1668 break;
1609 case '4': 1669 case '4':
1610 address_family = AF_INET; 1670 address_family = AF_INET;
@@ -1639,7 +1699,7 @@ process_arguments (int argc, char **argv)
1639 break; 1699 break;
1640 } 1700 }
1641 case 'N': /* no-body */ 1701 case 'N': /* no-body */
1642 no_body = TRUE; 1702 no_body = true;
1643 break; 1703 break;
1644 case 'M': /* max-age */ 1704 case 'M': /* max-age */
1645 { 1705 {
@@ -1662,10 +1722,10 @@ process_arguments (int argc, char **argv)
1662 } 1722 }
1663 break; 1723 break;
1664 case 'E': /* show extended perfdata */ 1724 case 'E': /* show extended perfdata */
1665 show_extended_perfdata = TRUE; 1725 show_extended_perfdata = true;
1666 break; 1726 break;
1667 case 'B': /* print body content after status line */ 1727 case 'B': /* print body content after status line */
1668 show_body = TRUE; 1728 show_body = true;
1669 break; 1729 break;
1670 case HTTP_VERSION_OPTION: 1730 case HTTP_VERSION_OPTION:
1671 curl_http_version = CURL_HTTP_VERSION_NONE; 1731 curl_http_version = CURL_HTTP_VERSION_NONE;
@@ -1685,7 +1745,10 @@ process_arguments (int argc, char **argv)
1685 } 1745 }
1686 break; 1746 break;
1687 case AUTOMATIC_DECOMPRESSION: 1747 case AUTOMATIC_DECOMPRESSION:
1688 automatic_decompression = TRUE; 1748 automatic_decompression = true;
1749 break;
1750 case COOKIE_JAR:
1751 cookie_jar_file = optarg;
1689 break; 1752 break;
1690 case '?': 1753 case '?':
1691 /* print short usage statement if args not parsable */ 1754 /* print short usage statement if args not parsable */
@@ -1726,52 +1789,52 @@ process_arguments (int argc, char **argv)
1726 virtual_port = server_port; 1789 virtual_port = server_port;
1727 else { 1790 else {
1728 if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) 1791 if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT))
1729 if(specify_port == FALSE) 1792 if(!specify_port)
1730 server_port = virtual_port; 1793 server_port = virtual_port;
1731 } 1794 }
1732 1795
1733 return TRUE; 1796 return true;
1734} 1797}
1735 1798
1736char *perfd_time (double elapsed_time) 1799char *perfd_time (double elapsed_time)
1737{ 1800{
1738 return fperfdata ("time", elapsed_time, "s", 1801 return fperfdata ("time", elapsed_time, "s",
1739 thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, 1802 thlds->warning?true:false, thlds->warning?thlds->warning->end:0,
1740 thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, 1803 thlds->critical?true:false, thlds->critical?thlds->critical->end:0,
1741 TRUE, 0, TRUE, socket_timeout); 1804 true, 0, true, socket_timeout);
1742} 1805}
1743 1806
1744char *perfd_time_connect (double elapsed_time_connect) 1807char *perfd_time_connect (double elapsed_time_connect)
1745{ 1808{
1746 return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1809 return fperfdata ("time_connect", elapsed_time_connect, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1747} 1810}
1748 1811
1749char *perfd_time_ssl (double elapsed_time_ssl) 1812char *perfd_time_ssl (double elapsed_time_ssl)
1750{ 1813{
1751 return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1814 return fperfdata ("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1752} 1815}
1753 1816
1754char *perfd_time_headers (double elapsed_time_headers) 1817char *perfd_time_headers (double elapsed_time_headers)
1755{ 1818{
1756 return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1819 return fperfdata ("time_headers", elapsed_time_headers, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1757} 1820}
1758 1821
1759char *perfd_time_firstbyte (double elapsed_time_firstbyte) 1822char *perfd_time_firstbyte (double elapsed_time_firstbyte)
1760{ 1823{
1761 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1824 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1762} 1825}
1763 1826
1764char *perfd_time_transfer (double elapsed_time_transfer) 1827char *perfd_time_transfer (double elapsed_time_transfer)
1765{ 1828{
1766 return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1829 return fperfdata ("time_transfer", elapsed_time_transfer, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1767} 1830}
1768 1831
1769char *perfd_size (int page_len) 1832char *perfd_size (int page_len)
1770{ 1833{
1771 return perfdata ("size", page_len, "B", 1834 return perfdata ("size", page_len, "B",
1772 (min_page_len>0?TRUE:FALSE), min_page_len, 1835 (min_page_len>0?true:false), min_page_len,
1773 (min_page_len>0?TRUE:FALSE), 0, 1836 (min_page_len>0?true:false), 0,
1774 TRUE, 0, FALSE, 0); 1837 true, 0, false, 0);
1775} 1838}
1776 1839
1777void 1840void
@@ -1906,6 +1969,8 @@ print_help (void)
1906 printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); 1969 printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)"));
1907 printf (" %s\n", "--enable-automatic-decompression"); 1970 printf (" %s\n", "--enable-automatic-decompression");
1908 printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); 1971 printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING)."));
1972 printf (" %s\n", "---cookie-jar=FILE");
1973 printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested."));
1909 printf ("\n"); 1974 printf ("\n");
1910 1975
1911 printf (UT_WARN_CRIT); 1976 printf (UT_WARN_CRIT);
@@ -1990,7 +2055,8 @@ print_usage (void)
1990 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 2055 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1991 printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); 2056 printf (" [-A string] [-k string] [-S <version>] [--sni]\n");
1992 printf (" [-T <content-type>] [-j method]\n"); 2057 printf (" [-T <content-type>] [-j method]\n");
1993 printf (" [--http-version=<version>]\n"); 2058 printf (" [--http-version=<version>] [--enable-automatic-decompression]\n");
2059 printf (" [--cookie-jar=<cookie jar file>\n");
1994 printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); 2060 printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname);
1995 printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); 2061 printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n");
1996 printf ("\n"); 2062 printf ("\n");