mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-04-22 14:46:57 -04:00
check_smtp: extended support for expect option
expect option (-e) supported only first response, so checking for any other response like 250-xxx would never match. This fix stores return of relevant buffer closes #1381
This commit is contained in:
parent
b6de2341f8
commit
6b8c0bdf11
1 changed files with 22 additions and 15 deletions
|
|
@ -128,6 +128,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 */
|
||||
|
|
@ -189,21 +190,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);
|
||||
|
|
@ -284,6 +273,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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue