From b667913a72f9516e3c9ae1452784874ff01a7688 Mon Sep 17 00:00:00 2001 From: Tomas Jelinek Date: Tue, 2 Jul 2019 13:35:58 +0200 Subject: [PATCH] fix - and -- options for non-root users --- pcs/app.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pcs/app.py b/pcs/app.py index abb9277e..c13cb15c 100644 --- a/pcs/app.py +++ b/pcs/app.py @@ -37,12 +37,21 @@ from pcs.cli.routing import ( from pcs.lib.errors import LibraryError -def non_root_run(argv_cmd): +def _non_root_run(argv_cmd): """ This function will run commands which has to be run as root for users which are not root. If it required to run such command as root it will do that by sending it to the local pcsd and then it will exit. """ + # matching the commands both in here and in pcsd expects -o and --options + # to be at the end of a command + argv_and_options = argv_cmd[:] + for option, value in utils.pcs_options.items(): + if parse_args.is_option_expecting_value(option): + argv_and_options.extend([option, value]) + else: + argv_and_options.append(option) + # specific commands need to be run under root account, pass them to pcsd # don't forget to allow each command in pcsd.rb in "post /run_pcs do" root_command_list = [ @@ -67,29 +76,29 @@ def non_root_run(argv_cmd): ['status', 'quorum', '...'], ['status', 'pcsd', '...'], ] - orig_argv = argv_cmd[:] + for root_cmd in root_command_list: if ( - (argv_cmd == root_cmd) + (argv_and_options == root_cmd) or ( root_cmd[-1] == "..." and - argv_cmd[:len(root_cmd)-1] == root_cmd[:-1] + argv_and_options[:len(root_cmd)-1] == root_cmd[:-1] ) ): # handle interactivity of 'pcs cluster auth' - if argv_cmd[0:2] in [["cluster", "auth"], ["host", "auth"]]: + if argv_and_options[0:2] in [["cluster", "auth"], ["host", "auth"]]: if "-u" not in utils.pcs_options: username = utils.get_terminal_input('Username: ') - orig_argv.extend(["-u", username]) + argv_and_options.extend(["-u", username]) if "-p" not in utils.pcs_options: password = utils.get_terminal_password() - orig_argv.extend(["-p", password]) + argv_and_options.extend(["-p", password]) # call the local pcsd err_msgs, exitcode, std_out, std_err = utils.call_local_pcsd( - orig_argv + argv_and_options ) if err_msgs: for msg in err_msgs: @@ -105,7 +114,10 @@ logging.basicConfig() usefile = False filename = "" def main(argv=None): - # pylint: disable=too-many-locals, too-many-branches, too-many-statements, global-statement + # pylint: disable=global-statement + # pylint: disable=too-many-branches + # pylint: disable=too-many-locals + # pylint: disable=too-many-statements if completion.has_applicable_environment(os.environ): print(completion.make_suggestions( os.environ, @@ -207,7 +219,7 @@ def main(argv=None): logger.handlers = [] if (os.getuid() != 0) and (argv and argv[0] != "help") and not usefile: - non_root_run(argv) + _non_root_run(argv) cmd_map = { "resource": resource.resource_cmd, "cluster": cluster.cluster_cmd, -- 2.21.0