2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup lead
|
|
|
|
* \file lib/rpmlead.c
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-11-18 11:13:56 +08:00
|
|
|
|
1996-02-15 01:55:28 +08:00
|
|
|
#include <netinet/in.h>
|
1996-01-05 11:08:34 +08:00
|
|
|
|
2008-01-30 19:53:51 +08:00
|
|
|
#include <rpm/rpmlib.h> /* rpmGetOs/ArchInfo() */
|
2008-01-30 23:05:29 +08:00
|
|
|
#include <rpm/rpmlog.h>
|
2008-04-17 23:15:34 +08:00
|
|
|
#include <rpm/rpmstring.h>
|
2008-01-30 23:05:29 +08:00
|
|
|
|
2007-11-23 18:39:29 +08:00
|
|
|
#include "lib/signature.h"
|
|
|
|
#include "lib/rpmlead.h"
|
2008-01-30 23:05:29 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1996-01-05 11:05:34 +08:00
|
|
|
|
2008-10-10 20:59:38 +08:00
|
|
|
int _noDirTokens = 0;
|
|
|
|
|
2008-03-07 14:15:03 +08:00
|
|
|
static unsigned char const lead_magic[] = {
|
2002-08-06 03:45:52 +08:00
|
|
|
RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
|
|
|
|
};
|
|
|
|
|
2007-12-02 00:31:09 +08:00
|
|
|
/** \ingroup lead
|
|
|
|
* The lead data structure.
|
|
|
|
* The lead needs to be 8 byte aligned.
|
|
|
|
* @deprecated The lead (except for signature_type) is legacy.
|
|
|
|
* @todo Don't use any information from lead.
|
|
|
|
*/
|
|
|
|
struct rpmlead_s {
|
|
|
|
unsigned char magic[4];
|
|
|
|
unsigned char major;
|
|
|
|
unsigned char minor;
|
|
|
|
short type;
|
|
|
|
short archnum;
|
|
|
|
char name[66];
|
|
|
|
short osnum;
|
|
|
|
short signature_type; /*!< Signature header type (RPMSIG_HEADERSIG) */
|
|
|
|
char reserved[16]; /*!< Pad to 96 bytes -- 8 byte aligned! */
|
|
|
|
};
|
|
|
|
|
|
|
|
rpmlead rpmLeadNew(void)
|
|
|
|
{
|
|
|
|
int archnum, osnum;
|
2008-09-26 01:32:27 +08:00
|
|
|
rpmlead l = xcalloc(1, sizeof(*l));
|
2007-12-02 00:31:09 +08:00
|
|
|
|
|
|
|
rpmGetArchInfo(NULL, &archnum);
|
|
|
|
rpmGetOsInfo(NULL, &osnum);
|
|
|
|
|
|
|
|
l->major = (_noDirTokens ? 4: 3);
|
|
|
|
l->minor = 0;
|
|
|
|
l->archnum = archnum;
|
|
|
|
l->osnum = osnum;
|
|
|
|
l->signature_type = RPMSIGTYPE_HEADERSIG;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmlead rpmLeadFromHeader(Header h)
|
|
|
|
{
|
|
|
|
char * nevr;
|
|
|
|
assert(h != NULL);
|
|
|
|
rpmlead l = rpmLeadNew();
|
|
|
|
|
2008-02-08 19:45:56 +08:00
|
|
|
l->type = (headerIsSource(h) ? 1 : 0);
|
2007-12-02 00:31:09 +08:00
|
|
|
nevr = headerGetNEVR(h, NULL);
|
2008-04-17 22:35:57 +08:00
|
|
|
rstrlcpy(l->name, nevr, sizeof(l->name));
|
2007-12-02 00:31:09 +08:00
|
|
|
free(nevr);
|
1996-06-20 02:18:04 +08:00
|
|
|
|
2007-12-02 00:31:09 +08:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmlead rpmLeadFree(rpmlead lead)
|
1996-01-05 11:05:34 +08:00
|
|
|
{
|
2007-12-02 00:31:09 +08:00
|
|
|
assert(lead != NULL);
|
|
|
|
free(lead);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The lead needs to be 8 byte aligned */
|
|
|
|
rpmRC rpmLeadWrite(FD_t fd, rpmlead lead)
|
|
|
|
{
|
|
|
|
struct rpmlead_s l;
|
|
|
|
assert(lead != NULL);
|
1996-01-05 11:05:34 +08:00
|
|
|
|
2002-08-09 00:06:13 +08:00
|
|
|
memcpy(&l, lead, sizeof(l));
|
1996-01-05 11:05:34 +08:00
|
|
|
|
2002-08-09 00:06:13 +08:00
|
|
|
memcpy(&l.magic, lead_magic, sizeof(l.magic));
|
2007-12-02 00:31:09 +08:00
|
|
|
l.type = htons(lead->type);
|
|
|
|
l.archnum = htons(lead->archnum);
|
|
|
|
l.osnum = htons(lead->osnum);
|
|
|
|
l.signature_type = htons(lead->signature_type);
|
1996-01-05 11:05:34 +08:00
|
|
|
|
2002-04-13 09:28:20 +08:00
|
|
|
if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
|
2002-08-24 05:01:59 +08:00
|
|
|
return RPMRC_FAIL;
|
1996-01-05 11:05:34 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
return RPMRC_OK;
|
1996-01-05 11:05:34 +08:00
|
|
|
}
|
|
|
|
|
2008-03-31 17:07:37 +08:00
|
|
|
rpmRC rpmLeadCheck(rpmlead lead, const char **msg)
|
1996-01-05 11:05:34 +08:00
|
|
|
{
|
2007-12-02 00:31:09 +08:00
|
|
|
if (memcmp(lead->magic, lead_magic, sizeof(lead_magic))) {
|
2008-03-31 17:07:37 +08:00
|
|
|
if (msg) *msg = _("not an rpm package");
|
2007-12-02 00:31:09 +08:00
|
|
|
return RPMRC_NOTFOUND;
|
|
|
|
}
|
|
|
|
if (lead->signature_type != RPMSIGTYPE_HEADERSIG) {
|
2008-03-31 17:07:37 +08:00
|
|
|
if (msg) *msg = _("illegal signature type");
|
2007-12-02 00:31:09 +08:00
|
|
|
return RPMRC_FAIL;
|
|
|
|
}
|
|
|
|
if (lead->major < 3 || lead->major > 4) {
|
2008-03-31 17:07:37 +08:00
|
|
|
if (msg) *msg = _("unsupported RPM package version");
|
2007-12-02 00:31:09 +08:00
|
|
|
return RPMRC_FAIL;
|
|
|
|
}
|
|
|
|
return RPMRC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
|
|
|
|
{
|
|
|
|
assert(lead != NULL);
|
2001-04-30 06:43:01 +08:00
|
|
|
memset(lead, 0, sizeof(*lead));
|
2007-09-12 01:07:39 +08:00
|
|
|
/* FIX: remove timed read */
|
1999-11-05 05:26:08 +08:00
|
|
|
if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
|
2003-04-17 01:48:04 +08:00
|
|
|
if (Ferror(fd)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
|
2003-04-17 01:48:04 +08:00
|
|
|
Fstrerror(fd), errno);
|
|
|
|
return RPMRC_FAIL;
|
|
|
|
}
|
|
|
|
return RPMRC_NOTFOUND;
|
1996-02-15 01:55:28 +08:00
|
|
|
}
|
1996-01-05 11:05:34 +08:00
|
|
|
lead->type = ntohs(lead->type);
|
|
|
|
lead->archnum = ntohs(lead->archnum);
|
|
|
|
lead->osnum = ntohs(lead->osnum);
|
2002-09-01 06:39:34 +08:00
|
|
|
lead->signature_type = ntohs(lead->signature_type);
|
1996-01-05 11:05:34 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
return RPMRC_OK;
|
1996-01-05 11:05:34 +08:00
|
|
|
}
|
2008-12-09 01:50:07 +08:00
|
|
|
|
|
|
|
int rpmLeadType(rpmlead lead)
|
|
|
|
{
|
|
|
|
return lead ? lead->type : -1;
|
|
|
|
}
|