#!/usr/bin/perl -wT use English; # # usage: console_setup node [node node ...] # sub usage() { print STDOUT "Usage: console_setup node [node ...]\n"; exit(-1); } my $optlist = ""; # # Configure variables # my $TB = "@prefix@"; # # Load the Testbed support stuff. # push(@INC, "$TB/lib"); require libdb; # Turn off line buffering on output $| = 1; my $SSH = "sshtb -n -q -l root plastic.emulab.net"; my $PROG = "$TB/sbin/console_setup.proxy"; my $TBPID = "flux"; my $cmdargs = ""; my @row; # un-taint path $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; # # Parse command arguments. Once we return from getopts, all that should # left are the required arguments. # %options = (); if (! getopts($optlist, \%options)) { usage(); } if (@ARGV == 0) { usage(); } my @nodes = @ARGV; # # Script must be setuid root. We don't worry about who called us or what # nodes are specified since this script always does the right thing. # if ($EUID != 0) { die("Must be root! Maybe its a development version?"); } # # Build of a list of nodes/pid pairs and then send the command over to # plastic. # foreach my $node (@nodes) { my($db_result); # # Untaint the argument. # if ($node =~ /^([-\@\w.]+)$/) { $node = $1; } else { die("Tainted node name: $node"); } # # Need the project for the node since that is the group. # # HACK! If its a shark shelf, then need a wildcard query so we can # the nodes. # if ($node =~ /sh\d+/) { $db_result = DBQueryFatal("select pid from reserved ". "where node_id like '$node%'"); } else { $db_result = DBQueryFatal("select pid from reserved where node_id='$node'"); } if ($db_result->numrows > 0) { @row = $db_result->fetchrow_array(); $pid = $row[0]; } else { $pid = $TBPID; } $cmdargs = "$cmdargs $node $pid"; } $UID = 0; system("$SSH $PROG $cmdargs") == 0 or die("Failed: $SSH $PROG $cmdargs: $?"); exit 0;