From 2725dd6f22bfe8e9c54c8a910f283b77a7226a82 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 8 Jan 2007 21:15:47 +0000 Subject: [PATCH] - fail2ban-client returns an error code if configuration is not valid git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@518 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 2 ++ client/configurator.py | 2 +- client/jailsreader.py | 2 ++ fail2ban-client | 20 ++++++++++++++------ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 65285a81..bd9e6631 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,8 @@ ver. 0.7.7 (2007/??/??) ---------- - Added signal handling in fail2ban-client - Added a wonderful visual effect when waiting on the server +- fail2ban-client returns an error code if configuration is + not valid ver. 0.7.6 (2007/01/04) - beta ---------- diff --git a/client/configurator.py b/client/configurator.py index f4882f4b..8181a889 100644 --- a/client/configurator.py +++ b/client/configurator.py @@ -60,7 +60,7 @@ class Configurator: def getAllOptions(self): self.__fail2ban.getOptions() - self.__jails.getOptions() + return self.__jails.getOptions() def convertToProtocol(self): self.__streams["general"] = self.__fail2ban.convert() diff --git a/client/jailsreader.py b/client/jailsreader.py index 6208572d..ada5fe09 100644 --- a/client/jailsreader.py +++ b/client/jailsreader.py @@ -54,6 +54,8 @@ class JailsReader(ConfigReader): self.__jails.append(jail) else: logSys.error("Errors in jail '" + sec + "'. Skipping...") + return False + return True def convert(self): stream = list() diff --git a/fail2ban-client b/fail2ban-client index 52103d19..dbb0f185 100755 --- a/fail2ban-client +++ b/fail2ban-client @@ -175,10 +175,14 @@ class Fail2banClient: logSys.error("Server already running") return False else: + # Read the config + ret = self.__readConfig() + # Do not continue if configuration is not 100% valid + if not ret: + return False + # Start the server self.__startServerAsync(self.__conf["socket"], self.__conf["force"]) - # Read the config while the server is starting - self.__readConfig() try: # Wait for the server to start self.__waitOnServer() @@ -194,7 +198,10 @@ class Fail2banClient: return False elif len(cmd) == 1 and cmd[0] == "reload": if self.__ping(): - self.__readConfig() + ret = self.__readConfig() + # Do not continue if configuration is not 100% valid + if not ret: + return False self.__processCmd([['stop', 'all']], False) # Configure the server return self.__processCmd(self.__stream, False) @@ -312,9 +319,9 @@ class Fail2banClient: logSys.info("Using socket file " + self.__conf["socket"]) if self.__conf["dump"]: - self.__readConfig() + ret = self.__readConfig() self.dumpConfig(self.__stream) - return True + return ret # Interactive mode if self.__conf["interactive"]: @@ -345,9 +352,10 @@ class Fail2banClient: def __readConfig(self): # Read the configuration self.__configurator.readAll() - self.__configurator.getAllOptions() + ret = self.__configurator.getAllOptions() self.__configurator.convertToProtocol() self.__stream = self.__configurator.getConfigStream() + return ret @staticmethod def dumpConfig(cmd):