Просмотр исходного кода

the last round of pedantic compiler warnings

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@676 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop 22 лет назад
Родитель
Сommit
f4f92be60c

+ 4 - 4
plugins/check_by_ssh.c

@@ -169,8 +169,8 @@ process_arguments (int argc, char **argv)
 	int c;
 	char *p1, *p2;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"version", no_argument, 0, 'V'},
 		{"help", no_argument, 0, 'h'},
 		{"verbose", no_argument, 0, 'v'},
@@ -200,8 +200,8 @@ process_arguments (int argc, char **argv)
 			strcpy (argv[c], "-t");
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", long_options,
-									 &option_index);
+		c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", longopts,
+									 &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 4 - 4
plugins/check_dig.c

@@ -160,8 +160,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"query_address", required_argument, 0, 'e'},
 		{"verbose", no_argument, 0, 'v'},
@@ -174,7 +174,7 @@ process_arguments (int argc, char **argv)
 		return ERROR;
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVvt:l:H:", long_options, &option_index);
+		c = getopt_long (argc, argv, "hVvt:l:H:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -300,7 +300,7 @@ print_help (void)
 
 	printf (_(UT_VERBOSE));
 
-	support ();
+	printf (_(UT_SUPPORT));
 }
 
 

+ 6 - 6
plugins/check_disk.c

@@ -237,8 +237,8 @@ process_arguments (int argc, char **argv)
 
 	unsigned long l;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"timeout", required_argument, 0, 't'},
 		{"warning", required_argument, 0, 'w'},
 		{"critical", required_argument, 0, 'c'},
@@ -274,7 +274,7 @@ process_arguments (int argc, char **argv)
 			strcpy (argv[c], "-t");
 
 	while (1) {
-		c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", long_options, &option_index);
+		c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -363,7 +363,7 @@ process_arguments (int argc, char **argv)
 			break;
 		case 'p':									/* select path */
 			se = (struct name_list *) malloc (sizeof (struct name_list));
-			se->name = strdup (optarg);
+			se->name = optarg;
 			se->name_next = NULL;
 			se->w_df = w_df;
 			se->c_df = c_df;
@@ -374,14 +374,14 @@ process_arguments (int argc, char **argv)
 			break;
  		case 'x':									/* exclude path or partition */
 			se = (struct name_list *) malloc (sizeof (struct name_list));
-			se->name = strdup (optarg);
+			se->name = optarg;
 			se->name_next = NULL;
 			*dptail = se;
 			dptail = &se->name_next;
 			break;
 		case 'X':									/* exclude file system type */
 			se = (struct name_list *) malloc (sizeof (struct name_list));
-			se->name = strdup (optarg);
+			se->name = optarg;
 			se->name_next = NULL;
 			*fstail = se;
 			fstail = &se->name_next;

+ 50 - 38
plugins/check_dns.c

@@ -54,47 +54,11 @@ const char *revision = "$Revision$";
 const char *copyright = "2000-2003";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
-void
-print_usage (void)
-{
-	printf (_("\
-Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\
-       %s --help\n\
-       %s --version\n"),
-					progname, progname, progname);
-}
-
-void
-print_help (void)
-{
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_("\
--H, --hostname=HOST\n\
-   The name or address you want to query\n\
--s, --server=HOST\n\
-   Optional DNS server you want to use for the lookup\n\
--a, --expected-address=IP-ADDRESS\n\
-   Optional IP address you expect the DNS server to return\n"));
-
-	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
-
-	printf (_("\n\
-This plugin uses the nslookup program to obtain the IP address\n\
-for the given host/domain query.  A optional DNS server to use may\n\
-be specified.  If no DNS server is specified, the default server(s)\n\
-specified in /etc/resolv.conf will be used.\n"));
-}
-
 int process_arguments (int, char **);
 int validate_arguments (void);
 int error_scan (char *);
+void print_help (void);
+void print_usage (void);
 
 #define ADDRESS_LENGTH 256
 char query_address[ADDRESS_LENGTH] = "";
@@ -421,3 +385,51 @@ validate_arguments ()
 	else
 		return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_("\
+-H, --hostname=HOST\n\
+   The name or address you want to query\n\
+-s, --server=HOST\n\
+   Optional DNS server you want to use for the lookup\n\
+-a, --expected-address=IP-ADDRESS\n\
+   Optional IP address you expect the DNS server to return\n"));
+
+	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+	printf (_("\n\
+This plugin uses the nslookup program to obtain the IP address\n\
+for the given host/domain query.  A optional DNS server to use may\n\
+be specified.  If no DNS server is specified, the default server(s)\n\
+specified in /etc/resolv.conf will be used.\n"));
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("\
+Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\
+       %s --help\n\
+       %s --version\n"),
+					progname, progname, progname);
+}

+ 64 - 51
plugins/check_fping.c

@@ -34,6 +34,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
 #include "popen.h"
+#include "netutils.h"
 #include "utils.h"
 
 #define PACKET_COUNT 1
@@ -44,54 +45,11 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #define PL 0
 #define RTA 1
 
-void
-print_usage (void)
-{
-	printf (_("Usage: %s <host_address>\n"), progname);
-}
-
-void
-print_help (void)
-{
-
-	print_revision (progname, "$Revision$");
-
-	printf (_("\
-Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n\
-This plugin will use the /bin/fping command (from saint) to ping the\n\
-specified host for a fast check if the host is alive. Note that it is\n\
-necessary to set the suid flag on fping.\n\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_("\
- -H, --hostname=HOST\n\
-    Name or IP Address of host to ping (IP Address bypasses name lookup,\n\
-    reducing system load)\n\
- -w, --warning=THRESHOLD\n\
-    warning threshold pair\n\
- -c, --critical=THRESHOLD\n\
-    critical threshold pair\n\
- -b, --bytes=INTEGER\n\
-    Size of ICMP packet (default: %d)\n\
- -n, --number=INTEGER\n\
-    Number of ICMP packets to send (default: %d)\n"),
-	        PACKET_SIZE, PACKET_COUNT);
-
-	printf (_(UT_VERBOSE));
-
-	printf (_("\n\
-THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel\n\
-time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n\
-percentage of packet loss to trigger an alarm state.\n"));
-
-}
-
 int textscan (char *buf);
 int process_arguments (int, char **);
 int get_threshold (char *arg, char *rv[2]);
+void print_help (void);
+void print_usage (void);
 
 char *server_name = NULL;
 int cpl = UNKNOWN_PACKET_LOSS;
@@ -200,11 +158,11 @@ textscan (char *buf)
 		rta = strtod (rtastr, NULL);
 		if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl)
 			status = STATE_CRITICAL;
-		else if (crta != UNKNOWN_TRIP_TIME && rta > crta)
+		else if (crta <= 0 && rta > crta)
 			status = STATE_CRITICAL;
 		else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl)
 			status = STATE_WARNING;
-		else if (wrta != UNKNOWN_TRIP_TIME && rta > wrta)
+		else if (wrta >= 0 && rta > wrta)
 			status = STATE_WARNING;
 		else
 			status = STATE_OK;
@@ -218,7 +176,7 @@ textscan (char *buf)
 		losstr = 1 + strstr (losstr, "/");
 		losstr = 1 + strstr (losstr, "/");
 		loss = strtod (losstr, NULL);
-		if (loss == 100)
+		if (atoi(losstr) == 100)
 			status = STATE_CRITICAL;
 		else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl)
 			status = STATE_CRITICAL;
@@ -248,8 +206,8 @@ process_arguments (int argc, char **argv)
 	int c;
 	char *rv[2];
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"critical", required_argument, 0, 'c'},
 		{"warning", required_argument, 0, 'w'},
@@ -275,7 +233,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", long_options, &option_index);
+		c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;
@@ -389,3 +347,58 @@ get_threshold (char *arg, char *rv[2])
 
 	return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+
+	print_revision (progname, "$Revision$");
+
+	printf (_("\
+Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n\
+This plugin will use the /bin/fping command (from saint) to ping the\n\
+specified host for a fast check if the host is alive. Note that it is\n\
+necessary to set the suid flag on fping.\n\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_("\
+ -H, --hostname=HOST\n\
+    Name or IP Address of host to ping (IP Address bypasses name lookup,\n\
+    reducing system load)\n\
+ -w, --warning=THRESHOLD\n\
+    warning threshold pair\n\
+ -c, --critical=THRESHOLD\n\
+    critical threshold pair\n\
+ -b, --bytes=INTEGER\n\
+    Size of ICMP packet (default: %d)\n\
+ -n, --number=INTEGER\n\
+    Number of ICMP packets to send (default: %d)\n"),
+	        PACKET_SIZE, PACKET_COUNT);
+
+	printf (_(UT_VERBOSE));
+
+	printf (_("\n\
+THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel\n\
+time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n\
+percentage of packet loss to trigger an alarm state.\n"));
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("Usage: %s <host_address>\n"), progname);
+	printf (_(UT_HLP_VRS), progname, progname);
+}

+ 54 - 43
plugins/check_game.c

@@ -25,48 +25,10 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #include "popen.h"
 #include "utils.h"
 
-void
-print_usage (void)
-{
-	printf (_("\
-Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\
-  [-pf ping_field]\n"), progname);
-	printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf (_("This plugin tests %s connections with the specified host."), progname);
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_("\
-<game>        = Game type that is recognised by qstat (without the leading dash)\n\
-<ip_address>  = The IP address of the device you wish to query\n\
- [port]        = Optional port of which to connect\n\
- [game_field]  = Field number in raw qstat output that contains game name\n\
- [map_field]   = Field number in raw qstat output that contains map name\n\
- [ping_field]  = Field number in raw qstat output that contains ping time\n"),
-	        DEFAULT_SOCKET_TIMEOUT);
-
-	printf (_("\n\
-Notes:\n\
-- This plugin uses the 'qstat' command, the popular game server status query tool .\n\
-  If you don't have the package installed, you will need to download it from\n\
-  http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n"));
-
-	printf (_(UT_SUPPORT));
-}
-
 int process_arguments (int, char **);
 int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
 
 #define QSTAT_DATA_DELIMITER 	","
 
@@ -152,7 +114,7 @@ main (int argc, char **argv)
 
 	/* initialize the returned data buffer */
 	for (i = 0; i < QSTAT_MAX_RETURN_ARGS; i++)
