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.
pull/1346/head
sebres 2014-09-25 18:29:10 +02:00
parent 410f9d7c10
commit dad4234beb
2 changed files with 6 additions and 2 deletions

View File

@ -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):

View File

@ -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):