mirror of
https://gitlab.com/shorewall/code.git
synced 2025-06-13 05:06:55 +02:00
Implement ?SECTION
Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
parent
855cb6e7f4
commit
80d54ec40b
@ -447,12 +447,16 @@ sub setup_accounting() {
|
|||||||
|
|
||||||
if ( my $fn = open_file 'accounting', 1, 1 ) {
|
if ( my $fn = open_file 'accounting', 1, 1 ) {
|
||||||
|
|
||||||
|
set_section_function( &process_section );
|
||||||
|
|
||||||
first_entry "$doing $fn...";
|
first_entry "$doing $fn...";
|
||||||
|
|
||||||
my $nonEmpty = 0;
|
my $nonEmpty = 0;
|
||||||
|
|
||||||
$nonEmpty |= process_accounting_rule while read_a_line( NORMAL_READ );
|
$nonEmpty |= process_accounting_rule while read_a_line( NORMAL_READ );
|
||||||
|
|
||||||
|
clear_section_function;
|
||||||
|
|
||||||
if ( $nonEmpty ) {
|
if ( $nonEmpty ) {
|
||||||
my $tableref = $chain_table{$acctable};
|
my $tableref = $chain_table{$acctable};
|
||||||
|
|
||||||
|
@ -152,6 +152,8 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
|
|||||||
no_comment
|
no_comment
|
||||||
macro_comment
|
macro_comment
|
||||||
dump_mark_layout
|
dump_mark_layout
|
||||||
|
set_section_function
|
||||||
|
clear_section_function
|
||||||
|
|
||||||
$product
|
$product
|
||||||
$Product
|
$Product
|
||||||
@ -200,6 +202,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
|
|||||||
SUPPRESS_WHITESPACE
|
SUPPRESS_WHITESPACE
|
||||||
CONFIG_CONTINUATION
|
CONFIG_CONTINUATION
|
||||||
DO_INCLUDE
|
DO_INCLUDE
|
||||||
|
DO_SECTION
|
||||||
NORMAL_READ
|
NORMAL_READ
|
||||||
|
|
||||||
OPTIMIZE_POLICY_MASK
|
OPTIMIZE_POLICY_MASK
|
||||||
@ -626,11 +629,14 @@ use constant { PLAIN_READ => 0, # No read_a_line options
|
|||||||
CONFIG_CONTINUATION => 32, # Suppress leading whitespace if
|
CONFIG_CONTINUATION => 32, # Suppress leading whitespace if
|
||||||
# continued line ends in ',' or ':'
|
# continued line ends in ',' or ':'
|
||||||
DO_INCLUDE => 64, # Look for INCLUDE <filename>
|
DO_INCLUDE => 64, # Look for INCLUDE <filename>
|
||||||
|
DO_SECTION => 128, # Look for [?]SECTION <section>
|
||||||
NORMAL_READ => -1 # All options
|
NORMAL_READ => -1 # All options
|
||||||
};
|
};
|
||||||
|
|
||||||
our %variables; # Symbol table for expanding shell variables
|
our %variables; # Symbol table for expanding shell variables
|
||||||
|
|
||||||
|
our $section_function; #Function Reference for handling ?section
|
||||||
|
|
||||||
sub process_shorewallrc($$);
|
sub process_shorewallrc($$);
|
||||||
sub add_variables( \% );
|
sub add_variables( \% );
|
||||||
#
|
#
|
||||||
@ -2150,6 +2156,17 @@ sub macro_comment( $ ) {
|
|||||||
$comment = $macro unless $comment || ! ( have_capability( 'COMMENTS' ) && $config{AUTOCOMMENT} );
|
$comment = $macro unless $comment || ! ( have_capability( 'COMMENTS' ) && $config{AUTOCOMMENT} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set/clear $section_function
|
||||||
|
#
|
||||||
|
sub set_section_function( \& ) {
|
||||||
|
$section_function = $_[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
sub clear_section_function() {
|
||||||
|
$section_function = undef;
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Open a file, setting $currentfile. Returns the file's absolute pathname if the file
|
# Open a file, setting $currentfile. Returns the file's absolute pathname if the file
|
||||||
# exists, is non-empty and was successfully opened. Terminates with a fatal error
|
# exists, is non-empty and was successfully opened. Terminates with a fatal error
|
||||||
@ -2202,7 +2219,8 @@ sub push_include() {
|
|||||||
$file_format,
|
$file_format,
|
||||||
$max_format,
|
$max_format,
|
||||||
$comment,
|
$comment,
|
||||||
$nocomment ];
|
$nocomment,
|
||||||
|
$section_function ];
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -2225,11 +2243,13 @@ sub pop_include() {
|
|||||||
$file_format,
|
$file_format,
|
||||||
$max_format,
|
$max_format,
|
||||||
$comment,
|
$comment,
|
||||||
$nocomment ) = @$arrayref;
|
$nocomment,
|
||||||
|
$section_function ) = @$arrayref;
|
||||||
} else {
|
} else {
|
||||||
$currentfile = undef;
|
$currentfile = undef;
|
||||||
$currentlinenumber = 'EOF';
|
$currentlinenumber = 'EOF';
|
||||||
clear_comment;
|
clear_comment;
|
||||||
|
clear_section_function;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2795,6 +2815,7 @@ EOF
|
|||||||
sub push_open( $;$$$ ) {
|
sub push_open( $;$$$ ) {
|
||||||
my ( $file, $max , $ca, $nc ) = @_;
|
my ( $file, $max , $ca, $nc ) = @_;
|
||||||
push_include;
|
push_include;
|
||||||
|
clear_section_function;
|
||||||
my @a = @includestack;
|
my @a = @includestack;
|
||||||
push @openstack, \@a;
|
push @openstack, \@a;
|
||||||
@includestack = ();
|
@includestack = ();
|
||||||
@ -3288,6 +3309,12 @@ sub read_a_line($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$currentline = '';
|
$currentline = '';
|
||||||
|
} elsif ( ( $options & DO_SECTION ) && $currentline =~ /^s*\??SECTION\s+(.*)/i ) {
|
||||||
|
my $sectionname = $1;
|
||||||
|
fatal_error "Invalid SECTION name ($sectionname)" unless $sectionname =~ /^[-_\da-zA-Z]+$/;
|
||||||
|
fatal_error "This file does not allow ?SECTION" unless $section_function;
|
||||||
|
$section_function->($sectionname);
|
||||||
|
$currentline = '';
|
||||||
} else {
|
} else {
|
||||||
fatal_error "Non-ASCII gunk in file" if ( $options && CHECK_GUNK ) && $currentline =~ /[^\s[:print:]]/;
|
fatal_error "Non-ASCII gunk in file" if ( $options && CHECK_GUNK ) && $currentline =~ /[^\s[:print:]]/;
|
||||||
print "IN===> $currentline\n" if $debug;
|
print "IN===> $currentline\n" if $debug;
|
||||||
|
@ -3331,9 +3331,13 @@ sub process_rules( $ ) {
|
|||||||
|
|
||||||
if ( $fn ) {
|
if ( $fn ) {
|
||||||
|
|
||||||
|
set_section_function( &process_section );
|
||||||
|
|
||||||
first_entry "$doing $fn...";
|
first_entry "$doing $fn...";
|
||||||
|
|
||||||
process_raw_rule while read_a_line( NORMAL_READ );
|
process_raw_rule while read_a_line( NORMAL_READ );
|
||||||
|
|
||||||
|
clear_section_function;
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
# No need to finish the NEW section since no rules need to be generated
|
# No need to finish the NEW section since no rules need to be generated
|
||||||
|
Loading…
x
Reference in New Issue
Block a user