aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Oliver Skibbe <oliskibbe@gmail.com> 2016-11-19 16:38:07 +0100
committerGravatar GitHub <noreply@github.com> 2016-11-19 16:38:07 +0100
commit6438fec7888ffca6d435abffd5283bcc1a9814b5 (patch)
tree2fb2cfc85f84ba1c9181dbc73c105e9eb4dd31fb
parent099bd86f1c949b0db05c5c24b2538c8e3370d290 (diff)
parent6b8c0bdf11f3a94ed85774932fdf90a9c882eeea (diff)
downloadmonitoring-plugins-6438fec7888ffca6d435abffd5283bcc1a9814b5.tar.gz
Merge pull request #1382 from riskersen/smtp_tls_expec
check_smtp: extended support for expect option
-rw-r--r--plugins/check_smtp.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 587a7245..6e0e22ed 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -124,6 +124,7 @@ main (int argc, char **argv)
char *cmd_str = NULL;
char *helocmd = NULL;
char *error_msg = "";
+ char *server_response = NULL;
struct timeval tv;
/* Catch pipe errors in read/write - sometimes occurs when writing QUIT */
@@ -185,21 +186,9 @@ main (int argc, char **argv)
printf (_("recv() failed\n"));
return STATE_WARNING;
}
- else {
- if (verbose)
- printf ("%s", buffer);
- /* strip the buffer of carriage returns */
- strip (buffer);
- /* make sure we find the response we are looking for */
- if (!strstr (buffer, server_expect)) {
- if (server_port == SMTP_PORT)
- printf (_("Invalid SMTP response received from host: %s\n"), buffer);
- else
- printf (_("Invalid SMTP response received from host on port %d: %s\n"),
- server_port, buffer);
- return STATE_WARNING;
- }
- }
+
+ /* save connect return (220 hostname ..) for later use */
+ xasprintf(&server_response, "%s", buffer);
/* send the HELO/EHLO command */
send(sd, helocmd, strlen(helocmd), 0);
@@ -280,6 +269,24 @@ main (int argc, char **argv)
}
#endif
+ if (verbose)
+ printf ("%s", buffer);
+
+ /* save buffer for later use */
+ xasprintf(&server_response, "%s%s", server_response, buffer);
+ /* strip the buffer of carriage returns */
+ strip (server_response);
+
+ /* make sure we find the droids we are looking for */
+ if (!strstr (server_response, server_expect)) {
+ if (server_port == SMTP_PORT)
+ printf (_("Invalid SMTP response received from host: %s\n"), server_response);
+ else
+ printf (_("Invalid SMTP response received from host on port %d: %s\n"),
+ server_port, server_response);
+ return STATE_WARNING;
+ }
+
if (send_mail_from) {
my_send(cmd_str, strlen(cmd_str));
if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)