8 #include <netinet/in.h>
10 #include <rpm/rpmlib.h> /* rpmGetOs/ArchInfo() */
11 #include <rpm/rpmlog.h>
12 #include <rpm/rpmstring.h>
14 #include "lib/signature.h"
15 #include "lib/header_internal.h" /* Freadall() */
16 #include "lib/rpmlead.h"
20 static unsigned char const lead_magic[] = {
21 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
25 * The lead data structure.
26 * The lead needs to be 8 byte aligned.
27 * @deprecated The lead (except for signature_type) is legacy.
28 * @todo Don't use any information from lead.
31 unsigned char magic[4];
38 short signature_type; /*!< Signature header type (RPMSIG_HEADERSIG) */
39 char reserved[16]; /*!< Pad to 96 bytes -- 8 byte aligned! */
42 rpmlead rpmLeadFromHeader(Header h)
48 char * nevr = headerGetAsString(h, RPMTAG_NEVR);
50 /* FIXME: should grab these from header instead (RhBug:717898) */
51 rpmGetArchInfo(NULL, &archnum);
52 rpmGetOsInfo(NULL, &osnum);
54 l = xcalloc(1, sizeof(*l));
59 l->signature_type = RPMSIGTYPE_HEADERSIG;
60 l->type = (headerIsSource(h) ? 1 : 0);
62 memcpy(l->magic, lead_magic, sizeof(l->magic));
63 rstrlcpy(l->name, nevr, sizeof(l->name));
71 rpmlead rpmLeadFree(rpmlead lead)
77 /* The lead needs to be 8 byte aligned */
78 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
80 rpmRC rc = RPMRC_FAIL;
84 memcpy(&l, lead, sizeof(l));
86 l.type = htons(lead->type);
87 l.archnum = htons(lead->archnum);
88 l.osnum = htons(lead->osnum);
89 l.signature_type = htons(lead->signature_type);
91 if (Fwrite(&l, 1, sizeof(l), fd) == sizeof(l))
97 static rpmRC rpmLeadCheck(rpmlead lead, char **msg)
99 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
100 *msg = xstrdup(_("not an rpm package"));
101 return RPMRC_NOTFOUND;
103 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
104 *msg = xstrdup(_("illegal signature type"));
107 if (lead->major < 3 || lead->major > 4) {
108 *msg = xstrdup(_("unsupported RPM package version"));
114 rpmRC rpmLeadRead(FD_t fd, rpmlead *lead, int *type, char **emsg)
120 memset(&l, 0, sizeof(l));
121 if (Freadall(fd, &l, sizeof(l)) != sizeof(l)) {
123 rasprintf(&err, _("read failed: %s (%d)\n"), Fstrerror(fd), errno);
126 err = xstrdup(_("not an rpm package\n"));
130 l.type = ntohs(l.type);
131 l.archnum = ntohs(l.archnum);
132 l.osnum = ntohs(l.osnum);
133 l.signature_type = ntohs(l.signature_type);
134 rc = rpmLeadCheck(&l, &err);
137 if (rc == RPMRC_OK) {
139 *lead = xmalloc(sizeof(l));
140 memcpy(*lead, &l, sizeof(l));