From e6127a278e51ec3b04f052790de809a78beec00e 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 8227dea5..b3bae41b 100644 --- a/fail2ban/server/database.py +++ b/fail2ban/server/database.py @@ -265,8 +265,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 30c8c48d..deada0e0 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -570,7 +570,7 @@ class FileFilter(Filter): if lastpos and not tail: container.setPos(lastpos) self.__logPath.append(container) - logSys.info("Added logfile = %s" % path) + logSys.info("Added logfile = %s (pos = %s, hash = %s)" , path, container.getPos(), container.getHash()) self._addLogPath(path) # backend specific def _addLogPath(self, path):