diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2002-01-16 13:00:17 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2002-01-16 13:00:17 +0000 |
commit | 84a327507b1d181a87e753a7603c665111373974 (patch) | |
tree | 0acb9d203b6f93bcfc6815c926ec0367e4891b6c | |
parent | 3ca82235844ffcff1856100633cd03df628af492 (diff) | |
download | drakx-84a327507b1d181a87e753a7603c665111373974.tar drakx-84a327507b1d181a87e753a7603c665111373974.tar.gz drakx-84a327507b1d181a87e753a7603c665111373974.tar.bz2 drakx-84a327507b1d181a87e753a7603c665111373974.tar.xz drakx-84a327507b1d181a87e753a7603c665111373974.zip |
add locking to ensure things are in a proper state
-rwxr-xr-x | perl-install/standalone/fileshareset | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/perl-install/standalone/fileshareset b/perl-install/standalone/fileshareset index e2185b07a..d7fcdfece 100755 --- a/perl-install/standalone/fileshareset +++ b/perl-install/standalone/fileshareset @@ -12,7 +12,7 @@ my $authorisation_group = 'fileshare'; ######################################## # fileshare utility $Id$ -# Copyright (C) 2001 MandrakeSoft (pixel@mandrakesoft.com) +# Copyright (C) 2001-2002 MandrakeSoft (pixel@mandrakesoft.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -64,7 +64,10 @@ my %exit_codes = reverse ( ################################################################################ # correct PATH needed to call /etc/init.d/... ? seems not, but... %ENV = ();#(PATH => '/bin:/sbin:/usr/bin:/usr/sbin'); -authorisation::check(); + +my $modify = $0 =~ /fileshareset/; + +authorisation::check($modify); my @exports = ( -e $nfs_exports::conf_file ? nfs_exports::read() : (), @@ -72,7 +75,7 @@ my @exports = ( ); @exports or error($no_export_method); -if ($0 =~ /fileshareset/) { +if ($modify) { my ($cmd, $dir) = @ARGV; $< = $>; @ARGV == 2 && ($cmd eq '--add' || $cmd eq '--remove') or error($usage); @@ -121,10 +124,11 @@ sub uniq { my %l; $l{$_} = 1 foreach @_; grep { delete $l{$_} } @_ } package authorisation; sub read_conf { - local *F; - open F, $authorisation_file; # don't care if it's missing + my ($exclusive_lock) = @_; + open F_lock, $authorisation_file; # don't care if it's missing + flock(F_lock, $exclusive_lock ? 2 : 1) or die "can't lock"; my %conf; - foreach (<F>) { + foreach (<F_lock>) { s/#.*//; # remove comments s/^\s+//; s/\s+$//; @@ -132,11 +136,13 @@ sub read_conf { my ($cmd, $value) = split('=', $_, 2); $conf{$cmd} = $value || warn qq(suspicious line "$_" in $authorisation_file\n); } + # no close F_lock, keep it locked \%conf } sub check { - my $conf = read_conf(); + my ($exclusive_lock) = @_; + my $conf = read_conf($exclusive_lock); if (lc($conf->{RESTRICT}) eq 'no') { # ok, access granted for everybody |