Created
April 30, 2013 20:42
-
-
Save kwirk/5491782 to your computer and use it in GitHub Desktop.
fail2ban/fail2ban issue #189
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/fail2ban/client/jailreader.py b/fail2ban/client/jailreader.py | |
index 9943b69..776a164 100644 | |
--- a/fail2ban/client/jailreader.py | |
+++ b/fail2ban/client/jailreader.py | |
@@ -94,12 +94,28 @@ class JailReader(ConfigReader): | |
logSys.error("Unable to read the filter") | |
return False | |
+ actNames = set() | |
# Read action | |
for act in self.__opts["action"].split('\n'): | |
try: | |
if not act: # skip empty actions | |
continue | |
actName, actOpt = JailReader.extractOptions(act) | |
+ | |
+ # In case of duplicate named action, append number | |
+ if actOpt.get("actname", actName) in actNames: | |
+ n = 0 | |
+ while True: | |
+ n += 1 | |
+ newName = "%s-%i" % ( | |
+ actOpt.get("actname", actName), n) | |
+ if newName not in actNames: | |
+ break | |
+ logSys.warn("Duplicate action '%s'. Renaming to '%s'" % | |
+ (actOpt.get("actname", actName), newName)) | |
+ actOpt["actname"] = newName | |
+ | |
+ actNames.add(actOpt.get("actname", actName)) | |
action = ActionReader( | |
actName, self.__name, actOpt, basedir=self.getBaseDir()) | |
ret = action.read() | |
diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py | |
index 61101aa..805d026 100644 | |
--- a/fail2ban/tests/clientreadertestcase.py | |
+++ b/fail2ban/tests/clientreadertestcase.py | |
@@ -323,7 +323,24 @@ filter = testfilter1 | |
comm_commands = jails.convert() | |
action_names = [comm[-1] for comm in comm_commands if comm[:3] == ['set', 'testjail1', 'addaction']] | |
+ self.assertEqual(["test1", "test2"], action_names) | |
- self.assertNotEqual(len(set(action_names)), 1) | |
+ jailfd = open(os.path.join(basedir, "jail.conf"), 'w') | |
+ jailfd.write(""" | |
+[testjail1] | |
+action = testaction1 | |
+ testaction1 | |
+ testaction1 | |
+filter = testfilter1 | |
+""") | |
+ jailfd.close() | |
+ jails = JailsReader(basedir=basedir) | |
+ self.assertTrue(jails.read()) | |
+ self.assertTrue(jails.getOptions()) | |
+ comm_commands = jails.convert() | |
+ | |
+ action_names = [comm[-1] for comm in comm_commands if comm[:3] == ['set', 'testjail1', 'addaction']] | |
+ self.assertEqual( | |
+ ["testaction1", "testaction1-1", "testaction1-2"], action_names) | |
shutil.rmtree(basedir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment