diff options
author | Zdenek Prikryl <zprikryl@redhat.com> | 2009-02-18 17:23:52 +0100 |
---|---|---|
committer | Zdenek Prikryl <zprikryl@redhat.com> | 2009-02-18 17:23:52 +0100 |
commit | 673c55281eaef1052e3a08db240469fb3f490b62 (patch) | |
tree | 5947a32e3d1e59f9cdd8059c18e3fa621a155f16 /lib/MiddleWare | |
parent | 1b1d9e234abb9cbba7f722d32e7a0eb9dfe267d1 (diff) | |
download | abrt-673c55281eaef1052e3a08db240469fb3f490b62.tar.gz abrt-673c55281eaef1052e3a08db240469fb3f490b62.tar.xz abrt-673c55281eaef1052e3a08db240469fb3f490b62.zip |
new rmp interace
Diffstat (limited to 'lib/MiddleWare')
-rw-r--r-- | lib/MiddleWare/RPMInfo.cpp | 119 | ||||
-rw-r--r-- | lib/MiddleWare/RPMInfo.h | 52 |
2 files changed, 171 insertions, 0 deletions
diff --git a/lib/MiddleWare/RPMInfo.cpp b/lib/MiddleWare/RPMInfo.cpp new file mode 100644 index 00000000..8c395c88 --- /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.substr(0, pPackage.find("-")).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.substr(0, pPackage.find("-")).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/MiddleWare/RPMInfo.h b/lib/MiddleWare/RPMInfo.h new file mode 100644 index 00000000..2850fd66 --- /dev/null +++ b/lib/MiddleWare/RPMInfo.h @@ -0,0 +1,52 @@ +/* + 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. + + 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 RPMINFO_H_ +#define RPMINFO_H_ + +#include "MiddleWareTypes.h" + +#include <rpm/rpmcli.h> +#include <rpm/rpmts.h> +#include <rpm/rpmdb.h> + +class CRPMInfo +{ + private: + + typedef set_strings_t set_fingerprints_t; + + poptContext m_poptContext; + set_fingerprints_t m_setFingerprints; + + public: + CRPMInfo(); + ~CRPMInfo(); + + void LoadOpenGPGPublicKey(const std::string& pFileName); + + bool CheckFingerprint(const std::string& pPackage); + bool CheckHash(const std::string& pPackage, const std::string&pPath); + std::string GetPackage(const std::string& pFileName); +}; + +#endif /* RPMINFO_H_ */ |