summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian May <brian@linuxpenguins.xyz>2020-05-15 07:55:38 +1000
committerBrian May <brian@linuxpenguins.xyz>2020-05-29 07:44:51 +1000
commit6c21addde97c4582b3dccb22bca64c33af3e5eff (patch)
tree7e7ca84ef55444012645f996deca262b7d836d6c
parent4b320180c45c6ac96a73a966dda167457e9dd70b (diff)
Fix Python 3.8 file operations
Under Python 3.8 we can not wrap a File in a Sock. Note this currently requires Python >= 3.5
-rw-r--r--sshuttle/client.py2
-rw-r--r--sshuttle/server.py5
-rw-r--r--sshuttle/ssnet.py28
3 files changed, 16 insertions, 19 deletions
diff --git a/sshuttle/client.py b/sshuttle/client.py
index eebc0d8..efdaae1 100644
--- a/sshuttle/client.py
+++ b/sshuttle/client.py
@@ -461,7 +461,7 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
raise Fatal("failed to establish ssh session (1)")
else:
raise
- mux = Mux(serversock, serversock)
+ mux = Mux(serversock.makefile("rb"), serversock.makefile("wb"))
handlers.append(mux)
expected = b'SSHUTTLE0001'
diff --git a/sshuttle/server.py b/sshuttle/server.py
index b6f6604..37f942a 100644
--- a/sshuttle/server.py
+++ b/sshuttle/server.py
@@ -294,10 +294,7 @@ def main(latency_control, auto_hosts, to_nameserver, auto_nets):
sys.stdout.flush()
handlers = []
- mux = Mux(socket.fromfd(sys.stdin.fileno(),
- socket.AF_INET, socket.SOCK_STREAM),
- socket.fromfd(sys.stdout.fileno(),
- socket.AF_INET, socket.SOCK_STREAM))
+ mux = Mux(sys.stdin, sys.stdout)
handlers.append(mux)
debug1('auto-nets:' + str(auto_nets) + '\n')
diff --git a/sshuttle/ssnet.py b/sshuttle/ssnet.py
index f6044aa..e7f668b 100644
--- a/sshuttle/ssnet.py
+++ b/sshuttle/ssnet.py
@@ -339,10 +339,10 @@ class Proxy(Handler):
class Mux(Handler):
- def __init__(self, rsock, wsock):
- Handler.__init__(self, [rsock, wsock])
- self.rsock = rsock
- self.wsock = wsock
+ def __init__(self, rfile, wfile):
+ Handler.__init__(self, [rfile, wfile])
+ self.rfile = rfile
+ self.wfile = wfile
self.new_channel = self.got_dns_req = self.got_routes = None
self.got_udp_open = self.got_udp_data = self.got_udp_close = None
self.got_host_req = self.got_host_list = None
@@ -439,9 +439,9 @@ class Mux(Handler):
callback(cmd, data)
def flush(self):
- self.wsock.setblocking(False)
+ os.set_blocking(self.wfile.fileno(), False)
if self.outbuf and self.outbuf[0]:
- wrote = _nb_clean(os.write, self.wsock.fileno(), self.outbuf[0])
+ wrote = _nb_clean(os.write, self.wfile.fileno(), self.outbuf[0])
debug2('mux wrote: %r/%d\n' % (wrote, len(self.outbuf[0])))
if wrote:
self.outbuf[0] = self.outbuf[0][wrote:]
@@ -449,9 +449,9 @@ class Mux(Handler):
self.outbuf[0:1] = []
def fill(self):
- self.rsock.setblocking(False)
+ os.set_blocking(self.rfile.fileno(), False)
try:
- read = _nb_clean(os.read, self.rsock.fileno(), LATENCY_BUFFER_SIZE)
+ read = _nb_clean(os.read, self.rfile.fileno(), LATENCY_BUFFER_SIZE)
except OSError:
_, e = sys.exc_info()[:2]
raise Fatal('other end: %r' % e)
@@ -481,22 +481,22 @@ class Mux(Handler):
break
def pre_select(self, r, w, x):
- _add(r, self.rsock)
+ _add(r, self.rfile)
if self.outbuf:
- _add(w, self.wsock)
+ _add(w, self.wfile)
def callback(self, sock):
- (r, w, _) = select.select([self.rsock], [self.wsock], [], 0)
- if self.rsock in r:
+ (r, w, _) = select.select([self.rfile], [self.wfile], [], 0)
+ if self.rfile in r:
self.handle()
- if self.outbuf and self.wsock in w:
+ if self.outbuf and self.wfile in w:
self.flush()
class MuxWrapper(SockWrapper):
def __init__(self, mux, channel):
- SockWrapper.__init__(self, mux.rsock, mux.wsock)
+ SockWrapper.__init__(self, mux.rfile, mux.wfile)
self.mux = mux
self.channel = channel
self.mux.channels[channel] = self.got_packet