From 6fef85ff2d0be4e33b8e99d4012c42d25258ef27 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 8 May 2013 12:07:26 -0400 Subject: [PATCH 1/3] ENH: strip CR and LF while analyzing the lines (processLine) (Close #202) This should allow to resolve issues with logs written in MS-DOS fashion, e.g. with daemontools See https://github.com/fail2ban/fail2ban/issues/202\#issuecomment-17393613 --- server/filter.py | 1 + testcases/filtertestcase.py | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/server/filter.py b/server/filter.py index 754a2a08..90530f92 100644 --- a/server/filter.py +++ b/server/filter.py @@ -290,6 +290,7 @@ class Filter(JailThread): l = line.decode('utf-8') except UnicodeDecodeError: l = line + l = l.rstrip('\r\n') timeMatch = self.dateDetector.matchTime(l) if timeMatch: # Lets split into time part and log part of the line diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index 00946f90..ce142bfd 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -579,11 +579,29 @@ class GetFailures(unittest.TestCase): - def testGetFailures01(self): - self.filter.addLogPath(GetFailures.FILENAME_01) - self.filter.addFailRegex("(?:(?:Authentication failure|Failed [-/\w+]+) for(?: [iI](?:llegal|nvalid) user)?|[Ii](?:llegal|nvalid) user|ROOT LOGIN REFUSED) .*(?: from|FROM) ") - self.filter.getFailures(GetFailures.FILENAME_01) - _assert_correct_last_attempt(self, self.filter, GetFailures.FAILURES_01) + def testGetFailures01(self, filename=None, failures=None): + filename = filename or GetFailures.FILENAME_01 + failures = failures or GetFailures.FAILURES_01 + + self.filter.addLogPath(filename) + self.filter.addFailRegex("(?:(?:Authentication failure|Failed [-/\w+]+) for(?: [iI](?:llegal|nvalid) user)?|[Ii](?:llegal|nvalid) user|ROOT LOGIN REFUSED) .*(?: from|FROM) $") + self.filter.getFailures(filename) + _assert_correct_last_attempt(self, self.filter, failures) + + def testCRLFFailures01(self): + # We first adjust logfile/failures to end with CR+LF + fname = tempfile.mktemp(prefix='tmp_fail2ban', suffix='crlf') + f = open(fname, 'w') + for l in open(GetFailures.FILENAME_01).readlines(): + f.write('%s\r\n' % l.rstrip('\n')) + f.close() + + # now see if we should be getting the "same" failures + self.testGetFailures01(filename=fname, + failures=GetFailures.FAILURES_01[:3] + + ([x.rstrip('\n') + '\r\n' for x in + GetFailures.FAILURES_01[-1]],)) + _killfile(f, fname) def testGetFailures02(self): From 239406a8b9c26829453daf5a078c0debc2f4d990 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 8 May 2013 12:09:06 -0400 Subject: [PATCH 2/3] Changelog for preceeding commit --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index be28f028..a4dc4b75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -103,6 +103,7 @@ fail2ban-users mailing list and IRC. * [40c5a2d] adding more of diagnostic messages into -client while starting the daemon. * [8e63d4c] Compare against None with 'is' instead of '=='. + * [6fef85f] Strip CR and LF while analyzing the log line Daniel Black * [3aeb1a9] Add jail.conf manual page. Closes gh-143. * [MANY] man page edits. From f4d2b5b33860c6ad6b6e8e83e67c2e451dabc04c Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 8 May 2013 16:12:37 -0400 Subject: [PATCH 3/3] Previous coverage was 56% (without disregarding any pragma) --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index be28f028..50ffe209 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,7 +12,7 @@ ver. 0.8.9 (2013/05/XX) - wanna-be-stable Originally targeted as a bugfix release, it incorporated many new enhancements, few new features, and more importantly -- quite extended -tests battery with current 94% coverage. +tests battery with current 94% coverage (from 56% of 0.8.8). This release introduces over 200 of non-merge commits from 16 contributors (sorted by number of commits): Yaroslav Halchenko, Daniel