[monitoring-plugins] check_smtp: Let port option always take precedence

Franz Schwartau git at monitoring-plugins.org
Tue Aug 29 17:00:13 CEST 2023


 Module: monitoring-plugins
 Branch: master
 Commit: ce96ef868a5ee14947b9e213e3c36917cdd9e786
 Author: Franz Schwartau <franz at electromail.org>
   Date: Tue Aug 29 09:35:53 2023 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=ce96ef8

check_smtp: Let port option always take precedence

Otherwise -s/--ssl would overwrite a port given with -p if it comes
after it, e. g.

check_smtp -H mailhost.example.com -p 4465 --ssl

Found-By: Lorenz Kästle

---

 plugins/check_smtp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 3990ad8..fc0ae2c 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -84,6 +84,7 @@ int eflags = 0;
 int errcode, excode;
 
 int server_port = SMTP_PORT;
+int server_port_option = 0;
 char *server_address = NULL;
 char *server_expect = NULL;
 char *mail_command = NULL;
@@ -544,7 +545,7 @@ process_arguments (int argc, char **argv)
 			break;
 		case 'p':									/* port */
 			if (is_intpos (optarg))
-				server_port = atoi (optarg);
+				server_port_option = atoi (optarg);
 			else
 				usage4 (_("Port must be a positive integer"));
 			break;
@@ -719,6 +720,10 @@ process_arguments (int argc, char **argv)
 		usage4 (_("Set either -s/--ssl/--tls or -S/--starttls"));
 	}
 
+	if (server_port_option != 0) {
+		server_port = server_port_option;
+	}
+
 	return validate_arguments ();
 }
 



More information about the Commits mailing list