diff options
Diffstat (limited to 'plugins/check_tcp.c')
-rw-r--r-- | plugins/check_tcp.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 6dc9aa96..1d307cf3 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -86,6 +86,11 @@ static char buffer[MAXBUF]; | |||
86 | static int expect_mismatch_state = STATE_WARNING; | 86 | static int expect_mismatch_state = STATE_WARNING; |
87 | static int match_flags = NP_MATCH_EXACT; | 87 | static int match_flags = NP_MATCH_EXACT; |
88 | 88 | ||
89 | #ifdef HAVE_SSL | ||
90 | static char *sni = NULL; | ||
91 | static int sni_specified = FALSE; | ||
92 | #endif | ||
93 | |||
89 | #define FLAG_SSL 0x01 | 94 | #define FLAG_SSL 0x01 |
90 | #define FLAG_VERBOSE 0x02 | 95 | #define FLAG_VERBOSE 0x02 |
91 | #define FLAG_TIME_WARN 0x04 | 96 | #define FLAG_TIME_WARN 0x04 |
@@ -123,7 +128,7 @@ main (int argc, char **argv) | |||
123 | SERVICE[i] = toupper(SERVICE[i]); | 128 | SERVICE[i] = toupper(SERVICE[i]); |
124 | } | 129 | } |
125 | 130 | ||
126 | /* set up a resonable buffer at first (will be realloc()'ed if | 131 | /* set up a reasonable buffer at first (will be realloc()'ed if |
127 | * user specifies other options) */ | 132 | * user specifies other options) */ |
128 | server_expect = calloc(sizeof(char *), 2); | 133 | server_expect = calloc(sizeof(char *), 2); |
129 | 134 | ||
@@ -241,14 +246,14 @@ main (int argc, char **argv) | |||
241 | 246 | ||
242 | #ifdef HAVE_SSL | 247 | #ifdef HAVE_SSL |
243 | if (flags & FLAG_SSL){ | 248 | if (flags & FLAG_SSL){ |
244 | result = np_net_ssl_init(sd); | 249 | result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL)); |
245 | if (result == STATE_OK && check_cert == TRUE) { | 250 | if (result == STATE_OK && check_cert == TRUE) { |
246 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); | 251 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); |
247 | } | 252 | } |
248 | } | 253 | } |
249 | if(result != STATE_OK){ | 254 | if(result != STATE_OK){ |
250 | np_net_ssl_cleanup(); | ||
251 | if(sd) close(sd); | 255 | if(sd) close(sd); |
256 | np_net_ssl_cleanup(); | ||
252 | return result; | 257 | return result; |
253 | } | 258 | } |
254 | #endif /* HAVE_SSL */ | 259 | #endif /* HAVE_SSL */ |
@@ -321,10 +326,10 @@ main (int argc, char **argv) | |||
321 | if (server_quit != NULL) { | 326 | if (server_quit != NULL) { |
322 | my_send(server_quit, strlen(server_quit)); | 327 | my_send(server_quit, strlen(server_quit)); |
323 | } | 328 | } |
329 | if (sd) close (sd); | ||
324 | #ifdef HAVE_SSL | 330 | #ifdef HAVE_SSL |
325 | np_net_ssl_cleanup(); | 331 | np_net_ssl_cleanup(); |
326 | #endif | 332 | #endif |
327 | if (sd) close (sd); | ||
328 | 333 | ||
329 | microsec = deltime (tv); | 334 | microsec = deltime (tv); |
330 | elapsed_time = (double)microsec / 1.0e6; | 335 | elapsed_time = (double)microsec / 1.0e6; |
@@ -401,6 +406,10 @@ process_arguments (int argc, char **argv) | |||
401 | int escape = 0; | 406 | int escape = 0; |
402 | char *temp; | 407 | char *temp; |
403 | 408 | ||
409 | enum { | ||
410 | SNI_OPTION = CHAR_MAX + 1 | ||
411 | }; | ||
412 | |||
404 | int option = 0; | 413 | int option = 0; |
405 | static struct option longopts[] = { | 414 | static struct option longopts[] = { |
406 | {"hostname", required_argument, 0, 'H'}, | 415 | {"hostname", required_argument, 0, 'H'}, |
@@ -427,6 +436,7 @@ process_arguments (int argc, char **argv) | |||
427 | {"version", no_argument, 0, 'V'}, | 436 | {"version", no_argument, 0, 'V'}, |
428 | {"help", no_argument, 0, 'h'}, | 437 | {"help", no_argument, 0, 'h'}, |
429 | {"ssl", no_argument, 0, 'S'}, | 438 | {"ssl", no_argument, 0, 'S'}, |
439 | {"sni", required_argument, 0, SNI_OPTION}, | ||
430 | {"certificate", required_argument, 0, 'D'}, | 440 | {"certificate", required_argument, 0, 'D'}, |
431 | {0, 0, 0, 0} | 441 | {0, 0, 0, 0} |
432 | }; | 442 | }; |
@@ -604,6 +614,15 @@ process_arguments (int argc, char **argv) | |||
604 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); | 614 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); |
605 | #endif | 615 | #endif |
606 | break; | 616 | break; |
617 | case SNI_OPTION: | ||
618 | #ifdef HAVE_SSL | ||
619 | flags |= FLAG_SSL; | ||
620 | sni_specified = TRUE; | ||
621 | sni = optarg; | ||
622 | #else | ||
623 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); | ||
624 | #endif | ||
625 | break; | ||
607 | case 'A': | 626 | case 'A': |
608 | match_flags |= NP_MATCH_ALL; | 627 | match_flags |= NP_MATCH_ALL; |
609 | break; | 628 | break; |
@@ -671,6 +690,8 @@ print_help (void) | |||
671 | printf (" %s\n", _("1st is #days for warning, 2nd is critical (if not specified - 0).")); | 690 | printf (" %s\n", _("1st is #days for warning, 2nd is critical (if not specified - 0).")); |
672 | printf (" %s\n", "-S, --ssl"); | 691 | printf (" %s\n", "-S, --ssl"); |
673 | printf (" %s\n", _("Use SSL for the connection.")); | 692 | printf (" %s\n", _("Use SSL for the connection.")); |
693 | printf (" %s\n", "--sni=STRING"); | ||
694 | printf (" %s\n", _("SSL server_name")); | ||
674 | #endif | 695 | #endif |
675 | 696 | ||
676 | printf (UT_WARN_CRIT); | 697 | printf (UT_WARN_CRIT); |