[Automatic Bug Reporting Tool - ABRT] #947: use default callbacks for both logging and error callbacks in run_event_state struct
by fedora-badges
#947: use default callbacks for both logging and error callbacks in
run_event_state struct
-----------------------+---------------------
Reporter: jfilak | Owner: jfilak
Type: task | Status: new
Priority: major | Milestone:
Component: libreport | Version:
Keywords: | Blocked By:
Blocking: |
-----------------------+---------------------
By default, run_event_on_dir consumes all nonprefixed output (no ALLERT,
ASK, ...) produced by event's command. We found out that this behaviour
doesn't met our needs. (e.g. abrt-cli report $DUMP_DIR)
run_event_state struct uses default callbacks for questions and alerts
which simply forwards requests to stdout and reads responses from stdin.
We have decided to use similar functions for both logging and error
callbacks.
--
Ticket URL: <https://fedorahosted.org/abrt/ticket/947>
Automatic Bug Reporting Tool - ABRT <http://fedorahoted.org/abrt/>
Automatic bug reporting tool
11 years, 3 months
[LIBREPORT PATCH] add build time condition for dump dir ownership schema
by Jakub Filak
- related to trac#927 (/var/spool/abrt -> /var/tmp/abrt)
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
configure.ac | 2 ++
src/lib/Makefile.am | 1 +
src/lib/dump_dir.c | 82 ++++++++++++++++++++++++++++++++++++++++++++---------
3 files changed, 71 insertions(+), 14 deletions(-)
diff --git a/configure.ac b/configure.ac
index dbe3a62..6209cc4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -184,6 +184,7 @@ WORKFLOWS_DIR='${sysconfdir}/${PACKAGE_NAME}/workflows'
WORKFLOWS_CONF_DIR='${sysconfdir}/${PACKAGE_NAME}/workflows.d'
PLUGINS_LIB_DIR='${libdir}/${PACKAGE_NAME}'
LIBEXEC_DIR='${libexecdir}'
+DUMP_DIR_OWNED_BY_USER=0
DEBUG_DUMPS_DIR='${localstatedir}/spool/abrt'
@@ -203,6 +204,7 @@ AC_SUBST(DEBUG_DUMPS_DIR)
AC_SUBST(LIBEXEC_DIR)
AC_SUBST(WORKFLOWS_DIR)
AC_SUBST(WORKFLOWS_CONF_DIR)
+AC_SUBST(DUMP_DIR_OWNED_BY_USER)
# Initialize the test suite.
AC_CONFIG_TESTDIR(tests)
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index e8dfd43..91d128f 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -65,6 +65,7 @@ libreport_la_CPPFLAGS = \
-DWORKFLOWS_DIR=\"$(WORKFLOWS_DIR)\" \
-DBIN_DIR=\"$(bindir)\" \
-DDEFAULT_DUMP_DIR_MODE=$(DEFAULT_DUMP_DIR_MODE) \
+ -DDUMP_DIR_OWNED_BY_USER=$(DUMP_DIR_OWNED_BY_USER) \
$(GLIB_CFLAGS) \
-D_GNU_SOURCE
libreport_la_LDFLAGS = \
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 22fc93c..5118860 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -415,22 +415,59 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
/* Create a fresh empty debug dump dir.
*
- * Security: we should not allow users to write new files or write
- * into existing ones, but they should be able to read them.
+ * ABRT owns dump dir:
+ * We should not allow users to write new files or write into existing ones,
+ * but they should be able to read them.
+ *
+ * We set dir's gid to passwd(uid)->pw_gid parameter, and we set uid to
+ * abrt's user id. We do not allow write access to group. We can't set dir's
+ * uid to crashed applications's user uid because owner can modify dir's
+ * mode and ownership.
+ *
+ * Advantages:
+ * Safeness
+ *
+ * Disadvantages:
+ * This approach leads to stealing of directories because events requires
+ * write access to a dump directory and events are run under non root (abrt)
+ * user while reporting.
+ *
+ * This approach allows group members to see crashes of other members.
+ * Institutions like schools uses one common group for all students.
+ *
+ * User owns dump dir:
+ * We grant ownership of dump directories to the user (read/write access).
+ *
+ * We set set dir's uid to crashed applications's user uid, and we set gid to
+ * abrt's group id. We allow write access to group because we want to allow
+ * abrt binaries to process dump directories.
+ *
+ * Advantages:
+ * No disadvantages from the previous approach
+ *
+ * Disadvantages:
+ * In order to protect the system dump directories must be saved on
+ * noncritical filesystem (e.g. /tmp or /var/tmp).
+ *
*
* @param uid
* Crashed application's User Id
*
* We currently have only three callers:
- * kernel oops hook: uid -> not saved, so everyone can steal and work with it
- * this hook runs under 0:0
- * ccpp hook: uid=uid of crashed user's binary
- * this hook runs under 0:0
- * python hook: uid=uid of crashed user's script
- * this hook runs under abrt:gid
+ * kernel oops hook: uid -> not saved, so everyone can steal and work with it
+ * this hook runs under 0:0
*
- * Currently, we set dir's gid to passwd(uid)->pw_gid parameter, and we set uid to
- * abrt's user id. We do not allow write access to group.
+ * ccpp hook: uid=uid of crashed user's binary
+ * this hook runs under 0:0
+ *
+ * create_dump_dir_from_problem_data() function:
+ * Currently known callers:
+ * abrt server: uid=uid of user's executable
+ * this runs under 0:0
+ * - clinets: python hook, ruby hook
+ * abrt dbus: uid=uid of user's executable
+ * this runs under 0:0
+ * - clients: setroubleshootd, abrt python
*/
struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
{
@@ -490,21 +527,38 @@ struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
dd->dd_gid = (gid_t)-1L;
if (uid != (uid_t)-1L)
{
- /* Get ABRT's user id */
dd->dd_uid = 0;
+ dd->dd_uid = 0;
+
+#if DUMP_DIR_OWNED_BY_USER > 0
+ /* Check crashed application's uid */
+ struct passwd *pw = getpwuid(uid);
+ if (pw)
+ dd->dd_uid = pw->pw_uid;
+ else
+ error_msg("User %lu does not exist, using uid 0", (long)uid);
+
+ /* Get ABRT's group gid */
+ struct group *gr = getgrnam("abrt");
+ if (gr)
+ dd->dd_gid = gr->gr_gid;
+ else
+ error_msg("Group 'abrt' does not exist, using gid 0");
+#else
+ /* Get ABRT's user uid */
struct passwd *pw = getpwnam("abrt");
if (pw)
dd->dd_uid = pw->pw_uid;
else
- error_msg("user 'abrt' does not exist, using uid 0");
+ error_msg("User 'abrt' does not exist, using uid 0");
- /* Get crashed application's group id */
- /*dd->dd_gid = 0; - dd_init did this already */
+ /* Get crashed application's gid */
pw = getpwuid(uid);
if (pw)
dd->dd_gid = pw->pw_gid;
else
error_msg("User %lu does not exist, using gid 0", (long)uid);
+#endif
if (lchown(dir, dd->dd_uid, dd->dd_gid) == -1)
{
--
1.7.11.7
11 years, 3 months
[PATCH] teach bugzilla reporter to use a different comment format for dups
by Denys Vlasenko
The new flag "reporter-bugzilla -A FILE" can be used to specify a different
comment format file. We supply example file (bugzilla_formatdup.conf).
abrt package will use that file.
--
vda
diff -x '*.po' -d -urpN libreport.7/libreport.spec.in libreport.8/libreport.spec.in
--- libreport.7/libreport.spec.in 2013-01-10 14:18:05.000000000 +0100
+++ libreport.8/libreport.spec.in 2013-01-16 14:54:48.960506138 +0100
@@ -391,6 +391,7 @@ gtk-update-icon-cache %{_datadir}/icons/
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/libreport/plugins/bugzilla.conf
%config(noreplace) %{_sysconfdir}/libreport/plugins/bugzilla_format.conf
+%config(noreplace) %{_sysconfdir}/libreport/plugins/bugzilla_formatdup.conf
%config(noreplace) %{_sysconfdir}/libreport/plugins/bugzilla_format_libreport.conf
%config(noreplace) %{_sysconfdir}/libreport/plugins/bugzilla_format_kernel.conf
%{_sysconfdir}/libreport/events/report_Bugzilla.xml
diff -x '*.po' -d -urpN libreport.7/src/plugins/bugzilla_formatdup.conf libreport.8/src/plugins/bugzilla_formatdup.conf
--- libreport.7/src/plugins/bugzilla_formatdup.conf 1970-01-01 01:00:00.000000000 +0100
+++ libreport.8/src/plugins/bugzilla_formatdup.conf 2013-01-16 14:54:34.667524306 +0100
@@ -0,0 +1,54 @@
+# Lines starting with # are ignored.
+# Lines can be continued on the next line using trailing backslash.
+#
+# Format:
+# %summary:: summary format
+# section:: element1[,element2]...
+# The literal text line to be added to Bugzilla comment. Can be empty.
+# (IOW: empty lines are NOT ignored!)
+#
+# Summary format is a line of text, where %element% is replaced by
+# text element's content, and [[...%element%...]] block is used only if
+# %element% exists. [[...]] blocks can nest.
+#
+# Sections can be:
+# - %summary: bug summary format string.
+# - %attach: a list of elements to attach.
+# - text, double colon (::) and the list of comma-separated elements.
+#
+# Elements can be:
+# - problem directory element names, which get formatted as
+# <element_name>: <contents>
+# or
+# <element_name>:
+# :<contents>
+# :<contents>
+# :<contents>
+# - problem directory element names prefixed by "%bare_",
+# which is formatted as-is, without "<element_name>:" and colons
+# - %oneline, %multiline, %text wildcards, which select all corresponding
+# elements for output or attachment
+# - %binary wildcard, valid only for %attach section, instructs to attach
+# binary elements
+# - problem directory element names prefixed by "-",
+# which excludes given element from all wildcards
+#
+# Nonexistent elements are silently ignored.
+# If none of elements exists, the section will not be created.
+
+%summary:: [abrt] %package%[[: %crash_function%]][[: %reason%]][[: TAINTED %tainted_short%]]
+
+Description of problem:: %bare_comment
+
+Version-Release number of selected component:: %bare_package
+
+# var_log_messages has too much variance (time/date),
+# we exclude it from message so that dup message elimination has more chances to work
+Additional info:: \
+ -pkg_arch,-pkg_epoch,-pkg_name,-pkg_release,-pkg_version,\
+ -component,-architecture,\
+ -analyzer,-count,-duphash,-uuid,-abrt_version,\
+ -username,-hostname,-os_release,\
+ -time,-pid,-pwd,\
+ -var_log_messages,\
+ %oneline
diff -x '*.po' -d -urpN libreport.7/src/plugins/Makefile.am libreport.8/src/plugins/Makefile.am
--- libreport.7/src/plugins/Makefile.am 2013-01-10 14:18:05.000000000 +0100
+++ libreport.8/src/plugins/Makefile.am 2013-01-16 14:55:27.372457362 +0100
@@ -25,6 +25,7 @@ reporters_plugin_conf =
if BUILD_BUGZILLA
reporters_plugin_conf += bugzilla.conf \
bugzilla_format.conf \
+ bugzilla_formatdup.conf \
bugzilla_format_libreport.conf \
bugzilla_format_kernel.conf
diff -x '*.po' -d -urpN libreport.7/src/plugins/reporter-bugzilla.c libreport.8/src/plugins/reporter-bugzilla.c
--- libreport.7/src/plugins/reporter-bugzilla.c 2013-01-15 12:23:21.000000000 +0100
+++ libreport.8/src/plugins/reporter-bugzilla.c 2013-01-16 14:47:48.722044298 +0100
@@ -794,7 +794,7 @@ int main(int argc, char **argv)
/* Can't keep these strings/structs static: _() doesn't support that */
const char *program_usage_string = _(
- "\n& [-vbf] [-g GROUP-NAME]... [-c CONFFILE]... [-F FMTFILE] -d DIR"
+ "\n& [-vbf] [-g GROUP-NAME]... [-c CONFFILE]... [-F FMTFILE] [-A FMTFILE2] -d DIR"
"\nor:"
"\n& [-v] [-c CONFFILE]... [-d DIR] -t[ID] FILE..."
"\nor:"
@@ -833,24 +833,26 @@ int main(int argc, char **argv)
"\nRecognized boolean parameter (VALUE should be 1/0, yes/no): SSLVerify."
"\nParameters can be overridden via $Bugzilla_PARAM environment variables."
"\n"
- "\nFMTFILE defaults to "CONF_DIR"/plugins/bugzilla_format.conf"
+ "\nFMTFILE and FMTFILE2 default to "CONF_DIR"/plugins/bugzilla_format.conf"
);
enum {
OPT_v = 1 << 0,
OPT_d = 1 << 1,
OPT_c = 1 << 2,
OPT_F = 1 << 3,
- OPT_t = 1 << 4,
- OPT_b = 1 << 5,
- OPT_f = 1 << 6,
- OPT_w = 1 << 7,
- OPT_h = 1 << 8,
- OPT_g = 1 << 9,
- OPT_D = 1 << 10,
+ OPT_A = 1 << 4,
+ OPT_t = 1 << 5,
+ OPT_b = 1 << 6,
+ OPT_f = 1 << 7,
+ OPT_w = 1 << 8,
+ OPT_h = 1 << 9,
+ OPT_g = 1 << 10,
+ OPT_D = 1 << 11,
};
const char *dump_dir_name = ".";
GList *conf_file = NULL;
const char *fmt_file = CONF_DIR"/plugins/bugzilla_format.conf";
+ const char *fmt_file2 = fmt_file;
char *abrt_hash = NULL;
char *ticket_no = NULL;
char *debug_str = NULL;
@@ -860,7 +862,8 @@ int main(int argc, char **argv)
OPT__VERBOSE(&g_verbose),
OPT_STRING( 'd', NULL, &dump_dir_name , "DIR" , _("Problem directory")),
OPT_LIST( 'c', NULL, &conf_file , "FILE" , _("Configuration file (may be given many times)")),
- OPT_STRING( 'F', NULL, &fmt_file , "FILE" , _("Formatting file")),
+ OPT_STRING( 'F', NULL, &fmt_file , "FILE" , _("Formatting file for initial comment")),
+ OPT_STRING( 'A', NULL, &fmt_file2 , "FILE" , _("Formatting file for duplicates")),
OPT_OPTSTRING('t', "ticket", &ticket_no , "ID" , _("Attach FILEs [to bug with this ID]")),
OPT_BOOL( 'b', NULL, NULL, _("When creating bug, attach binary files too")),
OPT_BOOL( 'f', NULL, NULL, _("Force reporting even if this problem is already reported")),
@@ -1215,65 +1218,43 @@ int main(int argc, char **argv)
rhbz_mail_to_cc(client, bz->bi_id, rhbz.b_login, RHBZ_NOMAIL_NOTIFY);
}
- /* Add comment */
+ /* Add comment and bt */
const char *comment = problem_data_get_content_or_NULL(problem_data, FILENAME_COMMENT);
if (comment && comment[0])
{
- const char *package = problem_data_get_content_or_NULL(problem_data, FILENAME_PACKAGE);
- const char *arch = problem_data_get_content_or_NULL(problem_data, FILENAME_ARCHITECTURE);
- const char *rating_str = problem_data_get_content_or_NULL(problem_data, FILENAME_RATING);
-
- struct strbuf *full_desc = strbuf_new();
- strbuf_append_strf(full_desc, "%s\n\n", comment);
-
- /* python doesn't have rating file */
- if (rating_str)
- strbuf_append_strf(full_desc, "%s: %s\n", FILENAME_RATING, rating_str);
- strbuf_append_strf(full_desc, "Package: %s\n", package);
- /* attach the architecture only if it's different from the initial report */
- if ((strcmp(bz->bi_platform, "All") != 0) &&
- (strcmp(bz->bi_platform, "Unspecified") != 0) &&
- (strcmp(bz->bi_platform, arch) !=0))
- strbuf_append_strf(full_desc, "Architecture: %s\n", arch);
- else
- {
- VERB3 log("not adding the arch: %s because rep_plat is %s", arch, bz->bi_platform);
- }
- strbuf_append_strf(full_desc, "OS Release: %s\n", rhbz.b_os_release);
-
- /* unused code, enable it when gui/cli will be ready
- int is_priv = is_private && string_to_bool(is_private);
- const char *is_private = problem_data_get_content_or_NULL(problem_data,
- "is_private");
- */
+ GList *comment_fmt_spec = load_bzrep_conf_file(fmt_file2);
+ struct strbuf *bzcomment_buf = strbuf_new();
+ generate_bz_comment(bzcomment_buf, problem_data, comment_fmt_spec);
+ char *bzcomment = strbuf_free_nobuf(bzcomment_buf);
+//TODO: free_comment_fmt_spec(comment_fmt_spec);
- int dup_comment = is_comment_dup(bz->bi_comments, full_desc->buf);
+ int dup_comment = is_comment_dup(bz->bi_comments, bzcomment);
if (!dup_comment)
{
log(_("Adding new comment to bug %d"), bz->bi_id);
- rhbz_add_comment(client, bz->bi_id, full_desc->buf, 0);
+ rhbz_add_comment(client, bz->bi_id, bzcomment, 0);
+ free(bzcomment);
+
+ const char *bt = problem_data_get_content_or_NULL(problem_data, FILENAME_BACKTRACE);
+ unsigned rating = 0;
+ const char *rating_str = problem_data_get_content_or_NULL(problem_data, FILENAME_RATING);
+ /* python doesn't have rating file */
+ if (rating_str)
+ rating = xatou(rating_str);
+ if (bt && rating > bz->bi_best_bt_rating)
+ {
+ char bug_id_str[sizeof(int)*3 + 2];
+ sprintf(bug_id_str, "%i", bz->bi_id);
+ log(_("Attaching better backtrace"));
+ rhbz_attach_blob(client, FILENAME_BACKTRACE, bug_id_str, bt, strlen(bt),
+ RHBZ_NOMAIL_NOTIFY);
+ }
}
else
{
+ free(bzcomment);
log(_("Found the same comment in the bug history, not adding a new one"));
}
- strbuf_free(full_desc);
-
- unsigned rating = 0;
- /* python doesn't have rating file */
- if (rating_str)
- rating = xatou(rating_str);
- if (!dup_comment && (rating > bz->bi_best_bt_rating))
- {
- char bug_id_str[sizeof(int)*3 + 2];
- snprintf(bug_id_str, sizeof(bug_id_str), "%i", bz->bi_id);
-
- const char *bt = problem_data_get_content_or_NULL(problem_data,
- FILENAME_BACKTRACE);
- log(_("Attaching better backtrace"));
- rhbz_attach_blob(client, FILENAME_BACKTRACE, bug_id_str, bt, strlen(bt),
- RHBZ_NOMAIL_NOTIFY);
- }
}
}
11 years, 3 months
[LIBREPORT PATCH 1/3] run_event: default callbacks for logging and errors
by Jakub Filak
- closes trac#947
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/include/run_event.h | 5 +++++
src/lib/run_event.c | 21 +++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/src/include/run_event.h b/src/include/run_event.h
index 9dcc355..49c2a38 100644
--- a/src/include/run_event.h
+++ b/src/include/run_event.h
@@ -36,6 +36,8 @@ struct run_event_state {
/* Can take ownership of log_line, which is malloced. In this case, return NULL.
* Otherwise should return log_line (it will be freed by caller)
+ *
+ * The default value prints log_line with trailing newline to stdout.
*/
char* (*logging_callback)(char *log_line, void *param);
void *logging_param;
@@ -43,6 +45,9 @@ struct run_event_state {
/*
* Called if any error occures during communication with child's command.
*
+ * The default value prints error_line with trailing newline to stderr and
+ * exits with an error code.
+ *
* @param error_line An error message
* @param param a custom param
*/
diff --git a/src/lib/run_event.c b/src/lib/run_event.c
index a60913e..ea90029 100644
--- a/src/lib/run_event.c
+++ b/src/lib/run_event.c
@@ -21,10 +21,16 @@
#include "client.h"
#include "internal_libreport.h"
+static char *run_event_stdio_log(char *log_line, void *param);
+static void run_event_stdio_error_and_die(const char *error_line, void *param);
+
struct run_event_state *new_run_event_state()
{
struct run_event_state *state = xzalloc(sizeof(struct run_event_state));
+ state->logging_callback = run_event_stdio_log;
+ state->error_callback = run_event_stdio_error_and_die;
+
state->alert_callback = run_event_stdio_alert;
state->ask_callback = run_event_stdio_ask;
state->ask_yes_no_callback = run_event_stdio_ask_yes_no;
@@ -55,6 +61,10 @@ void make_run_event_state_forwarding(struct run_event_state *state)
state->ask_yes_no_yesforever_callback= run_event_stdio_ask_yes_no_yesforever;
state->ask_password_callback = run_event_stdio_ask_password;
+ /*
+ * Not sure if we should reset even logging_callback and error_callback?
+ */
+
xsetenv("REPORT_CLIENT_SLAVE", "1");
}
@@ -731,3 +741,14 @@ char *run_event_stdio_ask_password(const char *msg, void *param)
{
return ask_password(msg);
}
+
+static char *run_event_stdio_log(char *log_line, void *param)
+{
+ printf("%s\n", log_line);
+ return log_line;
+}
+
+static void run_event_stdio_error_and_die(const char *error_line, void *param)
+{
+ error_msg_and_die("Can't write bytes to child's stdin");
+}
--
1.7.11.7
11 years, 3 months
[ABRT PATCH 1/2] harvest-vmcore: read dump dir path from configuration
by Jakub Filak
- realted to trac#927
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
.gitignore | 1 +
src/hooks/Makefile.am | 6 +++-
src/hooks/abrt-harvest-vmcore | 63 -------------------------------------
src/hooks/abrt-harvest-vmcore.in | 68 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 64 deletions(-)
delete mode 100755 src/hooks/abrt-harvest-vmcore
create mode 100644 src/hooks/abrt-harvest-vmcore.in
diff --git a/.gitignore b/.gitignore
index af61b26..039b9f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,6 +34,7 @@ src/plugins/abrt-action-install-debuginfo
src/plugins/abrt-action-generate-core-backtrace
src/plugins/abrt-bodhi
src/hooks/abrt_exception_handler.py
+src/hooks/abrt-harvest-vmcore
src/hooks/abrt-hook-ccpp
src/hooks/abrt-install-ccpp-hook
src/applet/abrt-applet.desktop
diff --git a/src/hooks/Makefile.am b/src/hooks/Makefile.am
index 982803e..fe0c8db 100644
--- a/src/hooks/Makefile.am
+++ b/src/hooks/Makefile.am
@@ -33,7 +33,7 @@ abrt_hook_ccpp_LDADD = \
python_PYTHON = abrt.pth abrt_exception_handler.py
EXTRA_DIST = abrt_exception_handler.py.in \
abrt-install-ccpp-hook.in \
- abrt-harvest-vmcore
+ abrt-harvest-vmcore.in
CLEANFILES := $(notdir $(wildcard *~)) $(notdir $(wildcard *\#)) $(notdir $(wildcard \.\#*)) $(notdir $(wildcard *.pyc)) $(man1_MANS)
@@ -56,3 +56,7 @@ abrt-install-ccpp-hook: abrt-install-ccpp-hook.in
sed -e s,\@VAR_RUN\@,$(VAR_RUN),g \
-e s,\@libexecdir\@,$(libexecdir),g \
$< >$@
+
+abrt-harvest-vmcore: abrt-harvest-vmcore.in
+ sed -e s,\@CONF_DIR\@,\$(CONF_DIR)\,g \
+ $< >$@
diff --git a/src/hooks/abrt-harvest-vmcore b/src/hooks/abrt-harvest-vmcore
deleted file mode 100755
index dbca8ca..0000000
--- a/src/hooks/abrt-harvest-vmcore
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/sh
-#
-# This script is meant to be run once at system startup after abrtd is up
-# and running. It moves all vmcore directories in /var/crash
-# (which are presumably created by kdump) to abrtd spool directory.
-#
-# The goal is to let abrtd notice and process them as new problem data dirs.
-#
-
-cd /var/crash 2>/dev/null || exit 0
-
-# Wait for abrtd to start. Give it at least 1 second to initialize.
-i=10
-while ! pidof abrtd >/dev/null; do
- if test $((i--)) = 0; then
- exit 1
- fi
- sleep 1
-done
-sleep 1
-
-umask 077
-
-CopyVMcore=`sed -n '/^CopyVMcore[ \t]*=/ s/.*=[ \t]*//p' /etc/abrt/abrt-harvest-vmcore.conf 2>/dev/null`
-
-move_core=false
-if test x"$CopyVMcore" = x"no" || test x"$CopyVMcore" = x"0"; then
- move_core=true
-fi
-
-for d in *; do
- test -d "$d" || continue
- test -f "$d/vmcore" || continue
-
- # Let abrtd know what type of problem it is:
- printf 'vmcore' >"$d/analyzer"
- printf 'vmcore' >"$d/type"
- printf 'kernel' >"$d/component"
- printf '%s' "`date '+%s'`" >"$d/time"
- printf '0' >"$d/uid"
- # TODO: need to generate *real* UUID,
- # one which has a real chance of catching dups!
- # This one generates different hashes even for similar cores:
- printf '%s' "`sha1sum <"$d/vmcore" | cut -d" " -f1`" >"$d/uuid"
-
- # Move vmcore directory to abrt spool dir.
- # We use .new suffix - we must make sure abrtd doesn't try
- # to process partially-copied directory.
- #
- # This is the efficient way:
- #mv -- "$d" "/var/spool/abrt/vmcore-$d.new" || continue
- # ...and this is what selinux forces me to do
- # (otherwise files have wrong context and abrtd can't access them):
- cp -r --no-preserve=all -- "$d" "/var/spool/abrt/vmcore-$d.new" || {
- rm -rf "/var/spool/abrt/vmcore-$d.new"
- continue
- }
- $move_core && rm -rf -- "$d"
-
- chown -R 0:0 "/var/spool/abrt/vmcore-$d.new"
- chmod -R u+rwX,go-rwxst "/var/spool/abrt/vmcore-$d.new"
- mv "/var/spool/abrt/vmcore-$d.new" "/var/spool/abrt/vmcore-$d"
-done
diff --git a/src/hooks/abrt-harvest-vmcore.in b/src/hooks/abrt-harvest-vmcore.in
new file mode 100644
index 0000000..3c463df
--- /dev/null
+++ b/src/hooks/abrt-harvest-vmcore.in
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# This script is meant to be run once at system startup after abrtd is up
+# and running. It moves all vmcore directories in /var/crash
+# (which are presumably created by kdump) to abrtd spool directory.
+#
+# The goal is to let abrtd notice and process them as new problem data dirs.
+#
+
+cd /var/crash 2>/dev/null || exit 0
+
+# Wait for abrtd to start. Give it at least 1 second to initialize.
+i=10
+while ! pidof abrtd >/dev/null; do
+ if test $((i--)) = 0; then
+ exit 1
+ fi
+ sleep 1
+done
+sleep 1
+
+umask 077
+
+CopyVMcore=`sed -n '/^CopyVMcore[ \t]*=/ s/.*=[ \t]*//p' @CONF_DIR(a)/abrt-harvest-vmcore.conf 2>/dev/null`
+ABRTDumpDir=`sed -n '/^DumpLocation [ \t]*=/ s/.*=[ \t]*//p' @CONF_DIR(a)/abrt.conf 2>/dev/null`
+
+if test -z "$ABRTDumpDir"; then
+ ABRTDumpDir="/var/spool/abrt"
+fi
+
+move_core=false
+if test x"$CopyVMcore" = x"no" || test x"$CopyVMcore" = x"0"; then
+ move_core=true
+fi
+
+for d in *; do
+ test -d "$d" || continue
+ test -f "$d/vmcore" || continue
+
+ # Let abrtd know what type of problem it is:
+ printf 'vmcore' >"$d/analyzer"
+ printf 'vmcore' >"$d/type"
+ printf 'kernel' >"$d/component"
+ printf '%s' "`date '+%s'`" >"$d/time"
+ printf '0' >"$d/uid"
+ # TODO: need to generate *real* UUID,
+ # one which has a real chance of catching dups!
+ # This one generates different hashes even for similar cores:
+ printf '%s' "`sha1sum <"$d/vmcore" | cut -d" " -f1`" >"$d/uuid"
+
+ # Move vmcore directory to abrt spool dir.
+ # We use .new suffix - we must make sure abrtd doesn't try
+ # to process partially-copied directory.
+ #
+ # This is the efficient way:
+ #mv -- "$d" "/var/spool/abrt/vmcore-$d.new" || continue
+ # ...and this is what selinux forces me to do
+ # (otherwise files have wrong context and abrtd can't access them):
+ cp -r --no-preserve=all -- "$d" "$ABRTDumpDir/vmcore-$d.new" || {
+ rm -rf "$ABRTDumpDir/vmcore-$d.new"
+ continue
+ }
+ $move_core && rm -rf -- "$d"
+
+ chown -R 0:0 "$ABRTDumpDir/vmcore-$d.new"
+ chmod -R u+rwX,go-rwxst "$ABRTDumpDir/vmcore-$d.new"
+ mv "$ABRTDumpDir/vmcore-$d.new" "$ABRTDumpDir/vmcore-$d"
+done
--
1.7.11.7
11 years, 3 months
[LIBREPORT PATCH] make default dump dir mode configurable at build time
by Jakub Filak
- related to trac#927
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
configure.ac | 4 ++++
libreport.pc.in | 1 +
src/lib/Makefile.am | 1 +
src/lib/create_dump_dir.c | 4 ++--
src/lib/steal_directory.c | 2 +-
src/report-python/Makefile.am | 1 +
src/report-python/dump_dir.c | 2 +-
7 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/configure.ac b/configure.ac
index 5211bfd..dbe3a62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,10 @@ AM_PROG_CC_C_O
AC_PROG_LN_S
AC_SYS_LARGEFILE
+
+DEFAULT_DUMP_DIR_MODE="0640"
+AC_SUBST(DEFAULT_DUMP_DIR_MODE)
+
CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE \
-D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -std=gnu99 -Wall -Wwrite-strings"
diff --git a/libreport.pc.in b/libreport.pc.in
index 82987ce..8f939cb 100755
--- a/libreport.pc.in
+++ b/libreport.pc.in
@@ -2,6 +2,7 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
+dd_mode=@DEFAULT_DUMP_DIR_MODE@
Name: libreport
Description: Generic library for reporting various problems
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index dad9f89..e8dfd43 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -64,6 +64,7 @@ libreport_la_CPPFLAGS = \
-DEVENTS_DIR=\"$(EVENTS_DIR)\" \
-DWORKFLOWS_DIR=\"$(WORKFLOWS_DIR)\" \
-DBIN_DIR=\"$(bindir)\" \
+ -DDEFAULT_DUMP_DIR_MODE=$(DEFAULT_DUMP_DIR_MODE) \
$(GLIB_CFLAGS) \
-D_GNU_SOURCE
libreport_la_LDFLAGS = \
diff --git a/src/lib/create_dump_dir.c b/src/lib/create_dump_dir.c
index d0db9b2..873139d 100644
--- a/src/lib/create_dump_dir.c
+++ b/src/lib/create_dump_dir.c
@@ -25,7 +25,7 @@
static struct dump_dir *try_dd_create(const char *base_dir_name, const char *dir_name, uid_t uid)
{
char *path = concat_path_file(base_dir_name, dir_name);
- struct dump_dir *dd = dd_create(path, uid, 0640);
+ struct dump_dir *dd = dd_create(path, uid, DEFAULT_DUMP_DIR_MODE);
free(path);
return dd;
}
@@ -107,7 +107,7 @@ struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data,
{
char *dest = concat_path_file(dd->dd_dirname, name);
VERB2 log("copying '%s' to '%s'", value->content, dest);
- off_t copied = copy_file(value->content, dest, 0644);
+ off_t copied = copy_file(value->content, dest, DEFAULT_DUMP_DIR_MODE | S_IROTH);
if (copied < 0)
error_msg("Can't copy %s to %s", value->content, dest);
else
diff --git a/src/lib/steal_directory.c b/src/lib/steal_directory.c
index 4318662..519d418 100644
--- a/src/lib/steal_directory.c
+++ b/src/lib/steal_directory.c
@@ -50,7 +50,7 @@ struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name
char *dst_dir_name = concat_path_file(base_dir, base_name);
while (1)
{
- dd_dst = dd_create(dst_dir_name, (uid_t)-1, 0640);
+ dd_dst = dd_create(dst_dir_name, (uid_t)-1, DEFAULT_DUMP_DIR_MODE);
free(dst_dir_name);
if (dd_dst)
break;
diff --git a/src/report-python/Makefile.am b/src/report-python/Makefile.am
index a333472..5dc0b54 100644
--- a/src/report-python/Makefile.am
+++ b/src/report-python/Makefile.am
@@ -20,6 +20,7 @@ _pyreport_la_CPPFLAGS = \
-DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
-DLOCALSTATEDIR='"$(localstatedir)"' \
-DVAR_RUN=\"$(VAR_RUN)\" \
+ -DDEFAULT_DUMP_DIR_MODE=$(DEFAULT_DUMP_DIR_MODE) \
$(GLIB_CFLAGS) \
$(PYTHON_CFLAGS) \
-D_GNU_SOURCE \
diff --git a/src/report-python/dump_dir.c b/src/report-python/dump_dir.c
index 6934bd6..f087563 100644
--- a/src/report-python/dump_dir.c
+++ b/src/report-python/dump_dir.c
@@ -266,7 +266,7 @@ PyObject *p_dd_create(PyObject *module, PyObject *args)
p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type);
if (!new_dd)
return NULL;
- new_dd->dd = dd_create(dir, uid, 0640);
+ new_dd->dd = dd_create(dir, uid, DEFAULT_DUMP_DIR_MODE);
return (PyObject*)new_dd;
}
--
1.7.11.7
11 years, 3 months
[ABRT PATCH] use lchown when chowning files over dbus
by Jiri Moskovcak
- we don't want to follow symlinks
---
src/dbus/abrt-dbus.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
index c8e0bac..5a58160 100644
--- a/src/dbus/abrt-dbus.c
+++ b/src/dbus/abrt-dbus.c
@@ -604,13 +604,13 @@ static void handle_method_call(GDBusConnection *connection,
return;
}
- int chown_res = chown(problem_dir, statbuf.st_uid, pwd->pw_gid);
+ int chown_res = lchown(problem_dir, statbuf.st_uid, pwd->pw_gid);
dd_init_next_file(dd);
char *full_name;
while (chown_res == 0 && dd_get_next_file(dd, /*short_name*/ NULL, &full_name))
{
VERB3 log("chowning %s", full_name);
- chown_res = chown(full_name, statbuf.st_uid, pwd->pw_gid);
+ chown_res = lchown(full_name, statbuf.st_uid, pwd->pw_gid);
free(full_name);
}
--
1.8.0.1
11 years, 3 months
[LIBREPORT PATCH] never follow symlinks rhbz#887866
by Jiri Moskovcak
- use lchown instead chown and O_NOFOLLOW where we use open
---
src/lib/dump_dir.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 57c439d..01e1edd 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -116,7 +116,7 @@ static bool exist_file_dir(const char *path)
static bool not_valid_time_file(const char *filename)
{
/* Open input file, and parse it. */
- int fd = open(filename, O_RDONLY);
+ int fd = open(filename, O_RDONLY | O_NOFOLLOW);
if (fd < 0)
{
VERB2 perror_msg("Can't open '%s'", filename);
@@ -506,7 +506,7 @@ struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode)
else
error_msg("User %lu does not exist, using gid 0", (long)uid);
- if (chown(dir, dd->dd_uid, dd->dd_gid) == -1)
+ if (lchown(dir, dd->dd_uid, dd->dd_gid) == -1)
{
perror_msg("Can't change '%s' ownership to %lu:%lu", dir,
(long)dd->dd_uid, (long)dd->dd_gid);
@@ -606,7 +606,7 @@ void dd_sanitize_mode_and_owner(struct dump_dir *dd)
chmod(full_path, dd->mode);
if (statbuf.st_uid != dd->dd_uid || statbuf.st_gid != dd->dd_gid)
{
- if (chown(full_path, dd->dd_uid, dd->dd_gid) != 0)
+ if (lchown(full_path, dd->dd_uid, dd->dd_gid) != 0)
{
perror_msg("Can't change '%s' ownership to %lu:%lu", full_path,
(long)dd->dd_uid, (long)dd->dd_gid);
@@ -708,8 +708,8 @@ int dd_delete(struct dump_dir *dd)
static char *load_text_file(const char *path, unsigned flags)
{
- FILE *fp = fopen(path, "r");
- if (!fp)
+ int fd = open(path, O_RDONLY | O_NOFOLLOW);
+ if (fd == -1)
{
if (!(flags & DD_FAIL_QUIETLY_ENOENT))
perror_msg("Can't open file '%s'", path);
@@ -718,8 +718,8 @@ static char *load_text_file(const char *path, unsigned flags)
struct strbuf *buf_content = strbuf_new();
int oneline = 0;
- int ch;
- while ((ch = fgetc(fp)) != EOF)
+ char ch;
+ while (safe_read(fd, &ch, 1) > 0)
{
//TODO? \r -> \n?
//TODO? strip trailing spaces/tabs?
@@ -730,7 +730,7 @@ static char *load_text_file(const char *path, unsigned flags)
if (isspace(ch) || ch >= ' ') /* used !iscntrl, but it failed on unicode */
strbuf_append_char(buf_content, ch);
}
- fclose(fp);
+ close(fd);
char last = oneline != 0 ? buf_content->buf[buf_content->len - 1] : 0;
if (last == '\n')
@@ -760,7 +760,7 @@ static bool save_binary_file(const char *path, const char* data, unsigned size,
{
/* the mode is set by the caller, see dd_create() for security analysis */
unlink(path);
- int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
+ int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT | O_NOFOLLOW, mode);
if (fd < 0)
{
perror_msg("Can't open file '%s'", path);
--
1.8.0.1
11 years, 3 months