malmond / rpms / rpm

Forked from rpms/rpm 4 years ago
Clone

Blame SOURCES/0012-Generalize-file-signing-to-use-a-generic-flags-field.patch

657fb1
From 1afb1b5f5711e70a0806d041c57d35ac2456d6de Mon Sep 17 00:00:00 2001
657fb1
From: Panu Matilainen <pmatilai@redhat.com>
657fb1
Date: Mon, 2 Mar 2020 13:56:33 +0200
657fb1
Subject: [PATCH 12/33] Generalize file signing to use a generic flags field in
657fb1
 signing arguments
657fb1
657fb1
There will be any number of signing flags in the future, and we don't
657fb1
want to break the ABI for every single one of them by adding new
657fb1
fields to the sign argument struct. Replace the signfiles field
657fb1
with a bitfield in the common rpm style. No functional changes.
657fb1
657fb1
This is an API change of course, but we'll have to bump the soname for
657fb1
the next release anyway so might as well do it now.
657fb1
---
657fb1
 rpmsign.c        | 11 ++++++-----
657fb1
 sign/rpmgensig.c |  8 ++++----
657fb1
 sign/rpmsign.h   |  8 +++++++-
657fb1
 3 files changed, 17 insertions(+), 10 deletions(-)
657fb1
657fb1
diff --git a/rpmsign.c b/rpmsign.c
657fb1
index 1a5cd59c2..57cb36919 100644
657fb1
--- a/rpmsign.c
657fb1
+++ b/rpmsign.c
657fb1
@@ -19,7 +19,7 @@ enum modes {
657fb1
 static int mode = MODE_NONE;
657fb1
 
657fb1
 #ifdef WITH_IMAEVM
657fb1
-static int signfiles = 0, fskpass = 0;
657fb1
+static int fskpass = 0;
657fb1
 static char * fileSigningKey = NULL;
657fb1
 #endif
657fb1
 
657fb1
@@ -33,7 +33,8 @@ static struct poptOption signOptsTable[] = {
657fb1
     { "delsign", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELSIGN,
657fb1
 	N_("delete package signatures"), NULL },
657fb1
 #ifdef WITH_IMAEVM
657fb1
-    { "signfiles", '\0', POPT_ARG_NONE, &signfiles, 0,
657fb1
+    { "signfiles", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR),
657fb1
+	&sargs.signflags, RPMSIGN_FLAG_IMA,
657fb1
 	N_("sign package(s) files"), NULL},
657fb1
     { "fskpath", '\0', POPT_ARG_STRING, &fileSigningKey, 0,
657fb1
 	N_("use file signing key <key>"),
657fb1
@@ -107,7 +108,7 @@ static int doSign(poptContext optCon, struct rpmSignArgs *sargs)
657fb1
 	rpmPushMacro(NULL, "_file_signing_key", NULL, fileSigningKey, RMIL_GLOBAL);
657fb1
     }
657fb1
 
657fb1
-    if (signfiles) {
657fb1
+    if (sargs->signflags & RPMSIGN_FLAG_IMA) {
657fb1
 	char *fileSigningKeyPassword = NULL;
657fb1
 	char *key = rpmExpand("%{?_file_signing_key}", NULL);
657fb1
 	if (rstreq(key, "")) {
657fb1
@@ -126,7 +127,7 @@ static int doSign(poptContext optCon, struct rpmSignArgs *sargs)
657fb1
 	    free(fileSigningKeyPassword);
657fb1
 	}
657fb1
 
657fb1
-	sargs->signfiles = 1;
657fb1
+	sargs->signflags |= RPMSIGN_FLAG_IMA;
657fb1
 	free(key);
657fb1
     }
657fb1
 #endif
657fb1
@@ -163,7 +164,7 @@ int main(int argc, char *argv[])
657fb1
     }
657fb1
 
657fb1
 #ifdef WITH_IMAEVM
657fb1
-    if (fileSigningKey && !signfiles) {
657fb1
+    if (fileSigningKey && !(sargs.signflags & RPMSIGN_FLAG_IMA)) {
657fb1
 	argerror(_("--fskpath may only be specified when signing files"));
657fb1
     }
657fb1
 #endif
657fb1
diff --git a/sign/rpmgensig.c b/sign/rpmgensig.c
657fb1
index 875b96078..6ab8c23fa 100644
657fb1
--- a/sign/rpmgensig.c
657fb1
+++ b/sign/rpmgensig.c
657fb1
@@ -465,10 +465,10 @@ static int checkPkg(FD_t fd, char **msg)
657fb1
  * Create/modify elements in signature header.
657fb1
  * @param rpm		path to package
657fb1
  * @param deleting	adding or deleting signature?
657fb1
- * @param signfiles	sign files if non-zero
657fb1
+ * @param flags
657fb1
  * @return		0 on success, -1 on error
657fb1
  */
657fb1
-static int rpmSign(const char *rpm, int deleting, int signfiles)
657fb1
+static int rpmSign(const char *rpm, int deleting, int flags)
657fb1
 {
657fb1
     FD_t fd = NULL;
657fb1
     FD_t ofd = NULL;
657fb1
@@ -524,7 +524,7 @@ static int rpmSign(const char *rpm, int deleting, int signfiles)
657fb1
     unloadImmutableRegion(&sigh, RPMTAG_HEADERSIGNATURES);
657fb1
     origSigSize = headerSizeof(sigh, HEADER_MAGIC_YES);
657fb1
 
657fb1
-    if (signfiles) {
657fb1
+    if (flags & RPMSIGN_FLAG_IMA) {
657fb1
 	if (includeFileSignatures(&sigh, &h))
657fb1
 	    goto exit;
657fb1
     }
657fb1
@@ -675,7 +675,7 @@ int rpmPkgSign(const char *path, const struct rpmSignArgs * args)
657fb1
 	}
657fb1
     }
657fb1
 
657fb1
-    rc = rpmSign(path, 0, args ? args->signfiles : 0);
657fb1
+    rc = rpmSign(path, 0, args ? args->signflags : 0);
657fb1
 
657fb1
     if (args) {
657fb1
 	if (args->hashalgo) {
657fb1
diff --git a/sign/rpmsign.h b/sign/rpmsign.h
657fb1
index bed8d6245..545e80d2d 100644
657fb1
--- a/sign/rpmsign.h
657fb1
+++ b/sign/rpmsign.h
657fb1
@@ -13,10 +13,16 @@
657fb1
 extern "C" {
657fb1
 #endif
657fb1
 
657fb1
+enum rpmSignFlags_e {
657fb1
+    RPMSIGN_FLAG_NONE		= 0,
657fb1
+    RPMSIGN_FLAG_IMA		= (1 << 0),
657fb1
+};
657fb1
+typedef rpmFlags rpmSignFlags;
657fb1
+
657fb1
 struct rpmSignArgs {
657fb1
     char *keyid;
657fb1
     pgpHashAlgo hashalgo;
657fb1
-    int signfiles;
657fb1
+    rpmSignFlags signflags;
657fb1
     /* ... what else? */
657fb1
 };
657fb1
 
657fb1
-- 
657fb1
2.13.5
657fb1