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

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