Commit 231fc2b1 authored by Leigh Stoller's avatar Leigh Stoller

Changes to sshtb. Remove sshremote, and convert sshtb into a perl

script that checks the database to see if local or remote. The problem
with this is that the ssh syntax makes it hard to determine the host
name by inspection. Would need to parse all the ssh args (bad idea),
ot work backwards and try to figure out the difference between the
command (which is not a string but a sequence of args) and the host
and the preceeding ssh args. Hell with that! Changed sshtb to require
a specific -host argument. Read the args and look for it. Error out of
not found, to catch improper usage.

The moral of this update: "sshtb [ssh args] -host <host> [more args ...]
parent 9de156ea
...@@ -1233,7 +1233,6 @@ outfiles="$outfiles Makeconf GNUmakefile \ ...@@ -1233,7 +1233,6 @@ outfiles="$outfiles Makeconf GNUmakefile \
tmcd/tmcd.restart \ tmcd/tmcd.restart \
utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \ utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \
utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \ utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \
utils/sshremote \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \ www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
vis/GNUmakefile vis/vistopology vis/webvistopology vis/top2gif \ vis/GNUmakefile vis/vistopology vis/webvistopology vis/top2gif \
vis/dbvistopology vis/dbtopper \ vis/dbvistopology vis/dbtopper \
......
...@@ -305,7 +305,6 @@ outfiles="$outfiles Makeconf GNUmakefile \ ...@@ -305,7 +305,6 @@ outfiles="$outfiles Makeconf GNUmakefile \
tmcd/tmcd.restart \ tmcd/tmcd.restart \
utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \ utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \
utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \ utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \
utils/sshremote \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \ www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
vis/GNUmakefile vis/vistopology vis/webvistopology vis/top2gif \ vis/GNUmakefile vis/vistopology vis/webvistopology vis/top2gif \
vis/dbvistopology vis/dbtopper \ vis/dbvistopology vis/dbtopper \
......
...@@ -21,7 +21,7 @@ my $TBALL = "@TBUSERSARCHIVE@"; ...@@ -21,7 +21,7 @@ my $TBALL = "@TBUSERSARCHIVE@";
my $PROJROOT = "/proj"; my $PROJROOT = "/proj";
# Note no -n option. We redirect stdin from the new exports file below. # Note no -n option. We redirect stdin from the new exports file below.
my $SSH = "$TB/bin/sshtb -l root $USERS"; my $SSH = "$TB/bin/sshtb -l root -host $USERS";
my $PROG = "/usr/testbed/sbin/genelists.proxy"; my $PROG = "/usr/testbed/sbin/genelists.proxy";
my $lockfile = "/var/tmp/testbed_genelists_lockfile"; my $lockfile = "/var/tmp/testbed_genelists_lockfile";
my $tempfile = "/var/tmp/testbed_genelists_tempfile"; my $tempfile = "/var/tmp/testbed_genelists_tempfile";
......
...@@ -64,7 +64,6 @@ foreach my $n (sort pcnum @nodes) { ...@@ -64,7 +64,6 @@ foreach my $n (sort pcnum @nodes) {
exit 0; exit 0;
sub check { sub check {
#my $ssh="sshtb -o \"FallBackToRsh no\" -o \"ConnectionAttempts 3\" -q";
my $ssh="sshtb -q"; my $ssh="sshtb -q";
my $node = shift; my $node = shift;
my $cmd1 = "ps auxwww | grep slothd | grep -v grep"; my $cmd1 = "ps auxwww | grep slothd | grep -v grep";
...@@ -101,7 +100,7 @@ sub check { ...@@ -101,7 +100,7 @@ sub check {
} }
} else { } else {
# child # child
$str = `sudo $ssh $node $cmd1`; $str = `sudo $ssh -host $node $cmd1`;
#print "$syspid - ssh succeeded:'$str'\n"; #print "$syspid - ssh succeeded:'$str'\n";
if ($str) { if ($str) {
#print "running.\n"; #print "running.\n";
...@@ -112,7 +111,7 @@ sub check { ...@@ -112,7 +111,7 @@ sub check {
my $f = "/tmp/tmp-$node-$$"; my $f = "/tmp/tmp-$node-$$";
open (STDERR, "> $f") || open (STDERR, "> $f") ||
warn("Couldn't open $f: $!\n"); warn("Couldn't open $f: $!\n");
$str = `sudo $ssh $node $cmd2`; $str = `sudo $ssh -host $node $cmd2`;
my $rv = $?; my $rv = $?;
if ($rv > 255) { $rv /= 256; } if ($rv > 255) { $rv /= 256; }
#print "\n(start=$rv)\n"; #print "\n(start=$rv)\n";
......
...@@ -134,7 +134,7 @@ $UID = 0; ...@@ -134,7 +134,7 @@ $UID = 0;
foreach my $server (keys(%cmdargs)) { foreach my $server (keys(%cmdargs)) {
my $args = $cmdargs{$server}; my $args = $cmdargs{$server};
if (system("$SSH $server $PROG $args")) { if (system("$SSH -host $server $PROG $args")) {
print STDERR "*** Failed: $SSH $server $PROG $args: $?\n"; print STDERR "*** Failed: $SSH $server $PROG $args: $?\n";
exit 1; exit 1;
} }
......
...@@ -24,7 +24,7 @@ my $usersdir = "@FSDIR_USERS@"; ...@@ -24,7 +24,7 @@ my $usersdir = "@FSDIR_USERS@";
my $groupdir = "@FSDIR_GROUPS@"; my $groupdir = "@FSDIR_GROUPS@";
# Note no -n option. We redirect stdin from the new exports file below. # Note no -n option. We redirect stdin from the new exports file below.
my $SSH = "$TB/bin/sshtb -l root $FSNODE"; my $SSH = "$TB/bin/sshtb -l root -host $FSNODE";
my $PROG = "/usr/testbed/sbin/exports_setup.proxy"; my $PROG = "/usr/testbed/sbin/exports_setup.proxy";
my $exportstail = "/var/tmp/exports.tail"; my $exportstail = "/var/tmp/exports.tail";
my $lockfile = "/var/tmp/testbed_exports_lockfile"; my $lockfile = "/var/tmp/testbed_exports_lockfile";
......
...@@ -221,10 +221,10 @@ else { ...@@ -221,10 +221,10 @@ else {
$fullname =~ s/\"/\'/g; $fullname =~ s/\"/\'/g;
$fullname =~ s/([^\\])([\'\"\(\)])/$1\\$2/g; $fullname =~ s/([^\\])([\'\"\(\)])/$1\\$2/g;
if (system("$SSH $control_node egrep -q -s '^${user}:' /etc/passwd")) { if (system("$SSH -host $control_node egrep -q -s '^${user}:' /etc/passwd")) {
print "Adding user $user ($user_number) to $control_node.\n"; print "Adding user $user ($user_number) to $control_node.\n";
if (system("$SSH $control_node ". if (system("$SSH -host $control_node ".
"'$USERADD $user -u $user_number -c \"$fullname\" ". "'$USERADD $user -u $user_number -c \"$fullname\" ".
"-k /usr/share/skel -m -d $HOMEDIR/$user ". "-k /usr/share/skel -m -d $HOMEDIR/$user ".
"-g $default_groupname -s /bin/tcsh'")) { "-g $default_groupname -s /bin/tcsh'")) {
...@@ -237,7 +237,7 @@ else { ...@@ -237,7 +237,7 @@ else {
# #
# MAKE SURE not to update anything else! # MAKE SURE not to update anything else!
# #
if (system("$SSH $control_node ". if (system("$SSH -host $control_node ".
"'$USERMOD $user -c \"$fullname\"'")) { "'$USERMOD $user -c \"$fullname\"'")) {
fatal("Could not modify user $user record on $control_node."); fatal("Could not modify user $user record on $control_node.");
} }
...@@ -245,7 +245,7 @@ else { ...@@ -245,7 +245,7 @@ else {
print "Updating user $user password on $control_node.\n"; print "Updating user $user password on $control_node.\n";
if (system("$SSH $control_node $CHPASS -p $pswd $user")) { if (system("$SSH -host $control_node $CHPASS -p $pswd $user")) {
fatal("Could not change password for user $user on $control_node.\n"); fatal("Could not change password for user $user on $control_node.\n");
} }
......
...@@ -227,10 +227,12 @@ $UID = $EUID; ...@@ -227,10 +227,12 @@ $UID = $EUID;
# #
# Create group on the control node if it does not exist. # Create group on the control node if it does not exist.
# #
if (system("$SSH $control_node egrep -q -s '^${unix_name}:' /etc/group")) { if (system("$SSH -host $control_node ".
"egrep -q -s '^${unix_name}:' /etc/group")) {
print "Adding group $unix_name to $control_node.\n"; print "Adding group $unix_name to $control_node.\n";
if (system("$SSH $control_node $GROUPADD $unix_name -g $unix_gid")) { if (system("$SSH -host $control_node ".
"$GROUPADD $unix_name -g $unix_gid")) {
fatal("*** Could not add $unix_name ($unix_gid) to $control_node!\n"); fatal("*** Could not add $unix_name ($unix_gid) to $control_node!\n");
} }
} }
...@@ -246,10 +248,12 @@ while (@db_row = $query_result->fetchrow_array() ) { ...@@ -246,10 +248,12 @@ while (@db_row = $query_result->fetchrow_array() ) {
} }
foreach my $tipserver ( @tipservers ) { foreach my $tipserver ( @tipservers ) {
if (system("$SSH $tipserver egrep -q -s '^${unix_name}:' /etc/group")) { if (system("$SSH -host $tipserver ".
"egrep -q -s '^${unix_name}:' /etc/group")) {
print "Adding group $unix_name to $tipserver\n"; print "Adding group $unix_name to $tipserver\n";
if (system("$SSH $tipserver $GROUPADD $unix_name -g $unix_gid")) { if (system("$SSH -host $tipserver ".
"$GROUPADD $unix_name -g $unix_gid")) {
fatal("*** Could not add $unix_name ($unix_gid) to $tipserver!\n"); fatal("*** Could not add $unix_name ($unix_gid) to $tipserver!\n");
} }
} }
......
...@@ -53,7 +53,6 @@ my $TB = "@prefix@"; ...@@ -53,7 +53,6 @@ my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@"; my $TBLOGS = "@TBLOGSEMAIL@";
my $ssh = "$TB/bin/sshtb -n";
my @nodes = (); my @nodes = ();
my %controls = (); my %controls = ();
my $eidmode = 0; my $eidmode = 0;
......
...@@ -339,7 +339,7 @@ sub RebootNode { ...@@ -339,7 +339,7 @@ sub RebootNode {
} }
} }
else { else {
exec("$ssh $pc /sbin/reboot"); exec("$ssh -host $pc /sbin/reboot");
exit(0); exit(0);
} }
......
...@@ -31,7 +31,6 @@ my $TBOPS = "@TBOPSEMAIL@"; ...@@ -31,7 +31,6 @@ my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@"; my $TBLOGS = "@TBLOGSEMAIL@";
my $ssh = "$TB/bin/sshtb -n"; my $ssh = "$TB/bin/sshtb -n";
my $sshremote = "$TB/bin/sshremote -n";
my $expsetup = "$TB/sbin/exports_setup"; my $expsetup = "$TB/sbin/exports_setup";
my $batchmode = 0; my $batchmode = 0;
my $maxchildren = 20; my $maxchildren = 20;
...@@ -303,10 +302,10 @@ sub UpdateNode { ...@@ -303,10 +302,10 @@ sub UpdateNode {
} }
else { else {
if ($isremote) { if ($isremote) {
exec("$sshremote $node /usr/local/etc/testbed/update"); exec("$ssh -host $node /usr/local/etc/testbed/update");
} }
else { else {
exec("$ssh $node /etc/testbed/update"); exec("$ssh -host $node /etc/testbed/update");
} }
exit(0); exit(0);
} }
......
...@@ -93,7 +93,7 @@ if (system("$USERDEL $user")) { ...@@ -93,7 +93,7 @@ if (system("$USERDEL $user")) {
} }
print "Removing user $user from $control_node.\n"; print "Removing user $user from $control_node.\n";
if (system("$SSH $control_node '$USERDEL $user'")) { if (system("$SSH -host $control_node '$USERDEL $user'")) {
fatal("Could not remove user $user from $control_node.\n"); fatal("Could not remove user $user from $control_node.\n");
} }
......
...@@ -142,7 +142,7 @@ $UID = 0; ...@@ -142,7 +142,7 @@ $UID = 0;
print "Removing group $unix_name ($unix_gid) on $CONTROL.\n"; print "Removing group $unix_name ($unix_gid) on $CONTROL.\n";
if (system("$SSH $CONTROL $GROUPDEL $unix_name")) { if (system("$SSH -host $CONTROL $GROUPDEL $unix_name")) {
warn("*** WARNING: Could not remove group $unix_name from $CONTROL\n"); warn("*** WARNING: Could not remove group $unix_name from $CONTROL\n");
$errors++; $errors++;
} }
...@@ -162,7 +162,7 @@ while (@db_row = $query_result->fetchrow_array() ) { ...@@ -162,7 +162,7 @@ while (@db_row = $query_result->fetchrow_array() ) {
foreach my $tipserver ( @tipservers ) { foreach my $tipserver ( @tipservers ) {
print "Removing group $unix_name ($unix_gid) on $tipserver.\n"; print "Removing group $unix_name ($unix_gid) on $tipserver.\n";
if (system("$SSH $tipserver $GROUPDEL $unix_name")) { if (system("$SSH -host $tipserver $GROUPDEL $unix_name")) {
warn("*** WARNING: ". warn("*** WARNING: ".
"Could not remove group $unix_name from $tipserver!\n"); "Could not remove group $unix_name from $tipserver!\n");
$errors++; $errors++;
......
...@@ -119,7 +119,7 @@ if (system("$GROUPDEL $unix_name")) { ...@@ -119,7 +119,7 @@ if (system("$GROUPDEL $unix_name")) {
# #
$UID = 0; $UID = 0;
if (system("$SSH $CONTROL $GROUPDEL $unix_name")) { if (system("$SSH -host $CONTROL $GROUPDEL $unix_name")) {
warn("*** WARNING: ". warn("*** WARNING: ".
"Could not remove group $pid from from $CONTROL!\n"); "Could not remove group $pid from from $CONTROL!\n");
} }
...@@ -137,7 +137,7 @@ while (@db_row = $query_result->fetchrow_array() ) { ...@@ -137,7 +137,7 @@ while (@db_row = $query_result->fetchrow_array() ) {
} }
foreach my $tipserver ( @tipservers ) { foreach my $tipserver ( @tipservers ) {
if (system("$SSH $tipserver $GROUPDEL $unix_name")) { if (system("$SSH -host $tipserver $GROUPDEL $unix_name")) {
warn("*** WARNING: ". warn("*** WARNING: ".
"Could not remove group $pid from $tipserver!\n"); "Could not remove group $pid from $tipserver!\n");
$errors++; $errors++;
......
...@@ -318,7 +318,7 @@ foreach my $uid (@userlist) { ...@@ -318,7 +318,7 @@ foreach my $uid (@userlist) {
print "Updating user $uid record on $control_node.\n"; print "Updating user $uid record on $control_node.\n";
if (system("$SSH $control_node ". if (system("$SSH -host $control_node ".
"'$USERMOD $uid -g $project $groupargument'")) { "'$USERMOD $uid -g $project $groupargument'")) {
fatal("Could not modify user $uid record on $control_node."); fatal("Could not modify user $uid record on $control_node.");
} }
......
...@@ -26,7 +26,6 @@ my $TBOPS = "@TBOPSEMAIL@"; ...@@ -26,7 +26,6 @@ my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@"; my $TBLOGS = "@TBLOGSEMAIL@";
my $ssh = "$TB/bin/sshtb -n"; my $ssh = "$TB/bin/sshtb -n";
my $sshremote = "$TB/bin/sshremote -n";
my $debug = 0; my $debug = 0;
my $force = 0; my $force = 0;
my $failed = 0; my $failed = 0;
...@@ -220,10 +219,10 @@ foreach my $node (@nodes) { ...@@ -220,10 +219,10 @@ foreach my $node (@nodes) {
$UID = 0; $UID = 0;
if ($isremote) { if ($isremote) {
exec("$sshremote $pnode /usr/local/etc/testbed/vnodesetup $args"); exec("$ssh -host $pnode /usr/local/etc/testbed/vnodesetup $args");
} }
else { else {
exec("$ssh $pnode /etc/testbed/vnodesetup $args"); exec("$ssh -host $pnode /etc/testbed/vnodesetup $args");
} }
die("*** $0:\n". die("*** $0:\n".
" exec failed!\n"); " exec failed!\n");
......
...@@ -8,7 +8,7 @@ SUBDIR = utils ...@@ -8,7 +8,7 @@ SUBDIR = utils
include $(OBJDIR)/Makeconf include $(OBJDIR)/Makeconf
BIN_SCRIPTS = delay_config sshtb create_image node_admin sshremote BIN_SCRIPTS = delay_config sshtb create_image node_admin
SBIN_SCRIPTS = vlandiff vlansync SBIN_SCRIPTS = vlandiff vlansync
LIBEXEC_SCRIPTS = webcreateimage LIBEXEC_SCRIPTS = webcreateimage
......
#!/bin/sh
exec @SSH@ -l emulabman @SSH_ARGS@ $*
#!/bin/sh #!/usr/bin/perl -w
exec @SSH@ @SSH_ARGS@ $* use English;
#
# An ssh frontend to determine if the node is local or remote, and to
# add in special options.
#
# NOTE THE DIFFERENT SYNTAX!
#
sub usage()
{
print STDOUT
"Usage: sshtb [ssh args] -host <hostname> [command and args ...]\n";
exit(-1);
}
#
# Configure variables
#
my $TB = "@prefix@";
my $SSH = "@SSH@";
my $SSH_ARGS = '@SSH_ARGS@';
# Locals
my $debug = 0;
my @args;
my $hostname;
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
#
# Turn off line buffering on output
#
$| = 1;
# un-taint path
$ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:$TB/libexec:$TB/sbin:$TB/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# We run through the args looking for -host. We save everything else.
#
if (@ARGV < 2) {
usage();
}
# Find everything before the -host.
while (@ARGV) {
my $arg = shift(@ARGV);
if ($arg eq "-host") {
$hostname = shift(@ARGV);
last;
}
push(@args, $arg);
}
if (!defined($hostname)) {
usage();
}
#
# Different stuff for remote nodes.
#
my $cmd;
if (! TBValidNodeName($hostname) || !TBIsNodeRemote($hostname)) {
$cmd = "$SSH $SSH_ARGS @args $hostname @ARGV";
}
else {
$cmd = "$SSH $SSH_ARGS @args -l emulabman $hostname @ARGV";
}
if ($debug) {
print "$cmd\n";
}
system("$cmd");
exit($CHILD_ERROR >> 8);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment