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> [<interp>]
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.
36
# <interp> If given, the interpreter to invoke the script with.
48
limits = [(resource.RLIMIT_CORE, (0,0)), \
49
(resource.RLIMIT_CPU, (1,2)), \
50
(resource.RLIMIT_FSIZE, (5 * Mb, 5 * Mb)), \
51
(resource.RLIMIT_DATA, (20 * Mb, 24 * Mb)), \
52
(resource.RLIMIT_STACK, (8 * Mb, 9 * Mb)), \
53
(resource.RLIMIT_NPROC, (10, 10)), \
54
(resource.RLIMIT_NOFILE, (10, 12))]
57
resource.setrlimit(r,l)
59
def runscript(uid, jail, cwd, script, interp):
61
sys.exit(sys.argv[0] + ": cannot run scripts as root!\n")
62
# os.chroot(os.path.join(<<base-directory-for-jails>>, jail))
68
os.execl(interp, script)
72
if len(sys.argv) == 5:
73
runscript(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], None)
75
runscript(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])