From ac42fddbce3a3a051ada1741f3eda51208190c00 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Tue, 21 Dec 2010 12:29:52 -0800 Subject: [PATCH] Finish (unpublished) parameterized actions --- Shorewall/Perl/Shorewall/Config.pm | 27 ++++++++++++++++++++++++++- Shorewall/Perl/Shorewall/Rules.pm | 8 +++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index a28ad4cd2..bce2e78a9 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -96,6 +96,8 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script close_file push_open pop_open + add_params + del_params read_a_line validate_level which @@ -1781,6 +1783,29 @@ sub embedded_perl( $ ) { } } +# +# Add parameters +# +sub add_params( $ ) { + my $params = shift; + + my @params = split /,/, $params; + + for ( my $i = 1; $i <= @params; $i++ ) { + $params{$i} = $params[$i]; + } +} + +sub del_params( $ ) { + my $params = shift; + + my @params = split /,/, $params; + + for ( my $i = 1; $i <= @params; $i++ ) { + delete $params{$i}; + } +} + # # Read a line from the current include stack. # @@ -1857,7 +1882,7 @@ sub read_a_line(;$) { # Expand Shell Variables using %params and %ENV # # $1 $2 $3 - $4 - while ( $currentline =~ m( ^(.*?) \$({)? ([a-zA-Z]\w*) (?(2)}) (.*)$ )x ) { + while ( $currentline =~ m( ^(.*?) \$({)? (\w+) (?(2)}) (.*)$ )x ) { unless ( exists $params{$3} ) { # diff --git a/Shorewall/Perl/Shorewall/Rules.pm b/Shorewall/Perl/Shorewall/Rules.pm index 2b82cb6a3..655aa45f4 100644 --- a/Shorewall/Perl/Shorewall/Rules.pm +++ b/Shorewall/Perl/Shorewall/Rules.pm @@ -342,8 +342,8 @@ sub process_actions1() { # # Generate chain for non-builtin action invocation # -sub process_action3( $$$$$ ) { - my ( $chainref, $wholeaction, $action, $level, $tag ) = @_; +sub process_action3( $$$$$$ ) { + my ( $chainref, $wholeaction, $action, $level, $tag, $param ) = @_; my $actionfile = find_file "action.$action"; my $format = 1; @@ -353,6 +353,8 @@ sub process_action3( $$$$$ ) { open_file $actionfile; + add_params( $param ); + while ( read_a_line ) { my ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers ); @@ -550,7 +552,7 @@ sub process_actions3 () { $level = '' if $level =~ /none!?/; $builtinops{$action}->($chainref, $level, $tag, $param ); } else { - process_action3 $chainref, $wholeaction, $action, $level, $tag; + process_action3 $chainref, $wholeaction, $action, $level, $tag, $param; } } }