Blame SOURCES/0131-lib-allow-creating-root-owned-problem-directories-fr.patch

5f7b57
From 41ec59db3e6e2f19adc128d8fbd4526976ee2ca2 Mon Sep 17 00:00:00 2001
5f7b57
From: Jakub Filak <jfilak@redhat.com>
5f7b57
Date: Thu, 23 Apr 2015 16:33:00 +0200
5f7b57
Subject: [LIBREPORT PATCH] lib: allow creating root owned problem directories
5f7b57
 from problem data
5f7b57
5f7b57
Without this patch libreport sets the owner of new problem directory
5f7b57
according to FILENAME_UID. This approach is not sufficient because ABRT
5f7b57
has introduced PrivateReports that should ensure that all problem
5f7b57
directories are owned by root. So ABRT needs a way to tell libreport to
5f7b57
create the new problem directory with uid=0.
5f7b57
5f7b57
Signed-off-by: Jakub Filak <jfilak@redhat.com>
5f7b57
---
5f7b57
 src/include/problem_data.h |  1 +
5f7b57
 src/lib/create_dump_dir.c  | 47 +++++++++++++++++++++++++++-------------------
5f7b57
 2 files changed, 29 insertions(+), 19 deletions(-)
5f7b57
5f7b57
diff --git a/src/include/problem_data.h b/src/include/problem_data.h
5f7b57
index 7a65d6c..02c945c 100644
5f7b57
--- a/src/include/problem_data.h
5f7b57
+++ b/src/include/problem_data.h
5f7b57
@@ -131,6 +131,7 @@ problem_data_t *create_problem_data_for_reporting(const char *dump_dir_name);
5f7b57
   @param base_dir_name Location to store the problem data
5f7b57
 */
5f7b57
 struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name);
5f7b57
+struct dump_dir *create_dump_dir_from_problem_data_ext(problem_data_t *problem_data, const char *base_dir_name, uid_t uid);
5f7b57
 
5f7b57
 #ifdef __cplusplus
5f7b57
 }
5f7b57
diff --git a/src/lib/create_dump_dir.c b/src/lib/create_dump_dir.c
5f7b57
index 989a50c..45c248d 100644
5f7b57
--- a/src/lib/create_dump_dir.c
5f7b57
+++ b/src/lib/create_dump_dir.c
5f7b57
@@ -30,7 +30,7 @@ static struct dump_dir *try_dd_create(const char *base_dir_name, const char *dir
5f7b57
     return dd;
5f7b57
 }
5f7b57
 
5f7b57
-struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name)
5f7b57
+struct dump_dir *create_dump_dir_from_problem_data_ext(problem_data_t *problem_data, const char *base_dir_name, uid_t uid)
5f7b57
 {
5f7b57
     INITIALIZE_LIBREPORT();
5f7b57
 
5f7b57
@@ -48,23 +48,8 @@ struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data,
5f7b57
         return NULL;
5f7b57
     }
5f7b57
 
5f7b57
-    uid_t uid = (uid_t)-1L;
5f7b57
-    char *uid_str = problem_data_get_content_or_NULL(problem_data, FILENAME_UID);
5f7b57
-
5f7b57
-    if (uid_str)
5f7b57
-    {
5f7b57
-        char *endptr;
5f7b57
-        errno = 0;
5f7b57
-        long val = strtol(uid_str, &endptr, 10);
5f7b57
-
5f7b57
-        if (errno != 0 || endptr == uid_str || *endptr != '\0' || INT_MAX < val)
5f7b57
-        {
5f7b57
-            error_msg(_("uid value is not valid: '%s'"), uid_str);
5f7b57
-            return NULL;
5f7b57
-        }
5f7b57
-
5f7b57
-        uid = (uid_t)val;
5f7b57
-    }
5f7b57
+    if (uid == (uid_t)-1L)
5f7b57
+        uid = 0;
5f7b57
 
5f7b57
     struct timeval tv;
5f7b57
     if (gettimeofday(&tv, NULL) < 0)
5f7b57
@@ -139,7 +124,8 @@ struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data,
5f7b57
      * reporting from anaconda where we can't read /etc/{system,redhat}-release
5f7b57
      * and os_release is taken from anaconda
5f7b57
      */
5f7b57
-    dd_create_basic_files(dd, uid, NULL);
5f7b57
+    const uid_t crashed_uid = problem_data_get_content_or_NULL(problem_data, FILENAME_UID) == NULL ? uid : /*uid already saved*/-1;
5f7b57
+    dd_create_basic_files(dd, crashed_uid, NULL);
5f7b57
 
5f7b57
     problem_id[strlen(problem_id) - strlen(NEW_PD_SUFFIX)] = '\0';
5f7b57
     char* new_path = concat_path_file(base_dir_name, problem_id);
5f7b57
@@ -150,3 +136,26 @@ struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data,
5f7b57
     free(problem_id);
5f7b57
     return dd;
5f7b57
 }
5f7b57
+
5f7b57
+struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name)
5f7b57
+{
5f7b57
+    uid_t uid = (uid_t)-1L;
5f7b57
+    char *uid_str = problem_data_get_content_or_NULL(problem_data, FILENAME_UID);
5f7b57
+
5f7b57
+    if (uid_str)
5f7b57
+    {
5f7b57
+        char *endptr;
5f7b57
+        errno = 0;
5f7b57
+        long val = strtol(uid_str, &endptr, 10);
5f7b57
+
5f7b57
+        if (errno != 0 || endptr == uid_str || *endptr != '\0' || INT_MAX < val)
5f7b57
+        {
5f7b57
+            error_msg(_("uid value is not valid: '%s'"), uid_str);
5f7b57
+            return NULL;
5f7b57
+        }
5f7b57
+
5f7b57
+        uid = (uid_t)val;
5f7b57
+    }
5f7b57
+
5f7b57
+    return create_dump_dir_from_problem_data_ext(problem_data, base_dir_name, uid);
5f7b57
+}
5f7b57
-- 
5f7b57
1.8.3.1
5f7b57