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/Utils | |
| 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/Utils')
| -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 |
4 files changed, 134 insertions, 36 deletions
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(); |
