3
# Copyright (C) 2007-2008 The University of Melbourne
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
# Usage: trampoline.py <uid> <jail-dir> <cwd-within-jail> <script-name>
24
# <uid> The user id of the user to do the evaluation
25
# At the moment this is the user-name, but it would be
26
# nice if it were made to be the numeric uid, since the
27
# trampoline has to read /etc/passwd to figure this out
28
# at the moment. OTOH, the server invoking the trampoline
29
# may know it already, and in any case can cache it between
30
# requests, which the trampoline cannot.
31
# <jail-dir> The directory that the trampoline should chroot to
32
# <cwd-within-jail> The directory within the jail that should be
33
# made the current working directory for the script.
34
# This should be relative to / within the jail.
35
# <script-name> The path (within the jail) to the script to be executed.
47
limits = [(resource.RLIMIT_CORE, (0,0)), \
48
(resource.RLIMIT_CPU, (1,2)), \
49
(resource.RLIMIT_FSIZE, (5 * Mb, 5 * Mb)), \
50
(resource.RLIMIT_DATA, (20 * Mb, 24 * Mb)), \
51
(resource.RLIMIT_STACK, (8 * Mb, 9 * Mb)), \
52
(resource.RLIMIT_NPROC, (10, 10)), \
53
(resource.RLIMIT_NOFILE, (10, 12))]
56
resource.setrlimit(r,l)
58
def runscript(uid, jail, cwd, script):
60
sys.exit(sys.argv[0] + ": cannot run scripts as root!\n")
61
if not jail.startswith("/home/mgiuca/playground"):
62
sys.exit(sys.argv[0] + ": invalid jail location!\n")
67
m = compile(file(script,'r').read(), script, 'exec')
69
g['__builtins__'] = globals()['__builtins__']
70
g['__file__'] = script
71
g['__name__'] = '__main__'
76
runscript(int(sys.argv[1]), sys.argv[2], sys.argv[3], sys.argv[4])