From 0b431aa8c17b03ffd145fa8fc15600ee32c91867 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 26 Jun 2011 06:50:22 -0700 Subject: [PATCH] Minor tweaks to Config.pm - Add/revise comments - Rename $line -> $lineref in expand_variables() - Collapse 3 lines into one in process_shorewall_conf() --- Shorewall/Perl/Shorewall/Config.pm | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 465cdfa7e..ca517a688 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1852,12 +1852,12 @@ sub set_action_param( $$ ) { } # -# Expand shell variables and action parameters in the passed scalar +# Expand Shell Variables in the passed buffer using %params and @actparms # sub expand_variables( \$ ) { - my ( $line, $count ) = ( $_[0], 0 ); + my ( $lineref, $count ) = ( $_[0], 0 ); # $1 $2 $3 - $4 - while ( $$line =~ m( ^(.*?) \$({)? (\w+) (?(2)}) (.*)$ )x ) { + while ( $$lineref =~ m( ^(.*?) \$({)? (\w+) (?(2)}) (.*)$ )x ) { my ( $first, $var, $rest ) = ( $1, $3, $4); @@ -1872,7 +1872,7 @@ sub expand_variables( \$ ) { } $val = '' unless defined $val; - $$line = join( '', $first , $val , $rest ); + $$lineref = join( '', $first , $val , $rest ); fatal_error "Variable Expansion Loop" if ++$count > 100; } } @@ -3037,19 +3037,17 @@ sub process_shorewall_conf( $$ ) { first_entry "Processing $file..."; # - # Don't expand shell variables if $config + # Don't expand shell variables if $update # while ( read_a_line( 0,! $update ) ) { if ( $currentline =~ /^\s*([a-zA-Z]\w*)=(.*?)\s*$/ ) { my ($var, $val) = ($1, $2); - unless ( exists $config{$var} ) { - warning_message "Unknown configuration option ($var) ignored"; - next; - } + + warning_message "Unknown configuration option ($var) ignored", next unless exists $config{$var}; $config{$var} = ( $val =~ /\"([^\"]*)\"$/ ? $1 : $val ); } else { - fatal_error "Unrecognized entry"; + fatal_error "Unrecognized $product.conf entry"; } } } else { @@ -3064,7 +3062,10 @@ sub process_shorewall_conf( $$ ) { # if ( $update ) { update_config_file( $annotate) if $update; - + # + # Config file update requires that the option values not have + # Shell variables expanded. We do that now. + # supplied $_ && expand_variables( $_ ) for values %config; }