From 12c99741a00fe3fbe38b7ad656a1e2261a1fdce1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 11 Aug 2022 07:35:18 +0530 Subject: [PATCH] Add an example of restricting the launch command --- docs/remote-control.rst | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/docs/remote-control.rst b/docs/remote-control.rst index 4452749c7..1bd95d3dd 100644 --- a/docs/remote-control.rst +++ b/docs/remote-control.rst @@ -237,15 +237,26 @@ as shown below: .. code-block:: py - def is_cmd_allowed(pcmd, window, from_socket, extra_data): - cmd_name = pcmd['cmd'] # the name of the command - cmd_payload = pcmd['payload'] # the arguments to the command - # examine the cmd_name and cmd_payload and return True to allow - # the command or False to disallow it. Return None to have no - # effect on the command. + def is_cmd_allowed(pcmd, window, from_socket, extra_data): + cmd_name = pcmd['cmd'] # the name of the command + cmd_payload = pcmd['payload'] # the arguments to the command + # examine the cmd_name and cmd_payload and return True to allow + # the command or False to disallow it. Return None to have no + # effect on the command. + + # The command payload will vary from command to command, see + # the rc protocol docs for details. Below is an example of + # restricting the launch command to allow only running the + # default shell. + + if cmd_name != 'launch': + return None + if cmd_payload.get('args') or cmd_payload.get('env') or cmd_payload.get('copy_cmdline') or cmd_payload.get('copy_env'): + return False + # prints in this function go to the parent kitty process STDOUT + print('Allowing launch command:', cmd_payload) + return True - # The command payload will vary from command to command, see - # the rc protocol docs for details. .. _rc_mapping: