diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 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 | ||
35 | int port = -1; | 35 | int port = -1; |
36 | char *server_name = NULL; | 36 | char *server_name = NULL; |
37 | char *remote_version = NULL; | ||
37 | int verbose = FALSE; | 38 | int verbose = FALSE; |
38 | 39 | ||
39 | int process_arguments (int, char **); | 40 | int process_arguments (int, char **); |
@@ -41,7 +42,7 @@ int validate_arguments (void); | |||
41 | void print_help (void); | 42 | void print_help (void); |
42 | void print_usage (void); | 43 | void print_usage (void); |
43 | 44 | ||
44 | int ssh_connect (char *haddr, int hport); | 45 | int ssh_connect (char *haddr, int hport, char *remote_version); |
45 | 46 | ||
46 | int | 47 | int |
47 | main (int argc, char **argv) | 48 | main (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 | ||
185 | int | 190 | int |
186 | ssh_connect (char *haddr, int hport) | 191 | ssh_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 | |||
257 | print_usage (void) | 275 | print_usage (void) |
258 | { | 276 | { |
259 | printf (_("\ | 277 | printf (_("\ |
260 | Usage: %s [-46] [-t <timeout>] [-p <port>] <host>\n"), progname); | 278 | Usage: %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 | ||