doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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