Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#568 check_smtp error when combining -S and -e

CVS
open
nobody
5
2012-08-10
2012-08-10
lgarrett
No

Hi,

tested with git checkout as of today:

$ ./check_smtp -S -H mail.programmfabrik.de -e "220 mail.berlin.programmfabrik.de ESMTP Postfix (Debian/GNU)" -p 25 -D 30 -v
HELOCMD: EHLO mycomputer
220 mail.berlin.programmfabrik.de ESMTP Postfix (Debian/GNU)
Server does not support STARTTLS
sent QUIT
^C

In fact, our SMTP server does support STARTTLS, as shown here:

$ ./check_smtp -S -H mail.programmfabrik.de -p 25 -D 30 -v
HELOCMD: EHLO lgarrett-Inspiron-531
220 mail.berlin.programmfabrik.de ESMTP Postfix (Debian/GNU)
sent EHLO mycomputer
250-mail.berlin.programmfabrik.de
250-PIPELINING
250-SIZE 157286400
250-VRFY
250-ETRN
250-AUTH DIGEST-MD5 PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
sent QUIT
received 221 2.0.0 Bye

SMTP OK - 0.027 sec. response time, 221 2.0.0 Bye
|time=0.027238s;;;0.000000

Running check_smtp in gdb showed me the following:

$ gdb --args ./check_smtp -S -H mail.programmfabrik.de -e "220 mail.berlin.programmfabrik.de ESMTP Postfix (Debian/GNU)" -p 25 -D 30 -v
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /scratch/nagios/nagios-plugins/plugins/check_smtp...done.
(gdb) b 235
Breakpoint 1 at 0x403e4f: file check_smtp.c, line 235.
(gdb) run
Starting program: /scratch/nagios/nagios-plugins/plugins/check_smtp -S -H mail.programmfabrik.de -e 220\ mail.berlin.programmfabrik.de\ ESMTP\ Postfix\ \(Debian/GNU\) -p 25 -D 30 -v
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
HELOCMD: EHLO mycomputer
220 mail.berlin.programmfabrik.de ESMTP Postfix (Debian/GNU)

Breakpoint 1, main (argc=<optimized out>, argv=<optimized out>) at check_smtp.c:235
235 printf (_("Server does not support STARTTLS\n"));
(gdb) print buffer
$1 = "220 2.0.0 Ready to start TLS\r\n\000de\r\n250-PIPELINING\r\n250-SIZE 157286400\r\n250-VRFY\r\n250-ETRN\r\n250-STARTTLS\r\n250-AUTH DIGEST-MD5 PLAIN\r\n250-ENHANCEDSTATUSCODES\r\n250-8BITMIME\r\n250 DSN\r\n", '\000' <repeats 8011 times>
(gdb) print server_expect
$2 = 0x7fffffffe12e "220 mail.berlin.programmfabrik.de ESMTP Postfix (Debian/GNU)"
(gdb) q
A debugging session is active.

Inferior 1 [process 30377] will be killed.

Quit anyway? (y or n) y

Looking into the code, we are checking for the expect string in line 198 of check_smtp.c. However, we do the same again in line 234, this time matching against the returned string after the 'STARTTLS' command being sent. This looks like a bug to me. Commenting out the if-block solved my problem, I don't know if it's a proper fix though.

Regards,
Lee

Discussion