From b38c69c61ec31646ac7eb5d43f2e1f2a76673d95 Mon Sep 17 00:00:00 2001 From: teastep Date: Sat, 17 Mar 2007 18:18:54 +0000 Subject: [PATCH] Generate Auxillary conf file git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5563 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- New/Shorewall/Common.pm | 25 ++++++++++++++++++++++++- New/Shorewall/Config.pm | 39 +++++++++++++++++++++++++++++++++++++-- New/compiler.pl | 1 + 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/New/Shorewall/Common.pm b/New/Shorewall/Common.pm index 38d6c1dce..f0fb0e302 100644 --- a/New/Shorewall/Common.pm +++ b/New/Shorewall/Common.pm @@ -25,6 +25,7 @@ package Shorewall::Common; require Exporter; use File::Basename; use File::Temp qw/ tempfile tempdir /; +use Cwd 'abs_path'; use strict; @@ -47,6 +48,8 @@ our @EXPORT = qw(ALLIPv4 pop_indent copy copy1 + create_temp_aux_config + finalize_aux_config @allipv4 @rfc1918_networks @@ -102,6 +105,7 @@ sub create_temp_object( $ ) { eval { ( $file, $dir, $suffix ) = fileparse( $objectfile ); + $dir = abs_path $dir; fatal_error "Directory $dir does not exist" unless -d $dir; fatal_error "$dir is a Symbolic Link" if -l $dir; fatal_error "$objectfile is a Directory" if -d $objectfile; @@ -110,7 +114,7 @@ sub create_temp_object( $ ) { ( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir ); }; - fatal_error "$@" if $@; + die if $@; $file = "$file.$suffix" if $suffix; $file = $dir . $file; @@ -118,6 +122,8 @@ sub create_temp_object( $ ) { } sub finalize_object() { + close $object; + $object = 0; rename $tempfile, $file or fatal_error "Cannot Rename $tempfile to $file: $!"; chmod 0700, $file; } @@ -247,4 +253,21 @@ sub copy1( $ ) { } } +sub create_temp_aux_config() { + eval { + ( $object, $tempfile ) = tempfile ( 'tempfileXXXX' , DIR => $dir ); + }; + + die if $@; + +} + +sub finalize_aux_config() { + close $object; + $object = 0; + rename $tempfile, "$file.conf" or fatal_error "Cannot Rename $tempfile to $file.conf: $!"; + + progress_message3 "Shorewall configuration compiled to $file"; +} + 1; diff --git a/New/Shorewall/Config.pm b/New/Shorewall/Config.pm index 5e756561d..70378f619 100644 --- a/New/Shorewall/Config.pm +++ b/New/Shorewall/Config.pm @@ -28,7 +28,7 @@ use warnings; use Shorewall::Common; our @ISA = qw(Exporter); -our @EXPORT = qw(find_file get_configuration report_capabilities propagateconfig append_file %config %env %capabilities ); +our @EXPORT = qw(find_file get_configuration report_capabilities propagateconfig append_file generate_aux_config %config %env %capabilities ); our @EXPORT_OK = (); our @VERSION = 1.00; @@ -525,4 +525,39 @@ sub append_file( $ ) { } } -; +sub generate_aux_config() { + sub conditionally_add_option( $ ) { + my $option = $_[0]; + + my $value = $config{$option}; + + emit "[ -n \"\${$option:=$value}\" ]" if $value; + } + + sub conditionally_add_option1( $ ) { + my $option = $_[0]; + + my $value = $config{$option}; + + emit "$option=\"$value\"" if $value; + } + + create_temp_aux_config; + + my $date = localtime; + + emit "# +# Shorewall auxiliary configuration file created by Shorewall version $ENV{VERSION} - $date +#"; + + for my $option qw(VERBOSITY LOGFILE LOGFORMAT IPTABLES PATH SHOREWALL_SHELL SUBSYSLOCK RESTOREFILE SAVE_IPSETS) { + conditionally_add_option $option; + } + + conditionally_add_option1 'TC_ENABLED'; + + finalize_aux_config; + +} + +1; diff --git a/New/compiler.pl b/New/compiler.pl index fc051fb13..f400c558c 100755 --- a/New/compiler.pl +++ b/New/compiler.pl @@ -710,6 +710,7 @@ sub compile_firewall( $ ) { dump_chain_table if $ENV{DEBUG}; generate_script_3; finalize_object; + generate_aux_config; } }