mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-19 04:18:23 +01:00
ssh.py: support finding sshuttle in "$HOME/.../sshuttle"
If you ran sshuttle from /home/apenwarr/sshuttle/sshuttle, we would automatically add /home/apenwarr/sshuttle to the PATH before trying to execute sshuttle on the remote machine. That way, if you install it in the same place on two computers, the client would still be able to start the server. Someone reported, though, that if they installed the client in /home/apenwarr/sshuttle/shuttle, and the server in /root/sshuttle/sshuttle, then used "-r root@servername", it wasn't able to find the program. Similar problems would happen if you're apenwarr at home and averyp at work. So what we now do is add *two* directories to the PATH: /home/apenwarr/sshuttle and $HOME/sshuttle, where $HOME is the value of $HOME on the *server*, not the client. So it'll find it in either place.
This commit is contained in:
parent
a5fc93c841
commit
4a462258f5
15
ssh.py
15
ssh.py
@ -1,10 +1,16 @@
|
|||||||
import sys, os, re, subprocess, socket
|
import sys, os, re, subprocess, socket
|
||||||
import helpers
|
import helpers
|
||||||
|
from helpers import *
|
||||||
|
|
||||||
def connect(rhost):
|
def connect(rhost):
|
||||||
main_exe = sys.argv[0]
|
main_exe = sys.argv[0]
|
||||||
nicedir = os.path.split(os.path.abspath(main_exe))[0]
|
nicedir = os.path.split(os.path.abspath(main_exe))[0]
|
||||||
nicedir = re.sub(r':', "_", nicedir)
|
nicedir = re.sub(r':', "_", nicedir)
|
||||||
|
myhome = os.path.expanduser('~') + '/'
|
||||||
|
if nicedir.startswith(myhome):
|
||||||
|
nicedir2 = nicedir[len(myhome):]
|
||||||
|
else:
|
||||||
|
nicedir2 = nicedir
|
||||||
if rhost == '-':
|
if rhost == '-':
|
||||||
rhost = None
|
rhost = None
|
||||||
if not rhost:
|
if not rhost:
|
||||||
@ -17,11 +23,14 @@ def connect(rhost):
|
|||||||
# can't exec *safely* using argv, because *both* ssh and 'sh -c'
|
# can't exec *safely* using argv, because *both* ssh and 'sh -c'
|
||||||
# allow shellquoting. So we end up having to double-shellquote
|
# allow shellquoting. So we end up having to double-shellquote
|
||||||
# stuff here.
|
# stuff here.
|
||||||
escapedir = re.sub(r'([^\w/])', r'\\\\\\\1', nicedir)
|
escapedir = re.sub(r'([^\w/])', r'\\\\\\\1', nicedir)
|
||||||
|
escapedir2 = re.sub(r'([^\w/])', r'\\\\\\\1', nicedir2)
|
||||||
cmd = r"""
|
cmd = r"""
|
||||||
sh -c PATH=%s:'$PATH exec sshuttle --server%s'
|
sh -c PATH=%s:'$HOME'/%s:'$PATH exec sshuttle --server%s'
|
||||||
""" % (escapedir, ' -v' * (helpers.verbose or 0))
|
""" % (escapedir, escapedir2,
|
||||||
|
' -v' * (helpers.verbose or 0))
|
||||||
argv = ['ssh', rhost, '--', cmd.strip()]
|
argv = ['ssh', rhost, '--', cmd.strip()]
|
||||||
|
debug2('executing: %r\n' % argv)
|
||||||
(s1,s2) = socket.socketpair()
|
(s1,s2) = socket.socketpair()
|
||||||
def setup():
|
def setup():
|
||||||
# runs in the child process
|
# runs in the child process
|
||||||
|
Loading…
Reference in New Issue
Block a user