/** * Define or undefine per-header macros. * @param h header * @param define define/undefine? * @return 0 always */ static void rpmInstallLoadMacros(Header h, int define) { const struct tagMacro * tagm; for (tagm = tagMacros; tagm->macroname != NULL; tagm++) { struct rpmtd_s td; char *body; if (!headerGet(h, tagm->tag, &td, HEADERGET_DEFAULT)) continue; /* * Undefine doesn't need the actual data for anything, but * this way ensures we only undefine what was defined earlier. */ switch (rpmtdType(&td)) { default: if (define) { body = rpmtdFormat(&td, RPMTD_FORMAT_STRING, NULL); addMacro(NULL, tagm->macroname, NULL, body, -1); free(body); } else { delMacro(NULL, tagm->macroname); } break; case RPM_NULL_TYPE: break; } rpmtdFreeData(&td); } }
static rpmRC verifyMD5Digest(rpmtd sigtd, DIGEST_CTX md5ctx, char **msg) { rpmRC res = RPMRC_FAIL; /* assume failure */ uint8_t * md5sum = NULL; size_t md5len = 0; char *md5; const char *title = _("MD5 digest:"); *msg = NULL; DIGEST_CTX ctx = rpmDigestDup(md5ctx); if (ctx == NULL) { rasprintf(msg, "%s %s\n", title, rpmSigString(res)); goto exit; } (void) rpmDigestFinal(ctx, (void **)&md5sum, &md5len, 0); md5 = pgpHexStr(md5sum, md5len); if (md5len != sigtd->count || memcmp(md5sum, sigtd->data, md5len)) { char *hex = rpmtdFormat(sigtd, RPMTD_FORMAT_STRING, NULL); rasprintf(msg, "%s %s Expected(%s) != (%s)\n", title, rpmSigString(res), hex, md5); free(hex); } else { res = RPMRC_OK; rasprintf(msg, "%s %s (%s)\n", title, rpmSigString(res), md5); } free(md5); exit: md5sum = _free(md5sum); return res; }
static rpmRC verifyDigest(rpmtd sigtd, DIGEST_CTX digctx, const char *title, char **msg) { rpmRC res = RPMRC_FAIL; /* assume failure */ char * dig = NULL; size_t diglen = 0; char *pkgdig = rpmtdFormat(sigtd, RPMTD_FORMAT_STRING, NULL); DIGEST_CTX ctx = rpmDigestDup(digctx); if (rpmDigestFinal(ctx, (void **)&dig, &diglen, 1) || diglen == 0) { rasprintf(msg, "%s %s", title, rpmSigString(res)); goto exit; } if (strcasecmp(pkgdig, dig) == 0) { res = RPMRC_OK; rasprintf(msg, "%s %s (%s)", title, rpmSigString(res), pkgdig); } else { rasprintf(msg, "%s: %s Expected(%s) != (%s)", title, rpmSigString(res), pkgdig, dig); } exit: free(dig); free(pkgdig); return res; }
/* * Convert single tag data item to python object of suitable type */ PyObject * rpmtd_ItemAsPyobj(rpmtd td) { PyObject *res = NULL; char *str = NULL; switch (rpmtdType(td)) { case RPM_STRING_TYPE: case RPM_I18NSTRING_TYPE: case RPM_STRING_ARRAY_TYPE: res = PyString_FromString(rpmtdGetString(td)); break; case RPM_INT64_TYPE: res = PyLong_FromLongLong(*rpmtdGetUint64(td)); break; case RPM_INT32_TYPE: res = PyInt_FromLong(*rpmtdGetUint32(td)); break; case RPM_INT16_TYPE: res = PyInt_FromLong(*rpmtdGetUint16(td)); break; case RPM_BIN_TYPE: str = rpmtdFormat(td, RPMTD_FORMAT_STRING, NULL); res = PyString_FromString(str); free(str); break; default: PyErr_SetString(PyExc_KeyError, "unhandled data type"); break; } return res; }
static PyObject *rpmtd_str(rpmtdObject *self) { char *str = rpmtdFormat(self->td, RPMTD_FORMAT_STRING, NULL); if (str) { return PyString_FromString(str); } else { Py_RETURN_NONE; } }
/** * Wrap tag data in simple header xml markup. * @param td tag data container * @return formatted string */ static char * xmlFormat(rpmtd td) { const char *xtag = NULL; char *val = NULL; char *s = NULL; rpmtdFormats fmt = RPMTD_FORMAT_STRING; switch (rpmtdClass(td)) { case RPM_STRING_CLASS: xtag = "string"; break; case RPM_BINARY_CLASS: fmt = RPMTD_FORMAT_BASE64; xtag = "base64"; break; case RPM_NUMERIC_CLASS: xtag = "integer"; break; case RPM_NULL_TYPE: default: return xstrdup(_("(invalid xml type)")); break; } /* XXX TODO: handle errors */ s = rpmtdFormat(td, fmt, NULL); if (s[0] == '\0') { val = rstrscat(NULL, "\t<", xtag, "/>", NULL); } else { char *new_s = NULL; size_t i, s_size = strlen(s); for (i=0; i<s_size; i++) { switch (s[i]) { case '<': rstrcat(&new_s, "<"); break; case '>': rstrcat(&new_s, ">"); break; case '&': rstrcat(&new_s, "&"); break; default: { char c[2] = " "; *c = s[i]; rstrcat(&new_s, c); break; } } } val = rstrscat(NULL, "\t<", xtag, ">", new_s, "</", xtag, ">", NULL); free(new_s); } free(s); return val; }
/* string format should never fail but do regular repr just in case it does */ static PyObject *rpmtd_str(rpmtdObject *s) { PyObject *res = NULL; char *str = rpmtdFormat(&(s->td), RPMTD_FORMAT_STRING, NULL); if (str) { res = PyBytes_FromString(str); free(str); } else { res = PyObject_Repr((PyObject *)s); } return res; }
char * headerGetAsString(Header h, rpmTag tag) { char *res = NULL; struct rpmtd_s td; if (headerGet(h, tag, &td, HEADERGET_EXT)) { if (rpmtdCount(&td) == 1) { res = rpmtdFormat(&td, RPMTD_FORMAT_STRING, NULL); } rpmtdFreeData(&td); } return res; }
static PyObject *rpmtd_Format(rpmtdObject *self, PyObject *args, PyObject *kwds) { char *kwlist[] = {"fmt", NULL}; char *str; rpmtdFormats fmt; if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &fmt)) return NULL; str = rpmtdFormat(self->td, fmt, NULL); if (str) { return PyString_FromString(str); } Py_RETURN_NONE; }
/** * Define per-header macros. * @param h header * @return 0 always */ static void rpmInstallLoadMacros(Header h) { const struct tagMacro * tagm; for (tagm = tagMacros; tagm->macroname != NULL; tagm++) { struct rpmtd_s td; char *body; if (!headerGet(h, tagm->tag, &td, HEADERGET_DEFAULT)) continue; switch (rpmtdType(&td)) { default: body = rpmtdFormat(&td, RPMTD_FORMAT_STRING, NULL); addMacro(NULL, tagm->macroname, NULL, body, -1); free(body); break; case RPM_NULL_TYPE: break; } rpmtdFreeData(&td); } }
/** * Retrieve trigger info. * @param mode type of trigger (see tMode_e) * @param h header * @retval td tag data container * @param hgflags header get flags * @return 1 on success */ static int triggercondsTagFor(tMode mode, Header h, rpmtd td, headerGetFlags hgflags) { uint32_t * indices; int i, j; char ** conds; struct rpmtd_s nametd, indextd, flagtd, versiontd, scripttd; int hgeflags = HEADERGET_MINMEM; rpmTagVal triggername, triggerindex, triggerflags; rpmTagVal triggerversion, triggerscripts; switch (mode) { case NORMALTRIGGER: triggername = RPMTAG_TRIGGERNAME; triggerindex = RPMTAG_TRIGGERINDEX; triggerflags = RPMTAG_TRIGGERFLAGS; triggerversion = RPMTAG_TRIGGERVERSION; triggerscripts = RPMTAG_TRIGGERSCRIPTS; break; case FILETRIGGER: triggername = RPMTAG_FILETRIGGERNAME; triggerindex = RPMTAG_FILETRIGGERINDEX; triggerflags = RPMTAG_FILETRIGGERFLAGS; triggerversion = RPMTAG_FILETRIGGERVERSION; triggerscripts = RPMTAG_FILETRIGGERSCRIPTS; break; case TRANSFILETRIGGER: triggername = RPMTAG_TRANSFILETRIGGERNAME; triggerindex = RPMTAG_TRANSFILETRIGGERINDEX; triggerflags = RPMTAG_TRANSFILETRIGGERFLAGS; triggerversion = RPMTAG_TRANSFILETRIGGERVERSION; triggerscripts = RPMTAG_TRANSFILETRIGGERSCRIPTS; break; default: return 0; } if (!headerGet(h, triggername, &nametd, hgeflags)) { return 0; } headerGet(h, triggerindex, &indextd, hgeflags); headerGet(h, triggerflags, &flagtd, hgeflags); headerGet(h, triggerversion, &versiontd, hgeflags); headerGet(h, triggerscripts, &scripttd, hgeflags); td->type = RPM_STRING_ARRAY_TYPE; td->flags = RPMTD_ALLOCED | RPMTD_PTR_ALLOCED; td->data = conds = xmalloc(sizeof(*conds) * rpmtdCount(&scripttd)); td->count = rpmtdCount(&scripttd); indices = indextd.data; while ((i = rpmtdNext(&scripttd)) >= 0) { rpm_flag_t *flag; char *flagStr, *item; ARGV_t items = NULL; rpmtdInit(&nametd); rpmtdInit(&flagtd); rpmtdInit(&versiontd); while ((j = rpmtdNext(&nametd)) >= 0) { /* flag and version arrays match name array size always */ rpmtdNext(&flagtd); rpmtdNext(&versiontd); if (indices[j] != i) continue; flag = rpmtdGetUint32(&flagtd); if (flag && *flag & RPMSENSE_SENSEMASK) { flagStr = rpmtdFormat(&flagtd, RPMTD_FORMAT_DEPFLAGS, NULL); rasprintf(&item, "%s %s %s", rpmtdGetString(&nametd), flagStr, rpmtdGetString(&versiontd)); free(flagStr); } else { item = xstrdup(rpmtdGetString(&nametd)); } argvAdd(&items, item); free(item); } conds[i] = argvJoin(items, ", "); argvFree(items); } rpmtdFreeData(&nametd); rpmtdFreeData(&versiontd); rpmtdFreeData(&flagtd); rpmtdFreeData(&indextd); rpmtdFreeData(&scripttd); return 1; }