[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ssh.c,1.4,1.5

Jeremy T. Bouse undrgrid at users.sourceforge.net
Mon Feb 10 06:19:04 CET 2003


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

Modified Files:
	check_ssh.c 
Log Message:
Revised code to use resolving and connection code in utils.c and
netutils.c rather than its own functions.
Corrected code to properly handle input of server hostname and port on 
commandline without option flags.


Index: check_ssh.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ssh.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** check_ssh.c	13 Jan 2003 12:15:16 -0000	1.4
--- check_ssh.c	10 Feb 2003 14:18:00 -0000	1.5
***************
*** 35,39 ****
  void print_usage (void);
  
- char *ssh_resolve (char *hostname);
  int ssh_connect (char *haddr, short hport);
  
--- 35,38 ----
***************
*** 50,54 ****
  
  	/* ssh_connect exits if error is found */
! 	ssh_connect (ssh_resolve (server_name), port);
  
  	alarm (0);
--- 49,53 ----
  
  	/* ssh_connect exits if error is found */
! 	ssh_connect (server_name, port);
  
  	alarm (0);
***************
*** 63,66 ****
--- 62,66 ----
  {
  	int c;
+ 	char *tmp = NULL;
  
  #ifdef HAVE_GETOPT_H
***************
*** 110,113 ****
--- 110,115 ----
  			break;
  		case 'H':									/* host */
+ 			if (is_host (optarg) == FALSE)
+ 				usage ("Invalid hostname/address\n");
  			server_name = optarg;
  			break;
***************
*** 126,132 ****
  	c = optind;
  	if (server_name == NULL && argv[c]) {
! 		server_name = argv[c++];
  	}
! 	else if (port == -1 && argv[c]) {
  		if (is_intpos (argv[c])) {
  			port = atoi (argv[c++]);
--- 128,137 ----
  	c = optind;
  	if (server_name == NULL && argv[c]) {
! 		if (is_host (argv[c])) {
! 			server_name = argv[c++];
! 		}
  	}
! 
! 	if (port == -1 && argv[c]) {
  		if (is_intpos (argv[c])) {
  			port = atoi (argv[c++]);
***************
*** 154,177 ****
  /************************************************************************
  *
- * Resolve hostname into IP address
- *
- *-----------------------------------------------------------------------*/
- 
- char *
- ssh_resolve (char *hostname)
- {
- 	struct hostent *host;
- 
- 	host = gethostbyname (hostname);
- 	if (!host) {
- 		herror (hostname);
- 		exit (STATE_CRITICAL);
- 	}
- 	return (host->h_addr);
- }
- 
- 
- /************************************************************************
- *
  * Try to connect to SSH server at specified server and port
  *
--- 159,162 ----
***************
*** 181,188 ****
  ssh_connect (char *haddr, short hport)
  {
! 	int s;
! 	struct sockaddr_in addr;
! 	int addrlen;
! 	int len;
  	char *output = NULL;
  	char *buffer = NULL;
--- 166,171 ----
  ssh_connect (char *haddr, short hport)
  {
! 	int sd;
! 	int result;
  	char *output = NULL;
  	char *buffer = NULL;
***************
*** 193,217 ****
  	sscanf ("$Revision$", "$Revision: %[0123456789.]", revision);
  
! 	addrlen = sizeof (addr);
! 	memset (&addr, 0, addrlen);
! 	addr.sin_port = htons (hport);
! 	addr.sin_family = AF_INET;
! 	bcopy (haddr, (void *) &addr.sin_addr.s_addr, 4);
! 
! 	s = socket (AF_INET, SOCK_STREAM, 0);
! 	if (!s) {
! 		printf ("socket(): %s for %s:%d\n", strerror (errno), server_name, hport);
! 		exit (STATE_CRITICAL);
! 	}
  
! 	if (connect (s, (struct sockaddr *) &addr, addrlen)) {
! 		printf ("connect(): %s for %s:%d\n", strerror (errno), server_name,
! 						hport);
! 		exit (STATE_CRITICAL);
! 	}
  
  	output = (char *) malloc (BUFF_SZ + 1);
  	memset (output, 0, BUFF_SZ + 1);
! 	recv (s, output, BUFF_SZ, 0);
  	if (strncmp (output, "SSH", 3)) {
  		printf ("Server answer: %s", output);
--- 176,187 ----
  	sscanf ("$Revision$", "$Revision: %[0123456789.]", revision);
  
! 	result = my_tcp_connect (haddr, hport, &sd);
  
! 	if (result != STATE_OK)
! 		return result;
  
  	output = (char *) malloc (BUFF_SZ + 1);
  	memset (output, 0, BUFF_SZ + 1);
! 	recv (sd, output, BUFF_SZ, 0);
  	if (strncmp (output, "SSH", 3)) {
  		printf ("Server answer: %s", output);
***************
*** 229,233 ****
  			 ssh_server, ssh_proto);
  		asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
! 		send (s, buffer, strlen (buffer), MSG_DONTWAIT);
  		if (verbose)
  			printf ("%s\n", buffer);
--- 199,203 ----
  			 ssh_server, ssh_proto);
  		asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
! 		send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
  		if (verbose)
  			printf ("%s\n", buffer);





More information about the Commits mailing list