24
35
print 'signal: ', signum
25
36
raise Exception, 'Timeout!'
27
signal.signal(signal.SIGALRM, timeout)
29
sok = socket.socket(socket.AF_INET)
30
sok.bind(('localhost',9998))
32
(new_sok,addr) = sok.accept()
34
c = codeop.CommandCompiler()
38
globs['__builtins__'] = globals()['__builtins__']
40
out = cStringIO.StringIO()
43
for line in req_lines(new_sok):
48
src = src + '\n' + line
52
res = eval(cmd, globs, locos)
54
new_sok.send(cjson.encode((out.getvalue(),res)) + '\n')
55
out = cStringIO.StringIO()
59
sok.shutdown(socket.SHUT_RDWR)
38
# signal.signal(signal.SIGALRM, timeout)
40
# sok = socket.socket(socket.AF_INET)
41
# sok.bind(('localhost',9998))
43
# (new_sok,addr) = sok.accept()
45
# c = codeop.CommandCompiler()
49
# globs['__builtins__'] = globals()['__builtins__']
51
# out = cStringIO.StringIO()
54
# for line in req_lines(new_sok):
59
# src = src + '\n' + line
63
# res = eval(cmd, globs, locos)
65
# new_sok.send(cjson.encode((out.getvalue(),res)) + '\n')
66
# out = cStringIO.StringIO()
70
# sok.shutdown(socket.SHUT_RDWR)
72
if __name__ == "__main__":
74
uid = int(sys.argv[1])
76
print >> sys.stderr, "uid must be an integer."
81
port = int(sys.argv[4])
83
print >> sys.stderr, "port must be an integer."
93
print >> sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
96
# Okay, now decouple from the parent environment
107
print >> sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
110
# establish the chrooted environment
111
setup_environment(uid, jail, cwd)
113
signal.signal(signal.SIGALRM, timeout)
115
main_sok = socket.socket(socket.AF_INET)
116
main_sok.bind(('localhost',port))
119
comp = codeop.CommandCompiler()
122
globs['__builtins__'] = globals()['__builtins__']
127
(sok,addr) = main_sok.accept()
132
for line in req_lines(new_sok):
137
src = src + '\n' + line
142
res = eval(cmd, globs, locos)
144
rval = (out.getvalue(), res, None)
145
sok.send(cjson.encode(rval) + '\n')
146
out = cStringIO.StringIO()
150
rval = (None, None, str(e))
151
sok.send(cjson.encode(rval) + '\n')
152
out = cStringIO.StringIO()
159
main_sok.shutdown(socket.SHUT_RDWR)