}
/*
+ * XXX Yet Another dressed entry to unify signature/header tag retrieval.
+ */
+int rpmPackageGetEntry(void *leadp, Header sigs, Header h,
+ int_32 tag, int_32 *type, void **p, int_32 *c)
+{
+ int_32 sigtag;
+
+ switch (tag) {
+ case RPMTAG_SIGSIZE: sigtag = RPMSIGTAG_SIZE; break;
+ case RPMTAG_SIGLEMD5_1: sigtag = RPMSIGTAG_LEMD5_1; break;
+ case RPMTAG_SIGPGP: sigtag = RPMSIGTAG_PGP; break;
+ case RPMTAG_SIGLEMD5_2: sigtag = RPMSIGTAG_LEMD5_2; break;
+ case RPMTAG_SIGMD5: sigtag = RPMSIGTAG_MD5; break;
+ case RPMTAG_SIGGPG: sigtag = RPMSIGTAG_GPG; break;
+ case RPMTAG_SIGPGP5: sigtag = RPMSIGTAG_GPG; break;
+
+ default:
+ return rpmHeaderGetEntry(h, tag, type, p, c);
+ /*@notreached@*/ break;
+ }
+
+ if (sigs == NULL) {
+ if (c) *c = 0;
+ return 0;
+ }
+
+ return headerGetEntry(sigs, sigtag, type, p, c);
+
+}
+
+/*
* Up to rpm 3.0.4, packages implicitly provided their own name-version-release.
* Retrofit an explicit "Provides: name = epoch:version-release.
*/
int rpmHeaderGetEntry(Header h, int_32 tag, /*@out@*/ int_32 *type,
/*@out@*/ void **p, /*@out@*/int_32 *c);
+/*
+ * XXX Yet Another dressed entry to unify signature/header tag retrieval.
+ */
+int rpmPackageGetEntry(void *leadp, Header sigs, Header h,
+ int_32 tag, int_32 *type, void **p, int_32 *c);
+
/* 0 = success */
/* 1 = bad magic */
/* 2 = error */
#define RPMDBI_REMOVED 4
#define RPMDBI_AVAILABLE 5
+/* Retrofit (and uniqify) signature tags for use by tagName() and rpmQuery. */
+
+/* XXX underscore prevents tagTable generation */
+#define RPMTAG_SIG_BASE 256
+#define RPMTAG_SIGSIZE RPMTAG_SIG_BASE+1
+/* the md5 sum was broken *twice* on big endian machines */
+#define RPMTAG_SIGLEMD5_1 RPMTAG_SIG_BASE+2
+#define RPMTAG_SIGPGP RPMTAG_SIG_BASE+3
+#define RPMTAG_SIGLEMD5_2 RPMTAG_SIG_BASE+4
+#define RPMTAG_SIGMD5 RPMTAG_SIG_BASE+5
+#define RPMTAG_SIGGPG RPMTAG_SIG_BASE+6
+#define RPMTAG_SIGPGP5 RPMTAG_SIG_BASE+7 /* internal */
/* these tags are found in package headers */
/* none of these can be 0 !! */
static int rpmtransSetAttr(rpmtransObject * o, char * name,
PyObject * val);
+/* signature verification */
+static PyObject * checkSig (PyObject * self, PyObject * args);
/* internal functions */
static long tagNumFromPyObject (PyObject *item);
struct hdrObject_s {
PyObject_HEAD;
Header h;
+ Header sigs;
char ** md5list;
char ** fileList;
char ** linkList;
{ "errorString", (PyCFunction) errorString, METH_VARARGS, NULL },
{ "versionCompare", (PyCFunction) versionCompare, METH_VARARGS, NULL },
{ "labelCompare", (PyCFunction) labelCompare, METH_VARARGS, NULL },
+ { "checksig", (PyCFunction) checkSig, METH_VARARGS, NULL },
/* { "Fopen", (PyCFunction) doFopen, METH_VARARGS, NULL }, */
{ NULL }
} ;
PyInt_FromLong(RPMPROB_OLDPACKAGE));
PyDict_SetItemString(d, "RPMPROB_DISKSPACE",
PyInt_FromLong(RPMPROB_DISKSPACE));
+
+ PyDict_SetItemString(d, "CHECKSIG_PGP",
+ PyInt_FromLong(CHECKSIG_PGP));
+ PyDict_SetItemString(d, "CHECKSIG_GPG",
+ PyInt_FromLong(CHECKSIG_GPG));
+ PyDict_SetItemString(d, "CHECKSIG_MD5",
+ PyInt_FromLong(CHECKSIG_MD5));
}
/* make a header with _all_ the tags we need */
static PyObject * rpmHeaderFromPackage(PyObject * self, PyObject * args) {
hdrObject * h;
Header header;
+ Header sigs;
int rc;
FD_t fd;
int rawFd;
- int isSource;
+ int isSource = 0;
if (!PyArg_ParseTuple(args, "i", &rawFd)) return NULL;
fd = fdDup(rawFd);
- rc = rpmReadPackageHeader(fd, &header, &isSource, NULL, NULL);
+ rc = rpmReadPackageInfo(fd, &sigs, &header);
Fclose(fd);
switch (rc) {
case 0:
h = (hdrObject *) PyObject_NEW(PyObject, &hdrType);
h->h = header;
+ h->sigs = sigs;
h->fileList = h->linkList = h->md5list = NULL;
h->uids = h->gids = h->mtimes = h->fileSizes = NULL;
h->modes = h->rdevs = NULL;
+ if (headerIsEntry(header, RPMTAG_SOURCEPACKAGE))
+ isSource = 1;
break;
case 1:
static void hdrDealloc(hdrObject * s) {
if (s->h) headerFree(s->h);
+ if (s->sigs) headerFree(s->sigs);
if (s->md5list) free(s->md5list);
if (s->fileList) free(s->fileList);
if (s->linkList) free(s->linkList);
return NULL;
}
- if (!rpmHeaderGetEntry(s->h, tag, &type, &data, &count)) {
+ if (!rpmPackageGetEntry(NULL, s->sigs, s->h, tag, &type, &data, &count))
+ {
Py_INCREF(Py_None);
return Py_None;
}
}
return 0;
}
+
+static PyObject * checkSig (PyObject * self, PyObject * args) {
+ char * filename;
+ int flags;
+ int rc = 255;
+
+ if (PyArg_ParseTuple(args, "si", &filename, &flags)) {
+ const char *av[2];
+ av[0] = filename;
+ av[1] = NULL;
+fprintf(stderr, "*** rpmCheckSig(%x,%p) %s\n", flags, av, av[0]);
+ rc = rpmCheckSig(flags, av);
+ }
+ return Py_BuildValue("i", rc);
+}
+
/* disable
static PyObject * doFopen(PyObject * self, PyObject * args) {
char * path, * mode;