summaryrefslogtreecommitdiffstats
path: root/web/attachments/154515-nagios_plugins-check_ssh.c.patch
blob: da31ea2e7d022501be0952533c5689b706462303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--- ../../original_sources/nagios-plugins-1.4.2/plugins/check_ssh.c	2005-04-11 14:02:40.000000000 -0400
+++ nagios-plugins-1.4.2/plugins/check_ssh.c	2005-10-31 09:04:34.000000000 -0500
@@ -36,7 +36,8 @@
 
 int port = -1;
 char *server_name = NULL;
-char *remote_version = NULL;
+int remote_versions = 0;
+char **remote_version;
 int verbose = FALSE;
 
 int process_arguments (int, char **);
@@ -44,7 +45,7 @@
 void print_help (void);
 void print_usage (void);
 
-int ssh_connect (char *haddr, int hport, char *remote_version);
+int ssh_connect (char *haddr, int hport, char **remote_version);
 
 
 
@@ -136,9 +137,13 @@
 			usage4 (_("IPv6 support not available"));
 #endif
 			break;
-		case 'r':									/* remote version */
-			remote_version = optarg;
-			break;
+		case 'r':									/* remote version multiple occurances allowed */
+		  if (verbose) printf("pre-parsing %s-%d\n",optarg, remote_versions);
+		  remote_version = realloc(remote_version, (++remote_versions) * sizeof(char *));
+		  if (verbose) printf("post-parsing %s\n",optarg);
+		  
+		  remote_version[remote_versions - 1] = optarg;
+		  break;
 		case 'H':									/* host */
 			if (is_host (optarg) == FALSE)
 				usage2 (_("Invalid hostname/address"), optarg);
@@ -193,7 +198,7 @@
 
 
 int
-ssh_connect (char *haddr, int hport, char *remote_version)
+ssh_connect (char *haddr, int hport, char **remote_version)
 {
 	int sd;
 	int result;
@@ -202,6 +207,7 @@
 	char *ssh_proto = NULL;
 	char *ssh_server = NULL;
 	char rev_no[20];
+	int remote_versions_i;
 
 	sscanf ("$Revision: 1.27 $", "$Revision: %[0123456789.]", rev_no);
 
@@ -230,11 +236,26 @@
 		if (verbose)
 			printf ("%s\n", buffer);
 
-		if (remote_version && strcmp(remote_version, ssh_server)) {
-			printf
-				(_("SSH WARNING - %s (protocol %s) version mismatch, expected '%s'\n"),
-				 ssh_server, ssh_proto, remote_version);
-			exit (STATE_WARNING);
+		if ( remote_versions ) {
+		  remote_versions_i = remote_versions;
+		  while ( remote_versions_i > 0) {
+		    if (verbose) printf("Comparing server '%s' to -r opt '%s'\n", ssh_server, remote_version[remote_versions_i -1]);
+		    if ( ! strcmp(remote_version[remote_versions_i - 1], ssh_server)) {
+		      break;
+		    } else {
+		      remote_versions_i--;
+		    }
+		  }
+		  if (remote_versions_i == 0) {
+		    printf
+		      (_("SSH WARNING - '%s' (protocol %s) version mismatch, expected "),
+		       ssh_server, ssh_proto);
+		    while (remote_versions > 0) {
+		      printf("'%s'%s", remote_version[remote_versions -1], remote_versions == 1?".\n":", ");
+		      remote_versions --;
+		    }
+		    exit (STATE_WARNING);
+		  }
 		}
 		
 		printf
@@ -272,7 +293,9 @@
 
 	printf (_("\
  -r, --remote-version=STRING\n\
-    Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)\n"));
+    Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1).\n"));
+	printf (_("\
+    Can use multiple times to accept multiple version strings.\n"));
 	
 	printf (_(UT_VERBOSE));