Ensure that qssh and qscp can be forcibly told to connect to a VM, instead of using the heuristic of the host name.

This commit is contained in:
Manuel Amador (Rudd-O) 2015-12-11 04:28:54 +00:00
parent 5af01dc496
commit 8e38ed73bb
2 changed files with 32 additions and 4 deletions

View File

@ -120,6 +120,14 @@ to communicate with said presumed VM. SaltStack's SSH-based `salt-ssh`
automator will pick these fake SSH and SCP clients based on the path, automator will pick these fake SSH and SCP clients based on the path,
and they will work transparently. and they will work transparently.
If the program `qssh` or `qscp` get a first and second parameters
`--vmname <VM>`, then it is assumed that the host name passed to
the command is irrelevant, and that you want to connect to the VM
specified by `<VM>`. If, in addition to that, you specify third
and fourth parameters `--management-proxy <M>`, then it is assumed
that you want to connect to the VM through the IP address of the
management proxy `<M>`.
Bug bounties Bug bounties
------------ ------------

View File

@ -12,6 +12,15 @@ def is_scp():
def find_scp_hostname(parms): def find_scp_hostname(parms):
overridden_host = None
if len(parms) > 1 and parms[0] == "--vmname":
overridden_host = parms[1]
parms = parms[2:]
if len(parms) > 1 and parms[0] == "--management-proxy":
proxy = parms[1]
parms = parms[2:]
overridden_host = overridden_host + ".__%s__" % proxy
overridden_host = overridden_host + ".__qubes__"
host = None host = None
while host is None: while host is None:
if parms[-1].startswith("-"): if parms[-1].startswith("-"):
@ -22,11 +31,22 @@ def find_scp_hostname(parms):
parms = parms[:-2] parms = parms[:-2]
host = parms[-1] host = parms[-1]
host, _ = host.split(":", 1) host, _ = host.split(":", 1)
return host if overridden_host:
parms[-1] = overridden_host + parms[-1][len(host):]
return overridden_host if overridden_host else host, parms
def find_hostname_and_command(parms): def find_hostname_and_command(parms):
host = None host = None
overridden_host = None
if len(parms) > 1 and parms[0] == "--vmname":
overridden_host = parms[1]
parms = parms[2:]
if len(parms) > 1 and parms[0] == "--management-proxy":
proxy = parms[1]
parms = parms[2:]
overridden_host = overridden_host + ".__%s__" % proxy
overridden_host = overridden_host + ".__qubes__"
rest = parms rest = parms
while True: while True:
if not rest: if not rest:
@ -49,7 +69,7 @@ def find_hostname_and_command(parms):
else: else:
break break
host, port = urllib.splitport(host) host, port = urllib.splitport(host)
return host, rest return overridden_host if overridden_host else host, rest
def is_qubes_host(host): def is_qubes_host(host):
@ -71,14 +91,14 @@ parms = sys.argv[1:]
# SCP execution path. # SCP execution path.
if is_scp(): if is_scp():
host = find_scp_hostname(parms) host, rest = find_scp_hostname(parms)
if not is_qubes_host(host): if not is_qubes_host(host):
os.execv("/usr/bin/scp", ["/usr/bin/scp"] + parms) os.execv("/usr/bin/scp", ["/usr/bin/scp"] + parms)
path_to_this_file = os.path.dirname(__file__) path_to_this_file = os.path.dirname(__file__)
path_to_ssh = os.path.join(path_to_this_file, "qssh") path_to_ssh = os.path.join(path_to_this_file, "qssh")
scmd = ["/usr/bin/scp"] + ["-S", path_to_ssh] + parms scmd = ["/usr/bin/scp"] + ["-S", path_to_ssh] + rest
os.execvp(scmd[0], scmd) os.execvp(scmd[0], scmd)
host, rest = find_hostname_and_command(parms) host, rest = find_hostname_and_command(parms)