subboss_wrapper.in 1.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2009-2010 University of Utah and the Flux Group.
# All rights reserved.
#

use strict;
use English;

sub usage()
{
    print "Usage: subboss_wrapper <command> [args]\n";
    print "\n";
    print "Valid commands:\n";
Ryan Jackson's avatar
Ryan Jackson committed
16
    print "  frisbeelauncher [args]    Run frisbee_launcher with specified arugments\n";
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
    print "\n";
    exit(1);
}

sub fatal($) {
    my($mesg) = $_[0];

    die("*** $0:\n".
	"    $mesg\n");
}

my $TB          = "@prefix@";
my $ELABMAN     = "elabman";

my $FRISBEE_LAUNCHER = "$TB/sbin/frisbeelauncher";

use lib "@prefix@/lib";
use User;

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# We do not want to run this script unless its the real version.
#
if ($EUID != 0) {
    die("*** $0:\n".
	"    Must be setuid! Maybe its a development version?\n");
}

#
# We need this user for running below.
#
my $elabman = User->Lookup($ELABMAN);
if (!defined($elabman)) {
    fatal("Could not lookup $ELABMAN user. Exiting ...");
}

if ($UID != $elabman->unix_uid()) {
    die("Must be elabman to run this script\n");
}

# Switch to root

$UID = $EUID = 0;

usage() if (@ARGV == 0);

my $command = shift @ARGV;
if ($command eq 'frisbeelauncher') {
	# Pass the argument list through as-is
	my @args = map { /(.*)/; $1 } @ARGV;
	exec $FRISBEE_LAUNCHER, @args;
} else {
    fatal("Invalid command \"$command\"");
}