teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone
Blob Blame History Raw
From 8235711d92d8783abe63d6e4f29afd495fc4b22e Mon Sep 17 00:00:00 2001
From: chantra <chantr4@gmail.com>
Date: Wed, 16 Feb 2022 23:21:14 -0800
Subject: [PATCH 25/30] [extents] move more functions/helpers behind
 rpmextents_internal.h

---
 lib/rpmchecksig.c         | 58 ++-------------------------------------
 lib/rpmextents.c          | 56 +++++++++++++++++++++++++++++++++++++
 lib/rpmextents_internal.h |  6 ++++
 3 files changed, 64 insertions(+), 56 deletions(-)

diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c
index 729f79f9f..5e8794e2d 100644
--- a/lib/rpmchecksig.c
+++ b/lib/rpmchecksig.c
@@ -221,61 +221,6 @@ exit:
     return rc;
 }
 
-static int rpmpkgVerifySigsTranscoded(FD_t fd){
-    rpm_loff_t current;
-    int32_t rc;
-    size_t len;
-    uint64_t content_len;
-    char *content = NULL;
-    struct extents_footer_t footer;
-
-    current = Ftell(fd);
-
-    if(extentsFooterFromFD(fd, &footer) != RPMRC_OK) {
-	rc = -1;
-	goto exit;
-    }
-    if(Fseek(fd, footer.offsets.checksig_offset, SEEK_SET) < 0) {
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to seek signature verification offset\n"));
-	rc = -1;
-	goto exit;
-    }
-    len = sizeof(rc);
-    if (Fread(&rc, len, 1, fd) != len) {
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to read Signature Verification RC\n"));
-	rc = -1;
-	goto exit;
-    }
-
-    len = sizeof(content_len);
-    if (Fread(&content_len, len, 1, fd) != len) {
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to read signature content length\n"));
-	goto exit;
-    }
-
-    content = malloc(content_len + 1);
-    if(content == NULL) {
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to allocate memory to read signature content\n"));
-	goto exit;
-    }
-    content[content_len] = 0;
-    if (Fread(content, content_len, 1, fd) != content_len) {
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to read signature content\n"));
-	goto exit;
-    }
-
-    rpmlog(RPMLOG_NOTICE, "%s", content);
-exit:
-    if(content){
-	free(content);
-    }
-    if (Fseek(fd, current, SEEK_SET) < 0) {
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: unable to seek back to original location\n"));
-    }
-    return rc;
-
-}
-
 static int rpmpkgVerifySigs(rpmKeyring keyring, int vfylevel, rpmVSFlags flags,
 			   FD_t fd, const char *fn)
 {
@@ -289,8 +234,9 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, int vfylevel, rpmVSFlags flags,
     rpmlog(RPMLOG_NOTICE, "%s:%s", fn, vd.verbose ? "\n" : "");
 
     if(isTranscodedRpm(fd) == RPMRC_OK){
-	return rpmpkgVerifySigsTranscoded(fd);
+	return extentsVerifySigs(fd);
     }
+
     struct rpmvs_s *vs = rpmvsCreate(vfylevel, flags, keyring);
 
     rc = rpmpkgRead(vs, fd, NULL, NULL, &msg);
diff --git a/lib/rpmextents.c b/lib/rpmextents.c
index 46b7aadff..f28596f0b 100644
--- a/lib/rpmextents.c
+++ b/lib/rpmextents.c
@@ -9,6 +9,62 @@
 
 #include "lib/rpmextents_internal.h"
 
+
+int extentsVerifySigs(FD_t fd){
+    rpm_loff_t current;
+    int32_t rc;
+    size_t len;
+    uint64_t content_len;
+    char *content = NULL;
+    struct extents_footer_t footer;
+
+    current = Ftell(fd);
+
+    if(extentsFooterFromFD(fd, &footer) != RPMRC_OK) {
+	rc = -1;
+	goto exit;
+    }
+    if(Fseek(fd, footer.offsets.checksig_offset, SEEK_SET) < 0) {
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to seek signature verification offset\n"));
+	rc = -1;
+	goto exit;
+    }
+    len = sizeof(rc);
+    if (Fread(&rc, len, 1, fd) != len) {
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read Signature Verification RC\n"));
+	rc = -1;
+	goto exit;
+    }
+
+    len = sizeof(content_len);
+    if (Fread(&content_len, len, 1, fd) != len) {
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read signature content length\n"));
+	goto exit;
+    }
+
+    content = rmalloc(content_len + 1);
+    if(content == NULL) {
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to allocate memory to read signature content\n"));
+	goto exit;
+    }
+    content[content_len] = 0;
+    if (Fread(content, content_len, 1, fd) != content_len) {
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read signature content\n"));
+	goto exit;
+    }
+
+    rpmlog(RPMLOG_NOTICE, "%s", content);
+exit:
+    if(content){
+	rfree(content);
+    }
+    if (Fseek(fd, current, SEEK_SET) < 0) {
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: unable to seek back to original location\n"));
+    }
+    return rc;
+
+}
+
 rpmRC extentsFooterFromFD(FD_t fd, struct extents_footer_t *footer) {
 
     rpmRC rc = RPMRC_NOTFOUND;
diff --git a/lib/rpmextents_internal.h b/lib/rpmextents_internal.h
index f0c29c807..380c08425 100644
--- a/lib/rpmextents_internal.h
+++ b/lib/rpmextents_internal.h
@@ -29,6 +29,12 @@ struct __attribute__ ((__packed__)) extents_footer_t {
     extents_magic_t magic;
 };
 
+/** \ingroup rpmextents
+ * Checks the results of the signature verification ran during transcoding.
+ * @param fd	The FD_t of the transcoded RPM
+ * @return	The number of checks that `rpmvsVerify` failed during transcoding.
+ */
+int extentsVerifySigs(FD_t fd);
 
 /** \ingroup rpmextents
  * Read the RPM Extents footer from a file descriptor.
-- 
2.35.1