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)
77 /* The lead needs to be 8 byte aligned */
78 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
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 rpmRC rpmLeadCheck(rpmlead lead, const char **msg)
98 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
99 if (msg) *msg = _("not an rpm package");
100 return RPMRC_NOTFOUND;
102 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
103 if (msg) *msg = _("illegal signature type");
106 if (lead->major < 3 || lead->major > 4) {
107 if (msg) *msg = _("unsupported RPM package version");
113 rpmRC rpmLeadRead(FD_t fd, rpmlead *lead)
116 rpmlead l = xcalloc(1, sizeof(*l));
118 if (Fread(l, 1, sizeof(*l), fd) != sizeof(*l)) {
120 rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
121 Fstrerror(fd), errno);
124 rpmlog(RPMLOG_ERR, _("not an rpm package\n"));
129 if (rc == RPMRC_OK) {
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);
136 if (rc || lead == NULL)
144 int rpmLeadType(rpmlead lead)
146 return lead ? lead->type : -1;