Lookup signature type from cli utility already
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 3 Sep 2010 11:03:48 +0000 (14:03 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 3 Sep 2010 11:23:55 +0000 (14:23 +0300)
- Avoid relying on the murky rpmLookupSignatureType() foobar on
  low API level, pass the wanted tag explicitly from caller
- rpmLookupSignature(), rpmGetPassPhrase() + the bits they rely on
  are now free of users within librpm itself

lib/rpmcli.h
lib/rpmgensig.c
rpmqv.c

index 8d625b8..7c53c2e 100644 (file)
@@ -444,10 +444,12 @@ extern struct poptOption rpmSignPoptTable[];
  * Create/delete package signatures.
  * @param argv         array of package path arguments (NULL terminated)
  * @param deleting     adding or deleting signature(s)
- * @param passPhrase   passphrase (or NULL when deleting)
+ * @param sigTag       signature tag (ignored when deleting)
+ * @param passPhrase   passphrase (ignored when deleting)
  * @return             0 on success
  */
-int rpmcliSign(ARGV_const_t argv, int deleting, const char *passPhrase);
+int rpmcliSign(ARGV_const_t argv, int deleting,
+               rpmSigTag sigTag, const char *passPhrase);
 
 /** Import public key(s) to rpm keyring
  * @param ts           transaction set
index 7282d96..da6acc7 100644 (file)
@@ -128,15 +128,16 @@ static int getSignid(Header sig, rpmSigTag sigtag, pgpKeyID_t signid)
  * Create/modify elements in signature header.
  * @param rpm          path to package
  * @param deleting     adding or deleting signature?
- * @param passPhrase   passPhrase (or NULL when deleting)
+ * @param sigtag       signature to generate (ignored when deleting)
+ * @param passPhrase   passPhrase (ignored when deleting)
  * @return             0 on success, -1 on error
  */
-static int rpmSign(const char *rpm, int deleting, const char *passPhrase)
+static int rpmSign(const char *rpm, int deleting, 
+               rpmSigTag sigtag, const char *passPhrase)
 {
     FD_t fd = NULL;
     FD_t ofd = NULL;
     rpmlead lead;
-    rpmSigTag sigtag;
     char *sigtarget = NULL, *trpm = NULL;
     Header sigh = NULL;
     char * msg;
@@ -239,8 +240,8 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase)
            xx = headerDel(sigh, RPMSIGTAG_PGP5);
            xx = headerDel(sigh, RPMSIGTAG_PGP);
            xx = headerDel(sigh, RPMSIGTAG_RSA);
-       } else          /* If gpg/pgp is configured, replace the signature. */
-       if ((sigtag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) > 0) {
+       } else if (sigtag > 0) {
+           /* If gpg/pgp is configured, replace the signature. */
            pgpKeyID_t oldsignid, newsignid;
 
            /* Grab the old signature fingerprint (if any) */
@@ -357,11 +358,12 @@ exit:
     return res;
 }
 
-int rpmcliSign(ARGV_const_t argv, int deleting, const char *passPhrase)
+int rpmcliSign(ARGV_const_t argv, int deleting,
+               rpmSigTag sigtag, const char *passPhrase)
 {
     int res = 0;
     for (ARGV_const_t arg = argv; arg && *arg; arg++) {
-       res += rpmSign(*arg, deleting, passPhrase);
+       res += rpmSign(*arg, deleting, sigtag, passPhrase);
     }
     return res;
 }
diff --git a/rpmqv.c b/rpmqv.c
index bf7e828..fbea262 100644 (file)
--- a/rpmqv.c
+++ b/rpmqv.c
@@ -500,7 +500,8 @@ int main(int argc, char *argv[])
        if (!poptPeekArg(optCon))
            argerror(_("no arguments given"));
        ec = rpmcliSign((ARGV_const_t) poptGetArgs(optCon),
-                       (qva->qva_mode == RPMSIGN_DEL_SIGNATURE), passPhrase);
+                       (qva->qva_mode == RPMSIGN_DEL_SIGNATURE),
+                       rpmLookupSignatureType(RPMLOOKUPSIG_QUERY), passPhrase);
        break;
 #endif /* IAM_RPMK */