Right now, libabrt depends on libreport and it's not possible to call any
funtions from python written in libabrt.
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
src/include/internal_libreport.h | 3 ++
src/lib/Makefile.am | 3 +-
src/lib/sanitize.c | 40 ++++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletions(-)
create mode 100644 src/lib/sanitize.c
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
index afaf911..e1e0e30 100644
--- a/src/include/internal_libreport.h
+++ b/src/include/internal_libreport.h
@@ -707,6 +707,9 @@ unsigned parse_opts(int argc, char **argv, const struct options *opt,
#define show_usage_and_die libreport_show_usage_and_die
void show_usage_and_die(const char *usage, const struct options *opt) NORETURN;
+/* libabrt depends on libreport! break that chain and move this func back to abrt */
+#define ensure_writable_dir abrt_ensure_writable_dir
+void ensure_writable_dir(const char *dir, mode_t mode, const char *user);
#ifdef __cplusplus
}
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index e914f8a..1b30a20 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -46,7 +46,8 @@ libreport_la_SOURCES = \
event_config.c \
kernel-tainted.c \
report.c \
- client.c
+ client.c \
+ sanitize.c
libreport_la_CPPFLAGS = \
-Wall -Wwrite-strings -Werror \
-I$(srcdir)/../include \
diff --git a/src/lib/sanitize.c b/src/lib/sanitize.c
new file mode 100644
index 0000000..e8fd083
--- /dev/null
+++ b/src/lib/sanitize.c
@@ -0,0 +1,40 @@
+/*
+ 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"
+
+void ensure_writable_dir(const char *dir, mode_t mode, const char *user)
+{
+ struct stat sb;
+
+ if (mkdir(dir, mode) != 0 && errno != EEXIST)
+ perror_msg_and_die("Can't create '%s'", dir);
+ if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode))
+ error_msg_and_die("'%s' is not a directory", dir);
+
+ struct passwd *pw = getpwnam(user);
+ if (!pw)
+ perror_msg_and_die("Can't find user '%s'", user);
+
+ if ((sb.st_uid != pw->pw_uid || sb.st_gid != pw->pw_gid)
+ && chown(dir, pw->pw_uid, pw->pw_gid) != 0)
+ perror_msg_and_die("Can't set owner %u:%u on '%s'",
+ (unsigned int)pw->pw_uid, (unsigned int)pw->pw_gid,
dir);
+ if ((sb.st_mode & 07777) != mode && chmod(dir, mode) != 0)
+ perror_msg_and_die("Can't set mode %o on '%s'", mode,
dir);
+}
--
1.7.7.rc0.70.g82660
Show replies by date