7 #include <netinet/in.h>
9 #include <rpm/rpmlib.h> /* rpmGetOs/ArchInfo() */
10 #include <rpm/rpmlog.h>
11 #include <rpm/rpmstring.h>
13 #include "lib/signature.h"
14 #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 rpmLeadNew(void)
45 rpmlead l = xcalloc(1, sizeof(*l));
47 rpmGetArchInfo(NULL, &archnum);
48 rpmGetOsInfo(NULL, &osnum);
50 l->major = (_noDirTokens ? 4: 3);
54 l->signature_type = RPMSIGTYPE_HEADERSIG;
58 rpmlead rpmLeadFromHeader(Header h)
62 rpmlead l = rpmLeadNew();
64 l->type = (headerIsSource(h) ? 1 : 0);
65 nevr = headerGetAsString(h, RPMTAG_NEVR);
66 rstrlcpy(l->name, nevr, sizeof(l->name));
72 rpmlead rpmLeadFree(rpmlead lead)
79 /* The lead needs to be 8 byte aligned */
80 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
85 memcpy(&l, lead, sizeof(l));
87 memcpy(&l.magic, lead_magic, sizeof(l.magic));
88 l.type = htons(lead->type);
89 l.archnum = htons(lead->archnum);
90 l.osnum = htons(lead->osnum);
91 l.signature_type = htons(lead->signature_type);
93 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
99 rpmRC rpmLeadCheck(rpmlead lead, const char **msg)
101 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
102 if (msg) *msg = _("not an rpm package");
103 return RPMRC_NOTFOUND;
105 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
106 if (msg) *msg = _("illegal signature type");
109 if (lead->major < 3 || lead->major > 4) {
110 if (msg) *msg = _("unsupported RPM package version");
116 rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
118 assert(lead != NULL);
119 memset(lead, 0, sizeof(*lead));
120 /* FIX: remove timed read */
121 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
123 rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
124 Fstrerror(fd), errno);
127 rpmlog(RPMLOG_ERR, _("not an rpm package\n"));
128 return RPMRC_NOTFOUND;
131 lead->type = ntohs(lead->type);
132 lead->archnum = ntohs(lead->archnum);
133 lead->osnum = ntohs(lead->osnum);
134 lead->signature_type = ntohs(lead->signature_type);
139 int rpmLeadType(rpmlead lead)
141 return lead ? lead->type : -1;