From 156a7b16192abaace01c415171fdd45c3d1fa4e8 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 28 Jan 2018 15:17:01 -0800 Subject: [PATCH] Fix adding records to .local files --- fail2ban/fail2ban-lib.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fail2ban/fail2ban-lib.pl b/fail2ban/fail2ban-lib.pl index 416617de5..54783f141 100644 --- a/fail2ban/fail2ban-lib.pl +++ b/fail2ban/fail2ban-lib.pl @@ -359,15 +359,22 @@ elsif (!$old && defined($dir)) { if (!$sect->{'local'} && $file =~ /^(.*)\.conf$/) { # New directives should go in a .local file. We can assume at # this point that it doesn't exist yet, or that there is no - # section in it + # section in it. So convert this section object to local. my $lfile = $1.".local"; &unflush_file_lines($file); $file = $lfile; $lref = &read_file_lines($file); - # XXX need to add section + $sect->{'line'} = $sect->{'eline'} = scalar(@$lref); + $sect->{'file'} = $file; + splice(@$lref, $sect->{'eline'}, 0, "[$sect->{'name'}]"); + splice(@$lref, $sect->{'eline'}+1, 0, @dirlines); + $dir->{'line'} = $sect->{'eline'}+1; + $dir->{'file'} = $sect->{'file'}; + $sect->{'eline'} += scalar(@dirlines); + $dir->{'eline'} = $sect->{'eline'}; } else { - # Just add to section file + # Just add to the file the section is in (which will be local) splice(@$lref, $sect->{'eline'}+1, 0, @dirlines); $dir->{'line'} = $sect->{'eline'}+1; $dir->{'file'} = $sect->{'file'};