michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 5 months ago
Clone

Blame SOURCES/0025-extents-move-more-functions-helpers-behind-rpmextent.patch

629b27
From 8235711d92d8783abe63d6e4f29afd495fc4b22e Mon Sep 17 00:00:00 2001
629b27
From: chantra <chantr4@gmail.com>
629b27
Date: Wed, 16 Feb 2022 23:21:14 -0800
629b27
Subject: [PATCH 25/30] [extents] move more functions/helpers behind
629b27
 rpmextents_internal.h
629b27
629b27
---
629b27
 lib/rpmchecksig.c         | 58 ++-------------------------------------
629b27
 lib/rpmextents.c          | 56 +++++++++++++++++++++++++++++++++++++
629b27
 lib/rpmextents_internal.h |  6 ++++
629b27
 3 files changed, 64 insertions(+), 56 deletions(-)
629b27
629b27
diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c
629b27
index 729f79f9f..5e8794e2d 100644
629b27
--- a/lib/rpmchecksig.c
629b27
+++ b/lib/rpmchecksig.c
629b27
@@ -221,61 +221,6 @@ exit:
629b27
     return rc;
629b27
 }
629b27
 
629b27
-static int rpmpkgVerifySigsTranscoded(FD_t fd){
629b27
-    rpm_loff_t current;
629b27
-    int32_t rc;
629b27
-    size_t len;
629b27
-    uint64_t content_len;
629b27
-    char *content = NULL;
629b27
-    struct extents_footer_t footer;
629b27
-
629b27
-    current = Ftell(fd);
629b27
-
629b27
-    if(extentsFooterFromFD(fd, &footer) != RPMRC_OK) {
629b27
-	rc = -1;
629b27
-	goto exit;
629b27
-    }
629b27
-    if(Fseek(fd, footer.offsets.checksig_offset, SEEK_SET) < 0) {
629b27
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to seek signature verification offset\n"));
629b27
-	rc = -1;
629b27
-	goto exit;
629b27
-    }
629b27
-    len = sizeof(rc);
629b27
-    if (Fread(&rc, len, 1, fd) != len) {
629b27
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to read Signature Verification RC\n"));
629b27
-	rc = -1;
629b27
-	goto exit;
629b27
-    }
629b27
-
629b27
-    len = sizeof(content_len);
629b27
-    if (Fread(&content_len, len, 1, fd) != len) {
629b27
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to read signature content length\n"));
629b27
-	goto exit;
629b27
-    }
629b27
-
629b27
-    content = malloc(content_len + 1);
629b27
-    if(content == NULL) {
629b27
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to allocate memory to read signature content\n"));
629b27
-	goto exit;
629b27
-    }
629b27
-    content[content_len] = 0;
629b27
-    if (Fread(content, content_len, 1, fd) != content_len) {
629b27
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: Failed to read signature content\n"));
629b27
-	goto exit;
629b27
-    }
629b27
-
629b27
-    rpmlog(RPMLOG_NOTICE, "%s", content);
629b27
-exit:
629b27
-    if(content){
629b27
-	free(content);
629b27
-    }
629b27
-    if (Fseek(fd, current, SEEK_SET) < 0) {
629b27
-	rpmlog(RPMLOG_ERR, _("rpmpkgVerifySigsTranscoded: unable to seek back to original location\n"));
629b27
-    }
629b27
-    return rc;
629b27
-
629b27
-}
629b27
-
629b27
 static int rpmpkgVerifySigs(rpmKeyring keyring, int vfylevel, rpmVSFlags flags,
629b27
 			   FD_t fd, const char *fn)
