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

« back to all changes in this revision

Viewing changes to lib/common/interpret.py

  • Committer: dcoles
  • Date: 2008-02-13 04:10:55 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:443
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
CGI_BLOCK_SIZE = 65535
44
44
 
45
 
def interpret_file(req, owner, filename, interpreter):
 
45
def interpret_file(req, owner, jail_dir, filename, interpreter):
46
46
    """Serves a file by interpreting it using one of IVLE's builtin
47
47
    interpreters. All interpreters are intended to run in the user's jail. The
48
48
    jail location is provided as an argument to the interpreter but it is up
50
50
 
51
51
    req: An IVLE request object.
52
52
    owner: Username of the user who owns the file being served.
53
 
    filename: Filename in the local file system.
 
53
    jail_dir: Absolute path to the user's jail.
 
54
    filename: Absolute filename within the user's jail.
54
55
    interpreter: A function object to call.
55
56
    """
56
57
    # Make sure the file exists (otherwise some interpreters may not actually
57
58
    # complain).
58
59
    # Don't test for execute permission, that will only be required for
59
60
    # certain interpreters.
60
 
    if not os.access(filename, os.R_OK):
 
61
    if filename.startswith(os.sep):
 
62
        filename_abs = filename
 
63
        filename_rel = filename[1:]
 
64
    else:
 
65
        filename_abs = os.path.join(os.sep, filename)
 
66
        filename_rel = filename
 
67
 
 
68
    if not os.access(os.path.join(jail_dir, filename_rel), os.R_OK):
61
69
        req.throw_error(req.HTTP_NOT_FOUND)
62
70
 
63
71
    # Get the UID of the owner of the file
72
80
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR)
73
81
 
74
82
    # Split up req.path again, this time with respect to the jail
75
 
    (_, jail_dir, path) = studpath.url_to_jailpaths(req.path)
76
 
    path = os.path.join('/', path)
77
 
    (working_dir, _) = os.path.split(path)
 
83
    (working_dir, _) = os.path.split(filename_abs)
78
84
    # jail_dir is the absolute jail directory.
79
85
    # path is the filename relative to the user's jail.
80
86
    # working_dir is the directory containing the file relative to the user's
82
88
    # (Note that paths "relative" to the jail actually begin with a '/' as
83
89
    # they are absolute in the jailspace)
84
90
 
85
 
    return interpreter(uid, jail_dir, working_dir, path, req)
 
91
    return interpreter(uid, jail_dir, working_dir, filename_abs, req)
86
92
 
87
93
class CGIFlags:
88
94
    """Stores flags regarding the state of reading CGI output."""