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