5
by drtomc
Fix a bunch of glitches that Ivo and I found yesterday. |
1 |
#!/usr/local/bin/python
|
1
by drtomc
An initial checkin. |
2 |
|
3 |
import os |
|
4 |
import sys |
|
5 |
import re |
|
6 |
import resource |
|
7 |
||
5
by drtomc
Fix a bunch of glitches that Ivo and I found yesterday. |
8 |
jailBase = '/home/informatics/jails/' |
1
by drtomc
An initial checkin. |
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)), \ |
|
6
by drtomc
Make a bunch of small changes suggested by Ivo. |
30 |
(resource.RLIMIT_NOFILE, (50, 60))] |
1
by drtomc
An initial checkin. |
31 |
|
32 |
for (r,l) in limits: |
|
33 |
resource.setrlimit(r,l) |
|
34 |
||
5
by drtomc
Fix a bunch of glitches that Ivo and I found yesterday. |
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']) |
|
6
by drtomc
Make a bunch of small changes suggested by Ivo. |
40 |
os.environ['HOME'] = '/home/' + login |
5
by drtomc
Fix a bunch of glitches that Ivo and I found yesterday. |
41 |
script = os.environ['SCRIPT_FILENAME'] |
1
by drtomc
An initial checkin. |
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 |
||
5
by drtomc
Fix a bunch of glitches that Ivo and I found yesterday. |
55 |
runit(login) |