629b27
 {
629b27
@@ -289,8 +234,9 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, int vfylevel, rpmVSFlags flags,
629b27
     rpmlog(RPMLOG_NOTICE, "%s:%s", fn, vd.verbose ? "\n" : "");
629b27
 
629b27
     if(isTranscodedRpm(fd) == RPMRC_OK){
629b27
-	return rpmpkgVerifySigsTranscoded(fd);
629b27
+	return extentsVerifySigs(fd);
629b27
     }
629b27
+
629b27
     struct rpmvs_s *vs = rpmvsCreate(vfylevel, flags, keyring);
629b27
 
629b27
     rc = rpmpkgRead(vs, fd, NULL, NULL, &msg;;
629b27
diff --git a/lib/rpmextents.c b/lib/rpmextents.c
629b27
index 46b7aadff..f28596f0b 100644
629b27
--- a/lib/rpmextents.c
629b27
+++ b/lib/rpmextents.c
629b27
@@ -9,6 +9,62 @@
629b27
 
629b27
 #include "lib/rpmextents_internal.h"
629b27
 
629b27
+
629b27
+int extentsVerifySigs(FD_t fd){
629b27
+    rpm_loff_t current;
629b27
+    int32_t rc;
629b27
+    size_t len;
629b27
+    uint64_t content_len;
629b27
+    char *content = NULL;
629b27
+    struct extents_footer_t footer;
629b27
+
629b27
+    current = Ftell(fd);
629b27
+
629b27
+    if(extentsFooterFromFD(fd, &footer) != RPMRC_OK) {
629b27
+	rc = -1;
629b27
+	goto exit;
629b27
+    }
629b27
+    if(Fseek(fd, footer.offsets.checksig_offset, SEEK_SET) < 0) {
629b27
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to seek signature verification offset\n"));
629b27
+	rc = -1;
629b27
+	goto exit;
629b27
+    }
629b27
+    len = sizeof(rc);
629b27
+    if (Fread(&rc, len, 1, fd) != len) {
629b27
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read Signature Verification RC\n"));
629b27
+	rc = -1;
629b27
+	goto exit;
629b27
+    }
629b27
+
629b27
+    len = sizeof(content_len);
629b27
+    if (Fread(&content_len, len, 1, fd) != len) {
629b27
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read signature content length\n"));
629b27
+	goto exit;
629b27
+    }
629b27
+
629b27
+    content = rmalloc(content_len + 1);
629b27
+    if(content == NULL) {
629b27
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to allocate memory to read signature content\n"));
629b27
+	goto exit;
629b27
+    }
629b27
+    content[content_len] = 0;
629b27
+    if (Fread(content, content_len, 1, fd) != content_len) {
629b27
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read signature content\n"));
629b27
+	goto exit;
629b27
+    }
629b27
+
629b27
+    rpmlog(RPMLOG_NOTICE, "%s", content);
629b27
+exit:
629b27
+    if(content){
629b27
+	rfree(content);
629b27
+    }
629b27
+    if (Fseek(fd, current, SEEK_SET) < 0) {
629b27
+	rpmlog(RPMLOG_ERR, _("extentsVerifySigs: unable to seek back to original location\n"));
629b27
+    }
629b27
+    return rc;
629b27
+
629b27
+}
629b27
+
629b27
 rpmRC extentsFooterFromFD(FD_t fd, struct extents_footer_t *footer) {
629b27
 
629b27
     rpmRC rc = RPMRC_NOTFOUND;
629b27
diff --git a/lib/rpmextents_internal.h b/lib/rpmextents_internal.h
629b27
index f0c29c807..380c08425 100644
629b27
--- a/lib/rpmextents_internal.h
629b27
+++ b/lib/rpmextents_internal.h
629b27
@@ -29,6 +29,12 @@ struct __attribute__ ((__packed__)) extents_footer_t {
629b27
     extents_magic_t magic;
629b27
 };
629b27
 
629b27
+/** \ingroup rpmextents
629b27
+ * Checks the results of the signature verification ran during transcoding.
629b27
+ * @param fd	The FD_t of the transcoded RPM
629b27
+ * @return	The number of checks that `rpmvsVerify` failed during transcoding.
629b27
+ */
629b27
+int extentsVerifySigs(FD_t fd);
629b27
 
629b27
 /** \ingroup rpmextents
629b27
  * Read the RPM Extents footer from a file descriptor.
629b27
-- 
629b27
2.35.1
629b27