|
|
5f7b57 |
From b81884dcf41a6ee84c9ef5633acd2193bee60005 Mon Sep 17 00:00:00 2001
|
|
|
5f7b57 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
5f7b57 |
Date: Wed, 15 Apr 2015 15:19:40 +0200
|
|
|
5f7b57 |
Subject: [LIBREPORT PATCH] dump_dir: allow creating of a new dir w/o chowning
|
|
|
5f7b57 |
it
|
|
|
5f7b57 |
|
|
|
5f7b57 |
Split dd_create() in to dd_create_skeleton() creating the directory and
|
|
|
5f7b57 |
intializing struct dd* and dd_reset_ownership() updating UID and GUI to
|
|
|
5f7b57 |
the deemed values.
|
|
|
5f7b57 |
|
|
|
5f7b57 |
We need this because we have to avoid situations where root is using a
|
|
|
5f7b57 |
directory owned by a regular user.
|
|
|
5f7b57 |
|
|
|
5f7b57 |
Related: #1211835
|
|
|
5f7b57 |
|
|
|
5f7b57 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
5f7b57 |
---
|
|
|
5f7b57 |
src/include/dump_dir.h | 2 ++
|
|
|
5f7b57 |
src/lib/dump_dir.c | 39 ++++++++++++++++++++++++++++++++-------
|
|
|
5f7b57 |
2 files changed, 34 insertions(+), 7 deletions(-)
|
|
|
5f7b57 |
|
|
|
5f7b57 |
diff --git a/src/include/dump_dir.h b/src/include/dump_dir.h
|
|
|
5f7b57 |
index 124511e..71cf66f 100644
|
|
|
5f7b57 |
--- a/src/include/dump_dir.h
|
|
|
5f7b57 |
+++ b/src/include/dump_dir.h
|
|
|
5f7b57 |
@@ -60,6 +60,8 @@ struct dump_dir {
|
|
|
5f7b57 |
void dd_close(struct dump_dir *dd);
|
|
|
5f7b57 |
|
|
|
5f7b57 |
struct dump_dir *dd_opendir(const char *dir, int flags);
|
|
|
5f7b57 |
+struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode);
|
|
|
5f7b57 |
+int dd_reset_ownership(struct dump_dir *dd);
|
|
|
5f7b57 |
/* Pass uid = (uid_t)-1L to disable chown'ing of newly created files
|
|
|
5f7b57 |
* (IOW: if you aren't running under root):
|
|
|
5f7b57 |
*/
|
|
|
5f7b57 |
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
|
|
|
5f7b57 |
index 28439af..fabad0b 100644
|
|
|
5f7b57 |
--- a/src/lib/dump_dir.c
|
|
|
5f7b57 |
+++ b/src/lib/dump_dir.c
|
|
|
5f7b57 |
@@ -455,7 +455,10 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
|
|
|
5f7b57 |
return dd;
|
|
|
5f7b57 |
}
|
|
|
5f7b57 |
|
|
|
5f7b57 |
-/* Create a fresh empty debug dump dir.
|
|
|
5f7b57 |
+/* Create a fresh empty debug dump dir which is owned bu the calling user. If
|
|
|
5f7b57 |
+ * you want to create the directory with meaningful ownership you should
|
|
|
5f7b57 |
+ * consider using dd_create() function or you can modify the ownership
|
|
|
5f7b57 |
+ * afterwards by calling dd_reset_ownership() function.
|
|
|
5f7b57 |
*
|
|
|
5f7b57 |
* ABRT owns dump dir:
|
|
|
5f7b57 |
* We should not allow users to write new files or write into existing ones,
|
|
|
5f7b57 |
@@ -511,7 +514,7 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
|
|
|
5f7b57 |
* this runs under 0:0
|
|
|
5f7b57 |
* - clients: setroubleshootd, abrt python
|
|
|
5f7b57 |
*/
|
|
|
5f7b57 |
-struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
|
|
|
5f7b57 |
+struct dump_dir *dd_create_skeleton(const char *dir, uid_t uid, mode_t mode)
|
|
|
5f7b57 |
{
|
|
|
5f7b57 |
/* a little trick to copy read bits from file mode to exec bit of dir mode*/
|
|
|
5f7b57 |
mode_t dir_mode = mode | ((mode & 0444) >> 2);
|
|
|
5f7b57 |
@@ -601,13 +604,35 @@ struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
|
|
|
5f7b57 |
else
|
|
|
5f7b57 |
error_msg("User %lu does not exist, using gid 0", (long)uid);
|
|
|
5f7b57 |
#endif
|
|
|
5f7b57 |
+ }
|
|
|
5f7b57 |
|
|
|
5f7b57 |
- if (lchown(dir, dd->dd_uid, dd->dd_gid) == -1)
|
|
|
5f7b57 |
- {
|
|
|
5f7b57 |
- perror_msg("Can't change '%s' ownership to %lu:%lu", dir,
|
|
|
5f7b57 |
- (long)dd->dd_uid, (long)dd->dd_gid);
|
|
|
5f7b57 |
- }
|
|
|
5f7b57 |
+ return dd;
|
|
|
5f7b57 |
+}
|
|
|
5f7b57 |
+
|
|
|
5f7b57 |
+/* Resets ownership of the given directory to UID and GID according to values
|
|
|
5f7b57 |
+ * in dd_create_skeleton().
|
|
|
5f7b57 |
+ */
|
|
|
5f7b57 |
+int dd_reset_ownership(struct dump_dir *dd)
|
|
|
5f7b57 |
+{
|
|
|
5f7b57 |
+ const int r =lchown(dd->dd_dirname, dd->dd_uid, dd->dd_gid);
|
|
|
5f7b57 |
+ if (r < 0)
|
|
|
5f7b57 |
+ {
|
|
|
5f7b57 |
+ perror_msg("Can't change '%s' ownership to %lu:%lu", dd->dd_dirname,
|
|
|
5f7b57 |
+ (long)dd->dd_uid, (long)dd->dd_gid);
|
|
|
5f7b57 |
}
|
|
|
5f7b57 |
+ return r;
|
|
|
5f7b57 |
+}
|
|
|
5f7b57 |
+
|
|
|
5f7b57 |
+/* Calls dd_create_skeleton() and dd_reset_ownership().
|
|
|
5f7b57 |
+ */
|
|
|
5f7b57 |
+struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
|
|
|
5f7b57 |
+{
|
|
|
5f7b57 |
+ struct dump_dir *dd = dd_create_skeleton(dir, uid, mode);
|
|
|
5f7b57 |
+ if (dd == NULL)
|
|
|
5f7b57 |
+ return NULL;
|
|
|
5f7b57 |
+
|
|
|
5f7b57 |
+ /* ignore results */
|
|
|
5f7b57 |
+ dd_reset_ownership(dd);
|
|
|
5f7b57 |
|
|
|
5f7b57 |
return dd;
|
|
|
5f7b57 |
}
|
|
|
5f7b57 |
--
|
|
|
5f7b57 |
1.8.3.1
|
|
|
5f7b57 |
|