Blame SOURCES/0016-SSSCTL-don-t-require-root-for-analyze-cmd.patch

1c5238
From 66c318d212d56e26f303fc52d5fecbde4a6b9589 Mon Sep 17 00:00:00 2001
1c5238
From: Alexey Tikhonov <atikhono@redhat.com>
1c5238
Date: Thu, 10 Nov 2022 22:18:06 +0100
1c5238
Subject: [PATCH 16/16] SSSCTL: don't require 'root' for "analyze" cmd
1c5238
MIME-Version: 1.0
1c5238
Content-Type: text/plain; charset=UTF-8
1c5238
Content-Transfer-Encoding: 8bit
1c5238
1c5238
:relnote: `sssctl analyze` tool doesn't require anymore to be run under root.
1c5238
1c5238
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
1c5238
Reviewed-by: Justin Stephenson <jstephen@redhat.com>
1c5238
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
1c5238
(cherry picked from commit 99791400bec1054cf0081884e013a3cbed75fe8a)
1c5238
1c5238
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
1c5238
Reviewed-by: Justin Stephenson <jstephen@redhat.com>
1c5238
---
1c5238
 src/tools/common/sss_tools.c | 16 +++++++++-------
1c5238
 src/tools/common/sss_tools.h |  3 ++-
1c5238
 src/tools/sssctl/sssctl.c    |  2 +-
1c5238
 3 files changed, 12 insertions(+), 9 deletions(-)
1c5238
1c5238
diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c
1c5238
index 38ae88306..d16de7c4d 100644
1c5238
--- a/src/tools/common/sss_tools.c
1c5238
+++ b/src/tools/common/sss_tools.c
1c5238
@@ -267,6 +267,15 @@ static int tool_cmd_init(struct sss_tool_ctx *tool_ctx,
1c5238
                          struct sss_route_cmd *command)
1c5238
 {
1c5238
     int ret;
1c5238
+    uid_t uid;
1c5238
+
1c5238
+    if (!(command->flags & SSS_TOOL_FLAG_SKIP_ROOT_CHECK)) {
1c5238
+        uid = getuid();
1c5238
+        if (uid != 0) {
1c5238
+            ERROR("'%s' must be run as root\n", command->command);
1c5238
+            return EXIT_FAILURE;
1c5238
+        }
1c5238
+    }
1c5238
 
1c5238
     if (command->flags & SSS_TOOL_FLAG_SKIP_CMD_INIT) {
1c5238
         return EOK;
1c5238
@@ -515,15 +524,8 @@ int sss_tool_main(int argc, const char **argv,
1c5238
                   void *pvt)
1c5238
 {
1c5238
     struct sss_tool_ctx *tool_ctx;
1c5238
-    uid_t uid;
1c5238
     errno_t ret;
1c5238
 
1c5238
-    uid = getuid();
1c5238
-    if (uid != 0) {
1c5238
-        ERROR("%1$s must be run as root\n", argv[0]);
1c5238
-        return EXIT_FAILURE;
1c5238
-    }
1c5238
-
1c5238
     ret = sss_tool_init(NULL, &argc, argv, &tool_ctx);
1c5238
     if (ret != EOK) {
1c5238
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tool context\n");
1c5238
diff --git a/src/tools/common/sss_tools.h b/src/tools/common/sss_tools.h
1c5238
index 75dc15391..24dd4b559 100644
1c5238
--- a/src/tools/common/sss_tools.h
1c5238
+++ b/src/tools/common/sss_tools.h
1c5238
@@ -54,7 +54,8 @@ typedef errno_t
1c5238
 #define SSS_TOOL_DELIMITER(message) {"", _(message), 0, NULL, 0}
1c5238
 #define SSS_TOOL_LAST {NULL, NULL, 0, NULL, 0}
1c5238
 
1c5238
-#define SSS_TOOL_FLAG_SKIP_CMD_INIT 0x01
1c5238
+#define SSS_TOOL_FLAG_SKIP_CMD_INIT   0x01
1c5238
+#define SSS_TOOL_FLAG_SKIP_ROOT_CHECK 0x02
1c5238
 
1c5238
 struct sss_route_cmd {
1c5238
     const char *command;
1c5238
diff --git a/src/tools/sssctl/sssctl.c b/src/tools/sssctl/sssctl.c
1c5238
index f18689f9f..b73d19ffe 100644
1c5238
--- a/src/tools/sssctl/sssctl.c
1c5238
+++ b/src/tools/sssctl/sssctl.c
1c5238
@@ -296,7 +296,7 @@ int main(int argc, const char **argv)
1c5238
         SSS_TOOL_COMMAND("logs-remove", "Remove existing SSSD log files", 0, sssctl_logs_remove),
1c5238
         SSS_TOOL_COMMAND("logs-fetch", "Archive SSSD log files in tarball", 0, sssctl_logs_fetch),
1c5238
         SSS_TOOL_COMMAND("debug-level", "Change SSSD debug level", 0, sssctl_debug_level),
1c5238
-        SSS_TOOL_COMMAND_FLAGS("analyze", "Analyze logged data", 0, sssctl_analyze, SSS_TOOL_FLAG_SKIP_CMD_INIT),
1c5238
+        SSS_TOOL_COMMAND_FLAGS("analyze", "Analyze logged data", 0, sssctl_analyze, SSS_TOOL_FLAG_SKIP_CMD_INIT|SSS_TOOL_FLAG_SKIP_ROOT_CHECK),
1c5238
 #ifdef HAVE_LIBINI_CONFIG_V1_3
1c5238
         SSS_TOOL_DELIMITER("Configuration files tools:"),
1c5238
         SSS_TOOL_COMMAND_FLAGS("config-check", "Perform static analysis of SSSD configuration", 0, sssctl_config_check, SSS_TOOL_FLAG_SKIP_CMD_INIT),
1c5238
-- 
1c5238
2.37.3
1c5238