From f643e2e907ddb47d565896cc7bec6cfccf79517d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 27 Mar 2013 11:51:07 -0400 Subject: [PATCH 1/2] non-static (get|set)BaseDir for Configurator. fixes #160 ConfigReader's (get|set)BaseDir are no longer static as a result of .d/ support RFing --- client/configurator.py | 20 ++++++++++++-------- testcases/clientreadertestcase.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/client/configurator.py b/client/configurator.py index 0baff2d8..2097fd54 100644 --- a/client/configurator.py +++ b/client/configurator.py @@ -43,15 +43,19 @@ class Configurator: self.__fail2ban = Fail2banReader() self.__jails = JailsReader() - #@staticmethod - def setBaseDir(folderName): - ConfigReader.setBaseDir(folderName) - setBaseDir = staticmethod(setBaseDir) + def setBaseDir(self, folderName): + self.__fail2ban.setBaseDir(folderName) + self.__jails.setBaseDir(folderName) - #@staticmethod - def getBaseDir(): - return ConfigReader.getBaseDir() - getBaseDir = staticmethod(getBaseDir) + def getBaseDir(self): + fail2ban_basedir = self.__fail2ban.getBaseDir() + jails_basedir = self.__jails.getBaseDir() + if fail2ban_basedir != jails_basedir: + logSys.error("fail2ban.conf and jails.conf readers have differing " + "basedirs: %r and %r. " + "Returning the one for fail2ban.conf" + % (fail2ban_basedir, jails_basedir)) + return fail2ban_basedir def readEarly(self): self.__fail2ban.read() diff --git a/testcases/clientreadertestcase.py b/testcases/clientreadertestcase.py index 28eb6b09..3e606785 100644 --- a/testcases/clientreadertestcase.py +++ b/testcases/clientreadertestcase.py @@ -25,6 +25,7 @@ import os, shutil, tempfile, unittest from client.configreader import ConfigReader from client.jailreader import JailReader from client.jailsreader import JailsReader +from client.configurator import Configurator class ConfigReaderTest(unittest.TestCase): @@ -146,3 +147,21 @@ class JailsReaderTest(unittest.TestCase): self.assertEqual(comm_commands[-1][0], 'start') # TODO: make sure that all of the jails have actions assigned, # otherwise it makes little to no sense + + def testConfigurator(self): + configurator = Configurator() + configurator.setBaseDir('config') + self.assertEqual(configurator.getBaseDir(), 'config') + + configurator.readEarly() + opts = configurator.getEarlyOptions() + # our current default settings + self.assertEqual(opts['socket'], '/var/run/fail2ban/fail2ban.sock') + self.assertEqual(opts['pidfile'], '/var/run/fail2ban/fail2ban.pid') + + # and if we force change configurator's fail2ban's baseDir + # there should be an error message (test visually ;) -- + # otherwise just a code smoke test) + configurator._Configurator__jails.setBaseDir('/tmp') + self.assertEqual(configurator._Configurator__jails.getBaseDir(), '/tmp') + self.assertEqual(configurator.getBaseDir(), 'config') From 4b11f071ed3f3a3f066e9680ec0b4a2ad3c1822e Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 27 Mar 2013 12:02:19 -0400 Subject: [PATCH 2/2] DOC: minor fix ups of manpages. fixes #159 --- man/fail2ban.1 | 2 +- man/jail.conf.5 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/man/fail2ban.1 b/man/fail2ban.1 index 9af9ec54..8f93dbc7 100644 --- a/man/fail2ban.1 +++ b/man/fail2ban.1 @@ -1,4 +1,4 @@ -.TH FAIL2BAN "1" +.TH FAIL2BAN "1" "March 2013" "Fail2Ban" .SH NAME fail2ban \- a set of server and client programs to limit brute force authentication attempts. .SH DESCRIPTION diff --git a/man/jail.conf.5 b/man/jail.conf.5 index 10bcef7f..552b0ac0 100644 --- a/man/jail.conf.5 +++ b/man/jail.conf.5 @@ -1,4 +1,4 @@ -.TH JAIL.CONF.5 "fail2ban" "jail.conf(5)" +.TH JAIL.CONF "5" "March 2013" "Fail2Ban" "Fail2Ban Configuration" .SH NAME jail.conf \- configuration for the fail2ban server .SH SYNOPSIS @@ -30,7 +30,7 @@ Override only the settings you need to change and the rest of the configuration \fI*.d/\fR .RS In addition to .local, for any .conf file there can be a corresponding -.d directory to contain additional .conf files that will be read after the +\fI.d/\fR directory to contain additional .conf files that will be read after the appropriate .local file. Last parsed file will take precidence over identical entries, parsed alphabetically, e.g.