-Detect when hosts.ip is misconfigured and report

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6261 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2010-05-27 15:57:56 +00:00
parent fe30dd3adc
commit 246874ee0d

View File

@ -234,6 +234,19 @@ sub get_dbdir {
}
}
sub isvalidip {
#inet_pton/ntop good for ensuring an ip looks like an ip? or do string compare manually?
#for now, do string analysis, one problem with pton/ntop is that 010.1.1.1 would look diff from 10.1.1.1)
my $candidate = shift;
if ($candidate =~ /^(\d+)\.(\d+)\.(\d+).(\d+)\z/) {
return (
$1 >= 0 and $1 <= 255 and
$2 >= 0 and $2 <= 255 and
$3 >= 0 and $3 <= 255 and
$4 >= 0 and $4 <= 255
);
}
}
sub update_zones {
my $ctx = shift;
my $currzone;
@ -253,6 +266,10 @@ sub update_zones {
my $ip=$node;
if ($ctx->{hoststab} and $ctx->{hoststab}->{$node} and $ctx->{hoststab}->{$node}->[0]->{ip}) {
$ip = $ctx->{hoststab}->{$node}->[0]->{ip};
unless (isvalidip($ip)) {
sendmsg([1,"The hosts table entry for $node indicates $ip as an ip address, which is not a valid address"]);
next;
}
} else {
unless ($ip = inet_aton($ip)) {
print "Unable to find an IP for $node in hosts table or via system lookup (i.e. /etc/hosts";