mirror of https://github.com/fail2ban/fail2ban
Merge branch '0.10' into 0.11
commit
f51712d275
|
@ -37,6 +37,7 @@ logSys = getLogger(__name__)
|
||||||
class FilterReader(DefinitionInitConfigReader):
|
class FilterReader(DefinitionInitConfigReader):
|
||||||
|
|
||||||
_configOpts = {
|
_configOpts = {
|
||||||
|
"usedns": ["string", None],
|
||||||
"prefregex": ["string", None],
|
"prefregex": ["string", None],
|
||||||
"ignoreregex": ["string", None],
|
"ignoreregex": ["string", None],
|
||||||
"failregex": ["string", None],
|
"failregex": ["string", None],
|
||||||
|
@ -61,6 +62,7 @@ class FilterReader(DefinitionInitConfigReader):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _fillStream(stream, opts, jailName):
|
def _fillStream(stream, opts, jailName):
|
||||||
|
prio0idx = 0
|
||||||
for opt, value in opts.iteritems():
|
for opt, value in opts.iteritems():
|
||||||
if opt in ("failregex", "ignoreregex"):
|
if opt in ("failregex", "ignoreregex"):
|
||||||
if value is None: continue
|
if value is None: continue
|
||||||
|
@ -73,9 +75,11 @@ class FilterReader(DefinitionInitConfigReader):
|
||||||
stream.append(["multi-set", jailName, "add" + opt, multi])
|
stream.append(["multi-set", jailName, "add" + opt, multi])
|
||||||
elif len(multi):
|
elif len(multi):
|
||||||
stream.append(["set", jailName, "add" + opt, multi[0]])
|
stream.append(["set", jailName, "add" + opt, multi[0]])
|
||||||
elif opt in ('maxlines', 'prefregex'):
|
elif opt in ('usedns', 'maxlines', 'prefregex'):
|
||||||
# Be sure we set this options first.
|
# Be sure we set this options first, and usedns is before all regex(s).
|
||||||
stream.insert(0, ["set", jailName, opt, value])
|
stream.insert(0 if opt == 'usedns' else prio0idx,
|
||||||
|
["set", jailName, opt, value])
|
||||||
|
prio0idx += 1
|
||||||
elif opt in ('datepattern'):
|
elif opt in ('datepattern'):
|
||||||
stream.append(["set", jailName, opt, value])
|
stream.append(["set", jailName, opt, value])
|
||||||
elif opt == 'journalmatch':
|
elif opt == 'journalmatch':
|
||||||
|
|
|
@ -105,7 +105,6 @@ class JailReader(ConfigReader):
|
||||||
"bantime.maxtime": ["string", None],
|
"bantime.maxtime": ["string", None],
|
||||||
"bantime.rndtime": ["string", None],
|
"bantime.rndtime": ["string", None],
|
||||||
"bantime.overalljails": ["bool", None],
|
"bantime.overalljails": ["bool", None],
|
||||||
"usedns": ["string", None], # be sure usedns is before all regex(s) in stream
|
|
||||||
"ignorecommand": ["string", None],
|
"ignorecommand": ["string", None],
|
||||||
"ignoreself": ["bool", None],
|
"ignoreself": ["bool", None],
|
||||||
"ignoreip": ["string", None],
|
"ignoreip": ["string", None],
|
||||||
|
@ -113,11 +112,13 @@ class JailReader(ConfigReader):
|
||||||
"filter": ["string", ""],
|
"filter": ["string", ""],
|
||||||
"logtimezone": ["string", None],
|
"logtimezone": ["string", None],
|
||||||
"logencoding": ["string", None],
|
"logencoding": ["string", None],
|
||||||
"logpath": ["string", None], # logpath after all log-related data (backend, date-pattern, etc)
|
"logpath": ["string", None],
|
||||||
"action": ["string", ""]
|
"action": ["string", ""]
|
||||||
}
|
}
|
||||||
_configOpts.update(FilterReader._configOpts)
|
_configOpts.update(FilterReader._configOpts)
|
||||||
|
|
||||||
|
_ignoreOpts = set(['action', 'filter', 'enabled'] + FilterReader._configOpts.keys())
|
||||||
|
|
||||||
def getOptions(self):
|
def getOptions(self):
|
||||||
|
|
||||||
# Before interpolation (substitution) add static options always available as default:
|
# Before interpolation (substitution) add static options always available as default:
|
||||||
|
@ -234,6 +235,7 @@ class JailReader(ConfigReader):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
stream = []
|
stream = []
|
||||||
|
stream2 = []
|
||||||
e = self.__opts.get('config-error')
|
e = self.__opts.get('config-error')
|
||||||
if e:
|
if e:
|
||||||
stream.extend([['config-error', "Jail '%s' skipped, because of wrong configuration: %s" % (self.__name, e)]])
|
stream.extend([['config-error', "Jail '%s' skipped, because of wrong configuration: %s" % (self.__name, e)]])
|
||||||
|
@ -255,23 +257,22 @@ class JailReader(ConfigReader):
|
||||||
logSys.notice("No file(s) found for glob %s" % path)
|
logSys.notice("No file(s) found for glob %s" % path)
|
||||||
for p in pathList:
|
for p in pathList:
|
||||||
found_files += 1
|
found_files += 1
|
||||||
stream.append(
|
# logpath after all log-related data (backend, date-pattern, etc)
|
||||||
|
stream2.append(
|
||||||
["set", self.__name, "addlogpath", p, tail])
|
["set", self.__name, "addlogpath", p, tail])
|
||||||
if not found_files:
|
if not found_files:
|
||||||
msg = "Have not found any log file for %s jail" % self.__name
|
msg = "Have not found any log file for %s jail" % self.__name
|
||||||
if not allow_no_files:
|
if not allow_no_files:
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
logSys.warning(msg)
|
logSys.warning(msg)
|
||||||
|
|
||||||
elif opt == "logencoding":
|
|
||||||
stream.append(["set", self.__name, "logencoding", value])
|
|
||||||
elif opt == "backend":
|
elif opt == "backend":
|
||||||
backend = value
|
backend = value
|
||||||
elif opt == "ignoreip":
|
elif opt == "ignoreip":
|
||||||
stream.append(["set", self.__name, "addignoreip"] + splitwords(value))
|
stream.append(["set", self.__name, "addignoreip"] + splitwords(value))
|
||||||
elif (opt not in ('action', 'filter', 'enabled')
|
elif opt not in JailReader._ignoreOpts:
|
||||||
and opt not in FilterReader._configOpts):
|
|
||||||
stream.append(["set", self.__name, opt, value])
|
stream.append(["set", self.__name, opt, value])
|
||||||
|
# consider options order (after other options):
|
||||||
|
if stream2: stream += stream2
|
||||||
for action in self.__actions:
|
for action in self.__actions:
|
||||||
if isinstance(action, (ConfigReaderUnshared, ConfigReader)):
|
if isinstance(action, (ConfigReaderUnshared, ConfigReader)):
|
||||||
stream.extend(action.convert())
|
stream.extend(action.convert())
|
||||||
|
|
|
@ -321,6 +321,13 @@ class JailReaderTest(LogCaptureTestCase):
|
||||||
# maxlines:
|
# maxlines:
|
||||||
self.assertEqual([['set', 'sshd-override-flt-opts', 'maxlines', 2]],
|
self.assertEqual([['set', 'sshd-override-flt-opts', 'maxlines', 2]],
|
||||||
[o for o in stream if len(o) > 2 and o[2] == 'maxlines'])
|
[o for o in stream if len(o) > 2 and o[2] == 'maxlines'])
|
||||||
|
# usedns should be before all regex in jail stream:
|
||||||
|
usednsidx = stream.index(['set', 'sshd-override-flt-opts', 'usedns', 'no'])
|
||||||
|
i = 0
|
||||||
|
for o in stream:
|
||||||
|
self.assertFalse(len(o) > 2 and o[2].endswith('regex'))
|
||||||
|
i += 1
|
||||||
|
if i > usednsidx: break
|
||||||
|
|
||||||
def testSplitOption(self):
|
def testSplitOption(self):
|
||||||
# Simple example
|
# Simple example
|
||||||
|
|
|
@ -69,6 +69,8 @@ filter = zzz-sshd-obsolete-multiline[logtype=short]
|
||||||
backend = systemd
|
backend = systemd
|
||||||
prefregex = ^Test
|
prefregex = ^Test
|
||||||
failregex = ^Test unused <ADDR>$
|
failregex = ^Test unused <ADDR>$
|
||||||
|
ignoreregex = ^Test ignore <ADDR>$
|
||||||
journalmatch = _COMM=test
|
journalmatch = _COMM=test
|
||||||
maxlines = 2
|
maxlines = 2
|
||||||
|
usedns = no
|
||||||
enabled = false
|
enabled = false
|
||||||
|
|
Loading…
Reference in New Issue