From dccc08ab66c044beaba806006302c88c42ad458e Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 31 Mar 2008 12:07:37 +0300 Subject: [PATCH] Make rpmLeadCheck() return error msg instead of direct logging - allows silent checking of lead and differentiating between non-rpm files and incompatible rpms, avoiding bogus "not an rpm package" message on manifests --- lib/package.c | 5 ++++- lib/rpmchecksig.c | 10 ++++++++-- lib/rpmlead.c | 8 ++++---- lib/rpmlead.h | 8 +++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/package.c b/lib/package.c index a78427420..6dc3cfbc2 100644 --- a/lib/package.c +++ b/lib/package.c @@ -700,7 +700,10 @@ rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char * fn, Header * hdrp) l = rpmLeadNew(); if ((rc = rpmLeadRead(fd, l)) == RPMRC_OK) { - rc = rpmLeadCheck(l, fn); + const char * err = NULL; + if ((rc = rpmLeadCheck(l, &err)) == RPMRC_FAIL) { + rpmlog(RPMLOG_ERR, "%s: %s\n", fn, err); + } } l = rpmLeadFree(l); diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index daf79270d..471afc363 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -169,7 +169,10 @@ static int rpmReSign(rpmts ts, lead = rpmLeadNew(); if ((rc = rpmLeadRead(fd, lead)) == RPMRC_OK) { - rc = rpmLeadCheck(lead, rpm); + const char *lmsg = NULL; + rc = rpmLeadCheck(lead, &lmsg); + if (rc != RPMRC_OK) + rpmlog(RPMLOG_ERR, "%s: %s\n", rpm, lmsg); } if (rc != RPMRC_OK) { @@ -542,7 +545,10 @@ int rpmVerifySignatures(QVA_t qva, rpmts ts, FD_t fd, { rpmlead lead = rpmLeadNew(); if ((rc = rpmLeadRead(fd, lead)) == RPMRC_OK) { - rc = rpmLeadCheck(lead, fn); + const char *lmsg = NULL; + rc = rpmLeadCheck(lead, &lmsg); + if (rc != RPMRC_OK) + rpmlog(RPMLOG_ERR, "%s: %s\n", fn, lmsg); } lead = rpmLeadFree(lead); diff --git a/lib/rpmlead.c b/lib/rpmlead.c index 7991774cc..0907becf7 100644 --- a/lib/rpmlead.c +++ b/lib/rpmlead.c @@ -94,18 +94,18 @@ rpmRC rpmLeadWrite(FD_t fd, rpmlead lead) return RPMRC_OK; } -rpmRC rpmLeadCheck(rpmlead lead, const char* fn) +rpmRC rpmLeadCheck(rpmlead lead, const char **msg) { if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) { - rpmlog(RPMLOG_ERR, _("%s: not an rpm package\n"), fn); + if (msg) *msg = _("not an rpm package"); return RPMRC_NOTFOUND; } if (lead->signature_type != RPMSIGTYPE_HEADERSIG) { - rpmlog(RPMLOG_ERR, _("%s: illegal signature type\n"), fn); + if (msg) *msg = _("illegal signature type"); return RPMRC_FAIL; } if (lead->major < 3 || lead->major > 4) { - rpmlog(RPMLOG_ERR, _("%s: unsupported RPM package (version %d)\n"), fn, lead->major); + if (msg) *msg = _("unsupported RPM package version"); return RPMRC_FAIL; } return RPMRC_OK; diff --git a/lib/rpmlead.h b/lib/rpmlead.h index 63dbe1829..11a21eb6e 100644 --- a/lib/rpmlead.h +++ b/lib/rpmlead.h @@ -61,10 +61,12 @@ rpmRC rpmLeadRead(FD_t fd, rpmlead lead); /** \ingroup lead * Check lead for compatibility. * @param lead Pointer to lead handle - * @param fn File name - * @return RPMRC_OK on success, RPMRC_FAIL/RPMRC_NOTFOUND on error + * @retval fn Pointer to error message, NULL on success + * @return RPMRC_OK on success, + * RPMRC_NOTFOUND if not an rpm, + * RPMRC_FAIL on invalid/incompatible rpm */ -rpmRC rpmLeadCheck(rpmlead lead, const char* fn); +rpmRC rpmLeadCheck(rpmlead lead, const char **msg); #ifdef __cplusplus }