michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone
Blob Blame History Raw
From 492823ca53f5666b82e94fcfdd422bdcd67005cb Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Tue, 10 Oct 2017 11:07:38 +0300
Subject: [PATCH 03/33] Use lower-level headerPut() for file signing

Not supposed to affect behavior at all, but we'll need this in the
next step.
---
 sign/rpmsignfiles.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/sign/rpmsignfiles.c b/sign/rpmsignfiles.c
index 61b73bd40..1fc127cb1 100644
--- a/sign/rpmsignfiles.c
+++ b/sign/rpmsignfiles.c
@@ -82,7 +82,7 @@ char *keypass)
 
 rpmRC rpmSignFiles(Header h, const char *key, char *keypass)
 {
-    struct rpmtd_s digests;
+    struct rpmtd_s digests, td;
     int algo;
     int diglen;
     uint32_t siglen;
@@ -110,7 +110,19 @@ rpmRC rpmSignFiles(Header h, const char *key, char *keypass)
     headerDel(h, RPMTAG_FILESIGNATURELENGTH);
     headerDel(h, RPMTAG_FILESIGNATURES);
     siglen = signatureLength(algoname, diglen, key, keypass);
-    headerPutUint32(h, RPMTAG_FILESIGNATURELENGTH, &siglen, 1);
+
+    rpmtdReset(&td);
+    td.tag = RPMTAG_FILESIGNATURELENGTH;
+    td.type = RPM_INT32_TYPE;
+    td.data = &siglen;
+    td.count = 1;
+    headerPut(h, &td, HEADERPUT_DEFAULT);
+
+    rpmtdReset(&td);
+    td.tag = RPMTAG_FILESIGNATURES;
+    td.type = RPM_STRING_ARRAY_TYPE;
+    td.data = NULL; /* set in the loop below */
+    td.count = 1;
 
     headerGet(h, RPMTAG_FILEDIGESTS, &digests, HEADERGET_MINMEM);
     while ((digest = rpmtdNextString(&digests))) {
@@ -120,7 +132,8 @@ rpmRC rpmSignFiles(Header h, const char *key, char *keypass)
 	    rc = RPMRC_FAIL;
 	    goto exit;
 	}
-	if (!headerPutString(h, RPMTAG_FILESIGNATURES, signature)) {
+	td.data = &signature;
+	if (!headerPut(h, &td, HEADERPUT_APPEND)) {
 	    free(signature);
 	    rpmlog(RPMLOG_ERR, _("headerPutString failed\n"));
 	    rc = RPMRC_FAIL;
-- 
2.27.0