From d2a49f29d0acb2314d52a0987cdb05e2163c3a5b Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 21 Nov 2024 13:30:20 +0200 Subject: [PATCH] Use RPMTAG_RPMFORMAT for rpm format detection in the signing code We now have a nice way to centrally get the format number, use it in the signing code instead of the various ad-hoc methods added during multi-signature development, and use 'rpmformat' as the variable name for easy grepping. No functional changes. --- sign/rpmgensig.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sign/rpmgensig.cc b/sign/rpmgensig.cc index 85a515e3bd..92036676b9 100644 --- a/sign/rpmgensig.cc +++ b/sign/rpmgensig.cc @@ -641,7 +641,8 @@ static int rpmSign(const char *rpm, int deleting, int flags) struct sigTarget_s sigt_v4; unsigned int origSigSize; int insSig = 0; - rpmTagVal reserveTag = RPMSIGTAG_RESERVEDSPACE; + int rpmformat = 0; + rpmTagVal reserveTag = 0; if (manageFile(&fd, rpm, O_RDWR)) goto exit; @@ -671,7 +672,9 @@ static int rpmSign(const char *rpm, int deleting, int flags) goto exit; } - if (!headerIsEntry(h, RPMTAG_HEADERIMMUTABLE)) { + rpmformat = headerGetNumber(h, RPMTAG_RPMFORMAT); + + if (rpmformat < 4) { rpmlog(RPMLOG_ERR, _("Cannot sign RPM v3 packages: %s\n"), rpm); goto exit; } @@ -682,8 +685,7 @@ static int rpmSign(const char *rpm, int deleting, int flags) flags |= RPMSIGN_FLAG_RPMV3; } - /* Only v6 packages have this */ - if (headerIsEntry(sigh, RPMSIGTAG_RESERVED)) { + if (rpmformat >= 6) { flags |= RPMSIGN_FLAG_RPMV6; reserveTag = RPMSIGTAG_RESERVED; /* v3 signatures are not welcome in v6 packages */ @@ -694,6 +696,7 @@ static int rpmSign(const char *rpm, int deleting, int flags) } } else { flags |= RPMSIGN_FLAG_RPMV4; + reserveTag = RPMSIGTAG_RESERVEDSPACE; /* Ensure only one legacy signature is added if adding v6 signatures */ if ((flags & RPMSIGN_FLAG_RPMV6) && haveLegacySig(sigh)) flags &= ~(RPMSIGN_FLAG_RPMV4|RPMSIGN_FLAG_RPMV3);