static rpmRC rpmpkgReadHeader(FD_t fd, Header *hdrp, char ** msg) { char *buf = NULL; struct hdrblob_s blob; Header h = NULL; rpmRC rc = RPMRC_FAIL; /* assume failure */ if (hdrp) *hdrp = NULL; if (msg) *msg = NULL; if (hdrblobRead(fd, 1, 1, RPMTAG_HEADERIMMUTABLE, &blob, &buf) != RPMRC_OK) goto exit; /* OK, blob looks sane, load the header. */ rc = hdrblobImport(&blob, 0, &h, &buf); exit: if (hdrp && h && rc == RPMRC_OK) *hdrp = headerLink(h); headerFree(h); if (msg != NULL && *msg == NULL && buf != NULL) { *msg = buf; } else { free(buf); } return rc; }
rpmRC rpmReadSignature(FD_t fd, Header * sighp, char ** msg) { char *buf = NULL; struct hdrblob_s blob; Header sigh = NULL; rpmRC rc = RPMRC_FAIL; /* assume failure */ if (sighp) *sighp = NULL; if (hdrblobRead(fd, 1, 1, RPMTAG_HEADERSIGNATURES, &blob, &buf) != RPMRC_OK) goto exit; /* OK, blob looks sane, load the header. */ if (hdrblobImport(&blob, 0, &sigh, &buf) != RPMRC_OK) goto exit; printSize(fd, sigh); rc = RPMRC_OK; exit: if (sighp && sigh && rc == RPMRC_OK) *sighp = headerLink(sigh); headerFree(sigh); if (msg != NULL) { *msg = buf; } else { free(buf); } return rc; }
rpmRC rpmpkgRead(rpmKeyring keyring, rpmVSFlags flags, FD_t fd, rpmsinfoCb cb, void *cbdata, Header *hdrp) { char * msg = NULL; rpmRC xx, rc = RPMRC_FAIL; /* assume failure */ int failed = 0; int leadtype = -1; struct hdrblob_s sigblob, blob; struct rpmvs_s *sigset = NULL; Header h = NULL; Header sigh = NULL; rpmDigestBundle bundle = fdGetBundle(fd, 1); /* freed with fd */ memset(&blob, 0, sizeof(blob)); memset(&sigblob, 0, sizeof(sigblob)); if ((xx = rpmLeadRead(fd, &leadtype, &msg)) != RPMRC_OK) { /* Avoid message spew on manifests */ if (xx == RPMRC_NOTFOUND) msg = _free(msg); rc = xx; goto exit; } /* Read the signature header. Might not be in a contiguous region. */ if (hdrblobRead(fd, 1, 0, RPMTAG_HEADERSIGNATURES, &sigblob, &msg)) goto exit; sigset = rpmvsCreate(&sigblob, flags); /* Initialize digests ranging over the header */ rpmvsInitDigests(sigset, RPMSIG_HEADER, bundle); /* Read the header from the package. */ if (hdrblobRead(fd, 1, 1, RPMTAG_HEADERIMMUTABLE, &blob, &msg)) goto exit; /* Fish interesting tags from the main header. This is a bit hacky... */ if (!(flags & (RPMVSF_NOPAYLOAD|RPMVSF_NEEDPAYLOAD))) rpmvsAppend(sigset, &blob, RPMTAG_PAYLOADDIGEST); /* Initialize digests ranging over the payload only */ rpmvsInitDigests(sigset, RPMSIG_PAYLOAD, bundle); /* Verify header signatures and digests */ failed += rpmvsVerifyItems(sigset, (RPMSIG_HEADER), bundle, keyring, cb, cbdata); /* Unless disabled, read the file, generating digest(s) on the fly. */ if (!(flags & RPMVSF_NEEDPAYLOAD)) { if (readFile(fd, &msg)) goto exit; } /* Verify signatures and digests ranging over the payload */ failed += rpmvsVerifyItems(sigset, (RPMSIG_PAYLOAD), bundle, keyring, cb, cbdata); failed += rpmvsVerifyItems(sigset, (RPMSIG_HEADER|RPMSIG_PAYLOAD), bundle, keyring, cb, cbdata); if (failed == 0) { /* Finally import the headers and do whatever required retrofits etc */ if (hdrp) { if (hdrblobImport(&sigblob, 0, &sigh, &msg)) goto exit; if (hdrblobImport(&blob, 0, &h, &msg)) goto exit; /* Append (and remap) signature tags to the metadata. */ headerMergeLegacySigs(h, sigh); applyRetrofits(h, leadtype); /* Bump reference count for return. */ *hdrp = headerLink(h); } rc = RPMRC_OK; } exit: if (rc && msg != NULL) rpmlog(RPMLOG_ERR, "%s: %s\n", Fdescr(fd), msg); free(msg); free(sigblob.ei); free(blob.ei); headerFree(h); headerFree(sigh); rpmvsFree(sigset); return rc; }