1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
#include <signal.h>
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "rpmbuild.h"
|
1998-08-09 06:27:08 +08:00
|
|
|
#include "buildio.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
#include "lib/signature.h"
|
|
|
|
#include "lib/rpmlead.h"
|
|
|
|
|
|
|
|
#define RPM_MAJOR_NUMBER 3
|
|
|
|
|
|
|
|
static int processScriptFiles(Spec spec, Package pkg);
|
1998-03-21 06:38:00 +08:00
|
|
|
static StringBuf addFileToTagAux(Spec spec, char *file, StringBuf sb);
|
1998-01-13 05:31:29 +08:00
|
|
|
static int addFileToTag(Spec spec, char *file, Header h, int tag);
|
1998-03-21 06:38:00 +08:00
|
|
|
static int addFileToArrayTag(Spec spec, char *file, Header h, int tag);
|
1998-08-09 06:27:08 +08:00
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
static int cpio_gzip(FD_t fdo, CSA_t *csa);
|
|
|
|
static int cpio_copy(FD_t fdo, CSA_t *csa);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-04-08 07:58:01 +08:00
|
|
|
static int genSourceRpmName(Spec spec)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
|
|
|
char *name, *version, *release;
|
|
|
|
char fileName[BUFSIZ];
|
1998-04-08 07:58:01 +08:00
|
|
|
|
|
|
|
if (spec->sourceRpmName) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_NAME,
|
|
|
|
NULL, (void **)&name, NULL);
|
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_VERSION,
|
|
|
|
NULL, (void **)&version, NULL);
|
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_RELEASE,
|
|
|
|
NULL, (void **)&release, NULL);
|
|
|
|
sprintf(fileName, "%s-%s-%s.%ssrc.rpm", name, version, release,
|
|
|
|
spec->noSource ? "no" : "");
|
|
|
|
spec->sourceRpmName = strdup(fileName);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int packageSources(Spec spec)
|
|
|
|
{
|
1998-08-09 06:27:08 +08:00
|
|
|
CSA_t csabuf, *csa = &csabuf;
|
1998-04-08 07:58:01 +08:00
|
|
|
char fileName[BUFSIZ];
|
1998-01-13 05:31:29 +08:00
|
|
|
HeaderIterator iter;
|
|
|
|
int_32 tag, count;
|
|
|
|
char **ptr;
|
|
|
|
|
|
|
|
/* Add some cruft */
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_RPMVERSION,
|
|
|
|
RPM_STRING_TYPE, VERSION, 1);
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_BUILDHOST,
|
|
|
|
RPM_STRING_TYPE, buildHost(), 1);
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_BUILDTIME,
|
|
|
|
RPM_INT32_TYPE, getBuildTime(), 1);
|
|
|
|
|
1998-11-20 02:10:28 +08:00
|
|
|
{ int capability = 0;
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_CAPABILITY, RPM_INT32_TYPE,
|
|
|
|
&capability, 1);
|
|
|
|
}
|
|
|
|
|
1998-04-08 07:58:01 +08:00
|
|
|
genSourceRpmName(spec);
|
1998-09-06 05:54:05 +08:00
|
|
|
|
|
|
|
/* XXX this should be %_srpmdir */
|
|
|
|
strcpy(fileName, "%{_srcrpmdir}/");
|
|
|
|
expandMacros(spec, spec->macros, fileName, sizeof(fileName));
|
|
|
|
strcat(fileName, spec->sourceRpmName);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* Add the build restrictions */
|
|
|
|
iter = headerInitIterator(spec->buildRestrictions);
|
|
|
|
while (headerNextIterator(iter, &tag, NULL, (void **)&ptr, &count)) {
|
|
|
|
headerAddEntry(spec->sourceHeader, tag,
|
|
|
|
RPM_STRING_ARRAY_TYPE, ptr, count);
|
|
|
|
FREE(ptr);
|
|
|
|
}
|
|
|
|
headerFreeIterator(iter);
|
|
|
|
if (spec->buildArchitectureCount) {
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_BUILDARCHS,
|
|
|
|
RPM_STRING_ARRAY_TYPE,
|
|
|
|
spec->buildArchitectures, spec->buildArchitectureCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(spec->cookie);
|
|
|
|
|
1998-08-10 01:01:57 +08:00
|
|
|
memset(csa, 0, sizeof(*csa));
|
1998-08-09 06:27:08 +08:00
|
|
|
csa->cpioArchiveSize = 0;
|
1998-11-19 05:41:05 +08:00
|
|
|
csa->cpioFdIn = fdNew();
|
1998-08-09 06:27:08 +08:00
|
|
|
csa->cpioList = spec->sourceCpioList;
|
|
|
|
csa->cpioCount = spec->sourceCpioCount;
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
return writeRPM(spec->sourceHeader, fileName, RPMLEAD_SOURCE,
|
1998-08-09 06:27:08 +08:00
|
|
|
csa, spec->passPhrase, &(spec->cookie));
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
1998-09-01 05:06:41 +08:00
|
|
|
static int copyTags[] = {
|
|
|
|
RPMTAG_CHANGELOGTIME,
|
|
|
|
RPMTAG_CHANGELOGNAME,
|
|
|
|
RPMTAG_CHANGELOGTEXT,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int packageBinaries(Spec spec)
|
|
|
|
{
|
1998-08-09 06:27:08 +08:00
|
|
|
CSA_t csabuf, *csa = &csabuf;
|
1998-01-13 05:31:29 +08:00
|
|
|
int rc;
|
|
|
|
char *binFormat, *binRpm, *errorString;
|
|
|
|
char *name, fileName[BUFSIZ];
|
|
|
|
Package pkg;
|
|
|
|
|
1998-09-06 05:54:05 +08:00
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
|
|
|
|
|
1998-11-17 05:40:28 +08:00
|
|
|
if (pkg->fileList == NULL)
|
1998-01-13 05:31:29 +08:00
|
|
|
continue;
|
|
|
|
|
1998-09-06 05:54:05 +08:00
|
|
|
if ((rc = processScriptFiles(spec, pkg)))
|
1998-01-13 05:31:29 +08:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (spec->cookie) {
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_COOKIE,
|
|
|
|
RPM_STRING_TYPE, spec->cookie, 1);
|
|
|
|
}
|
1998-09-01 05:06:41 +08:00
|
|
|
|
|
|
|
/* Copy changelog from src rpm */
|
|
|
|
headerCopyTags(spec->packages->header, pkg->header, copyTags);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_RPMVERSION,
|
|
|
|
RPM_STRING_TYPE, VERSION, 1);
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_BUILDHOST,
|
|
|
|
RPM_STRING_TYPE, buildHost(), 1);
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_BUILDTIME,
|
|
|
|
RPM_INT32_TYPE, getBuildTime(), 1);
|
1998-04-08 07:58:01 +08:00
|
|
|
|
1998-11-20 02:10:28 +08:00
|
|
|
{ int capability = 0;
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_CAPABILITY, RPM_INT32_TYPE,
|
|
|
|
&capability, 1);
|
|
|
|
}
|
|
|
|
|
1998-04-08 07:58:01 +08:00
|
|
|
genSourceRpmName(spec);
|
1998-01-13 05:31:29 +08:00
|
|
|
headerAddEntry(pkg->header, RPMTAG_SOURCERPM, RPM_STRING_TYPE,
|
1998-04-08 07:58:01 +08:00
|
|
|
spec->sourceRpmName, 1);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
binFormat = rpmGetVar(RPMVAR_RPMFILENAME);
|
|
|
|
binRpm = headerSprintf(pkg->header, binFormat, rpmTagTable,
|
|
|
|
rpmHeaderFormats, &errorString);
|
1998-09-06 05:54:05 +08:00
|
|
|
if (binRpm == NULL) {
|
1998-01-13 05:31:29 +08:00
|
|
|
headerGetEntry(pkg->header, RPMTAG_NAME, NULL,
|
|
|
|
(void **)&name, NULL);
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADFILENAME, _("Could not generate output "
|
|
|
|
"filename for package %s: %s\n"), name, errorString);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
1998-09-06 05:54:05 +08:00
|
|
|
strcpy(fileName, "%{_rpmdir}/");
|
|
|
|
expandMacros(spec, spec->macros, fileName, sizeof(fileName));
|
|
|
|
strcat(fileName, binRpm);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(binRpm);
|
|
|
|
|
1998-08-10 01:01:57 +08:00
|
|
|
memset(csa, 0, sizeof(*csa));
|
1998-08-09 06:27:08 +08:00
|
|
|
csa->cpioArchiveSize = 0;
|
1998-11-19 05:41:05 +08:00
|
|
|
csa->cpioFdIn = fdNew();
|
1998-08-09 06:27:08 +08:00
|
|
|
csa->cpioList = pkg->cpioList;
|
|
|
|
csa->cpioCount = pkg->cpioCount;
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = writeRPM(pkg->header, fileName, RPMLEAD_BINARY,
|
1998-08-09 06:27:08 +08:00
|
|
|
csa, spec->passPhrase, NULL))) {
|
1998-01-13 05:31:29 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-10-12 04:58:58 +08:00
|
|
|
int readRPM(char *fileName, Spec *specp, struct rpmlead *lead, Header *sigs,
|
|
|
|
CSA_t *csa)
|
|
|
|
{
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fdi;
|
1998-10-12 04:58:58 +08:00
|
|
|
Spec spec;
|
|
|
|
int rc;
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fileName != NULL && fdFileno(fdi = fdOpen(fileName, O_RDONLY, 0644)) < 0) {
|
1998-10-12 04:58:58 +08:00
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: open %s: %s\n"), fileName,
|
|
|
|
strerror(errno));
|
|
|
|
return RPMERR_BADMAGIC;
|
1998-11-19 05:41:05 +08:00
|
|
|
} else {
|
1998-11-20 02:10:28 +08:00
|
|
|
fdi = fdDup(STDIN_FILENO);
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get copy of lead */
|
1998-11-19 05:41:05 +08:00
|
|
|
if ((rc = fdRead(fdi, lead, sizeof(*lead))) != sizeof(*lead)) {
|
1998-10-12 04:58:58 +08:00
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: read %s: %s\n"), fileName,
|
|
|
|
strerror(errno));
|
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
}
|
1998-11-19 05:41:05 +08:00
|
|
|
(void)fdLseek(fdi, 0, SEEK_SET); /* XXX FIXME: EPIPE */
|
1998-10-12 04:58:58 +08:00
|
|
|
|
|
|
|
/* Reallocate build data structures */
|
|
|
|
spec = newSpec();
|
|
|
|
spec->packages = newPackage(spec);
|
|
|
|
|
|
|
|
/* XXX the header just allocated will be allocated again */
|
1998-11-17 05:40:28 +08:00
|
|
|
if (spec->packages->header != NULL) {
|
1998-10-12 04:58:58 +08:00
|
|
|
headerFree(spec->packages->header);
|
|
|
|
spec->packages->header = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the rpm lead and header */
|
|
|
|
rc = rpmReadPackageInfo(fdi, sigs, &spec->packages->header);
|
|
|
|
switch (rc) {
|
|
|
|
case 1:
|
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: %s is not an RPM package\n"),
|
|
|
|
fileName);
|
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: reading header from %s\n"), fileName);
|
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specp)
|
|
|
|
*specp = spec;
|
|
|
|
|
|
|
|
if (csa) {
|
|
|
|
csa->cpioFdIn = fdi;
|
1998-11-19 05:41:05 +08:00
|
|
|
} else {
|
|
|
|
fdClose(fdi);
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-08-09 06:27:08 +08:00
|
|
|
int writeRPM(Header header, char *fileName, int type,
|
|
|
|
CSA_t *csa, char *passPhrase, char **cookie)
|
1996-02-19 10:24:47 +08:00
|
|
|
{
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fd, ifd;
|
|
|
|
int rc, count, sigtype;
|
1998-10-08 01:06:10 +08:00
|
|
|
int archnum, osnum;
|
1998-01-13 05:31:29 +08:00
|
|
|
char *sigtarget, *name, *version, *release;
|
|
|
|
char buf[BUFSIZ];
|
1996-07-08 06:11:13 +08:00
|
|
|
Header sig;
|
1998-01-13 05:31:29 +08:00
|
|
|
struct rpmlead lead;
|
1996-02-19 10:24:47 +08:00
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdFileno(csa->cpioFdIn) < 0) {
|
1998-08-10 01:01:57 +08:00
|
|
|
csa->cpioArchiveSize = 0;
|
1998-08-12 02:24:48 +08:00
|
|
|
/* Add a bogus archive size to the Header */
|
1998-08-10 01:01:57 +08:00
|
|
|
headerAddEntry(header, RPMTAG_ARCHIVESIZE, RPM_INT32_TYPE,
|
|
|
|
&csa->cpioArchiveSize, 1);
|
|
|
|
}
|
1996-02-20 07:00:16 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
/* Create and add the cookie */
|
|
|
|
if (cookie) {
|
|
|
|
sprintf(buf, "%s %d", buildHost(), (int) time(NULL));
|
|
|
|
*cookie = strdup(buf);
|
|
|
|
headerAddEntry(header, RPMTAG_COOKIE, RPM_STRING_TYPE, *cookie, 1);
|
|
|
|
}
|
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Write the header */
|
1998-01-13 05:31:29 +08:00
|
|
|
if (makeTempFile(NULL, &sigtarget, &fd)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_CREATE, _("Unable to open temp file"));
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_CREATE;
|
|
|
|
}
|
1996-11-19 02:02:36 +08:00
|
|
|
headerWrite(fd, header, HEADER_MAGIC_YES);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Write the archive and get the size */
|
1998-08-09 06:27:08 +08:00
|
|
|
if (csa->cpioList != NULL) {
|
|
|
|
rc = cpio_gzip(fd, csa);
|
1998-11-19 05:41:05 +08:00
|
|
|
} else if (fdFileno(csa->cpioFdIn) >= 0) {
|
1998-08-09 06:27:08 +08:00
|
|
|
rc = cpio_copy(fd, csa);
|
|
|
|
} else {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_CREATE, _("Bad CSA data"));
|
1998-08-09 06:27:08 +08:00
|
|
|
rc = RPMERR_BADARG;
|
|
|
|
}
|
|
|
|
if (rc != 0) {
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(fd);
|
1996-12-07 00:52:11 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
return rc;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Now set the real archive size in the Header */
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdFileno(csa->cpioFdIn) < 0) {
|
1998-08-10 01:01:57 +08:00
|
|
|
headerModifyEntry(header, RPMTAG_ARCHIVESIZE,
|
|
|
|
RPM_INT32_TYPE, &csa->cpioArchiveSize, 1);
|
|
|
|
}
|
1998-11-19 05:41:05 +08:00
|
|
|
(void)fdLseek(fd, 0, SEEK_SET);
|
1996-12-07 00:52:11 +08:00
|
|
|
headerWrite(fd, header, HEADER_MAGIC_YES);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(fd);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* Open the output file */
|
1998-05-25 06:38:40 +08:00
|
|
|
unlink(fileName);
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdFileno(fd = fdOpen(fileName, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_CREATE, _("Could not open %s\n"), fileName);
|
1996-03-30 04:06:02 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_CREATE;
|
1996-03-30 04:06:02 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* Now write the lead */
|
|
|
|
headerGetEntry(header, RPMTAG_NAME, NULL, (void **)&name, NULL);
|
|
|
|
headerGetEntry(header, RPMTAG_VERSION, NULL, (void **)&version, NULL);
|
|
|
|
headerGetEntry(header, RPMTAG_RELEASE, NULL, (void **)&release, NULL);
|
|
|
|
sprintf(buf, "%s-%s-%s", name, version, release);
|
1998-08-10 01:01:57 +08:00
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdFileno(csa->cpioFdIn) < 0) {
|
1998-10-08 01:06:10 +08:00
|
|
|
rpmGetArchInfo(NULL, &archnum);
|
|
|
|
rpmGetOsInfo(NULL, &osnum);
|
1998-08-10 01:01:57 +08:00
|
|
|
} else if (csa->lead != NULL) { /* XXX FIXME: exorcize lead/arch/os */
|
1998-10-08 01:06:10 +08:00
|
|
|
archnum = csa->lead->archnum;
|
|
|
|
osnum = csa->lead->osnum;
|
1998-08-10 01:01:57 +08:00
|
|
|
} else {
|
1998-10-08 01:06:10 +08:00
|
|
|
archnum = -1;
|
|
|
|
osnum = -1;
|
1998-08-10 01:01:57 +08:00
|
|
|
}
|
|
|
|
|
1998-04-10 04:20:17 +08:00
|
|
|
memset(&lead, 0, sizeof(lead));
|
1998-01-13 05:31:29 +08:00
|
|
|
lead.major = RPM_MAJOR_NUMBER;
|
|
|
|
lead.minor = 0;
|
|
|
|
lead.type = type;
|
1998-10-08 01:06:10 +08:00
|
|
|
lead.archnum = archnum;
|
|
|
|
lead.osnum = osnum;
|
1998-01-13 05:31:29 +08:00
|
|
|
lead.signature_type = RPMSIG_HEADERSIG; /* New-style signature */
|
|
|
|
strncpy(lead.name, buf, sizeof(lead.name));
|
|
|
|
if (writeLead(fd, &lead)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write package: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
strerror(errno));
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(fd);
|
1996-02-22 09:35:34 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return rc;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate the signature */
|
1996-11-19 02:02:36 +08:00
|
|
|
sigtype = rpmLookupSignatureType();
|
1996-02-19 10:24:47 +08:00
|
|
|
fflush(stdout);
|
1996-11-19 02:02:36 +08:00
|
|
|
sig = rpmNewSignature();
|
|
|
|
rpmAddSignature(sig, sigtarget, RPMSIGTAG_SIZE, passPhrase);
|
|
|
|
rpmAddSignature(sig, sigtarget, RPMSIGTAG_MD5, passPhrase);
|
1998-01-13 05:31:29 +08:00
|
|
|
if (sigtype > 0) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Generating signature: %d\n"), sigtype);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmAddSignature(sig, sigtarget, sigtype, passPhrase);
|
1996-07-08 06:11:13 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = rpmWriteSignature(fd, sig))) {
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(fd);
|
1996-02-22 09:35:34 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmFreeSignature(sig);
|
1998-01-13 05:31:29 +08:00
|
|
|
return rc;
|
1996-02-22 09:35:34 +08:00
|
|
|
}
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmFreeSignature(sig);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/* Append the header and archive */
|
1998-11-19 05:41:05 +08:00
|
|
|
ifd = fdOpen(sigtarget, O_RDONLY, 0);
|
|
|
|
while ((count = fdRead(ifd, buf, sizeof(buf))) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
if (count == -1) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_READERROR, _("Unable to read sigtarget: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
strerror(errno));
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(ifd);
|
|
|
|
fdClose(fd);
|
1996-02-22 23:46:54 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return RPMERR_READERROR;
|
|
|
|
}
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdWrite(fd, buf, count) < 0) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write package: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
strerror(errno));
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(ifd);
|
|
|
|
fdClose(fd);
|
1996-02-22 23:46:54 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return RPMERR_NOSPACE;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(ifd);
|
|
|
|
fdClose(fd);
|
1996-02-19 10:24:47 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1996-06-28 01:21:31 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Wrote: %s\n"), fileName);
|
1995-12-21 06:49:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
static int cpio_gzip(FD_t fdo, CSA_t *csa) {
|
1998-08-09 06:27:08 +08:00
|
|
|
CFD_t *cfd = &csa->cpioCfd;
|
1998-07-25 23:33:15 +08:00
|
|
|
int rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
char *failedFile;
|
1996-02-29 08:55:31 +08:00
|
|
|
|
1998-07-25 23:33:15 +08:00
|
|
|
cfd->cpioIoType = cpioIoTypeGzFd;
|
1998-11-23 03:48:48 +08:00
|
|
|
cfd->cpioGzFd = gzdFdopen(fdDup(fdFileno(fdo)), "w9");
|
1998-07-25 23:33:15 +08:00
|
|
|
rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL,
|
|
|
|
&csa->cpioArchiveSize, &failedFile);
|
1997-07-24 02:08:01 +08:00
|
|
|
if (rc) {
|
1998-12-06 07:22:41 +08:00
|
|
|
rpmError(RPMERR_CPIO, _("create archive failed on file %s: %s"),
|
|
|
|
failedFile, cpioStrerror(rc));
|
|
|
|
rc = 1;
|
1997-07-24 02:08:01 +08:00
|
|
|
}
|
|
|
|
|
1998-12-06 07:22:41 +08:00
|
|
|
gzdClose(cfd->cpioGzFd);
|
|
|
|
|
|
|
|
return rc;
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
static int cpio_copy(FD_t fdo, CSA_t *csa) {
|
1998-07-25 23:33:15 +08:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
size_t nb;
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
while((nb = fdRead(csa->cpioFdIn, buf, sizeof(buf))) > 0) {
|
|
|
|
if (fdWrite(fdo, buf, nb) != nb) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_CPIO, _("cpio_copy write failed: %s"),
|
1998-07-25 23:33:15 +08:00
|
|
|
strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
1998-08-09 06:27:08 +08:00
|
|
|
csa->cpioArchiveSize += nb;
|
1998-07-25 23:33:15 +08:00
|
|
|
}
|
|
|
|
if (nb < 0) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_CPIO, _("cpio_copy read failed: %s"), strerror(errno));
|
1998-07-25 23:33:15 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
static StringBuf addFileToTagAux(Spec spec, char *file, StringBuf sb)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
FILE *f;
|
|
|
|
|
1998-09-06 04:02:08 +08:00
|
|
|
strcpy(buf, "%{_builddir}/");
|
|
|
|
expandMacros(spec, spec->macros, buf, sizeof(buf));
|
|
|
|
strcat(buf, spec->buildSubdir);
|
|
|
|
strcat(buf, "/");
|
|
|
|
strcat(buf, file);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((f = fopen(buf, "r")) == NULL) {
|
|
|
|
freeStringBuf(sb);
|
1998-03-21 06:38:00 +08:00
|
|
|
return NULL;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
while (fgets(buf, sizeof(buf), f)) {
|
1998-08-01 04:11:49 +08:00
|
|
|
if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line: %s"), buf);
|
1998-05-21 01:05:26 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
appendStringBuf(sb, buf);
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
fclose(f);
|
1998-03-21 06:38:00 +08:00
|
|
|
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int addFileToTag(Spec spec, char *file, Header h, int tag)
|
|
|
|
{
|
|
|
|
StringBuf sb;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
sb = newStringBuf();
|
|
|
|
if (headerGetEntry(h, tag, NULL, (void **)&s, NULL)) {
|
|
|
|
appendLineStringBuf(sb, s);
|
|
|
|
headerRemoveEntry(h, tag);
|
|
|
|
}
|
|
|
|
|
1998-11-17 05:40:28 +08:00
|
|
|
if ((sb = addFileToTagAux(spec, file, sb)) == NULL) {
|
1998-03-21 06:38:00 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
headerAddEntry(h, tag, RPM_STRING_TYPE, getStringBuf(sb), 1);
|
1996-07-19 00:09:25 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
freeStringBuf(sb);
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
static int addFileToArrayTag(Spec spec, char *file, Header h, int tag)
|
|
|
|
{
|
|
|
|
StringBuf sb;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
sb = newStringBuf();
|
1998-11-17 05:40:28 +08:00
|
|
|
if ((sb = addFileToTagAux(spec, file, sb)) == NULL) {
|
1998-03-21 06:38:00 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = getStringBuf(sb);
|
|
|
|
headerAddOrAppendEntry(h, tag, RPM_STRING_ARRAY_TYPE, &s, 1);
|
|
|
|
|
|
|
|
freeStringBuf(sb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
static int processScriptFiles(Spec spec, Package pkg)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1998-03-21 06:38:00 +08:00
|
|
|
struct TriggerFileEntry *p;
|
|
|
|
char *bull = "";
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->preInFile) {
|
|
|
|
if (addFileToTag(spec, pkg->preInFile, pkg->header, RPMTAG_PREIN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("Could not open PreIn file: %s"), pkg->preInFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
1996-01-18 02:17:50 +08:00
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->preUnFile) {
|
|
|
|
if (addFileToTag(spec, pkg->preUnFile, pkg->header, RPMTAG_PREUN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("Could not open PreUn file: %s"), pkg->preUnFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
1996-01-08 15:07:35 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->postInFile) {
|
|
|
|
if (addFileToTag(spec, pkg->postInFile, pkg->header, RPMTAG_POSTIN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("Could not open PostIn file: %s"), pkg->postInFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->postUnFile) {
|
|
|
|
if (addFileToTag(spec, pkg->postUnFile, pkg->header, RPMTAG_POSTUN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("Could not open PostUn file: %s"), pkg->postUnFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->verifyFile) {
|
|
|
|
if (addFileToTag(spec, pkg->verifyFile, pkg->header,
|
|
|
|
RPMTAG_VERIFYSCRIPT)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("Could not open VerifyScript file: %s"), pkg->verifyFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
1996-01-08 15:07:35 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
p = pkg->triggerFiles;
|
|
|
|
while (p) {
|
|
|
|
headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTPROG,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &(p->prog), 1);
|
|
|
|
if (p->script) {
|
|
|
|
headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &(p->script), 1);
|
|
|
|
} else if (p->fileName) {
|
|
|
|
if (addFileToArrayTag(spec, p->fileName, pkg->header,
|
|
|
|
RPMTAG_TRIGGERSCRIPTS)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("Could not open Trigger script file: %s"),
|
1998-03-21 06:38:00 +08:00
|
|
|
p->fileName);
|
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* This is dumb. When the header supports NULL string */
|
|
|
|
/* this will go away. */
|
|
|
|
headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &bull, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|