From dad4234beb325a1d9836c525575956d768938208 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 25 Sep 2014 18:29:10 +0200 Subject: [PATCH] The tricky bug fixed - last position of log file will be never retrieved (#795): addJail (executed before addLog) early uses a "INSERT OR REPLACE" statement to update "enabled" to 1 (and add jail the first time used at once), but this syntax in sqlite always deletes an entry (cause of constraint) and inserts it again, so because of CASCADE all log entries with this jail will be also deleted from logs table. --- fail2ban/server/database.py | 6 +++++- fail2ban/server/filter.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fail2ban/server/database.py b/fail2ban/server/database.py index 7de87554..fcc56f73 100644 --- a/fail2ban/server/database.py +++ b/fail2ban/server/database.py @@ -274,8 +274,12 @@ class Fail2BanDb(object): Jail to be added to the database. """ cur.execute( - "INSERT OR REPLACE INTO jails(name, enabled) VALUES(?, 1)", + "INSERT OR IGNORE INTO jails(name, enabled) VALUES(?, 1)", (jail.name,)) + if cur.rowcount <= 0: + cur.execute( + "UPDATE jails SET enabled = 1 WHERE name = ? AND enabled != 1", + (jail.name,)) @commitandrollback def delJail(self, cur, jail): diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index 296ff101..ee0e2a1d 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -576,7 +576,7 @@ class FileFilter(Filter): if lastpos and not tail: log.setPos(lastpos) self.__logs[path] = log - logSys.info("Added logfile = %s" % path) + logSys.info("Added logfile = %s (pos = %s, hash = %s)" , path, log.getPos(), log.getHash()) self._addLogPath(path) # backend specific def _addLogPath(self, path):