2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup header
|
|
|
|
* \file lib/package.c
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-11-18 11:13:56 +08:00
|
|
|
|
1999-09-13 04:43:23 +08:00
|
|
|
#ifdef __LCLINT__
|
|
|
|
#define ntohl(_x) (_x)
|
|
|
|
#define ntohs(_x) (_x)
|
|
|
|
#define htonl(_x) (_x)
|
|
|
|
#define htons(_x) (_x)
|
|
|
|
#else
|
1996-02-15 01:54:37 +08:00
|
|
|
#include <netinet/in.h>
|
1999-09-13 04:43:23 +08:00
|
|
|
#endif /* __LCLINT__ */
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1999-07-14 05:37:57 +08:00
|
|
|
#include <rpmlib.h>
|
1998-07-31 06:09:42 +08:00
|
|
|
|
1996-02-27 06:45:10 +08:00
|
|
|
#include "misc.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
#include "rpmlead.h"
|
1996-02-22 06:20:51 +08:00
|
|
|
#include "signature.h"
|
1996-01-06 08:07:50 +08:00
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
|
|
|
* Retrieve package components from file handle.
|
|
|
|
* @param fd file handle
|
|
|
|
* @param leadPtr address of lead (or NULL)
|
|
|
|
* @param sigs address of signatures (or NULL)
|
|
|
|
* @param hdrPtr address of header (or NULL)
|
|
|
|
* @return 0 on success, 1 on bad magic, 2 on error
|
|
|
|
*/
|
1999-09-18 04:52:46 +08:00
|
|
|
static int readPackageHeaders(FD_t fd, /*@out@*/struct rpmlead * leadPtr,
|
|
|
|
/*@out@*/Header * sigs, /*@out@*/Header * hdrPtr)
|
2000-08-23 21:02:13 +08:00
|
|
|
/*@modifies *leadPtr, *sigs, *hdrPtr @*/
|
1999-07-14 07:33:02 +08:00
|
|
|
{
|
1999-07-09 06:10:33 +08:00
|
|
|
Header hdrBlock;
|
|
|
|
struct rpmlead leadBlock;
|
1999-09-18 04:52:46 +08:00
|
|
|
Header * hdr = NULL;
|
1999-07-09 06:10:33 +08:00
|
|
|
struct rpmlead * lead;
|
|
|
|
char * defaultPrefix;
|
|
|
|
struct stat sb;
|
|
|
|
int_32 true = 1;
|
|
|
|
|
|
|
|
hdr = hdrPtr ? hdrPtr : &hdrBlock;
|
|
|
|
lead = leadPtr ? leadPtr : &leadBlock;
|
|
|
|
|
1999-10-31 00:43:29 +08:00
|
|
|
fstat(Fileno(fd), &sb);
|
1999-07-09 06:10:33 +08:00
|
|
|
/* if fd points to a socket, pipe, etc, sb.st_size is *always* zero */
|
|
|
|
if (S_ISREG(sb.st_mode) && sb.st_size < sizeof(*lead)) return 1;
|
|
|
|
|
|
|
|
if (readLead(fd, lead)) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lead->magic[0] != RPMLEAD_MAGIC0 || lead->magic[1] != RPMLEAD_MAGIC1 ||
|
|
|
|
lead->magic[2] != RPMLEAD_MAGIC2 || lead->magic[3] != RPMLEAD_MAGIC3) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-05-31 03:30:28 +08:00
|
|
|
switch (lead->major) {
|
1999-07-09 06:10:33 +08:00
|
|
|
case 1:
|
2000-07-15 22:53:54 +08:00
|
|
|
rpmError(RPMERR_NEWPACKAGE, _("packaging version 1 is not"
|
2000-07-17 08:40:17 +08:00
|
|
|
" supported by this version of RPM"));
|
2000-07-15 22:53:54 +08:00
|
|
|
return 2;
|
|
|
|
/*@notreached@*/ break;
|
1999-07-09 06:10:33 +08:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2000-05-31 03:30:28 +08:00
|
|
|
case 4:
|
1999-07-09 06:10:33 +08:00
|
|
|
if (rpmReadSignature(fd, sigs, lead->signature_type)) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
*hdr = headerRead(fd, (lead->major >= 3) ?
|
|
|
|
HEADER_MAGIC_YES : HEADER_MAGIC_NO);
|
|
|
|
if (*hdr == NULL) {
|
1999-09-21 11:22:53 +08:00
|
|
|
if (sigs != NULL) {
|
|
|
|
headerFree(*sigs);
|
|
|
|
}
|
1999-07-09 06:10:33 +08:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
1999-10-07 06:50:55 +08:00
|
|
|
/* We don't use these entries (and rpm >= 2 never have) and they are
|
|
|
|
pretty misleading. Let's just get rid of them so they don't confuse
|
|
|
|
anyone. */
|
|
|
|
if (headerIsEntry(*hdr, RPMTAG_FILEUSERNAME))
|
|
|
|
headerRemoveEntry(*hdr, RPMTAG_FILEUIDS);
|
|
|
|
if (headerIsEntry(*hdr, RPMTAG_FILEGROUPNAME))
|
|
|
|
headerRemoveEntry(*hdr, RPMTAG_FILEGIDS);
|
|
|
|
|
1999-07-09 06:10:33 +08:00
|
|
|
/* We switched the way we do relocateable packages. We fix some of
|
|
|
|
it up here, though the install code still has to be a bit
|
|
|
|
careful. This fixup makes queries give the new values though,
|
|
|
|
which is quite handy. */
|
|
|
|
if (headerGetEntry(*hdr, RPMTAG_DEFAULTPREFIX, NULL,
|
|
|
|
(void **) &defaultPrefix, NULL)) {
|
|
|
|
defaultPrefix = strcpy(alloca(strlen(defaultPrefix) + 1),
|
|
|
|
defaultPrefix);
|
|
|
|
stripTrailingSlashes(defaultPrefix);
|
|
|
|
headerAddEntry(*hdr, RPMTAG_PREFIXES, RPM_STRING_ARRAY_TYPE,
|
|
|
|
&defaultPrefix, 1);
|
|
|
|
}
|
|
|
|
|
1999-10-06 23:51:14 +08:00
|
|
|
/* The file list was moved to a more compressed format which not
|
|
|
|
only saves memory (nice), but gives fingerprinting a nice, fat
|
|
|
|
speed boost (very nice). Go ahead and convert old headers to
|
|
|
|
the new style (this is a noop for new headers) */
|
2000-05-31 03:30:28 +08:00
|
|
|
if (lead->major < 4) {
|
|
|
|
compressFilelist(*hdr);
|
|
|
|
}
|
1999-10-06 23:51:14 +08:00
|
|
|
|
1999-07-09 06:10:33 +08:00
|
|
|
/* XXX binary rpms always have RPMTAG_SOURCERPM, source rpms do not */
|
|
|
|
if (lead->type == RPMLEAD_SOURCE) {
|
|
|
|
if (!headerIsEntry(*hdr, RPMTAG_SOURCEPACKAGE))
|
|
|
|
headerAddEntry(*hdr, RPMTAG_SOURCEPACKAGE, RPM_INT32_TYPE,
|
|
|
|
&true, 1);
|
2000-05-31 03:30:28 +08:00
|
|
|
} else if (lead->major < 4) {
|
2000-04-14 01:59:10 +08:00
|
|
|
/* Retrofit "Provide: name = EVR" for binary packages. */
|
|
|
|
providePackageNVR(*hdr);
|
1999-07-09 06:10:33 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-07-15 22:53:54 +08:00
|
|
|
rpmError(RPMERR_NEWPACKAGE, _("only packaging with major numbers <= 4 "
|
|
|
|
"is supported by this version of RPM"));
|
1999-07-09 06:10:33 +08:00
|
|
|
return 2;
|
1999-09-18 04:52:46 +08:00
|
|
|
/*@notreached@*/ break;
|
1999-07-09 06:10:33 +08:00
|
|
|
}
|
|
|
|
|
1999-09-21 11:22:53 +08:00
|
|
|
if (hdrPtr == NULL) {
|
|
|
|
headerFree(*hdr);
|
|
|
|
}
|
1999-07-09 06:10:33 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-07-14 07:33:02 +08:00
|
|
|
int rpmReadPackageInfo(FD_t fd, Header * signatures, Header * hdr)
|
|
|
|
{
|
1999-07-09 06:10:33 +08:00
|
|
|
return readPackageHeaders(fd, NULL, signatures, hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpmReadPackageHeader(FD_t fd, Header * hdr, int * isSource, int * major,
|
1999-07-14 07:33:02 +08:00
|
|
|
int * minor)
|
|
|
|
{
|
1999-07-09 06:10:33 +08:00
|
|
|
int rc;
|
|
|
|
struct rpmlead lead;
|
|
|
|
|
|
|
|
rc = readPackageHeaders(fd, &lead, NULL, hdr);
|
|
|
|
if (rc) return rc;
|
|
|
|
|
|
|
|
if (isSource) *isSource = lead.type == RPMLEAD_SOURCE;
|
|
|
|
if (major) *major = lead.major;
|
|
|
|
if (minor) *minor = lead.minor;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|