From 32b4defa9b55ba8a214373a408ef6b42c9a58414 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 9 Nov 2010 00:17:01 -0800 Subject: [PATCH] Add a new --ssh-cmd= option to let you override the ssh command. Requested by Axel Beckert. --- client.py | 9 +++++---- main.py | 4 +++- ssh.py | 10 ++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/client.py b/client.py index 167d4ca..0301ca0 100644 --- a/client.py +++ b/client.py @@ -98,7 +98,7 @@ class FirewallClient: raise Fatal('cleanup: %r returned %d' % (self.argv, rv)) -def _main(listener, fw, remotename, python, seed_hosts, auto_nets): +def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets): handlers = [] if helpers.verbose >= 1: helpers.logprefix = 'c : ' @@ -106,7 +106,7 @@ def _main(listener, fw, remotename, python, seed_hosts, auto_nets): helpers.logprefix = 'client: ' debug1('connecting to server...\n') try: - (serverproc, serversock) = ssh.connect(remotename, python) + (serverproc, serversock) = ssh.connect(ssh_cmd, remotename, python) except socket.error, e: if e.errno == errno.EPIPE: raise Fatal("failed to establish ssh session") @@ -181,7 +181,7 @@ def _main(listener, fw, remotename, python, seed_hosts, auto_nets): mux.check_fullness() -def main(listenip, remotename, python, seed_hosts, auto_nets, +def main(listenip, ssh_cmd, remotename, python, seed_hosts, auto_nets, subnets_include, subnets_exclude): debug1('Starting sshuttle proxy.\n') listener = socket.socket() @@ -212,6 +212,7 @@ def main(listenip, remotename, python, seed_hosts, auto_nets, fw = FirewallClient(listenip[1], subnets_include, subnets_exclude) try: - return _main(listener, fw, remotename, python, seed_hosts, auto_nets) + return _main(listener, fw, ssh_cmd, remotename, + python, seed_hosts, auto_nets) finally: fw.done() diff --git a/main.py b/main.py index bc0ddd3..eab4e5b 100755 --- a/main.py +++ b/main.py @@ -56,6 +56,7 @@ python= specify the name/path of the python interpreter on the remote server [py r,remote= ssh hostname (and optional username) of remote sshuttle server x,exclude= exclude this subnet (can be used more than once) v,verbose increase debug message verbosity +e,ssh-cmd= the command to use to connect to the remote [ssh] seed-hosts= with -H, use these hostnames for initial scan (comma-separated) server (internal use only) firewall (internal use only) @@ -97,8 +98,9 @@ try: else: sh = None sys.exit(client.main(parse_ipport(opt.listen or '0.0.0.0:0'), + opt.ssh_cmd, remotename, - (opt.python or "python"), + opt.python, sh, opt.auto_nets, parse_subnets(includes), diff --git a/ssh.py b/ssh.py index a222bf3..df3a537 100644 --- a/ssh.py +++ b/ssh.py @@ -21,7 +21,7 @@ def empackage(z, filename): return '%s\n%d\n%s' % (basename,len(content), content) -def connect(rhostport, python): +def connect(ssh_cmd, rhostport, python): main_exe = sys.argv[0] l = (rhostport or '').split(':', 1) rhost = l[0] @@ -53,7 +53,13 @@ def connect(rhostport, python): if not rhost: argv = [python, '-c', pyscript] else: - argv = ['ssh'] + portl + [rhost, '--', "'%s' -c '%s'" % (python, pyscript)] + if ssh_cmd: + sshl = ssh_cmd.split(' ') + else: + sshl = ['ssh'] + argv = (sshl + + portl + + [rhost, '--', "'%s' -c '%s'" % (python, pyscript)]) (s1,s2) = socket.socketpair() def setup(): # runs in the child process