Only use the last line of ssh hostname -f output incase the user has configured ssh to print random junk on login

This commit is contained in:
Kovid Goyal 2021-05-07 11:42:52 +05:30
parent eced40a761
commit f110a01ffe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -151,7 +151,7 @@ def check_hostname_matches(self) -> bool:
cp = subprocess.run(self.batch_cmd_prefix + [self.conn_data.hostname, 'hostname', '-f'], stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL)
if cp.returncode == 0:
q = cp.stdout.decode('utf-8').strip()
q = tuple(filter(None, cp.stdout.decode('utf-8').strip().splitlines()))[-1]
if not hostname_matches(self.cli_opts.hostname or '', q):
print(reset_terminal(), end='')
print(f'The remote hostname {styled(q, fg="green")} does not match the')