From 8d978764d17a8472b89a4f47587dc259db39c5f8 Mon Sep 17 00:00:00 2001
From: Karl DeBisschop <kdebisschop@users.sourceforge.net>
Date: Sat, 23 Aug 2003 13:59:36 +0000
Subject: - hacked interim fix to segfault on redirect - for tesing only

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@694 f882894a-f735-0410-b71e-b25c423dba1c
---
 plugins/check_http.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

(limited to 'plugins')

diff --git a/plugins/check_http.c b/plugins/check_http.c
index 3ec9e499..6b952c37 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -90,6 +90,7 @@ char server_type[6] = "http";
 char *server_address;
 char *host_name;
 char *server_url;
+char *user_agent;
 int server_url_length;
 int server_expect_yn = 0;
 char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
@@ -130,6 +131,8 @@ main (int argc, char **argv)
 	/* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
 	server_url = strdup(HTTP_URL);
 	server_url_length = strlen(server_url);
+	asprintf (&user_agent, "User-Agent: check_http/%s (nagios-plugins %s)",
+	          clean_revstring (revision), VERSION);
 
 	if (process_arguments (argc, argv) == ERROR)
 		usage (_("check_http: could not parse arguments\n"));
@@ -472,6 +475,9 @@ check_http (void)
 	int sslerr;
 #endif
 
+	if (verbose)
+		printf ("%s://%s:%d%s [%s]\n", server_type, server_address, server_port, server_url, host_name);
+
 	/* try to connect to the host at the given port number */
 #ifdef HAVE_SSL
 	if (use_ssl == TRUE) {
@@ -497,22 +503,21 @@ check_http (void)
 	}
 #endif
 
-	asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
+	asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent);
 
-	/* optionally send the host header info (not clear if it's usable) */
+	/* optionally send the host header info */
 	if (host_name)
 		asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
 
-	/* send user agent */
-	asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n",
-	          buf, clean_revstring (revision), VERSION);
-
 	/* optionally send the authentication info */
 	if (strlen(user_auth)) {
 		auth = base64 (user_auth, strlen (user_auth));
 		asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
 	}
 
+	if (verbose)
+		printf ("%s://%s:%d%s\n", server_type, server_address, server_port, server_url);
+
 	/* either send http POST data */
 	if (http_post_data) {
 		asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
@@ -524,6 +529,9 @@ check_http (void)
 		asprintf (&buf, "%s%s", buf, CRLF);
 	}
 
+	if (verbose)
+		printf ("%s\n", buf);
+
 #ifdef HAVE_SSL
 	if (use_ssl == TRUE) {
 		if (SSL_write (ssl, buf, (int)strlen(buf)) == -1) {
@@ -617,7 +625,6 @@ check_http (void)
 		die (STATE_CRITICAL, "%s", msg);
 	}
 
-
 	/* Exit here if server_expect was set by user and not default */
 	if ( server_expect_yn  )  {
 		asprintf (&msg, _("HTTP OK: Status line output matched \"%s\"\n"),
@@ -860,9 +867,15 @@ redir (char *pos, char *status_line)
 
 	server_port = i;
 	strcpy (server_type, type);
-	asprintf (&host_name, "%s", addr);
-	asprintf (&server_address, "%s", addr);
-	asprintf (&server_url, "%s", url);
+
+	free (host_name);
+	host_name = strdup (addr);
+
+	free (server_address);
+	server_address = strdup (addr);
+
+	free (server_url);
+	server_url = strdup (url);
 
 	return check_http ();
 }
-- 
cgit v1.2.3-74-g34f1