From c1da6611ecfdc4cf86597f614b7b5f0d780b4ab1 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 13 Mar 2017 18:47:26 +0100 Subject: [PATCH] [BF] prevents always converting of calling map items in replaceTag (without direct access of item): substituteRecursiveTags: ignore replacing callable items from calling map - should be converted on demand only (by get) --- fail2ban/helpers.py | 3 +++ fail2ban/server/action.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/fail2ban/helpers.py b/fail2ban/helpers.py index 2407df1f..726631a6 100644 --- a/fail2ban/helpers.py +++ b/fail2ban/helpers.py @@ -240,6 +240,7 @@ def substituteRecursiveTags(inptags, conditional='', # init: ignore = set(ignore) done = set() + calmap = hasattr(tags, "getRawItem") # repeat substitution while embedded-recursive (repFlag is True) while True: repFlag = False @@ -247,6 +248,8 @@ def substituteRecursiveTags(inptags, conditional='', for tag in tags.iterkeys(): # ignore escaped or already done (or in ignore list): if tag in ignore or tag in done: continue + # ignore replacing callable items from calling map - should be converted on demand only (by get): + if calmap and callable(tags.getRawItem(tag)): continue value = orgval = str(tags[tag]) # search and replace all tags within value, that can be interpolated using other tags: m = tre_search(value) diff --git a/fail2ban/server/action.py b/fail2ban/server/action.py index e7a98dbb..06a499df 100644 --- a/fail2ban/server/action.py +++ b/fail2ban/server/action.py @@ -98,6 +98,13 @@ class CallingMap(MutableMapping, object): except: return dict(self.data, **self.storage) + def getRawItem(self, key): + try: + value = self.storage[key] + except KeyError: + value = self.data[key] + return value + def __getitem__(self, key): try: value = self.storage[key]