[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ldap.c,1.3,1.4

Karl DeBisschop kdebisschop at users.sourceforge.net
Tue Jan 28 22:17:05 CET 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv25402/plugins

Modified Files:
	check_ldap.c 
Log Message:
fix segfault when argc>=2 and the -H or -b options are not supplied

Index: check_ldap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ldap.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** check_ldap.c	13 Jan 2003 12:15:16 -0000	1.3
--- check_ldap.c	29 Jan 2003 06:16:15 -0000	1.4
***************
*** 22,26 ****
  
  const char *progname = "check_ldap";
! #define REVISION "$Revision$"
  
  #include "config.h"
--- 22,26 ----
  
  const char *progname = "check_ldap";
! const char *revision = "$Revision$";
  
  #include "config.h"
***************
*** 32,36 ****
  #include <ldap.h>
  
! #define UNKNOWN -1
  
  int process_arguments (int, char **);
--- 32,39 ----
  #include <ldap.h>
  
! enum {
! 	UNDEFINED = -1,
! 	DEFAULT_PORT = 389
! };
  
  int process_arguments (int, char **);
***************
*** 41,47 ****
  char ld_defattr[] = "(objectclass=*)";
  char *ld_attr = ld_defattr;
! char *ld_host = NULL, *ld_base = NULL, *ld_passwd = NULL, *ld_binddn = NULL;
! unsigned int ld_port = 389;
! int warn_time = UNKNOWN, crit_time = UNKNOWN;
  
  int
--- 44,54 ----
  char ld_defattr[] = "(objectclass=*)";
  char *ld_attr = ld_defattr;
! char *ld_host = "";
! char *ld_base = "";
! char *ld_passwd = NULL;
! char *ld_binddn = NULL;
! unsigned int ld_port = DEFAULT_PORT;
! int warn_time = UNDEFINED;
! int crit_time = UNDEFINED;
  
  int
***************
*** 99,115 ****
  	time (&time1);
  
! 	/* calcutate the elapsed time */
  	t_diff = time1 - time0;
  
! 	/* check if warn_time or crit_time was exceeded */
! 	if ((t_diff >= warn_time) && (t_diff < crit_time)) {
! 		printf ("LDAP warning - %i seconds response time\n", t_diff);
! 		return STATE_WARNING;
! 	}
! 	if (t_diff >= crit_time) {
  		printf ("LDAP critical - %i seconds response time\n", t_diff);
  		return STATE_CRITICAL;
  	}
  
  	/* print out the result */
  	printf ("LDAP ok - %i seconds response time\n", t_diff);
--- 106,122 ----
  	time (&time1);
  
! 	/* calcutate the elapsed time and compare to thresholds */
  	t_diff = time1 - time0;
  
! 	if (crit_time!=UNDEFINED && t_diff>=crit_time) {
  		printf ("LDAP critical - %i seconds response time\n", t_diff);
  		return STATE_CRITICAL;
  	}
  
+ 	if (warn_time!=UNDEFINED && t_diff>=warn_time) {
+ 		printf ("LDAP warning - %i seconds response time\n", t_diff);
+ 		return STATE_WARNING;
+ 	}
+ 
  	/* print out the result */
  	printf ("LDAP ok - %i seconds response time\n", t_diff);
***************
*** 166,174 ****
  			exit (STATE_OK);
  		case 'V':									/* version */
! 			print_revision (progname, REVISION);
  			exit (STATE_OK);
  		case 't':									/* timeout period */
  			if (!is_intnonneg (optarg))
! 				usage2 ("timeout interval must be an integer", optarg);
  			socket_timeout = atoi (optarg);
  			break;
--- 173,181 ----
  			exit (STATE_OK);
  		case 'V':									/* version */
! 			print_revision (progname, revision);
  			exit (STATE_OK);
  		case 't':									/* timeout period */
  			if (!is_intnonneg (optarg))
! 				usage2 ("timeout interval must be a positive integer", optarg);
  			socket_timeout = atoi (optarg);
  			break;
***************
*** 213,224 ****
  validate_arguments ()
  {
! 	if (ld_host[0] == 0 ||
! 			ld_base[0] == 0 ||
! 			ld_port == UNKNOWN || warn_time == UNKNOWN || crit_time == UNKNOWN) {
! 		return ERROR;
! 	}
! 	else {
  		return OK;
! 	}
  }
  
--- 220,232 ----
  validate_arguments ()
  {
! 	if (strlen(ld_host) == 0)
! 		usage ("please specify the host name\n");
! 
! 	if (strlen(ld_base) == 0)
! 		usage ("please specify the LDAP base\n");
! 
! 	else
  		return OK;
! 
  }
  
***************
*** 229,233 ****
  print_help ()
  {
! 	print_revision (progname, REVISION);
  	printf
  		("Copyright (c) 1999 Didi Rieder (adrieder at sbox.tu-graz.ac.at)\n"
--- 237,241 ----
  print_help ()
  {
! 	print_revision (progname, revision);
  	printf
  		("Copyright (c) 1999 Didi Rieder (adrieder at sbox.tu-graz.ac.at)\n"
***************
*** 242,249 ****
  		 "\t-D [--bind] ... ldap bind DN (if required)\n"
  		 "\t-P [--pass] ... ldap password (if required)\n"
! 		 "\t-p [--port] ... ldap port (normaly 389)\n"
  		 "\t-w [--warn] ... time in secs. - if the exceeds <warn> the STATE_WARNING will be returned\n"
  		 "\t-c [--crit] ... time in secs. - if the exceeds <crit> the STATE_CRITICAL will be returned\n"
! 		 "\n");
  }
  
--- 250,257 ----
  		 "\t-D [--bind] ... ldap bind DN (if required)\n"
  		 "\t-P [--pass] ... ldap password (if required)\n"
! 		 "\t-p [--port] ... ldap port (default: %d)\n"
  		 "\t-w [--warn] ... time in secs. - if the exceeds <warn> the STATE_WARNING will be returned\n"
  		 "\t-c [--crit] ... time in secs. - if the exceeds <crit> the STATE_CRITICAL will be returned\n"
! 		 "\n", DEFAULT_PORT);
  }
  
***************
*** 253,257 ****
  {
  	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]\n"
  		 "(Note: all times are in seconds.)\n", progname);
--- 261,265 ----
  {
  	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]\n"
  		 "(Note: all times are in seconds.)\n", progname);





More information about the Commits mailing list