From 231fc2b157fe941b53274d82cdaf2f5a02b955ba Mon Sep 17 00:00:00 2001 From: "Leigh B. Stoller" Date: Wed, 5 Jun 2002 13:31:34 +0000 Subject: [PATCH] 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 [more args ...] --- configure | 1 - configure.in | 1 - db/genelists.in | 2 +- sensors/slothd/sdisrunning.in | 5 +-- tbsetup/console_setup.in | 2 +- tbsetup/exports_setup.in | 2 +- tbsetup/mkacct.in | 8 ++-- tbsetup/mkgroup.in | 12 +++-- tbsetup/node_control.in | 1 - tbsetup/node_reboot.in | 2 +- tbsetup/node_update.in | 5 +-- tbsetup/rmacct-ctrl.in | 2 +- tbsetup/rmgroup.in | 4 +- tbsetup/rmproj.in | 4 +- tbsetup/setgroups.in | 2 +- tbsetup/vnode_setup.in | 5 +-- utils/GNUmakefile.in | 2 +- utils/sshremote.in | 2 - utils/sshtb.in | 85 ++++++++++++++++++++++++++++++++++- 19 files changed, 112 insertions(+), 35 deletions(-) delete mode 100755 utils/sshremote.in diff --git a/configure b/configure index 4da4f2c21..706b2ba42 100755 --- a/configure +++ b/configure @@ -1233,7 +1233,6 @@ outfiles="$outfiles Makeconf GNUmakefile \ tmcd/tmcd.restart \ utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \ utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \ - utils/sshremote \ www/GNUmakefile www/defs.php3 www/dbdefs.php3 \ vis/GNUmakefile vis/vistopology vis/webvistopology vis/top2gif \ vis/dbvistopology vis/dbtopper \ diff --git a/configure.in b/configure.in index 08826c129..b3b8a7d1a 100755 --- a/configure.in +++ b/configure.in @@ -305,7 +305,6 @@ outfiles="$outfiles Makeconf GNUmakefile \ tmcd/tmcd.restart \ utils/GNUmakefile utils/vlandiff utils/vlansync utils/delay_config \ utils/sshtb utils/create_image utils/node_admin utils/webcreateimage \ - utils/sshremote \ www/GNUmakefile www/defs.php3 www/dbdefs.php3 \ vis/GNUmakefile vis/vistopology vis/webvistopology vis/top2gif \ vis/dbvistopology vis/dbtopper \ diff --git a/db/genelists.in b/db/genelists.in index 00c5de977..18f00bfd1 100644 --- a/db/genelists.in +++ b/db/genelists.in @@ -21,7 +21,7 @@ my $TBALL = "@TBUSERSARCHIVE@"; my $PROJROOT = "/proj"; # 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 $lockfile = "/var/tmp/testbed_genelists_lockfile"; my $tempfile = "/var/tmp/testbed_genelists_tempfile"; diff --git a/sensors/slothd/sdisrunning.in b/sensors/slothd/sdisrunning.in index b22a885be..d403b2a92 100755 --- a/sensors/slothd/sdisrunning.in +++ b/sensors/slothd/sdisrunning.in @@ -64,7 +64,6 @@ foreach my $n (sort pcnum @nodes) { exit 0; sub check { - #my $ssh="sshtb -o \"FallBackToRsh no\" -o \"ConnectionAttempts 3\" -q"; my $ssh="sshtb -q"; my $node = shift; my $cmd1 = "ps auxwww | grep slothd | grep -v grep"; @@ -101,7 +100,7 @@ sub check { } } else { # child - $str = `sudo $ssh $node $cmd1`; + $str = `sudo $ssh -host $node $cmd1`; #print "$syspid - ssh succeeded:'$str'\n"; if ($str) { #print "running.\n"; @@ -112,7 +111,7 @@ sub check { my $f = "/tmp/tmp-$node-$$"; open (STDERR, "> $f") || warn("Couldn't open $f: $!\n"); - $str = `sudo $ssh $node $cmd2`; + $str = `sudo $ssh -host $node $cmd2`; my $rv = $?; if ($rv > 255) { $rv /= 256; } #print "\n(start=$rv)\n"; diff --git a/tbsetup/console_setup.in b/tbsetup/console_setup.in index 1a0dddca5..4e9ca1f92 100755 --- a/tbsetup/console_setup.in +++ b/tbsetup/console_setup.in @@ -134,7 +134,7 @@ $UID = 0; foreach my $server (keys(%cmdargs)) { 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"; exit 1; } diff --git a/tbsetup/exports_setup.in b/tbsetup/exports_setup.in index cb87a19e0..e318b885e 100644 --- a/tbsetup/exports_setup.in +++ b/tbsetup/exports_setup.in @@ -24,7 +24,7 @@ my $usersdir = "@FSDIR_USERS@"; my $groupdir = "@FSDIR_GROUPS@"; # 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 $exportstail = "/var/tmp/exports.tail"; my $lockfile = "/var/tmp/testbed_exports_lockfile"; diff --git a/tbsetup/mkacct.in b/tbsetup/mkacct.in index d6f55bffd..6d2689b21 100755 --- a/tbsetup/mkacct.in +++ b/tbsetup/mkacct.in @@ -221,10 +221,10 @@ else { $fullname =~ s/\"/\'/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"; - if (system("$SSH $control_node ". + if (system("$SSH -host $control_node ". "'$USERADD $user -u $user_number -c \"$fullname\" ". "-k /usr/share/skel -m -d $HOMEDIR/$user ". "-g $default_groupname -s /bin/tcsh'")) { @@ -237,7 +237,7 @@ else { # # MAKE SURE not to update anything else! # - if (system("$SSH $control_node ". + if (system("$SSH -host $control_node ". "'$USERMOD $user -c \"$fullname\"'")) { fatal("Could not modify user $user record on $control_node."); } @@ -245,7 +245,7 @@ else { 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"); } diff --git a/tbsetup/mkgroup.in b/tbsetup/mkgroup.in index 469296271..c131332fc 100644 --- a/tbsetup/mkgroup.in +++ b/tbsetup/mkgroup.in @@ -227,10 +227,12 @@ $UID = $EUID; # # 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"; - 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"); } } @@ -246,10 +248,12 @@ while (@db_row = $query_result->fetchrow_array() ) { } 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"; - 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"); } } diff --git a/tbsetup/node_control.in b/tbsetup/node_control.in index c86b194db..57fc8dbb2 100644 --- a/tbsetup/node_control.in +++ b/tbsetup/node_control.in @@ -53,7 +53,6 @@ my $TB = "@prefix@"; my $TBOPS = "@TBOPSEMAIL@"; my $TBLOGS = "@TBLOGSEMAIL@"; -my $ssh = "$TB/bin/sshtb -n"; my @nodes = (); my %controls = (); my $eidmode = 0; diff --git a/tbsetup/node_reboot.in b/tbsetup/node_reboot.in index 421209131..783a6e68f 100644 --- a/tbsetup/node_reboot.in +++ b/tbsetup/node_reboot.in @@ -339,7 +339,7 @@ sub RebootNode { } } else { - exec("$ssh $pc /sbin/reboot"); + exec("$ssh -host $pc /sbin/reboot"); exit(0); } diff --git a/tbsetup/node_update.in b/tbsetup/node_update.in index a0a18c59a..d39e38b02 100644 --- a/tbsetup/node_update.in +++ b/tbsetup/node_update.in @@ -31,7 +31,6 @@ my $TBOPS = "@TBOPSEMAIL@"; my $TBLOGS = "@TBLOGSEMAIL@"; my $ssh = "$TB/bin/sshtb -n"; -my $sshremote = "$TB/bin/sshremote -n"; my $expsetup = "$TB/sbin/exports_setup"; my $batchmode = 0; my $maxchildren = 20; @@ -303,10 +302,10 @@ sub UpdateNode { } else { if ($isremote) { - exec("$sshremote $node /usr/local/etc/testbed/update"); + exec("$ssh -host $node /usr/local/etc/testbed/update"); } else { - exec("$ssh $node /etc/testbed/update"); + exec("$ssh -host $node /etc/testbed/update"); } exit(0); } diff --git a/tbsetup/rmacct-ctrl.in b/tbsetup/rmacct-ctrl.in index 23d4f9196..4ffe8de27 100755 --- a/tbsetup/rmacct-ctrl.in +++ b/tbsetup/rmacct-ctrl.in @@ -93,7 +93,7 @@ if (system("$USERDEL $user")) { } 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"); } diff --git a/tbsetup/rmgroup.in b/tbsetup/rmgroup.in index 5f9b2d42f..94977c763 100644 --- a/tbsetup/rmgroup.in +++ b/tbsetup/rmgroup.in @@ -142,7 +142,7 @@ $UID = 0; 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"); $errors++; } @@ -162,7 +162,7 @@ while (@db_row = $query_result->fetchrow_array() ) { foreach my $tipserver ( @tipservers ) { 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: ". "Could not remove group $unix_name from $tipserver!\n"); $errors++; diff --git a/tbsetup/rmproj.in b/tbsetup/rmproj.in index 22fc7c608..907eb0eb8 100755 --- a/tbsetup/rmproj.in +++ b/tbsetup/rmproj.in @@ -119,7 +119,7 @@ if (system("$GROUPDEL $unix_name")) { # $UID = 0; -if (system("$SSH $CONTROL $GROUPDEL $unix_name")) { +if (system("$SSH -host $CONTROL $GROUPDEL $unix_name")) { warn("*** WARNING: ". "Could not remove group $pid from from $CONTROL!\n"); } @@ -137,7 +137,7 @@ while (@db_row = $query_result->fetchrow_array() ) { } foreach my $tipserver ( @tipservers ) { - if (system("$SSH $tipserver $GROUPDEL $unix_name")) { + if (system("$SSH -host $tipserver $GROUPDEL $unix_name")) { warn("*** WARNING: ". "Could not remove group $pid from $tipserver!\n"); $errors++; diff --git a/tbsetup/setgroups.in b/tbsetup/setgroups.in index 55e475620..0d37a4f9d 100755 --- a/tbsetup/setgroups.in +++ b/tbsetup/setgroups.in @@ -318,7 +318,7 @@ foreach my $uid (@userlist) { 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'")) { fatal("Could not modify user $uid record on $control_node."); } diff --git a/tbsetup/vnode_setup.in b/tbsetup/vnode_setup.in index 32d02b337..76386cab5 100644 --- a/tbsetup/vnode_setup.in +++ b/tbsetup/vnode_setup.in @@ -26,7 +26,6 @@ my $TBOPS = "@TBOPSEMAIL@"; my $TBLOGS = "@TBLOGSEMAIL@"; my $ssh = "$TB/bin/sshtb -n"; -my $sshremote = "$TB/bin/sshremote -n"; my $debug = 0; my $force = 0; my $failed = 0; @@ -220,10 +219,10 @@ foreach my $node (@nodes) { $UID = 0; if ($isremote) { - exec("$sshremote $pnode /usr/local/etc/testbed/vnodesetup $args"); + exec("$ssh -host $pnode /usr/local/etc/testbed/vnodesetup $args"); } else { - exec("$ssh $pnode /etc/testbed/vnodesetup $args"); + exec("$ssh -host $pnode /etc/testbed/vnodesetup $args"); } die("*** $0:\n". " exec failed!\n"); diff --git a/utils/GNUmakefile.in b/utils/GNUmakefile.in index f466b9c82..9c34cb323 100644 --- a/utils/GNUmakefile.in +++ b/utils/GNUmakefile.in @@ -8,7 +8,7 @@ SUBDIR = utils 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 LIBEXEC_SCRIPTS = webcreateimage diff --git a/utils/sshremote.in b/utils/sshremote.in deleted file mode 100755 index 7bb886448..000000000 --- a/utils/sshremote.in +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec @SSH@ -l emulabman @SSH_ARGS@ $* diff --git a/utils/sshtb.in b/utils/sshtb.in index b79cec2b3..55aa8f927 100755 --- a/utils/sshtb.in +++ b/utils/sshtb.in @@ -1,2 +1,83 @@ -#!/bin/sh -exec @SSH@ @SSH_ARGS@ $* +#!/usr/bin/perl -w +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 [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); -- GitLab