Blame SOURCES/0128-dump_dir-allow-hooks-to-create-dump-directory-withou.patch

4b6aa8
From e76a8655152129de09bd9521ade8158bb07cc8fe Mon Sep 17 00:00:00 2001
4b6aa8
From: Jakub Filak <jfilak@redhat.com>
4b6aa8
Date: Wed, 15 Apr 2015 17:41:49 +0200
4b6aa8
Subject: [LIBREPORT PATCH] dump_dir: allow hooks to create dump directory
4b6aa8
 without parents
4b6aa8
4b6aa8
With a centralized model of handling problems like ABRT, there is a need
4b6aa8
to ensure that every dump directory is a descendant of some central
4b6aa8
directory (database). This commit together with other security commits
4b6aa8
makes code of the tools creating the dump directories in the central
4b6aa8
directory more robust by ensuring that no tool accidentally creates the
4b6aa8
central directory and all tools creates exactly one directory.
4b6aa8
4b6aa8
Related: #1211835
4b6aa8
4b6aa8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
4b6aa8
---
4b6aa8
 src/include/dump_dir.h |  4 +++-
4b6aa8
 src/lib/dump_dir.c     | 12 +++++++++---
4b6aa8
 2 files changed, 12 insertions(+), 4 deletions(-)
4b6aa8
4b6aa8
diff --git a/src/include/dump_dir.h b/src/include/dump_dir.h
4b6aa8
index 71cf66f..8f672d3 100644
4b6aa8
--- a/src/include/dump_dir.h
4b6aa8
+++ b/src/include/dump_dir.h
4b6aa8
@@ -43,6 +43,8 @@ enum {
4b6aa8
     DD_OPEN_READONLY = (1 << 3),
4b6aa8
     DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE = (1 << 4),
4b6aa8
     DD_DONT_WAIT_FOR_LOCK = (1 << 5),
4b6aa8
+    /* Create the new dump directory with parent directories (mkdir -p)*/
4b6aa8
+    DD_CREATE_PARENTS = (1 << 6),
4b6aa8
 };
4b6aa8
 
4b6aa8
 struct dump_dir {
4b6aa8
@@ -60,7 +62,7 @@ struct dump_dir {
4b6aa8
 void dd_close(struct dump_dir *dd);
4b6aa8
 
4b6aa8
 struct dump_dir *dd_opendir(const char *dir, int flags);
4b6aa8
-struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode);
4b6aa8
+struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode, int flags);
4b6aa8
 int dd_reset_ownership(struct dump_dir *dd);
4b6aa8
 /* Pass uid = (uid_t)-1L to disable chown'ing of newly created files
4b6aa8
  * (IOW: if you aren't running under root):
4b6aa8
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
4b6aa8
index fabad0b..2a65100 100644
4b6aa8
--- a/src/lib/dump_dir.c
4b6aa8
+++ b/src/lib/dump_dir.c
4b6aa8
@@ -514,7 +514,7 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
4b6aa8
  *     this runs under 0:0
4b6aa8
  *     - clients: setroubleshootd, abrt python
4b6aa8
  */
4b6aa8
-struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode)
4b6aa8
+struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode, int flags)
4b6aa8
 {
4b6aa8
     /* a little trick to copy read bits from file mode to exec bit of dir mode*/
4b6aa8
     mode_t dir_mode = mode | ((mode & 0444) >> 2);
4b6aa8
@@ -547,7 +547,13 @@ struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode)
4b6aa8
      * the user to replace any file in the directory, changing security-sensitive data
4b6aa8
      * (e.g. "uid", "analyzer", "executable")
4b6aa8
      */
4b6aa8
-    if (g_mkdir_with_parents(dd->dd_dirname, dir_mode) != 0)
4b6aa8
+    int r;
4b6aa8
+    if ((flags & DD_CREATE_PARENTS))
4b6aa8
+        r = g_mkdir_with_parents(dd->dd_dirname, dir_mode);
4b6aa8
+    else
4b6aa8
+        r = mkdir(dd->dd_dirname, dir_mode);
4b6aa8
+
4b6aa8
+    if (r != 0)
4b6aa8
     {
4b6aa8
         perror_msg("Can't create directory '%s'", dir);
4b6aa8
         dd_close(dd);
4b6aa8
@@ -627,7 +633,7 @@ int dd_reset_ownership(struct dump_dir *dd)
4b6aa8
  */
4b6aa8
 struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
4b6aa8
 {
4b6aa8
-    struct dump_dir *dd = dd_create_skeleton(dir, uid, mode);
4b6aa8
+    struct dump_dir *dd = dd_create_skeleton(dir, uid, mode, DD_CREATE_PARENTS);
4b6aa8
     if (dd == NULL)
4b6aa8
         return NULL;
4b6aa8
 
4b6aa8
-- 
4b6aa8
1.8.3.1
4b6aa8