wasm-demo/demo/ermis-f/python_m/cur/0936

46 lines
1.6 KiB
Plaintext

From: arcege at shore.net (Michael P. Reilly)
Date: Thu, 22 Apr 1999 12:51:56 GMT
Subject: stdout in a restricted environment
References: <7fn3rs$1v9$1@whisper.globalserve.net>
Message-ID: <MXET2.15$7j4.3896@news.shore.net>
Content-Length: 1351
X-UID: 936
Chris AtLee <catlee at globalserve.net> wrote:
: I'm trying to make a program that will enable users to connect to a server
: running a python interpreter and be able to program in a restricted
: environment in that interpreter. The rexec object has methods called s_exec
: and s_eval which are supposed to use secure forms of the standard I/O
: streams, but I can't redefine them to be something else (specifically, an
: object that sends the response back to the client) Any pointers on how to
: go about redirecting the standard I/O streams from a restricted environment?
I would suggest making a subclass of RExec that redefines the
make_delegate_files method.
def __init__(self, socket, hooks = None, verbose = 0):
RExec.__init__(self, hooks=hooks, verbose=verbose)
self._data_socket = socket
def make_delegate_files(self):
reader = self._data_socket.makefile('r')
writer = self._data_socket.makefile('w')
s = self.modules['sys']
self.delegate_stdin = FileDelegate(s, 'stdin')
self.delegate_stdout = FileDelegate(s, 'stdout')
self.delegate_stderr = FileDelegate(s, 'stderr')
self.restricted_stdin = FileWrapper(reader)
self.restricted_stdout = FileWrapper(writer)
self.restricted_stderr = FileWrapper(writer)
Granted, I haven't tried this, but it looks correct. :)
Good luck.
-Arcege