[Nagiosplug-checkins] CVS: nagiosplug/plugins check_tcp.c,1.7,1.8

Karl DeBisschop kdebisschop at users.sourceforge.net
Mon Nov 25 04:01:07 CET 2002


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

Modified Files:
	check_tcp.c 
Log Message:
was segfaulting if no dtat was returned

Index: check_tcp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_tcp.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** check_tcp.c	8 Nov 2002 07:18:49 -0000	1.7
--- check_tcp.c	25 Nov 2002 12:00:17 -0000	1.8
***************
*** 92,96 ****
  int verbose = FALSE;
  int use_ssl = FALSE;
! int sd;
  
  int
--- 92,96 ----
  int verbose = FALSE;
  int use_ssl = FALSE;
! int sd = 0;
  
  int
***************
*** 99,109 ****
  	int result;
  	int i;
! 	char buffer[MAX_INPUT_BUFFER] = "";
  	char *status = "";
  	struct timeval tv;
  
  	if (strstr (argv[0], "check_udp")) {
! 		PROGNAME = strscpy (PROGNAME, "check_udp");
! 		SERVICE = strscpy (SERVICE, "UDP");
  		SEND = NULL;
  		EXPECT = NULL;
--- 99,109 ----
  	int result;
  	int i;
! 	char *buffer = "";
  	char *status = "";
  	struct timeval tv;
  
  	if (strstr (argv[0], "check_udp")) {
! 		asprintf (&PROGNAME, "check_udp");
! 		asprintf (&SERVICE, "UDP");
  		SEND = NULL;
  		EXPECT = NULL;
***************
*** 113,118 ****
  	}
  	else if (strstr (argv[0], "check_tcp")) {
! 		PROGNAME = strscpy (PROGNAME, "check_tcp");
! 		SERVICE = strscpy (SERVICE, "TCP");
  		SEND = NULL;
  		EXPECT = NULL;
--- 113,118 ----
  	}
  	else if (strstr (argv[0], "check_tcp")) {
! 		asprintf (&PROGNAME, "check_tcp");
! 		asprintf (&SERVICE, "TCP");
  		SEND = NULL;
  		EXPECT = NULL;
***************
*** 122,157 ****
  	}
  	else if (strstr (argv[0], "check_ftp")) {
! 		PROGNAME = strscpy (PROGNAME, "check_ftp");
! 		SERVICE = strscpy (SERVICE, "FTP");
  		SEND = NULL;
! 		EXPECT = strscpy (EXPECT, "220");
! 		QUIT = strscpy (QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 21;
  	}
  	else if (strstr (argv[0], "check_smtp")) {
! 		PROGNAME = strscpy (PROGNAME, "check_smtp");
! 		SERVICE = strscpy (SERVICE, "SMTP");
  		SEND = NULL;
! 		EXPECT = strscpy (EXPECT, "220");
! 		QUIT = strscpy (QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 25;
  	}
  	else if (strstr (argv[0], "check_pop")) {
! 		PROGNAME = strscpy (PROGNAME, "check_pop");
! 		SERVICE = strscpy (SERVICE, "POP");
  		SEND = NULL;
! 		EXPECT = strscpy (EXPECT, "110");
! 		QUIT = strscpy (QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 110;
  	}
  	else if (strstr (argv[0], "check_imap")) {
! 		PROGNAME = strscpy (PROGNAME, "check_imap");
! 		SERVICE = strscpy (SERVICE, "IMAP");
  		SEND = NULL;
! 		EXPECT = strscpy (EXPECT, "* OK");
! 		QUIT = strscpy (QUIT, "a1 LOGOUT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 143;
--- 122,157 ----
  	}
  	else if (strstr (argv[0], "check_ftp")) {
! 		asprintf (&PROGNAME, "check_ftp");
! 		asprintf (&SERVICE, "FTP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "220");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 21;
  	}
  	else if (strstr (argv[0], "check_smtp")) {
! 		asprintf (&PROGNAME, "check_smtp");
! 		asprintf (&SERVICE, "SMTP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "220");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 25;
  	}
  	else if (strstr (argv[0], "check_pop")) {
! 		asprintf (&PROGNAME, "check_pop");
! 		asprintf (&SERVICE, "POP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "110");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 110;
  	}
  	else if (strstr (argv[0], "check_imap")) {
! 		asprintf (&PROGNAME, "check_imap");
! 		asprintf (&SERVICE, "IMAP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "* OK");
! 		asprintf (&QUIT, "a1 LOGOUT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 143;
***************
*** 159,167 ****
  #ifdef HAVE_SSL
  	else if (strstr(argv[0],"check_simap")) {
! 		PROGNAME=strscpy(PROGNAME,"check_simap");
! 		SERVICE=strscpy(SERVICE,"SIMAP");
  		SEND=NULL;
! 		EXPECT=strscpy(EXPECT,"* OK");
! 		QUIT=strscpy(QUIT,"a1 LOGOUT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
--- 159,167 ----
  #ifdef HAVE_SSL
  	else if (strstr(argv[0],"check_simap")) {
! 		asprintf (&PROGNAME, "check_simap");
! 		asprintf (&SERVICE, "SIMAP");
  		SEND=NULL;
! 		asprintf (&EXPECT, "* OK");
! 		asprintf (&QUIT, "a1 LOGOUT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
***************
*** 169,177 ****
  	}
  	else if (strstr(argv[0],"check_spop")) {
! 		PROGNAME=strscpy(PROGNAME,"check_spop");
! 		SERVICE=strscpy(SERVICE,"SPOP");
  		SEND=NULL;
! 		EXPECT=strscpy(EXPECT,"110");
! 		QUIT=strscpy(QUIT,"QUIT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
--- 169,177 ----
  	}
  	else if (strstr(argv[0],"check_spop")) {
! 		asprintf (&PROGNAME, "check_spop");
! 		asprintf (&SERVICE, "SPOP");
  		SEND=NULL;
! 		asprintf (&EXPECT, "110");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
***************
*** 180,192 ****
  #endif
  	else if (strstr (argv[0], "check_nntp")) {
! 		PROGNAME = strscpy (PROGNAME, "check_nntp");
! 		SERVICE = strscpy (SERVICE, "NNTP");
  		SEND = NULL;
  		EXPECT = NULL;
  		server_expect = realloc (server_expect, ++server_expect_count);
! 		server_expect[server_expect_count - 1] = strscpy (EXPECT, "200");
  		server_expect = realloc (server_expect, ++server_expect_count);
! 		server_expect[server_expect_count - 1] = strscpy (NULL, "201");
! 		QUIT = strscpy (QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 119;
--- 180,192 ----
  #endif
  	else if (strstr (argv[0], "check_nntp")) {
! 		asprintf (&PROGNAME, "check_nntp");
! 		asprintf (&SERVICE, "NNTP");
  		SEND = NULL;
  		EXPECT = NULL;
  		server_expect = realloc (server_expect, ++server_expect_count);
! 		asprintf (&server_expect[server_expect_count - 1], "200");
  		server_expect = realloc (server_expect, ++server_expect_count);
! 		asprintf (&server_expect[server_expect_count - 1], "201");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 119;
***************
*** 196,200 ****
  	}
  
! 	server_address = strscpy (NULL, "127.0.0.1");
  	server_port = PORT;
  	server_send = SEND;
--- 196,200 ----
  	}
  
! 	asprintf (&server_address, "127.0.0.1");
  	server_port = PORT;
  	server_send = SEND;
***************
*** 250,264 ****
  	if (server_send || server_expect_count > 0) {
  
  		/* watch for the expect string */
  #ifdef HAVE_SSL
! 		if (use_ssl && SSL_read (ssl, buffer, MAX_INPUT_BUFFER - 1)>=0)
  			asprintf (&status, "%s%s", status, buffer);
  		else
  #endif
! 			{
! 				if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) >= 0)
! 					asprintf (&status, "%s%s", status, buffer);
! 			}
! 		strip (status);
  
  		/* return a CRITICAL status if we couldn't read any data */
--- 250,262 ----
  	if (server_send || server_expect_count > 0) {
  
+ 		buffer = malloc (MAX_INPUT_BUFFER);
  		/* watch for the expect string */
  #ifdef HAVE_SSL
! 		if (use_ssl && SSL_read (ssl, buffer, MAX_INPUT_BUFFER - 1) > 0)
  			asprintf (&status, "%s%s", status, buffer);
  		else
  #endif
! 			if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) > 0)
! 				asprintf (&status, "%s%s", status, buffer);
  
  		/* return a CRITICAL status if we couldn't read any data */
***************
*** 266,269 ****
--- 264,269 ----
  			terminate (STATE_CRITICAL, "No data received from host\n");
  
+ 		strip (status);
+ 
  		if (status && verbose)
  			printf ("%s\n", status);
***************
*** 286,291 ****
  			SSL_write (ssl, QUIT, strlen (QUIT));
  			SSL_shutdown (ssl);
! 			SSL_free (ssl);
! 			SSL_CTX_free (ctx);
  		}
  		else
--- 286,291 ----
  			SSL_write (ssl, QUIT, strlen (QUIT));
  			SSL_shutdown (ssl);
!  			SSL_free (ssl);
!  			SSL_CTX_free (ctx);
  		}
  		else
***************
*** 294,298 ****
  
  	/* close the connection */
! 	close (sd);
  
  	elapsed_time = delta_time (tv);
--- 294,299 ----
  
  	/* close the connection */
! 	if (sd)
! 		close (sd);
  
  	elapsed_time = delta_time (tv);
***************
*** 311,315 ****
  		 state_text (result), elapsed_time, server_port);
  
! 	if (strlen (status))
  		printf (" [%s]", status);
  
--- 312,316 ----
  		 state_text (result), elapsed_time, server_port);
  
! 	if (status && strlen(status) > 0)
  		printf (" [%s]", status);
  





More information about the Commits mailing list