From be0e8faa4eab4e0b444374647360ad3d1fd9e41b Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Mon, 15 Apr 2013 21:14:12 +0100 Subject: [PATCH 1/3] TST: Add maxlines to transmitter testcases --- fail2ban/tests/servertestcase.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 4a3435b4..bc08c061 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -271,6 +271,12 @@ class Transmitter(TransmitterBase): self.setGetTest("maxretry", "-2", -2, jail=self.jailName) self.setGetTestNOK("maxretry", "Duck", jail=self.jailName) + def testJailMaxLines(self): + self.setGetTest("maxlines", "5", 5, jail=self.jailName) + self.setGetTest("maxlines", "2", 2, jail=self.jailName) + self.setGetTestNOK("maxlines", "-2", jail=self.jailName) + self.setGetTestNOK("maxlines", "Duck", jail=self.jailName) + def testJailLogPath(self): self.jailAddDelTest( "logpath", From 183cfa6e0062159b4053c4b56eabe991ea89aef0 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Mon, 15 Apr 2013 21:21:19 +0100 Subject: [PATCH 2/3] ENH: Default maxlines value in jail.conf, and verify value is int >0 --- bin/fail2ban-regex | 8 +------- config/jail.conf | 3 +++ fail2ban/server/filter.py | 6 ++++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bin/fail2ban-regex b/bin/fail2ban-regex index e05a4687..b80affab 100755 --- a/bin/fail2ban-regex +++ b/bin/fail2ban-regex @@ -136,13 +136,7 @@ class Fail2banRegex: elif opt[0] in ["-v", "--verbose"]: self.__verbose = True elif opt[0] in ["-l", "--maxlines"]: - try: - self.__filter.setMaxLines(int(opt[1])) - except ValueError: - print "Invlaid value for maxlines: %s" % ( - opt[1]) - fail2banRegex.dispUsage() - sys.exit(-1) + self.__filter.setMaxLines(opt[1]) #@staticmethod def logIsFile(value): diff --git a/config/jail.conf b/config/jail.conf index 4399d0bd..b7ba25d4 100644 --- a/config/jail.conf +++ b/config/jail.conf @@ -32,6 +32,9 @@ findtime = 600 # "maxretry" is the number of failures before a host get banned. maxretry = 3 +# "maxlines" is number of log lines to buffer for multi-line regex searches +maxlines = 1 + # "backend" specifies the backend used to get files modification. # Available options are "pyinotify", "gamin", "polling" and "auto". # This option can be overridden in each jail as well. diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index fe990578..f028b44d 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -218,8 +218,10 @@ class Filter(JailThread): # @param value the line buffer size def setMaxLines(self, value): - self.__lineBufferSize = max(1, value) - logSys.info("Set maxLines = %i" % self.__lineBufferSize) + if int(value) <= 0: + raise ValueError("maxlines must be integer greater than zero") + self.__lineBufferSize = int(value) + logSys.info("Set maxlines = %i" % self.__lineBufferSize) ## # Get the maximum line buffer size. From 1756f709da34d37336b158bdaf33ea1bb196df1b Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Mon, 15 Apr 2013 22:14:00 +0100 Subject: [PATCH 3/3] DOC: Revert change to fail2ban-refex from 183cfa6 --- bin/fail2ban-regex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/fail2ban-regex b/bin/fail2ban-regex index b80affab..e05a4687 100755 --- a/bin/fail2ban-regex +++ b/bin/fail2ban-regex @@ -136,7 +136,13 @@ class Fail2banRegex: elif opt[0] in ["-v", "--verbose"]: self.__verbose = True elif opt[0] in ["-l", "--maxlines"]: - self.__filter.setMaxLines(opt[1]) + try: + self.__filter.setMaxLines(int(opt[1])) + except ValueError: + print "Invlaid value for maxlines: %s" % ( + opt[1]) + fail2banRegex.dispUsage() + sys.exit(-1) #@staticmethod def logIsFile(value):