diff options
-rw-r--r-- | abrt.spec | 2 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/plugins/Mailx.cpp | 153 | ||||
-rw-r--r-- | src/plugins/Mailx.h | 48 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 27 | ||||
-rw-r--r-- | src/plugins/abrt-action-mailx.cpp | 182 |
6 files changed, 204 insertions, 209 deletions
@@ -407,9 +407,9 @@ fi %files plugin-mailx %defattr(-,root,root,-) %config(noreplace) %{_sysconfdir}/%{name}/plugins/Mailx.conf -%{_libdir}/%{name}/libMailx.so* %{_libdir}/%{name}/Mailx.glade %{_mandir}/man7/abrt-Mailx.7.gz +%{_libexecdir}/abrt-action-mailx %files plugin-bugzilla %defattr(-,root,root,-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 0d1274ba..4881b159 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,7 +5,6 @@ lib/plugins/CCpp.cpp lib/plugins/Kerneloops.cpp lib/plugins/KerneloopsScanner.cpp lib/plugins/KerneloopsSysLog.cpp -lib/plugins/Mailx.cpp lib/plugins/Python.cpp lib/plugins/SQLite3.cpp lib/plugins/Bugzilla.glade diff --git a/src/plugins/Mailx.cpp b/src/plugins/Mailx.cpp deleted file mode 100644 index 255c873d..00000000 --- a/src/plugins/Mailx.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - Mailx.cpp - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 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 "abrtlib.h" -#include "Mailx.h" -#include "abrt_exception.h" -#include "comm_layer_inner.h" - -#define MAILX_COMMAND "/bin/mailx" - -CMailx::CMailx() -{ - m_email_from = xstrdup("user@localhost"); - m_email_to = xstrdup("root@localhost"); - m_subject = xstrdup("[abrt] full crash report"); - m_send_binary_data = false; -} - -CMailx::~CMailx() -{ - free(m_email_from); - free(m_email_to); - free(m_subject); -} - -static void exec_and_feed_input(uid_t uid, const char* text, char **args) -{ - int pipein[2]; - - pid_t child = fork_execv_on_steroids( - EXECFLG_INPUT | EXECFLG_QUIET | EXECFLG_SETGUID, - args, - pipein, - /*unsetenv_vec:*/ NULL, - /*dir:*/ NULL, - uid); - - full_write_str(pipein[1], text); - close(pipein[1]); - - waitpid(child, NULL, 0); /* wait for command completion */ -} - -static char** append_str_to_vector(char **vec, unsigned &size, const char *str) -{ - //log("old vec: %p", vec); - vec = (char**) xrealloc(vec, (size+2) * sizeof(vec[0])); - vec[size] = xstrdup(str); - //log("new vec: %p, added [%d] %p", vec, size, vec[size]); - size++; - vec[size] = NULL; - return vec; -} - -std::string CMailx::Report(const map_crash_data_t& pCrashData, - const map_plugin_settings_t& pSettings, - const char *pArgs) -{ - SetSettings(pSettings); - char **args = NULL; - unsigned arg_size = 0; - args = append_str_to_vector(args, arg_size, MAILX_COMMAND); - - char *dsc = make_dsc_mailx(pCrashData); - - map_crash_data_t::const_iterator it; - for (it = pCrashData.begin(); it != pCrashData.end(); it++) - { - if (it->second[CD_TYPE] == CD_BIN && m_send_binary_data) - { - args = append_str_to_vector(args, arg_size, "-a"); - args = append_str_to_vector(args, arg_size, it->second[CD_CONTENT].c_str()); - } - } - - args = append_str_to_vector(args, arg_size, "-s"); - args = append_str_to_vector(args, arg_size, (pArgs[0] != '\0' ? pArgs : m_subject)); - args = append_str_to_vector(args, arg_size, "-r"); - args = append_str_to_vector(args, arg_size, m_email_from); - args = append_str_to_vector(args, arg_size, m_email_to); - - update_client(_("Sending an email...")); - const char *uid_str = get_crash_data_item_content_or_NULL(pCrashData, CD_UID); - exec_and_feed_input(xatoi_u(uid_str), dsc, args); - - free(dsc); - - while (*args) - { - free(*args++); - } - args -= arg_size; - free(args); - - return ssprintf("Email was sent to: %s", m_email_to); -} - -void CMailx::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - it = pSettings.find("Subject"); - if (it != end) - { - free(m_subject); - m_subject = xstrdup(it->second.c_str()); - } - it = pSettings.find("EmailFrom"); - if (it != end) - { - free(m_email_from); - m_email_from = xstrdup(it->second.c_str()); - } - it = pSettings.find("EmailTo"); - if (it != end) - { - free(m_email_to); - m_email_to = xstrdup(it->second.c_str()); - } - it = pSettings.find("SendBinaryData"); - if (it != end) - { - m_send_binary_data = string_to_bool(it->second.c_str()); - } -} - -PLUGIN_INFO(REPORTER, - CMailx, - "Mailx", - "0.0.2", - _("Sends an email with a report (via mailx command)"), - "zprikryl@redhat.com", - "https://fedorahosted.org/abrt/wiki", - PLUGINS_LIB_DIR"/Mailx.glade"); diff --git a/src/plugins/Mailx.h b/src/plugins/Mailx.h deleted file mode 100644 index 326a6371..00000000 --- a/src/plugins/Mailx.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Mailx.h - header file for Mailx reporter plugin - - it simple sends an email to specific address via mailx command - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 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. -*/ -#ifndef MAILX_H_ -#define MAILX_H_ - -#include <string> -#include "plugin.h" -#include "reporter.h" - -class CMailx : public CReporter -{ - private: - char *m_email_from; - char *m_email_to; - char *m_subject; - bool m_send_binary_data; - - public: - CMailx(); - ~CMailx(); - - virtual void SetSettings(const map_plugin_settings_t& pSettings); - - virtual std::string Report(const map_crash_data_t& pCrashData, - const map_plugin_settings_t& pSettings, - const char *pArgs); -}; - -#endif diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index b1b9fac1..c131e3ea 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -8,7 +8,6 @@ libexec_SCRIPTS = \ pluginslib_LTLIBRARIES = \ libCCpp.la \ libPython.la \ - libMailx.la \ libKerneloopsScanner.la \ libKerneloops.la \ libSQLite3.la @@ -73,11 +72,6 @@ libKerneloopsScanner_la_SOURCES = KerneloopsScanner.cpp KerneloopsScanner.h Kern libKerneloopsScanner_la_LDFLAGS = -avoid-version $(GLIB_LIBS) libKerneloopsScanner_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(GLIB_CFLAGS) -# Mailx -libMailx_la_SOURCES = Mailx.cpp Mailx.h -libMailx_la_LDFLAGS = -avoid-version -libMailx_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" -DLOCALSTATEDIR='"$(localstatedir)"' - # SQLite3 libSQLite3_la_SOURCES = SQLite3.cpp SQLite3.h libSQLite3_la_LDFLAGS = -avoid-version @@ -99,6 +93,7 @@ libexec_PROGRAMS = \ abrt-action-rhtsupport \ abrt-action-kerneloops \ abrt-action-upload \ + abrt-action-mailx \ abrt-action-print abrt_action_analyze_c_SOURCES = \ @@ -269,6 +264,26 @@ abrt_action_kerneloops_LDADD = \ ../../lib/utils/libABRTdUtils.la \ ../../lib/utils/libABRTUtils.la +abrt_action_mailx_SOURCES = \ + abrt-action-mailx.cpp +abrt_action_mailx_CPPFLAGS = \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../../lib/utils \ + -DBIN_DIR=\"$(bindir)\" \ + -DVAR_RUN=\"$(VAR_RUN)\" \ + -DCONF_DIR=\"$(CONF_DIR)\" \ + -DLOCALSTATEDIR='"$(localstatedir)"' \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \ + -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + $(GLIB_CFLAGS) \ + -D_GNU_SOURCE \ + -Wall -Werror +abrt_action_mailx_LDADD = \ + ../../lib/utils/libABRTdUtils.la \ + ../../lib/utils/libABRTUtils.la + abrt_action_print_SOURCES = \ abrt-action-print.cpp abrt_action_print_CPPFLAGS = \ diff --git a/src/plugins/abrt-action-mailx.cpp b/src/plugins/abrt-action-mailx.cpp new file mode 100644 index 00000000..9f33e8c1 --- /dev/null +++ b/src/plugins/abrt-action-mailx.cpp @@ -0,0 +1,182 @@ +/* + Mailx.cpp + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 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 "abrtlib.h" +#include "parse_options.h" +#include "crash_types.h" +#include "abrt_exception.h" + +#include "plugin.h" /* LoadPluginSettings */ + + +#define PROGNAME "abrt-action-mailx" + +static void exec_and_feed_input(uid_t uid, const char* text, char **args) +{ + int pipein[2]; + + pid_t child = fork_execv_on_steroids( + EXECFLG_INPUT | EXECFLG_QUIET | EXECFLG_SETGUID, + args, + pipein, + /*unsetenv_vec:*/ NULL, + /*dir:*/ NULL, + uid); + + full_write_str(pipein[1], text); + close(pipein[1]); + + int status; + waitpid(child, &status, 0); /* wait for command completion */ + if (status != 0) + error_msg_and_die("Error running '%s'", args[0]); +} + +static char** append_str_to_vector(char **vec, unsigned &size, const char *str) +{ + //log("old vec: %p", vec); + vec = (char**) xrealloc(vec, (size+2) * sizeof(vec[0])); + vec[size] = xstrdup(str); + //log("new vec: %p, added [%d] %p", vec, size, vec[size]); + size++; + vec[size] = NULL; + return vec; +} + +static void create_and_send_email( + const char *dump_dir_name, + const map_plugin_settings_t& settings) +{ + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + exit(1); /* error msg is already logged by dd_opendir */ + + map_crash_data_t pCrashData; + load_crash_data_from_debug_dump(dd, pCrashData); + dd_close(dd); + + char* env; + map_plugin_settings_t::const_iterator end = settings.end(); + map_plugin_settings_t::const_iterator it; + env = getenv("Mailx_Subject"); + it = settings.find("Subject"); + const char *subject = xstrdup(env ? env : (it != end ? it->second.c_str() : "[abrt] full crash report")); + env = getenv("Mailx_EmailFrom"); + it = settings.find("EmailFrom"); + const char *email_from = (env ? env : (it != end ? it->second.c_str() : "user@localhost")); + env = getenv("Mailx_EmailTo"); + it = settings.find("EmailTo"); + const char *email_to = (env ? env : (it != end ? it->second.c_str() : "root@localhost")); + env = getenv("Mailx_SendBinaryData"); + it = settings.find("SendBinaryData"); + bool send_binary_data = string_to_bool(env ? env : (it != end ? it->second.c_str() : "0")); + + char **args = NULL; + unsigned arg_size = 0; + args = append_str_to_vector(args, arg_size, "/bin/mailx"); + + char *dsc = make_dsc_mailx(pCrashData); + + if (send_binary_data) + { + map_crash_data_t::const_iterator it_cd; + for (it_cd = pCrashData.begin(); it_cd != pCrashData.end(); it_cd++) + { + if (it_cd->second[CD_TYPE] == CD_BIN) + { + args = append_str_to_vector(args, arg_size, "-a"); + args = append_str_to_vector(args, arg_size, it_cd->second[CD_CONTENT].c_str()); + } + } + } + + args = append_str_to_vector(args, arg_size, "-s"); + args = append_str_to_vector(args, arg_size, subject); + args = append_str_to_vector(args, arg_size, "-r"); + args = append_str_to_vector(args, arg_size, email_from); + args = append_str_to_vector(args, arg_size, email_to); + + log(_("Sending an email...")); + const char *uid_str = get_crash_data_item_content_or_NULL(pCrashData, CD_UID); + exec_and_feed_input(xatoi_u(uid_str), dsc, args); + + free(dsc); + + while (*args) + free(*args++); + args -= arg_size; + free(args); + + log("Email was sent to: %s", email_to); +} + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + const char *dump_dir_name = "."; + const char *conf_file = NULL; + + const char *program_usage = _( + PROGNAME" [-v] -d DIR [-c CONFFILE]\n" + "\n" + "Upload compressed tarball of crash dump" + ); + enum { + OPT_v = 1 << 0, + OPT_d = 1 << 1, + OPT_c = 1 << 2, + }; + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), + OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")), + OPT_END() + }; + + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + //msg_prefix = PROGNAME; + //if (optflags & OPT_s) + //{ + // openlog(msg_prefix, 0, LOG_DAEMON); + // logmode = LOGMODE_SYSLOG; + //} + + map_plugin_settings_t settings; + if (conf_file) + LoadPluginSettings(conf_file, settings); + + try + { + create_and_send_email(dump_dir_name, settings); + } + catch (CABRTException& e) + { + error_msg_and_die("%s", e.what()); + } + + return 0; +} |