diff --git a/fail2ban/client/configreader.py b/fail2ban/client/configreader.py index 82bf0fdc..d9bfb271 100644 --- a/fail2ban/client/configreader.py +++ b/fail2ban/client/configreader.py @@ -267,7 +267,9 @@ class DefinitionInitConfigReader(ConfigReader): # needed for fail2ban-regex that doesn't need fancy directories def readexplicit(self): - return SafeConfigParserWithIncludes.read(self, self._file) + if not self._cfg: + self.touch(self._file) + return SafeConfigParserWithIncludes.read(self._cfg, self._file) def getOptions(self, pOpts): self._opts = ConfigReader.getOptions( diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 3f24f2b5..331d821c 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -334,6 +334,22 @@ class FilterReaderTest(unittest.TestCase): filterReader.getOptions(None) self.assertRaises(ValueError, FilterReader.convert, filterReader) + def testFilterReaderExplicit(self): + # read explicit uses absolute path: + path_ = os.path.abspath(os.path.join(TEST_FILES_DIR, "filter.d")) + filterReader = FilterReader(os.path.join(path_, "testcase01.conf"), "testcase01", {}) + self.assertEqual(filterReader.readexplicit(), + [os.path.join(path_, "testcase-common.conf"), os.path.join(path_, "testcase01.conf")] + ) + try: + filterReader.getOptions(None) + # from included common + filterReader.get('Definition', '__prefix_line') + # from testcase01 + filterReader.get('Definition', 'failregex') + filterReader.get('Definition', 'ignoreregex') + except Exception, e: + self.fail('unexpected options after readexplicit: %s' % (e)) class JailsReaderTestCache(LogCaptureTestCase):