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

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