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

« back to all changes in this revision

Viewing changes to ivle/interpret.py

  • Committer: David Coles
  • Date: 2010-02-25 12:47:39 UTC
  • Revision ID: coles.david@gmail.com-20100225124739-182p1ec7zggfjt3v
interpret: Make fixup_env use a user object rather than path munging...

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
    # (Note that paths "relative" to the jail actually begin with a '/' as
74
74
    # they are absolute in the jailspace)
75
75
 
76
 
    return interpreter(owner.unixid, jail_dir, working_dir, filename_abs, req,
 
76
    return interpreter(owner, jail_dir, working_dir, filename_abs, req,
77
77
                       gentle)
78
78
 
79
79
class CGIFlags:
88
88
        self.linebuf = ""
89
89
        self.headers = {}       # Header names : values
90
90
 
91
 
def execute_cgi(interpreter, uid, jail_dir, working_dir, script_path,
 
91
def execute_cgi(interpreter, owner, jail_dir, working_dir, script_path,
92
92
                req, gentle):
93
93
    """
94
94
    trampoline: Full path on the local system to the CGI wrapper program
95
95
        being executed.
96
 
    uid: User ID of the owner of the file.
 
96
    owner: User object of the owner of the file.
97
97
    jail_dir: Absolute path of owner's jail directory.
98
98
    working_dir: Directory containing the script file relative to owner's
99
99
        jail.
136
136
        del os.environ[k]
137
137
    for (k,v) in req.get_cgi_environ().items():
138
138
        os.environ[k] = v
139
 
    fixup_environ(req, script_path)
 
139
    fixup_environ(req, script_path, owner)
140
140
 
141
141
    # usage: tramp uid jail_dir working_dir script_path
142
 
    cmd_line = [trampoline, str(uid), req.config['paths']['jails']['mounts'],
143
 
         req.config['paths']['jails']['src'],
144
 
         req.config['paths']['jails']['template'],
145
 
         jail_dir, working_dir, interpreter, script_path]
 
142
    cmd_line = [trampoline, str(owner.unixid),
 
143
            req.config['paths']['jails']['mounts'],
 
144
            req.config['paths']['jails']['src'],
 
145
            req.config['paths']['jails']['template'],
 
146
            jail_dir, working_dir, interpreter, script_path]
146
147
    # Popen doesn't like unicode strings. It hateses them.
147
148
    cmd_line = [(s.encode('utf-8') if isinstance(s, unicode) else s)
148
149
                for s in cmd_line]
361
362
    # python-server-page
362
363
}
363
364
 
364
 
def fixup_environ(req, script_path):
 
365
def fixup_environ(req, script_path, user):
365
366
    """Assuming os.environ has been written with the CGI variables from
366
367
    apache, make a few changes for security and correctness.
367
368
 
418
419
    env['SERVER_SOFTWARE'] = "IVLE/" + ivle.__version__
419
420
 
420
421
    # Additional environment variables
421
 
    username = split_path(req.path)[0]
 
422
    username = user.login
422
423
    env['HOME'] = os.path.join('/home', username)
423
424
 
424
425
class ExecutionError(Exception):