From 251f40143eb444ce68b69682296c8e21c17d99d2 Mon Sep 17 00:00:00 2001 From: mxi1 Date: Tue, 12 May 2009 12:18:12 +0000 Subject: [PATCH] #bug 2788254 for Linux is fixed, and with more comments, hope it helps. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3358 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/credentials.pm | 26 +++-- xCAT/postscripts/remoteshell | 115 +++++++++++++------- 2 files changed, 95 insertions(+), 46 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/credentials.pm b/xCAT-server/lib/xcat/plugins/credentials.pm index fe5e32ec9..477956597 100644 --- a/xCAT-server/lib/xcat/plugins/credentials.pm +++ b/xCAT-server/lib/xcat/plugins/credentials.pm @@ -179,15 +179,25 @@ sub process_request } else { next; } - open($tmpfile,$tfilename); - @filecontent=<$tmpfile>; - close($tmpfile); - $retdata = "\n".join('',@filecontent); - push @{$rsp->{'data'}},{content=>[$retdata],desc=>[$_]}; - $retdata=""; - @filecontent=(); + #check if the file exists or not + 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]) { + #if we got the data from the file, send the data message to the client + xCAT::MsgUtils->message("D", $rsp, $callback, 0); + }else { + #if the file doesn't exist, send the error message to the client + 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..cefc429e0 100755 --- a/xCAT/postscripts/remoteshell +++ b/xCAT/postscripts/remoteshell @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash -x # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html #egan@us.ibm.com #(C)IBM Corp @@ -48,38 +48,65 @@ 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 +getcredentials.awk ssh_dsa_hostkey | grep -E -v '|' | sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /tmp/ssh_dsa_hostkey + +#check the message is an error or not +grep -E '' /tmp/ssh_dsa_hostkey +if [ $? -ne 0 ]; then + #the message received is the data + cat /tmp/ssh_dsa_hostkey | grep -E -v '||' >/etc/ssh/ssh_host_dsa_key + logger -t xCAT ssh_dsa_hostkey + 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 +else + #the message received is an error, so parse it + ERR_MSG=`sed -n 's%.*\(.*\).*%\1%p' /tmp/ssh_dsa_hostkey` + logger -t xCAT Error: $ERR_MSG +fi +rm /tmp/ssh_dsa_hostkey + +getcredentials.awk ssh_rsa_hostkey | grep -E -v '|' | sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /tmp/ssh_rsa_hostkey + +#check whether the message is an error or not +grep -E '' /tmp/ssh_rsa_hostkey +if [ $? -ne 0 ]; then + #the message received is the data we request + cat /tmp/ssh_rsa_hostkey | grep -E -v '||' >/etc/ssh/ssh_host_rsa_key + logger -t xCAT ssh_rsa_hostkey + 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 +else + #This is an error message + ERR_MSG=`sed -n 's%.*\(.*\).*%\1%p' /tmp/ssh_rsa_hostkey` + logger -t xCAT Error: $ERR_MSG +fi +rm /tmp/ssh_rsa_hostkey + if [ -r /etc/xCATSN ] ; then mkdir /etc/xcat/hostkeys cp /etc/ssh/ssh* /etc/xcat/hostkeys/. - fi @@ -87,17 +114,29 @@ umask 0077 mkdir -p /root/.ssh/ sleep 1 -getcredentials.awk ssh_root_key | grep -v '<'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /root/.ssh/id_rsa -MYCONT=`cat /root/.ssh/id_rsa` -while [ -z "$MYCONT" ]; do - let SLI=$RANDOM%10 - let SLI=SLI+10 - sleep $SLI - getcredentials.awk ssh_root_key | grep -v '<'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /root/.ssh/id_rsa - MYCONT=`cat /root/.ssh/id_rsa` -done +getcredentials.awk ssh_root_key | grep -E -v '|'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /tmp/ssh_root_key + +#check whether the message is an error or not +grep -E '' /tmp/ssh_root_key +if [ $? -ne 0 ]; then + #The message contains the data we request + cat /tmp/ssh_root_key | grep -E -v '||' > /root/.ssh/id_rsa + logger -t xCAT ssh_root_key + MYCONT=`cat /root/.ssh/id_rsa` + while [ -z "$MYCONT" ]; do + let SLI=$RANDOM%10 + let SLI=SLI+10 + sleep $SLI + getcredentials.awk ssh_root_key | grep -v '<'|sed -e 's/<//' -e 's/&/&/' -e 's/"/"/' -e "s/'/'/" > /root/.ssh/id_rsa + MYCONT=`cat /root/.ssh/id_rsa` + done +else + #This is an error message + ERR_MSG=`sed -n 's%.*\(.*\).*%\1%p' /tmp/ssh_root_key` + logger -t xCAT ssh_root_key Error: $ERR_MSG +fi +rm /tmp/ssh_root_key - if ! grep "PRIVATE KEY" /root/.ssh/id_rsa > /dev/null 2>&1 ; then rm /root/.ssh/id_rsa fi