Blame 0143-cli-enable-authetication-for-all-commands.patch

69165ba
From 7fc5bd1851d9b1b3f18eb8037432edbd7f7b7e66 Mon Sep 17 00:00:00 2001
69165ba
From: Jakub Filak <jfilak@redhat.com>
69165ba
Date: Wed, 8 Jul 2015 14:16:39 +0200
69165ba
Subject: [PATCH] cli: enable authetication for all commands
69165ba
69165ba
I forgot to test the info, rm and status commands when I was working on
69165ba
commit cb770e507f247476651b84ebbef63a5cd4c41d11 and later on I found out
69165ba
that these commands must be updated to work with the system problems.
69165ba
69165ba
Related: #1224984
69165ba
69165ba
Signed-off-by: Jakub Filak <jfilak@redhat.com>
69165ba
---
69165ba
 src/cli/list.c   |  2 +-
69165ba
 src/cli/rm.c     | 41 ++++++++++++++++++++++++++++-------------
69165ba
 src/cli/status.c |  3 ++-
69165ba
 3 files changed, 31 insertions(+), 15 deletions(-)
69165ba
69165ba
diff --git a/src/cli/list.c b/src/cli/list.c
69165ba
index 483e9de..909d36d 100644
69165ba
--- a/src/cli/list.c
69165ba
+++ b/src/cli/list.c
69165ba
@@ -35,7 +35,7 @@ static problem_data_t *load_problem_data(const char *problem_id)
69165ba
     char *name2 = NULL;
69165ba
 
69165ba
     /* First, check if there is a problem with the passed id */
69165ba
-    GList *problems = get_problems_over_dbus(/*don't authorize*/false);
69165ba
+    GList *problems = get_problems_over_dbus(g_cli_authenticate);
69165ba
     GList *item = g_list_find_custom(problems, problem_id, (GCompareFunc)strcmp);
69165ba
 
69165ba
     /* (git requires at least 5 char hash prefix, we do the same) */
69165ba
diff --git a/src/cli/rm.c b/src/cli/rm.c
69165ba
index fe458ff..37d50e2 100644
69165ba
--- a/src/cli/rm.c
69165ba
+++ b/src/cli/rm.c
69165ba
@@ -19,12 +19,39 @@
69165ba
 
69165ba
 #include "libabrt.h"
69165ba
 #include "builtin-cmd.h"
69165ba
+#include "abrt-cli-core.h"
69165ba
 
69165ba
 /* TODO npajkovs:
69165ba
  *   add -n, --dry-run
69165ba
  *   add -q, --quite
69165ba
  */
69165ba
 
69165ba
+static int remove_using_dbus(const char **dirs_strv)
69165ba
+{
69165ba
+    GList *dirs = NULL;
69165ba
+    while (*dirs_strv)
69165ba
+        dirs = g_list_prepend(dirs, (void *)*dirs_strv++);
69165ba
+    const int ret = delete_problem_dirs_over_dbus(dirs);
69165ba
+    g_list_free(dirs);
69165ba
+    return ret;
69165ba
+}
69165ba
+
69165ba
+static int remove_using_abrtd_or_fs(const char **dirs_strv)
69165ba
+{
69165ba
+    int errs = 0;
69165ba
+    while (*dirs_strv)
69165ba
+    {
69165ba
+        int status;
69165ba
+        const char *rm_dir = *dirs_strv++;
69165ba
+        status = delete_dump_dir_possibly_using_abrtd(rm_dir);
69165ba
+        if (!status)
69165ba
+            log("rm '%s'", rm_dir);
69165ba
+        else
69165ba
+            errs++;
69165ba
+    }
69165ba
+    return errs;
69165ba
+}
69165ba
+
69165ba
 int cmd_remove(int argc, const char **argv)
69165ba
 {
69165ba
     const char *program_usage_string = _(
69165ba
@@ -42,17 +69,5 @@ int cmd_remove(int argc, const char **argv)
69165ba
     if (!argv[0])
69165ba
         show_usage_and_die(program_usage_string, program_options);
69165ba
 
69165ba
-    int errs = 0;
69165ba
-    while (*argv)
69165ba
-    {
69165ba
-        int status;
69165ba
-        const char *rm_dir = *argv++;
69165ba
-        status = delete_dump_dir_possibly_using_abrtd(rm_dir);
69165ba
-        if (!status)
69165ba
-            log("rm '%s'", rm_dir);
69165ba
-        else
69165ba
-            errs++;
69165ba
-    }
69165ba
-
69165ba
-    return errs;
69165ba
+    return (g_cli_authenticate ? remove_using_dbus : remove_using_abrtd_or_fs)(argv);
69165ba
 }
69165ba
diff --git a/src/cli/status.c b/src/cli/status.c
69165ba
index a65ba05..0635289 100644
69165ba
--- a/src/cli/status.c
69165ba
+++ b/src/cli/status.c
69165ba
@@ -20,12 +20,13 @@
69165ba
 #include <unistd.h>
69165ba
 #include <sys/types.h>
69165ba
 #include "problem_api.h"
69165ba
+#include "abrt-cli-core.h"
69165ba
 
69165ba
 static unsigned int count_problem_dirs(unsigned long since)
69165ba
 {
69165ba
     unsigned count = 0;
69165ba
 
69165ba
-    GList *problems = get_problems_over_dbus(/*don't authorize*/false);
69165ba
+    GList *problems = get_problems_over_dbus(g_cli_authenticate);
69165ba
     for (GList *iter = problems; iter != NULL; iter = g_list_next(iter))
69165ba
     {
69165ba
         const char *problem_id = (const char *)iter->data;
69165ba
-- 
69165ba
2.4.3
69165ba