Use the external Net::IP perl module to do a proper IPv4/IPv6 address or
network validation.
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
our @EXPORT_OK = qw(GenerateMonitoredFiles FilePositions);
our @EXPORT_OK = qw(GenerateMonitoredFiles FilePositions);
#
## Function to generate a hash of monitored files and their file positions.
#
#
## Function to generate a hash of monitored files and their file positions.
#
return %new_file_positions;
}
return %new_file_positions;
}
+#
+## Wrapper function for IP address and network validation.
+#
+## This wrapper function uses the external Net::IP perl module to
+## check if a given input is a valid IPv4/IPv6 address or network.
+#
+sub IsValidAddressOrNetwork ($) {
+ my $address = shift;
+
+ # Check if the address is a valid IPv4/IPv6 address or network.
+ # Return "undef" False if the address is not valid.
+ my $ip = new Net::IP ($address) || return undef;
+
+ # If we got here, the address is valid. Return True.
+ return 1;
+}
+
#
## Function for fileposition initialization.
#
#
## Function for fileposition initialization.
#
# Check if the given address is valid.
# Check if the given address is valid.
+ unless(&Guardian::Base::IsValidAddressOrNetwork($address)) {
+ # Log error message.
+ $logger->Log("err", "Invalid IP address: $address");
+ return;
+ }
# Call required handler.
my $error = $commands{$command}->($self, $address, $module, $message);
# Call required handler.
my $error = $commands{$command}->($self, $address, $module, $message);