fixes `ignoreip` prefix `file://` - it shall resolve absolute file name (starting with `/`) unless it starts with `./`;

relative paths are based relative the working dir;
to use it relative current config root (normally `/etc/fail2ban`), one can use interpolation `%(fail2ban_confpath)s`, e.g.:
  file://%(fail2ban_confpath)s/ignore-ipaddr-file
pull/3598/merge
sebres 2025-08-12 23:46:10 +02:00
parent 3ce6f344e3
commit 4e22c20559
1 changed files with 6 additions and 9 deletions

View File

@ -739,11 +739,11 @@ class IPAddrSet(set):
class FileIPAddrSet(IPAddrSet): class FileIPAddrSet(IPAddrSet):
# RE matching file://... # RE matching file://... (absolute as well as relative file name)
RE_FILE_IGN_IP = re.compile(r'^file:/{0,2}(.*)$') RE_FILE_IGN_IP = re.compile(r'^file:(?:/{0,2}(?=/(?!/|.{1,2}/))|/{0,2})(.*)$')
fileName = '' fileName = ''
_shortRepr = None _reprName = None
maxUpdateLatency = 1 # latency in seconds to update by changes maxUpdateLatency = 1 # latency in seconds to update by changes
_nextCheck = 0 _nextCheck = 0
_fileStats = () _fileStats = ()
@ -798,12 +798,9 @@ class FileIPAddrSet(IPAddrSet):
logSys.warning("Retrieving IPs set from %r failed: %s", self.fileName, e) logSys.warning("Retrieving IPs set from %r failed: %s", self.fileName, e)
def __repr__(self): def __repr__(self):
if not self._shortRepr: if self._reprName is None:
shortfn = os.path.basename(self.fileName) self._reprName = 'file:' + ('/' if self.fileName.startswith('/') else '') + self.fileName
if shortfn != self.fileName: return self._reprName
shortfn = '.../' + shortfn
self._shortRepr = 'file:' + shortfn + ')'
return self._shortRepr
def __contains__(self, ip): def __contains__(self, ip):
# load if needed: # load if needed: