From 35c31e425e4270996ce26c85701f8418be702b15 Mon Sep 17 00:00:00 2001 From: Gavin Romig-Koch Date: Tue, 23 Mar 2010 15:50:59 -0400 Subject: implement the strata submit signature plugin --- abrt.spec | 16 ++++ lib/Plugins/Makefile.am | 9 ++ lib/Plugins/StrataSignature.GTKBuilder | 125 ++++++++++++++++++++++++ lib/Plugins/StrataSignature.conf | 20 ++++ lib/Plugins/StrataSignature.cpp | 169 +++++++++++++++++++++++++++++++++ lib/Plugins/StrataSignature.h | 45 +++++++++ 6 files changed, 384 insertions(+) create mode 100644 lib/Plugins/StrataSignature.GTKBuilder create mode 100644 lib/Plugins/StrataSignature.conf create mode 100644 lib/Plugins/StrataSignature.cpp create mode 100644 lib/Plugins/StrataSignature.h diff --git a/abrt.spec b/abrt.spec index fc96d7a..3f1af31 100644 --- a/abrt.spec +++ b/abrt.spec @@ -40,6 +40,7 @@ BuildRequires: polkit-devel BuildRequires: libzip-devel, libtar-devel, bzip2-devel, zlib-devel BuildRequires: intltool BuildRequires: bison +BuildRequires: report-devel BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires: %{name}-libs = %{version}-%{release} Requires(pre): shadow-utils @@ -184,6 +185,15 @@ Requires: %{name} = %{version}-%{release} %description plugin-ticketuploader Plugin to report bugs into anonymous FTP site associated with ticketing system. +%package plugin-stratasignature +Summary: %{name}'s Strata Signature plugin +Group: System Environment/Libraries +Requires: %{name} = %{version}-%{release} +Requires: report + +%description plugin-stratasignature +Plugin to send signatures to Strata's signature service. + %package plugin-filetransfer Summary: %{name}'s File Transfer plugin Group: System Environment/Libraries @@ -429,6 +439,12 @@ fi %{_libdir}/%{name}/TicketUploader.GTKBuilder %{_mandir}/man7/%{name}-TicketUploader.7.gz +%files plugin-stratasignature +%defattr(-,root,root,-) +%config(noreplace) %{_sysconfdir}/%{name}/plugins/StrataSignature.conf +%{_libdir}/%{name}/libStrataSignature.so* +%{_libdir}/%{name}/StrataSignature.GTKBuilder + %files plugin-filetransfer %defattr(-,root,root,-) %config(noreplace) %{_sysconfdir}/%{name}/plugins/FileTransfer.conf diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 139e8b3..5b0424a 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -14,6 +14,7 @@ pluginslib_LTLIBRARIES = \ librhticket.la \ libCatcut.la \ libTicketUploader.la \ + libStrataSignature.la \ libPython.la \ libFileTransfer.la # libFirefox.la @@ -23,6 +24,7 @@ dist_pluginslib_DATA = \ Mailx.GTKBuilder \ Bugzilla.GTKBuilder \ TicketUploader.GTKBuilder \ + StrataSignature.GTKBuilder \ Catcut.GTKBuilder \ KerneloopsReporter.GTKBuilder @@ -36,6 +38,7 @@ dist_pluginsconf_DATA = \ Bugzilla.conf \ Catcut.conf \ TicketUploader.conf \ + StrataSignature.conf \ FileTransfer.conf \ Python.conf \ SOSreport.conf @@ -153,6 +156,12 @@ libTicketUploader_la_LDFLAGS = -avoid-version libTicketUploader_la_LIBADD = $(CURL_LIBS) libTicketUploader_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" +# StrataSignature +libStrataSignature_la_SOURCES = StrataSignature.h StrataSignature.cpp +libStrataSignature_la_LDFLAGS = -avoid-version +libStrataSignature_la_LIBADD = -lstrata_client +libStrataSignature_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" + # Python libPython_la_SOURCES = Python.h Python.cpp Python_hash.h Python_hash.cpp #libPython_la_LIBADD = $(NSS_LIBS) diff --git a/lib/Plugins/StrataSignature.GTKBuilder b/lib/Plugins/StrataSignature.GTKBuilder new file mode 100644 index 0000000..40947cc --- /dev/null +++ b/lib/Plugins/StrataSignature.GTKBuilder @@ -0,0 +1,125 @@ + + + + + + 5 + False + True + center-on-parent + abrt + normal + False + + + True + vertical + 2 + + + True + 0 + none + + + True + 6 + 12 + + + True + 1 + 2 + 12 + 6 + + + True + 0 + URL: + + + 2 + 3 + GTK_FILL + + + + + True + True + + + + 1 + 2 + 2 + 3 + + + + + + + + + True + <b>Ticket Uploader plugin configuration</b> + True + + + + + False + False + 1 + + + + + True + end + + + gtk-cancel + True + True + True + True + + + False + False + 0 + + + + + gtk-apply + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + button2 + bApply + + + + diff --git a/lib/Plugins/StrataSignature.conf b/lib/Plugins/StrataSignature.conf new file mode 100644 index 0000000..97f455c --- /dev/null +++ b/lib/Plugins/StrataSignature.conf @@ -0,0 +1,20 @@ +# Customer = "Example Inc." +# Ticket = IT12345 +# Encrypt = yes +# If set to "no" or commented out, +# compressed ticket data will be copied to /tmp: +# Upload = yes + +# If "Upload = yes", URL to upload the files to. +# supported: ftp, ftps, http, https, scp, sftp, tftp, file +# for example: ftp://user:password@server.name/directory +# or: scp://user:password@server.name:port/directory etc. +# for testing: file:///tmp/test_directory +# URL = + +# How many times we try to upload the file +# RetryCount = 3 + +# How long we wait between we retry the upload (in seconds) +# RetryDelay = 20 +Enabled = yes diff --git a/lib/Plugins/StrataSignature.cpp b/lib/Plugins/StrataSignature.cpp new file mode 100644 index 0000000..5f525fd --- /dev/null +++ b/lib/Plugins/StrataSignature.cpp @@ -0,0 +1,169 @@ +/* + StrataSignature.cpp + + 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 "abrt_xmlrpc.h" /* for xcurl_easy_init */ +#include "StrataSignature.h" +#include "DebugDump.h" +#include "ABRTException.h" +#include "CommLayerInner.h" + +#include "strata_client.h" + +using namespace std; + + +CStrataSignature::CStrataSignature() +{} + +CStrataSignature::~CStrataSignature() +{} + +string CStrataSignature::Report(const map_crash_data_t& pCrashData, + const map_plugin_settings_t& pSettings, + const char *pArgs) +{ + string URL; + + map_plugin_settings_t settings = parse_settings(pSettings); + if (!settings.empty()) + { + URL = settings["URL"]; + } + else + { + URL = m_sURL; + } + update_client(_("Creating a signature...")); + + reportfile_t* file = reportfile_start(1); + if (!file) + { + throw CABRTException(EXCEP_PLUGIN, "%s", strata_client_strerror()); + } + + // Copy each entry into the tarball root. + // Files are simply copied, strings are written to a file + // TODO: some files are totally useless: + // "Reported", "Message" (plugin's output), "DumpDir", + // "Description" (package description) - maybe skip those? + int rc; + map_crash_data_t::const_iterator it; + for (it = pCrashData.begin(); it != pCrashData.end(); it++) + { + const char *content = it->second[CD_CONTENT].c_str(); + if (it->second[CD_TYPE] == CD_TXT) + { + rc = reportfile_add_binding_from_string(file, + it->first.c_str(), + content, 0, 0); + if (rc < 0) + { + throw CABRTException(EXCEP_PLUGIN, "%s", strata_client_strerror()); + } + } + else if (it->second[CD_TYPE] == CD_BIN) + { + rc = reportfile_add_binding_from_namedfile(file, + it->first.c_str(), + content, 1, content); + if (rc < 0) + { + throw CABRTException(EXCEP_PLUGIN, "%s", strata_client_strerror()); + } + } + } + + rc = reportfile_end(file); + if (rc < 0) + { + throw CABRTException(EXCEP_PLUGIN, "%s", strata_client_strerror()); + } + + char* signature = reportfile_as_string(file); + if (!signature) + { + throw CABRTException(EXCEP_PLUGIN, "%s", strata_client_strerror()); + } + + rc = reportfile_free(file); + if (rc < 0) + { + throw CABRTException(EXCEP_PLUGIN, "%s", strata_client_strerror()); + } + + update_client(_("Creating a signature...")); + const char* p = post_signature(URL.c_str(), signature); + if (!p) + { + throw CABRTException(EXCEP_PLUGIN, "%s", strata_client_strerror()); + } + + string msg = p; + free((void*)p); + return msg; +} + +void CStrataSignature::SetSettings(const map_plugin_settings_t& pSettings) +{ + log("entering CStrataSignature::SetSettings"); + m_pSettings = pSettings; + + map_plugin_settings_t::const_iterator end = pSettings.end(); + map_plugin_settings_t::const_iterator it; + it = pSettings.find("URL"); + if (it != end) + { + m_sURL = it->second; + } +} + +const map_plugin_settings_t& CStrataSignature::GetSettings() +{ + m_pSettings["URL"] = m_sURL; + return m_pSettings; +} + +//todo: make static +map_plugin_settings_t CStrataSignature::parse_settings(const map_plugin_settings_t& pSettings) +{ + map_plugin_settings_t plugin_settings; + + map_plugin_settings_t::const_iterator end = pSettings.end(); + map_plugin_settings_t::const_iterator it; + + it = pSettings.find("URL"); + if (it == end) + { + plugin_settings.clear(); + return plugin_settings; + } + plugin_settings["URL"] = it->second; + VERB1 log("User settings ok, using them instead of defaults"); + return plugin_settings; +} + +PLUGIN_INFO(REPORTER, + CStrataSignature, + "StrataSignature", + "0.0.1", + "Sends a signature to a Strata signature service.", + "gavin@redhat.com", + "https://fedorahosted.org/abrt/wiki", + PLUGINS_LIB_DIR"/StrataSignature.GTKBuilder"); diff --git a/lib/Plugins/StrataSignature.h b/lib/Plugins/StrataSignature.h new file mode 100644 index 0000000..55db834 --- /dev/null +++ b/lib/Plugins/StrataSignature.h @@ -0,0 +1,45 @@ +/* + StrataSignature.h + + Submit a signature to Strata's signature service. + + Copyright (C) 2010 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 STRATASIGNATURE_H_ +#define STRATASIGNATURE_H_ + +#include "Plugin.h" +#include "Reporter.h" + +class CStrataSignature : public CReporter +{ + private: + std::string m_sURL; + map_plugin_settings_t parse_settings(const map_plugin_settings_t& pSettings); + + public: + CStrataSignature(); + virtual ~CStrataSignature(); + virtual const map_plugin_settings_t& GetSettings(); + 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 -- cgit