7 #include <netinet/in.h>
9 #include <rpm/rpmlib.h> /* rpmGetOs/ArchInfo() */
10 #include <rpm/rpmlog.h>
12 #include "lib/signature.h"
13 #include "lib/rpmlead.h"
14 #include "lib/legacy.h"
18 static unsigned char lead_magic[] = {
19 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
23 * The lead data structure.
24 * The lead needs to be 8 byte aligned.
25 * @deprecated The lead (except for signature_type) is legacy.
26 * @todo Don't use any information from lead.
29 unsigned char magic[4];
36 short signature_type; /*!< Signature header type (RPMSIG_HEADERSIG) */
37 char reserved[16]; /*!< Pad to 96 bytes -- 8 byte aligned! */
40 rpmlead rpmLeadNew(void)
43 rpmlead l = calloc(1, sizeof(*l));
45 rpmGetArchInfo(NULL, &archnum);
46 rpmGetOsInfo(NULL, &osnum);
48 l->major = (_noDirTokens ? 4: 3);
52 l->signature_type = RPMSIGTYPE_HEADERSIG;
56 rpmlead rpmLeadFromHeader(Header h)
60 rpmlead l = rpmLeadNew();
62 l->type = (headerIsSource(h) ? 1 : 0);
63 nevr = headerGetNEVR(h, NULL);
64 strncpy(l->name, nevr, sizeof(l->name));
70 rpmlead rpmLeadFree(rpmlead lead)
77 /* The lead needs to be 8 byte aligned */
78 rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
83 memcpy(&l, lead, sizeof(l));
85 memcpy(&l.magic, lead_magic, sizeof(l.magic));
86 l.type = htons(lead->type);
87 l.archnum = htons(lead->archnum);
88 l.osnum = htons(lead->osnum);
89 l.signature_type = htons(lead->signature_type);
91 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
97 rpmRC rpmLeadCheck(rpmlead lead, const char* fn)
99 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
100 rpmlog(RPMLOG_ERR, _("%s: not an rpm package\n"), fn);
101 return RPMRC_NOTFOUND;
103 if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
104 rpmlog(RPMLOG_ERR, _("%s: illegal signature type\n"), fn);
107 if (lead->major < 3 || lead->major > 4) {
108 rpmlog(RPMLOG_ERR, _("%s: unsupported RPM package (version %d)\n"), fn, lead->major);
114 rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
116 assert(lead != NULL);
117 memset(lead, 0, sizeof(*lead));
118 /* FIX: remove timed read */
119 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
121 rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
122 Fstrerror(fd), errno);
125 return RPMRC_NOTFOUND;
127 lead->type = ntohs(lead->type);
128 lead->archnum = ntohs(lead->archnum);
129 lead->osnum = ntohs(lead->osnum);
130 lead->signature_type = ntohs(lead->signature_type);