Kaydet (Commit) 42ded89c authored tarafından Guido van Rossum's avatar Guido van Rossum

Reformulate security check using getsockname().

üst eca991df
......@@ -48,14 +48,15 @@ def main_thread(port):
print "Listening on port", port, "..."
while 1:
(conn, addr) = sock.accept()
if addr[0] != conn.getsockname()[0]:
conn.close()
print "Refusing connection from non-local host", addr[0], "."
continue
thread.start_new_thread(service_thread, (conn, addr))
del conn, addr
def service_thread(conn, addr):
(caddr, cport) = addr
if caddr != socket.gethostbyname(socket.gethostname()):
print "Connection from", caddr, "not accepted."
return
print "Thread %s has connection from %s.\n" % (str(thread.get_ident()),
caddr),
stdin = conn.makefile("r")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment