[Nagiosplug-devel] PATCH: SMTP auth support in nagios plugin check_smtp.c

Holger Weiss holger at CIS.FU-Berlin.DE
Wed Nov 2 20:02:39 CET 2005


* Holger Weiss <holger at CIS.FU-Berlin.DE> [2005-11-03 04:14]:
> I've attached a patch for the current code, it would be nice if it could
> be applied.

Sorry, minor update -- just realized that using 'helocmd' in the plugin
output is ugly because it contains a newline.

Holger

-- 
PGP fingerprint:  F1F0 9071 8084 A426 DD59  9839 59D3 F3A1 B8B5 D3DE
-------------- next part --------------
Index: check_smtp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_smtp.c,v
retrieving revision 1.50
diff -u -r1.50 check_smtp.c
--- check_smtp.c	2 Nov 2005 08:47:26 -0000	1.50
+++ check_smtp.c	3 Nov 2005 03:59:39 -0000
@@ -270,6 +270,35 @@
 		  } else {
 			ssl_established = 1;
 		  }
+
+		/*
+		 * Resend the EHLO command.
+		 *
+		 * RFC 3207 (4.2) says: ``The client MUST discard any knowledge
+		 * obtained from the server, such as the list of SMTP service
+		 * extensions, which was not obtained from the TLS negotiation
+		 * itself.  The client SHOULD send an EHLO command as the first
+		 * command after a successful TLS negotiation.''  For this
+		 * reason, some MTAs will not allow an AUTH LOGIN command before
+		 * we resent EHLO via TLS.
+		 */
+		if (my_send(helocmd, strlen(helocmd)) <= 0) {
+			printf(_("SMTP UNKNOWN - Cannot send EHLO command via TLS.\n"));
+			np_net_ssl_cleanup(), close(sd);
+			return STATE_UNKNOWN;
+		}
+		if (verbose)
+			printf(_("sent %s"), helocmd);
+		if ((n = my_recv(buffer, MAX_INPUT_BUFFER - 1)) <= 0) {
+			printf(_("SMTP UNKNOWN - Cannot read EHLO response via TLS.\n"));
+			np_net_ssl_cleanup(), close(sd);
+			return STATE_UNKNOWN;
+		}
+		if (verbose) {
+			buffer[n] = '\0';
+			printf("%s", buffer);
+		}
+
 #  ifdef USE_OPENSSL
 		  if ( check_cert ) {
 		    result = np_net_ssl_check_cert(days_till_exp);


More information about the Devel mailing list