[Rpm-maint] [PATCH] Add RPMTAG_IDENTITY calculation as tag extension
Vladimir D. Seleznev
vseleznv at altlinux.org
Tue Apr 3 19:31:39 UTC 2018
RPMTAG_IDENTITY is calculating as digest of part of package header that
does not contain irrelevant to package build tag entries.
Mathematically RPMTAG_IDENTITY value is a result of function of two
variable: a package header and an rpm utility, thus this value can
differ for same package and different version of rpm.
Despite tag entries are filtering by blacklist, rpm also filters tags
that it doesn't know while it calculates identity value. So technically,
it's a graylist.
---
lib/rpmtag.h | 3 +-
lib/tagexts.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 1 deletion(-)
diff --git a/lib/rpmtag.h b/lib/rpmtag.h
index 973a6b6..36dac85 100644
--- a/lib/rpmtag.h
+++ b/lib/rpmtag.h
@@ -371,11 +371,12 @@ typedef enum rpmTag_e {
RPMTAG_PAYLOADDIGEST = 5092, /* s[] */
RPMTAG_PAYLOADDIGESTALGO = 5093, /* i */
RPMTAG_AUTOINSTALLED = 5094, /* i reservation (unimplemented) */
- RPMTAG_IDENTITY = 5095, /* s reservation (unimplemented) */
+ RPMTAG_IDENTITY = 5095, /* s extension */
RPMTAG_FIRSTFREE_TAG /*!< internal */
} rpmTag;
+#define RPMTAG_IDENTITY_MAX_TAG RPMTAG_FIRSTFREE_TAG
#define RPMTAG_EXTERNAL_TAG 1000000
/** \ingroup rpmtag
diff --git a/lib/tagexts.c b/lib/tagexts.c
index f72ff60..ca8ac35 100644
--- a/lib/tagexts.c
+++ b/lib/tagexts.c
@@ -952,6 +952,98 @@ static int filenlinksTag(Header h, rpmtd td, headerGetFlags hgflags)
return (fc > 0);
}
+static int identityFilter(rpmTag tag)
+{
+ int ret = 0;
+
+ switch(tag) {
+ case RPMTAG_ARCH:
+ case RPMTAG_ARCHIVESIZE:
+ case RPMTAG_AUTOINSTALLED:
+ case RPMTAG_BUILDHOST:
+ case RPMTAG_BUILDTIME:
+ case RPMTAG_CHANGELOG:
+ case RPMTAG_COOKIE:
+ case RPMTAG_DBINSTANCE:
+ case RPMTAG_DISTRIBUTION:
+ case RPMTAG_DISTTAG:
+ case RPMTAG_DISTURL:
+ case RPMTAG_FILESTATES:
+ case RPMTAG_HEADERIMMUTABLE:
+ case RPMTAG_IDENTITY:
+ case RPMTAG_INSTALLCOLOR:
+ case RPMTAG_INSTALLTID:
+ case RPMTAG_INSTALLTIME:
+ case RPMTAG_INSTFILENAMES:
+ case RPMTAG_LONGARCHIVESIZE:
+ case RPMTAG_LONGSIGSIZE:
+ case RPMTAG_LONGSIZE:
+ case RPMTAG_PAYLOADDIGEST:
+ case RPMTAG_RSAHEADER:
+ case RPMTAG_SHA1HEADER:
+ case RPMTAG_SIGLEMD5_1:
+ case RPMTAG_SIGLEMD5_2:
+ case RPMTAG_SIGMD5:
+ case RPMTAG_SIGPGP:
+ case RPMTAG_SIGSIZE:
+ case RPMTAG_SIZE:
+ ret = 1;
+ break;
+ default:
+ break;
+ }
+
+ if (tag >= RPMTAG_IDENTITY_MAX_TAG)
+ ret = 1;
+
+ return ret;
+}
+
+static int identityTag(Header h, rpmtd td, headerGetFlags hgflags)
+{
+ int rc = 1;
+ unsigned int bsize;
+ void * hb;
+ DIGEST_CTX ctx;
+ char * identity = NULL;
+
+ struct rpmtd_s ttd;
+ Header ih = headerNew();
+ HeaderIterator hi = headerInitIterator(h);
+
+ while (headerNext(hi, &ttd) && rc) {
+ if (rpmtdCount(&ttd) > 0) {
+ if (!identityFilter(ttd.tag))
+ rc = headerPut(ih, &ttd, HEADERPUT_DEFAULT);
+ }
+ rpmtdFreeData(&ttd);
+ }
+ headerFreeIterator(hi);
+
+ if (!rc)
+ return 0;
+
+ hb = headerExport(ih, &bsize);
+
+ if (hb == NULL)
+ return 0;
+
+ ctx = rpmDigestInit(PGPHASHALGO_SHA256, RPMDIGEST_NONE);
+ rpmDigestUpdate(ctx, hb, bsize);
+ rpmDigestFinal(ctx, (void **) &identity, NULL, 1);
+ headerFree(ih);
+
+ td->data = xstrdup(identity);
+ td->type = RPM_STRING_TYPE;
+ td->count = 1;
+ td->flags = RPMTD_ALLOCED;
+
+ if (identity != NULL)
+ identity = _free(identity);
+
+ return rc;
+}
+
static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
{ RPMTAG_GROUP, groupTag },
{ RPMTAG_DESCRIPTION, descriptionTag },
@@ -990,6 +1082,7 @@ static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
{ RPMTAG_OBSOLETENEVRS, obsoletenevrsTag },
{ RPMTAG_CONFLICTNEVRS, conflictnevrsTag },
{ RPMTAG_FILENLINKS, filenlinksTag },
+ { RPMTAG_IDENTITY, identityTag },
{ 0, NULL }
};
--
2.10.5
More information about the Rpm-maint
mailing list