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"
21 static unsigned char const lead_magic[] = {
22 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
26 * The lead data structure.
27 * The lead needs to be 8 byte aligned.
28 * @deprecated The lead (except for signature_type) is legacy.
29 * @todo Don't use any information from lead.
32 unsigned char magic[4];
39 short signature_type; /*!< Signature header type (RPMSIG_HEADERSIG) */
40 char reserved[16]; /*!< Pad to 96 bytes -- 8 byte aligned! */
43 rpmlead rpmLeadNew(void)
46 rpmlead l = xcalloc(1, sizeof(*l));
48 rpmGetArchInfo(NULL, &archnum);
49 rpmGetOsInfo(NULL, &osnum);
55 l->signature_type = RPMSIGTYPE_HEADERSIG;
59 rpmlead rpmLeadFromHeader(Header h)
63 rpmlead l = rpmLeadNew();
65 l->type = (headerIsSource(h) ? 1 : 0);
66 nevr = headerGetAsString(h, RPMTAG_NEVR);
67 rstrlcpy(l->name, nevr, sizeof(l->name));
73 rpmlead rpmLeadFree(rpmlead lead)
80 /* The lead needs to be 8 byte aligned */
81 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
86 memcpy(&l, lead, sizeof(l));
88 memcpy(&l.magic, lead_magic, sizeof(l.magic));
89 l.type = htons(lead->type);
90 l.archnum = htons(lead->archnum);
91 l.osnum = htons(lead->osnum);
92 l.signature_type = htons(lead->signature_type);
94 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
100 rpmRC rpmLeadCheck(rpmlead lead, const char **msg)
102 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
103 if (msg) *msg = _("not an rpm package");
104 return RPMRC_NOTFOUND;
106 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
107 if (msg) *msg = _("illegal signature type");
110 if (lead->major < 3 || lead->major > 4) {
111 if (msg) *msg = _("unsupported RPM package version");
117 rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
119 assert(lead != NULL);
120 memset(lead, 0, sizeof(*lead));
121 /* FIX: remove timed read */
122 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
124 rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
125 Fstrerror(fd), errno);
128 rpmlog(RPMLOG_ERR, _("not an rpm package\n"));
129 return RPMRC_NOTFOUND;
132 lead->type = ntohs(lead->type);
133 lead->archnum = ntohs(lead->archnum);
134 lead->osnum = ntohs(lead->osnum);
135 lead->signature_type = ntohs(lead->signature_type);
140 int rpmLeadType(rpmlead lead)
142 return lead ? lead->type : -1;