~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-25 02:26:39 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:562
Added new app: Diff (SVN diff application)
setup.py: Added diffservice script to jail scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# This can be resolved but needs careful sanitisation. See fixup_environ.
29
29
 
30
30
from common import studpath
31
 
from common import db
32
31
import conf
33
32
import functools
34
33
 
43
42
 
44
43
CGI_BLOCK_SIZE = 65535
45
44
 
46
 
uids = {}
47
 
 
48
 
def get_uid(login):
49
 
    """Get the unix uid corresponding to the given login name.
50
 
       If it is not in the dictionary of uids, then consult the
51
 
       database and retrieve an update of the user table."""
52
 
    global uids
53
 
    if login in uids:
54
 
        return uids[login]
55
 
 
56
 
    conn = db.DB()
57
 
    res = conn.get_all('login', ['login', 'unixid'])
58
 
    def repack(flds):
59
 
        return (flds['login'], flds['unixid'])
60
 
    uids = dict(map(repack,res))
61
 
 
62
 
    return uids[login]
63
 
 
64
45
def interpret_file(req, owner, jail_dir, filename, interpreter):
65
46
    """Serves a file by interpreting it using one of IVLE's builtin
66
47
    interpreters. All interpreters are intended to run in the user's jail. The
73
54
    filename: Absolute filename within the user's jail.
74
55
    interpreter: A function object to call.
75
56
    """
76
 
    # We can't test here whether or not the target file actually exists,
77
 
    # because the apache user may not have permission. Instead we have to
78
 
    # rely on the interpreter generating an error.
 
57
    # Make sure the file exists (otherwise some interpreters may not actually
 
58
    # complain).
 
59
    # Don't test for execute permission, that will only be required for
 
60
    # certain interpreters.
79
61
    if filename.startswith(os.sep):
80
62
        filename_abs = filename
81
63
        filename_rel = filename[1:]
83
65
        filename_abs = os.path.join(os.sep, filename)
84
66
        filename_rel = filename
85
67
 
 
68
    if not os.access(os.path.join(jail_dir, filename_rel), os.R_OK):
 
69
        req.throw_error(req.HTTP_NOT_FOUND)
 
70
 
86
71
    # Get the UID of the owner of the file
87
72
    # (Note: files are executed by their owners, not the logged in user.
88
73
    # This ensures users are responsible for their own programs and also
89
74
    # allows them to be executed by the public).
90
 
    uid = get_uid(owner)
 
75
    uid = req.user.unixid
91
76
 
92
77
    # Split up req.path again, this time with respect to the jail
93
78
    (working_dir, _) = os.path.split(filename_abs)