summaryrefslogtreecommitdiffstats
path: root/lib/Utils
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-02-18 17:23:26 +0100
committerZdenek Prikryl <zprikryl@redhat.com>2009-02-18 17:23:26 +0100
commit1b1d9e234abb9cbba7f722d32e7a0eb9dfe267d1 (patch)
tree04c88efe2655ec97b9b66a916538eed461efcb93 /lib/Utils
parente43c8c787e7b3eb189e3dab8f8ca11958b23e054 (diff)
downloadabrt-1b1d9e234abb9cbba7f722d32e7a0eb9dfe267d1.tar.gz
abrt-1b1d9e234abb9cbba7f722d32e7a0eb9dfe267d1.tar.xz
abrt-1b1d9e234abb9cbba7f722d32e7a0eb9dfe267d1.zip
new logic of getting package name
Diffstat (limited to 'lib/Utils')
-rw-r--r--lib/Utils/DebugDump.cpp25
-rw-r--r--lib/Utils/DebugDump.h1
-rw-r--r--lib/Utils/Packages.cpp107
-rw-r--r--lib/Utils/Packages.h13
4 files changed, 9 insertions, 137 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index f09de9e..5386162 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -93,11 +93,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 +107,7 @@ void CDebugDump::Lock()
}
if (lockf(m_nFD,F_LOCK, 0) < 0)
{
+ remove(lockPath.c_str());
throw std::string("CDebugDump::Lock(): cannot lock DebugDump");
}
}
@@ -334,16 +336,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..08e2643 100644
--- a/lib/Utils/DebugDump.h
+++ b/lib/Utils/DebugDump.h
@@ -68,7 +68,6 @@ class CDebugDump
void Close();
void SaveProc(const std::string& pPID);
- void SavePackage();
bool Exist(const std::string& pFileName);
diff --git a/lib/Utils/Packages.cpp b/lib/Utils/Packages.cpp
index e93c292..418331b 100644
--- a/lib/Utils/Packages.cpp
+++ b/lib/Utils/Packages.cpp
@@ -20,7 +20,6 @@
*/
#include "Packages.h"
-#include <rpm/rpmcli.h>
#include <iostream>
@@ -30,29 +29,6 @@ CPackages::CPackages() :
{
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()
@@ -60,89 +36,6 @@ 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)
{
diff --git a/lib/Utils/Packages.h b/lib/Utils/Packages.h
index 67e5f24..4213de4 100644
--- a/lib/Utils/Packages.h
+++ b/lib/Utils/Packages.h
@@ -25,28 +25,19 @@
#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();
- std::string SearchFile(const std::string& pPath);
bool Install(const std::string& pPackage);
bool GetInstallationStatus();