summaryrefslogtreecommitdiffstats
path: root/plugins/check_smtp.c
diff options
context:
space:
mode:
authorOliver Skibbe <oliskibbe@gmail.com>2016-11-19 15:38:07 (GMT)
committerGitHub <noreply@github.com>2016-11-19 15:38:07 (GMT)
commit6438fec7888ffca6d435abffd5283bcc1a9814b5 (patch)
tree2fb2cfc85f84ba1c9181dbc73c105e9eb4dd31fb /plugins/check_smtp.c
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
Diffstat (limited to 'plugins/check_smtp.c')
-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 587a724..6e0e22e 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -124,6 +124,7 @@ main (int argc, char **argv)
124 char *cmd_str = NULL; 124 char *cmd_str = NULL;
125 char *helocmd = NULL; 125 char *helocmd = NULL;
126 char *error_msg = ""; 126 char *error_msg = "";
127 char *server_response = NULL;
127 struct timeval tv; 128 struct timeval tv;
128 129
129 /* Catch pipe errors in read/write - sometimes occurs when writing QUIT */ 130 /* Catch pipe errors in read/write - sometimes occurs when writing QUIT */
@@ -185,21 +186,9 @@ main (int argc, char **argv)
185 printf (_("recv() failed\n")); 186 printf (_("recv() failed\n"));
186 return STATE_WARNING; 187 return STATE_WARNING;
187 } 188 }
188 else { 189
189 if (verbose) 190 /* save connect return (220 hostname ..) for later use */
190 printf ("%s", buffer); 191 xasprintf(&server_response, "%s", buffer);
191 /* strip the buffer of carriage returns */
192 strip (buffer);
193 /* make sure we find the response we are looking for */
194 if (!strstr (buffer, server_expect)) {
195 if (server_port == SMTP_PORT)
196 printf (_("Invalid SMTP response received from host: %s\n"), buffer);
197 else
198 printf (_("Invalid SMTP response received from host on port %d: %s\n"),
199 server_port, buffer);
200 return STATE_WARNING;
201 }
202 }
203 192
204 /* send the HELO/EHLO command */ 193 /* send the HELO/EHLO command */
205 send(sd, helocmd, strlen(helocmd), 0); 194 send(sd, helocmd, strlen(helocmd), 0);
@@ -280,6 +269,24 @@ main (int argc, char **argv)
280 } 269 }
281#endif 270#endif
282 271
272 if (verbose)
273 printf ("%s", buffer);
274
275 /* save buffer for later use */
276 xasprintf(&server_response, "%s%s", server_response, buffer);
277 /* strip the buffer of carriage returns */
278 strip (server_response);
279
280 /* make sure we find the droids we are looking for */
281 if (!strstr (server_response, server_expect)) {
282 if (server_port == SMTP_PORT)
283 printf (_("Invalid SMTP response received from host: %s\n"), server_response);
284 else
285 printf (_("Invalid SMTP response received from host on port %d: %s\n"),
286 server_port, server_response);
287 return STATE_WARNING;
288 }
289
283 if (send_mail_from) { 290 if (send_mail_from) {
284 my_send(cmd_str, strlen(cmd_str)); 291 my_send(cmd_str, strlen(cmd_str));
285 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose) 292 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)