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
This commit is contained in:
Panu Matilainen 2008-03-31 12:07:37 +03:00
parent 7ddab3ab8d
commit dccc08ab66
4 changed files with 21 additions and 10 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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
}