ssh kitten: match hostnames against both remote hostname and hostname used on the command line to connect to it

This commit is contained in:
Kovid Goyal
2022-03-07 20:32:02 +05:30
parent d037c0b0fc
commit 855718b179
6 changed files with 34 additions and 25 deletions

View File

@@ -24,11 +24,11 @@ def host_matches(pat: str, hostname: str, username: str) -> bool:
return fnmatch.fnmatchcase(hostname, pat) and fnmatch.fnmatchcase(username, upat)
def options_for_host(hostname: str, username: str, per_host_opts: Dict[str, SSHOptions]) -> SSHOptions:
def options_for_host(hostname: str, username: str, per_host_opts: Dict[str, SSHOptions], cli_hostname: str = '', cli_uname: str = '') -> SSHOptions:
matches = []
for spat, opts in per_host_opts.items():
for pat in spat.split():
if host_matches(pat, hostname, username):
if host_matches(pat, hostname, username) or (cli_hostname and host_matches(pat, cli_hostname, cli_uname)):
matches.append(opts)
if not matches:
return SSHOptions({})