From a3d6ae19f63f6960a3b322144f5d23782149d1ff Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 1 Sep 2009 21:21:30 +0000 Subject: [PATCH] - Check the inode number for rotation in addition to checking the first line of the file. Thanks to Jonathan Kamens. - Red Hat Bugzilla - Bug 503852 - SF.net Bug #2800279. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@752 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- server/filter.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/filter.py b/server/filter.py index c749b30b..66bd5f35 100644 --- a/server/filter.py +++ b/server/filter.py @@ -31,7 +31,7 @@ from datedetector import DateDetector from mytime import MyTime from failregex import FailRegex, Regex, RegexException -import logging, re +import logging, re, os # Gets the instance of the logger. logSys = logging.getLogger("fail2ban.filter") @@ -449,6 +449,8 @@ class FileContainer: self.__handler = None # Try to open the file. Raises an exception if an error occured. handler = open(filename) + stats = os.fstat(handler.fileno()) + self.__ino = stats.st_ino try: firstLine = handler.readline() # Computes the MD5 of the first line. @@ -470,10 +472,12 @@ class FileContainer: firstLine = self.__handler.readline() # Computes the MD5 of the first line. myHash = md5.new(firstLine).digest() - # Compare hash. - if not self.__hash == myHash: + stats = os.fstat(self.__handler.fileno()) + # Compare hash and inode + if self.__hash != myHash or self.__ino != stats.st_ino: logSys.info("Log rotation detected for %s" % self.__filename) self.__hash = myHash + self.__ino = stats.st_ino self.__pos = 0 # Sets the file pointer to the last position. self.__handler.seek(self.__pos)