---
src/include/internal_libreport.h | 3 ++
src/lib/Makefile.am | 1 +
src/lib/dump_dir.c | 21 +----------------
src/lib/make_dir_recursive.c | 47 ++++++++++++++++++++++++++++++++++++++
4 files changed, 52 insertions(+), 20 deletions(-)
create mode 100644 src/lib/make_dir_recursive.c
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
index 7ece26a..e754871 100644
--- a/src/include/internal_libreport.h
+++ b/src/include/internal_libreport.h
@@ -584,6 +584,9 @@ int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name);
#define steal_directory libreport_steal_directory
struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name);
+#define make_dir_recursive libreport_make_dir_recursive
+bool make_dir_recursive(char *dir, mode_t dir_mode);
+
// Text bigger than this usually is attached, not added inline
// was 2k, now bumbed up to 20k:
#define CD_TEXT_ATT_SIZE (20*1024)
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index f80e2f7..624c3f6 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -45,6 +45,7 @@ libreport_la_SOURCES = \
event_xml_parser.c \
event_config.c \
report.c \
+ make_dir_recursive.c \
client.c
libreport_la_CPPFLAGS = \
-Wall -Wwrite-strings -Werror \
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 5fe5c8b..fc5def1 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -404,31 +404,12 @@ struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
return NULL;
}
- bool created_parents = false;
- try_again:
/* Was creating it with mode 0700 and user as the owner, but this allows
* the user to replace any file in the directory, changing security-sensitive data
* (e.g. "uid", "analyzer", "executable")
*/
- if (mkdir(dir, dir_mode) == -1)
+ if (!make_dir_recursive(dd->dd_dirname, dir_mode))
{
- int err = errno;
- if (!created_parents && errno == ENOENT)
- {
- char *p = dd->dd_dirname + 1;
- while ((p = strchr(p, '/')) != NULL)
- {
- *p = '\0';
- int r = (mkdir(dd->dd_dirname, 0755) == 0 || errno == EEXIST);
- *p++ = '/';
- if (!r)
- goto report_err;
- }
- created_parents = true;
- goto try_again;
- }
- report_err:
- errno = err;
perror_msg("Can't create directory '%s'", dir);
dd_close(dd);
return NULL;
diff --git a/src/lib/make_dir_recursive.c b/src/lib/make_dir_recursive.c
new file mode 100644
index 0000000..13523b8
--- /dev/null
+++ b/src/lib/make_dir_recursive.c
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include "internal_libreport.h"
+
+bool make_dir_recursive(char *dir, mode_t dir_mode)
+{
+ bool created_parents = false;
+ try_again:
+ if (mkdir(dir, dir_mode) == -1)
+ {
+ int err = errno;
+ if (!created_parents && errno == ENOENT)
+ {
+ char *p = dir + 1;
+ while ((p = strchr(p, '/')) != NULL)
+ {
+ *p = '\0';
+ int r = (mkdir(dir, 0755) == 0 || errno == EEXIST);
+ *p++ = '/';
+ if (!r)
+ goto report_err;
+ }
+ created_parents = true;
+ goto try_again;
+ }
+ report_err:
+ errno = err;
+ return false;
+ }
+
+ return true;
+}
--
1.7.6.4