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

« back to all changes in this revision

Viewing changes to platform/scripts/safe-python

[Uber-commit of holiday work because I lacked a local copy of the branch.]

 ivle.makeuser: Don't use jailconf.py as a header for the in-jail conf.py;
     generate the whole thing using string formatting operators and include
     the template inline.

 ivle.makeuser.make_conf_py: XXX the inclusion of ivle.conf.jail_base in
     the jail. It is simply there to placate ivle.studpath, and needs
     to go before we can entirely remove the in-jail config.

 ivle-buildjail:
   - Add. Converted from setup.buildjail.
   - Build the jail in __base_build__ and rsync it to __base__ when
     done, rather than operating only in ./jail
   - Rename --rebuildjail/-j to --recreate/-r, as the whole script
     is now for jail rebuilding. Also add a warning to the usage string about
     the large volume likely to be downloaded.
   - Check existence before removing trees.
   - Don't copy jailconf.py over conf.py in the jail. Also make
     sure that we remove conf.pyc.

 setup.configure:
   - Stop generating jailconf.py at all.
   - Add a jail_system_build setting, defaulting to __base_build__ next to
     the existing __base__.
   - Don't use an OptionParser before calling the real function, as that
     adds options dynamically.

 setup.install:
   - Add an option (-R) to avoid writing out svn revision info to
     $PREFIX/share/ivle/revision.txt.
   - Remove jail-copying things.
   - Install all services to the host, rather than just usrmgt-server. We do
     this so we can build the jail from the host without the source tree.
   - Shuffle some things, and don't install phpBB3 twice.
   - Add a --root argument, to take an alternate root directory to install
     into (as given to autotools in $DESTDIR).

 setup.build:
   - Allow running as non-root.
   - Take a --no-compile option to not byte-compile Python files.

 setup.util:
   - Include usrmgt-server in the list of services.
   - Add make_install_path(), a wrapper around os.path.join() that ensures
     the second path is relative.
   - Install ivle-buildjail with the other binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/local/bin/python
2
 
 
3
 
import os
4
 
import sys
5
 
import re
6
 
import resource
7
 
 
8
 
jailBase = '/home/informatics/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,   (50, 60))]
31
 
 
32
 
    for (r,l) in limits:
33
 
        resource.setrlimit(r,l)
34
 
 
35
 
def runit(login):
36
 
    os.environ['DOCUMENT_ROOT'] = '/'
37
 
    os.environ['SCRIPT_FILENAME'] = re.sub(siteBase + login + '/',
38
 
                        '/home/' + login + '/svn/' + login + '/trunk/',
39
 
                        os.environ['SCRIPT_FILENAME'])
40
 
    os.environ['HOME'] = '/home/' + login
41
 
    script = os.environ['SCRIPT_FILENAME']
42
 
    user = findUser(login)
43
 
    uid = int(user[2])
44
 
    os.chdir(jailBase + login)
45
 
    os.chroot(jailBase + login)
46
 
    os.setuid(uid)
47
 
    throttle()
48
 
    os.execlp("/usr/bin/python", "python", script)
49
 
 
50
 
m = re.match('^/([^/]*)/', os.environ['SCRIPT_NAME'])
51
 
if m is None:
52
 
    exit(1)
53
 
login = m.group(1)
54
 
 
55
 
runit(login)