From 7b75b8b766735202a167688c52324b5b051d146d Mon Sep 17 00:00:00 2001 From: leiaibj Date: Wed, 9 Jan 2013 09:17:27 +0000 Subject: [PATCH] update hostname validate rule: only 0-9 a-z and - are valid characters git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14815 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/NetworkUtils.pm | 4 ++-- perl-xCAT/xCAT/ProfiledNodeUtils.pm | 14 ++++++++++++-- xCAT-server/lib/xcat/plugins/profilednodes.pm | 14 ++++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index f3c92e13a..7a4fd80bd 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -2205,7 +2205,7 @@ sub isValidMAC sub isValidHostname { my ($class, $hostname) = @_; - if ($hostname =~ /^[\-a-zA-Z0-9]+$/){ + if ($hostname =~ /^[a-z0-9][\-a-z0-9]+[a-z0-9]$/){ return 1; } return 0; @@ -2224,7 +2224,7 @@ sub isValidHostname sub isValidFQDN { my ($class, $hostname) = @_; - if ($hostname =~ /^[\-\.a-zA-Z0-9]+$/){ + if ($hostname =~ /^[a-z0-9][\.\-a-z0-9]+[a-z0-9]$/){ return 1; } return 0; diff --git a/perl-xCAT/xCAT/ProfiledNodeUtils.pm b/perl-xCAT/xCAT/ProfiledNodeUtils.pm index c3b735519..cb8af36f4 100644 --- a/perl-xCAT/xCAT/ProfiledNodeUtils.pm +++ b/perl-xCAT/xCAT/ProfiledNodeUtils.pm @@ -187,16 +187,20 @@ sub get_hostname_format_type{ my $ridx = index $format, "#R"; my $nidx = index $format, "#N"; + my $simpname = ""; if ($ridx >= 0){ ($prefix, $appendix, $rlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'R'); - ($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'N'); - if ($rlen >= 10 || $nlen >= 10){ + $simpname = $prefix."0".$appendix; + ($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($simpname, 'N'); + $simpname = $prefix."0".$appendix; + if ($rlen >= 10 || $nlen >= 10 || $nlen == 0){ $type = "unknown"; } else{ $type = "rack"; } } elsif ($nidx >= 0){ ($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'N'); + $simpname = $prefix."0".$appendix; if ($nlen >= 10){ $type = "unknown"; } else{ @@ -205,6 +209,12 @@ sub get_hostname_format_type{ } else{ $type = "unknown"; } + # validate whether hostname format includes other invalid characters. + if ($type ne "unknown"){ + if (! xCAT::NetworkUtils->isValidHostname($simpname)){ + $type = "unknown"; + } + } return $type; } diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm index 0c6246486..47e233d10 100644 --- a/xCAT-server/lib/xcat/plugins/profilednodes.pm +++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm @@ -1269,12 +1269,6 @@ sub gen_new_hostinfo_string{ $allips{$nextip} = 0; } } - my $nicips = ""; - foreach(keys %ipshash){ - $nicips = "$_:$ipshash{$_},$nicips"; - } - $hostinfo_dict{$item}{"nicips"} = $nicips; - # Generate IP address if no IP specified. if (! exists $hostinfo_dict{$item}{"ip"}) { if (exists $ipshash{$installnic}){ @@ -1283,6 +1277,14 @@ sub gen_new_hostinfo_string{ return 0, "There are no more IP addresses available in the static network range for interface $installnic"; } } + + my $nicips = $installnic.":".$hostinfo_dict{$item}{"ip"}; + foreach(keys %ipshash){ + if ( $_ eq $installnic ) {next;} + $nicips = "$_:$ipshash{$_},$nicips"; + } + $hostinfo_dict{$item}{"nicips"} = $nicips; + $hostinfo_dict{$item}{"objtype"} = "node"; $hostinfo_dict{$item}{"groups"} = "__Managed"; if (exists $args_dict{'networkprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'networkprofile'}}