1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-11-18 11:13:56 +08:00
|
|
|
#include "miscfn.h"
|
|
|
|
|
1996-02-15 01:54:37 +08:00
|
|
|
#include <netinet/in.h>
|
1996-01-06 02:12:55 +08:00
|
|
|
|
|
|
|
#include "header.h"
|
1998-01-10 03:10:54 +08:00
|
|
|
#include "intl.h"
|
1996-02-27 06:45:10 +08:00
|
|
|
#include "misc.h"
|
1996-01-06 08:07:50 +08:00
|
|
|
#include "oldheader.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
#include "rpmlead.h"
|
1996-01-06 08:07:50 +08:00
|
|
|
#include "rpmlib.h"
|
1996-02-22 06:20:51 +08:00
|
|
|
#include "signature.h"
|
1996-11-19 02:02:36 +08:00
|
|
|
#include "messages.h"
|
1996-01-06 08:07:50 +08:00
|
|
|
|
|
|
|
/* 0 = success */
|
|
|
|
/* !0 = error */
|
|
|
|
static int readOldHeader(int fd, Header * hdr, int * isSource);
|
1996-01-06 02:12:55 +08:00
|
|
|
|
|
|
|
/* 0 = success */
|
|
|
|
/* 1 = bad magic */
|
|
|
|
/* 2 = error */
|
1996-11-16 04:54:00 +08:00
|
|
|
static int readPackageHeaders(int fd, struct rpmlead * leadPtr,
|
|
|
|
Header * sigs, Header * hdrPtr) {
|
|
|
|
Header hdrBlock;
|
|
|
|
struct rpmlead leadBlock;
|
|
|
|
Header * hdr;
|
|
|
|
struct rpmlead * lead;
|
|
|
|
struct oldrpmlead * oldLead;
|
1996-02-27 06:45:10 +08:00
|
|
|
int_8 arch;
|
1996-11-16 04:54:00 +08:00
|
|
|
int isSource;
|
1998-01-29 00:49:43 +08:00
|
|
|
char * defaultPrefix;
|
1997-11-04 04:17:45 +08:00
|
|
|
struct stat sb;
|
1996-11-16 04:54:00 +08:00
|
|
|
|
|
|
|
hdr = hdrPtr ? hdrPtr : &hdrBlock;
|
|
|
|
lead = leadPtr ? leadPtr : &leadBlock;
|
|
|
|
|
|
|
|
oldLead = (struct oldrpmlead *) lead;
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1997-11-04 04:17:45 +08:00
|
|
|
fstat(fd, &sb);
|
1998-01-06 11:20:24 +08:00
|
|
|
/* if fd points to a socket, pipe, etc, sb.st_size is *always* zero */
|
1998-01-29 00:49:43 +08:00
|
|
|
if (S_ISREG(sb.st_mode) && sb.st_size < sizeof(*lead)) return 1;
|
1997-11-04 04:17:45 +08:00
|
|
|
|
1997-11-04 23:28:55 +08:00
|
|
|
if (readLead(fd, lead)) {
|
1996-01-06 02:12:55 +08:00
|
|
|
return 2;
|
|
|
|
}
|
1996-11-16 04:54:00 +08:00
|
|
|
|
|
|
|
if (lead->magic[0] != RPMLEAD_MAGIC0 || lead->magic[1] != RPMLEAD_MAGIC1 ||
|
|
|
|
lead->magic[2] != RPMLEAD_MAGIC2 || lead->magic[3] != RPMLEAD_MAGIC3) {
|
1996-01-06 02:12:55 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1996-11-16 04:54:00 +08:00
|
|
|
if (lead->major == 1) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "package is a version one package!\n");
|
1996-03-08 00:48:06 +08:00
|
|
|
|
1996-11-16 04:54:00 +08:00
|
|
|
if (lead->type == RPMLEAD_SOURCE) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "old style source package -- "
|
1996-11-16 04:54:00 +08:00
|
|
|
"I'll do my best\n");
|
1996-02-15 01:54:37 +08:00
|
|
|
oldLead->archiveOffset = ntohl(oldLead->archiveOffset);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "archive offset is %d\n",
|
1996-03-08 00:48:06 +08:00
|
|
|
oldLead->archiveOffset);
|
1996-02-15 01:54:37 +08:00
|
|
|
lseek(fd, oldLead->archiveOffset, SEEK_SET);
|
1996-03-30 03:39:56 +08:00
|
|
|
|
|
|
|
/* we can't put togeher a header for old format source packages,
|
|
|
|
there just isn't enough information there. We'll return
|
|
|
|
NULL <gulp> */
|
|
|
|
|
|
|
|
*hdr = NULL;
|
1996-07-11 03:50:46 +08:00
|
|
|
} else {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "old style binary package\n");
|
1996-11-16 04:54:00 +08:00
|
|
|
readOldHeader(fd, hdr, &isSource);
|
|
|
|
arch = lead->archnum;
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(*hdr, RPMTAG_ARCH, RPM_INT8_TYPE, &arch, 1);
|
1996-07-18 04:01:45 +08:00
|
|
|
arch = 1; /* old versions of RPM only supported Linux */
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(*hdr, RPMTAG_OS, RPM_INT8_TYPE, &arch, 1);
|
1996-11-16 04:54:00 +08:00
|
|
|
}
|
|
|
|
} else if (lead->major == 2 || lead->major == 3) {
|
1996-11-19 02:02:36 +08:00
|
|
|
if (rpmReadSignature(fd, sigs, lead->signature_type)) {
|
1996-11-16 04:54:00 +08:00
|
|
|
return 2;
|
|
|
|
}
|
1996-11-19 02:02:36 +08:00
|
|
|
*hdr = headerRead(fd, (lead->major >= 3) ?
|
|
|
|
HEADER_MAGIC_YES : HEADER_MAGIC_NO);
|
1996-11-16 04:54:00 +08:00
|
|
|
if (! *hdr) {
|
1996-11-19 02:02:36 +08:00
|
|
|
if (sigs) headerFree(*sigs);
|
1996-02-15 01:54:37 +08:00
|
|
|
return 2;
|
1996-11-16 04:54:00 +08:00
|
|
|
}
|
1998-01-29 00:49:43 +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);
|
|
|
|
}
|
1996-11-16 04:54:00 +08:00
|
|
|
} else {
|
1998-01-10 03:10:54 +08:00
|
|
|
rpmError(RPMERR_NEWPACKAGE, _("only packages with major numbers <= 3 "
|
|
|
|
"are supported by this version of RPM"));
|
1996-11-16 04:54:00 +08:00
|
|
|
return 2;
|
|
|
|
}
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (!hdrPtr) headerFree(*hdr);
|
1996-11-16 04:54:00 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0 = success */
|
|
|
|
/* 1 = bad magic */
|
|
|
|
/* 2 = error */
|
|
|
|
int rpmReadPackageInfo(int fd, Header * signatures, Header * hdr) {
|
|
|
|
return readPackageHeaders(fd, NULL, signatures, hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0 = success */
|
|
|
|
/* 1 = bad magic */
|
|
|
|
/* 2 = error */
|
1996-11-19 02:02:36 +08:00
|
|
|
int rpmReadPackageHeader(int fd, Header * hdr, int * isSource, int * major,
|
1996-11-16 04:54:00 +08:00
|
|
|
int * minor) {
|
|
|
|
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;
|
|
|
|
|
1996-01-06 02:12:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1996-01-06 08:07:50 +08:00
|
|
|
|
|
|
|
static int readOldHeader(int fd, Header * hdr, int * isSource) {
|
|
|
|
struct oldrpmHeader oldheader;
|
|
|
|
struct oldrpmHeaderSpec spec;
|
|
|
|
Header dbentry;
|
|
|
|
int_32 installTime = 0;
|
|
|
|
char ** fileList;
|
|
|
|
char ** fileMD5List;
|
|
|
|
char ** fileLinktoList;
|
|
|
|
int_32 * fileSizeList;
|
|
|
|
int_32 * fileUIDList;
|
|
|
|
int_32 * fileGIDList;
|
|
|
|
int_32 * fileMtimesList;
|
|
|
|
int_32 * fileFlagsList;
|
|
|
|
int_16 * fileModesList;
|
|
|
|
int_16 * fileRDevsList;
|
|
|
|
char * fileStatesList;
|
1996-01-30 03:31:05 +08:00
|
|
|
int i, j;
|
1997-08-29 02:41:06 +08:00
|
|
|
char ** unames, ** gnames;
|
1996-01-06 08:07:50 +08:00
|
|
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
if (oldhdrReadFromStream(fd, &oldheader)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldhdrParseSpec(&oldheader, &spec)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
dbentry = headerNew();
|
|
|
|
headerAddEntry(dbentry, RPMTAG_NAME, RPM_STRING_TYPE, oldheader.name, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_VERSION, RPM_STRING_TYPE, oldheader.version, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_RELEASE, RPM_STRING_TYPE, oldheader.release, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_DESCRIPTION, RPM_STRING_TYPE,
|
1996-01-06 08:07:50 +08:00
|
|
|
spec.description, 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_BUILDTIME, RPM_INT32_TYPE, &spec.buildTime, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_BUILDHOST, RPM_STRING_TYPE, spec.buildHost, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_INSTALLTIME, RPM_INT32_TYPE, &installTime, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_DISTRIBUTION, RPM_STRING_TYPE,
|
1996-01-06 08:07:50 +08:00
|
|
|
spec.distribution, 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_VENDOR, RPM_STRING_TYPE, spec.vendor, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_SIZE, RPM_INT32_TYPE, &oldheader.size, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_COPYRIGHT, RPM_STRING_TYPE, spec.copyright, 1);
|
1996-02-15 00:12:32 +08:00
|
|
|
|
|
|
|
if (oldheader.group)
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_GROUP, RPM_STRING_TYPE, oldheader.group, 1);
|
1996-02-15 00:12:32 +08:00
|
|
|
else
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_GROUP, RPM_STRING_TYPE, "Unknown", 1);
|
1996-01-06 08:07:50 +08:00
|
|
|
|
1996-01-09 03:17:43 +08:00
|
|
|
if (spec.prein)
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_PREIN, RPM_STRING_TYPE, spec.prein, 1);
|
1996-01-09 03:17:43 +08:00
|
|
|
if (spec.preun)
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_PREUN, RPM_STRING_TYPE, spec.preun, 1);
|
1996-01-09 03:17:43 +08:00
|
|
|
if (spec.postin)
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_POSTIN, RPM_STRING_TYPE, spec.postin, 1);
|
1996-01-09 03:17:43 +08:00
|
|
|
if (spec.postun)
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_POSTUN, RPM_STRING_TYPE, spec.postun, 1);
|
1996-01-09 03:17:43 +08:00
|
|
|
|
1996-01-06 08:07:50 +08:00
|
|
|
*hdr = dbentry;
|
|
|
|
|
|
|
|
if (spec.fileCount) {
|
|
|
|
/* some packages have no file lists */
|
|
|
|
|
|
|
|
fileList = malloc(sizeof(char *) * spec.fileCount);
|
|
|
|
fileLinktoList = malloc(sizeof(char *) * spec.fileCount);
|
|
|
|
fileMD5List = malloc(sizeof(char *) * spec.fileCount);
|
|
|
|
fileSizeList = malloc(sizeof(int_32) * spec.fileCount);
|
|
|
|
fileUIDList = malloc(sizeof(int_32) * spec.fileCount);
|
|
|
|
fileGIDList = malloc(sizeof(int_32) * spec.fileCount);
|
|
|
|
fileMtimesList = malloc(sizeof(int_32) * spec.fileCount);
|
|
|
|
fileFlagsList = malloc(sizeof(int_32) * spec.fileCount);
|
|
|
|
fileModesList = malloc(sizeof(int_16) * spec.fileCount);
|
|
|
|
fileRDevsList = malloc(sizeof(int_16) * spec.fileCount);
|
|
|
|
fileStatesList = malloc(sizeof(char) * spec.fileCount);
|
1997-08-29 02:41:06 +08:00
|
|
|
unames = malloc(sizeof(char *) * spec.fileCount);
|
|
|
|
gnames = malloc(sizeof(char *) * spec.fileCount);
|
|
|
|
|
|
|
|
|
|
|
|
/* We also need to contstruct a file owner/group list. We'll just
|
|
|
|
hope the numbers all map to something, those that don't will
|
|
|
|
get set as 'id%d'. Not perfect, but this should be
|
|
|
|
good enough. */
|
1996-01-06 08:07:50 +08:00
|
|
|
|
1996-01-30 03:31:05 +08:00
|
|
|
/* old packages were reverse sorted, new ones are forward sorted */
|
|
|
|
j = spec.fileCount - 1;
|
|
|
|
for (i = 0; i < spec.fileCount; i++, j--) {
|
|
|
|
fileList[j] = spec.files[i].path;
|
|
|
|
fileMD5List[j] = spec.files[i].md5;
|
|
|
|
fileSizeList[j] = spec.files[i].size;
|
|
|
|
fileUIDList[j] = spec.files[i].uid;
|
|
|
|
fileGIDList[j] = spec.files[i].gid;
|
|
|
|
fileMtimesList[j] = spec.files[i].mtime;
|
|
|
|
fileModesList[j] = spec.files[i].mode;
|
|
|
|
fileRDevsList[j] = spec.files[i].rdev;
|
|
|
|
fileStatesList[j] = spec.files[i].state;
|
1996-01-06 08:07:50 +08:00
|
|
|
|
|
|
|
if (spec.files[i].linkto)
|
1996-01-30 03:31:05 +08:00
|
|
|
fileLinktoList[j] = spec.files[i].linkto;
|
1996-01-06 08:07:50 +08:00
|
|
|
else
|
1996-01-30 03:31:05 +08:00
|
|
|
fileLinktoList[j] = "";
|
1996-01-06 08:07:50 +08:00
|
|
|
|
1996-01-30 03:31:05 +08:00
|
|
|
fileFlagsList[j] = 0;
|
1996-01-06 08:07:50 +08:00
|
|
|
if (spec.files[i].isdoc)
|
1996-01-30 03:31:05 +08:00
|
|
|
fileFlagsList[j] |= RPMFILE_DOC;
|
1996-01-06 08:07:50 +08:00
|
|
|
if (spec.files[i].isconf)
|
1996-01-30 03:31:05 +08:00
|
|
|
fileFlagsList[j] |= RPMFILE_CONFIG;
|
1997-08-29 02:41:06 +08:00
|
|
|
|
|
|
|
unames[j] = uidToUname(fileUIDList[j]);
|
|
|
|
if (unames[j])
|
|
|
|
unames[j] = strdup(unames[j]);
|
|
|
|
else {
|
|
|
|
unames[j] = malloc(20);
|
|
|
|
sprintf(unames[j], "uid%d", fileUIDList[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gnames[j] = gidToGname(fileGIDList[j]);
|
|
|
|
if (gnames[j])
|
|
|
|
gnames[j] = strdup(gnames[j]);
|
|
|
|
else {
|
|
|
|
gnames[j] = malloc(20);
|
|
|
|
sprintf(gnames[j], "gid%d", fileGIDList[j]);
|
|
|
|
}
|
1996-01-06 08:07:50 +08:00
|
|
|
}
|
|
|
|
|
1997-08-29 02:41:06 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILENAMES, RPM_STRING_ARRAY_TYPE,
|
|
|
|
fileList, spec.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILELINKTOS, RPM_STRING_ARRAY_TYPE,
|
1996-01-06 08:07:50 +08:00
|
|
|
fileLinktoList, spec.fileCount);
|
1997-08-29 02:41:06 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEMD5S, RPM_STRING_ARRAY_TYPE,
|
|
|
|
fileMD5List, spec.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILESIZES, RPM_INT32_TYPE, fileSizeList,
|
1997-08-29 02:41:06 +08:00
|
|
|
spec.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEUIDS, RPM_INT32_TYPE, fileUIDList,
|
1997-08-29 02:41:06 +08:00
|
|
|
spec.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEGIDS, RPM_INT32_TYPE, fileGIDList,
|
1997-08-29 02:41:06 +08:00
|
|
|
spec.fileCount);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEMTIMES, RPM_INT32_TYPE,
|
|
|
|
fileMtimesList, spec.fileCount);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEFLAGS, RPM_INT32_TYPE,
|
|
|
|
fileFlagsList, spec.fileCount);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEMODES, RPM_INT16_TYPE,
|
|
|
|
fileModesList, spec.fileCount);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_FILERDEVS, RPM_INT16_TYPE,
|
|
|
|
fileRDevsList, spec.fileCount);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_FILESTATES, RPM_INT8_TYPE,
|
|
|
|
fileStatesList, spec.fileCount);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEUSERNAME, RPM_STRING_ARRAY_TYPE,
|
|
|
|
unames, spec.fileCount);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEGROUPNAME, RPM_STRING_ARRAY_TYPE,
|
|
|
|
gnames, spec.fileCount);
|
1996-01-06 08:07:50 +08:00
|
|
|
|
|
|
|
free(fileList);
|
|
|
|
free(fileLinktoList);
|
|
|
|
free(fileMD5List);
|
|
|
|
free(fileSizeList);
|
|
|
|
free(fileUIDList);
|
|
|
|
free(fileGIDList);
|
|
|
|
free(fileMtimesList);
|
|
|
|
free(fileFlagsList);
|
|
|
|
free(fileModesList);
|
|
|
|
free(fileRDevsList);
|
|
|
|
free(fileStatesList);
|
1997-08-29 02:41:06 +08:00
|
|
|
|
|
|
|
for (i = 0; i < spec.fileCount; i++) {
|
|
|
|
free(unames[i]);
|
|
|
|
free(gnames[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(unames);
|
|
|
|
free(gnames);
|
1996-01-06 08:07:50 +08:00
|
|
|
}
|
|
|
|
|
1996-02-15 00:12:32 +08:00
|
|
|
oldhdrFree(&oldheader);
|
|
|
|
|
1996-01-06 08:07:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|