diff --git a/xCAT-server/lib/xcat/plugins/credentials.pm b/xCAT-server/lib/xcat/plugins/credentials.pm index fe5e32ec9..9b937a277 100644 --- a/xCAT-server/lib/xcat/plugins/credentials.pm +++ b/xCAT-server/lib/xcat/plugins/credentials.pm @@ -179,15 +179,22 @@ sub process_request } else { next; } - open($tmpfile,$tfilename); - @filecontent=<$tmpfile>; - close($tmpfile); - $retdata = "\n".join('',@filecontent); - push @{$rsp->{'data'}},{content=>[$retdata],desc=>[$_]}; - $retdata=""; - @filecontent=(); + if (defined $tfilename && -r $tfilename) { + open($tmpfile,$tfilename); + @filecontent=<$tmpfile>; + close($tmpfile); + $retdata = "\n".join('',@filecontent); + push @{$rsp->{'data'}},{content=>[$retdata],desc=>[$_]}; + $retdata=""; + @filecontent=(); + } + } + if (defined $rsp->{data}->[0]) { + xCAT::MsgUtils->message("D", $rsp, $callback, 0); + }else { + delete $rsp->{'data'}; + xCAT::MsgUtils->message("E", $rsp, $callback, 0); } - xCAT::MsgUtils->message("D", $rsp, $callback, 0); return; } diff --git a/xCAT/postscripts/remoteshell b/xCAT/postscripts/remoteshell index afd566a89..0fb3acaaf 100755 --- a/xCAT/postscripts/remoteshell +++ b/xCAT/postscripts/remoteshell @@ -48,33 +48,58 @@ fi allowcred.awk & CREDPID=$! sleep 1 -getcredentials.awk ssh_dsa_hostkey | grep -v '<'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /etc/ssh/ssh_host_dsa_key -MYCONT=`cat /etc/ssh/ssh_host_dsa_key` -while [ -z "$MYCONT" ]; do - let SLI=$RANDOM%10 - let SLI=SLI+10 - sleep $SLI - getcredentials.awk ssh_dsa_hostkey | grep -v '<'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /etc/ssh/ssh_host_dsa_key - MYCONT=`cat /etc/ssh/ssh_host_dsa_key` -done -chmod 600 /etc/ssh/ssh_host_dsa_key -if ! grep "PRIVATE KEY" /etc/ssh/ssh_host_dsa_key > /dev/null 2>&1 ; then - rm /etc/ssh/ssh_host_dsa_key -fi -getcredentials.awk ssh_rsa_hostkey | grep -v '<'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /etc/ssh/ssh_host_rsa_key -MYCONT=`cat /etc/ssh/ssh_host_rsa_key` -while [ -z "$MYCONT" ]; do - let SLI=$RANDOM%10 - let SLI=SLI+10 - sleep $SLI - getcredentials.awk ssh_rsa_hostkey | grep -v '<'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /etc/ssh/ssh_host_rsa_key - MYCONT=`cat /etc/ssh/ssh_host_rsa_key` -done -chmod 600 /etc/ssh/ssh_host_rsa_key -if ! grep "PRIVATE KEY" /etc/ssh/ssh_host_rsa_key > /dev/null 2>&1 ; then - rm /etc/ssh/ssh_host_rsa_key -fi +function cred_handler() { + getcredentials.awk $1 | grep -E -v '|'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /tmp/$1 + grep -E '' /tmp/$1 + if [ $? ]; then + cat /tmp/$1 | grep -E -v '||' >/etc/ssh/$1 + chmod 600 /etc/ssh/$1 + if ! grep "PRIVATE KEY" /etc/ssh/$1 > /dev/null 2>&1 ; then + logger -t xCAT $1 is PRIVATE KEY + rm /etc/ssh/$1 + return + fi + logger -t xCAT $1 + rm /tmp/$1 + else + ERR_MSG = `send -n 's%.*\(.*\).*%\1%p' /tmp/$1` + logger -t xCAT $1 Error: $ERR_MSG + rm /tm/$1 + return + fi + + MYCONT=`cat /etc/ssh/$1` + while [ -z "$MYCONT" ]; do + let SLI=$RANDOM%10 + let SLI=SLI+10 + sleep $SLI + getcredentials.awk $1 | grep -E -v '|'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /tmp/$1 + grep -E '' /tmp/$1 + if [ $? ]; then + cat /tmp/$1 | grep -E -v '||' >/etc/ssh/$1 + chmod 600 /etc/ssh/$1 + if ! grep "PRIVATE KEY" /etc/ssh/$1 > /dev/null 2>&1 ; then + logger -t xCAT $1 is PRIVATE KEY + rm /etc/ssh/$1 + return + fi + logger -t xCAT $1 + rm /tmp/$1 + else + ERR_MSG = `send -n 's%.*\(.*\).*%\1%p' /tmp/$1` + logger -t xCAT $1 Error: $ERR_MSG + rm /tm/$1 + return + fi + + MYCONT=`cat /etc/ssh/$1` + done + + return +} +cred_handler ssh_dsa_hostkey +cred_handler ssh_rsa_hostkey if [ -r /etc/xCATSN ] ; then mkdir /etc/xcat/hostkeys