summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-08-19 11:41:08 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-08-19 11:41:08 (GMT)
commitc8c0e9d9a748618a92404341800432fd84ede7e3 (patch)
tree73e7370613b5df8c338ab8b70eb6752ce600377e /plugins
parent2e3e2a06436c3911905475b943b953b1066d6764 (diff)
downloadmonitoring-plugins-c8c0e9d9a748618a92404341800432fd84ede7e3.tar.gz
*BUGFIX: LWS is not required betwwen "Location:" header field name and field value
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@685 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_http.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 2c13dcd..6d52109 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -304,13 +304,13 @@ process_arguments (int argc, char **argv)
304 break; 304 break;
305 /* Note: H, I, and u must be malloc'd or will fail on redirects */ 305 /* Note: H, I, and u must be malloc'd or will fail on redirects */
306 case 'H': /* Host Name (virtual host) */ 306 case 'H': /* Host Name (virtual host) */
307 host_name = optarg; 307 host_name = strdup (optarg);
308 break; 308 break;
309 case 'I': /* Server IP-address */ 309 case 'I': /* Server IP-address */
310 server_address = optarg; 310 server_address = strdup (optarg);
311 break; 311 break;
312 case 'u': /* URL path */ 312 case 'u': /* URL path */
313 asprintf (&server_url, "%s", optarg); 313 server_url = strdup (optarg);
314 server_url_length = strlen (server_url); 314 server_url_length = strlen (server_url);
315 break; 315 break;
316 case 'p': /* Server port */ 316 case 'p': /* Server port */
@@ -328,7 +328,7 @@ process_arguments (int argc, char **argv)
328 case 'P': /* HTTP POST data in URL encoded format */ 328 case 'P': /* HTTP POST data in URL encoded format */
329 if (http_method || http_post_data) break; 329 if (http_method || http_post_data) break;
330 http_method = strdup("POST"); 330 http_method = strdup("POST");
331 http_post_data = optarg; 331 http_post_data = strdup (optarg);
332 break; 332 break;
333 case 's': /* string or substring */ 333 case 's': /* string or substring */
334 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); 334 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
@@ -387,7 +387,7 @@ process_arguments (int argc, char **argv)
387 server_address = strdup (argv[c++]); 387 server_address = strdup (argv[c++]);
388 388
389 if (host_name == NULL && c < argc) 389 if (host_name == NULL && c < argc)
390 asprintf (&host_name, "%s", argv[c++]); 390 host_name = strdup (argv[c++]);
391 391
392 if (server_address == NULL) { 392 if (server_address == NULL) {
393 if (host_name == NULL) 393 if (host_name == NULL)
@@ -456,11 +456,11 @@ base64 (char *bin, size_t len)
456#define URI_HOST "%[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" 456#define URI_HOST "%[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
457#define URI_PORT ":%[0123456789]" 457#define URI_PORT ":%[0123456789]"
458#define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" 458#define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
459#define HD1 HDR_LOCATION URI_HTTP URI_HOST URI_PORT URI_PATH 459#define HD1 URI_HTTP URI_HOST URI_PORT URI_PATH
460#define HD2 HDR_LOCATION URI_HTTP URI_HOST URI_PATH 460#define HD2 URI_HTTP URI_HOST URI_PATH
461#define HD3 HDR_LOCATION URI_HTTP URI_HOST URI_PORT 461#define HD3 URI_HTTP URI_HOST URI_PORT
462#define HD4 HDR_LOCATION URI_HTTP URI_HOST 462#define HD4 URI_HTTP URI_HOST
463#define HD5 HDR_LOCATION URI_PATH 463#define HD5 URI_PATH
464 464
465int 465int
466check_http (void) 466check_http (void)
@@ -476,6 +476,7 @@ check_http (void)
476 char *buf; 476 char *buf;
477 char *pos; 477 char *pos;
478 char *x; 478 char *x;
479 char xx[2];
479 char *orig_url; 480 char *orig_url;
480 long microsec; 481 long microsec;
481 double elapsed_time; 482 double elapsed_time;
@@ -590,7 +591,7 @@ check_http (void)
590 page = full_page; 591 page = full_page;
591 592
592 if (verbose) 593 if (verbose)
593 printf ("Page is %d characters\n", pagesize); 594 printf ("%s://%s:%d%s is %d characters\n", server_type, server_address, server_port, server_url, pagesize);
594 595
595 /* find status line and null-terminate it */ 596 /* find status line and null-terminate it */
596 status_line = page; 597 status_line = page;
@@ -669,17 +670,27 @@ check_http (void)
669 strstr (status_line, "306")) { 670 strstr (status_line, "306")) {
670 if (onredirect == STATE_DEPENDENT) { 671 if (onredirect == STATE_DEPENDENT) {
671 672
673 server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1);
674 if (server_address == NULL)
675 die (STATE_UNKNOWN,_("ERROR: could not allocate server_address"));
676
672 asprintf (&orig_url, "%s", server_url); 677 asprintf (&orig_url, "%s", server_url);
678 if (strcspn (pos, "\r\n") > (size_t)server_url_length) {
679 server_url = realloc (server_url, strcspn (pos, "\r\n"));
680 if (server_url == NULL)
681 die (STATE_UNKNOWN, _("ERROR: could not allocate server_url"));
682 server_url_length = strcspn (pos, "\r\n");
683 }
684
673 pos = header; 685 pos = header;
674 while (pos) { 686 while (pos) {
675 server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1); 687 if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) > 0) {
676 if (server_address == NULL) 688 pos += i;
677 die (STATE_UNKNOWN,_("ERROR: could not allocate server_address")); 689 pos += strspn (pos, " \t\r\n");
678 if (strcspn (pos, "\r\n") > (size_t)server_url_length) { 690 } else {
679 server_url = realloc (server_url, strcspn (pos, "\r\n")); 691 pos += (size_t) strcspn (pos, "\r\n");
680 if (server_url == NULL) 692 pos += (size_t) strspn (pos, "\r\n");
681 die (STATE_UNKNOWN, _("ERROR: could not allocate server_url")); 693 continue;
682 server_url_length = strcspn (pos, "\r\n");
683 } 694 }
684 /* HDR_LOCATION, URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ 695 /* HDR_LOCATION, URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
685 if (sscanf (pos, HD1, server_type, server_address, server_port_text, server_url) == 4) { 696 if (sscanf (pos, HD1, server_type, server_address, server_port_text, server_url) == 4) {
@@ -723,8 +734,6 @@ check_http (void)
723 } 734 }
724 check_http (); 735 check_http ();
725 } 736 }
726 pos += (size_t) strcspn (pos, "\r\n");
727 pos += (size_t) strspn (pos, "\r\n");
728 } /* end while (pos) */ 737 } /* end while (pos) */
729 printf (_("UNKNOWN - Could not find redirect location - %s%s"), 738 printf (_("UNKNOWN - Could not find redirect location - %s%s"),
730 status_line, (display_html ? "</A>" : "")); 739 status_line, (display_html ? "</A>" : ""));