[Rpm-maint] [PATCH]Move parsePGP and _print_pkts from rpmchecksig.c and package.c to signature.[ch]

Rakesh Pandit rakesh.pandit at gmail.com
Tue Apr 27 10:44:01 UTC 2010


http://rakesh.fedorapeople.org/misc/0001-Move-parsePGP-and-_print_pkts-from-rpmchecksig.c-and.patch

-- 
Rakesh Pandit
https://fedoraproject.org/wiki/User:Rakesh
freedom, friends, features, first

>From 5d0976a8d14a1aa763bf1c63c78f42517d835d83 Mon Sep 17 00:00:00 2001
From: Rakesh Pandit <rakesh at fedoraproject.org>
Date: Tue, 27 Apr 2010 16:00:09 +0530
Subject: [PATCH] Move parsePGP and _print_pkts from rpmchecksig.c and
package.c to
 signature.[ch]
  - Rename parsePGP to rpmParsePGP
  - remove unused static _print_pkts in package.c
  - corresponding change parsePGP calls to rpmParsePGP calls

---
 lib/package.c     |   24 +++---------------------
 lib/rpmchecksig.c |   21 +--------------------
 lib/signature.c   |   18 ++++++++++++++++++
 lib/signature.h   |    9 +++++++++
 4 files changed, 31 insertions(+), 41 deletions(-)

diff --git a/lib/package.c b/lib/package.c
index 90e4f9c..9743536 100644
--- a/lib/package.c
+++ b/lib/package.c
@@ -20,8 +20,6 @@

 #include "debug.h"

-static int _print_pkts = 0;
-
 static const unsigned int nkeyids_max = 256;
 static unsigned int nkeyids = 0;
 static unsigned int nextkeyid  = 0;
@@ -179,22 +177,6 @@ static int stashKeyid(pgpDig dig)
     return 0;
 }

