diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-02-18 11:57:56 +0100 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-02-18 11:57:56 +0100 |
| commit | 0979cbdd39166d6b5a42380e3ff6297e77d1236d (patch) | |
| tree | b6de00056eb26b5cd995db09b3dfcbb9ecbd21d6 /lib | |
| parent | 5c22d0c110b8678509817abf9ecf10e3f48525d5 (diff) | |
| parent | 77ef93c89e3fa75d1a5c0f126bcbb001a152bacf (diff) | |
| download | abrt-0979cbdd39166d6b5a42380e3ff6297e77d1236d.tar.gz abrt-0979cbdd39166d6b5a42380e3ff6297e77d1236d.tar.xz abrt-0979cbdd39166d6b5a42380e3ff6297e77d1236d.zip | |
Merge branch 'master' of git://git.fedorahosted.org/git/crash-catcher
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/MiddleWare/CrashTypes.h | 71 | ||||
| -rw-r--r-- | lib/MiddleWare/Database.h | 2 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 103 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.h | 46 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWareTypes.h | 13 | ||||
| -rw-r--r-- | lib/MiddleWare/Reporter.h | 15 | ||||
| -rw-r--r-- | lib/MiddleWare/Settings.h | 9 | ||||
| -rw-r--r-- | lib/MiddleWare/test.cpp | 10 | ||||
| -rw-r--r-- | lib/Plugins/Logger.conf | 5 | ||||
| -rw-r--r-- | lib/Plugins/Logger.cpp | 80 | ||||
| -rw-r--r-- | lib/Plugins/Logger.h | 33 | ||||
| -rw-r--r-- | lib/Plugins/Mailx.conf | 4 | ||||
| -rw-r--r-- | lib/Plugins/Mailx.cpp | 14 | ||||
| -rw-r--r-- | lib/Plugins/Mailx.h | 2 | ||||
| -rw-r--r-- | lib/Plugins/Makefile.am | 7 | ||||
| -rw-r--r-- | lib/Plugins/SQLite3.cpp | 4 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.cpp | 45 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.h | 2 | ||||
| -rw-r--r-- | lib/Utils/Packages.cpp | 113 | ||||
| -rw-r--r-- | lib/Utils/Packages.h | 10 |
20 files changed, 426 insertions, 162 deletions
diff --git a/lib/MiddleWare/CrashTypes.h b/lib/MiddleWare/CrashTypes.h new file mode 100644 index 0000000..3a4031c --- /dev/null +++ b/lib/MiddleWare/CrashTypes.h @@ -0,0 +1,71 @@ +#ifndef CRASHTYPES_H_ +#define CRASHTYPES_H_ + +#include <string> +#include <map> + +typedef std::map<std::string, std::string> map_crash_t; + +typedef struct SCrashInfo +{ + std::string m_sUUID; + std::string m_sUID; + std::string m_sCount; + std::string m_sExecutable; + std::string m_sPackage; + std::string m_sTime; + + const map_crash_t GetMap() + { + map_crash_t mci; + mci["UUID"] = m_sUUID; + mci["UID"] = m_sUID; + mci["Count"] = m_sCount; + mci["Executable"] = m_sExecutable; + mci["Package"] = m_sPackage; + mci["Time"] = m_sTime; + + return mci; + } +} crash_info_t; + +typedef std::vector<crash_info_t> vector_crash_infos_t; + +typedef struct SCrashContex +{ + std::string m_sUUID; + std::string m_sUID; + std::string m_sLanAppPlugin; +} crash_context_t; + + +typedef struct SCrashReport +{ + std::string m_sArchitecture; + std::string m_sKernel; + std::string m_sExecutable; + std::string m_sCmdLine; + std::string m_sPackage; + std::string m_sTextData1; + std::string m_sTextData2; + std::string m_sBinaryData1; + std::string m_sBinaryData2; + + const map_crash_t GetMap() + { + map_crash_t mci; + mci["Architecture"] = m_sArchitecture; + mci["Kernel"] = m_sKernel; + mci["Executable"] = m_sExecutable; + mci["CmdLine"] = m_sCmdLine; + mci["Package"] = m_sPackage; + mci["TextData1"] = m_sTextData1; + mci["TextData2"] = m_sTextData2; + mci["BinaryData1"] = m_sBinaryData1; + mci["BinaryData2"] = m_sBinaryData2; + + return mci; + } +} crash_report_t; + +#endif /* CRASHTYPES_H_ */ diff --git a/lib/MiddleWare/Database.h b/lib/MiddleWare/Database.h index 84099af..b634a70 100644 --- a/lib/MiddleWare/Database.h +++ b/lib/MiddleWare/Database.h @@ -46,7 +46,7 @@ typedef struct SDatabaseRow { std::string m_sUUID; std::string m_sUID; - std::string m_sDebugDumpPath; + std::string m_sDebugDumpDir; std::string m_sCount; std::string m_sReported; std::string m_sTime; diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp index 91eff06..2f86c00 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/lib/MiddleWare/MiddleWare.cpp @@ -85,31 +85,31 @@ void CMiddleWare::LoadSettings(const std::string& pPath) } } -void CMiddleWare::DebugDump2Report(const std::string& pDebugDumpDir, CReporter::report_t& pReport) +void CMiddleWare::DebugDump2Report(const std::string& pDebugDumpDir, crash_report_t& pCrashReport) { CDebugDump dd; dd.Open(pDebugDumpDir); - dd.LoadText(FILENAME_ARCHITECTURE, pReport.m_sArchitecture); - dd.LoadText(FILENAME_KERNEL, pReport.m_sKernel); - dd.LoadText(FILENAME_PACKAGE, pReport.m_sPackage); - dd.LoadText(FILENAME_EXECUTABLE, pReport.m_sExecutable); - dd.LoadText(FILENAME_CMDLINE, pReport.m_sCmdLine); + dd.LoadText(FILENAME_ARCHITECTURE, pCrashReport.m_sArchitecture); + dd.LoadText(FILENAME_KERNEL, pCrashReport.m_sKernel); + dd.LoadText(FILENAME_PACKAGE, pCrashReport.m_sPackage); + dd.LoadText(FILENAME_EXECUTABLE, pCrashReport.m_sExecutable); + dd.LoadText(FILENAME_CMDLINE, pCrashReport.m_sCmdLine); if (dd.Exist(FILENAME_TEXTDATA1)) { - dd.LoadText(FILENAME_TEXTDATA1, pReport.m_sTextData1); + dd.LoadText(FILENAME_TEXTDATA1, pCrashReport.m_sTextData1); } if (dd.Exist(FILENAME_TEXTDATA2)) { - dd.LoadText(FILENAME_TEXTDATA2, pReport.m_sTextData2); + dd.LoadText(FILENAME_TEXTDATA2, pCrashReport.m_sTextData2); } if (dd.Exist(FILENAME_BINARYDATA1)) { - pReport.m_bBinaryData1 = pDebugDumpDir + "/" + FILENAME_BINARYDATA1; + pCrashReport.m_sBinaryData1 = pDebugDumpDir + "/" + FILENAME_BINARYDATA1; } if (dd.Exist(FILENAME_BINARYDATA2)) { - pReport.m_bBinaryData2 = pDebugDumpDir + "/" + FILENAME_BINARYDATA2; + pCrashReport.m_sBinaryData2 = pDebugDumpDir + "/" + FILENAME_BINARYDATA2; } dd.Close(); } @@ -154,32 +154,9 @@ void CMiddleWare::CreateReportApplication(const std::string& pApplication, return application->CreateReport(pDebugDumpDir); } - -void CMiddleWare::CreateReport(const std::string& pDebugDumpDir, - crash_report_t& pCrashReport) -{ - CDebugDump dd; - dd.Open(pDebugDumpDir); - if (dd.Exist(FILENAME_APPLICATION)) - { - std::string application; - dd.LoadText(FILENAME_APPLICATION, application); - pCrashReport.m_sPlugin2ReportersName = application; - CreateReportApplication(application, pDebugDumpDir); - } - if (dd.Exist(FILENAME_LANGUAGE)) - { - std::string language; - dd.LoadText(FILENAME_LANGUAGE, language); - pCrashReport.m_sPlugin2ReportersName = language; - CreateReportLanguage(language, pDebugDumpDir); - } - DebugDump2Report(pDebugDumpDir, pCrashReport.m_Report); - dd.Close(); -} - void CMiddleWare::CreateReport(const std::string& pUUID, const std::string& pUID, + crash_context_t& pCrashContext, crash_report_t& pCrashReport) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); @@ -187,37 +164,55 @@ void CMiddleWare::CreateReport(const std::string& pUUID, database->Connect(); row = database->GetUUIDData(pUUID, pUID); database->DisConnect(); + if (row.m_sUUID != pUUID) { throw std::string("CMiddleWare::GetReport(): UUID '"+pUUID+"' is not in database."); } - pCrashReport.m_sUUID = pUUID; - pCrashReport.m_sUID = pUID; - CreateReport(row.m_sDebugDumpPath, pCrashReport); + + std::string appLan; + CDebugDump dd; + dd.Open(row.m_sDebugDumpDir); + if (dd.Exist(FILENAME_APPLICATION)) + { + dd.LoadText(FILENAME_APPLICATION, appLan); + CreateReportApplication(appLan, row.m_sDebugDumpDir); + } + if (dd.Exist(FILENAME_LANGUAGE)) + { + dd.LoadText(FILENAME_LANGUAGE, appLan); + CreateReportLanguage(appLan, row.m_sDebugDumpDir); + } + DebugDump2Report(row.m_sDebugDumpDir, pCrashReport); + dd.Close(); + pCrashContext.m_sLanAppPlugin = appLan; + pCrashContext.m_sUUID = pUUID; + pCrashContext.m_sUID = pUID; } -void CMiddleWare::Report(const crash_report_t& pCrashReport) +void CMiddleWare::Report(const crash_context_t& pCrashContext, + const crash_report_t& pCrashReport) { - std::string plugin2ReportersName = pCrashReport.m_sPlugin2ReportersName; - if (m_mapPlugin2Reporters.find(plugin2ReportersName) != m_mapPlugin2Reporters.end()) + std::string lanAppPlugin = pCrashContext.m_sLanAppPlugin; + if (m_mapPlugin2Reporters.find(lanAppPlugin) != m_mapPlugin2Reporters.end()) { set_reporters_t::iterator it_r; - for (it_r = m_mapPlugin2Reporters[plugin2ReportersName].begin(); - it_r != m_mapPlugin2Reporters[plugin2ReportersName].end(); + for (it_r = m_mapPlugin2Reporters[lanAppPlugin].begin(); + it_r != m_mapPlugin2Reporters[lanAppPlugin].end(); it_r++) { CReporter* reporter = m_pPluginManager->GetReporter(*it_r); - reporter->Report(pCrashReport.m_Report); + reporter->Report(pCrashReport); } } CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); database->Connect(); - database->SetReported(pCrashReport.m_sUUID, pCrashReport.m_sUID); + database->SetReported(pCrashContext.m_sUUID, pCrashContext.m_sUID); database->DisConnect(); } -int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& pCrashInfo) +int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); @@ -228,7 +223,7 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& std::string time; CDebugDump dd; - dd.Open(pDebugDumpPath); + dd.Open(pDebugDumpDir); dd.LoadText(FILENAME_PACKAGE, package); dd.LoadText(FILENAME_TIME, time); @@ -236,7 +231,7 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& if (package == "" || m_setBlackList.find(package.substr(0, package.find("-"))) != m_setBlackList.end()) { - dd.Delete(pDebugDumpPath); + dd.Delete(pDebugDumpDir); return 0; } @@ -244,13 +239,13 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& { std::string application; dd.LoadText(FILENAME_APPLICATION, application); - UUID = GetLocalUUIDApplication(application, pDebugDumpPath); + UUID = GetLocalUUIDApplication(application, pDebugDumpDir); } if (dd.Exist(FILENAME_LANGUAGE)) { std::string language; dd.LoadText(FILENAME_LANGUAGE, language); - UUID = GetLocalUUIDLanguage(language, pDebugDumpPath); + UUID = GetLocalUUIDLanguage(language, pDebugDumpDir); } if (UUID == "") { @@ -262,18 +257,18 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& database_row_t row; database->Connect(); - database->Insert(UUID, UID, pDebugDumpPath, time); + database->Insert(UUID, UID, pDebugDumpDir, time); row = database->GetUUIDData(UUID, UID); database->DisConnect(); if (row.m_sReported == "1") { - dd.Delete(pDebugDumpPath); + dd.Delete(pDebugDumpDir); return 0; } if (row.m_sCount != "1") { - dd.Delete(pDebugDumpPath); + dd.Delete(pDebugDumpDir); } dd.Close(); @@ -287,7 +282,7 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& return 1; } -CMiddleWare::vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID) +vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); vector_database_rows_t rows; @@ -306,7 +301,7 @@ CMiddleWare::vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& info.m_sUID = rows[ii].m_sUID; info.m_sCount = rows[ii].m_sCount; - dd.Open(rows[ii].m_sDebugDumpPath); + dd.Open(rows[ii].m_sDebugDumpDir); dd.LoadText(FILENAME_EXECUTABLE, data); info.m_sExecutable = data; dd.LoadText(FILENAME_PACKAGE, data); diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h index 71c85ef..ed94f8b 100644 --- a/lib/MiddleWare/MiddleWare.h +++ b/lib/MiddleWare/MiddleWare.h @@ -25,38 +25,15 @@ #define MIDDLEWARE_H_ #include "PluginManager.h" -#include <set> -#include <string> - +#include "CrashTypes.h" +#include "MiddleWareTypes.h" class CMiddleWare { - public: - - typedef struct SCrashInfo - { - std::string m_sUUID; - std::string m_sUID; - std::string m_sCount; - std::string m_sExecutable; - std::string m_sPackage; - std::string m_sTime; - } crash_info_t; - - typedef struct SCrashReport - { - std::string m_sUUID; - std::string m_sUID; - std::string m_sPlugin2ReportersName; - CReporter::report_t m_Report; - } crash_report_t; - - typedef std::vector<crash_info_t> vector_crash_infos_t; - private: - typedef set_settings_t set_blacklist_t; - typedef set_settings_t set_enabled_plugins_t; - typedef set_settings_t set_reporters_t; + typedef set_strings_t set_blacklist_t; + typedef set_strings_t set_enabled_plugins_t; + typedef set_strings_t set_reporters_t; typedef std::map<std::string, set_reporters_t> map_plugin2reporters_t; CPluginManager* m_pPluginManager; @@ -78,9 +55,7 @@ class CMiddleWare void LoadSettings(const std::string& pPath); void DebugDump2Report(const std::string& pDebugDumpDir, - CReporter::report_t& pReport); - void CreateReport(const std::string& pDebugDumpDir, - crash_report_t& pReport); + crash_report_t& pCrashReport); public: @@ -95,10 +70,13 @@ class CMiddleWare void CreateReport(const std::string& pUUID, const std::string& pUID, - crash_report_t& pReport); - void Report(const crash_report_t& pReport); + crash_context_t& pCrashContext, + crash_report_t& pCrashReport); + + void Report(const crash_context_t& pCrashContext, + const crash_report_t& pCrashReport); - int SaveDebugDump(const std::string& pDebugDumpPath, crash_info_t& pCrashInfo); + int SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo); vector_crash_infos_t GetCrashInfos(const std::string& pUID); }; diff --git a/lib/MiddleWare/MiddleWareTypes.h b/lib/MiddleWare/MiddleWareTypes.h new file mode 100644 index 0000000..f235056 --- /dev/null +++ b/lib/MiddleWare/MiddleWareTypes.h @@ -0,0 +1,13 @@ +#ifndef MIDDLEWARETYPES_H_ +#define MIDDLEWARETYPES_H_ + +#include <map> +#include <set> +#include <vector> +#include <string> + +typedef std::vector<std::string> vector_string_t; +typedef std::map<std::string, std::string> map_string_string_t; +typedef std::set<std::string> set_strings_t; + +#endif /* MIDDLEWARETYPES_H_ */ diff --git a/lib/MiddleWare/Reporter.h b/lib/MiddleWare/Reporter.h index 8f23065..80fe668 100644 --- a/lib/MiddleWare/Reporter.h +++ b/lib/MiddleWare/Reporter.h @@ -24,25 +24,14 @@ #include <string> #include "Plugin.h" +#include "CrashTypes.h" class CReporter : public CPlugin { public: - typedef struct SReport - { - std::string m_sArchitecture; - std::string m_sKernel; - std::string m_sExecutable; - std::string m_sCmdLine; - std::string m_sPackage; - std::string m_sTextData1; - std::string m_sTextData2; - std::string m_bBinaryData1; - std::string m_bBinaryData2; - } report_t; virtual ~CReporter() {} - virtual void Report(const report_t& pReport) = 0; + virtual void Report(const crash_report_t& pReport) = 0; }; #endif /* REPORTER_H_ */ diff --git a/lib/MiddleWare/Settings.h b/lib/MiddleWare/Settings.h index 46d50a5..1629ce9 100644 --- a/lib/MiddleWare/Settings.h +++ b/lib/MiddleWare/Settings.h @@ -22,13 +22,10 @@ #ifndef SETTINGSFUNC_H_ #define SETTINGSFUNC_H_ -#include "Settings.h" -#include <string> -#include <map> -#include <set> +#include "MiddleWareTypes.h" -typedef std::map<std::string, std::string> map_settings_t; -typedef std::set<std::string> set_settings_t; +typedef map_string_string_t map_settings_t; +typedef set_strings_t set_settings_t; void load_settings(const std::string& path, map_settings_t& settings); void save_settings(const std::string& path, const map_settings_t& settings); diff --git a/lib/MiddleWare/test.cpp b/lib/MiddleWare/test.cpp index 0c2dd31..c9e849a 100644 --- a/lib/MiddleWare/test.cpp +++ b/lib/MiddleWare/test.cpp @@ -21,6 +21,7 @@ #include "MiddleWare.h" #include "DebugDump.h" +#include "CrashTypes.h" #include <iostream> #include <sys/types.h> #include <unistd.h> @@ -46,7 +47,7 @@ int main(int argc, char** argv) dd.SaveBinary(FILENAME_BINARYDATA1, "ass0-9as", sizeof("ass0-9as")); /* Try to save it into DB */ - CMiddleWare::crash_info_t info; + crash_info_t info; if (middleWare.SaveDebugDump(std::string(DEBUG_DUMPS_DIR)+"/"+pid, info)) { std::cout << "Application Crashed! " << @@ -57,10 +58,11 @@ int main(int argc, char** argv) /* Get Report, so user can change data (remove private stuff) * If we do not want user interaction, just send data immediately */ - CMiddleWare::crash_report_t crashReport; - middleWare.CreateReport(info.m_sUUID, info.m_sUID, crashReport); + crash_context_t crashContext; + crash_report_t crashReport; + middleWare.CreateReport(info.m_sUUID, info.m_sUID, crashContext, crashReport); /* Report crash */ - middleWare.Report(crashReport); + middleWare.Report(crashContext, crashReport); } dd.Close(); } diff --git a/lib/Plugins/Logger.conf b/lib/Plugins/Logger.conf new file mode 100644 index 0000000..8cd0950 --- /dev/null +++ b/lib/Plugins/Logger.conf @@ -0,0 +1,5 @@ +# Configuration for Logger plugin + +Log_Path = /tmp/CCLogger + +Append_Logs = yes
\ No newline at end of file diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp new file mode 100644 index 0000000..0af8f07 --- /dev/null +++ b/lib/Plugins/Logger.cpp @@ -0,0 +1,80 @@ +#include "Logger.h" +#include <fstream> + +CLogger::CLogger() : + m_sLogPath("/tmp/CCLogger"), + m_bAppendLogs(true) +{} + +void CLogger::SetSettings(const map_settings_t& pSettings) +{ + if (pSettings.find("Log_Path")!= pSettings.end()) + { + m_sLogPath = pSettings.find("Log_Path")->second; + } + if (pSettings.find("Append_Logs")!= pSettings.end()) + { + m_bAppendLogs = pSettings.find("Append_Logs")->second == "yes"; + } +} + +void CLogger::Report(const crash_report_t& pReport) +{ + std::ofstream fOut; + if (m_bAppendLogs) + { + fOut.open(m_sLogPath.c_str(), std::ios::app); + } + else + { + fOut.open(m_sLogPath.c_str()); + } + if (fOut.is_open()) + { + fOut << "Common information" << std::endl; + fOut << "==================" << std::endl << std::endl; + fOut << "Architecture" << std::endl; + fOut << "------------" << std::endl; + fOut << pReport.m_sArchitecture << std::endl << std::endl; + fOut << "Kernel version" << std::endl; + fOut << "--------------" << std::endl; + fOut << pReport.m_sKernel << std::endl << std::endl; + fOut << "Package" << std::endl; + fOut << "-------" << std::endl; + fOut << pReport.m_sPackage << std::endl << std::endl; + fOut << "Executable" << std::endl; + fOut << "----------" << std::endl; + fOut << pReport.m_sExecutable << std::endl << std::endl; + fOut << "CmdLine" << std::endl; + fOut << "----------" << std::endl; + fOut << pReport.m_sCmdLine << std::endl << std::endl; + fOut << "Created report" << std::endl; + fOut << "==============" << std::endl; + fOut << "Text reports" << std::endl; + fOut << "==============" << std::endl; + if (pReport.m_sTextData1 != "") + { + fOut << "Text Data 1" << std::endl; + fOut << "-----------" << std::endl; + fOut << pReport.m_sTextData1 << std::endl << std::endl; + } + if (pReport.m_sTextData2 != "") + { + fOut << "Text Data 2" << std::endl; + fOut << "-----------" << std::endl; + fOut << pReport.m_sTextData2 << std::endl << std::endl; + } + fOut << "Binary reports" << std::endl; + fOut << "==============" << std::endl; + if (pReport.m_sBinaryData1 != "") + { + fOut << "1. " << pReport.m_sBinaryData1 << std::endl; + } + if (pReport.m_sBinaryData2 != "") + { + fOut << "2. " << pReport.m_sBinaryData2 << std::endl; + } + fOut << std::endl; + fOut.close(); + } +} diff --git a/lib/Plugins/Logger.h b/lib/Plugins/Logger.h new file mode 100644 index 0000000..509d2ab --- /dev/null +++ b/lib/Plugins/Logger.h @@ -0,0 +1,33 @@ +#ifndef LOGGER_H_ +#define LOGGER_H_ + +#include "Plugin.h" +#include "Reporter.h" + +class CLogger : public CReporter +{ + private: + std::string m_sLogPath; + bool m_bAppendLogs; + public: + CLogger(); + virtual ~CLogger() {} + + void Init() {} + void DeInit() {} + void SetSettings(const map_settings_t& pSettings); + + void Report(const crash_report_t& pReport); +}; + + +PLUGIN_INFO(REPORTER, + "Logger", + "0.0.1", + "Write a report to a specific file", + "zprikryl@redhat.com", + "https://fedorahosted.org/crash-catcher/wiki"); + +PLUGIN_INIT(CLogger); + +#endif /* LOGGER_H_ */ diff --git a/lib/Plugins/Mailx.conf b/lib/Plugins/Mailx.conf index 5e7b824..0ba7bcc 100644 --- a/lib/Plugins/Mailx.conf +++ b/lib/Plugins/Mailx.conf @@ -3,7 +3,7 @@ Parameters = # Your Email -Email_From = zprikryl@redhat.com +Email_From = user@localhost # Email To -Email_To = jmoskovc@redhat.com +Email_To = root@localhost diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp index cb26e39..2b8ef35 100644 --- a/lib/Plugins/Mailx.cpp +++ b/lib/Plugins/Mailx.cpp @@ -28,8 +28,8 @@ #define MAILX_SUBJECT "\"CrashCatcher automated bug report\"" CMailx::CMailx() : - m_sEmailFrom(""), - m_sEmailTo(""), + m_sEmailFrom("user@localhost"), + m_sEmailTo("root@localhost"), m_sParameters(""), m_sAttachments("") {} @@ -56,7 +56,7 @@ void CMailx::SendEmail(const std::string& pText) } -void CMailx::Report(const report_t& pReport) +void CMailx::Report(const crash_report_t& pReport) { std::stringstream ss; @@ -97,13 +97,13 @@ void CMailx::Report(const report_t& pReport) ss << "==============" << std::endl; ss << "See the attachment[s]" << std::endl; - if (pReport.m_bBinaryData1 != "") + if (pReport.m_sBinaryData1 != "") { - m_sAttachments = " -a " + pReport.m_bBinaryData1; + m_sAttachments = " -a " + pReport.m_sBinaryData1; } - if (pReport.m_bBinaryData2 != "") + if (pReport.m_sBinaryData2 != "") { - m_sAttachments = " -a " + pReport.m_bBinaryData2; + m_sAttachments = " -a " + pReport.m_sBinaryData2; } SendEmail(ss.str()); diff --git a/lib/Plugins/Mailx.h b/lib/Plugins/Mailx.h index 3c54feb..ab317eb 100644 --- a/lib/Plugins/Mailx.h +++ b/lib/Plugins/Mailx.h @@ -44,7 +44,7 @@ class CMailx : public CReporter void DeInit() {} void SetSettings(const map_settings_t& pSettings); - void Report(const report_t& pReport); + void Report(const crash_report_t& pReport); }; diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 612e614..db23497 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -1,9 +1,9 @@ AM_CPPFLAGS = -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils pluginslibdir=$(PLUGINS_LIB_DIR) -pluginslib_LTLIBRARIES = libCCpp.la libMailx.la libSQLite3.la +pluginslib_LTLIBRARIES = libCCpp.la libMailx.la libSQLite3.la libLogger.la pluginsconfdir=$(PLUGINS_CONF_DIR) -pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf +pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf # CCpp libCCpp_la_SOURCES = CCpp.cpp CCpp.h @@ -20,3 +20,6 @@ libSQLite3_la_LDFLAGS = -version-info 0:1:0 libSQLite3_la_LIBADD = $(SQLITE3_LIBS) libSQLite3_la_CPPFLAGS = -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(SQLITE3_CFLAGS) +# Logger +libLogger_la_SOURCES = Logger.cpp Logger.h +libLogger_la_LDFLAGS = -version-info 0:1:0 diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index c6cf8f4..f96f3fa 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -28,7 +28,7 @@ #define TABLE_NAME "CrashCatcher" CSQLite3::CSQLite3() : - m_sDBPath(""), + m_sDBPath("/tmp/CCDB"), m_pDB(NULL) {} @@ -79,7 +79,7 @@ void CSQLite3::GetTable(const std::string& pCommand, vector_database_rows_t& pTa break; case 1: row.m_sUID = table[jj + ncol]; break; - case 2: row.m_sDebugDumpPath = table[jj + ncol]; + case 2: row.m_sDebugDumpDir = table[jj + ncol]; break; case 3: row.m_sCount = table[jj + ncol]; break; diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 19d3a2b..f09de9e 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -38,7 +38,7 @@ CDebugDump::CDebugDump() : m_sDebugDumpDir(""), m_nFD(0), - m_bLockCreated(false) + m_bUnlock(true) {} void CDebugDump::Open(const std::string& pDir) @@ -77,35 +77,48 @@ void CDebugDump::Lock() std::string lockPath = m_sDebugDumpDir + ".lock"; if (ExistFileDir(lockPath)) { - if ((m_nFD = open(lockPath.c_str(), O_RDWR | O_CREAT, 0640)) < 0) + int res; + if ((m_nFD = open(lockPath.c_str(), O_RDWR)) < 0) { - throw std::string("CDebugDump::Create(): can not create lock file"); + throw std::string("CDebugDump::Lock(): can not create lock file"); } - m_bLockCreated = false; - } - else - { - if ((m_nFD = open(lockPath.c_str(), O_RDWR | O_CREAT, 0640)) < 0) + res = lockf(m_nFD, F_TEST, 0); + if (res < 0) + { + throw std::string("CDebugDump::Lock(): cannot lock DebugDump"); + } + else if (res == 0) { - throw std::string("CDebugDump::Create(): can not create lock file"); + close(m_nFD); + m_bUnlock = false; + return; } - m_bLockCreated = true; + while (ExistFileDir(lockPath)) + { + std::cerr << "CDebugDump::Lock(): waiting..." << std::endl; + usleep(10); + } + } + + if ((m_nFD = open(lockPath.c_str(), O_RDWR | O_CREAT, 0640)) < 0) + { + throw std::string("CDebugDump::Lock(): can not create lock file"); } if (lockf(m_nFD,F_LOCK, 0) < 0) { - throw std::string("CDebugDump::Create(): cannot lock DebugDump"); + throw std::string("CDebugDump::Lock(): cannot lock DebugDump"); } } void CDebugDump::UnLock() { std::string lockPath = m_sDebugDumpDir + ".lock"; - lockf(m_nFD,F_ULOCK, 0); - close(m_nFD); - if (m_bLockCreated) + if (m_bUnlock) { + lockf(m_nFD,F_ULOCK, 0); + close(m_nFD); remove(lockPath.c_str()); - m_bLockCreated = false; + m_bUnlock = true; } } @@ -330,7 +343,7 @@ void CDebugDump::SavePackage() { CPackages packages; LoadText(FILENAME_EXECUTABLE, executable); - package = packages.SearchFile("/usr/sbin/acpid"); + package = packages.SearchFile(executable); } SaveText(FILENAME_PACKAGE, package); } diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index a6bb051..b32dfeb 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -44,7 +44,7 @@ class CDebugDump private: std::string m_sDebugDumpDir; int m_nFD; - bool m_bLockCreated; + bool m_bUnlock; void SaveEnvironment(); void SaveTime(); diff --git a/lib/Utils/Packages.cpp b/lib/Utils/Packages.cpp index 4c94ef6..e93c292 100644 --- a/lib/Utils/Packages.cpp +++ b/lib/Utils/Packages.cpp @@ -20,10 +20,8 @@ */ #include "Packages.h" -#include <rpm/rpmts.h> -#include <rpm/rpmdb.h> #include <rpm/rpmcli.h> -#include <sstream> +#include <iostream> CPackages::CPackages() : @@ -32,7 +30,29 @@ CPackages::CPackages() : { g_type_init(); m_pPkClient = pk_client_new(); -// pk_client_set_synchronous (m_pPkClient, TRUE, NULL); + + uint8_t* pkt = NULL; + size_t pklen; + pgpKeyID_t keyID; + char *argv[] = {(char*)""}; + poptContext context = rpmcliInit(0, argv, NULL); + + // TODO: make this configurable + + pgpReadPkts("/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora", &pkt, &pklen); + if (pgpPubkeyFingerprint(pkt, pklen, keyID) == 0) + { + char* fedoraFingerprint = pgpHexStr(keyID, sizeof(keyID)); + if (fedoraFingerprint != NULL) + { + m_setFingerprints.insert(fedoraFingerprint); + } + } + if (pkt) + { + free(pkt); + } + rpmcliFini(context); } CPackages::~CPackages() @@ -40,33 +60,88 @@ CPackages::~CPackages() g_object_unref(m_pPkClient); } +bool CPackages::CheckFingerprint(const Header& pHeader) +{ + if (!headerIsEntry(pHeader, RPMTAG_SIGGPG)) + { + return false; + } + std::cout << "aaa" << std::endl; + char* headerFingerprint; + rpmtd td = rpmtdNew(); + headerGet(pHeader, RPMTAG_SIGGPG, td, HEADERGET_DEFAULT); + headerFingerprint = pgpHexStr((const uint8_t*)td->data + 9, sizeof(pgpKeyID_t)); + rpmtdFree(td); + if (headerFingerprint != NULL) + { + if (m_setFingerprints.find(headerFingerprint) == m_setFingerprints.end()) + { + free(headerFingerprint); + return false; + } + free(headerFingerprint); + return true; + } + return false; +} + +bool CPackages::CheckHash(const Header& pHeader, const rpmts& pTs, const std::string&pPath) +{ + rpmfi fi = rpmfiNew(pTs, pHeader, RPMTAG_BASENAMES, 0); + pgpHashAlgo hashAlgo; + std::string headerHash; + char computedHash[1024] = ""; + + while(rpmfiNext(fi) != -1) + { + if (pPath == rpmfiFN(fi)) + { + headerHash = rpmfiFDigestHex(fi, &hashAlgo); + } + } + rpmfiFree(fi); + + rpmDoDigest(hashAlgo, pPath.c_str(), 1, (unsigned char*) computedHash, NULL); + + if (headerHash == "" || std::string(computedHash) == "") + { + return false; + } + else if (headerHash == computedHash) + { + return true; + } + return false; +} + std::string CPackages::SearchFile(const std::string& pPath) { - std::stringstream ss; + std::string ret = ""; char *argv[] = {(char*)""}; poptContext context = rpmcliInit(0, argv, NULL); rpmts ts = rpmtsCreate(); rpmdbMatchIterator iter = rpmtsInitIterator(ts, RPMTAG_BASENAMES, pPath.c_str(), 0); Header header; - char* nerv = NULL; - if ((header = rpmdbNextIterator(iter)) != NULL) { - nerv = headerGetNEVR(header, NULL); + if (CheckFingerprint(header)) + { + char* nerv = headerGetNEVR(header, NULL); + if (nerv != NULL) + { + if (CheckHash(header, ts, pPath)) + { + ret = nerv; + free(nerv); + } + } + } } - headerFree(header); - rpmcliFini(context); + rpmdbFreeIterator(iter); rpmtsFree(ts); - - if (nerv != NULL) - { - std::string ret = nerv; - free(nerv); - return ret; - } - - return ""; + rpmcliFini(context); + return ret; } bool CPackages::Install(const std::string& pPackage) diff --git a/lib/Utils/Packages.h b/lib/Utils/Packages.h index 9874dd7..67e5f24 100644 --- a/lib/Utils/Packages.h +++ b/lib/Utils/Packages.h @@ -25,14 +25,24 @@ #include <glib.h> #include <packagekit-glib/packagekit.h> #include <string> +#include <set> +#include <rpm/rpmts.h> +#include <rpm/rpmdb.h> class CPackages { private: + typedef std::set<std::string> set_fingerprints_t; PkClient *m_pPkClient; bool m_bBusy; + set_fingerprints_t m_setFingerprints; + + + bool CheckFingerprint(const Header& pHeader); + bool CheckHash(const Header& pHeader, const rpmts& pTs, const std::string&pPath); + public: CPackages(); ~CPackages(); |
