[monitoring-plugins] Fix check_smtp using the wrong port accidentaly ...

GitHub git at monitoring-plugins.org
Fri Aug 7 13:20:14 CEST 2026


    Module: monitoring-plugins
    Branch: master
    Commit: f6c4d168ac8f97d6266e7f3e0bea8b05fb264a35
    Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
 Committer: GitHub <noreply at github.com>
      Date: Fri Aug  7 13:19:46 2026 +0200
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=f6c4d168

Fix check_smtp using the wrong port accidentaly if -D was used before -S (#2309)

If the parameters were in the wrong order (where order was not
specified, nor should it have been), `check_smtp` chose the wrong
port to connect to a server.
This fixes this behaviour and requires now explicit setting of either
TLS or STARTTLS for the connection.

---

 plugins/check_smtp.c          | 15 +++++++--------
 plugins/check_smtp.d/config.h |  2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index e1f2842e..cae63787 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -660,7 +660,6 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
 
 	unsigned long command_size = 0;
 	unsigned long response_size = 0;
-	bool implicit_tls = false;
 	int server_port_option = 0;
 	while (true) {
 		int opt_index =
@@ -792,8 +791,7 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
 #else
 			usage(_("SSL support not available - install OpenSSL and recompile"));
 #endif
-			implicit_tls = true;
-			// fallthrough
+			break;
 		case 's':
 			/* ssl */
 			result.config.use_ssl = true;
@@ -864,11 +862,12 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
 	}
 
 	if (result.config.use_starttls && result.config.use_ssl) {
-		if (implicit_tls) {
-			result.config.use_ssl = false;
-		} else {
-			usage4(_("Set either -s/--ssl/--tls or -S/--starttls"));
-		}
+		usage4(_("Set either -s/--ssl/--tls or -S/--starttls"));
+	}
+
+	if (!result.config.use_starttls && !result.config.use_ssl &&
+		(result.config.days_till_exp_crit != 0 || result.config.days_till_exp_warn != 0)) {
+		usage4(_("Set either -s/--ssl/--tls or -S/--starttls"));
 	}
 
 	if (server_port_option != 0) {
diff --git a/plugins/check_smtp.d/config.h b/plugins/check_smtp.d/config.h
index 47826362..bb61331a 100644
--- a/plugins/check_smtp.d/config.h
+++ b/plugins/check_smtp.d/config.h
@@ -53,7 +53,7 @@ typedef struct {
 	mp_output_format output_format;
 } check_smtp_config;
 
-check_smtp_config check_smtp_config_init() {
+check_smtp_config check_smtp_config_init(void) {
 	check_smtp_config tmp = {
 		.server_port = SMTP_PORT,
 		.server_address = NULL,



More information about the Commits mailing list