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 rpmLeadNew(void)
44 rpmlead l = xcalloc(1, sizeof(*l));
46 rpmGetArchInfo(NULL, &archnum);
47 rpmGetOsInfo(NULL, &osnum);
53 l->signature_type = RPMSIGTYPE_HEADERSIG;
57 rpmlead rpmLeadFromHeader(Header h)
61 rpmlead l = rpmLeadNew();
63 l->type = (headerIsSource(h) ? 1 : 0);
64 nevr = headerGetAsString(h, RPMTAG_NEVR);
65 rstrlcpy(l->name, nevr, sizeof(l->name));
71 rpmlead rpmLeadFree(rpmlead lead)
78 /* The lead needs to be 8 byte aligned */
79 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
84 memcpy(&l, lead, sizeof(l));
86 memcpy(&l.magic, lead_magic, sizeof(l.magic));
87 l.type = htons(lead->type);
88 l.archnum = htons(lead->archnum);
89 l.osnum = htons(lead->osnum);
90 l.signature_type = htons(lead->signature_type);
92 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
98 rpmRC rpmLeadCheck(rpmlead lead, const char **msg)
100 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
101 if (msg) *msg = _("not an rpm package");
102 return RPMRC_NOTFOUND;
104 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
105 if (msg) *msg = _("illegal signature type");
108 if (lead->major < 3 || lead->major > 4) {
109 if (msg) *msg = _("unsupported RPM package version");
115 rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
117 assert(lead != NULL);
118 memset(lead, 0, sizeof(*lead));
119 /* FIX: remove timed read */
120 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
122 rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
123 Fstrerror(fd), errno);
126 rpmlog(RPMLOG_ERR, _("not an rpm package\n"));
127 return RPMRC_NOTFOUND;
130 lead->type = ntohs(lead->type);
131 lead->archnum = ntohs(lead->archnum);
132 lead->osnum = ntohs(lead->osnum);
133 lead->signature_type = ntohs(lead->signature_type);
138 int rpmLeadType(rpmlead lead)
140 return lead ? lead->type : -1;