From 12773c44fc9b48c8615e8f6352c1f0e52c815b65 Mon Sep 17 00:00:00 2001 From: bybai Date: Thu, 25 Aug 2016 01:52:19 -0400 Subject: [PATCH 1/2] fix issue 1553 makedns failed when input invalid hostname into /etc/hosts --- xCAT-server/lib/xcat/plugins/ddns.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index 266d15410..4d14a8f22 100755 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -423,6 +423,8 @@ sub process_request { my $names; my @hosts; my %nodehash; + my @eachhost; + my $invalid; foreach (@contents) { chomp; #no newline @@ -440,6 +442,18 @@ sub process_request { next; } + @eachhost = split(/ /,$names); + foreach my $hname (@eachhost) { + unless ($hname !~ /^\.[a-z0-9]+/i) { + xCAT::SvrUtils::sendmsg(":Ignoring line $_ in /etc/hosts, names $names start with . ", $callback); + $invalid = $names; + last; + } + } + if ($invalid) { + next; + } + my ($host, $ip) = xCAT::NetworkUtils->gethostnameandip($addr); push @hosts, $host; $nodehash{$addr}{names} = $names; From eedf5d706970d8799f83b6f94125a9158ad23310 Mon Sep 17 00:00:00 2001 From: bybai Date: Tue, 30 Aug 2016 22:33:21 -0400 Subject: [PATCH 2/2] polished the ddns.pm based on comments --- xCAT-server/lib/xcat/plugins/ddns.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index 4d14a8f22..5f468b3e5 100755 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -441,11 +441,11 @@ sub process_request { xCAT::SvrUtils::sendmsg(":Ignoring line $_ in /etc/hosts, names $names contain invalid characters (valid characters include a through z, numbers and the '-', but not '_'", $callback); next; } - + $invalid = ""; @eachhost = split(/ /,$names); foreach my $hname (@eachhost) { - unless ($hname !~ /^\.[a-z0-9]+/i) { - xCAT::SvrUtils::sendmsg(":Ignoring line $_ in /etc/hosts, names $names start with . ", $callback); + if ($hname =~ /^\./) { + xCAT::SvrUtils::sendmsg(":Ignoring line $_ in /etc/hosts, name $hname start with . ", $callback); $invalid = $names; last; }