From 2918849f9e781fc27a0fd0ba052c1a97d96d02bc Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 7 May 2021 01:10:26 +0200 Subject: [PATCH] fixes precise year pattern %ExY - accept years 20xx up to current century (using almost the same pattern in tests and production now) --- fail2ban/server/strptime.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fail2ban/server/strptime.py b/fail2ban/server/strptime.py index 69514b20..6f88add1 100644 --- a/fail2ban/server/strptime.py +++ b/fail2ban/server/strptime.py @@ -104,14 +104,14 @@ def _updateTimeRE(): # more precise year patterns, within same century of last year and # the next 3 years (for possible long uptime of fail2ban); thereby - # respect possible run in the test-cases (alternate date used there): - if MyTime.alternateNowTime != 0: - timeRE['ExY'] = r"(?P%s\d)" % _getYearCentRE(cent=(0,3), distance=3) - timeRE['Exy'] = r"(?P%s\d)" % _getYearCentRE(cent=(2,3), distance=3) - else: # accept years: 19xx|2xxx up to current century - timeRE['ExY'] = r"(?P(?:19\d{2}|%s\d))" % _getYearCentRE(cent=(0,3), distance=3, - now=(MyTime.now(), datetime.datetime.fromtimestamp(978393600))) - timeRE['Exy'] = r"(?P\d{2})" + # consider possible run in the test-cases (alternate date used there), + # so accept years: 20xx (from test-date or 2001 up to current century) + timeRE['ExY'] = r"(?P%s\d)" % _getYearCentRE(cent=(0,3), distance=3, + now=(datetime.datetime.now(), datetime.datetime.fromtimestamp( + min(MyTime.alternateNowTime or 978393600, 978393600)) + ) + ) + timeRE['Exy'] = r"(?P\d{2})" _updateTimeRE()