[Nagiosplug-checkins] SF.net SVN: nagiosplug:[2213] nagiosplug/trunk

dermoth at users.sourceforge.net dermoth at users.sourceforge.net
Thu Jun 11 17:29:22 CEST 2009


Revision: 2213
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2213&view=rev
Author:   dermoth
Date:     2009-06-11 15:29:21 +0000 (Thu, 11 Jun 2009)

Log Message:
-----------
Fixed SNMPv3 behaviour of check_ifoperstatus. Added -x to define privprotocol (#2343438 - Robin Schroeder)

check_ifoperstatus didn't function correctly with SNMPv3. This is fixed now.
Created argument-hash for SNMP session creation. This removes redundant code.
Session creation was moved out of process_arguments() and now takes place
after setting the timeout handler.

Additionally the -x argument was added to specify the privprotocol.

From: Matthias Eble <psychotrahe at gmx.de>

Modified Paths:
--------------
    nagiosplug/trunk/NEWS
    nagiosplug/trunk/THANKS.in
    nagiosplug/trunk/lib/extra_opts.h
    nagiosplug/trunk/lib/tests/test_opts1.c
    nagiosplug/trunk/lib/tests/test_opts2.c
    nagiosplug/trunk/lib/utils_base.c
    nagiosplug/trunk/plugins-root/check_icmp.c
    nagiosplug/trunk/plugins-scripts/check_ifoperstatus.pl

Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/NEWS	2009-06-11 15:29:21 UTC (rev 2213)
@@ -39,6 +39,7 @@
 	Fixed check_by_ssh interpretation of quotes in -C parameter (#1985246, #2268675)
 	check_snmp now supports standard threshold ranges and doubles (floating numbers) in thresholds
 	check_fping now supports passing target timeout and interval to fping (#2347686 - Martin Foster)
+	Fixed SNMPv3 behaviour of check_ifoperstatus. Added -x to define privprotocol (#2343438 - Robin Schroeder)
 
 1.4.13 25th Sept 2008
 	Fix Debian bug #460097: check_http --max-age broken (Hilko Bengen)

Modified: nagiosplug/trunk/THANKS.in
===================================================================
--- nagiosplug/trunk/THANKS.in	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/THANKS.in	2009-06-11 15:29:21 UTC (rev 2213)
@@ -254,4 +254,3 @@
 Martin Foster
 Joe Presbrey
 Will Preston
-Nikita Kalabukhov

Modified: nagiosplug/trunk/lib/extra_opts.h
===================================================================
--- nagiosplug/trunk/lib/extra_opts.h	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/lib/extra_opts.h	2009-06-11 15:29:21 UTC (rev 2213)
@@ -8,14 +8,11 @@
 
 /* np_extra_opts: Process the --extra-opts arguments and create a new argument
  * array with ini-processed and argument-passed arguments together. The
- * ini-procesed arguments always come first (in the order of --extra-opts
+ * ini-procesed arguments always come first (in the ord of --extra-opts
  * arguments). If no --extra-opts arguments are provided or returned nothing
  * it returns **argv otherwise the new array is returned. --extra-opts are
  * always removed from **argv. The original pointers from **argv are kept in
  * the new array to preserve ability to overwrite arguments in processlist.
- *
- * The new array can be easily freed as long as a pointer to the original one
- * is kept. See my_free() in lib/tests/test_opts1.c for an example.
  */
 char **np_extra_opts(int *argc, char **argv, const char *plugin_name);
 

Modified: nagiosplug/trunk/lib/tests/test_opts1.c
===================================================================
--- nagiosplug/trunk/lib/tests/test_opts1.c	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/lib/tests/test_opts1.c	2009-06-11 15:29:21 UTC (rev 2213)
@@ -21,44 +21,14 @@
 
 #include "tap.h"
 
-/* This my_free would be the most efficient way of freeing an extra-opts array,
- * provided as an example */
-#if 0
-void my_free(int *argc, char **newargv, char **argv) {
+void my_free(int *argc, char **argv) {
 	int i;
-	/* Return if both arrays are the same */
-	if (newargv == argv) return;
-
-	for (i=1; i<*argc; i++) {
-		/* Free array items until we reach the start of the original argv */
-		if (newargv[i] == argv[1]) break;
-		free(newargv[i]);
-	}
-	/* Free the array itself */
-	free(newargv);
-}
-#else
-void my_free(int *argc, char **newargv, char **argv) {
-	/* Free stuff (and print while we're at it) */
-	int i, freeflag=1;
-	printf ("    Arg(%i): ", *argc+1);
-	printf ("'%s' ", newargv[0]);
-	for (i=1; i<*argc; i++) {
-		printf ("'%s' ", newargv[i]);
-		/* Stop freeing when we get to the start of the original array */
-		if (freeflag) {
-			if (newargv[i] == argv[1])
-				freeflag=0;
-			else
-				free(newargv[i]);
-		}
-	}
+	printf ("    Arg(%i): ", *argc);
+	for (i=1; i<*argc; i++) printf ("'%s' ", argv[i]);
 	printf ("\n");
-	/* Free only if it's a different array */
-	if (newargv != argv) free(newargv);
+	free(argv);
 	*argc=0;
 }
-#endif
 
 int array_diff(int i1, char **a1, int i2, char **a2) {
 	int i;
@@ -84,55 +54,94 @@
 int
 main (int argc, char **argv)
 {
-	char **argv_new=NULL;
+	char **argv_test=NULL, **argv_known=NULL;
 	int i, argc_test;
 
 	plan_tests(5);
 
-	{
-		char *argv_test[] = {"prog_name", (char *) NULL};
-		argc_test=1;
-		char *argv_known[] = {"prog_name", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(2*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = NULL;
+	argc_test=1;
+	argv_known=(char **)realloc(argv_known, 2*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 1, argv_known), "No opts, returns correct argv/argc");
+	my_free(&argc_test, argv_test);
 
-	{
-		char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL};
-		argc_test=5;
-		char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--arg2=val1";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "arg1";
+	argv_known[2] = "--arg2=val1";
+	argv_known[3] = "--arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "No extra opts, verbatim copy of argv");
+	my_free(&argc_test,argv_test);
 
-	{
-		char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *) NULL};
-		argc_test=2;
-		char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(3*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--extra-opts=@./config-opts.ini";
+	argv_test[2] = NULL;
+	argc_test=2;
+	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=Bar";
+	argv_known[2] = "--this=Your Mother!";
+	argv_known[3] = "--blank";
+	argv_known[4] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts using default section");
+	my_free(&argc_test,argv_test);
 
-	{
-		char *argv_test[] = {"prog_name", "--extra-opts=sect1 at ./config-opts.ini", "--extra-opts", "sect2 at ./config-opts.ini", (char *) NULL};
-		argc_test=4;
-		char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(5*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--extra-opts=sect1 at ./config-opts.ini";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "sect2 at ./config-opts.ini";
+	argv_test[4] = NULL;
+	argc_test=4;
+	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--one=two";
+	argv_known[2] = "--something else=oops";
+	argv_known[3] = "--this=that";
+	argv_known[4] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts specified twice");
+	my_free(&argc_test,argv_test);
 
-	{
-		char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1 at ./config-opts.ini", "--arg2", (char *) NULL};
-		argc_test=6;
-		char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", "--arg1=val1", "--arg2", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(7*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--arg1=val1";
+	argv_test[2] = "--extra-opts=@./config-opts.ini";
+	argv_test[3] = "--extra-opts";
+	argv_test[4] = "sect1 at ./config-opts.ini";
+	argv_test[5] = "--arg2";
+	argv_test[6] = NULL;
+	argc_test=6;
+	argv_known=(char **)realloc(argv_known, 8*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=Bar";
+	argv_known[2] = "--this=Your Mother!";
+	argv_known[3] = "--blank";
+	argv_known[4] = "--one=two";
+	argv_known[5] = "--arg1=val1";
+	argv_known[6] = "--arg2";
+	argv_known[7] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 7, argv_known), "twice extra opts using two sections");
+	my_free(&argc_test,argv_test);
 
 	return exit_status();
 }

Modified: nagiosplug/trunk/lib/tests/test_opts2.c
===================================================================
--- nagiosplug/trunk/lib/tests/test_opts2.c	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/lib/tests/test_opts2.c	2009-06-11 15:29:21 UTC (rev 2213)
@@ -21,24 +21,12 @@
 
 #include "tap.h"
 
-void my_free(int *argc, char **newargv, char **argv) {
-	/* Free stuff (and print while we're at it) */
-	int i, freeflag=1;
-	printf ("    Arg(%i): ", *argc+1);
-	printf ("'%s' ", newargv[0]);
-	for (i=1; i<*argc; i++) {
-		printf ("'%s' ", newargv[i]);
-		/* Stop freeing when we get to the start of the original array */
-		if (freeflag) {
-			if (newargv[i] == argv[1])
-				freeflag=0;
-			else
-				free(newargv[i]);
-		}
-	}
+void my_free(int *argc, char **argv) {
+	int i;
+	printf ("    Arg(%i): ", *argc);
+	for (i=1; i<*argc; i++) printf ("'%s' ", argv[i]);
 	printf ("\n");
-	/* Free only if it's a different array */
-	if (newargv != argv) free(newargv);
+	free(argv);
 	*argc=0;
 }
 
@@ -66,55 +54,97 @@
 int
 main (int argc, char **argv)
 {
-	char **argv_new=NULL;
+	char **argv_test=NULL, **argv_known=NULL;
 	int i, argc_test;
 
 	plan_tests(5);
 
-	{
-		char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *) NULL};
-		argc_test=5;
-		char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 1");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=bar";
+	argv_known[2] = "arg1";
+	argv_known[3] = "--arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1");
 
-	{
-		char *argv_test[] = {"prog_name", "--extra-opts", (char *) NULL};
-		argc_test=2;
-		char *argv_known[] = {"prog_name", "--foo=bar", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 2, argv_known), "Default section 2");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(3*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--extra-opts";
+	argv_test[2] = NULL;
+	argc_test=2;
+	argv_known=(char **)realloc(argv_known, 3*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=bar";
+	argv_known[2] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 2, argv_known), "Default section 2");
+	my_free(&argc_test,argv_test);
 
-	{
-		char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *) NULL};
-		argc_test=5;
-		char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 3");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts=section1";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foobar=baz";
+	argv_known[2] = "arg1";
+	argv_known[3] = "--arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3");
+	my_free(&argc_test,argv_test);
 
-	{
-		char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *) NULL};
-		argc_test=5;
-		char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
-		ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 4");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "-arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=bar";
+	argv_known[2] = "arg1";
+	argv_known[3] = "-arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 4");
+	my_free(&argc_test,argv_test);
 
-	{
-		char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *) NULL};
-		argc_test=3;
-		char *argv_known[] = {"check_tcp", "--timeout=10", "--escape", "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", "--jail", (char *) NULL};
-		argv_new=np_extra_opts(&argc_test, argv_test, "check_tcp");
-		ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test");
-		my_free(&argc_test, argv_new, argv_test);
-	}
+	argv_test=(char **)malloc(4*sizeof(char **));
+	argv_test[0] = "check_tcp";
+	argv_test[1] = "--extra-opts";
+	argv_test[2] = "--extra-opts=tcp_long_lines";
+	argv_test[3] = NULL;
+	argc_test=3;
+	argv_known=(char **)realloc(argv_known, 7*sizeof(char **));
+	argv_known[0] = "check_tcp";
+	argv_known[1] = "--timeout=10";
+	argv_known[2] = "--escape";
+	argv_known[3] = "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
+	argv_known[4] = "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
+	argv_known[5] = "--jail";
+	argv_known[6] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_tcp");
+	ok(array_diff(argc_test, argv_test, 6, argv_known), "Long lines test");
+	my_free(&argc_test,argv_test);
 
 	return exit_status();
 }

Modified: nagiosplug/trunk/lib/utils_base.c
===================================================================
--- nagiosplug/trunk/lib/utils_base.c	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/lib/utils_base.c	2009-06-11 15:29:21 UTC (rev 2213)
@@ -101,9 +101,7 @@
 {
 	thresholds *temp_thresholds = NULL;
 
-	if ((temp_thresholds = malloc(sizeof(thresholds))) == NULL)
-		die(STATE_UNKNOWN, _("Cannot allocate memory: %s\n"),
-		    strerror(errno));
+	temp_thresholds = malloc(sizeof(temp_thresholds));
 
 	temp_thresholds->warning = NULL;
 	temp_thresholds->critical = NULL;

Modified: nagiosplug/trunk/plugins-root/check_icmp.c
===================================================================
--- nagiosplug/trunk/plugins-root/check_icmp.c	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/plugins-root/check_icmp.c	2009-06-11 15:29:21 UTC (rev 2213)
@@ -184,14 +184,14 @@
 static u_int get_timevaldiff(struct timeval *, struct timeval *);
 static in_addr_t get_ip_address(const char *);
 static int wait_for_reply(int, u_int);
-static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *);
+static int recvfrom_wto(int, char *, unsigned int, struct sockaddr *, u_int *);
 static int send_icmp_ping(int, struct rta_host *);
 static int get_threshold(char *str, threshold *th);
 static void run_checks(void);
 static void set_source_ip(char *);
 static int add_target(char *);
 static int add_target_ip(char *, struct in_addr *);
-static int handle_random_icmp(unsigned char *, struct sockaddr_in *);
+static int handle_random_icmp(char *, struct sockaddr_in *);
 static unsigned short icmp_checksum(unsigned short *, int);
 static void finish(int);
 static void crash(const char *, ...);
@@ -300,7 +300,7 @@
 }
 
 static int
-handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr)
+handle_random_icmp(char *packet, struct sockaddr_in *addr)
 {
 	struct icmp p, sent_icmp;
 	struct rta_host *host = NULL;
@@ -694,7 +694,7 @@
 wait_for_reply(int sock, u_int t)
 {
 	int n, hlen;
-	static unsigned char buf[4096];
+	static char buf[4096];
 	struct sockaddr_in resp_addr;
 	struct ip *ip;
 	struct icmp icp;
@@ -814,7 +814,7 @@
 send_icmp_ping(int sock, struct rta_host *host)
 {
 	static union {
-		void *buf; /* re-use so we prevent leaks */
+		char *buf; /* re-use so we prevent leaks */
 		struct icmp *icp;
 		u_short *cksum_in;
 	} packet = { NULL };
@@ -867,7 +867,7 @@
 }
 
 static int
-recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr,
+recvfrom_wto(int sock, char *buf, unsigned int len, struct sockaddr *saddr,
 			 u_int *timo)
 {
 	u_int slen;

Modified: nagiosplug/trunk/plugins-scripts/check_ifoperstatus.pl
===================================================================
--- nagiosplug/trunk/plugins-scripts/check_ifoperstatus.pl	2009-06-11 04:17:19 UTC (rev 2212)
+++ nagiosplug/trunk/plugins-scripts/check_ifoperstatus.pl	2009-06-11 15:29:21 UTC (rev 2213)
@@ -61,7 +61,7 @@
 my $snmpkey = 0;
 my $community = "public";
 my $maxmsgsize = 1472 ; # Net::SNMP default is 1472
-my ($seclevel, $authproto, $secname, $authpass, $privpass, $auth, $priv, $context);
+my ($seclevel, $authproto, $secname, $authpass, $privpass, $privproto, $auth, $priv, $context);
 my $port = 161;
 my @snmpoids;
 my $sysUptime        = '1.3.6.1.2.1.1.3.0';
@@ -89,12 +89,14 @@
 my $dormantWarn;
 my $adminWarn;
 my $name;
+my %session_opts;
 
 ### Validate Arguments
 
 $status = process_arguments();
 
 
+use Data::Dumper;
 # Just in case of problems, let's not hang Nagios
 $SIG{'ALRM'} = sub {
      print ("ERROR: No snmp response from $hostname (alarm)\n");
@@ -103,7 +105,17 @@
 
 alarm($timeout);
 
+print Dumper(\%session_opts);
+($session, $error) = Net::SNMP->session(%session_opts);
 
+		
+if (!defined($session)) {
+			$state='UNKNOWN';
+			$answer=$error;
+			print ("$state: $answer\n");
+			exit $ERRORS{$state};
+}
+
 ## map ifdescr to ifindex - should look at being able to cache this value
 
 if (defined $ifdescr || defined $iftype) {
@@ -293,6 +305,7 @@
 	printf "   -X (--privpass)   privacy password (cleartext ascii or localized key\n";
 	printf "                     in hex with 0x prefix generated by using	\"snmpkey\" utility\n"; 
 	printf "                     privacy password and authEngineID\n";
+	printf "   -x (--privproto)  privacy protocol (DES or AES; default: DES)\n";
 	printf "   -k (--key)        SNMP IfIndex value\n";
 	printf "   -d (--descr)      SNMP ifDescr value\n";
 	printf "   -T (--type)       SNMP ifType integer value (see http://www.iana.org/assignments/ianaiftype-mib)\n";
@@ -327,6 +340,7 @@
 			"U=s" => \$secname,   "secname=s"   => \$secname,
 			"A=s" => \$authpass,  "authpass=s"  => \$authpass,
 			"X=s" => \$privpass,  "privpass=s"  => \$privpass,
+			"x=s" => \$privproto,  "privproto=s"  => \$privproto,
 			"c=s" => \$context,   "context=s"   => \$context,
 			"k=i" => \$snmpkey, "key=i",\$snmpkey,
 			"d=s" => \$ifdescr, "descr=s" => \$ifdescr,
@@ -387,10 +401,27 @@
 		$timeout = $TIMEOUT;
 	}
 
+		
+	if ($snmp_version !~ /[123]/){
+		$state='UNKNOWN';
+		print ("$state: No support for SNMP v$snmp_version yet\n");
+		exit $ERRORS{$state};
+	}
+
+	%session_opts = (
+		-hostname  => $hostname,
+		-port      => $port,
+		-version	=> $snmp_version,
+		-maxmsgsize => $maxmsgsize
+	);
+
+	$session_opts{'-community'} = $community if (defined $community && $snmp_version =~ /[12]/);
+
 	if ($snmp_version =~ /3/ ) {
 		# Must define a security level even though default is noAuthNoPriv
 		# v3 requires a security username
 		if (defined $seclevel  && defined $secname) {
+			$session_opts{'-username'} = $secname;
 		
 			# Must define a security level even though defualt is noAuthNoPriv
 			unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) {
@@ -400,23 +431,22 @@
 			
 			# Authentication wanted
 			if ( $seclevel eq 'authNoPriv' || $seclevel eq 'authPriv' ) {
-		
 				unless ( $authproto eq 'MD5' || $authproto eq 'SHA1' ) {
 					usage();
 					exit $ERRORS{"UNKNOWN"};
 				}
+				$session_opts{'-authprotocol'} = $authproto if(defined $authproto);
 
 				if ( !defined $authpass) {
 					usage();
 					exit $ERRORS{"UNKNOWN"};
 				}else{
 					if ($authpass =~ /^0x/ ) {
-						$auth = "-authkey => $authpass" ;
+						$session_opts{'-authkey'} = $authpass ;
 					}else{
-						$auth = "-authpassword => $authpass";
+						$session_opts{'-authpassword'} = $authpass ;
 					}
 				}
-					
 			}
 			
 			# Privacy (DES encryption) wanted
@@ -426,21 +456,20 @@
 					exit $ERRORS{"UNKNOWN"};
 				}else{
 					if ($privpass =~ /^0x/){
-						$priv = "-privkey => $privpass";
+						$session_opts{'-privkey'} = $privpass;
 					}else{
-						$priv = "-privpassword => $privpass";
+						$session_opts{'-privpassword'} = $privpass;
 					}
 				}
+
+				$session_opts{'-privprotocol'} = $privproto if(defined $privproto);
 			}
 
 			# Context name defined or default
-
 			unless ( defined $context) {
 				$context = "";
 			}
 		
-		
-		
 		}else {
 					usage();
 					exit $ERRORS{'UNKNOWN'}; ;
@@ -448,67 +477,6 @@
 	} # end snmpv3
 
 
-	if ( $snmp_version =~ /[12]/ ) {
-  	($session, $error) = Net::SNMP->session(
-			-hostname  => $hostname,
-			-community => $community,
-			-port      => $port,
-			-version	=> $snmp_version,
-			-maxmsgsize => $maxmsgsize
-		);
-
-		if (!defined($session)) {
-			$state='UNKNOWN';
-			$answer=$error;
-			print ("$state: $answer\n");
-			exit $ERRORS{$state};
-		}
-	
-	}elsif ( $snmp_version =~ /3/ ) {
-
-		if ($seclevel eq 'noAuthNoPriv') {
-			($session, $error) = Net::SNMP->session(
-				-hostname  => $hostname,
-				-port      => $port,
-				-version  => $snmp_version,
-				-username => $secname,
-			);
-
-		}elsif ( $seclevel eq 'authNoPriv' ) {
-			($session, $error) = Net::SNMP->session(
-				-hostname  => $hostname,
-				-port      => $port,
-				-version  => $snmp_version,
-				-username => $secname,
-				$auth,
-				-authprotocol => $authproto,
-			);	
-		}elsif ($seclevel eq 'authPriv' ) {
-			($session, $error) = Net::SNMP->session(
-				-hostname  => $hostname,
-				-port      => $port,
-				-version  => $snmp_version,
-				-username => $secname,
-				$auth,
-				-authprotocol => $authproto,
-				$priv
-			);
-		}
-					
-					
-		if (!defined($session)) {
-					$state='UNKNOWN';
-					$answer=$error;
-					print ("$state: $answer\n");
-					exit $ERRORS{$state};
-		}
-
-	}else{
-		$state='UNKNOWN';
-		print ("$state: No support for SNMP v$snmp_version yet\n");
-		exit $ERRORS{$state};
-	}
-
 }
 ## End validation
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list