Merge pull request #392 from grooverdan/config_order

ENH: order config as jail.conf, jail.d/*.conf, jail.local, jail.d/*.local
pull/391/merge
Daniel Black 2013-10-14 04:25:05 -07:00
commit 445c6e6009
3 changed files with 27 additions and 9 deletions

View File

@ -54,16 +54,19 @@ class ConfigReader(SafeConfigParserWithIncludes):
% self._basedir) % self._basedir)
basename = os.path.join(self._basedir, filename) basename = os.path.join(self._basedir, filename)
logSys.debug("Reading configs for %s under %s " % (basename, self._basedir)) logSys.debug("Reading configs for %s under %s " % (basename, self._basedir))
config_files = [ basename + ".conf", config_files = [ basename + ".conf" ]
basename + ".local" ]
# choose only existing ones
config_files = filter(os.path.exists, config_files)
# possible further customizations under a .conf.d directory # possible further customizations under a .conf.d directory
config_dir = basename + '.d' config_dir = basename + '.d'
config_files += sorted(glob.glob('%s/*.conf' % config_dir)) config_files += sorted(glob.glob('%s/*.conf' % config_dir))
config_files.append(basename + ".local")
config_files += sorted(glob.glob('%s/*.local' % config_dir))
# choose only existing ones
config_files = filter(os.path.exists, config_files)
if len(config_files): if len(config_files):
# at least one config exists and accessible # at least one config exists and accessible
logSys.debug("Reading config files: " + ', '.join(config_files)) logSys.debug("Reading config files: " + ', '.join(config_files))

View File

@ -1,7 +1,10 @@
.TH JAIL.CONF "5" "March 2013" "Fail2Ban" "Fail2Ban Configuration" .TH JAIL.CONF "10" "October 2013" "Fail2Ban" "Fail2Ban Configuration"
.SH NAME .SH NAME
jail.conf \- configuration for the fail2ban server jail.conf \- configuration for the fail2ban server
.SH SYNOPSIS .SH SYNOPSIS
.I fail2ban.conf fail2ban.d/*.conf fail2ban.d/*.local
.I jail.conf / jail.local .I jail.conf / jail.local
.I action.d/*.conf action.d/*.local .I action.d/*.conf action.d/*.local
@ -45,6 +48,15 @@ identical entries, parsed alphabetically, e.g.
.RE .RE
.RE .RE
The order \fIjail\fR configuration is parsed is:
jail.conf ,
jail.d/*.conf (in alphabetical order),
jail.local, followed by
jail.d/*.local (in alphabetical order).
Likewise for fail2ban configuration.
.SH DEFAULT .SH DEFAULT
The following options are applicable to all jails. Their meaning is described in the default \fIjail.conf\fR file. The following options are applicable to all jails. Their meaning is described in the default \fIjail.conf\fR file.
.TP .TP

View File

@ -82,8 +82,6 @@ option = %s
self.assertEqual(self._getoption(), 1) self.assertEqual(self._getoption(), 1)
self._write("c.conf", "2") # overwrite self._write("c.conf", "2") # overwrite
self.assertEqual(self._getoption(), 2) self.assertEqual(self._getoption(), 2)
self._write("c.local", "3") # add override in .local
self.assertEqual(self._getoption(), 3)
self._write("c.d/98.conf", "998") # add 1st override in .d/ self._write("c.d/98.conf", "998") # add 1st override in .d/
self.assertEqual(self._getoption(), 998) self.assertEqual(self._getoption(), 998)
self._write("c.d/90.conf", "990") # add previously sorted override in .d/ self._write("c.d/90.conf", "990") # add previously sorted override in .d/
@ -95,10 +93,15 @@ option = %s
self._remove("c.d/98.conf") self._remove("c.d/98.conf")
self.assertEqual(self._getoption(), 990) self.assertEqual(self._getoption(), 990)
self._remove("c.d/90.conf") self._remove("c.d/90.conf")
self.assertEqual(self._getoption(), 2)
self._write("c.local", "3") # add override in .local
self.assertEqual(self._getoption(), 3) self.assertEqual(self._getoption(), 3)
self._write("c.d/5.local", "9") # add override in c.d/*.local
self.assertEqual(self._getoption(), 9)
self._remove("c.conf") # we allow to stay without .conf self._remove("c.conf") # we allow to stay without .conf
self.assertEqual(self._getoption(), 3) self.assertEqual(self._getoption(), 9)
self._write("c.conf", "1") self._write("c.conf", "1")
self._remove("c.d/5.local")
self._remove("c.local") self._remove("c.local")
self.assertEqual(self._getoption(), 1) self.assertEqual(self._getoption(), 1)