Eliminate one version of numeric_value()

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@7856 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-12-07 19:06:01 +00:00
parent 898a20a43a
commit f9bda7d0a0
7 changed files with 28 additions and 30 deletions

View File

@ -1113,7 +1113,7 @@ sub verify_mark( $ ) {
my $value = numeric_value( $mark );
fatal_error "Invalid Mark or Mask value ($mark)"
unless $value <= $limit;
unless defined( $value ) && $value <= $limit;
fatal_error "Invalid High Mark or Mask value ($mark)"
if ( $value > 0xFF && $value & 0xFF );

View File

@ -708,13 +708,13 @@ sub compiler {
$export = 0;
sub edit_boolean( $ ) {
my $val = numeric_value1( shift );
defined $val && $val >= 0 && $val < 2;
my $val = numeric_value( shift );
defined($val) && ($val >= 0) && ($val < 2);
}
sub edit_verbosity( $ ) {
my $val = numeric_value1( shift );
defined $val && $val >= -1 && $val < 3;
my $val = numeric_value( shift );
defined($val) && ($val >= -1) && ($val < 3);
}
my %elbat = ( object => { store => \$objectfile },

View File

@ -55,7 +55,6 @@ our @EXPORT_OK = qw( $shorewall_dir initialize read_a_line1 set_config_path shor
our %EXPORT_TAGS = ( internal => [ qw( create_temp_object
finalize_object
numeric_value
numeric_value1
emit
emit_unindented
save_progress_message
@ -506,12 +505,6 @@ sub fatal_error1 {
# Convert value to decimal number
#
sub numeric_value ( $ ) {
my $mark = lc $_[0];
fatal_error "Invalid Numeric Value ($mark)" unless $mark =~ /^-?(0x[a-f0-9]+|0[0-7]*|[1-9]\d*)$/;
$mark =~ /^0/ ? oct $mark : $mark;
}
sub numeric_value1 ( $ ) {
my $mark = lc $_[0];
return undef unless $mark =~ /^-?(0x[a-f0-9]+|0[0-7]*|[1-9]\d*)$/;
$mark =~ /^0/ ? oct $mark : $mark;
@ -586,18 +579,14 @@ sub set_log ( $$ ) {
if ( defined $v ) {
my $value = numeric_value( $v );
if ( ( $value < -1 ) || ( $value > 2 ) ) {
fatal_error "Invalid Log Verbosity ( $v )";
}
fatal_error "Invalid Log Verbosity ( $v )" unless defined($value) && ( $value >= -1 ) && ( $value <= 2);
$log_verbose = $value;
}
if ( $l && $log_verbose >= 0 ) {
unless ( open $log , '>>' , $l ) {
$log = undef;
fatal_error "Unable to open $l for writing: $!";
fatal_error "Unable to open STARTUP_LOG ($l) for writing: $!";
}
} else {
$log_verbose = -1;
@ -1799,8 +1788,8 @@ sub get_configuration( $ ) {
if ( $config{LOG_VERBOSITY} eq '' ) {
$config{LOG_VERBOSITY} = 2;
} else {
my $val = numeric_value1( $config{LOG_VERBOSITY} );
fatal_error "Invalid LOG_VERBOSITY ($config{LOG_VERBOSITY} )" unless defined $val && $val >= -1 && $val <= 2;
my $val = numeric_value( $config{LOG_VERBOSITY} );
fatal_error "Invalid LOG_VERBOSITY ($config{LOG_VERBOSITY} )" unless defined( $val ) && ( $val >= -1 ) && ( $val <= 2 );
$config{STARTUP_LOG} = '' if $config{LOG_VERBOSITY} < 0;
}
} else {

View File

@ -254,9 +254,9 @@ sub validate_policy()
if ( defined $queue ) {
fatal_error "Invalid policy ($policy/$queue)" unless $policy eq 'NFQUEUE';
require_capability( 'NFQUEUE_TARGET', 'An NFQUEUE Policy', 's' );
$queue = numeric_value( $queue );
fatal_error "Invalid NFQUEUE queue number ($queue)" if $queue > 65535;
$policy = "NFQUEUE --queue-num $queue";
my $queuenum = numeric_value( $queue );
fatal_error "Invalid NFQUEUE queue number ($queue)" unless defined( $queuenum) && $queuenum <= 65535;
$policy = "NFQUEUE --queue-num $queuenum";
} elsif ( $policy eq 'NONE' ) {
fatal_error "NONE policy not allowed with \"all\""
if $clientwild || $serverwild;

View File

@ -192,7 +192,11 @@ sub add_a_provider( $$$$$$$$ ) {
fatal_error "Duplicate provider ($table)" if $providers{$table};
$number = numeric_value $number;
my $num = numeric_value $number;
fatal_error "Invalid Provider number ($number)" unless defined $num;
$number = $num;
for my $providerref ( values %providers ) {
fatal_error "Duplicate provider number ($number)" if $providerref->{number} == $number;
@ -238,6 +242,8 @@ sub add_a_provider( $$$$$$$$ ) {
$val = numeric_value $mark;
fatal_error "Invalid Mark Value ($mark)" unless defined $val;
verify_mark $mark;
if ( $val < 256) {

View File

@ -110,8 +110,9 @@ sub process_tos() {
if ( defined ( my $tosval = $tosoptions{"\L$tos"} ) ) {
$tos = $tosval;
} elsif ( numeric_value( $tos ) > 0x1e ) {
fatal_error "Invalid TOS value ($tos)";
} else {
my $val = numeric_value( $tos );
fatal_error "Invalid TOS value ($tos)" unless defined( $val ) && $val < 0x1f;
}
my $chainref;
@ -954,9 +955,9 @@ sub process_rule1 ( $$$$$$$$$$$ ) {
} elsif ( $actiontype & NFQ ) {
require_capability( 'NFQUEUE_TARGET', 'NFQUEUE Rules', '' );
$param = $param eq '' ? 0 : numeric_value( $param );
fatal_error "Invalid value ($param) for NFQUEUE queue number" if $param > 65535;
$action = "NFQUEUE --queue-num $param";
my $paramval = $param eq '' ? 0 : numeric_value( $param );
fatal_error "Invalid value ($param) for NFQUEUE queue number" unless defined($paramval) && $paramval <= 65535;
$action = "NFQUEUE --queue-num $paramval";
} else {
fatal_error "The $basictarget TARGET does not accept a parameter" unless $param eq '';
}

View File

@ -700,7 +700,9 @@ sub validate_interfaces_file( $ )
}
} elsif ( $type == NUMERIC_IF_OPTION ) {
fatal_error "The $option option requires a value" unless defined $value;
$options{$option} = numeric_value $value;
my $numval = numeric_value $value;
fatal_error "Invalid value for option $option ($value)" unless defined $numval;
$options{$option} = $numval;
} else {
warning_message "Support for the $option interface option has been removed from Shorewall-perl";
}