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

« back to all changes in this revision

Viewing changes to platform/scripts/safe-python

  • Committer: drtomc
  • Date: 2007-12-04 01:57:41 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:3
A README file describing sundry bits of the platform infrastructure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
import sys
 
5
import re
 
6
import resource
 
7
 
 
8
jailBase = '/home/infomatics/jails/'
 
9
siteBase = '/home/informatics/www/'
 
10
 
 
11
def findUser(login):
 
12
    entries = {}
 
13
    passwdfile = open('/etc/passwd')
 
14
    for line in passwdfile.readlines():
 
15
        rec = re.split(':',line)
 
16
        if rec[0] == login:
 
17
            return rec
 
18
    raise Exception, (login + " not found!")
 
19
 
 
20
def throttle():
 
21
    Kb = 1024
 
22
    Mb = 1024 * 1024
 
23
 
 
24
    limits = [(resource.RLIMIT_CORE,     (0,0)), \
 
25
              (resource.RLIMIT_CPU,      (1,2)), \
 
26
              (resource.RLIMIT_FSIZE,    (5 * Mb, 5 * Mb)), \
 
27
              (resource.RLIMIT_DATA,     (20 * Mb, 24 * Mb)), \
 
28
              (resource.RLIMIT_STACK,    (8 * Mb, 9 * Mb)), \
 
29
              (resource.RLIMIT_NPROC,    (10, 10)), \
 
30
              (resource.RLIMIT_NOFILE,   (10, 12))]
 
31
 
 
32
    for (r,l) in limits:
 
33
        resource.setrlimit(r,l)
 
34
 
 
35
def runit(login, script):
 
36
    user = findUser(login)
 
37
    uid = int(user[2])
 
38
    os.chdir(jailBase + login)
 
39
    os.chroot(jailBase + login)
 
40
    os.setuid(uid)
 
41
    throttle()
 
42
    os.execlp("/usr/bin/python", "python", script)
 
43
 
 
44
os.environ['DOCUMENT_ROOT'] = '/'
 
45
os.environ['SCRIPT_FILENAME'] = re.sub(siteBase, '/home/',
 
46
                                        os.environ['SCRIPT_FILENAME'])
 
47
 
 
48
m = re.match('^/([^/]*)/', os.environ['SCRIPT_NAME'])
 
49
if m is None:
 
50
    exit(1)
 
51
login = m.group(1)
 
52
 
 
53
runit(login, os.environ['SCRIPT_FILENAME'])