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

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