Blame SOURCES/bz1725183-01-fix-and-options-for-non-root-users.patch

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