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/rpmlead.h"
19 static unsigned char const lead_magic[] = {
20 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
24 * The lead data structure.
25 * The lead needs to be 8 byte aligned.
26 * @deprecated The lead (except for signature_type) is legacy.
27 * @todo Don't use any information from lead.
30 unsigned char magic[4];
37 short signature_type; /*!< Signature header type (RPMSIG_HEADERSIG) */
38 char reserved[16]; /*!< Pad to 96 bytes -- 8 byte aligned! */
41 rpmlead rpmLeadFromHeader(Header h)
47 char * nevr = headerGetAsString(h, RPMTAG_NEVR);
49 /* FIXME: should grab these from header instead (RhBug:717898) */
50 rpmGetArchInfo(NULL, &archnum);
51 rpmGetOsInfo(NULL, &osnum);
53 l = xcalloc(1, sizeof(*l));
58 l->signature_type = RPMSIGTYPE_HEADERSIG;
59 l->type = (headerIsSource(h) ? 1 : 0);
61 memcpy(l->magic, lead_magic, sizeof(l->magic));
62 rstrlcpy(l->name, nevr, sizeof(l->name));
70 rpmlead rpmLeadFree(rpmlead lead)
76 /* The lead needs to be 8 byte aligned */
77 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
79 rpmRC rc = RPMRC_FAIL;
83 memcpy(&l, lead, sizeof(l));
85 l.type = htons(lead->type);
86 l.archnum = htons(lead->archnum);
87 l.osnum = htons(lead->osnum);
88 l.signature_type = htons(lead->signature_type);
90 if (Fwrite(&l, 1, sizeof(l), fd) == sizeof(l))
96 static rpmRC rpmLeadCheck(rpmlead lead, char **msg)
98 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
99 *msg = xstrdup(_("not an rpm package"));
100 return RPMRC_NOTFOUND;
102 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
103 *msg = xstrdup(_("illegal signature type"));
106 if (lead->major < 3 || lead->major > 4) {
107 *msg = xstrdup(_("unsupported RPM package version"));
113 rpmRC rpmLeadRead(FD_t fd, rpmlead *lead, int *type, char **emsg)
119 memset(&l, 0, sizeof(l));
120 if (Fread(&l, 1, sizeof(l), fd) != sizeof(l)) {
122 rasprintf(&err, _("read failed: %s (%d)\n"), Fstrerror(fd), errno);
125 err = xstrdup(_("not an rpm package\n"));
129 l.type = ntohs(l.type);
130 l.archnum = ntohs(l.archnum);
131 l.osnum = ntohs(l.osnum);
132 l.signature_type = ntohs(l.signature_type);
133 rc = rpmLeadCheck(&l, &err);
136 if (rc == RPMRC_OK) {
138 *lead = xmalloc(sizeof(l));
139 memcpy(*lead, &l, sizeof(l));