From 79abdf152c502f837a18959efc4cc0cb97457be7 Mon Sep 17 00:00:00 2001 From: mxi1 Date: Mon, 11 May 2009 02:39:34 +0000 Subject: [PATCH] -bug 2788254 is fixed; comitted the code change into trunk git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3331 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/credentials.pm | 23 +++--- xCAT/postscripts/remoteshell | 77 ++++++++++++++------- 2 files changed, 66 insertions(+), 34 deletions(-) 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