-		ret[i] = "";
+		ret[i] = strdup("");
 
 	i = 0;
 	p = (char *) strtok (input_buffer, QSTAT_DATA_DELIMITER);
@@ -253,7 +215,7 @@ process_arguments (int argc, char **argv)
 		case 'H': /* hostname */
 			if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH)
 				die (STATE_UNKNOWN, _("Input buffer overflow\n"));
-			server_ip = strdup (optarg);
+			server_ip = optarg;
 			break;
 		case 'P': /* port */
 			port = atoi (optarg);
@@ -261,7 +223,7 @@ process_arguments (int argc, char **argv)
 		case 'G': /* hostname */
 			if (strlen (optarg) >= MAX_INPUT_BUFFER)
 				die (STATE_UNKNOWN, _("Input buffer overflow\n"));
-			game_type = strdup (optarg);
+			game_type = optarg;
 			break;
 		case 'p': /* index of ping field */
 			qstat_ping_field = atoi (optarg);
@@ -308,3 +270,52 @@ validate_arguments (void)
 {
 		return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf (_("This plugin tests %s connections with the specified host."), progname);
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_("\
+<game>        = Game type that is recognised by qstat (without the leading dash)\n\
+<ip_address>  = The IP address of the device you wish to query\n\
+ [port]        = Optional port of which to connect\n\
+ [game_field]  = Field number in raw qstat output that contains game name\n\
+ [map_field]   = Field number in raw qstat output that contains map name\n\
+ [ping_field]  = Field number in raw qstat output that contains ping time\n"));
+
+	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+	printf (_("\n\
+Notes:\n\
+- This plugin uses the 'qstat' command, the popular game server status query tool .\n\
+  If you don't have the package installed, you will need to download it from\n\
+  http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n"));
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("\
+Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\
+  [-pf ping_field]\n"), progname);
+	printf (_(UT_HLP_VRS), progname, progname);
+}

+ 102 - 151
plugins/check_hpjd.c

@@ -29,36 +29,7 @@ const char *copyright = "2000-2003";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 const char *option_summary = "-H host [-C community]\n";
-void
-print_usage (void)
-{
-	printf (_("\
-Usage: %s -H host [-C community]\n"), progname);
-	printf (_(UT_HLP_VRS), progname, progname);
-}
 
-void
-print_help (void)
-{
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf (_("\
-This plugin tests the STATUS of an HP printer with a JetDirect card.\n\
-Net-snmp must be installed on the computer running the plugin.\n\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_("\
- -C, --community=STRING\n\
-    The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY);
-
-	printf (_(UT_SUPPORT));
-}
-
 #define HPJD_LINE_STATUS		".1.3.6.1.4.1.11.2.3.9.1.1.2.1"
 #define HPJD_PAPER_STATUS		".1.3.6.1.4.1.11.2.3.9.1.1.2.2"
 #define HPJD_INTERVENTION_REQUIRED	".1.3.6.1.4.1.11.2.3.9.1.1.2.3"
@@ -77,8 +48,10 @@ Net-snmp must be installed on the computer running the plugin.\n\n"));
 
 int process_arguments (int, char **);
 int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
 
-char *community = DEFAULT_COMMUNITY;
+char *community = NULL;
 char *address = NULL;
 
 int
@@ -89,7 +62,7 @@ main (int argc, char **argv)
 	int line;
 	char input_buffer[MAX_INPUT_BUFFER];
 	char query_string[512];
-	char error_message[MAX_INPUT_BUFFER];
+	char *errmsg;
 	char *temp_buffer;
 	int line_status = ONLINE;
 	int paper_status = 0;
@@ -103,7 +76,8 @@ main (int argc, char **argv)
 	int door_open = 0;
 	int paper_output = 0;
 	char display_message[MAX_INPUT_BUFFER];
-	char *temp ;
+
+	errmsg = malloc(MAX_INPUT_BUFFER);
 
 	if (process_arguments (argc, argv) != OK)
 		usage (_("Invalid command arguments supplied\n"));
@@ -154,118 +128,55 @@ main (int argc, char **argv)
 		temp_buffer = strtok (input_buffer, "=");
 		temp_buffer = strtok (NULL, "=");
 
-		switch (line) {
+		if (temp_buffer != NULL) {
 
-		case 1:										/* 1st line should contain the line status */
-			if (temp_buffer != NULL)
-				line_status = atoi (temp_buffer);
-			else {
 				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
+				strcpy (errmsg, input_buffer);
 
-		case 2:										/* 2nd line should contain the paper status */
-			if (temp_buffer != NULL)
-				paper_status = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
+		} else {
 
-		case 3:										/* 3rd line should be intervention required */
-			if (temp_buffer != NULL)
-				intervention_required = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
+			switch (line) {
 
-		case 4:										/* 4th line should be peripheral error */
-			if (temp_buffer != NULL)
+			case 1:										/* 1st line should contain the line status */
+				line_status = atoi (temp_buffer);
+				break;
+			case 2:										/* 2nd line should contain the paper status */
+				paper_status = atoi (temp_buffer);
+				break;
+			case 3:										/* 3rd line should be intervention required */
+				intervention_required = atoi (temp_buffer);
+				break;
+			case 4:										/* 4th line should be peripheral error */
 				peripheral_error = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 5:										/* 5th line should contain the paper jam status */
-			if (temp_buffer != NULL)
+				break;
+			case 5:										/* 5th line should contain the paper jam status */
 				paper_jam = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 6:										/* 6th line should contain the paper out status */
-			if (temp_buffer != NULL)
+				break;
+			case 6:										/* 6th line should contain the paper out status */
 				paper_out = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 7:										/* 7th line should contain the toner low status */
-			if (temp_buffer != NULL)
+				break;
+			case 7:										/* 7th line should contain the toner low status */
 				toner_low = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 8:										/* did data come too slow for engine */
-			if (temp_buffer != NULL)
+				break;
+			case 8:										/* did data come too slow for engine */
 				page_punt = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 9:										/* did we run out of memory */
-			if (temp_buffer != NULL)
+				break;
+			case 9:										/* did we run out of memory */
 				memory_out = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 10:										/* is there a door open */
-			if (temp_buffer != NULL)
+				break;
+			case 10:										/* is there a door open */
 				door_open = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 11:										/* is output tray full */
-			if (temp_buffer != NULL)
+				break;
+			case 11:										/* is output tray full */
 				paper_output = atoi (temp_buffer);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
-			}
-			break;
-
-		case 12:										/* display panel message */
-			if (temp_buffer != NULL)
+				break;
+			case 12:										/* display panel message */
 				strcpy (display_message, temp_buffer + 1);
-			else {
-				result = STATE_UNKNOWN;
-				strcpy (error_message, input_buffer);
+				break;
+			default:
+				break;
 			}
-			break;
 
-		default:
-			break;
 		}
 
 		/* break out of the read loop if we encounter an error */
@@ -279,7 +190,7 @@ main (int argc, char **argv)
 		/* remove CRLF */
 		if (input_buffer[strlen (input_buffer) - 1] == '\n')
 			input_buffer[strlen (input_buffer) - 1] = 0;
-		sprintf (error_message, "%s", input_buffer );
+		sprintf (errmsg, "%s", input_buffer );
 
 	}
 	
@@ -295,8 +206,7 @@ main (int argc, char **argv)
 
 		/* might not be the problem, but most likely is. */
 		result = STATE_UNKNOWN ;
-		asprintf (&temp, error_message);
-		sprintf (error_message, "%s : Timeout from host %s\n", temp, address );
+		asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address );
 		 
 	}
 
@@ -305,49 +215,49 @@ main (int argc, char **argv)
 
 		if (paper_jam) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Paper Jam"));
+			strcpy (errmsg, _("Paper Jam"));
 		}
 		else if (paper_out) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Out of Paper"));
+			strcpy (errmsg, _("Out of Paper"));
 		}
 		else if (line_status == OFFLINE) {
-			if (strcmp (error_message, "POWERSAVE ON") != 0) {
+			if (strcmp (errmsg, "POWERSAVE ON") != 0) {
 				result = STATE_WARNING;
-				strcpy (error_message, _("Printer Offline"));
+				strcpy (errmsg, _("Printer Offline"));
 			}
 		}
 		else if (peripheral_error) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Peripheral Error"));
+			strcpy (errmsg, _("Peripheral Error"));
 		}
 		else if (intervention_required) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Intervention Required"));
+			strcpy (errmsg, _("Intervention Required"));
 		}
 		else if (toner_low) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Toner Low"));
+			strcpy (errmsg, _("Toner Low"));
 		}
 		else if (memory_out) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Insufficient Memory"));
+			strcpy (errmsg, _("Insufficient Memory"));
 		}
 		else if (door_open) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("A Door is Open"));
+			strcpy (errmsg, _("A Door is Open"));
 		}
 		else if (paper_output) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Output Tray is Full"));
+			strcpy (errmsg, _("Output Tray is Full"));
 		}
 		else if (page_punt) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Data too Slow for Engine"));
+			strcpy (errmsg, _("Data too Slow for Engine"));
 		}
 		else if (paper_status) {
 			result = STATE_WARNING;
-			strcpy (error_message, _("Unknown Paper Error"));
+			strcpy (errmsg, _("Unknown Paper Error"));
 		}
 	}
 
@@ -356,15 +266,15 @@ main (int argc, char **argv)
 
 	else if (result == STATE_UNKNOWN) {
 
-		printf ("%s\n", error_message);
+		printf ("%s\n", errmsg);
 
 		/* if printer could not be reached, escalate to critical */
-		if (strstr (error_message, "Timeout"))
+		if (strstr (errmsg, "Timeout"))
 			result = STATE_CRITICAL;
 	}
 
 	else if (result == STATE_WARNING)
-		printf ("%s (%s)\n", error_message, display_message);
+		printf ("%s (%s)\n", errmsg, display_message);
 
 	return result;
 }
@@ -379,8 +289,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"community", required_argument, 0, 'C'},
 /*  		{"critical",       required_argument,0,'c'}, */
