[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ssh.c,1.1.1.1,1.2

Karl DeBisschop kdebisschop at users.sourceforge.net
Tue Oct 22 02:14:05 CEST 2002


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv28096/plugins

Modified Files:
	check_ssh.c 
Log Message:
remove call_getopt, replace ssprintf with asprintf,better server version reporting

Index: check_ssh.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ssh.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_ssh.c	28 Feb 2002 06:42:59 -0000	1.1.1.1
--- check_ssh.c	22 Oct 2002 09:13:56 -0000	1.2
***************
*** 17,20 ****
--- 17,21 ----
  
  #define PROGNAME "check_ssh"
+ #define REVISION "$Revision$"
  
  #ifndef MSG_DONTWAIT
***************
*** 64,107 ****
  	int c;
  
- 	if (argc < 2)
- 		return ERROR;
- 
- 	for (c = 1; c < argc; c++)
- 		if (strcmp ("-to", argv[c]) == 0)
- 			strcpy (argv[c], "-t");
- 
- 	c = 0;
- 	while (c += (call_getopt (argc - c, &argv[c]))) {
- 		if (argc <= c)
- 			break;
- 		if (server_name == NULL) {
- 			server_name = argv[c];
- 		}
- 		else if (port == -1) {
- 			if (is_intpos (argv[c])) {
- 				port = atoi (argv[c]);
- 			}
- 			else {
- 				print_usage ();
- 				exit (STATE_UNKNOWN);
- 			}
- 		}
- 	}
- 
- 	return validate_arguments ();
- }
- 
- 
- /************************************************************************
- *
- * Run the getopt until we encounter a non-option entry in the arglist
- *
- *-----------------------------------------------------------------------*/
- 
- int
- call_getopt (int argc, char **argv)
- {
- 	int c, i = 1;
- 
  #ifdef HAVE_GETOPT_H
  	int option_index = 0;
--- 65,68 ----
***************
*** 116,119 ****
--- 77,87 ----
  #endif
  
+ 	if (argc < 2)
+ 		return ERROR;
+ 
+ 	for (c = 1; c < argc; c++)
+ 		if (strcmp ("-to", argv[c]) == 0)
+ 			strcpy (argv[c], "-t");
+ 
  	while (1) {
  #ifdef HAVE_GETOPT_H
***************
*** 122,142 ****
  		c = getopt (argc, argv, "+Vhvt:H:p:");
  #endif
- 
  		if (c == -1 || c == EOF)
  			break;
  
- 		i++;
- 		switch (c) {
- 		case 't':
- 		case 'H':
- 		case 'p':
- 			i++;
- 		}
- 
  		switch (c) {
  		case '?':									/* help */
  			usage ("");
  		case 'V':									/* version */
! 			print_revision (my_basename (argv[0]), "$Revision$");
  			exit (STATE_OK);
  		case 'h':									/* help */
--- 90,101 ----
  		c = getopt (argc, argv, "+Vhvt:H:p:");
  #endif
  		if (c == -1 || c == EOF)
  			break;
  
  		switch (c) {
  		case '?':									/* help */
  			usage ("");
  		case 'V':									/* version */
! 			print_revision (PROGNAME, REVISION);
  			exit (STATE_OK);
  		case 'h':									/* help */
***************
*** 165,169 ****
  
  	}
! 	return i;
  }
  
--- 124,143 ----
  
  	}
! 
! 	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++]);
! 		}
! 		else {
! 			print_usage ();
! 			exit (STATE_UNKNOWN);
! 		}
! 	}
! 
! 	return validate_arguments ();
  }
  
***************
*** 250,260 ****
  			printf ("%s\n", output);
  		ssh_proto = output + 4;
! 		ssh_server = ssh_proto + strspn (ssh_proto, "0123456789-. ");
! 		ssh_proto[strspn (ssh_proto, "0123456789-. ")] = 0;
  		printf
! 			("SSH ok - protocol version %s - server version %s\n",
! 			 ssh_proto, ssh_server);
! 		buffer =
! 			ssprintf (buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
  		send (s, buffer, strlen (buffer), MSG_DONTWAIT);
  		if (verbose)
--- 224,233 ----
  			printf ("%s\n", output);
  		ssh_proto = output + 4;
! 		ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
! 		ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
  		printf
! 			("SSH ok - %s (protocol %s)\n",
! 			 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)
***************
*** 267,271 ****
  print_help (void)
  {
! 	print_revision (PROGNAME, "$Revision$");
  	printf ("Copyright (c) 1999 Remi Paulmier (remi at sinfomic.fr)\n\n");
  	print_usage ();
--- 240,244 ----
  print_help (void)
  {
! 	print_revision (PROGNAME, REVISION);
  	printf ("Copyright (c) 1999 Remi Paulmier (remi at sinfomic.fr)\n\n");
  	print_usage ();





More information about the Commits mailing list