7 #include <netinet/in.h>
9 #include <rpm/rpmlib.h> /* rpmGetOs/ArchInfo() */
10 #include "lib/signature.h"
11 #include "lib/rpmlead.h"
12 #include "lib/legacy.h"
13 #include <rpm/rpmlog.h>
16 static unsigned char lead_magic[] = {
17 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
21 * The lead data structure.
22 * The lead needs to be 8 byte aligned.
23 * @deprecated The lead (except for signature_type) is legacy.
24 * @todo Don't use any information from lead.
27 unsigned char magic[4];
34 short signature_type; /*!< Signature header type (RPMSIG_HEADERSIG) */
35 char reserved[16]; /*!< Pad to 96 bytes -- 8 byte aligned! */
38 rpmlead rpmLeadNew(void)
41 rpmlead l = calloc(1, sizeof(*l));
43 rpmGetArchInfo(NULL, &archnum);
44 rpmGetOsInfo(NULL, &osnum);
46 l->major = (_noDirTokens ? 4: 3);
50 l->signature_type = RPMSIGTYPE_HEADERSIG;
54 rpmlead rpmLeadFromHeader(Header h)
58 rpmlead l = rpmLeadNew();
60 l->type = !(headerIsSource(h));
61 nevr = headerGetNEVR(h, NULL);
62 strncpy(l->name, nevr, sizeof(l->name));
68 rpmlead rpmLeadFree(rpmlead lead)
75 /* The lead needs to be 8 byte aligned */
76 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
81 memcpy(&l, lead, sizeof(l));
83 memcpy(&l.magic, lead_magic, sizeof(l.magic));
84 l.type = htons(lead->type);
85 l.archnum = htons(lead->archnum);
86 l.osnum = htons(lead->osnum);
87 l.signature_type = htons(lead->signature_type);
89 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
95 rpmRC rpmLeadCheck(rpmlead lead, const char* fn)
97 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
98 rpmlog(RPMLOG_ERR, _("%s: not an rpm package\n"), fn);
99 return RPMRC_NOTFOUND;
101 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
102 rpmlog(RPMLOG_ERR, _("%s: illegal signature type\n"), fn);
105 if (lead->major < 3 || lead->major > 4) {
106 rpmlog(RPMLOG_ERR, _("%s: unsupported RPM package (version %d)\n"), fn, lead->major);
112 rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
114 assert(lead != NULL);
115 memset(lead, 0, sizeof(*lead));
116 /* FIX: remove timed read */
117 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
119 rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
120 Fstrerror(fd), errno);
123 return RPMRC_NOTFOUND;
125 lead->type = ntohs(lead->type);
126 lead->archnum = ntohs(lead->archnum);
127 lead->osnum = ntohs(lead->osnum);
128 lead->signature_type = ntohs(lead->signature_type);