~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to src/bin/trampoline-generic

  • Committer: drtomc
  • Date: 2007-12-17 05:02:10 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:73
Partial fix for potential security issue with the trampoline

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# Author: Tom Conway
21
21
# Date: 13/12/2007
22
22
 
23
 
# Usage: trampoline.py <uid> <jail-dir> <cwd-within-jail> <script-name>
 
23
# Usage: trampoline.py <uid> <jail-dir> <cwd-within-jail> <script-name> [<interp>]
24
24
#   <uid>       The user id of the user to do the evaluation
25
25
#               At the moment this is the user-name, but it would be
26
26
#               nice if it were made to be the numeric uid, since the
33
33
#               made the current working directory for the script.
34
34
#               This should be relative to / within the jail.
35
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.
 
37
 
36
38
 
37
39
import os
38
40
import sys
54
56
    for (r,l) in limits:
55
57
        resource.setrlimit(r,l)
56
58
 
57
 
def runscript(uid, jail, cwd, script):
 
59
def runscript(uid, jail, cwd, script, interp):
 
60
    if uid == 0:
 
61
        sys.exit(sys.argv[0] + ": cannot run scripts as root!\n")
 
62
    # os.chroot(os.path.join(<<base-directory-for-jails>>, jail))
58
63
    os.chroot(jail)
59
64
    os.chdir(cwd)
60
65
    os.setuid(uid)
61
66
    throttle()
62
 
    os.execl(script)
63
 
 
64
 
runscript(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
 
67
    if interp:
 
68
        os.execl(interp, script)
 
69
    else
 
70
        os.execl(script)
 
71
 
 
72
if len(sys.argv) == 5:
 
73
    runscript(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], None)
 
74
else:
 
75
    runscript(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
 
76