From 495b3c39eac62b855d24652d4b657d8714727d78 Mon Sep 17 00:00:00 2001 From: vieira Date: Tue, 3 May 2016 00:18:32 +0000 Subject: [PATCH] Seed hosts without auto hosts A possible implementation for the change requested in #94, so that seed hosts can be used without auto hosts. In this scenario only the specified hosts (or ips) will be looked up (or rev looked up). --- sshuttle/assembler.py | 2 +- sshuttle/client.py | 9 +++++---- sshuttle/cmdline.py | 3 +-- sshuttle/hostwatch.py | 19 ++++++++++--------- sshuttle/server.py | 9 +++++---- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/sshuttle/assembler.py b/sshuttle/assembler.py index 137331e..c063dc6 100644 --- a/sshuttle/assembler.py +++ b/sshuttle/assembler.py @@ -34,4 +34,4 @@ sshuttle.helpers.verbose = verbosity import sshuttle.cmdline_options as options from sshuttle.server import main -main(options.latency_control) +main(options.latency_control, options.auto_hosts) diff --git a/sshuttle/client.py b/sshuttle/client.py index 4b4c89c..ffe598e 100644 --- a/sshuttle/client.py +++ b/sshuttle/client.py @@ -400,7 +400,7 @@ def ondns(listener, method, mux, handlers): def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename, python, latency_control, - dns_listener, seed_hosts, auto_nets, daemon): + dns_listener, seed_hosts, auto_hosts, auto_nets, daemon): debug1('Starting client with Python version %s\n' % platform.python_version()) @@ -418,7 +418,8 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename, (serverproc, serversock) = ssh.connect( ssh_cmd, remotename, python, stderr=ssyslog._p and ssyslog._p.stdin, - options=dict(latency_control=latency_control)) + options=dict(latency_control=latency_control, + auto_hosts=auto_hosts)) except socket.error as e: if e.args[0] == errno.EPIPE: raise Fatal("failed to establish ssh session (1)") @@ -514,7 +515,7 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename, def main(listenip_v6, listenip_v4, ssh_cmd, remotename, python, latency_control, dns, nslist, - method_name, seed_hosts, auto_nets, + method_name, seed_hosts, auto_hosts, auto_nets, subnets_include, subnets_exclude, daemon, pidfile): if daemon: @@ -713,7 +714,7 @@ def main(listenip_v6, listenip_v4, try: return _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename, python, latency_control, dns_listener, - seed_hosts, auto_nets, daemon) + seed_hosts, auto_hosts, auto_nets, daemon) finally: try: if daemon: diff --git a/sshuttle/cmdline.py b/sshuttle/cmdline.py index f5171ac..9e94e2c 100644 --- a/sshuttle/cmdline.py +++ b/sshuttle/cmdline.py @@ -35,8 +35,6 @@ def main(): if remotename == '' or remotename == '-': remotename = None nslist = [family_ip_tuple(ns) for ns in opt.ns_hosts] - if opt.seed_hosts and not opt.auto_hosts: - parser.error('--seed-hosts only works if you also use -H') if opt.seed_hosts: sh = re.split(r'[\s,]+', (opt.seed_hosts or "").strip()) elif opt.auto_hosts: @@ -69,6 +67,7 @@ def main(): nslist, opt.method, sh, + opt.auto_hosts, opt.auto_nets, includes, excludes, diff --git a/sshuttle/hostwatch.py b/sshuttle/hostwatch.py index 5dede13..3018597 100644 --- a/sshuttle/hostwatch.py +++ b/sshuttle/hostwatch.py @@ -255,7 +255,7 @@ def _stdin_still_ok(timeout): return True -def hw_main(seed_hosts): +def hw_main(seed_hosts, auto_hosts): if helpers.verbose >= 2: helpers.logprefix = 'HH: ' else: @@ -264,17 +264,18 @@ def hw_main(seed_hosts): debug1('Starting hostwatch with Python version %s\n' % platform.python_version()) - read_host_cache() - - _enqueue(_check_etc_hosts) - _enqueue(_check_netstat) - check_host('localhost') - check_host(socket.gethostname()) - check_workgroup('workgroup') - check_workgroup('-') for h in seed_hosts: check_host(h) + if auto_hosts: + read_host_cache() + _enqueue(_check_etc_hosts) + _enqueue(_check_netstat) + check_host('localhost') + check_host(socket.gethostname()) + check_workgroup('workgroup') + check_workgroup('-') + while 1: now = time.time() for t, last_polled in list(queue.items()): diff --git a/sshuttle/server.py b/sshuttle/server.py index 73c961d..ba11a99 100644 --- a/sshuttle/server.py +++ b/sshuttle/server.py @@ -98,7 +98,7 @@ def _exc_dump(): return ''.join(traceback.format_exception(*exc_info)) -def start_hostwatch(seed_hosts): +def start_hostwatch(seed_hosts, auto_hosts): s1, s2 = socket.socketpair() pid = os.fork() if not pid: @@ -110,7 +110,7 @@ def start_hostwatch(seed_hosts): os.dup2(s1.fileno(), 1) os.dup2(s1.fileno(), 0) s1.close() - rv = hostwatch.hw_main(seed_hosts) or 0 + rv = hostwatch.hw_main(seed_hosts, auto_hosts) or 0 except Exception: log('%s\n' % _exc_dump()) rv = 98 @@ -227,7 +227,7 @@ class UdpProxy(Handler): self.mux.send(self.chan, ssnet.CMD_UDP_DATA, hdr + data) -def main(latency_control): +def main(latency_control, auto_hosts): debug1('Starting server with Python version %s\n' % platform.python_version()) @@ -277,7 +277,8 @@ def main(latency_control): def got_host_req(data): if not hw.pid: - (hw.pid, hw.sock) = start_hostwatch(data.strip().split()) + (hw.pid, hw.sock) = start_hostwatch( + data.strip().split(), auto_hosts) handlers.append(Handler(socks=[hw.sock], callback=hostwatch_ready)) mux.got_host_req = got_host_req