arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

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

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