summaryrefslogtreecommitdiffstats
path: root/plugins/check_smtp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r--plugins/check_smtp.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 1996c6d..d37c57c 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -59,10 +59,6 @@ enum {
59#define SMTP_STARTTLS "STARTTLS\r\n" 59#define SMTP_STARTTLS "STARTTLS\r\n"
60#define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n" 60#define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n"
61 61
62#ifndef HOST_MAX_BYTES
63#define HOST_MAX_BYTES 255
64#endif
65
66#define EHLO_SUPPORTS_STARTTLS 1 62#define EHLO_SUPPORTS_STARTTLS 1
67 63
68int process_arguments (int, char **); 64int process_arguments (int, char **);
@@ -128,6 +124,7 @@ main (int argc, char **argv)
128 char *cmd_str = NULL; 124 char *cmd_str = NULL;
129 char *helocmd = NULL; 125 char *helocmd = NULL;
130 char *error_msg = ""; 126 char *error_msg = "";
127 char *server_response = NULL;
131 struct timeval tv; 128 struct timeval tv;
132 129
133 /* Catch pipe errors in read/write - sometimes occurs when writing QUIT */ 130 /* Catch pipe errors in read/write - sometimes occurs when writing QUIT */
@@ -189,21 +186,9 @@ main (int argc, char **argv)
189 printf (_("recv() failed\n")); 186 printf (_("recv() failed\n"));
190 return STATE_WARNING; 187 return STATE_WARNING;
191 } 188 }
192 else { 189
193 if (verbose) 190 /* save connect return (220 hostname ..) for later use */
194 printf ("%s", buffer); 191 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 192
208 /* send the HELO/EHLO command */ 193 /* send the HELO/EHLO command */
209 send(sd, helocmd, strlen(helocmd), 0); 194 send(sd, helocmd, strlen(helocmd), 0);
@@ -239,8 +224,8 @@ main (int argc, char **argv)
239 result = np_net_ssl_init(sd); 224 result = np_net_ssl_init(sd);
240 if(result != STATE_OK) { 225 if(result != STATE_OK) {
241 printf (_("CRITICAL - Cannot create SSL context.\n")); 226 printf (_("CRITICAL - Cannot create SSL context.\n"));
242 np_net_ssl_cleanup();
243 close(sd); 227 close(sd);
228 np_net_ssl_cleanup();
244 return STATE_CRITICAL; 229 return STATE_CRITICAL;
245 } else { 230 } else {
246 ssl_established = 1; 231 ssl_established = 1;
@@ -284,12 +269,31 @@ main (int argc, char **argv)
284 } 269 }
285#endif 270#endif
286 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
287 if (send_mail_from) { 290 if (send_mail_from) {
288 my_send(cmd_str, strlen(cmd_str)); 291 my_send(cmd_str, strlen(cmd_str));
289 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose) 292 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)
290 printf("%s", buffer); 293 printf("%s", buffer);
291 } 294 }
292 295
296 n = 0;
293 while (n < ncommands) { 297 while (n < ncommands) {
294 xasprintf (&cmd_str, "%s%s", commands[n], "\r\n"); 298 xasprintf (&cmd_str, "%s%s", commands[n], "\r\n");
295 my_send(cmd_str, strlen(cmd_str)); 299 my_send(cmd_str, strlen(cmd_str));
@@ -764,10 +768,12 @@ recvlines(char *buf, size_t bufsize)
764int 768int
765my_close (void) 769my_close (void)
766{ 770{
771 int result;
772 result = close(sd);
767#ifdef HAVE_SSL 773#ifdef HAVE_SSL
768 np_net_ssl_cleanup(); 774 np_net_ssl_cleanup();
769#endif 775#endif
770 return close(sd); 776 return result;
771} 777}
772 778
773 779
@@ -830,7 +836,7 @@ print_help (void)
830 printf("\n"); 836 printf("\n");
831 printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return")); 837 printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return"));
832 printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful")); 838 printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful"));
833 printf ("%s\n", _("connects, but incorrect reponse messages from the host result in")); 839 printf ("%s\n", _("connects, but incorrect response messages from the host result in"));
834 printf ("%s\n", _("STATE_WARNING return values.")); 840 printf ("%s\n", _("STATE_WARNING return values."));
835 841
836 printf (UT_SUPPORT); 842 printf (UT_SUPPORT);