From 5eb2ece36516e8a05ae63baec22c24cd0f21e954 Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 10 Mar 2008 16:44:11 +0000 Subject: [PATCH] SSH setup for service node. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@742 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server-2.0/lib/xcat/plugins/SSHsn.pm | 122 ++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 xCAT-server-2.0/lib/xcat/plugins/SSHsn.pm diff --git a/xCAT-server-2.0/lib/xcat/plugins/SSHsn.pm b/xCAT-server-2.0/lib/xcat/plugins/SSHsn.pm new file mode 100644 index 000000000..c6c184a3e --- /dev/null +++ b/xCAT-server-2.0/lib/xcat/plugins/SSHsn.pm @@ -0,0 +1,122 @@ +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- +package xCAT_plugin::SSHsn; +use xCAT::Table; + +use xCAT::Utils; + +use xCAT::MsgUtils; +use Getopt::Long; + +#------------------------------------------------------- + +=head1 + xCAT plugin package to setup of SSH on service node + + +#------------------------------------------------------- + +=head3 handled_commands + +Check to see if on a Service Node +Call setup_SSH + +=cut + +#------------------------------------------------------- + +sub handled_commands +{ + my $rc = 0; + if (xCAT::Utils->isServiceNode()) + { + my $service = "ssh"; + + $rc = &setup_SSH(); # setup SSH + if ($rc == 0) + { + xCAT::Utils->update_xCATSN($service); + } + } + return $rc; +} + +#------------------------------------------------------- + +=head3 process_request + + Process the command + +=cut + +#------------------------------------------------------- +sub process_request +{ + return; +} + +#----------------------------------------------------------------------------- + +=head3 setup_SSH + + Sets up SSH default configuration for root + Turns strict host checking off + + +=cut + +#----------------------------------------------------------------------------- +sub setup_SSH +{ + + my $configfile; + my $cmd; + my $configinfo; + + # build the $HOMEROOT/.ssh/config + if (xCAT::Utils->isLinux()) + { + $configfile = "/root/.ssh/config"; + } + else + { #AIX + $configfile = "/.ssh/config"; + } + $configinfo = "StrictHostKeyChecking no"; + my $cmd; + if (-e $configfile) + { + $cmd = "grep StrictHostKeyChecking $configfile"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { # not there + $cmd = "echo $configinfo >> $configfile"; + my @output = xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) + { # error + xCAT::MsgUtils->message("S", "Error on $cmd, @output"); + return 1; + } + + } + } + else # file does not exist + { + $cmd = "echo $configinfo >> $configfile"; + my @output = xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) + { # error + xCAT::MsgUtils->message("S", "Error on $cmd, @output"); + return 1; + } + else + { + chmod 0600, $configfile; + + } + } + + return 0; +} +1;