summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorHolger Weiss <hweiss@users.sourceforge.net>2007-07-31 14:47:04 (GMT)
committerHolger Weiss <hweiss@users.sourceforge.net>2007-07-31 14:47:04 (GMT)
commit0616123167c4a3e928df6605249d94f8197666d8 (patch)
treefff21a79c28426df8657a0af9955535f7fbd49c4 /plugins
parentd18b8f5d9451b65700b9260d418bd5d245318b2c (diff)
downloadmonitoring-plugins-0616123167c4a3e928df6605249d94f8197666d8.tar.gz
Read the response to an SMTP QUIT command before closing the socket
(noted by Dieter Hendricks on nagiosplug-help@) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1769 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_smtp.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index a7a0783..8d392cc 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -74,6 +74,7 @@ int process_arguments (int, char **);
74int validate_arguments (void); 74int validate_arguments (void);
75void print_help (void); 75void print_help (void);
76void print_usage (void); 76void print_usage (void);
77void smtp_quit(void);
77int my_close(void); 78int my_close(void);
78 79
79#include "regex.h" 80#include "regex.h"
@@ -258,7 +259,7 @@ main (int argc, char **argv)
258 259
259 if(use_ssl && ! supports_tls){ 260 if(use_ssl && ! supports_tls){
260 printf(_("WARNING - TLS not supported by server\n")); 261 printf(_("WARNING - TLS not supported by server\n"));
261 send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0); 262 smtp_quit();
262 return STATE_WARNING; 263 return STATE_WARNING;
263 } 264 }
264 265
@@ -270,7 +271,7 @@ main (int argc, char **argv)
270 recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */ 271 recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */
271 if (!strstr (buffer, server_expect)) { 272 if (!strstr (buffer, server_expect)) {
272 printf (_("Server does not support STARTTLS\n")); 273 printf (_("Server does not support STARTTLS\n"));
273 send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0); 274 smtp_quit();
274 return STATE_UNKNOWN; 275 return STATE_UNKNOWN;
275 } 276 }
276 result = np_net_ssl_init(sd); 277 result = np_net_ssl_init(sd);
@@ -460,7 +461,7 @@ main (int argc, char **argv)
460 } 461 }
461 462
462 /* tell the server we're done */ 463 /* tell the server we're done */
463 my_send (SMTP_QUIT, strlen (SMTP_QUIT)); 464 smtp_quit();
464 465
465 /* finally close the connection */ 466 /* finally close the connection */
466 close (sd); 467 close (sd);
@@ -704,6 +705,30 @@ validate_arguments (void)
704} 705}
705 706
706 707
708void
709smtp_quit(void)
710{
711 int bytes;
712
713 my_send(SMTP_QUIT, strlen(SMTP_QUIT));
714 if (verbose)
715 printf(_("sent %s\n"), "QUIT");
716
717 /* read the response but don't care about problems */
718 bytes = my_recv(buffer, MAXBUF - 1);
719 if (verbose) {
720 if (bytes < 0)
721 printf(_("recv() failed after QUIT."));
722 else if (bytes == 0)
723 printf(_("Connection reset by peer."));
724 else {
725 buffer[bytes] = '\0';
726 printf(_("received %s\n"), buffer);
727 }
728 }
729}
730
731
707int 732int
708my_close (void) 733my_close (void)
709{ 734{