summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-02-19 15:23:00 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-02-19 15:23:00 +0100
commit2f907417d37d83cefad7950397bd141c0586b1d5 (patch)
tree12d58967607cac7f300e7dcaee456fdfe9bd95a1 /lib
parentb472b75f70c7e9144fb29f9d142e9f52f4caab39 (diff)
parent0c899d52e5e42caf8c5c394ef6c142c08ac38858 (diff)
downloadabrt-2f907417d37d83cefad7950397bd141c0586b1d5.tar.gz
abrt-2f907417d37d83cefad7950397bd141c0586b1d5.tar.xz
abrt-2f907417d37d83cefad7950397bd141c0586b1d5.zip
Merge branch 'master' of git://git.fedorahosted.org/git/crash-catcher
Conflicts: lib/DBus/Makefile.am lib/DBus/dbus-crash-catcher.conf lib/DBus/dbus-crashcatcher.conf src/Daemon/Makefile.am src/Daemon/dbus-crashcatcher.conf
Diffstat (limited to 'lib')
-rw-r--r--lib/MiddleWare/Makefile.am13
-rw-r--r--lib/MiddleWare/MiddleWare.cpp47
-rw-r--r--lib/MiddleWare/MiddleWare.h5
-rw-r--r--lib/MiddleWare/RPMInfo.cpp119
-rw-r--r--lib/MiddleWare/RPMInfo.h (renamed from lib/Utils/Packages.h)39
-rw-r--r--lib/MiddleWare/crash-catcher.conf (renamed from lib/MiddleWare/CrashCatcher.conf)4
-rw-r--r--lib/MiddleWare/test.cpp3
-rw-r--r--lib/Plugins/CCpp.cpp42
-rw-r--r--lib/Plugins/CCpp.h2
-rw-r--r--lib/Plugins/Logger.conf4
-rw-r--r--lib/Plugins/Logger.cpp29
-rw-r--r--lib/Plugins/Logger.h22
-rw-r--r--lib/Plugins/Mailx.conf4
-rw-r--r--lib/Plugins/Mailx.cpp8
-rw-r--r--lib/Plugins/Makefile.am2
-rw-r--r--lib/Utils/DebugDump.cpp46
-rw-r--r--lib/Utils/DebugDump.h5
-rw-r--r--lib/Utils/Makefile.am6
-rw-r--r--lib/Utils/Packages.cpp170
19 files changed, 316 insertions, 254 deletions
diff --git a/lib/MiddleWare/Makefile.am b/lib/MiddleWare/Makefile.am
index 2b63f85..f95253f 100644
--- a/lib/MiddleWare/Makefile.am
+++ b/lib/MiddleWare/Makefile.am
@@ -2,17 +2,20 @@ lib_LTLIBRARIES = libMiddleWare.la
libMiddleWare_la_SOURCES = MiddleWare.cpp MiddleWare.h PluginManager.cpp \
PluginManager.h CrashCatcherPlugin.cpp \
CrashCatcherPlugin.h DynamicLibrary.cpp \
- DynamicLibrary.h Settings.h Settings.cpp
-libMiddleWare_la_LIBADD = $(DL_LIBS) ../Utils/libUtils.la
+ DynamicLibrary.h Settings.h Settings.cpp \
+ RPMInfo.cpp RPMInfo.h Plugin.h CrashTypes.h \
+ MiddleWareTypes.h Application.h Database.h \
+ Reporter.h Language.h
+libMiddleWare_la_LIBADD = $(DL_LIBS) ../Utils/libUtils.la $(RPM_LIBS)
libMiddleWare_la_LDFLAGS = -version-info 0:1:0
-libMiddleWare_la_CPPFLAGS = -I$(srcdir)/../Utils
+libMiddleWare_la_CPPFLAGS = -I$(srcdir)/../Utils $(RPM_CFLAGS)
middlewareconfdir = $(CONF_DIR)
-middlewareconf_DATA = CrashCatcher.conf
+dist_middlewareconf_DATA = crash-catcher.conf
check_PROGRAMS = test
test_SOURCES = test.cpp
-test_LDADD = ../Utils/libUtils.la libMiddleWare.la $(DL_LIBS)
+test_LDADD = ../Utils/libUtils.la libMiddleWare.la $(DL_LIBS) $(RPM_LIBS)
test_CPPFLAGS = -I$(srcdir)/../Utils \
-DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
-DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp
index 2f86c00..f4f50df 100644
--- a/lib/MiddleWare/MiddleWare.cpp
+++ b/lib/MiddleWare/MiddleWare.cpp
@@ -26,7 +26,8 @@
CMiddleWare::CMiddleWare(const std::string& pPlugisConfDir,
const std::string& pPlugisLibDir,
const std::string& pMiddleWareConfFile) :
- m_pPluginManager(NULL)
+ m_pPluginManager(NULL),
+ m_bOpenGPGCheck(true)
{
m_pPluginManager = new CPluginManager(pPlugisConfDir, pPlugisLibDir);
if (m_pPluginManager == NULL)
@@ -61,6 +62,19 @@ void CMiddleWare::LoadSettings(const std::string& pPath)
{
parse_settings(settings["EnabledPlugins"], m_setEnabledPlugins);
}
+ if (settings.find("OpenGPGPublicKeys") != settings.end())
+ {
+ parse_settings(settings["OpenGPGPublicKeys"], m_setOpenGPGKeys);
+ set_opengpg_keys_t::iterator it_k;
+ for (it_k = m_setOpenGPGKeys.begin(); it_k != m_setOpenGPGKeys.end(); it_k++)
+ {
+ m_RPMInfo.LoadOpenGPGPublicKey(*it_k);
+ }
+ }
+ if (settings.find("EnableOpenGPG") != settings.end())
+ {
+ m_bOpenGPGCheck = settings["EnableOpenGPG"] == "yes";
+ }
if (settings.find("Database") != settings.end())
{
m_sDatabase = settings["Database"];
@@ -211,7 +225,7 @@ void CMiddleWare::Report(const crash_context_t& pCrashContext,
database->SetReported(pCrashContext.m_sUUID, pCrashContext.m_sUID);
database->DisConnect();
}
-
+#include <iostream>
int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo)
{
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
@@ -225,15 +239,25 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p
CDebugDump dd;
dd.Open(pDebugDumpDir);
- dd.LoadText(FILENAME_PACKAGE, package);
- dd.LoadText(FILENAME_TIME, time);
-
- if (package == "" ||
- m_setBlackList.find(package.substr(0, package.find("-"))) != m_setBlackList.end())
+ dd.LoadText(FILENAME_EXECUTABLE, executable);
+ package = m_RPMInfo.GetPackage(executable);
+ std::string packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1));
+ if (packageName == "" ||
+ (m_setBlackList.find(packageName) != m_setBlackList.end()))
{
- dd.Delete(pDebugDumpDir);
+ dd.Delete();
return 0;
}
+ if (m_bOpenGPGCheck)
+ {
+ if (!m_RPMInfo.CheckFingerprint(packageName) ||
+ !m_RPMInfo.CheckHash(packageName, executable))
+ {
+ dd.Delete();
+ return 0;
+ }
+ }
+ dd.SaveText(FILENAME_PACKAGE, package);
if (dd.Exist(FILENAME_APPLICATION))
{
@@ -252,8 +276,8 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p
throw std::string("CMiddleWare::SaveDebugDumpToDataBase(): Wrong UUID.");
}
+ dd.LoadText(FILENAME_TIME, time);
dd.LoadText(FILENAME_UID, UID);
- dd.LoadText(FILENAME_EXECUTABLE, executable);
database_row_t row;
database->Connect();
@@ -263,12 +287,12 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p
if (row.m_sReported == "1")
{
- dd.Delete(pDebugDumpDir);
+ dd.Delete();
return 0;
}
if (row.m_sCount != "1")
{
- dd.Delete(pDebugDumpDir);
+ dd.Delete();
}
dd.Close();
@@ -300,6 +324,7 @@ vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID)
info.m_sUUID = rows[ii].m_sUUID;
info.m_sUID = rows[ii].m_sUID;
info.m_sCount = rows[ii].m_sCount;
+ info.m_sTime = rows[ii].m_sTime;
dd.Open(rows[ii].m_sDebugDumpDir);
dd.LoadText(FILENAME_EXECUTABLE, data);
diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h
index ed94f8b..d2cd8a2 100644
--- a/lib/MiddleWare/MiddleWare.h
+++ b/lib/MiddleWare/MiddleWare.h
@@ -27,6 +27,7 @@
#include "PluginManager.h"
#include "CrashTypes.h"
#include "MiddleWareTypes.h"
+#include "RPMInfo.h"
class CMiddleWare
{
@@ -34,14 +35,18 @@ class CMiddleWare
typedef set_strings_t set_blacklist_t;
typedef set_strings_t set_enabled_plugins_t;
typedef set_strings_t set_reporters_t;
+ typedef set_strings_t set_opengpg_keys_t;
typedef std::map<std::string, set_reporters_t> map_plugin2reporters_t;
CPluginManager* m_pPluginManager;
+ CRPMInfo m_RPMInfo;
set_blacklist_t m_setBlackList;
set_enabled_plugins_t m_setEnabledPlugins;
+ set_opengpg_keys_t m_setOpenGPGKeys;
std::string m_sDatabase;
map_plugin2reporters_t m_mapPlugin2Reporters;
+ bool m_bOpenGPGCheck;
std::string GetLocalUUIDLanguage(const std::string& pLanguage,
const std::string& pDebugDumpDir);
diff --git a/lib/MiddleWare/RPMInfo.cpp b/lib/MiddleWare/RPMInfo.cpp
new file mode 100644
index 0000000..55dccd2
--- /dev/null
+++ b/lib/MiddleWare/RPMInfo.cpp
@@ -0,0 +1,119 @@
+#include "RPMInfo.h"
+#include <iostream>
+
+CRPMInfo::CRPMInfo()
+{
+ char *argv[] = {(char*)""};
+ m_poptContext = rpmcliInit(0, argv, NULL);
+}
+
+CRPMInfo::~CRPMInfo()
+{
+ rpmcliFini(m_poptContext);
+}
+
+void CRPMInfo::LoadOpenGPGPublicKey(const std::string& pFileName)
+{
+ uint8_t* pkt = NULL;
+ size_t pklen;
+ pgpKeyID_t keyID;
+ pgpReadPkts(pFileName.c_str(), &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);
+ }
+}
+
+bool CRPMInfo::CheckFingerprint(const std::string& pPackage)
+{
+ bool ret = false;
+ rpmts ts = rpmtsCreate();
+ rpmdbMatchIterator iter = rpmtsInitIterator(ts, RPMTAG_NAME, pPackage.c_str(), 0);
+ Header header;
+ if ((header = rpmdbNextIterator(iter)) != NULL)
+ {
+ if (headerIsEntry(header, RPMTAG_SIGGPG))
+ {
+ char* headerFingerprint;
+ rpmtd td = rpmtdNew();
+ headerGet(header, 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);
+ ret = true;
+ }
+ }
+ }
+ }
+ rpmdbFreeIterator(iter);
+ rpmtsFree(ts);
+ return ret;
+}
+
+bool CRPMInfo::CheckHash(const std::string& pPackage, const std::string& pPath)
+{
+ bool ret = false;
+ rpmts ts = rpmtsCreate();
+ rpmdbMatchIterator iter = rpmtsInitIterator(ts, RPMTAG_NAME, pPackage.c_str(), 0);
+ Header header;
+ if ((header = rpmdbNextIterator(iter)) != NULL)
+ {
+ rpmfi fi = rpmfiNew(ts, header, 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 != "" && headerHash == computedHash)
+ {
+ ret = true;
+ }
+ }
+ rpmdbFreeIterator(iter);
+ rpmtsFree(ts);
+ return ret;
+}
+
+std::string CRPMInfo::GetPackage(const std::string& pFileName)
+{
+ std::string ret = "";
+ rpmts ts = rpmtsCreate();
+ rpmdbMatchIterator iter = rpmtsInitIterator(ts, RPMTAG_BASENAMES, pFileName.c_str(), 0);
+ Header header;
+ if ((header = rpmdbNextIterator(iter)) != NULL)
+ {
+ char* nerv = headerGetNEVR(header, NULL);
+ if (nerv != NULL)
+ {
+ ret = nerv;
+ free(nerv);
+ }
+ }
+
+ rpmdbFreeIterator(iter);
+ rpmtsFree(ts);
+ return ret;
+}
+
diff --git a/lib/Utils/Packages.h b/lib/MiddleWare/RPMInfo.h
index 67e5f24..2850fd6 100644
--- a/lib/Utils/Packages.h
+++ b/lib/MiddleWare/RPMInfo.h
@@ -1,5 +1,6 @@
/*
- Packages.h - PackageKit wrapper
+ RPMInfo.h - header file for rpm database
+ - it implements query for local rpm database
Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
Copyright (C) 2009 RedHat inc.
@@ -19,37 +20,33 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef PACKAGES_H_
-#define PACKAGES_H_
+#ifndef RPMINFO_H_
+#define RPMINFO_H_
-#include <glib.h>
-#include <packagekit-glib/packagekit.h>
-#include <string>
-#include <set>
+#include "MiddleWareTypes.h"
+
+#include <rpm/rpmcli.h>
#include <rpm/rpmts.h>
#include <rpm/rpmdb.h>
-class CPackages
+class CRPMInfo
{
private:
- typedef std::set<std::string> set_fingerprints_t;
- PkClient *m_pPkClient;
- bool m_bBusy;
+ typedef set_strings_t set_fingerprints_t;
+ poptContext m_poptContext;
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();
- std::string SearchFile(const std::string& pPath);
+ CRPMInfo();
+ ~CRPMInfo();
+
+ void LoadOpenGPGPublicKey(const std::string& pFileName);
- bool Install(const std::string& pPackage);
- bool GetInstallationStatus();
+ bool CheckFingerprint(const std::string& pPackage);
+ bool CheckHash(const std::string& pPackage, const std::string&pPath);
+ std::string GetPackage(const std::string& pFileName);
};
-#endif /* PACKAGES_H_ */
+#endif /* RPMINFO_H_ */
diff --git a/lib/MiddleWare/CrashCatcher.conf b/lib/MiddleWare/crash-catcher.conf
index e865ebe..d8adce7 100644
--- a/lib/MiddleWare/CrashCatcher.conf
+++ b/lib/MiddleWare/crash-catcher.conf
@@ -1,4 +1,8 @@
# test conf file. it will be generated in the future
+# Enable GPG check
+EnableOpenGPG = yes
+# GPG keys
+OpenGPGPublicKeys = /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
# blacklisted packages
BlackList = bash, bind, apache2
# enabled plugins
diff --git a/lib/MiddleWare/test.cpp b/lib/MiddleWare/test.cpp
index c9e849a..3c2a055 100644
--- a/lib/MiddleWare/test.cpp
+++ b/lib/MiddleWare/test.cpp
@@ -35,14 +35,13 @@ int main(int argc, char** argv)
{
CMiddleWare middleWare(PLUGINS_CONF_DIR,
PLUGINS_LIB_DIR,
- std::string(CONF_DIR) + "/CrashCatcher.conf");
+ std::string(CONF_DIR) + "/crash-catcher.conf");
/* Create DebugDump */
CDebugDump dd;
char pid[100];
sprintf(pid, "%d", getpid());
dd.Create(std::string(DEBUG_DUMPS_DIR)+"/"+pid);
dd.SaveProc(pid);
- dd.SavePackage();
dd.SaveText(FILENAME_LANGUAGE, "CCpp");
dd.SaveBinary(FILENAME_BINARYDATA1, "ass0-9as", sizeof("ass0-9as"));
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 59b2f0e..f2c1723 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -24,14 +24,51 @@
#include <ctype.h>
#include "DebugDump.h"
#include <sstream>
+#include <iostream>
#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern"
#define CORE_PATTERN "|"CCPP_HOOK_PATH" %p %s"
+#define DEBUGINFO_INSTALL "debuginfo-install -y "
+
CLanguageCCpp::CLanguageCCpp() :
m_bMemoryMap(false)
{}
+void CLanguageCCpp::InstallDebugInfos(const std::string& pPackage)
+{
+ char line[1024];
+ std::string command = DEBUGINFO_INSTALL + pPackage;
+ std::string packageName = pPackage.substr(0, pPackage.rfind("-", pPackage.rfind("-") - 1));
+ std::string packageERV = pPackage.substr(packageName.length());
+ std::string installed = "Package "+packageName+"-debuginfo"+packageERV+" already installed and latest version";
+ std::string canNotInstall = "No debuginfo packages available to install";
+ FILE *fp = popen(command.c_str(), "r");
+ if (fp == NULL)
+ {
+ throw "CLanguageCCpp::InstallDebugInfos(): cannot install debuginfos for " + pPackage ;
+ }
+ while (fgets(line, sizeof(line), fp))
+ {
+ std::string text = line;
+ std::cerr << text;
+ if (text.find(installed) != std::string::npos)
+ {
+ pclose(fp);
+ return;
+ }
+ if (text.find(canNotInstall) != std::string::npos)
+ {
+ pclose(fp);
+ throw "CLanguageCCpp::InstallDebugInfos(): cannot install debuginfos for " + pPackage ;
+ }
+ }
+ if (pclose(fp) != 0)
+ {
+ throw "CLanguageCCpp::InstallDebugInfos(): cannot install debuginfos for " + pPackage ;
+ }
+}
+
std::string CLanguageCCpp::GetLocalUUID(const std::string& pDebugDumpDir)
{
std::stringstream ss;
@@ -60,10 +97,13 @@ std::string CLanguageCCpp::GetGlobalUUID(const std::string& pDebugDumpDir)
void CLanguageCCpp::CreateReport(const std::string& pDebugDumpDir)
{
+ std::string package;
CDebugDump dd;
dd.Open(pDebugDumpDir);
+ dd.LoadText(FILENAME_PACKAGE, package);
+
+ InstallDebugInfos(package);
- // TODO: install or mount debug-infos, gun gdb/archer and get backtrace
dd.SaveText(FILENAME_TEXTDATA1, "backtrace of the crashed C/C++ application");
if (m_bMemoryMap)
{
diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h
index e1c2015..319a789 100644
--- a/lib/Plugins/CCpp.h
+++ b/lib/Plugins/CCpp.h
@@ -32,6 +32,8 @@ class CLanguageCCpp : public CLanguage
private:
bool m_bMemoryMap;
std::string m_sOldCorePattern;
+ void InstallDebugInfos(const std::string& pPackage);
+
public:
CLanguageCCpp();
virtual ~CLanguageCCpp() {}
diff --git a/lib/Plugins/Logger.conf b/lib/Plugins/Logger.conf
index 8cd0950..b720b3b 100644
--- a/lib/Plugins/Logger.conf
+++ b/lib/Plugins/Logger.conf
@@ -1,5 +1,5 @@
# Configuration for Logger plugin
-Log_Path = /tmp/CCLogger
+LogPath = /tmp/CCLogger
-Append_Logs = yes \ No newline at end of file
+AppendLogs = yes \ No newline at end of file
diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp
index 0af8f07..68734df 100644
--- a/lib/Plugins/Logger.cpp
+++ b/lib/Plugins/Logger.cpp
@@ -1,3 +1,24 @@
+/*
+ Logger.cpp - it simple writes report to specific file
+
+ 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 "Logger.h"
#include <fstream>
@@ -8,13 +29,13 @@ CLogger::CLogger() :
void CLogger::SetSettings(const map_settings_t& pSettings)
{
- if (pSettings.find("Log_Path")!= pSettings.end())
+ if (pSettings.find("LogPath")!= pSettings.end())
{
- m_sLogPath = pSettings.find("Log_Path")->second;
+ m_sLogPath = pSettings.find("LogPath")->second;
}
- if (pSettings.find("Append_Logs")!= pSettings.end())
+ if (pSettings.find("AppendLogs")!= pSettings.end())
{
- m_bAppendLogs = pSettings.find("Append_Logs")->second == "yes";
+ m_bAppendLogs = pSettings.find("AppendLogs")->second == "yes";
}
}
diff --git a/lib/Plugins/Logger.h b/lib/Plugins/Logger.h
index 509d2ab..9a4e304 100644
--- a/lib/Plugins/Logger.h
+++ b/lib/Plugins/Logger.h
@@ -1,3 +1,25 @@
+/*
+ Logger.h - header file for Logger reporter plugin
+ - it simple writes report to specific file
+
+ 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 LOGGER_H_
#define LOGGER_H_
diff --git a/lib/Plugins/Mailx.conf b/lib/Plugins/Mailx.conf
index 0ba7bcc..bfbbff8 100644
--- a/lib/Plugins/Mailx.conf
+++ b/lib/Plugins/Mailx.conf
@@ -3,7 +3,7 @@
Parameters =
# Your Email
-Email_From = user@localhost
+EmailFrom = user@localhost
# Email To
-Email_To = root@localhost
+EmailTo = root@localhost
diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp
index 2b8ef35..13563c5 100644
--- a/lib/Plugins/Mailx.cpp
+++ b/lib/Plugins/Mailx.cpp
@@ -111,13 +111,13 @@ void CMailx::Report(const crash_report_t& pReport)
void CMailx::SetSettings(const map_settings_t& pSettings)
{
- if (pSettings.find("Email_From")!= pSettings.end())
+ if (pSettings.find("EmailFrom")!= pSettings.end())
{
- m_sEmailFrom = pSettings.find("Email_From")->second;
+ m_sEmailFrom = pSettings.find("EmailFrom")->second;
}
- if (pSettings.find("Email_To")!= pSettings.end())
+ if (pSettings.find("EmailTo")!= pSettings.end())
{
- m_sEmailTo = pSettings.find("Email_To")->second;
+ m_sEmailTo = pSettings.find("EmailTo")->second;
}
if (pSettings.find("Parameters")!= pSettings.end())
{
diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am
index db23497..b014f5a 100644
--- a/lib/Plugins/Makefile.am
+++ b/lib/Plugins/Makefile.am
@@ -3,7 +3,7 @@ pluginslibdir=$(PLUGINS_LIB_DIR)
pluginslib_LTLIBRARIES = libCCpp.la libMailx.la libSQLite3.la libLogger.la
pluginsconfdir=$(PLUGINS_CONF_DIR)
-pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf
+dist_pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf
# CCpp
libCCpp_la_SOURCES = CCpp.cpp CCpp.h
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index f09de9e..302d3be 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -20,7 +20,6 @@
*/
#include "DebugDump.h"
-#include "Packages.h"
#include <fstream>
#include <iostream>
#include <sstream>
@@ -30,7 +29,6 @@
#include <sys/utsname.h>
#include <limits.h>
#include <fcntl.h>
-#include <sys/procfs.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
@@ -93,11 +91,12 @@ void CDebugDump::Lock()
m_bUnlock = false;
return;
}
- while (ExistFileDir(lockPath))
- {
- std::cerr << "CDebugDump::Lock(): waiting..." << std::endl;
- usleep(10);
- }
+ }
+
+ 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)
@@ -106,6 +105,7 @@ void CDebugDump::Lock()
}
if (lockf(m_nFD,F_LOCK, 0) < 0)
{
+ remove(lockPath.c_str());
throw std::string("CDebugDump::Lock(): cannot lock DebugDump");
}
}
@@ -142,13 +142,12 @@ void CDebugDump::Create(const std::string& pDir)
SaveTime();
}
-void CDebugDump::Delete(const std::string& pDir)
+void CDebugDump::DeleteFileDir(const std::string& pDir)
{
if (!ExistFileDir(pDir))
{
return;
}
- Lock();
DIR *dir = opendir(pDir.c_str());
std::string fullPath;
struct dirent *dent = NULL;
@@ -161,20 +160,30 @@ void CDebugDump::Delete(const std::string& pDir)
fullPath = pDir + "/" + dent->d_name;
if (dent->d_type == DT_DIR)
{
- Delete(fullPath);
+ DeleteFileDir(fullPath);
}
if (remove(fullPath.c_str()) == -1)
{
- throw "CDebugDump::DeleteDir(): Cannot remove file: " + fullPath;
+ throw "CDebugDump::DeleteFileDir(): Cannot remove file: " + fullPath;
}
}
}
closedir(dir);
if (remove(pDir.c_str()) == -1)
{
- throw "CDebugDump::DeleteDir(): Cannot remove dir: " + fullPath;
+ throw "CDebugDump::DeleteFileDir(): Cannot remove dir: " + fullPath;
}
}
+}
+
+void CDebugDump::Delete()
+{
+ if (!ExistFileDir(m_sDebugDumpDir))
+ {
+ return;
+ }
+ Lock();
+ DeleteFileDir(m_sDebugDumpDir);
UnLock();
}
@@ -334,16 +343,3 @@ void CDebugDump::SaveProc(const std::string& pPID)
LoadTextFile(path, data);
SaveText(FILENAME_CMDLINE, data);
}
-
-void CDebugDump::SavePackage()
-{
- std::string executable;
- std::string package = "";
- if (Exist(FILENAME_EXECUTABLE))
- {
- CPackages packages;
- LoadText(FILENAME_EXECUTABLE, executable);
- package = packages.SearchFile(executable);
- }
- SaveText(FILENAME_PACKAGE, package);
-}
diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h
index b32dfeb..eecc89d 100644
--- a/lib/Utils/DebugDump.h
+++ b/lib/Utils/DebugDump.h
@@ -59,16 +59,17 @@ class CDebugDump
void Lock();
void UnLock();
+ void DeleteFileDir(const std::string& pDir);
+
public:
CDebugDump();
void Open(const std::string& pDir);
void Create(const std::string& pDir);
- void Delete(const std::string& pDir);
+ void Delete();
void Close();
void SaveProc(const std::string& pPID);
- void SavePackage();
bool Exist(const std::string& pFileName);
diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am
index cc98223..592bdb5 100644
--- a/lib/Utils/Makefile.am
+++ b/lib/Utils/Makefile.am
@@ -1,8 +1,6 @@
lib_LTLIBRARIES = libUtils.la
-libUtils_la_SOURCES = DebugDump.cpp DebugDump.h Packages.cpp Packages.h
+libUtils_la_SOURCES = DebugDump.cpp DebugDump.h
libUtils_la_LDFLAGS = -version-info 0:1:0
-libUtils_la_CPPFLAGS = $(PACKAGEKIT_GLIB_CFLAGS) $(RPM_CFLAGS)
-libUtils_la_LIBADD = $(PACKAGEKIT_GLIB_LIBS) $(RPM_LIBS)
install-data-local:
- $(mkdir_p) '$(DEBUG_DUMPS_DIR)' \ No newline at end of file
+ $(mkdir_p) '$(DESTDIR)/$(DEBUG_DUMPS_DIR)' \ No newline at end of file
diff --git a/lib/Utils/Packages.cpp b/lib/Utils/Packages.cpp
deleted file mode 100644
index e93c292..0000000
--- a/lib/Utils/Packages.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- Packages.cpp - PackageKit wrapper
-
- 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 "Packages.h"
-#include <rpm/rpmcli.h>
-#include <iostream>
-
-
-CPackages::CPackages() :
- m_pPkClient(NULL),
- m_bBusy(false)
-{
- g_type_init();
- m_pPkClient = pk_client_new();
-
- 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()
-{
- 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::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;
- if ((header = rpmdbNextIterator(iter)) != NULL)
- {
- if (CheckFingerprint(header))
- {
- char* nerv = headerGetNEVR(header, NULL);
- if (nerv != NULL)
- {
- if (CheckHash(header, ts, pPath))
- {
- ret = nerv;
- free(nerv);
- }
- }
- }
- }
-
- rpmdbFreeIterator(iter);
- rpmtsFree(ts);
- rpmcliFini(context);
- return ret;
-}
-
-bool CPackages::Install(const std::string& pPackage)
-{
- // TODO: write this
-}
-
-
-bool CPackages::GetInstallationStatus()
-{
- GError *error = NULL;
- PkStatusEnum status;
- gboolean ret = pk_client_get_status(m_pPkClient, &status, &error);
- if (ret == FALSE)
- {
- std::string err = error->message;
- g_error_free(error);
- error = NULL;
- throw std::string("CPackages::SearchFile(): ") + err;
- }
- if (status != PK_STATUS_ENUM_FINISHED)
- {
- return false;
- }
- return true;
-}