ssh kitten: Mimic behavior of ssh more closely
Execute any command specified on the command line via the users' shell on the remote side just as ssh does Fixes #3638
This commit is contained in:
parent
0a742ea8d0
commit
cf88eb9d60
@ -59,6 +59,10 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
|||||||
- Add an option :option:`kitty @ get-text --add-wrap-markers` to add line wrap
|
- Add an option :option:`kitty @ get-text --add-wrap-markers` to add line wrap
|
||||||
markers to the output (:pull:`3633`)
|
markers to the output (:pull:`3633`)
|
||||||
|
|
||||||
|
- ssh kitten: Mimic behavior of ssh command line client more closely by
|
||||||
|
executing any command specified on the command line via the users' shell
|
||||||
|
just as ssh does (:iss:`3638`)
|
||||||
|
|
||||||
|
|
||||||
0.20.3 [2021-05-06]
|
0.20.3 [2021-05-06]
|
||||||
----------------------
|
----------------------
|
||||||
|
|||||||
@ -26,8 +26,8 @@ rc=$?
|
|||||||
rm $tmp
|
rm $tmp
|
||||||
if [ "$rc" != "0" ]; then echo "$tic_out"; exit 1; fi
|
if [ "$rc" != "0" ]; then echo "$tic_out"; exit 1; fi
|
||||||
if [ -z "$USER" ]; then export USER=$(whoami); fi
|
if [ -z "$USER" ]; then export USER=$(whoami); fi
|
||||||
EXEC_CMD
|
|
||||||
shell_name=$(basename $0)
|
shell_name=$(basename $0)
|
||||||
|
EXEC_CMD
|
||||||
|
|
||||||
# We need to pass the first argument to the executed program with a leading -
|
# We need to pass the first argument to the executed program with a leading -
|
||||||
# to make sure the shell executes as a login shell. Note that not all shells
|
# to make sure the shell executes as a login shell. Note that not all shells
|
||||||
@ -41,7 +41,6 @@ case "dash" in
|
|||||||
exec $python -c "import os; os.execlp('$0', '-' '$shell_name')"
|
exec $python -c "import os; os.execlp('$0', '-' '$shell_name')"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
exec -a "-$shell_name" "$0"
|
exec -a "-$shell_name" "$0"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@ -62,13 +61,13 @@ with NamedTemporaryFile() as tmp:
|
|||||||
getattr(sys.stderr, 'buffer', sys.stderr).write(stdout + stderr)
|
getattr(sys.stderr, 'buffer', sys.stderr).write(stdout + stderr)
|
||||||
raise SystemExit('Failed to compile terminfo using tic')
|
raise SystemExit('Failed to compile terminfo using tic')
|
||||||
command_to_execute = json.loads(binascii.unhexlify('{command_to_execute}'))
|
command_to_execute = json.loads(binascii.unhexlify('{command_to_execute}'))
|
||||||
if command_to_execute:
|
|
||||||
os.execlp(command_to_execute[0], *command_to_execute)
|
|
||||||
try:
|
try:
|
||||||
shell_path = pwd.getpwuid(os.geteuid()).pw_shell or '/bin/sh'
|
shell_path = pwd.getpwuid(os.geteuid()).pw_shell or '/bin/sh'
|
||||||
except KeyError:
|
except KeyError:
|
||||||
shell_path = '/bin/sh'
|
shell_path = '/bin/sh'
|
||||||
shell_name = '-' + os.path.basename(shell_path)
|
shell_name = '-' + os.path.basename(shell_path)
|
||||||
|
if command_to_execute:
|
||||||
|
os.execlp(shell_path, shell_path, '-c', command_to_execute)
|
||||||
os.execlp(shell_path, shell_name)
|
os.execlp(shell_path, shell_name)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@ -179,11 +178,13 @@ def quote(x: str) -> str:
|
|||||||
|
|
||||||
def get_posix_cmd(terminfo: str, remote_args: List[str]) -> List[str]:
|
def get_posix_cmd(terminfo: str, remote_args: List[str]) -> List[str]:
|
||||||
sh_script = SHELL_SCRIPT.replace('TERMINFO', terminfo, 1)
|
sh_script = SHELL_SCRIPT.replace('TERMINFO', terminfo, 1)
|
||||||
|
command_to_execute = ''
|
||||||
if remote_args:
|
if remote_args:
|
||||||
command_to_executeg = (quote(c) for c in remote_args)
|
# ssh simply concatenates multiple commands using a space see
|
||||||
command_to_execute = 'exec ' + ' '.join(command_to_executeg)
|
# line 1129 of ssh.c and on the remote side sshd.c runs the
|
||||||
else:
|
# concatenated command as shell -c cmd
|
||||||
command_to_execute = ''
|
args = [c.replace("'", """'"'"'""") for c in remote_args]
|
||||||
|
command_to_execute = "exec $0 -c '{}'".format(' '.join(args))
|
||||||
sh_script = sh_script.replace('EXEC_CMD', command_to_execute)
|
sh_script = sh_script.replace('EXEC_CMD', command_to_execute)
|
||||||
return [sh_script] + remote_args
|
return [sh_script] + remote_args
|
||||||
|
|
||||||
@ -192,7 +193,7 @@ def get_python_cmd(terminfo: str, command_to_execute: List[str]) -> List[str]:
|
|||||||
import json
|
import json
|
||||||
script = PYTHON_SCRIPT.format(
|
script = PYTHON_SCRIPT.format(
|
||||||
terminfo=terminfo.encode('utf-8').hex(),
|
terminfo=terminfo.encode('utf-8').hex(),
|
||||||
command_to_execute=json.dumps(command_to_execute).encode('utf-8').hex()
|
command_to_execute=json.dumps(' '.join(command_to_execute)).encode('utf-8').hex()
|
||||||
)
|
)
|
||||||
return [f'python -c "{script}"']
|
return [f'python -c "{script}"']
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user