summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorOliver Skibbe <oliskibbe@gmail.com>2015-10-08 09:09:25 (GMT)
committerOliver Skibbe <oliskibbe@gmail.com>2015-10-08 09:09:25 (GMT)
commit6b8c0bdf11f3a94ed85774932fdf90a9c882eeea (patch)
tree9652c062bb8a4cabc9e64b1db26d90ba1cfc7f83 /plugins
parentb6de2341f8683d51b8723b772e4753507b1607f5 (diff)
downloadmonitoring-plugins-6b8c0bd.tar.gz
check_smtp: extended support for expect optionrefs/pull/1382/head
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
Diffstat (limited to 'plugins')
-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 1996c6d..a1c5f7e 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -128,6 +128,7 @@ main (int argc, char **argv)
128 char *cmd_str = NULL; 128 char *cmd_str = NULL;
129 char *helocmd = NULL; 129 char *helocmd = NULL;
130 char *error_msg = ""; 130 char *error_msg = "";
131 char *server_response = NULL;
131 struct timeval tv; 132 struct timeval tv;
132 133
133 /* Catch pipe errors in read/write - sometimes occurs when writing QUIT */ 134 /* Catch pipe errors in read/write - sometimes occurs when writing QUIT */
@@ -189,21 +190,9 @@ main (int argc, char **argv)
189 printf (_("recv() failed\n")); 190 printf (_("recv() failed\n"));
190 return STATE_WARNING; 191 return STATE_WARNING;
191 } 192 }
192 else { 193
193 if (verbose) 194 /* save connect return (220 hostname ..) for later use */
194 printf ("%s", buffer); 195 xasprintf(&server_response, "%s", buffer);
195 /* strip the buffer of carriage returns */
196 strip (buffer);
197 /* make sure we find the response we are looking for */
198 if (!strstr (buffer, server_expect)) {
199 if (server_port == SMTP_PORT)
200 printf (_("Invalid SMTP response received from host: %s\n"), buffer);
201 else
202 printf (_("Invalid SMTP response received from host on port %d: %s\n"),
203 server_port, buffer);
204 return STATE_WARNING;
205 }
206 }
207 196
208 /* send the HELO/EHLO command */ 197 /* send the HELO/EHLO command */
209 send(sd, helocmd, strlen(helocmd), 0); 198 send(sd, helocmd, strlen(helocmd), 0);
@@ -284,6 +273,24 @@ main (int argc, char **argv)
284 } 273 }
285#endif 274#endif
286 275
276 if (verbose)
277 printf ("%s", buffer);
278
279 /* save buffer for later use */
280 xasprintf(&server_response, "%s%s", server_response, buffer);
281 /* strip the buffer of carriage returns */
282 strip (server_response);
283
284 /* make sure we find the droids we are looking for */
285 if (!strstr (server_response, server_expect)) {
286 if (server_port == SMTP_PORT)
287 printf (_("Invalid SMTP response received from host: %s\n"), server_response);
288 else
289 printf (_("Invalid SMTP response received from host on port %d: %s\n"),
290 server_port, server_response);
291 return STATE_WARNING;
292 }
293
287 if (send_mail_from) { 294 if (send_mail_from) {
288 my_send(cmd_str, strlen(cmd_str)); 295 my_send(cmd_str, strlen(cmd_str));
289 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose) 296 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)