Blame 0135-cli-chown-before-reporting.patch

69165ba
From 5e288cf2d54f6b3e67745f71db836f37901d2ad5 Mon Sep 17 00:00:00 2001
69165ba
From: Jakub Filak <jfilak@redhat.com>
69165ba
Date: Wed, 3 Jun 2015 05:40:41 +0200
69165ba
Subject: [PATCH] cli: chown before reporting
69165ba
69165ba
User must have write access to the reported directory to be able to
69165ba
report it but abrt-dbus allows the user to read data of problems that
69165ba
belongs to him which may not be accessible in file system.
69165ba
69165ba
The GUI does the same and make sures the user can write to the reported
69165ba
directory by chowning it before reporting.
69165ba
69165ba
Related: #1224984
69165ba
69165ba
Signed-off-by: Jakub Filak <jfilak@redhat.com>
69165ba
---
69165ba
 src/cli/abrt-cli-core.c |  5 +++++
69165ba
 src/cli/abrt-cli-core.h |  3 +++
69165ba
 src/cli/report.c        | 24 +++++++++++++++---------
69165ba
 3 files changed, 23 insertions(+), 9 deletions(-)
69165ba
69165ba
diff --git a/src/cli/abrt-cli-core.c b/src/cli/abrt-cli-core.c
69165ba
index 77a37f7..46acd01 100644
69165ba
--- a/src/cli/abrt-cli-core.c
69165ba
+++ b/src/cli/abrt-cli-core.c
69165ba
@@ -107,3 +107,8 @@ char *hash2dirname(const char *hash)
69165ba
 
69165ba
     return found_name;
69165ba
 }
69165ba
+
69165ba
+char *hash2dirname_if_necessary(const char *input)
69165ba
+{
69165ba
+    return isxdigit_str(input) ? hash2dirname(input) : xstrdup(input);
69165ba
+}
69165ba
diff --git a/src/cli/abrt-cli-core.h b/src/cli/abrt-cli-core.h
69165ba
index 33b2ea6..d69d463 100644
69165ba
--- a/src/cli/abrt-cli-core.h
69165ba
+++ b/src/cli/abrt-cli-core.h
69165ba
@@ -34,6 +34,9 @@ vector_of_problem_data_t *fetch_crash_infos(void);
69165ba
 char *find_problem_by_hash(const char *hash, GList *problems);
69165ba
 /* Returns malloced string, or NULL if not found: */
69165ba
 char *hash2dirname(const char *hash);
69165ba
+/* If input looks like a hash, returns malloced string, or NULL if not found.
69165ba
+ * Otherwise returns a copy of the input. */
69165ba
+char *hash2dirname_if_necessary(const char *input);
69165ba
 
69165ba
 
69165ba
 #endif /* ABRT_CLI_CORE_H_ */
69165ba
diff --git a/src/cli/report.c b/src/cli/report.c
69165ba
index 33d8b44..6af9769 100644
69165ba
--- a/src/cli/report.c
69165ba
+++ b/src/cli/report.c
69165ba
@@ -53,26 +53,32 @@ int cmd_report(int argc, const char **argv)
69165ba
     while (*argv)
69165ba
     {
69165ba
         const char *dir_name = *argv++;
69165ba
+        char *const real_problem_id = hash2dirname_if_necessary(dir_name);
69165ba
+        if (real_problem_id == NULL)
69165ba
+        {
69165ba
+            error_msg(_("Can't find problem '%s'"), dir_name);
69165ba
+            continue;
69165ba
+        }
69165ba
 
69165ba
-        char *free_me = NULL;
69165ba
-        if (access(dir_name, F_OK) != 0 && errno == ENOENT)
69165ba
+        const int res = chown_dir_over_dbus(real_problem_id);
69165ba
+        if (res != 0)
69165ba
         {
69165ba
-            free_me = hash2dirname(dir_name);
69165ba
-            if (free_me)
69165ba
-                dir_name = free_me;
69165ba
+            error_msg(_("Can't take ownership of '%s'"), real_problem_id);
69165ba
+            free(real_problem_id);
69165ba
+            continue;
69165ba
         }
69165ba
-        int status = report_problem_in_dir(dir_name,
69165ba
+        int status = report_problem_in_dir(real_problem_id,
69165ba
                                              LIBREPORT_WAIT
69165ba
                                            | LIBREPORT_RUN_CLI);
69165ba
 
69165ba
         /* the problem was successfully reported and option is -d */
69165ba
         if((opts & OPT_d) && (status == 0 || status == EXIT_STOP_EVENT_RUN))
69165ba
         {
69165ba
-            log(_("Deleting '%s'"), dir_name);
69165ba
-            delete_dump_dir_possibly_using_abrtd(dir_name);
69165ba
+            log(_("Deleting '%s'"), real_problem_id);
69165ba
+            delete_dump_dir_possibly_using_abrtd(real_problem_id);
69165ba
         }
69165ba
 
69165ba
-        free(free_me);
69165ba
+        free(real_problem_id);
69165ba
 
69165ba
         if (status)
69165ba
             exit(status);
69165ba
-- 
69165ba
2.4.3
69165ba