(ssh_cmd, rhostport, python, stderr, add_cmd_delimiter, remote_shell, options)
| 85 | |
| 86 | |
| 87 | def connect(ssh_cmd, rhostport, python, stderr, add_cmd_delimiter, remote_shell, options): |
| 88 | username, password, port, host = parse_hostport(rhostport) |
| 89 | if username: |
| 90 | rhost = "{}@{}".format(username, host) |
| 91 | else: |
| 92 | rhost = host |
| 93 | |
| 94 | z = zlib.compressobj(1) |
| 95 | content = get_module_source('sshuttle.assembler') |
| 96 | optdata = ''.join("%s=%r\n" % (k, v) for (k, v) in list(options.items())) |
| 97 | optdata = optdata.encode("UTF8") |
| 98 | content2 = (empackage(z, 'sshuttle') + |
| 99 | empackage(z, 'sshuttle.cmdline_options', optdata) + |
| 100 | empackage(z, 'sshuttle.helpers') + |
| 101 | empackage(z, 'sshuttle.ssnet') + |
| 102 | empackage(z, 'sshuttle.hostwatch') + |
| 103 | empackage(z, 'sshuttle.server') + |
| 104 | b"\n") |
| 105 | |
| 106 | # If the exec() program calls sys.exit(), it should exit python |
| 107 | # and the sys.exit(98) call won't be reached (so we try to only |
| 108 | # exit that way in the server). However, if the code that we |
| 109 | # exec() simply returns from main, then we will return from |
| 110 | # exec(). If the server's python process dies, it should stop |
| 111 | # executing and also won't reach sys.exit(98). |
| 112 | # |
| 113 | # So, we shouldn't reach sys.exit(98) and we certainly shouldn't |
| 114 | # reach it immediately after trying to start the server. |
| 115 | pyscript = r""" |
| 116 | import sys, os; |
| 117 | verbosity=%d; |
| 118 | stdin = os.fdopen(0, 'rb'); |
| 119 | exec(compile(stdin.read(%d), 'assembler.py', 'exec')); |
| 120 | sys.exit(98); |
| 121 | """ % (helpers.verbose or 0, len(content)) |
| 122 | pyscript = re.sub(r'\s+', ' ', pyscript.strip()) |
| 123 | |
| 124 | if not rhost: |
| 125 | # ignore the --python argument when running locally; we already know |
| 126 | # which python version works. |
| 127 | argv = [sys.executable, '-c', pyscript] |
| 128 | else: |
| 129 | if ssh_cmd: |
| 130 | sshl = shlex.split(ssh_cmd) |
| 131 | else: |
| 132 | sshl = ['ssh'] |
| 133 | if port is not None: |
| 134 | portl = ["-p", str(port)] |
| 135 | else: |
| 136 | portl = [] |
| 137 | if remote_shell == "cmd": |
| 138 | pycmd = '"%s" -c "%s"' % (python or 'python', pyscript) |
| 139 | elif remote_shell == "powershell": |
| 140 | for c in ('\'', ' ', ';', '(', ')', ','): |
| 141 | pyscript = pyscript.replace(c, '`' + c) |
| 142 | pycmd = '%s -c %s' % (python or 'python', pyscript) |
| 143 | else: # posix shell expected |
| 144 | if python: |
nothing calls this directly
no test coverage detected