Lock all config files, rather than just the main one https://sourceforge.net/p/webadmin/bugs/4486/

This commit is contained in:
Jamie Cameron
2014-10-15 15:31:05 -07:00
parent 289b96b426
commit 9a268a632e
13 changed files with 51 additions and 27 deletions

View File

@ -9,7 +9,7 @@ if ($in{'cancel'}) {
&redirect("");
exit;
}
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
$par = &get_parent_config();
foreach $i ($in{'sidx'}, $in{'uidx'}) {
if ($i ne "") {
@ -64,7 +64,7 @@ if ($type) {
}
&save_directive($par, [ $to_del ], [ ], 0);
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
if ($to_del->{'name'} eq "group") {
@count = &find("host", $group->{'members'});
&webmin_log('delete', 'group', join(",", map { $_->{'values'}->[0] } @count), \%in);

View File

@ -10,7 +10,7 @@ require './params-lib.pl';
%access = &get_module_acl();
# Work out what is being done
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
$parent = &get_parent_config();
foreach $d (@d) {
local @subs = reverse(split(/\//, $d));
@ -37,7 +37,7 @@ if ($in{'confirm'}) {
&save_directive($pardel->[0], [ $pardel->[1] ], [ ], 0);
}
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&webmin_log("delete", "hosts", scalar(@d));
&redirect("");
}

View File

@ -23,14 +23,14 @@ while($i < @tok) {
}
# Delete them, in reverse order so that line numbers aren't messed up
&lock_file($config{'lease_file'});
&lock_all_files();
$lref = &read_file_lines($config{'lease_file'});
foreach $lease (reverse(@todelete)) {
splice(@$lref, $lease->{'line'},
$lease->{'eline'} - $lease->{'line'} + 1);
}
&flush_file_lines($config{'lease_file'});
&unlock_file($config{'lease_file'});
&unlock_all_files();
&restart_dhcpd();
&webmin_log("delete", "lease", $lease->{'values'}->[0]);

View File

@ -10,7 +10,7 @@ require './params-lib.pl';
%access = &get_module_acl();
# Work out what is being done
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
$parent = &get_parent_config();
foreach $d (@d) {
local ($idx, $pidx) = split(/\//, $d);
@ -35,7 +35,7 @@ if ($in{'confirm'}) {
&save_directive($pardel->[0], [ $pardel->[1] ], [ ], 0);
}
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&webmin_log("delete", "subnets", scalar(@d));
&redirect("");
}

View File

@ -993,4 +993,27 @@ else {
}
}
sub get_all_config_files
{
my $conf = &get_config();
my @rv = ( $config{'dhcpd_conf'} );
push(@rv, map { $_->{'file'} } @$conf);
push(@rv, $config{'add_file'}) if ($config{'add_file'});
return &unique(@rv);
}
sub lock_all_files
{
foreach my $f (&get_all_config_files()) {
&lock_file($f);
}
}
sub unlock_all_files
{
foreach my $f (reverse(&get_all_config_files())) {
&unlock_file($f);
}
}
1;

View File

@ -5,7 +5,7 @@
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
($par, $group, $indent, $npar, $nindent) = get_branch('grp', $in{'new'});
$parconf = $par->{'members'};
@ -121,12 +121,13 @@ if ($in{'delete'}) {
&flush_file_lines();
}
else {
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&redirect("confirm_delete.cgi?sidx=$in{'sidx'}&uidx=$in{'uidx'}".
"&idx=$in{'idx'}=&type=2");
exit;
}
}
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
@count = &find("host", $group->{'members'});
&webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
'group', join(",", map { $_->{'values'}->[0] } @count), \%in);

View File

@ -5,7 +5,7 @@
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
($par, $host, $indent, $npar, $nindent) = get_branch('hst', $in{'new'});
# check acls
@ -152,7 +152,7 @@ else {
}
}
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
'host', $host->{'values'}->[0], \%in);
if ($in{'ret'} eq "group") {

View File

@ -8,7 +8,7 @@
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
$conf = &get_config();
$client = &get_parent_config();
@ -31,7 +31,7 @@ for($i=0; defined($id = $in{"id_$i"}); $i++) {
}
&save_directive($client, 'key', \@keys, 0);
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&webmin_log("keys", undef, undef, \%in);
&redirect("");

View File

@ -5,7 +5,7 @@
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
$client = &get_parent_config();
push(@parents, $client);
foreach $i ($in{'sidx'}, $in{'uidx'}, $in{'gidx'}, $in{'idx'}) {
@ -184,7 +184,7 @@ else {
}
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
if ($client->{'name'} eq 'subnet') {
&webmin_log("options", 'subnet',
"$client->{'values'}->[0]/$client->{'values'}->[2]", \%in);

View File

@ -5,7 +5,7 @@
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
$conf = &get_config();
if ($in{'sidx'} ne "") {
$sha = $conf->[$in{'sidx'}];
@ -80,7 +80,7 @@ else {
}
}
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
if ($sub->{'name'} eq 'subnet') {
&webmin_log('modify', 'subnet',
"$sub->{'values'}->[0]/$sub->{'values'}->[2]", \%in);

View File

@ -5,7 +5,7 @@
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
($par, $sha, $indent) = &get_branch('sha', $in{'new'});
$parconf = $par->{'members'};
@ -189,12 +189,12 @@ if ($in{'delete'}) {
&flush_file_lines();
}
else {
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&redirect("confirm_delete.cgi?idx=$in{'idx'}\&type=0");
exit;
}
}
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
'shared', $sha->{'values'}->[0], \%in);
&redirect("");

View File

@ -5,7 +5,7 @@
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
($par, $sub, $indent, $npar, $nindent) = get_branch('sub', $in{'new'});
$parconf = $par->{'members'};
@ -201,13 +201,13 @@ if ($in{'delete'}) {
&flush_file_lines();
}
else {
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&redirect("confirm_delete.cgi?sidx=$in{'sidx'}&idx=$in{'idx'}"
."\&type=1");
exit;
}
}
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
'subnet', "$sub->{'values'}->[0]/$sub->{'values'}->[2]", \%in);

View File

@ -10,7 +10,7 @@ require './params-lib.pl';
&ReadParse();
%access = &get_module_acl();
$access{'zones'} || &error($text{'zone_ecannot'});
&lock_file($config{'dhcpd_conf'});
&lock_all_files();
unless ($in{'new'}){ # on change or delete
# Read current zone data from config file
@ -56,7 +56,7 @@ if ($in{'delete'}) {
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
&unlock_all_files();
&webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
'shared', $zone->{'values'}->[0], \%in);