-/* Parse the parameters from the OpenPGP packets that will be needed. */
-static rpmRC parsePGP(rpmtd sigtd, const char *type, pgpDig dig)
-{
-    rpmRC rc = RPMRC_FAIL;
-    int debug = (_print_pkts & rpmIsDebug());
-    if ((pgpPrtPkts(sigtd->data, sigtd->count, dig, debug) == 0) &&
-	 (dig->signature.version == 3 || dig->signature.version == 4)) {
-	rc = RPMRC_OK;
-    } else {
-	rpmlog(RPMLOG_ERR,
-	    _("skipping %s with unverifiable V%u signature\n"), type,
-	    dig->signature.version);
-    }
-    return rc;
-}
-
 static rpmRC headerVerify(rpmKeyring keyring, rpmVSFlags vsflags,
 			  const void * uh, size_t uc, char ** msg)
 {
@@ -386,7 +368,7 @@ verifyinfo_exit:
     switch (info.tag) {
     case RPMTAG_RSAHEADER:
     case RPMTAG_DSAHEADER:
-	if ((rc = parsePGP(&sigtd, "header", dig)) != RPMRC_OK) {
+	if ((rc = rpmParsePGP(&sigtd, "header", dig)) != RPMRC_OK) {
 	    pgpFreeDig(dig);
 	    goto exit;
 	}
@@ -656,7 +638,7 @@ static rpmRC rpmpkgRead(rpmKeyring keyring,
rpmVSFlags vsflags,
     switch (sigtag) {
     case RPMSIGTAG_RSA:
     case RPMSIGTAG_DSA:
-	if ((rc = parsePGP(&sigtd, "package", dig)) != RPMRC_OK) {
+	if ((rc = rpmParsePGP(&sigtd, "package", dig)) != RPMRC_OK) {
 	    goto exit;
 	}
 	/* fallthrough */
@@ -675,7 +657,7 @@ static rpmRC rpmpkgRead(rpmKeyring keyring,
rpmVSFlags vsflags,
     case RPMSIGTAG_GPG:
     case RPMSIGTAG_PGP5:	/* XXX legacy */
     case RPMSIGTAG_PGP:
-	if ((rc = parsePGP(&sigtd, "package", dig)) != RPMRC_OK) {
+	if ((rc = rpmParsePGP(&sigtd, "package", dig)) != RPMRC_OK) {
 	    goto exit;
 	}
 	/* fallthrough */
diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c
index 23ce871..2bf91d6 100644
--- a/lib/rpmchecksig.c
+++ b/lib/rpmchecksig.c
@@ -22,8 +22,6 @@

 #include "debug.h"

-int _print_pkts = 0;
-
 static int closeFile(FD_t *fdp)
 {
     if (fdp == NULL || *fdp == NULL)
@@ -494,23 +492,6 @@ exit:
     return rc;
 }

-/* Parse the parameters from the OpenPGP packets that will be needed. */
-/* XXX TODO: unify with similar parsePGP() in package.c */
-static rpmRC parsePGP(rpmtd sigtd, const char *fn, pgpDig dig)
-{
-    rpmRC rc = RPMRC_FAIL;
-    int debug = (_print_pkts & rpmIsDebug());
-    if ((pgpPrtPkts(sigtd->data, sigtd->count, dig, debug) == 0) &&
-	 (dig->signature.version == 3 || dig->signature.version == 4)) {
-	rc = RPMRC_OK;
-    } else {
-	rpmlog(RPMLOG_ERR,
-	    _("skipping package %s with unverifiable V%u signature\n"), fn,
-	    dig->signature.version);
-    }
-    return rc;
-}
-
 /*
  * Figure best available signature.
  * XXX TODO: Similar detection in rpmReadPackageFile(), unify these.
@@ -714,7 +695,7 @@ static int rpmpkgVerifySigs(rpmKeyring keyring,
rpmQueryFlags flags,
 	case RPMSIGTAG_DSA:
 	    if (nosignatures)
 		 continue;
-	    if (parsePGP(&sigtd, fn, dig) != RPMRC_OK) {
+	    if (rpmParsePGP(&sigtd, fn, dig) != RPMRC_OK) {
 		goto exit;
 	    }
 	    ctx = rpmDigestBundleDupCtx(havekey ? plbundle : hdrbundle,
diff --git a/lib/signature.c b/lib/signature.c
index 9145029..6743fd8 100644
--- a/lib/signature.c
+++ b/lib/signature.c
@@ -23,6 +23,8 @@

 #include "debug.h"

+int _print_pkts = 0;
+
 #if !defined(__GLIBC__) && !defined(__APPLE__)
 char ** environ = NULL;
 #endif
@@ -878,3 +880,19 @@ exit:
     }
     return res;
 }
+
+rpmRC
+rpmParsePGP(rpmtd sigtd, const char *fn, pgpDig dig)
+{
+    rpmRC rc = RPMRC_FAIL;
+    int debug = (_print_pkts & rpmIsDebug());
+    if ((pgpPrtPkts(sigtd->data, sigtd->count, dig, debug) == 0) &&
+	 (dig->signature.version == 3 || dig->signature.version == 4)) {
+	rc = RPMRC_OK;
+    } else {
+	rpmlog(RPMLOG_ERR,
+	    _("skipping package %s with unverifiable V%u signature\n"), fn,
+	    dig->signature.version);
+    }
+    return rc;
+}
diff --git a/lib/signature.h b/lib/signature.h
index fa595c6..4a64604 100644
--- a/lib/signature.h
+++ b/lib/signature.h
@@ -98,6 +98,15 @@ int rpmLookupSignatureType(int action);
  */
 char * rpmGetPassPhrase(const char * prompt, const rpmSigTag sigTag);

+/** \ingroup signature
+ * Parse parameters from the OpenPGP packets.
+ * @param sigtd		signature tag data container
+ * @param fn		package file name
+ * @param dig		signature/pubkey parameters
+ * @return		0 on success, 1 on failure
+ */
+rpmRC rpmParsePGP(rpmtd sigtd, const char *fn, pgpDig dig);
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.6.6.1


More information about the Rpm-maint mailing list