[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1769] nagiosplug/trunk/plugins/check_smtp.c

hweiss at users.sourceforge.net hweiss at users.sourceforge.net
Tue Jul 31 16:47:05 CEST 2007


Revision: 1769
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1769&view=rev
Author:   hweiss
Date:     2007-07-31 07:47:04 -0700 (Tue, 31 Jul 2007)

Log Message:
-----------
Read the response to an SMTP QUIT command before closing the socket
(noted by Dieter Hendricks on nagiosplug-help@)

Modified Paths:
--------------
    nagiosplug/trunk/plugins/check_smtp.c

Modified: nagiosplug/trunk/plugins/check_smtp.c
===================================================================
--- nagiosplug/trunk/plugins/check_smtp.c	2007-07-29 12:42:05 UTC (rev 1768)
+++ nagiosplug/trunk/plugins/check_smtp.c	2007-07-31 14:47:04 UTC (rev 1769)
@@ -74,6 +74,7 @@
 int validate_arguments (void);
 void print_help (void);
 void print_usage (void);
+void smtp_quit(void);
 int my_close(void);
 
 #include "regex.h"
@@ -258,7 +259,7 @@
 
 		if(use_ssl && ! supports_tls){
 			printf(_("WARNING - TLS not supported by server\n"));
-			send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
+			smtp_quit();
 			return STATE_WARNING;
 		}
 
@@ -270,7 +271,7 @@
 		  recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */
 		  if (!strstr (buffer, server_expect)) {
 		    printf (_("Server does not support STARTTLS\n"));
-		    send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
+		    smtp_quit();
 		    return STATE_UNKNOWN;
 		  }
 		  result = np_net_ssl_init(sd);
@@ -460,7 +461,7 @@
 		}
 
 		/* tell the server we're done */
-		my_send (SMTP_QUIT, strlen (SMTP_QUIT));
+		smtp_quit();
 
 		/* finally close the connection */
 		close (sd);
@@ -704,6 +705,30 @@
 }
 
 
+void
+smtp_quit(void)
+{
+	int bytes;
+
+	my_send(SMTP_QUIT, strlen(SMTP_QUIT));
+	if (verbose)
+		printf(_("sent %s\n"), "QUIT");
+
+	/* read the response but don't care about problems */
+	bytes = my_recv(buffer, MAXBUF - 1);
+	if (verbose) {
+		if (bytes < 0)
+			printf(_("recv() failed after QUIT."));
+		else if (bytes == 0)
+			printf(_("Connection reset by peer."));
+		else {
+			buffer[bytes] = '\0';
+			printf(_("received %s\n"), buffer);
+		}
+	}
+}
+
+
 int 
 my_close (void)
 {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list