@@ -396,7 +306,7 @@ process_arguments (int argc, char **argv)
 
 	
 	while (1) {
-		c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index);
+		c = getopt_long (argc, argv, "+hVH:C:", longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;
@@ -434,8 +344,11 @@ process_arguments (int argc, char **argv)
 		}
 	}
 	
-	if (argv[c] != NULL ) {
-		community = argv[c];
+	if (community == NULL) {
+		if (argv[c] != NULL )
+			community = argv[c];
+		else
+			community = strdup (DEFAULT_COMMUNITY);
 	}
 
 	return validate_arguments ();
@@ -450,3 +363,41 @@ validate_arguments (void)
 {
 	return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf (_("\
+This plugin tests the STATUS of an HP printer with a JetDirect card.\n\
+Net-snmp must be installed on the computer running the plugin.\n\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_("\
+ -C, --community=STRING\n\
+    The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY);
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("\
+Usage: %s -H host [-C community]\n"), progname);
+	printf (_(UT_HLP_VRS), progname, progname);
+}

+ 6 - 6
plugins/check_http.c

@@ -184,8 +184,8 @@ process_arguments (int argc, char **argv)
 {
 	int c = 1;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		STD_LONG_OPTS,
 		{"file",required_argument,0,'F'},
 		{"link", no_argument, 0, 'L'},
@@ -224,7 +224,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vvh46t:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:", long_options, &option_index);
+		c = getopt_long (argc, argv, "Vvh46t:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:", longopts, &option);
 		if (c == -1 || c == EOF)
 			break;
 
@@ -304,10 +304,10 @@ process_arguments (int argc, char **argv)
 			break;
 		/* Note: H, I, and u must be malloc'd or will fail on redirects */
 		case 'H': /* Host Name (virtual host) */
- 			host_name = strdup (optarg);
+ 			host_name = optarg;
 			break;
 		case 'I': /* Server IP-address */
- 			server_address = strdup(optarg);
+ 			server_address = optarg;
 			break;
 		case 'u': /* URL path */
 			asprintf (&server_url, "%s", optarg);
@@ -328,7 +328,7 @@ process_arguments (int argc, char **argv)
 		case 'P': /* HTTP POST data in URL encoded format */
 			if (http_method || http_post_data) break;
 			http_method = strdup("POST");
-			http_post_data = strdup(optarg);
+			http_post_data = optarg;
 			break;
 		case 's': /* string or substring */
 			strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);

+ 81 - 71
plugins/check_ldap.c

@@ -36,75 +36,18 @@ enum {
 	DEFAULT_PORT = 389
 };
 
-void
-print_usage ()
-{
-	printf (_("\
-Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\
-  [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\
-(Note: all times are in seconds.)\n"),
-	        progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : ""));
-	printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help ()
-{
-	char *myport;
-	asprintf (&myport, "%d", DEFAULT_PORT);
-
-	print_revision (progname, revision);
-
-	printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n"));
-	printf (_(COPYRIGHT), copyright, email);
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_(UT_HOST_PORT), 'p', myport);
-
-	printf (_(UT_IPv46));
-
-	printf (_("\
- -a [--attr]\n\
-    ldap attribute to search (default: \"(objectclass=*)\"\n\
- -b [--base]\n\
-    ldap base (eg. ou=my unit, o=my org, c=at)\n\
- -D [--bind]\n\
-    ldap bind DN (if required)\n\
- -P [--pass]\n\
-    ldap password (if required)\n"));
-
-#ifdef HAVE_LDAP_SET_OPTION
-	printf (_("\
- -2 [--ver2]\n\
-     use ldap protocol version 2\n\
- -3 [--ver3]\n\
-    use ldap protocol version 3\n\
-    (default protocol version: %d)\n"),
-	        DEFAULT_PROTOCOL);
-#endif
-
-	printf (_(UT_WARN_CRIT));
-
-	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
-
-	printf (_(UT_VERBOSE));
-
-	printf (_(UT_SUPPORT));
-}
-
 int process_arguments (int, char **);
 int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
 
 char ld_defattr[] = "(objectclass=*)";
 char *ld_attr = ld_defattr;
-char *ld_host = "";
-char *ld_base = "";
+char *ld_host = NULL;
+char *ld_base = NULL;
 char *ld_passwd = NULL;
 char *ld_binddn = NULL;
-unsigned int ld_port = DEFAULT_PORT;
+int ld_port = DEFAULT_PORT;
 #ifdef HAVE_LDAP_SET_OPTION
 int ld_protocol = DEFAULT_PROTOCOL;
 #endif
@@ -198,7 +141,7 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
+	int option = 0;
 	/* initialize the long option struct */
 	static struct option longopts[] = {
 		{"help", no_argument, 0, 'h'},
@@ -230,7 +173,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option_index);
+		c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -245,7 +188,8 @@ process_arguments (int argc, char **argv)
 		case 't':									/* timeout period */
 			if (!is_intnonneg (optarg))
 				usage2 (_("timeout interval must be a positive integer"), optarg);
-			socket_timeout = atoi (optarg);
+			else
+				socket_timeout = atoi (optarg);
 			break;
 		case 'H':
 			ld_host = optarg;
@@ -296,12 +240,11 @@ process_arguments (int argc, char **argv)
 	}
 
 	c = optind;
-	if (strlen(ld_host) == 0 && is_host(argv[c])) {
-		asprintf (&ld_host, "%s", argv[c++]);
-	}
-	if (strlen(ld_base) == 0 && argv[c]) {
-		asprintf (&ld_base, "%s", argv[c++]);
-	}
+	if (ld_host == NULL && is_host(argv[c]))
+		ld_host = strdup (argv[c++]);
+
+	if (ld_base == NULL && argv[c])
+		ld_base = strdup (argv[c++]);
 
 	return validate_arguments ();
 }
@@ -318,3 +261,70 @@ validate_arguments ()
 	return OK;
 
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	char *myport;
+	asprintf (&myport, "%d", DEFAULT_PORT);
+
+	print_revision (progname, revision);
+
+	printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n"));
+	printf (_(COPYRIGHT), copyright, email);
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_(UT_HOST_PORT), 'p', myport);
+
+	printf (_(UT_IPv46));
+
+	printf (_("\
+ -a [--attr]\n\
+    ldap attribute to search (default: \"(objectclass=*)\"\n\
+ -b [--base]\n\
+    ldap base (eg. ou=my unit, o=my org, c=at)\n\
+ -D [--bind]\n\
+    ldap bind DN (if required)\n\
+ -P [--pass]\n\
+    ldap password (if required)\n"));
+
+#ifdef HAVE_LDAP_SET_OPTION
+	printf (_("\
+ -2 [--ver2]\n\
+     use ldap protocol version 2\n\
+ -3 [--ver3]\n\
+    use ldap protocol version 3\n\
+    (default protocol version: %d)\n"),
+	        DEFAULT_PROTOCOL);
+#endif
+
+	printf (_(UT_WARN_CRIT));
+
+	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+	printf (_(UT_VERBOSE));
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("\
+Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\
+  [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\
+(Note: all times are in seconds.)\n"),
+	        progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : ""));
+	printf (_(UT_HLP_VRS), progname, progname);
+}

+ 3 - 3
plugins/check_load.c

@@ -158,8 +158,8 @@ process_arguments (int argc, char **argv)
 {
 	int c = 0;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"warning", required_argument, 0, 'w'},
 		{"critical", required_argument, 0, 'c'},
 		{"version", no_argument, 0, 'V'},
@@ -171,7 +171,7 @@ process_arguments (int argc, char **argv)
 		return ERROR;
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vhc:w:", long_options, &option_index);
+		c = getopt_long (argc, argv, "Vhc:w:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 4 - 4
plugins/check_mrtg.c

@@ -149,8 +149,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"logfile", required_argument, 0, 'F'},
 		{"expires", required_argument, 0, 'e'},
 		{"aggregation", required_argument, 0, 'a'},
@@ -178,8 +178,8 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", long_options,
-									 &option_index);
+		c = getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", longopts,
+									 &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 2 - 2
plugins/check_mrtgtraf.c

@@ -201,7 +201,7 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
+	int option = 0;
 	static struct option longopts[] = {
 		{"logfile", required_argument, 0, 'F'},
 		{"expires", required_argument, 0, 'e'},
@@ -228,7 +228,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option_index);
+		c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 94 - 102
plugins/check_mysql.c

@@ -25,65 +25,23 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #include <mysql/mysql.h>
 #include <mysql/errmsg.h>
 
-void
-print_usage (void)
-{
-	printf (_("\
-Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
-	        progname);
-	printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
-	char *myport;
-	asprintf (&myport, "%d", MYSQL_PORT);
-
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf (_("This program tests connections to a mysql server\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_(UT_HOST_PORT), 'P', myport);
-
-	printf (_("\
- -d, --database=STRING\n\
-   Check database with indicated name\n\
- -u, --username=STRING\n\
-   Connect using the indicated username\n\
- -p, --password=STRING\n\
-   Use the indicated password to authenticate the connection\n\
-   ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
-   Your clear-text password will be visible as a process table entry\n"));
-
-	printf (_("\n\
-There are no required arguments. By default, the local database with\n\
-a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT);
-
-	printf (_(UT_SUPPORT));
-}
-
-char *db_user = "";
-char *db_host = "";
-char *db_pass = "";
-char *db = "";
+char *db_user = NULL;
+char *db_host = NULL;
+char *db_pass = NULL;
+char *db = NULL;
 unsigned int db_port = MYSQL_PORT;
 
 int process_arguments (int, char **);
 int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
 
 int
 main (int argc, char **argv)
 {
 
 	MYSQL mysql;
-	char result[1024];
+	char *result = NULL;
 
 	if (process_arguments (argc, argv) != OK)
 		usage (_("Invalid command arguments supplied\n"));
@@ -92,62 +50,32 @@ main (int argc, char **argv)
 	mysql_init (&mysql);
 
 	/* establish a connection to the server and error checking */
-	if (!mysql_real_connect
-			(&mysql, db_host, db_user, db_pass, db, db_port, NULL, 0)) {
-
-		if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_WARNING;
-
-		}
-		else if (mysql_errno (&mysql) == CR_VERSION_ERROR) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_WARNING;
-
-		}
-		else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_WARNING;
-
-		}
-		else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_WARNING;
-
-		}
-		else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_WARNING;
-
-		}
-		else {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_CRITICAL;
-		}
-
+	if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) {
+		if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
+			die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+		else if (mysql_errno (&mysql) == CR_VERSION_ERROR)
+			die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+		else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY)
+			die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+		else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR)
+			die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+		else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR)
+			die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+		else
+			die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
 	}
 
 	/* get the server stats */
