summaryrefslogtreecommitdiffstats
path: root/plugins/check_ssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ssh.c')
-rw-r--r--plugins/check_ssh.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index 6e0b0f1..86267b2 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -34,6 +34,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
34 34
35int port = -1; 35int port = -1;
36char *server_name = NULL; 36char *server_name = NULL;
37char *remote_version = NULL;
37int verbose = FALSE; 38int verbose = FALSE;
38 39
39int process_arguments (int, char **); 40int process_arguments (int, char **);
@@ -41,7 +42,7 @@ int validate_arguments (void);
41void print_help (void); 42void print_help (void);
42void print_usage (void); 43void print_usage (void);
43 44
44int ssh_connect (char *haddr, int hport); 45int ssh_connect (char *haddr, int hport, char *remote_version);
45 46
46int 47int
47main (int argc, char **argv) 48main (int argc, char **argv)
@@ -60,7 +61,7 @@ main (int argc, char **argv)
60 alarm (socket_timeout); 61 alarm (socket_timeout);
61 62
62 /* ssh_connect exits if error is found */ 63 /* ssh_connect exits if error is found */
63 result = ssh_connect (server_name, port); 64 result = ssh_connect (server_name, port, remote_version);
64 65
65 alarm (0); 66 alarm (0);
66 67
@@ -84,6 +85,7 @@ process_arguments (int argc, char **argv)
84 {"use-ipv6", no_argument, 0, '6'}, 85 {"use-ipv6", no_argument, 0, '6'},
85 {"timeout", required_argument, 0, 't'}, 86 {"timeout", required_argument, 0, 't'},
86 {"verbose", no_argument, 0, 'v'}, 87 {"verbose", no_argument, 0, 'v'},
88 {"remote-version", required_argument, 0, 'r'},
87 {0, 0, 0, 0} 89 {0, 0, 0, 0}
88 }; 90 };
89 91
@@ -95,7 +97,7 @@ process_arguments (int argc, char **argv)
95 strcpy (argv[c], "-t"); 97 strcpy (argv[c], "-t");
96 98
97 while (1) { 99 while (1) {
98 c = getopt_long (argc, argv, "+Vhv46t:H:p:", longopts, &option); 100 c = getopt_long (argc, argv, "+Vhv46t:r:H:p:", longopts, &option);
99 101
100 if (c == -1 || c == EOF) 102 if (c == -1 || c == EOF)
101 break; 103 break;
@@ -109,7 +111,7 @@ process_arguments (int argc, char **argv)
109 case 'h': /* help */ 111 case 'h': /* help */
110 print_help (); 112 print_help ();
111 exit (STATE_OK); 113 exit (STATE_OK);
112 case 'v': /* verose */ 114 case 'v': /* verbose */
113 verbose = TRUE; 115 verbose = TRUE;
114 break; 116 break;
115 case 't': /* timeout period */ 117 case 't': /* timeout period */
@@ -128,6 +130,9 @@ process_arguments (int argc, char **argv)
128 usage (_("IPv6 support not available\n")); 130 usage (_("IPv6 support not available\n"));
129#endif 131#endif
130 break; 132 break;
133 case 'r': /* remote version */
134 remote_version = optarg;
135 break;
131 case 'H': /* host */ 136 case 'H': /* host */
132 if (is_host (optarg) == FALSE) 137 if (is_host (optarg) == FALSE)
133 usage2 (_("Invalid host name/address"), optarg); 138 usage2 (_("Invalid host name/address"), optarg);
@@ -183,7 +188,7 @@ validate_arguments (void)
183*-----------------------------------------------------------------------*/ 188*-----------------------------------------------------------------------*/
184 189
185int 190int
186ssh_connect (char *haddr, int hport) 191ssh_connect (char *haddr, int hport, char *remote_version)
187{ 192{
188 int sd; 193 int sd;
189 int result; 194 int result;
@@ -214,13 +219,22 @@ ssh_connect (char *haddr, int hport)
214 ssh_proto = output + 4; 219 ssh_proto = output + 4;
215 ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. "); 220 ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
216 ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0; 221 ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
217 printf 222
218 (_("SSH OK - %s (protocol %s)\n"),
219 ssh_server, ssh_proto);
220 asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no); 223 asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no);
221 send (sd, buffer, strlen (buffer), MSG_DONTWAIT); 224 send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
222 if (verbose) 225 if (verbose)
223 printf ("%s\n", buffer); 226 printf ("%s\n", buffer);
227
228 if (remote_version && strcmp(remote_version, ssh_server)) {
229 printf
230 (_("SSH WARNING - %s (protocol %s) version mismatch, expected '%s'\n"),
231 ssh_server, ssh_proto, remote_version);
232 exit (STATE_WARNING);
233 }
234
235 printf
236 (_("SSH OK - %s (protocol %s)\n"),
237 ssh_server, ssh_proto);
224 exit (STATE_OK); 238 exit (STATE_OK);
225 } 239 }
226} 240}
@@ -248,6 +262,10 @@ print_help (void)
248 262
249 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 263 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
250 264
265 printf (_("\
266 -r, --remote-version=STRING\n\
267 Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)\n"));
268
251 printf (_(UT_VERBOSE)); 269 printf (_(UT_VERBOSE));
252 270
253 printf (_(UT_SUPPORT)); 271 printf (_(UT_SUPPORT));
@@ -257,7 +275,7 @@ void
257print_usage (void) 275print_usage (void)
258{ 276{
259 printf (_("\ 277 printf (_("\
260Usage: %s [-46] [-t <timeout>] [-p <port>] <host>\n"), progname); 278Usage: %s [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n"), progname);
261 printf (_(UT_HLP_VRS), progname, progname); 279 printf (_(UT_HLP_VRS), progname, progname);
262} 280}
263 281