diff options
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r-- | plugins/check_smtp.c | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index fc0ae2c4..986c3e18 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -40,7 +40,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
40 | #include <ctype.h> | 40 | #include <ctype.h> |
41 | 41 | ||
42 | #ifdef HAVE_SSL | 42 | #ifdef HAVE_SSL |
43 | int check_cert = FALSE; | 43 | bool check_cert = false; |
44 | int days_till_exp_warn, days_till_exp_crit; | 44 | int days_till_exp_warn, days_till_exp_crit; |
45 | # define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) | 45 | # define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) |
46 | # define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) | 46 | # define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) |
@@ -100,17 +100,17 @@ char *authtype = NULL; | |||
100 | char *authuser = NULL; | 100 | char *authuser = NULL; |
101 | char *authpass = NULL; | 101 | char *authpass = NULL; |
102 | double warning_time = 0; | 102 | double warning_time = 0; |
103 | int check_warning_time = FALSE; | 103 | bool check_warning_time = false; |
104 | double critical_time = 0; | 104 | double critical_time = 0; |
105 | int check_critical_time = FALSE; | 105 | bool check_critical_time = false; |
106 | int verbose = 0; | 106 | int verbose = 0; |
107 | int use_ssl = FALSE; | 107 | bool use_ssl = false; |
108 | int use_starttls = FALSE; | 108 | bool use_starttls = false; |
109 | int use_sni = FALSE; | 109 | bool use_sni = false; |
110 | short use_proxy_prefix = FALSE; | 110 | bool use_proxy_prefix = false; |
111 | short use_ehlo = FALSE; | 111 | bool use_ehlo = false; |
112 | short use_lhlo = FALSE; | 112 | bool use_lhlo = false; |
113 | short ssl_established = 0; | 113 | bool ssl_established = false; |
114 | char *localhostname = NULL; | 114 | char *localhostname = NULL; |
115 | int sd; | 115 | int sd; |
116 | char buffer[MAX_INPUT_BUFFER]; | 116 | char buffer[MAX_INPUT_BUFFER]; |
@@ -118,13 +118,13 @@ enum { | |||
118 | TCP_PROTOCOL = 1, | 118 | TCP_PROTOCOL = 1, |
119 | UDP_PROTOCOL = 2, | 119 | UDP_PROTOCOL = 2, |
120 | }; | 120 | }; |
121 | int ignore_send_quit_failure = FALSE; | 121 | bool ignore_send_quit_failure = false; |
122 | 122 | ||
123 | 123 | ||
124 | int | 124 | int |
125 | main (int argc, char **argv) | 125 | main (int argc, char **argv) |
126 | { | 126 | { |
127 | short supports_tls=FALSE; | 127 | bool supports_tls = false; |
128 | int n = 0; | 128 | int n = 0; |
129 | double elapsed_time; | 129 | double elapsed_time; |
130 | long microsec; | 130 | long microsec; |
@@ -230,7 +230,7 @@ main (int argc, char **argv) | |||
230 | } else if(use_ehlo || use_lhlo){ | 230 | } else if(use_ehlo || use_lhlo){ |
231 | if(strstr(buffer, "250 STARTTLS") != NULL || | 231 | if(strstr(buffer, "250 STARTTLS") != NULL || |
232 | strstr(buffer, "250-STARTTLS") != NULL){ | 232 | strstr(buffer, "250-STARTTLS") != NULL){ |
233 | supports_tls=TRUE; | 233 | supports_tls=true; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
@@ -466,7 +466,7 @@ main (int argc, char **argv) | |||
466 | fperfdata ("time", elapsed_time, "s", | 466 | fperfdata ("time", elapsed_time, "s", |
467 | (int)check_warning_time, warning_time, | 467 | (int)check_warning_time, warning_time, |
468 | (int)check_critical_time, critical_time, | 468 | (int)check_critical_time, critical_time, |
469 | TRUE, 0, FALSE, 0)); | 469 | true, 0, false, 0)); |
470 | 470 | ||
471 | return result; | 471 | return result; |
472 | } | 472 | } |
@@ -480,6 +480,8 @@ process_arguments (int argc, char **argv) | |||
480 | int c; | 480 | int c; |
481 | char* temp; | 481 | char* temp; |
482 | 482 | ||
483 | bool implicit_tls = false; | ||
484 | |||
483 | enum { | 485 | enum { |
484 | SNI_OPTION | 486 | SNI_OPTION |
485 | }; | 487 | }; |
@@ -560,7 +562,7 @@ process_arguments (int argc, char **argv) | |||
560 | break; | 562 | break; |
561 | case 'A': | 563 | case 'A': |
562 | authtype = optarg; | 564 | authtype = optarg; |
563 | use_ehlo = TRUE; | 565 | use_ehlo = true; |
564 | break; | 566 | break; |
565 | case 'U': | 567 | case 'U': |
566 | authuser = optarg; | 568 | authuser = optarg; |
@@ -600,7 +602,7 @@ process_arguments (int argc, char **argv) | |||
600 | usage4 (_("Critical time must be a positive")); | 602 | usage4 (_("Critical time must be a positive")); |
601 | else { | 603 | else { |
602 | critical_time = strtod (optarg, NULL); | 604 | critical_time = strtod (optarg, NULL); |
603 | check_critical_time = TRUE; | 605 | check_critical_time = true; |
604 | } | 606 | } |
605 | break; | 607 | break; |
606 | case 'w': /* warning time threshold */ | 608 | case 'w': /* warning time threshold */ |
@@ -608,14 +610,14 @@ process_arguments (int argc, char **argv) | |||
608 | usage4 (_("Warning time must be a positive")); | 610 | usage4 (_("Warning time must be a positive")); |
609 | else { | 611 | else { |
610 | warning_time = strtod (optarg, NULL); | 612 | warning_time = strtod (optarg, NULL); |
611 | check_warning_time = TRUE; | 613 | check_warning_time = true; |
612 | } | 614 | } |
613 | break; | 615 | break; |
614 | case 'v': /* verbose */ | 616 | case 'v': /* verbose */ |
615 | verbose++; | 617 | verbose++; |
616 | break; | 618 | break; |
617 | case 'q': | 619 | case 'q': |
618 | ignore_send_quit_failure++; /* ignore problem sending QUIT */ | 620 | ignore_send_quit_failure = true; /* ignore problem sending QUIT */ |
619 | break; | 621 | break; |
620 | case 't': /* timeout */ | 622 | case 't': /* timeout */ |
621 | if (is_intnonneg (optarg)) { | 623 | if (is_intnonneg (optarg)) { |
@@ -645,33 +647,35 @@ process_arguments (int argc, char **argv) | |||
645 | usage2 ("Invalid certificate expiration period", optarg); | 647 | usage2 ("Invalid certificate expiration period", optarg); |
646 | days_till_exp_warn = atoi (optarg); | 648 | days_till_exp_warn = atoi (optarg); |
647 | } | 649 | } |
648 | check_cert = TRUE; | 650 | check_cert = true; |
649 | ignore_send_quit_failure = TRUE; | 651 | ignore_send_quit_failure = true; |
650 | #else | 652 | #else |
651 | usage (_("SSL support not available - install OpenSSL and recompile")); | 653 | usage (_("SSL support not available - install OpenSSL and recompile")); |
652 | #endif | 654 | #endif |
655 | implicit_tls = true; | ||
656 | // fallthrough | ||
653 | case 's': | 657 | case 's': |
654 | /* ssl */ | 658 | /* ssl */ |
655 | use_ssl = TRUE; | 659 | use_ssl = true; |
656 | server_port = SMTPS_PORT; | 660 | server_port = SMTPS_PORT; |
657 | break; | 661 | break; |
658 | case 'S': | 662 | case 'S': |
659 | /* starttls */ | 663 | /* starttls */ |
660 | use_starttls = TRUE; | 664 | use_starttls = true; |
661 | use_ehlo = TRUE; | 665 | use_ehlo = true; |
662 | break; | 666 | break; |
663 | case SNI_OPTION: | 667 | case SNI_OPTION: |
664 | #ifdef HAVE_SSL | 668 | #ifdef HAVE_SSL |
665 | use_sni = TRUE; | 669 | use_sni = true; |
666 | #else | 670 | #else |
667 | usage (_("SSL support not available - install OpenSSL and recompile")); | 671 | usage (_("SSL support not available - install OpenSSL and recompile")); |
668 | #endif | 672 | #endif |
669 | break; | 673 | break; |
670 | case 'r': | 674 | case 'r': |
671 | use_proxy_prefix = TRUE; | 675 | use_proxy_prefix = true; |
672 | break; | 676 | break; |
673 | case 'L': | 677 | case 'L': |
674 | use_lhlo = TRUE; | 678 | use_lhlo = true; |
675 | break; | 679 | break; |
676 | case '4': | 680 | case '4': |
677 | address_family = AF_INET; | 681 | address_family = AF_INET; |
@@ -717,7 +721,12 @@ process_arguments (int argc, char **argv) | |||
717 | from_arg = strdup(" "); | 721 | from_arg = strdup(" "); |
718 | 722 | ||
719 | if (use_starttls && use_ssl) { | 723 | if (use_starttls && use_ssl) { |
720 | usage4 (_("Set either -s/--ssl/--tls or -S/--starttls")); | 724 | if (implicit_tls) { |
725 | use_ssl = false; | ||
726 | server_port = SMTP_PORT; | ||
727 | } else { | ||
728 | usage4 (_("Set either -s/--ssl/--tls or -S/--starttls")); | ||
729 | } | ||
721 | } | 730 | } |
722 | 731 | ||
723 | if (server_port_option != 0) { | 732 | if (server_port_option != 0) { |