really skips invalid jails (because of theirs wrong configuration) - server starts nevertheless, as long as one jail was successful configured;

message about wrong jail configuration logged in client log (stdout, systemd journal etc.) and in server log as error
pull/1619/head
sebres 2016-11-22 13:19:09 +01:00
parent 261f875748
commit 77dc5a334c
3 changed files with 86 additions and 64 deletions

View File

@ -118,10 +118,12 @@ class JailReader(ConfigReader):
defsec = self._cfg.get_defaults()
defsec["fail2ban_version"] = version
try:
# Read first options only needed for merge defaults ('known/...' from filter):
self.__opts = ConfigReader.getOptions(self, self.__name, opts1st, shouldExist=True)
if not self.__opts:
return False
raise ValueError("Init jail options failed")
if self.isEnabled():
# Read filter
@ -135,8 +137,7 @@ class JailReader(ConfigReader):
self.__filter.getOptions(self.__opts)
ConfigReader.merge_section(self, self.__name, self.__filter.getCombined(), 'known/')
if not ret:
logSys.error("Unable to read the filter")
return False
raise ValueError("Unable to read the filter %r" % filterName)
else:
self.__filter = None
logSys.warning("No filter set for jail %s" % self.__name)
@ -144,7 +145,7 @@ class JailReader(ConfigReader):
# Read second all options (so variables like %(known/param) can be interpolated):
self.__opts = ConfigReader.getOptions(self, self.__name, opts)
if not self.__opts:
return False
raise ValueError("Read jail options failed")
# cumulate filter options again (ignore given in jail):
if self.__filter:
@ -177,11 +178,18 @@ class JailReader(ConfigReader):
else:
raise AttributeError("Unable to read action")
except Exception as e:
logSys.error("Error in action definition " + act)
logSys.debug("Caught exception: %s" % (e,))
return False
raise ValueError("Error in action definition %r" % e)
if not len(self.__actions):
logSys.warning("No actions were defined for %s" % self.__name)
except ValueError as e:
e = str(e)
logSys.error(e)
if not self.__opts:
self.__opts = dict()
self.__opts['config-error'] = e
return False
return True
def convert(self, allow_no_files=False):
@ -195,6 +203,10 @@ class JailReader(ConfigReader):
"""
stream = []
e = self.__opts.get('config-error')
if e:
stream.extend([['config-error', "Jail '%s' skipped, because of wrong configuration: %s" % (self.__name, e)]])
return stream
for opt, value in self.__opts.iteritems():
if opt == "logpath" and \
not self.__opts.get('backend', None).startswith("systemd"):

View File

@ -66,7 +66,7 @@ class JailsReader(ConfigReader):
sections = [ section ]
# Get the options of all jails.
parse_status = True
parse_status = None
for sec in sections:
if sec == 'INCLUDES':
continue
@ -77,11 +77,17 @@ class JailsReader(ConfigReader):
ret = jail.getOptions()
if ret:
if jail.isEnabled():
# at least one jail was successful:
parse_status = True
# We only add enabled jails
self.__jails.append(jail)
else:
logSys.error("Errors in jail %r. Skipping..." % sec)
self.__jails.append(jail)
if parse_status is None:
parse_status = False
if parse_status is None:
parse_status = True
return parse_status
def convert(self, allow_no_files=False):
@ -103,6 +109,7 @@ class JailsReader(ConfigReader):
stream.extend(jail.convert(allow_no_files=allow_no_files))
# Start jails
for jail in self.__jails:
if not jail.options.get('config-error'):
stream.append(["start", jail.getName()])
return stream

View File

@ -131,6 +131,9 @@ class Transmitter:
return self.status(command[1:])
elif command[0] == "version":
return version.version
elif command[0] == "config-error":
logSys.error(command[1])
return None
raise Exception("Invalid command")
def __commandSet(self, command, multiple=False):