summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_smtp.c34
-rw-r--r--plugins/t/check_smtp.t55
2 files changed, 69 insertions, 20 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index e7cf2ea..e4da30e 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -282,6 +282,35 @@ main (int argc, char **argv)
282 } else { 282 } else {
283 ssl_established = 1; 283 ssl_established = 1;
284 } 284 }
285
286 /*
287 * Resend the EHLO command.
288 *
289 * RFC 3207 (4.2) says: ``The client MUST discard any knowledge
290 * obtained from the server, such as the list of SMTP service
291 * extensions, which was not obtained from the TLS negotiation
292 * itself. The client SHOULD send an EHLO command as the first
293 * command after a successful TLS negotiation.'' For this
294 * reason, some MTAs will not allow an AUTH LOGIN command before
295 * we resent EHLO via TLS.
296 */
297 if (my_send(helocmd, strlen(helocmd)) <= 0) {
298 printf(_("SMTP UNKNOWN - Cannot send EHLO command via TLS.\n"));
299 my_close();
300 return STATE_UNKNOWN;
301 }
302 if (verbose)
303 printf(_("sent %s"), helocmd);
304 if ((n = my_recv(buffer, MAX_INPUT_BUFFER - 1)) <= 0) {
305 printf(_("SMTP UNKNOWN - Cannot read EHLO response via TLS.\n"));
306 my_close();
307 return STATE_UNKNOWN;
308 }
309 if (verbose) {
310 buffer[n] = '\0';
311 printf("%s", buffer);
312 }
313
285# ifdef USE_OPENSSL 314# ifdef USE_OPENSSL
286 if ( check_cert ) { 315 if ( check_cert ) {
287 result = np_net_ssl_check_cert(days_till_exp); 316 result = np_net_ssl_check_cert(days_till_exp);
@@ -705,8 +734,8 @@ print_help (void)
705 printf (_(UT_IPv46)); 734 printf (_(UT_IPv46));
706 735
707 printf (" %s\n", "-e, --expect=STRING"); 736 printf (" %s\n", "-e, --expect=STRING");
708 printf (_("String to expect in first line of server response (default: '%s')"),SMTP_EXPECT); 737 printf (_(" String to expect in first line of server response (default: '%s')\n"), SMTP_EXPECT);
709 printf (" %s\n\n", "-n, nocommand\n"); 738 printf (" %s\n", "-n, nocommand");
710 printf (" %s\n", _("Suppress SMTP command")); 739 printf (" %s\n", _("Suppress SMTP command"));
711 printf (" %s\n", "-C, --command=STRING"); 740 printf (" %s\n", "-C, --command=STRING");
712 printf (" %s\n", _("SMTP command (may be used repeatedly)")); 741 printf (" %s\n", _("SMTP command (may be used repeatedly)"));
@@ -734,6 +763,7 @@ print_help (void)
734 763
735 printf (_(UT_VERBOSE)); 764 printf (_(UT_VERBOSE));
736 765
766 printf("\n");
737 printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return")); 767 printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return"));
738 printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful")); 768 printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful"));
739 printf ("%s\n", _("connects, but incorrect reponse messages from the host result in")); 769 printf ("%s\n", _("connects, but incorrect reponse messages from the host result in"));
diff --git a/plugins/t/check_smtp.t b/plugins/t/check_smtp.t
index 3bf32ec..0046a58 100644
--- a/plugins/t/check_smtp.t
+++ b/plugins/t/check_smtp.t
@@ -6,29 +6,48 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More;
10use NPTest; 10use NPTest;
11 11
12use vars qw($tests); 12my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP",
13BEGIN {$tests = 5; plan tests => $tests} 13 "A host providing an SMTP Service (a mail server)", "mailhost");
14 14
15my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", 15my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
16 "A host providing an STMP Service (a mail server)"); 16 "The hostname of system not responsive to network requests", "10.0.0.1" );
17 17
18my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", 18my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
19 "The hostname of system not responsive to network requests" ); 19 "An invalid (not known to DNS) hostname", "nosuchhost" );
20my $res;
20 21
21my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", 22plan tests => 8;
22 "An invalid (not known to DNS) hostname" );
23my %exceptions = ( 2 => "No SMTP Server present?" );
24 23
25my $t; 24SKIP: {
25 skip "No SMTP server defined", 3 unless $host_tcp_smtp;
26 $res = NPTest->testCmd( "./check_smtp $host_tcp_smtp" );
27 is ($res->return_code, 0, "OK");
28
29 $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -w 9 -c 9 -t 10 -e 220" );
30 is ($res->return_code, 0, "OK, within 9 second response");
26 31
27$t += checkCmd( "./check_smtp $host_tcp_smtp", 0, undef, %exceptions ); 32 $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220" );
28$t += checkCmd( "./check_smtp -H $host_tcp_smtp -p 25 -t 1 -w 9 -c 9 -t 10 -e 220", 0, undef, %exceptions ); 33 is ($res->return_code, 0, "OK, old syntax");
29$t += checkCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220", 0, undef, %exceptions ); 34
30$t += checkCmd( "./check_smtp $host_nonresponsive", 2 ); 35 $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -e 221" );
31$t += checkCmd( "./check_smtp $hostname_invalid", 3 ); 36 is ($res->return_code, 1, "WARNING - got correct error when expecting 221 instead of 220" );
37
38 TODO: {
39 local $TODO = "Output is over two lines";
40 like ( $res->output, qr/^SMTP WARNING/, "Correct error message" );
41 }
42
43 # SSL connection
44 $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -S" );
45 is ($res->return_code, 0, "OK, with STARTTLS" );
46}
47
48$res = NPTest->testCmd( "./check_smtp $host_nonresponsive" );
49is ($res->return_code, 2, "CRITICAL - host non responding" );
50
51$res = NPTest->testCmd( "./check_smtp $hostname_invalid" );
52is ($res->return_code, 3, "UNKNOWN - hostname invalid" );
32 53
33exit(0) if defined($Test::Harness::VERSION);
34exit($tests - $t);