doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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