From b0d4eb07e5719a03c9eb0edf647cd0ff3272291e Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 19 Mar 2025 02:44:32 +0100 Subject: [PATCH] command-line: test config shall output error directly and not using logger --- fail2ban/client/fail2banclient.py | 2 ++ fail2ban/client/fail2bancmdline.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fail2ban/client/fail2banclient.py b/fail2ban/client/fail2banclient.py index e8fa410d..941a8661 100755 --- a/fail2ban/client/fail2banclient.py +++ b/fail2ban/client/fail2banclient.py @@ -406,6 +406,8 @@ class Fail2banClient(Fail2banCmdLine, Thread): if ret is not None: if ret: return True + if self._conf.get("test", False) and not self._args: # test only + return False raise ServerExecutionException("Init of command line failed") # Commands diff --git a/fail2ban/client/fail2bancmdline.py b/fail2ban/client/fail2bancmdline.py index 62008288..49b32ddb 100644 --- a/fail2ban/client/fail2bancmdline.py +++ b/fail2ban/client/fail2bancmdline.py @@ -260,12 +260,15 @@ class Fail2banCmdLine(): if readcfg: readcfg = False ret, stream = self.readConfig() - if not ret: - raise ServerExecutionException("ERROR: test configuration failed") # exit after test if no commands specified (test only): if not len(self._args): - output("OK: configuration test is successful") + if ret: + output("OK: configuration test is successful") + else: + output("ERROR: test configuration failed") return ret + if not ret: + raise ServerExecutionException("ERROR: test configuration failed") # Nothing to do here, process in client/server return None