-	sprintf (result, mysql_stat (&mysql));
+	result = strdup (mysql_stat (&mysql));
 
 	/* error checking once more */
 	if (mysql_error (&mysql)) {
-
-		if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_CRITICAL;
-
-		}
-		else if (mysql_errno (&mysql) == CR_SERVER_LOST) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_CRITICAL;
-
-		}
-		else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR) {
-			printf ("%s\n", mysql_error (&mysql));
-			return STATE_UNKNOWN;
-		}
-
+		if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR)
+			die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
+		else if (mysql_errno (&mysql) == CR_SERVER_LOST)
+			die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
+		else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR)
+			die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
 	}
 
 	/* close the connection */
@@ -169,8 +97,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"database", required_argument, 0, 'd'},
 		{"username", required_argument, 0, 'u'},
@@ -186,7 +114,7 @@ process_arguments (int argc, char **argv)
 		return ERROR;
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVP:p:u:d:H:", long_options, &option_index);
+		c = getopt_long (argc, argv, "hVP:p:u:d:H:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -256,5 +184,69 @@ process_arguments (int argc, char **argv)
 int
 validate_arguments (void)
 {
+	if (db_user == NULL)
+		db_user = strdup("");
+
+	if (db_host == NULL)
+		db_host = strdup("");
+
+	if (db_pass == NULL)
+		db_pass == strdup("");
+
+	if (db == NULL)
+		db = strdup("");
+
 	return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	char *myport;
+	asprintf (&myport, "%d", MYSQL_PORT);
+
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf (_("This program tests connections to a mysql server\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_(UT_HOST_PORT), 'P', myport);
+
+	printf (_("\
+ -d, --database=STRING\n\
+   Check database with indicated name\n\
+ -u, --username=STRING\n\
+   Connect using the indicated username\n\
+ -p, --password=STRING\n\
+   Use the indicated password to authenticate the connection\n\
+   ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
+   Your clear-text password will be visible as a process table entry\n"));
+
+	printf (_("\n\
+There are no required arguments. By default, the local database with\n\
+a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT);
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("\
+Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
+	        progname);
+	printf (_(UT_HLP_VRS), progname, progname);
+}

+ 58 - 48
plugins/check_nagios.c

@@ -25,48 +25,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #include "popen.h"
 #include "utils.h"
 
-void
-print_usage (void)
-{
-	printf (_("\
-Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"),
-	        progname);
-}
-
-void
-print_help (void)
-{
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf (_("\
-This plugin attempts to check the status of the Nagios process on the local\n\
-machine. The plugin will check to make sure the Nagios status log is no older\n\
-than the number of minutes specified by the <expire_minutes> option.  It also\n\
-uses the /bin/ps command to check for a process matching whatever you specify\n\
-by the <process_string> argument.\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_("\
--F, --filename=FILE\n\
-   Name of the log file to check\n\
--e, --expires=INTEGER\n\
-   Seconds aging afterwhich logfile is condsidered stale\n\
--C, --command=STRING\n\
-   Command to search for in process table\n"));
-
-	printf (_("\
-Example:\n\
-   ./check_nagios -e 5 \\\
-   -F /usr/local/nagios/var/status.log \\\
-   -C /usr/local/nagios/bin/nagios\n"));
-}
-
 int process_arguments (int, char **);
+void print_help (void);
+void print_usage (void);
 
 char *status_log = NULL;
 char *process_string = NULL;
@@ -198,8 +159,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"filename", required_argument, 0, 'F'},
 		{"expires", required_argument, 0, 'e'},
 		{"command", required_argument, 0, 'C'},
@@ -225,7 +186,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVvF:C:e:", long_options, &option_index);
+		c = getopt_long (argc, argv, "+hVvF:C:e:", longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;
@@ -252,8 +213,8 @@ process_arguments (int argc, char **argv)
 				expire_minutes = atoi (optarg);
 			else
 				die (STATE_UNKNOWN,
-									 _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
-									 progname);
+				     _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
+				     progname);
 			break;
 		case 'v':
 			verbose++;
@@ -264,8 +225,8 @@ process_arguments (int argc, char **argv)
 
 	if (status_log == NULL)
 		die (STATE_UNKNOWN,
-							 _("You must provide the status_log\nType '%s -h' for additional help\n"),
-							 progname);
+		     _("You must provide the status_log\nType '%s -h' for additional help\n"),
+		     progname);
 	else if (process_string == NULL)
 		die (STATE_UNKNOWN,
 							 _("You must provide a process string\nType '%s -h' for additional help\n"),
@@ -273,3 +234,52 @@ process_arguments (int argc, char **argv)
 
 	return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf (_("\
+This plugin attempts to check the status of the Nagios process on the local\n\
+machine. The plugin will check to make sure the Nagios status log is no older\n\
+than the number of minutes specified by the <expire_minutes> option.  It also\n\
+uses the /bin/ps command to check for a process matching whatever you specify\n\
+by the <process_string> argument.\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_("\
+-F, --filename=FILE\n\
+   Name of the log file to check\n\
+-e, --expires=INTEGER\n\
+   Seconds aging afterwhich logfile is condsidered stale\n\
+-C, --command=STRING\n\
+   Command to search for in process table\n"));
+
+	printf (_("\
+Example:\n\
+   ./check_nagios -e 5 \\\
+   -F /usr/local/nagios/var/status.log \\\
+   -C /usr/local/nagios/bin/nagios\n"));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("\
+Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"),
+	        progname);
+}

+ 6 - 7
plugins/check_nt.c

@@ -28,7 +28,6 @@
  *
  *****************************************************************************/
 
-#include "config.h"
 #include "common.h"
 #include "netutils.h"
 #include "utils.h"
@@ -331,8 +330,8 @@ int main(int argc, char **argv){
 int process_arguments(int argc, char **argv){
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] =
+	int option = 0;
+	static struct option longopts[] =
 	{ 
 		{"port",     required_argument,0,'p'},
 		{"timeout",  required_argument,0,'t'},
@@ -366,7 +365,7 @@ int process_arguments(int argc, char **argv){
 	}
 
 	while (1){
-		c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",long_options,&option_index);
+		c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",longopts,&option);
 
 		if (c==-1||c==EOF||c==1)
 			break;
@@ -385,10 +384,10 @@ int process_arguments(int argc, char **argv){
 				exit(STATE_OK);
 			case 'H': /* hostname */
 				if (server_address)	free(server_address);
-				server_address = strdup(optarg);
+				server_address = optarg;
 				break;
 			case 's': /* password */
-				req_password = strdup (optarg);
+				req_password = optarg;
 				break;
 			case 'p': /* port */
 				if (is_intnonneg(optarg))
@@ -421,7 +420,7 @@ int process_arguments(int argc, char **argv){
 					return ERROR;
 				break;
 			case 'l': /* value list */
-				value_list = strdup (optarg);
+				value_list = optarg;
 				break;
 			case 'w': /* warning threshold */
 				warning_value=strtoul(optarg,NULL,10);

+ 3 - 3
plugins/check_nwstat.c

@@ -705,8 +705,8 @@ main(int argc, char **argv) {
 int process_arguments(int argc, char **argv) {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] =
+	int option = 0;
+	static struct option longopts[] =
 		{ 
 			{"port",     required_argument,0,'p'},
 			{"timeout",  required_argument,0,'t'},
@@ -741,7 +741,7 @@ int process_arguments(int argc, char **argv) {
 	}
 
 	while (1) {
-		c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",long_options,&option_index);
+		c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",longopts,&option);
 
 		if (c==-1||c==EOF||c==1)
 			break;

+ 4 - 4
plugins/check_overcr.c

@@ -285,8 +285,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"port", required_argument, 0, 'p'},
 		{"timeout", required_argument, 0, 't'},
 		{"critical", required_argument, 0, 'c'},
@@ -320,8 +320,8 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", long_options,
-									 &option_index);
+		c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", longopts,
+									 &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;

+ 110 - 101
plugins/check_pgsql.c

@@ -1,26 +1,19 @@
 /******************************************************************************
- *
- * Program: PostgreSQL plugin for Nagios
- * License: GPL
- *
- * License Information:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- *
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
  *****************************************************************************/
 
 #define DEFAULT_DB "template1"
@@ -32,9 +25,9 @@ enum {
 	DEFAULT_CRIT = 8
 };
 
-#include "config.h"
 #include "common.h"
 #include "utils.h"
+#include "netutils.h"
 #include <libpq-fe.h>
 
 int process_arguments (int, char **);
@@ -121,72 +114,6 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
 
 
 
-void
-print_help (void)
-{
-	char *myport;
-
-	asprintf (&myport, "%d", DEFAULT_PORT);
-
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf (_("Test whether a PostgreSQL DBMS is accepting connections.\n\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_(UT_HOST_PORT), 'P', myport);
-
-	printf (_(UT_IPv46));
-
-	printf (S_("\
-  -d, --database=STRING\n\
-    Database to check (default: %s)\n\
-  -l, --logname = STRING\n\
-    Login name of user\n\
-  -p, --password = STRING\n\
-    Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB);
-
-	printf (_(UT_WARN_CRIT));
-
-	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
-
-	printf (_(UT_VERBOSE));
-
-	printf (S_("\nAll parameters are optional.\n\
-\n\
-This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\
-accepting queries. In its current operation, it simply connects to the\n\
-specified database, and then disconnects. If no database is specified, it\n\
-connects to the template1 database, which is present in every functioning \n\
-PostgreSQL DBMS.\n"));
-	printf (S_("\n\
-The plugin will connect to a local postmaster if no host is specified. To\n\
-connect to a remote host, be sure that the remote postmaster accepts TCP/IP\n\
-connections (start the postmaster with the -i option).\n"));
-	printf (S_("\n\
-Typically, the nagios user (unless the --logname option is used) should be\n\
-able to connect to the database without a password. The plugin can also send\n\
-a password, but no effort is made to obsure or encrypt the password.\n"));
-
-	support ();
-}
-
-void
-print_usage (void)
-{
-	printf (S_("\
-Usage:\n %s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n\
-            [-t <timeout>]"), progname);
-	printf (S_("[-d <database>] [-l <logname>] [-p <password>]\n"));
-	printf (S_("\
-         %s (-h | --help) for detailed help\n\
-         %s (-V | --version) for version information\n"),
-					progname, progname);
-}
 
 int
 main (int argc, char **argv)
@@ -251,8 +178,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"help", no_argument, 0, 'h'},
 		{"version", no_argument, 0, 'V'},
 		{"timeout", required_argument, 0, 't'},
@@ -269,7 +196,7 @@ process_arguments (int argc, char **argv)
 
 	while (1) {
 		c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:",
-		                 long_options, &option_index);
+		                 longopts, &option);
 
 		if (c == EOF)
 			break;
@@ -277,6 +204,7 @@ process_arguments (int argc, char **argv)
 		switch (c) {
 		case '?':     /* usage */
 			usage3 (_("Unknown argument"), optopt);
+			break;
 		case 'h':     /* help */
 			print_help ();
 			exit (STATE_OK);
@@ -286,38 +214,44 @@ process_arguments (int argc, char **argv)
 		case 't':     /* timeout period */
 			if (!is_integer (optarg))
 				usage2 (_("Timeout Interval must be an integer"), optarg);
-			timeout_interval = atoi (optarg);
+			else
+				timeout_interval = atoi (optarg);
 			break;
 		case 'c':     /* critical time threshold */
 			if (!is_integer (optarg))
 				usage2 (_("Invalid critical threshold"), optarg);
-			tcrit = atoi (optarg);
+			else
+				tcrit = atoi (optarg);
 			break;
 		case 'w':     /* warning time threshold */
 			if (!is_integer (optarg))
 				usage2 (_("Invalid critical threshold"), optarg);
-			twarn = atoi (optarg);
+			else
+				twarn = atoi (optarg);
 			break;
 		case 'H':     /* host */
 			if (!is_host (optarg))
 				usage2 (_("You gave an invalid host name"), optarg);
-			pghost = optarg;
+			else
+				pghost = optarg;
 			break;
 		case 'P':     /* port */
 			if (!is_integer (optarg))
 				usage2 (_("Port must be an integer"), optarg);
-			pgport = optarg;
+			else
+				pgport = optarg;
 			break;
 		case 'd':     /* database name */
-			if (!is_pg_dbname (optarg))
+			if (!is_pg_dbname (optarg)) /* checks length and valid chars */
 				usage2 (_("Database name is not valid"), optarg);
-			strncpy (dbName, optarg, NAMEDATALEN - 1);
-			dbName[NAMEDATALEN - 1] = 0;
+			else /* we know length, and know optarg is terminated, so us strcpy */
+				strcpy (dbName, optarg);
 			break;
 		case 'l':     /* login name */
 			if (!is_pg_logname (optarg))
 				usage2 (_("user name is not valid"), optarg);
-			pguser = optarg;
+			else
+				pguser = optarg;
 			break;
 		case 'p':     /* authentication password */
 		case 'a':
@@ -433,3 +367,78 @@ is_pg_logname (char *username)
 </article>
 -@@
 ******************************************************************************/
+
+
+
+
+
+void
+print_help (void)
+{
+	char *myport;
+
+	asprintf (&myport, "%d", DEFAULT_PORT);
+
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf (_("Test whether a PostgreSQL DBMS is accepting connections.\n\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_(UT_HOST_PORT), 'P', myport);
+
+	printf (_(UT_IPv46));
+
+	printf (S_("\
+  -d, --database=STRING\n\
+    Database to check (default: %s)\n\
+  -l, --logname = STRING\n\
+    Login name of user\n\
+  -p, --password = STRING\n\
+    Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB);
+
+	printf (_(UT_WARN_CRIT));
+
+	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+	printf (_(UT_VERBOSE));
+
+	printf (S_("\nAll parameters are optional.\n\
+\n\
+This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\
+accepting queries. In its current operation, it simply connects to the\n\
+specified database, and then disconnects. If no database is specified, it\n\
+connects to the template1 database, which is present in every functioning \n\
+PostgreSQL DBMS.\n"));
+	printf (S_("\n\
+The plugin will connect to a local postmaster if no host is specified. To\n\
+connect to a remote host, be sure that the remote postmaster accepts TCP/IP\n\
+connections (start the postmaster with the -i option).\n"));
+	printf (S_("\n\
+Typically, the nagios user (unless the --logname option is used) should be\n\
+able to connect to the database without a password. The plugin can also send\n\
+a password, but no effort is made to obsure or encrypt the password.\n"));
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (S_("\
+Usage:\n %s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n\
+            [-t <timeout>]"), progname);
+	printf (S_("[-d <database>] [-l <logname>] [-p <password>]\n"));
+	printf (S_("\
+         %s (-h | --help) for detailed help\n\
+         %s (-V | --version) for version information\n"),
+					progname, progname);
+}
+

+ 3 - 3
plugins/check_ping.c

@@ -162,8 +162,8 @@ process_arguments (int argc, char **argv)
 	int c = 1;
 	char *ptr;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		STD_LONG_OPTS,
 		{"packets", required_argument, 0, 'p'},
 		{"nohtml", no_argument, 0, 'n'},
@@ -184,7 +184,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", long_options, &option_index);
+		c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 6 - 6
plugins/check_procs.c

@@ -278,8 +278,8 @@ process_arguments (int argc, char **argv)
 	int c = 1;
 	char *user;
 	struct passwd *pw;
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"warning", required_argument, 0, 'w'},
 		{"critical", required_argument, 0, 'c'},
 		{"metric", required_argument, 0, 'm'},
@@ -303,7 +303,7 @@ process_arguments (int argc, char **argv)
 
 	while (1) {
 		c = getopt_long (argc, argv, "Vvht:c:w:p:s:u:C:a:z:r:m:P:", 
-			long_options, &option_index);
+			longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -362,7 +362,7 @@ process_arguments (int argc, char **argv)
 			if (statopts)
 				break;
 			else
-				statopts = strdup(optarg);
+				statopts = optarg;
 			asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts);
 			options |= STAT;
 			break;
@@ -397,7 +397,7 @@ process_arguments (int argc, char **argv)
 			if (prog)
 				break;
 			else
-				prog = strdup(optarg);
+				prog = optarg;
 			asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""),
 			          prog);
 			options |= PROG;
@@ -406,7 +406,7 @@ process_arguments (int argc, char **argv)
 			if (args)
 				break;
 			else
-				args = strdup(optarg);
+				args = optarg;
 			asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args);
 			options |= ARGS;
 			break;

+ 82 - 70
plugins/check_radius.c

@@ -21,79 +21,21 @@ const char *revision = "$Revision$";
 const char *copyright = "2000-2003";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
-#include "config.h"
 #include "common.h"
 #include "utils.h"
+#include "netutils.h"
 #include <radiusclient.h>
 
-void
-print_usage (void)
-{
-	printf ("\
-Usage: %s -H host -F config_file -u username -p password [-P port]\n\
-  [-t timeout] [-r retries] [-e expect]\n", progname);
-	printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
-	char *myport;
-	asprintf (&myport, "%d", PW_AUTH_UDP_PORT);
-
-	print_revision (progname, revision);
-
-	printf (_("Copyright (c) 1999 Robert August Vincent II\n"));
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf(_("Tests to see if a radius server is accepting connections.\n\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_(UT_HOST_PORT), 'P', myport);
-
-	printf (_("\
- -u, --username=STRING\n\
-    The user to authenticate\n\
- -p, --password=STRING\n\
-    Password for autentication (SECURITY RISK)\n\
- -F, --filename=STRING\n\
-    Configuration file\n\
- -e, --expect=STRING\n\
-    Response string to expect from the server\n\
- -r, --retries=INTEGER\n\
-    Number of times to retry a failed connection\n"));
-
-	printf (_(UT_TIMEOUT), timeout_interval);
-
-	printf (_("\n\
-This plugin tests a radius server to see if it is accepting connections.\n\
-\n\
-The server to test must be specified in the invocation, as well as a user\n\
-name and password. A configuration file may also be present. The format of\n\
-the configuration file is described in the radiusclient library sources.\n\n"));
-
-	printf (_("\
-The password option presents a substantial security issue because the\n\
-password can be determined by careful watching of the command line in\n\
-a process listing.  This risk is exacerbated because nagios will\n\
-run the plugin at regular prdictable intervals.  Please be sure that\n\
-the password used does not allow access to sensitive system resources,\n\
-otherwise compormise could occur.\n"));
-
-	printf (_(UT_SUPPORT));
-}
-
 int process_arguments (int, char **);
+void print_help (void);
+void print_usage (void);
 
 char *server = NULL;
 char *username = NULL;
 char *password = NULL;
 char *expect = NULL;
 char *config_file = NULL;
-int port = PW_AUTH_UDP_PORT;
+unsigned short port = PW_AUTH_UDP_PORT;
 int retries = 1;
 int verbose = FALSE;
 ENV *env = NULL;
@@ -159,12 +101,14 @@ main (int argc, char **argv)
 	SEND_DATA data;
 	int result;
 	UINT4 client_id;
+	char *str;
 
 	if (process_arguments (argc, argv) == ERROR)
 		usage (_("Could not parse arguments\n"));
 
+	str = strdup ("dictionary");
 	if ((config_file && rc_read_config (config_file)) ||
-			rc_read_dictionary (rc_conf_str ("dictionary")))
+			rc_read_dictionary (rc_conf_str (str)))
 		die (STATE_UNKNOWN, _("Config file error"));
 
 	service = PW_AUTHENTICATE_ONLY;
@@ -184,8 +128,8 @@ main (int argc, char **argv)
 	if (rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) ==
 			NULL) return (ERROR_RC);
 
-	rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, timeout_interval,
-							 retries);
+	rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, (int)timeout_interval,
+	             retries);
 
 	result = rc_send_server (&data, msg);
 	rc_avpair_free (data.send_pairs);
@@ -199,7 +143,7 @@ main (int argc, char **argv)
 	if (result == BADRESP_RC)
 		die (STATE_WARNING, _("Auth Failed"));
 	if (expect && !strstr (msg, expect))
-		die (STATE_WARNING, msg);
+		die (STATE_WARNING, "%s", msg);
 	if (result == OK_RC)
 		die (STATE_OK, _("Auth OK"));
 	return (0);
@@ -213,8 +157,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"port", required_argument, 0, 'P'},
 		{"username", required_argument, 0, 'u'},
@@ -254,8 +198,8 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVvH:P:F:u:p:t:r:e:", long_options,
-									 &option_index);
+		c = getopt_long (argc, argv, "+hVvH:P:F:u:p:t:r:e:", longopts,
+									 &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;
@@ -316,3 +260,71 @@ process_arguments (int argc, char **argv)
 	}
 	return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	char *myport;
+	asprintf (&myport, "%d", PW_AUTH_UDP_PORT);
+
+	print_revision (progname, revision);
+
+	printf (_("Copyright (c) 1999 Robert August Vincent II\n"));
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf(_("Tests to see if a radius server is accepting connections.\n\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_(UT_HOST_PORT), 'P', myport);
+
+	printf (_("\
+ -u, --username=STRING\n\
+    The user to authenticate\n\
+ -p, --password=STRING\n\
+    Password for autentication (SECURITY RISK)\n\
+ -F, --filename=STRING\n\
+    Configuration file\n\
+ -e, --expect=STRING\n\
+    Response string to expect from the server\n\
+ -r, --retries=INTEGER\n\
+    Number of times to retry a failed connection\n"));
+
+	printf (_(UT_TIMEOUT), timeout_interval);
+
+	printf (_("\n\
+This plugin tests a radius server to see if it is accepting connections.\n\
+\n\
+The server to test must be specified in the invocation, as well as a user\n\
+name and password. A configuration file may also be present. The format of\n\
+the configuration file is described in the radiusclient library sources.\n\n"));
+
+	printf (_("\
+The password option presents a substantial security issue because the\n\
+password can be determined by careful watching of the command line in\n\
+a process listing.  This risk is exacerbated because nagios will\n\
+run the plugin at regular prdictable intervals.  Please be sure that\n\
+the password used does not allow access to sensitive system resources,\n\
+otherwise compormise could occur.\n"));
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf ("\
+Usage: %s -H host -F config_file -u username -p password [-P port]\n\
+  [-t timeout] [-r retries] [-e expect]\n", progname);
+	printf (_(UT_HLP_VRS), progname, progname);
+}

+ 7 - 7
plugins/check_real.c

@@ -256,8 +256,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"IPaddress", required_argument, 0, 'I'},
 		{"expect", required_argument, 0, 'e'},
@@ -285,8 +285,8 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVI:H:e:u:p:w:c:t:", long_options,
-									 &option_index);
+		c = getopt_long (argc, argv, "+hVI:H:e:u:p:w:c:t:", longopts,
+									 &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -297,15 +297,15 @@ process_arguments (int argc, char **argv)
 			if (server_address)
 				break;
 			else if (is_host (optarg))
-				server_address = strdup(optarg);
+				server_address = optarg;
 			else
 				usage (_("Invalid host name\n"));
 			break;
 		case 'e':									/* string to expect in response header */
-			server_expect = strdup(optarg);
+			server_expect = optarg;
 			break;
 		case 'u':									/* server URL */
-			server_url = strdup(optarg);
+			server_url = optarg;
 			break;
 		case 'p':									/* port */
 			if (is_intpos (optarg)) {

+ 3 - 3
plugins/check_smtp.c

@@ -183,8 +183,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"expect", required_argument, 0, 'e'},
 		{"critical", required_argument, 0, 'c'},
@@ -216,7 +216,7 @@ process_arguments (int argc, char **argv)
 
 	while (1) {
 		c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:",
-		                 long_options, &option_index);
+		                 longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 43 - 30
plugins/check_snmp.c

@@ -84,7 +84,7 @@ int errcode, excode;
 #endif
 
 char *server_address = NULL;
-char *community = DEFAULT_COMMUNITY;
+char *community = NULL;
 char *authpriv = NULL;
 char *proto = NULL;
 char *seclevel = NULL;
@@ -92,17 +92,17 @@ char *secname = NULL;
 char *authproto = NULL;
 char *authpasswd = NULL;
 char *privpasswd = NULL;
-char *oid = "";
-char *label = "SNMP";
-char *units = "";
-char *port = DEFAULT_PORT;
+char *oid;
+char *label;
+char *units;
+char *port;
 char string_value[MAX_INPUT_BUFFER] = "";
 char **labels = NULL;
 char **unitv = NULL;
-int nlabels = 0;
-int labels_size = 8;
-int nunits = 0;
-int unitv_size = 8;
+size_t nlabels = 0;
+size_t labels_size = 8;
+size_t nunits = 0;
+size_t unitv_size = 8;
 int verbose = FALSE;
 unsigned long lower_warn_lim[MAX_OIDS];
 unsigned long upper_warn_lim[MAX_OIDS];
@@ -112,9 +112,9 @@ unsigned long response_value[MAX_OIDS];
 int check_warning_value = FALSE;
 int check_critical_value = FALSE;
 int eval_method[MAX_OIDS];
-char *delimiter = DEFAULT_DELIMITER;
-char *output_delim = DEFAULT_OUTPUT_DELIMITER;
-char *miblist = DEFAULT_MIBLIST;
+char *delimiter;
+char *output_delim;
+char *miblist;
 
 
 
@@ -131,8 +131,8 @@ main (int argc, char **argv)
 	char input_buffer[MAX_INPUT_BUFFER];
 	char *command_line = NULL;
 	char *response = NULL;
-	char *outbuff = "";
-	char *output = "";
+	char *outbuff;
+	char *output;
 	char *ptr = NULL;
 	char *p2 = NULL;
 	char *show = NULL;
@@ -143,6 +143,16 @@ main (int argc, char **argv)
 		eval_method[i] = CHECK_UNDEF;
 	i = 0;
 
+	oid = strdup ("");
+	label = strdup ("SNMP");
+	units = strdup ("");
+	port = strdup (DEFAULT_PORT);
+	outbuff = strdup ("");
+	output = strdup ("");
+	delimiter = strdup (DEFAULT_DELIMITER);
+	output_delim = strdup (DEFAULT_OUTPUT_DELIMITER);
+	miblist = strdup (DEFAULT_MIBLIST);
+
 	if (process_arguments (argc, argv) == ERROR)
 		usage (_("Incorrect arguments supplied\n"));
 
@@ -287,7 +297,7 @@ main (int argc, char **argv)
 		result = max_state (result, iresult);
 
 		/* Prepend a label for this OID if there is one */
-		if (nlabels > 1 && i < nlabels && labels[i] != NULL)
+		if (nlabels > (size_t)1 && (size_t)i < nlabels && labels[i] != NULL)
 			asprintf (&outbuff, "%s%s%s %s%s%s", outbuff,
 			          (i == 0) ? " " : output_delim,
 			          labels[i], mark (iresult), show, mark (iresult));
@@ -296,7 +306,7 @@ main (int argc, char **argv)
 			          mark (iresult), show, mark (iresult));
 
 		/* Append a unit string for this OID if there is one */
-		if (nunits > 0 && i < nunits && unitv[i] != NULL)
+		if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
 			asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
 
 		i++;
@@ -341,8 +351,8 @@ process_arguments (int argc, char **argv)
 	int c = 1;
 	int j = 0, jj = 0, ii = 0;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		STD_LONG_OPTS,
 		{"community", required_argument, 0, 'C'},
 		{"oid", required_argument, 0, 'o'},
@@ -381,7 +391,7 @@ process_arguments (int argc, char **argv)
 
 	while (1) {
 		c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:",
-									 long_options, &option_index);
+									 longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -401,34 +411,34 @@ process_arguments (int argc, char **argv)
 
 	/* Connection info */
 		case 'C':									/* group or community */
-			community = strscpy (community, optarg);
+			community = optarg;
 			break;
 		case 'H':									/* Host or server */
-			server_address = strscpy (server_address, optarg);
+			server_address = optarg;
 			break;
 		case 'p':       /* TCP port number */
-			port = strscpy(port, optarg);
+			port = optarg;
 			break;
 		case 'm':      /* List of MIBS  */
-			miblist = strscpy(miblist, optarg);
+			miblist = optarg;
 			break;
 		case 'P':     /* SNMP protocol version */
-			proto = strscpy(proto, optarg);
+			proto = optarg;
 			break;
 		case 'L':     /* security level */
-			seclevel = strscpy(seclevel,optarg);
+			seclevel = optarg;
 			break;
 		case 'U':     /* security username */
-			secname = strscpy(secname, optarg);
+			secname = optarg;
 			break;
 		case 'a':     /* auth protocol */
-			asprintf (&authproto, optarg);
+			authproto = optarg;
 			break;
 		case 'A':     /* auth passwd */
-			authpasswd = strscpy(authpasswd, optarg);
+			authpasswd = optarg;
 			break;
 		case 'X':     /* priv passwd */
-			privpasswd = strscpy(privpasswd, optarg);
+			privpasswd = optarg;
 			break;
 		case 't':	/* timeout period */
 			if (!is_integer (optarg))
@@ -585,7 +595,10 @@ process_arguments (int argc, char **argv)
 	}
 
 	if (server_address == NULL)
-		asprintf (&server_address, argv[optind]);
+		server_address = argv[optind];
+
+	if (community == NULL)
+		community = strdup (DEFAULT_COMMUNITY);
 
 	return validate_arguments ();
 }

+ 3 - 3
plugins/check_ssh.c

@@ -70,8 +70,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"help", no_argument, 0, 'h'},
 		{"version", no_argument, 0, 'V'},
 		{"host", required_argument, 0, 'H'},
@@ -91,7 +91,7 @@ process_arguments (int argc, char **argv)
 			strcpy (argv[c], "-t");
 
 	while (1) {
-		c = getopt_long (argc, argv, "+Vhv46t:H:p:", long_options, &option_index);
+		c = getopt_long (argc, argv, "+Vhv46t:H:p:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 64 - 62
plugins/check_swap.c

@@ -34,7 +34,7 @@ const char *revision = "$Revision$";
 const char *copyright = "2000-2003";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
-int check_swap (int usp, int free_swap);
+int check_swap (int usp, long unsigned int free_swap);
 int process_arguments (int argc, char **argv);
 int validate_arguments (void);
 void print_usage (void);
@@ -51,58 +51,6 @@ int allswaps;
 int sun = 0;	/* defined by compiler if it is a sun solaris system */
 #endif
 
-void
-print_usage (void)
-{
-	printf (_("Usage:\n\
- %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\
- %s [-a] -w <bytes_free> -c <bytes_free>\n\
- %s (-h | --help) for detailed help\n\
- %s (-V | --version) for version information\n"),
-	        progname, progname, progname, progname);
-}
-
-
-
-
-
-void
-print_help (void)
-{
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf (_("Check swap space on local server.\n\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_("\n\
- -w, --warning=INTEGER\n\
-   Exit with WARNING status if less than INTEGER bytes of swap space are free\n\
- -w, --warning=PERCENT%%\n\
-   Exit with WARNING status if less than PERCENT of swap space has been used\n\
- -c, --critical=INTEGER\n\
-   Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\
- -c, --critical=PERCENT%%\n\
-   Exit with CRITCAL status if less than PERCENT of swap space has been used\n\
- -a, --allswaps\n\
-    Conduct comparisons for all swap partitions, one by one\n"));
-
-#ifdef sun
-	printf (_("\n\
-On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
-Will be discrepencies because swap -s counts allocated swap and includes\n\
-real memory\n"));
-#endif
-
-	support ();
-}
-
-
-
 int
 main (int argc, char **argv)
 {
@@ -121,7 +69,9 @@ main (int argc, char **argv)
 	FILE *fp;
 #endif
 	char str[32];
-	char *status = "";
+	char *status;
+
+	status = strdup("");
 
 	if (process_arguments (argc, argv) != OK)
 		usage (_("Invalid command arguments supplied\n"));
@@ -233,16 +183,16 @@ main (int argc, char **argv)
 
 
 int
-check_swap (int usp, int free_swap)
+check_swap (int usp, long unsigned int free_swap)
 {
 	int result = STATE_UNKNOWN;
 	if (usp >= 0 && usp >= (100.0 - crit_percent))
 		result = STATE_CRITICAL;
-	else if (crit_size > 0 && (unsigned)free_swap <= crit_size)
+	else if (crit_size > 0 && free_swap <= crit_size)
 		result = STATE_CRITICAL;
 	else if (usp >= 0 && usp >= (100.0 - warn_percent))
 		result = STATE_WARNING;
-	else if (warn_size > 0 && (unsigned)free_swap <= warn_size)
+	else if (warn_size > 0 && free_swap <= warn_size)
 		result = STATE_WARNING;
 	else if (usp >= 0.0)
 		result = STATE_OK;
@@ -258,8 +208,8 @@ process_arguments (int argc, char **argv)
 	int wc = 0; /* warning counter  */
 	int cc = 0; /* critical counter */
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"warning", required_argument, 0, 'w'},
 		{"critical", required_argument, 0, 'c'},
 		{"allswaps", no_argument, 0, 'a'},
@@ -273,7 +223,7 @@ process_arguments (int argc, char **argv)
 		return ERROR;
 
 	while (1) {
-		c = getopt_long (argc, argv, "+?Vvhac:w:", long_options, &option_index);
+		c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -296,7 +246,6 @@ process_arguments (int argc, char **argv)
 			else {
 				usage (_("Warning threshold must be integer or percentage!\n"));
 			}
-			wc++;
 		case 'c':									/* critical time threshold */
 			if (is_intnonneg (optarg)) {
 				crit_size = atoi (optarg);
@@ -314,7 +263,6 @@ process_arguments (int argc, char **argv)
 			else {
 				usage (_("Critical threshold must be integer or percentage!\n"));
 			}
-			cc++;
 		case 'a':									/* all swap */
 			allswaps = TRUE;
 			break;
@@ -377,3 +325,57 @@ validate_arguments (void)
 	}
 	return OK;
 }
+
+
+
+
+
+
+void
+print_help (void)
+{
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf (_("Check swap space on local server.\n\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_("\n\
+ -w, --warning=INTEGER\n\
+   Exit with WARNING status if less than INTEGER bytes of swap space are free\n\
+ -w, --warning=PERCENT%%\n\
+   Exit with WARNING status if less than PERCENT of swap space has been used\n\
+ -c, --critical=INTEGER\n\
+   Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\
+ -c, --critical=PERCENT%%\n\
+   Exit with CRITCAL status if less than PERCENT of swap space has been used\n\
+ -a, --allswaps\n\
+    Conduct comparisons for all swap partitions, one by one\n"));
+
+#ifdef sun
+	printf (_("\n\
+On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
+Will be discrepencies because swap -s counts allocated swap and includes\n\
+real memory\n"));
+#endif
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("Usage:\n\
+ %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\
+ %s [-a] -w <bytes_free> -c <bytes_free>\n\
+ %s (-h | --help) for detailed help\n\
+ %s (-V | --version) for version information\n"),
+	        progname, progname, progname, progname);
+}

+ 3 - 3
plugins/check_tcp.c

@@ -345,8 +345,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"critical-time", required_argument, 0, 'c'},
 		{"warning-time", required_argument, 0, 'w'},
@@ -391,7 +391,7 @@ process_arguments (int argc, char **argv)
 
 	while (1) {
 		c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:",
-		                 long_options, &option_index);
+		                 longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;

+ 5 - 5
plugins/check_time.c

@@ -138,8 +138,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"warning-variance", required_argument, 0, 'w'},
 		{"critical-variance", required_argument, 0, 'c'},
@@ -169,8 +169,8 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", long_options,
-									 &option_index);
+		c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", longopts,
+									 &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -307,7 +307,7 @@ This plugin will check the time on the specified host.\n\n"));
 
 	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
 
-	support ();
+	printf (_(UT_SUPPORT));
 }
 
 

+ 3 - 3
plugins/check_udp.c

@@ -105,8 +105,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"critical", required_argument, 0, 'c'},
 		{"warning", required_argument, 0, 'w'},
@@ -133,7 +133,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", long_options, &option_index);
+		c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;

+ 4 - 4
plugins/check_ups.c

@@ -400,8 +400,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"hostname", required_argument, 0, 'H'},
 		{"ups", required_argument, 0, 'u'},
 		{"port", required_argument, 0, 'p'},
@@ -427,8 +427,8 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", long_options,
-									 &option_index);
+		c = getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", longopts,
+									 &option);
 
 		if (c == -1 || c == EOF)
 			break;

+ 3 - 3
plugins/check_users.c

@@ -107,8 +107,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"critical", required_argument, 0, 'c'},
 		{"warning", required_argument, 0, 'w'},
 		{"version", no_argument, 0, 'V'},
@@ -120,7 +120,7 @@ process_arguments (int argc, char **argv)
 		usage ("\n");
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index);
+		c = getopt_long (argc, argv, "+hVvc:w:", longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
 			break;

+ 91 - 97
plugins/negate.c

@@ -14,84 +14,12 @@
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-******************************************************************************/
-
-const char *progname = "negate";
-const char *revision = "$Revision$";
-const char *copyright = "2002-2003";
-const char *email = "nagiosplug-devel@lists.sourceforge.net";
-
-#define DEFAULT_TIMEOUT 9
-
-#include "common.h"
-#include "utils.h"
-#include "popen.h"
-
-void
-print_usage (void)
-{
-	printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"),
-	        progname);
-	printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
-	print_revision (progname, revision);
-
-	printf (_(COPYRIGHT), copyright, email);
-
-	printf (_("\
-Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\
-\n"));
-
-	print_usage ();
-
-	printf (_(UT_HELP_VRSN));
-
-	printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
-
-	printf (_("\
-     [keep timeout than the plugin timeout to retain CRITICAL status]\n"));
-
-	printf (_("\
-  negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\
-    Run check_ping and invert result. Must use full path to plugin\n\
-  negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\
-    Use single quotes if you need to retain spaces\n"));
-
-	printf (_("\
-This plugin is a wrapper to take the output of another plugin and invert it.\n\
-If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\
-If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\
-Otherwise, the output state of the wrapped plugin is unchanged.\n"));
-
-	printf (_(UT_SUPPORT));
-}
-
-char *command_line;
-
-int process_arguments (int, char **);
-int validate_arguments (void);
-/******************************************************************************
-
-The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
-tags in the comments. With in the tags, the XML is assembled sequentially.
-You can define entities in tags. You also have all the #defines available as
-entities.
-
-Please note that all tags must be lowercase to use the DocBook XML DTD.
-
 @@-<article>
 
 <sect1>
 <title>Quick Reference</title>
-<!-- The refentry forms a manpage -->
 <refentry>
-<refmeta>
-<manvolnum>5<manvolnum>
-</refmeta>
+<refmeta><manvolnum>5<manvolnum></refmeta>
 <refnamdiv>
 <refname>&progname;</refname>
 <refpurpose>&SUMMARY;</refpurpose>
@@ -119,19 +47,33 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
 <itemizedlist>
 <listitem>Add option to do regex substitution in output text</listitem>
 </itemizedlist>
-</sect2>
-
+</sect2>-@@
 
-<sect2>
-<title>Functions</title>
--@@
 ******************************************************************************/
 
+const char *progname = "negate";
+const char *revision = "$Revision$";
+const char *copyright = "2002-2003";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
+
+#define DEFAULT_TIMEOUT 9
+
+#include "common.h"
+#include "utils.h"
+#include "popen.h"
+
+char *command_line;
+
+int process_arguments (int, char **);
+int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
+
 int
 main (int argc, char **argv)
 {
 	int found = 0, result = STATE_UNKNOWN;
-	char input_buffer[MAX_INPUT_BUFFER];
+	char *buf;
 
 	if (process_arguments (argc, argv) == ERROR)
 		usage (_("Could not parse arguments\n"));
@@ -151,27 +93,22 @@ main (int argc, char **argv)
 		printf (_("Could not open stderr for %s\n"), command_line);
 	}
 
-	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
+	buf = malloc(MAX_INPUT_BUFFER);
+	while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
 		found++;
-		if (strchr (input_buffer, '\n')) {
-			input_buffer[strcspn (input_buffer, "\n")] = 0;
-			printf ("%s\n", input_buffer);
-		}
-		else {
-			printf ("%s\n", input_buffer);
-		}
+		printf ("%s", buf);
 	}
 
 	if (!found)
-		die (STATE_UNKNOWN,\
-		           _("%s problem - No data recieved from host\nCMD: %s\n"),\
-		           argv[0],	command_line);
+		die (STATE_UNKNOWN,
+		     _("%s problem - No data recieved from host\nCMD: %s\n"),\
+		     argv[0], command_line);
 
 	/* close the pipe */
 	result = spclose (child_process);
 
 	/* WARNING if output found on stderr */
-	if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
+	if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
 		result = max_state (result, STATE_WARNING);
 
 	/* close stderr */
@@ -189,6 +126,9 @@ main (int argc, char **argv)
 
 /******************************************************************************
 @@-
+<sect2>
+<title>Functions</title>
+
 <sect3>
 <title>process_arguments</title>
 
@@ -196,7 +136,7 @@ main (int argc, char **argv)
 variables.</para>
 
 <para>Aside from the standard 'help' and 'version' options, there
-is a only a 'timeout' option.No validation is currently done.</para>
+is a only a 'timeout' option.</para>
 
 </sect3>
 -@@
@@ -208,8 +148,8 @@ process_arguments (int argc, char **argv)
 {
 	int c;
 
-	int option_index = 0;
-	static struct option long_options[] = {
+	int option = 0;
+	static struct option longopts[] = {
 		{"help", no_argument, 0, 'h'},
 		{"version", no_argument, 0, 'V'},
 		{"timeout", required_argument, 0, 't'},
@@ -218,7 +158,7 @@ process_arguments (int argc, char **argv)
 
 	while (1) {
 		c = getopt_long (argc, argv, "+hVt:",
-		                 long_options, &option_index);
+		                 longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -226,16 +166,19 @@ process_arguments (int argc, char **argv)
 		switch (c) {
 		case '?':     /* help */
 			usage3 (_("Unknown argument"), optopt);
+			break;
 		case 'h':     /* help */
 			print_help ();
 			exit (EXIT_SUCCESS);
+			break;
 		case 'V':     /* version */
 			print_revision (progname, revision);
 			exit (EXIT_SUCCESS);
 		case 't':     /* timeout period */
 			if (!is_integer (optarg))
 				usage2 (_("Timeout Interval must be an integer"), optarg);
-			timeout_interval = atoi (optarg);
+			else
+				timeout_interval = atoi (optarg);
 			break;
 		}
 	}
@@ -267,7 +210,6 @@ validate_arguments ()
 		return ERROR;
 	return STATE_OK;
 }
-
 
 /******************************************************************************
 @@-
@@ -276,3 +218,55 @@ validate_arguments ()
 </article>
 -@@
 ******************************************************************************/
+
+
+
+
+
+
+void
+print_help (void)
+{
+	print_revision (progname, revision);
+
+	printf (_(COPYRIGHT), copyright, email);
+
+	printf (_("\
+Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\
+\n"));
+
+	print_usage ();
+
+	printf (_(UT_HELP_VRSN));
+
+	printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
+
+	printf (_("\
+     [keep timeout than the plugin timeout to retain CRITICAL status]\n"));
+
+	printf (_("\
+  negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\
+    Run check_ping and invert result. Must use full path to plugin\n\
+  negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\
+    Use single quotes if you need to retain spaces\n"));
+
+	printf (_("\
+This plugin is a wrapper to take the output of another plugin and invert it.\n\
+If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\
+If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\
+Otherwise, the output state of the wrapped plugin is unchanged.\n"));
+
+	printf (_(UT_SUPPORT));
+}
+
+
+
+
+
+void
+print_usage (void)
+{
+	printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"),
+	        progname);
+	printf (_(UT_HLP_VRS), progname, progname);
+}

+ 1 - 2
plugins/popen.c

@@ -18,8 +18,7 @@ int spclose(FILE *);
  *
  ******************************************************************************/
 
-#include <config.h>
-#include <common.h>
+#include "common.h"
 
 /* extern so plugin has pid to kill exec'd process on timeouts */
 extern int timeout_interval;

+ 114 - 111
plugins/urlize.c

@@ -1,41 +1,20 @@
 /******************************************************************************
- *
- * urlize.c
- *
- * Program: plugin wrapper for Nagios
- * License: GPL
- * Copyright (c) 2000 Karl DeBisschop (kdebiss@alum.mit.edu)
- *
- * Last Modified: $Date$
- * 2000-06-01 Karl DeBisschop <karl@debisschop.net>
- *  Written based of concept in urlize.pl
- *
- * Usage: urlize <url> <plugin> <arg1> ... <argN>
- *
- * Description:
- *
- * This plugin wraps the text output of another command (plugin) in HTML
- * <A> tags, thus displaying the plugin output in as a clickable link in
- * the Nagios status screen.  The return status is the same as the plugin
- * invoked by urlize
- *
- * License Information:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *****************************************************************************/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+******************************************************************************/
 
 const char *progname = "urlize";
 const char *revision = "$Revision$";
@@ -46,12 +25,101 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #include "utils.h"
 #include "popen.h"
 
-void
-print_usage (void)
+void print_help (void);
+void print_usage (void);
+
+int
+main (int argc, char **argv)
 {
-	printf (_("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n"), progname);
+	int found = 0, result = STATE_UNKNOWN;
+	char *url = NULL;
+	char *cmd;
+	char *buf;
+
+	int c;
+	int option = 0;
+	static struct option longopts[] = {
+		{"help", no_argument, 0, 'h'},
+		{"version", no_argument, 0, 'V'},
+		{"url", required_argument, 0, 'u'},
+		{0, 0, 0, 0}
+	};
+
+	while (1) {
+		c = getopt_long (argc, argv, "+hVu:", longopts, &option);
+
+		if (c == -1 || c == EOF)
+			break;
+
+		switch (c) {
+		case 'h':     /* help */
+			print_help ();
+			exit (EXIT_SUCCESS);
+			break;
+		case 'V':     /* version */
+			print_revision (progname, revision);
+			exit (EXIT_SUCCESS);
+			break;
+		case 'u':
+			url = strdup (argv[optind]);
+			break;
+		case '?':
+		default:
+			usage3 (_("Unknown argument"), optopt);
+			break;
+		}
+	}
+
+	if (url == NULL)
+		url = strdup (argv[optind++]);
+
+	cmd = strdup (argv[optind++]);
+	for (c = optind; c < argc; c++) {
+		asprintf (&cmd, "%s %s", cmd, argv[c]);
+	}
+
+	child_process = spopen (cmd);
+	if (child_process == NULL) {
+		printf (_("Could not open pipe: %s\n"), cmd);
+		exit (STATE_UNKNOWN);
+	}
+
+	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
+	if (child_stderr == NULL) {
+		printf (_("Could not open stderr for %s\n"), cmd);
+	}
+
+	buf = malloc(MAX_INPUT_BUFFER);
+	printf ("<A href=\"%s\">", argv[1]);
+	while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
+		found++;
+		printf ("%s", buf);
+	}
+
+	if (!found)
+		die (STATE_UNKNOWN,
+		     _("%s problem - No data recieved from host\nCMD: %s</A>\n"),
+		     argv[0], cmd);
+
+	/* close the pipe */
+	result = spclose (child_process);
+
+	/* WARNING if output found on stderr */
+	if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
+		result = max_state (result, STATE_WARNING);
+
+	/* close stderr */
+	(void) fclose (child_stderr);
+
+	printf ("</A>\n");
+	return result;
 }
 
+
+
+
+
+
 void
 print_help (void)
 {
@@ -81,80 +149,15 @@ the shell will remove the single quotes and urlize will see:\n\
 You probably want:\n\
 \n\
     urlize http://example.com/ \"check_http -H example.com -r 'two words'\"\n"));
-	exit (STATE_OK);
-}
-
-int
-main (int argc, char **argv)
-{
-	int i = 0, found = 0, result = STATE_UNKNOWN;
-	char *cmd = NULL;
-	char input_buffer[MAX_INPUT_BUFFER];
-
-	if (argc < 2) {
-		print_usage ();
-		exit (STATE_UNKNOWN);
-	}
-
-	if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) {
-		print_help ();
-		exit (STATE_OK);
-	}
-
-	if (!strcmp (argv[1], "-V") || !strcmp (argv[1], "--version")) {
-		print_revision (progname, revision);
-		exit (STATE_OK);
-	}
-
-	if (argc < 2) {
-		print_usage ();
-		exit (STATE_UNKNOWN);
-	}
-
-	asprintf (&cmd, "%s", argv[2]);
-	for (i = 3; i < argc; i++) {
-		asprintf (&cmd, "%s %s", cmd, argv[i]);
-	}
-
-	child_process = spopen (cmd);
-	if (child_process == NULL) {
-		printf (_("Could not open pipe: %s\n"), cmd);
-		exit (STATE_UNKNOWN);
-	}
-
-	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
-	if (child_stderr == NULL) {
-		printf (_("Could not open stderr for %s\n"), cmd);
-	}
-
-	printf ("<A href=\"%s\">", argv[1]);
-	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
-		found++;
-		if (index (input_buffer, '\n')) {
-			input_buffer[strcspn (input_buffer, "\n")] = 0;
-			printf ("%s", input_buffer);
-		}
-		else {
-			printf ("%s", input_buffer);
-		}
-	}
 
-	if (!found) {
-		printf (_("%s problem - No data recieved from host\nCMD: %s</A>\n"), argv[0],
-						cmd);
-		exit (STATE_UNKNOWN);
-	}
+	printf (_(UT_SUPPORT));
+}
 
-	/* close the pipe */
-	result = spclose (child_process);
 
-	/* WARNING if output found on stderr */
-	if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
-		result = max_state (result, STATE_WARNING);
 
-	/* close stderr */
-	(void) fclose (child_stderr);
 
-	printf ("</A>\n");
-	return result;
+void
+print_usage (void)
+{
+	printf (_("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n"), progname);
 }