7 #include <netinet/in.h>
9 #include <rpm/rpmlib.h>
11 #include "lib/signature.h"
12 #include "lib/rpmlead.h"
13 #include "lib/legacy.h"
14 #include <rpm/rpmlog.h>
17 static unsigned char lead_magic[] = {
18 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
22 * The lead data structure.
23 * The lead needs to be 8 byte aligned.
24 * @deprecated The lead (except for signature_type) is legacy.
25 * @todo Don't use any information from lead.
28 unsigned char magic[4];
35 short signature_type; /*!< Signature header type (RPMSIG_HEADERSIG) */
36 char reserved[16]; /*!< Pad to 96 bytes -- 8 byte aligned! */
39 rpmlead rpmLeadNew(void)
42 rpmlead l = calloc(1, sizeof(*l));
44 rpmGetArchInfo(NULL, &archnum);
45 rpmGetOsInfo(NULL, &osnum);
47 l->major = (_noDirTokens ? 4: 3);
51 l->signature_type = RPMSIGTYPE_HEADERSIG;
55 rpmlead rpmLeadFromHeader(Header h)
59 rpmlead l = rpmLeadNew();
61 l->type = !(headerIsEntry(h, RPMTAG_SOURCERPM));
62 nevr = headerGetNEVR(h, NULL);
63 strncpy(l->name, nevr, sizeof(l->name));
69 rpmlead rpmLeadFree(rpmlead lead)
76 /* The lead needs to be 8 byte aligned */
77 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
82 memcpy(&l, lead, sizeof(l));
84 memcpy(&l.magic, lead_magic, sizeof(l.magic));
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* fn)
98 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
99 rpmlog(RPMLOG_ERR, _("%s: not an rpm package\n"), fn);
100 return RPMRC_NOTFOUND;
102 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
103 rpmlog(RPMLOG_ERR, _("%s: illegal signature type\n"), fn);
106 if (lead->major < 3 || lead->major > 4) {
107 rpmlog(RPMLOG_ERR, _("%s: unsupported RPM package (version %d)\n"), fn, lead->major);
113 rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
115 assert(lead != NULL);
116 memset(lead, 0, sizeof(*lead));
117 /* FIX: remove timed read */
118 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
120 rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
121 Fstrerror(fd), errno);
124 return RPMRC_NOTFOUND;
126 lead->type = ntohs(lead->type);
127 lead->archnum = ntohs(lead->archnum);
128 lead->osnum = ntohs(lead->osnum);
129 lead->signature_type = ntohs(lead->signature_type);