- Main Page
- Related Pages
- Modules
- Data Structures
- Files

# build/pack.c

Go to the documentation of this file.

    00001
    00006 #include "system.h"
    00007
    00008 #include <rpmio_internal.h>     /* XXX fdGetFp, fdInitDigest, fdFiniDigest */
    00009 #define _RPMFI_INTERNAL         /* XXX fi->fsm */
    00010 #define _RPMEVR_INTERNAL        /* XXX RPMSENSE_ANY */
    00011 #define _RPMTAG_INTERNAL
    00012 #include <rpmbuild.h>
    00013 #include "signature.h"          /* XXX rpmTempFile */
    00014
    00015 #include "cpio.h"
    00016 #include "fsm.h"
    00017
    00018 #include "buildio.h"
    00019
    00020 #include "signature.h"
    00021 #include <pkgio.h>
    00022 #include "debug.h"
    00023
    00024 /*@access rpmts @*/
    00025 /*@access rpmfi @*/     /* compared with NULL */
    00026 /*@access Header @*/    /* compared with NULL */
    00027 /*@access FD_t @*/      /* compared with NULL */
    00028 /*@access StringBuf @*/ /* compared with NULL */
    00029 /*@access CSA_t @*/
    00030
    00033 static inline int genSourceRpmName(Spec spec)
    00034         /*@modifies spec->sourceRpmName, spec->packages->header @*/
    00035 {
    00036     if (spec->sourceRpmName == NULL) {
    00037         const char *N, *V, *R;
    00038         char fileName[BUFSIZ];
    00039
    00040         (void) headerNEVRA(spec->packages->header, &N, NULL, &V, &R, NULL);
    00041         (void) snprintf(fileName, sizeof(fileName), "%s-%s-%s.%ssrc.rpm",
    00042                         N, V, R, spec->noSource ? "no" : "");
    00043         fileName[sizeof(fileName)-1] = '\0';
    00044         N = _free(N);
    00045         V = _free(V);
    00046         R = _free(R);
    00047         spec->sourceRpmName = xstrdup(fileName);
    00048     }
    00049
    00050     return 0;
    00051 }
    00052
    00056 static rpmRC cpio_doio(FD_t fdo, /*@unused@*/ Header h, CSA_t csa,
    00057                 const char * payload_format, const char * fmodeMacro)
    00058         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
    00059         /*@modifies fdo, csa, rpmGlobalMacroContext,
    00060                 fileSystem, internalState @*/
    00061 {
    00062     rpmts ts = rpmtsCreate();
    00063     rpmfi fi = csa->cpioList;
    00064     const char *failedFile = NULL;
    00065     FD_t cfd;
    00066     rpmRC rc = RPMRC_OK;
    00067     int xx;
    00068
    00069     {   const char *fmode = rpmExpand(fmodeMacro, NULL);
    00070         if (!(fmode && fmode[0] == 'w'))
    00071             fmode = xstrdup("w9.gzdio");
    00072         /*@-nullpass@*/
    00073         (void) Fflush(fdo);
    00074         cfd = Fdopen(fdDup(Fileno(fdo)), fmode);
    00075         /*@=nullpass@*/
    00076         fmode = _free(fmode);
    00077     }
    00078     if (cfd == NULL)
    00079         return RPMRC_FAIL;
    00080
    00081     xx = fsmSetup(fi->fsm, FSM_PKGBUILD, payload_format, ts, fi, cfd,
    00082                 &csa->cpioArchiveSize, &failedFile);
    00083     if (xx)
    00084         rc = RPMRC_FAIL;
    00085     (void) Fclose(cfd);
    00086     xx = fsmTeardown(fi->fsm);
    00087     if (rc == RPMRC_OK && xx) rc = RPMRC_FAIL;
    00088
    00089     if (rc) {
    00090         if (failedFile)
    00091             rpmlog(RPMLOG_ERR, _("create archive failed on file %s: %s\n"),
    00092                 failedFile, cpioStrerror(rc));
    00093         else
    00094             rpmlog(RPMLOG_ERR, _("create archive failed: %s\n"),
    00095                 cpioStrerror(rc));
    00096       rc = RPMRC_FAIL;
    00097     }
    00098
    00099     failedFile = _free(failedFile);
    00100     ts = rpmtsFree(ts);
    00101
    00102     return rc;
    00103 }
    00104
    00107 static rpmRC cpio_copy(FD_t fdo, CSA_t csa)
    00108         /*@globals fileSystem, internalState @*/
    00109         /*@modifies fdo, csa, fileSystem, internalState @*/
    00110 {
    00111     char buf[BUFSIZ];
    00112     size_t nb;
    00113
    00114     while((nb = Fread(buf, sizeof(buf[0]), sizeof(buf), csa->cpioFdIn)) > 0) {
    00115         if (Fwrite(buf, sizeof(buf[0]), nb, fdo) != nb) {
    00116             rpmlog(RPMLOG_ERR, _("cpio_copy write failed: %s\n"),
    00117                         Fstrerror(fdo));
    00118             return RPMRC_FAIL;
    00119         }
    00120         csa->cpioArchiveSize += nb;
    00121     }
    00122     if (Ferror(csa->cpioFdIn)) {
    00123         rpmlog(RPMLOG_ERR, _("cpio_copy read failed: %s\n"),
    00124                 Fstrerror(csa->cpioFdIn));
    00125         return RPMRC_FAIL;
    00126     }
    00127     return RPMRC_OK;
    00128 }
    00129
    00132 static /*@only@*/ /*@null@*/ StringBuf addFileToTagAux(Spec spec,
    00133                 const char * file, /*@only@*/ StringBuf sb)
    00134         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
    00135         /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/
    00136 {
    00137     char buf[BUFSIZ];
    00138     const char * fn = buf;
    00139     FILE * f;
    00140     FD_t fd;
    00141
    00142     fn = rpmGetPath("%{_builddir}/%{?buildsubdir:%{buildsubdir}/}", file, NULL);
    00143
    00144     fd = Fopen(fn, "r.fdio");
    00145     if (fn != buf) fn = _free(fn);
    00146     if (fd == NULL || Ferror(fd)) {
    00147         sb = freeStringBuf(sb);
    00148         return NULL;
    00149     }
    00150     /*@-type@*/ /* FIX: cast? */
    00151     if ((f = fdGetFp(fd)) != NULL)
    00152     /*@=type@*/
    00153     while (fgets(buf, sizeof(buf), f)) {
    00154         /* XXX display fn in error msg */
    00155         if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
    00156             rpmlog(RPMLOG_ERR, _("line: %s\n"), buf);
    00157             sb = freeStringBuf(sb);
    00158             break;
    00159         }
    00160         appendStringBuf(sb, buf);
    00161     }
    00162     (void) Fclose(fd);
    00163
    00164     return sb;
    00165 }
    00166
    00169 static int addFileToTag(Spec spec, const char * file, Header h, rpmTag tag)
    00170         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
    00171         /*@modifies h, rpmGlobalMacroContext, fileSystem, internalState @*/
    00172 {
    00173     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    00174     StringBuf sb = newStringBuf();
    00175     int xx;
    00176
    00177     he->tag = tag;
    00178     xx = headerGet(h, he, 0);
    00179     if (xx) {
    00180         appendLineStringBuf(sb, he->p.str);
    00181         xx = headerDel(h, he, 0);
    00182     }
    00183     he->p.ptr = _free(he->p.ptr);
    00184
    00185     if ((sb = addFileToTagAux(spec, file, sb)) == NULL)
    00186         return 1;
    00187
    00188     he->tag = tag;
    00189     he->t = RPM_STRING_TYPE;
    00190     he->p.str = getStringBuf(sb);
    00191     he->c = 1;
    00192     xx = headerPut(h, he, 0);
    00193
    00194     sb = freeStringBuf(sb);
    00195     return 0;
    00196 }
    00197
    00200 static int addFileToArrayTag(Spec spec, const char *file, Header h, int tag)
    00201         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
    00202         /*@modifies h, rpmGlobalMacroContext, fileSystem, internalState  @*/
    00203 {
    00204     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    00205     StringBuf sb = newStringBuf();
    00206     const char *s;
    00207     int xx;
    00208
    00209     if ((sb = addFileToTagAux(spec, file, sb)) == NULL)
    00210         return 1;
    00211
    00212     s = getStringBuf(sb);
    00213
    00214     he->tag = tag;
    00215     he->t = RPM_STRING_ARRAY_TYPE;
    00216     he->p.argv = &s;
    00217     he->c = 1;
    00218     he->append = 1;
    00219     xx = headerPut(h, he, 0);
    00220     he->append = 0;
    00221
    00222     sb = freeStringBuf(sb);
    00223     return 0;
    00224 }
    00225
    00226 rpmRC processScriptFiles(Spec spec, Package pkg)
    00227         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
    00228         /*@modifies pkg->header, rpmGlobalMacroContext,
    00229                 fileSystem, internalState @*/
    00230 {
    00231     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    00232     struct TriggerFileEntry *p;
    00233     int xx;
    00234
    00235     if (pkg->preInFile) {
    00236         if (addFileToTag(spec, pkg->preInFile, pkg->header, RPMTAG_PREIN)) {
    00237             rpmlog(RPMLOG_ERR,
    00238                      _("Could not open PreIn file: %s\n"), pkg->preInFile);
    00239             return RPMRC_FAIL;
    00240         }
    00241     }
    00242     if (pkg->preUnFile) {
    00243         if (addFileToTag(spec, pkg->preUnFile, pkg->header, RPMTAG_PREUN)) {
    00244             rpmlog(RPMLOG_ERR,
    00245                      _("Could not open PreUn file: %s\n"), pkg->preUnFile);
    00246             return RPMRC_FAIL;
    00247         }
    00248     }
    00249     if (pkg->preTransFile) {
    00250         if (addFileToTag(spec, pkg->preTransFile, pkg->header, RPMTAG_PRETRANS)) {
    00251             rpmlog(RPMLOG_ERR,
    00252                      _("Could not open PreIn file: %s\n"), pkg->preTransFile);
    00253             return RPMRC_FAIL;
    00254         }
    00255     }
    00256     if (pkg->postInFile) {
    00257         if (addFileToTag(spec, pkg->postInFile, pkg->header, RPMTAG_POSTIN)) {
    00258             rpmlog(RPMLOG_ERR,
    00259                      _("Could not open PostIn file: %s\n"), pkg->postInFile);
    00260             return RPMRC_FAIL;
    00261         }
    00262     }
    00263     if (pkg->postUnFile) {
    00264         if (addFileToTag(spec, pkg->postUnFile, pkg->header, RPMTAG_POSTUN)) {
    00265             rpmlog(RPMLOG_ERR,
    00266                      _("Could not open PostUn file: %s\n"), pkg->postUnFile);
    00267             return RPMRC_FAIL;
    00268         }
    00269     }
    00270     if (pkg->postTransFile) {
    00271         if (addFileToTag(spec, pkg->postTransFile, pkg->header, RPMTAG_POSTTRANS)) {
    00272             rpmlog(RPMLOG_ERR,
    00273                      _("Could not open PostUn file: %s\n"), pkg->postTransFile);
    00274             return RPMRC_FAIL;
    00275         }
    00276     }
    00277     if (pkg->verifyFile) {
    00278         if (addFileToTag(spec, pkg->verifyFile, pkg->header,
    00279                          RPMTAG_VERIFYSCRIPT)) {
    00280             rpmlog(RPMLOG_ERR,
    00281                      _("Could not open VerifyScript file: %s\n"), pkg->verifyFile);
    00282             return RPMRC_FAIL;
    00283         }
    00284     }
    00285
    00286     if (pkg->sanityCheckFile) {
    00287         if (addFileToTag(spec, pkg->sanityCheckFile, pkg->header, RPMTAG_SANITYCHECK)) {
    00288             rpmlog(RPMLOG_ERR, _("Could not open Test file: %s\n"), pkg->sanityCheckFile);
    00289             return RPMRC_FAIL;
    00290         }
    00291     }
    00292
    00293     for (p = pkg->triggerFiles; p != NULL; p = p->next) {
    00294         he->tag = RPMTAG_TRIGGERSCRIPTPROG;
    00295         he->t = RPM_STRING_ARRAY_TYPE;
    00296         he->p.argv = (const char **)&p->prog;   /* XXX NOCAST */
    00297         he->c = 1;
    00298         he->append = 1;
    00299         xx = headerPut(pkg->header, he, 0);
    00300         he->append = 0;
    00301         if (p->script) {
    00302             he->tag = RPMTAG_TRIGGERSCRIPTS;
    00303             he->t = RPM_STRING_ARRAY_TYPE;
    00304             he->p.argv = (const char **)&p->script;     /* XXX NOCAST */
    00305             he->c = 1;
    00306             he->append = 1;
    00307             xx = headerPut(pkg->header, he, 0);
    00308             he->append = 0;
    00309         } else if (p->fileName) {
    00310             if (addFileToArrayTag(spec, p->fileName, pkg->header,
    00311                                   RPMTAG_TRIGGERSCRIPTS)) {
    00312                 rpmlog(RPMLOG_ERR,
    00313                          _("Could not open Trigger script file: %s\n"),
    00314                          p->fileName);
    00315                 return RPMRC_FAIL;
    00316             }
    00317         } else {
    00318             static const char *bull = "";
    00319             he->tag = RPMTAG_TRIGGERSCRIPTS;
    00320             he->t = RPM_STRING_ARRAY_TYPE;
    00321             he->p.argv = &bull;
    00322             he->c = 1;
    00323             he->append = 1;
    00324             xx = headerPut(pkg->header, he, 0);
    00325             he->append = 0;
    00326         }
    00327     }
    00328
    00329     return RPMRC_OK;
    00330 }
    00331
    00332 #if defined(DEAD)
    00333 int readRPM(const char *fileName, Spec *specp, void * l,
    00334                 Header *sigs, CSA_t csa)
    00335 {
    00336     const char * msg = "";
    00337     FD_t fdi;
    00338     Spec spec;
    00339     rpmRC rc;
    00340
    00341     fdi = (fileName != NULL)
    00342         ? Fopen(fileName, "r.fdio")
    00343         : fdDup(STDIN_FILENO);
    00344
    00345     if (fdi == NULL || Ferror(fdi)) {
    00346         rpmlog(RPMLOG_ERR, _("readRPM: open %s: %s\n"),
    00347                 (fileName ? fileName : "<stdin>"),
    00348                 Fstrerror(fdi));
    00349         if (fdi) (void) Fclose(fdi);
    00350         return RPMRC_FAIL;
    00351     }
    00352
    00353     {   const char item[] = "Lead";
    00354         size_t nl = rpmpkgSizeof(item, NULL);
    00355
    00356         if (nl == 0) {
    00357             rc = RPMRC_FAIL;
    00358             msg = xstrdup("item size is zero");
    00359         } else {
    00360             l = xcalloc(1, nl);         /* XXX memory leak */
    00361             msg = NULL;
    00362             rc = rpmpkgRead(item, fdi, l, &msg);
    00363         }
    00364     }
    00365
    00366     if (rc != RPMRC_OK) {
    00367         rpmlog(RPMLOG_ERR, _("readRPM: read %s: %s\n"),
    00368                 (fileName ? fileName : "<stdin>"), msg);
    00369         msg = _free(msg);
    00370         return RPMRC_FAIL;
    00371     }
    00372     msg = _free(msg);
    00373     /*@=sizeoftype@*/
    00374
    00375     /* XXX FIXME: EPIPE on <stdin> */
    00376     if (Fseek(fdi, 0, SEEK_SET) == -1) {
    00377         rpmlog(RPMLOG_ERR, _("%s: Fseek failed: %s\n"),
    00378                         (fileName ? fileName : "<stdin>"), Fstrerror(fdi));
    00379         return RPMRC_FAIL;
    00380     }
    00381
    00382     /* Reallocate build data structures */
    00383     spec = newSpec();
    00384     spec->packages = newPackage(spec);
    00385
    00386     /* XXX the header just allocated will be allocated again */
    00387     spec->packages->header = headerFree(spec->packages->header);
    00388
    00389     /* Read the rpm lead, signatures, and header */
    00390     {   rpmts ts = rpmtsCreate();
    00391
    00392         /* XXX W2DO? pass fileName? */
    00393         /*@-mustmod@*/      /* LCL: segfault */
    00394         rc = rpmReadPackageFile(ts, fdi, "readRPM",
    00395                          &spec->packages->header);
    00396         /*@=mustmod@*/
    00397
    00398         ts = rpmtsFree(ts);
    00399
    00400         if (sigs) *sigs = NULL;                 /* XXX HACK */
    00401     }
    00402
    00403     switch (rc) {
    00404     case RPMRC_OK:
    00405     case RPMRC_NOKEY:
    00406     case RPMRC_NOTTRUSTED:
    00407         break;
    00408     case RPMRC_NOTFOUND:
    00409         rpmlog(RPMLOG_ERR, _("readRPM: %s is not an RPM package\n"),
    00410                 (fileName ? fileName : "<stdin>"));
    00411         return RPMRC_FAIL;
    00412     case RPMRC_FAIL:
    00413     default:
    00414         rpmlog(RPMLOG_ERR, _("readRPM: reading header from %s\n"),
    00415                 (fileName ? fileName : "<stdin>"));
    00416         return RPMRC_FAIL;
    00417         /*@notreached@*/ break;
    00418     }
    00419
    00420     if (specp)
    00421         *specp = spec;
    00422     else
    00423         spec = freeSpec(spec);
    00424
    00425     if (csa != NULL)
    00426         csa->cpioFdIn = fdi;
    00427     else
    00428         (void) Fclose(fdi);
    00429
    00430     return 0;
    00431 }
    00432 #endif
    00433
    00434 #if defined(DEAD)
    00435 #define RPMPKGVERSION_MIN       30004
    00436 #define RPMPKGVERSION_MAX       40003
    00437 /*@unchecked@*/
    00438 static int rpmpkg_version = -1;
    00439
    00440 static int rpmLeadVersion(void)
    00441         /*@globals rpmpkg_version, rpmGlobalMacroContext, h_errno @*/
    00442         /*@modifies rpmpkg_version, rpmGlobalMacroContext @*/
    00443 {
    00444     int rpmlead_version;
    00445
    00446     /* Intitialize packaging version from macro configuration. */
    00447     if (rpmpkg_version < 0) {
    00448         rpmpkg_version = rpmExpandNumeric("%{_package_version}");
    00449         if (rpmpkg_version < RPMPKGVERSION_MIN)
    00450             rpmpkg_version = RPMPKGVERSION_MIN;
    00451         if (rpmpkg_version > RPMPKGVERSION_MAX)
    00452             rpmpkg_version = RPMPKGVERSION_MAX;
    00453     }
    00454
    00455     rpmlead_version = rpmpkg_version / 10000;
    00456     /* XXX silly sanity check. */
    00457     if (rpmlead_version < 3 || rpmlead_version > 4)
    00458         rpmlead_version = 3;
    00459     return rpmlead_version;
    00460 }
    00461 #endif
    00462
    00463 void providePackageNVR(Header h)
    00464 {
    00465     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    00466     const char *N, *V, *R;
    00467     uint32_t E;
    00468     int gotE;
    00469     const char *pEVR;
    00470     char *p;
    00471     uint32_t pFlags = RPMSENSE_EQUAL;
    00472     const char ** provides = NULL;
    00473     const char ** providesEVR = NULL;
    00474     uint32_t * provideFlags = NULL;
    00475     int providesCount;
    00476     int i, xx;
    00477     int bingo = 1;
    00478
    00479     /* Generate provides for this package N-V-R. */
    00480     xx = headerNEVRA(h, &N, NULL, &V, &R, NULL);
    00481     if (!(N && V && R))
    00482         return;
    00483     pEVR = p = alloca(21 + strlen(V) + 1 + strlen(R) + 1);
    00484     *p = '\0';
    00485     he->tag = RPMTAG_EPOCH;
    00486     gotE = headerGet(h, he, 0);
    00487     E = (he->p.ui32p ? he->p.ui32p[0] : 0);
    00488     he->p.ptr = _free(he->p.ptr);
    00489     if (gotE) {
    00490         sprintf(p, "%d:", E);
    00491         p += strlen(p);
    00492     }
    00493     (void) stpcpy( stpcpy( stpcpy(p, V) , "-") , R);
    00494     V = _free(V);
    00495     R = _free(R);
    00496
    00497     /*
    00498      * Rpm prior to 3.0.3 does not have versioned provides.
    00499      * If no provides at all are available, we can just add.
    00500      */
    00501     he->tag = RPMTAG_PROVIDENAME;
    00502     xx = headerGet(h, he, 0);
    00503     provides = he->p.argv;
    00504     providesCount = he->c;
    00505     if (!xx)
    00506         goto exit;
    00507
    00508     /*
    00509      * Otherwise, fill in entries on legacy packages.
    00510      */
    00511     he->tag = RPMTAG_PROVIDEVERSION;
    00512     xx = headerGet(h, he, 0);
    00513     providesEVR = he->p.argv;
    00514     if (!xx) {
    00515         for (i = 0; i < providesCount; i++) {
    00516             static const char * vdummy = "";
    00517             static rpmsenseFlags fdummy = RPMSENSE_ANY;
    00518
    00519             he->tag = RPMTAG_PROVIDEVERSION;
    00520             he->t = RPM_STRING_ARRAY_TYPE;
    00521             he->p.argv = &vdummy;
    00522             he->c = 1;
    00523             he->append = 1;
    00524             xx = headerPut(h, he, 0);
    00525             he->append = 0;
    00526
    00527             he->tag = RPMTAG_PROVIDEFLAGS;
    00528             he->t = RPM_UINT32_TYPE;
    00529             he->p.ui32p = (uint32_t *) &fdummy;
    00530             he->c = 1;
    00531             he->append = 1;
    00532             xx = headerPut(h, he, 0);
    00533             he->append = 0;
    00534         }
    00535         goto exit;
    00536     }
    00537
    00538     he->tag = RPMTAG_PROVIDEFLAGS;
    00539     xx = headerGet(h, he, 0);
    00540     provideFlags = he->p.ui32p;
    00541
    00542     /*@-nullderef@*/    /* LCL: providesEVR is not NULL */
    00543     if (provides && providesEVR && provideFlags)
    00544     for (i = 0; i < providesCount; i++) {
    00545         if (!(provides[i] && providesEVR[i]))
    00546             continue;
    00547         if (!(provideFlags[i] == RPMSENSE_EQUAL &&
    00548             !strcmp(N, provides[i]) && !strcmp(pEVR, providesEVR[i])))
    00549             continue;
    00550         bingo = 0;
    00551         break;
    00552     }
    00553     /*@=nullderef@*/
    00554
    00555 exit:
    00556     provides = _free(provides);
    00557     providesEVR = _free(providesEVR);
    00558     provideFlags = _free(provideFlags);
    00559
    00560     if (bingo) {
    00561         he->tag = RPMTAG_PROVIDENAME;
    00562         he->t = RPM_STRING_ARRAY_TYPE;
    00563         he->p.argv = &N;
    00564         he->c = 1;
    00565         he->append = 1;
    00566         xx = headerPut(h, he, 0);
    00567         he->append = 0;
    00568
    00569         he->tag = RPMTAG_PROVIDEVERSION;
    00570         he->t = RPM_STRING_ARRAY_TYPE;
    00571         he->p.argv = &pEVR;
    00572         he->c = 1;
    00573         he->append = 1;
    00574         xx = headerPut(h, he, 0);
    00575         he->append = 0;
    00576
    00577         he->tag = RPMTAG_PROVIDEFLAGS;
    00578         he->t = RPM_UINT32_TYPE;
    00579         he->p.ui32p = &pFlags;
    00580         he->c = 1;
    00581         he->append = 1;
    00582         xx = headerPut(h, he, 0);
    00583         he->append = 0;
    00584     }
    00585     N = _free(N);
    00586 }
    00587
    00588 rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileName,
    00589                 CSA_t csa, char *passPhrase, const char **cookie)
    00590 {
    00591     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    00592     FD_t fd = NULL;
    00593     FD_t ifd = NULL;
    00594     uint32_t count;
    00595     uint32_t sigtag;
    00596     const char * sigtarget;
    00597     const char * rpmio_flags = NULL;
    00598     const char * payload_format = NULL;
    00599     const char * SHA1 = NULL;
    00600     const char * msg = NULL;
    00601     char *s;
    00602     char buf[BUFSIZ];
    00603     Header h;
    00604     Header sigh = NULL;
    00605     int addsig = 0;
    00606     int isSource;
    00607     rpmRC rc = RPMRC_OK;
    00608     int xx;
    00609
    00610     /* Transfer header reference form *hdrp to h. */
    00611     h = headerLink(*hdrp);
    00612     *hdrp = headerFree(*hdrp);
    00613
    00614     if (pkgidp)
    00615         *pkgidp = NULL;
    00616
    00617     /* Save payload information */
    00618     isSource =
    00619         (headerIsEntry(h, RPMTAG_SOURCERPM) == 0 &&
    00620          headerIsEntry(h, RPMTAG_ARCH) != 0);
    00621     if (isSource) {
    00622         payload_format = rpmExpand("%{?_source_payload_format}", NULL);
    00623         rpmio_flags = rpmExpand("%{?_source_payload}", NULL);
    00624     } else {
    00625         payload_format = rpmExpand("%{?_binary_payload_format}", NULL);
    00626         rpmio_flags = rpmExpand("%{?_binary_payload}", NULL);
    00627     }
    00628
    00629     if (!(payload_format && *payload_format)) {
    00630         payload_format = _free(payload_format);
    00631         payload_format = xstrdup("cpio");
    00632     }
    00633     if (!(rpmio_flags && *rpmio_flags)) {
    00634         rpmio_flags = _free(rpmio_flags);
    00635         rpmio_flags = xstrdup("w9.gzdio");
    00636     }
    00637     s = strchr(rpmio_flags, '.');
    00638     if (s) {
    00639
    00640         if (payload_format) {
    00641             if (!strcmp(payload_format, "tar")
    00642              || !strcmp(payload_format, "ustar")) {
    00643                 /* XXX addition to header is too late to be displayed/sorted. */
    00644                 /* Add prereq on rpm version that understands tar payloads */
    00645                 (void) rpmlibNeedsFeature(h, "PayloadIsUstar", "4.4.4-1");
    00646             }
    00647
    00648             he->tag = RPMTAG_PAYLOADFORMAT;
    00649             he->t = RPM_STRING_TYPE;
    00650             he->p.str = payload_format;
    00651             he->c = 1;
    00652             xx = headerPut(h, he, 0);
    00653         }
    00654
    00655         /* XXX addition to header is too late to be displayed/sorted. */
    00656         if (s[1] == 'g' && s[2] == 'z') {
    00657             he->tag = RPMTAG_PAYLOADCOMPRESSOR;
    00658             he->t = RPM_STRING_TYPE;
    00659             he->p.str = "gzip";
    00660             he->c = 1;
    00661             xx = headerPut(h, he, 0);
    00662         } else if (s[1] == 'b' && s[2] == 'z') {
    00663             he->tag = RPMTAG_PAYLOADCOMPRESSOR;
    00664             he->t = RPM_STRING_TYPE;
    00665             he->p.str = "bzip2";
    00666             he->c = 1;
    00667             xx = headerPut(h, he, 0);
    00668         } else if (s[1] == 'l' && s[2] == 'z') {
    00669             he->tag = RPMTAG_PAYLOADCOMPRESSOR;
    00670             he->t = RPM_STRING_TYPE;
    00671             he->p.str = "lzma";
    00672             he->c = 1;
    00673             xx = headerPut(h, he, 0);
    00674             (void) rpmlibNeedsFeature(h, "PayloadIsLzma", "4.4.6-1");
    00675         }
    00676         strcpy(buf, rpmio_flags);
    00677         buf[s - rpmio_flags] = '\0';
    00678
    00679         he->tag = RPMTAG_PAYLOADFLAGS;
    00680         he->t = RPM_STRING_TYPE;
    00681         he->p.str = buf+1;
    00682         he->c = 1;
    00683         xx = headerPut(h, he, 0);
    00684     }
    00685
    00686     /* Create and add the cookie */
    00687     if (cookie) {
    00688         sprintf(buf, "%s %u", buildHost(), (unsigned) (*getBuildTime()));
    00689         *cookie = xstrdup(buf);         /* XXX memory leak */
    00690         he->tag = RPMTAG_COOKIE;
    00691         he->t = RPM_STRING_TYPE;
    00692         he->p.str = *cookie;
    00693         he->c = 1;
    00694         xx = headerPut(h, he, 0);
    00695     }
    00696
    00697     /* Reallocate the header into one contiguous region. */
    00698     h = headerReload(h, RPMTAG_HEADERIMMUTABLE);
    00699     if (h == NULL) {    /* XXX can't happen */
    00700         rpmlog(RPMLOG_ERR, _("Unable to create immutable header region.\n"));
    00701         rc = RPMRC_FAIL;
    00702         goto exit;
    00703     }
    00704     /* Re-reference reallocated header. */
    00705     *hdrp = headerLink(h);
    00706
    00707     /*
    00708      * Write the header+archive into a temp file so that the size of
    00709      * archive (after compression) can be added to the header.
    00710      */
    00711     sigtarget = NULL;
    00712     if (rpmTempFile(NULL, &sigtarget, &fd)) {
    00713         rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n"));
    00714         rc = RPMRC_FAIL;
    00715         goto exit;
    00716     }
    00717
    00718     /* Write the header to a temp file, computing header SHA1 on the fly. */
    00719     fdInitDigest(fd, PGPHASHALGO_SHA1, 0);
    00720     {   const char item[] = "Header";
    00721         msg = NULL;
    00722         rc = rpmpkgWrite(item, fd, h, &msg);
    00723         if (rc != RPMRC_OK) {
    00724             rpmlog(RPMLOG_ERR, "%s: %s: %s\n", sigtarget, item,
    00725                 (msg && *msg ? msg : "write failed\n"));
    00726             msg = _free(msg);
    00727             rc = RPMRC_FAIL;
    00728             goto exit;
    00729         }
    00730         msg = _free(msg);
    00731         (void) Fflush(fd);
    00732     }
    00733     fdFiniDigest(fd, PGPHASHALGO_SHA1, &SHA1, NULL, 1);
    00734
    00735     /* Append the payload to the temp file. */
    00736     if (csa->cpioList != NULL)
    00737         rc = cpio_doio(fd, h, csa, payload_format, rpmio_flags);
    00738     else if (Fileno(csa->cpioFdIn) >= 0)
    00739         rc = cpio_copy(fd, csa);
    00740     else
    00741 assert(0);
    00742
    00743     rpmio_flags = _free(rpmio_flags);
    00744     payload_format = _free(payload_format);
    00745     if (rc != RPMRC_OK)
    00746         goto exit;
    00747
    00748     (void) Fclose(fd);
    00749     fd = NULL;
    00750     (void) Unlink(fileName);
    00751
    00752     /* Generate the signature */
    00753     (void) fflush(stdout);
    00754     sigh = headerNew();
    00755     (void) rpmAddSignature(sigh, sigtarget, RPMSIGTAG_SIZE, passPhrase);
    00756     (void) rpmAddSignature(sigh, sigtarget, RPMSIGTAG_MD5, passPhrase);
    00757
    00758     sigtag = RPMSIGTAG_GPG;
    00759     addsig = (passPhrase && passPhrase[0]);
    00760
    00761     if (addsig) {
    00762         rpmlog(RPMLOG_NOTICE, _("Generating signature: %d\n"), sigtag);
    00763         (void) rpmAddSignature(sigh, sigtarget, sigtag, passPhrase);
    00764     }
    00765
    00766     if (SHA1) {
    00767         he->tag = (rpmTag) RPMSIGTAG_SHA1;
    00768         he->t = RPM_STRING_TYPE;
    00769         he->p.str = SHA1;
    00770         he->c = 1;
    00771         xx = headerPut(sigh, he, 0);
    00772         SHA1 = _free(SHA1);
    00773     }
    00774
    00775     {   uint32_t payloadSize = csa->cpioArchiveSize;
    00776         he->tag = (rpmTag) RPMSIGTAG_PAYLOADSIZE;
    00777         he->t = RPM_UINT32_TYPE;
    00778         he->p.ui32p = &payloadSize;
    00779         he->c = 1;
    00780         xx = headerPut(sigh, he, 0);
    00781     }
    00782
    00783     /* Reallocate the signature into one contiguous region. */
    00784     sigh = headerReload(sigh, RPMTAG_HEADERSIGNATURES);
    00785     if (sigh == NULL) { /* XXX can't happen */
    00786         rpmlog(RPMLOG_ERR, _("Unable to reload signature header.\n"));
    00787         rc = RPMRC_FAIL;
    00788         goto exit;
    00789     }
    00790
    00791     /* Open the output file */
    00792     fd = Fopen(fileName, "w.fdio");
    00793     if (fd == NULL || Ferror(fd)) {
    00794         rpmlog(RPMLOG_ERR, _("Could not open %s: %s\n"),
    00795                 fileName, Fstrerror(fd));
    00796         rc = RPMRC_FAIL;
    00797         goto exit;
    00798     }
    00799
    00800     /* Write the lead section into the package. */
    00801     {   const char item[] = "Lead";
    00802         size_t nl = rpmpkgSizeof(item, NULL);
    00803
    00804         msg = NULL;
    00805         if (nl == 0)
    00806             rc = RPMRC_FAIL;
    00807         else {
    00808             void * l = memset(alloca(nl), 0, nl);
    00809             const char *N, *V, *R;
    00810             (void) headerNEVRA(h, &N, NULL, &V, &R, NULL);
    00811             sprintf(buf, "%s-%s-%s", N, V, R);
    00812             N = _free(N);
    00813             V = _free(V);
    00814             R = _free(R);
    00815             msg = buf;
    00816             rc = rpmpkgWrite(item, fd, l, &msg);
    00817         }
    00818
    00819         if (rc != RPMRC_OK) {
    00820             rpmlog(RPMLOG_ERR, _("Unable to write package: %s\n"),
    00821                  Fstrerror(fd));
    00822             rc = RPMRC_FAIL;
    00823             goto exit;
    00824         }
    00825     }
    00826
    00827     /* Write the signature section into the package. */
    00828     {   const char item[] = "Signature";
    00829
    00830         msg = NULL;
    00831         rc = rpmpkgWrite(item, fd, sigh, &msg);
    00832         if (rc != RPMRC_OK) {
    00833             rpmlog(RPMLOG_ERR, "%s: %s: %s\n", fileName, item,
    00834                 (msg && *msg ? msg : "write failed\n"));
    00835             msg = _free(msg);
    00836             rc = RPMRC_FAIL;
    00837             goto exit;
    00838         }
    00839         msg = _free(msg);
    00840     }
    00841
    00842     /* Append the header and archive */
    00843     ifd = Fopen(sigtarget, "r.fdio");
    00844     if (ifd == NULL || Ferror(ifd)) {
    00845         rpmlog(RPMLOG_ERR, _("Unable to open sigtarget %s: %s\n"),
    00846                 sigtarget, Fstrerror(ifd));
    00847         rc = RPMRC_FAIL;
    00848         goto exit;
    00849     }
    00850
    00851     /* Add signatures to header, and write header into the package. */
    00852     {   const char item[] = "Header";
    00853         Header nh = NULL;
    00854
    00855         msg = NULL;
    00856         rc = rpmpkgRead(item, ifd, &nh, &msg);
    00857         if (rc != RPMRC_OK) {
    00858             rpmlog(RPMLOG_ERR, "%s: %s: %s\n", sigtarget, item,
    00859                 (msg && *msg ? msg : "read failed\n"));
    00860             msg = _free(msg);
    00861             rc = RPMRC_FAIL;
    00862             goto exit;
    00863         }
    00864         msg = _free(msg);
    00865
    00866 #ifdef  NOTYET
    00867         (void) headerMergeLegacySigs(nh, sigh);
    00868 #endif
    00869
    00870         msg = NULL;
    00871         rc = rpmpkgWrite(item, fd, nh, &msg);
    00872         nh = headerFree(nh);
    00873         if (rc != RPMRC_OK) {
    00874             rpmlog(RPMLOG_ERR, "%s: %s: %s\n", fileName, item,
    00875                 (msg && *msg ? msg : "write failed\n"));
    00876             msg = _free(msg);
    00877             rc = RPMRC_FAIL;
    00878             goto exit;
    00879         }
    00880         msg = _free(msg);
    00881     }
    00882
    00883     /* Write the payload into the package. */
    00884     while ((xx = Fread(buf, sizeof(buf[0]), sizeof(buf), ifd)) > 0) {
    00885         if (xx <= -1 || Ferror(ifd)) {
    00886             rpmlog(RPMLOG_ERR, _("Unable to read payload from %s: %s\n"),
    00887                      sigtarget, Fstrerror(ifd));
    00888             rc = RPMRC_FAIL;
    00889             goto exit;
    00890         }
    00891         count = (uint32_t) xx;
    00892         xx = Fwrite(buf, sizeof(buf[0]), count, fd);
    00893         if ((uint32_t)xx != count || Ferror(fd)) {
    00894             rpmlog(RPMLOG_ERR, _("Unable to write payload to %s: %s\n"),
    00895                      fileName, Fstrerror(fd));
    00896             rc = RPMRC_FAIL;
    00897             goto exit;
    00898         }
    00899     }
    00900     rc = RPMRC_OK;
    00901
    00902 exit:
    00903     SHA1 = _free(SHA1);
    00904     h = headerFree(h);
    00905
    00906     /* XXX Fish the pkgid out of the signature header. */
    00907     if (sigh != NULL && pkgidp != NULL) {
    00908         he->tag = (rpmTag) RPMSIGTAG_MD5;
    00909         xx = headerGet(sigh, he, 0);
    00910         if (he->t == RPM_BIN_TYPE && he->p.ptr != NULL && he->c == 16)
    00911             *pkgidp = he->p.ui8p;               /* XXX memory leak */
    00912     }
    00913
    00914     sigh = headerFree(sigh);
    00915     if (ifd) {
    00916         (void) Fclose(ifd);
    00917         ifd = NULL;
    00918     }
    00919     if (fd) {
    00920         (void) Fclose(fd);
    00921         fd = NULL;
    00922     }
    00923     if (sigtarget) {
    00924         (void) Unlink(sigtarget);
    00925         sigtarget = _free(sigtarget);
    00926     }
    00927
    00928     if (rc == RPMRC_OK)
    00929         rpmlog(RPMLOG_NOTICE, _("Wrote: %s\n"), fileName);
    00930     else
    00931         (void) Unlink(fileName);
    00932
    00933     return rc;
    00934 }
    00935
    00936 static int rpmlibMarkers(Header h)
    00937         /*@modifies h @*/
    00938 {
    00939     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    00940     uint32_t val;
    00941     int xx;
    00942
    00943     he->tag = RPMTAG_RPMVERSION;
    00944     he->t = RPM_STRING_TYPE;
    00945     he->p.str = VERSION;
    00946     he->c = 1;
    00947     xx = headerPut(h, he, 0);
    00948
    00949 if (!(_rpmbuildFlags & 4)) {
    00950     val = rpmlibTimestamp();
    00951     he->tag = RPMTAG_RPMLIBTIMESTAMP;
    00952     he->t = RPM_UINT32_TYPE;
    00953     he->p.ui32p = &val;
    00954     he->c = 1;
    00955     xx = headerPut(h, he, 0);
    00956
    00957     val = rpmlibVendor();
    00958     he->tag = RPMTAG_RPMLIBVENDOR;
    00959     he->t = RPM_UINT32_TYPE;
    00960     he->p.ui32p = &val;
    00961     he->c = 1;
    00962     xx = headerPut(h, he, 0);
    00963
    00964     val = rpmlibVersion();
    00965     he->tag = RPMTAG_RPMLIBVERSION;
    00966     he->t = RPM_UINT32_TYPE;
    00967     he->p.ui32p = &val;
    00968     he->c = 1;
    00969     xx = headerPut(h, he, 0);
    00970 }
    00971
    00972     he->tag = RPMTAG_BUILDHOST;
    00973     he->t = RPM_STRING_TYPE;
    00974     he->p.str = buildHost();
    00975     he->c = 1;
    00976     xx = headerPut(h, he, 0);
    00977
    00978     he->tag = RPMTAG_BUILDTIME;
    00979     he->t = RPM_UINT32_TYPE;
    00980     he->p.ui32p = getBuildTime();
    00981     he->c = 1;
    00982     xx = headerPut(h, he, 0);
    00983
    00984     return 0;
    00985 }
    00986
    00987 /*@unchecked@*/
    00988 static uint32_t copyTags[] = {
    00989     RPMTAG_CHANGELOGTIME,
    00990     RPMTAG_CHANGELOGNAME,
    00991     RPMTAG_CHANGELOGTEXT,
    00992     0
    00993 };
    00994
    00995 rpmRC packageBinaries(Spec spec)
    00996 {
    00997     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    00998     struct cpioSourceArchive_s csabuf;
    00999     CSA_t csa = &csabuf;
    01000     const char *errorString;
    01001     Package pkg;
    01002     rpmRC rc;
    01003     int xx;
    01004
    01005     for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
    01006         const char *fn;
    01007
    01008         if (pkg->fileList == NULL)
    01009             continue;
    01010
    01011         if (spec->cookie) {
    01012             he->tag = RPMTAG_COOKIE;
    01013             he->t = RPM_STRING_TYPE;
    01014             he->p.str = spec->cookie;
    01015             he->c = 1;
    01016             xx = headerPut(pkg->header, he, 0);
    01017         }
    01018
    01019         /* Copy changelog from src rpm */
    01020         headerCopyTags(spec->packages->header, pkg->header, copyTags);
    01021
    01022         /* Add rpmlib markers for tracking. */
    01023         (void) rpmlibMarkers(pkg->header);
    01024
    01025         he->tag = RPMTAG_OPTFLAGS;
    01026         he->t = RPM_STRING_TYPE;
    01027         he->p.str = rpmExpand("%{optflags}", NULL);
    01028         he->c = 1;
    01029         xx = headerPut(pkg->header, he, 0);
    01030         he->p.ptr = _free(he->p.ptr);
    01031
    01032         (void) genSourceRpmName(spec);
    01033         he->tag = RPMTAG_SOURCERPM;
    01034         he->t = RPM_STRING_TYPE;
    01035         he->p.str = spec->sourceRpmName;
    01036         he->c = 1;
    01037         xx = headerPut(pkg->header, he, 0);
    01038
    01039 if (!(_rpmbuildFlags & 4)) {
    01040         if (spec->sourcePkgId != NULL) {
    01041             he->tag = RPMTAG_SOURCEPKGID;
    01042             he->t = RPM_BIN_TYPE;
    01043             he->p.ptr = spec->sourcePkgId;
    01044             he->c = 16;
    01045             xx = headerPut(pkg->header, he, 0);
    01046         }
    01047 }
    01048
    01049         {   const char *binFormat = rpmGetPath("%{_rpmfilename}", NULL);
    01050             char *binRpm, *binDir;
    01051             binRpm = headerSprintf(pkg->header, binFormat, NULL,
    01052                                rpmHeaderFormats, &errorString);
    01053             binFormat = _free(binFormat);
    01054             if (binRpm == NULL) {
    01055                 he->tag = RPMTAG_NVRA;
    01056                 xx = headerGet(pkg->header, he, 0);
    01057                 rpmlog(RPMLOG_ERR, _("Could not generate output "
    01058                      "filename for package %s: %s\n"), he->p.str, errorString);
    01059                 he->p.ptr = _free(he->p.ptr);
    01060                 return RPMRC_FAIL;
    01061             }
    01062             fn = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
    01063             if ((binDir = strchr(binRpm, '/')) != NULL) {
    01064                 struct stat st;
    01065                 const char *dn;
    01066                 *binDir = '\0';
    01067                 dn = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
    01068                 if (Stat(dn, &st) < 0) {
    01069                     switch(errno) {
    01070                     case  ENOENT:
    01071                         if (Mkdir(dn, 0755) == 0)
    01072                             /*@switchbreak@*/ break;
    01073                         /*@fallthrough@*/
    01074                     default:
    01075                         rpmlog(RPMLOG_ERR,_("cannot create %s: %s\n"),
    01076                             dn, strerror(errno));
    01077                         /*@switchbreak@*/ break;
    01078                     }
    01079                 }
    01080                 dn = _free(dn);
    01081             }
    01082             binRpm = _free(binRpm);
    01083         }
    01084
    01085         memset(csa, 0, sizeof(*csa));
    01086         csa->cpioArchiveSize = 0;
    01087         /*@-type@*/ /* LCL: function typedefs */
    01088         csa->cpioFdIn = fdNew("init (packageBinaries)");
    01089 /*@-assignexpose -newreftrans@*/
    01090         csa->cpioList = rpmfiLink(pkg->cpioList, "packageBinaries");
    01091 /*@=assignexpose =newreftrans@*/
    01092 assert(csa->cpioList != NULL);
    01093
    01094         rc = writeRPM(&pkg->header, NULL, fn,
    01095                     csa, spec->passPhrase, NULL);
    01096
    01097 /*@-onlytrans@*/
    01098         csa->cpioList->te = _free(csa->cpioList->te);   /* XXX memory leak */
    01099 /*@=onlytrans@*/
    01100         csa->cpioList = rpmfiFree(csa->cpioList);
    01101         csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageBinaries)");
    01102         /*@=type@*/
    01103         fn = _free(fn);
    01104         if (rc)
    01105             return rc;
    01106     }
    01107
    01108     return RPMRC_OK;
    01109 }
    01110
    01111 rpmRC packageSources(Spec spec)
    01112 {
    01113     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    01114     struct cpioSourceArchive_s csabuf;
    01115     CSA_t csa = &csabuf;
    01116     rpmRC rc;
    01117     int xx;
    01118 #if defined(RPM_VENDOR_OPENPKG) /* backward-compat-rpmtag-sourcepackage */
    01119     uint32_t val;
    01120 #endif
    01121
    01122     /* Add rpmlib markers for tracking. */
    01123     (void) rpmlibMarkers(spec->sourceHeader);
    01124
    01125 #if defined(RPM_VENDOR_OPENPKG) /* backward-compat-rpmtag-sourcepackage */
    01126     /* Mark package as a SRPM for backward compatibility with RPM < 4.4.6 */
    01127     he->tag = RPMTAG_SOURCEPACKAGE;
    01128     he->t = RPM_UINT32_TYPE;
    01129     val = 1;
    01130     he->p.ui32p = &val;
    01131     he->c = 1;
    01132     xx = headerPut(spec->sourceHeader, he, 0);
    01133 #endif
    01134
    01135     (void) genSourceRpmName(spec);
    01136
    01137     {   const char ** av = NULL;
    01138         (void)rpmGetMacroEntries(NULL, NULL, 1, &av);
    01139         if (av != NULL && av[0] != NULL) {
    01140             he->tag = RPMTAG_BUILDMACROS;
    01141             he->t = RPM_STRING_ARRAY_TYPE;
    01142             he->p.argv = av;
    01143             he->c = argvCount(av);
    01144             xx = headerPut(spec->sourceHeader, he, 0);
    01145         }
    01146         av = argvFree(av);
    01147     }
    01148
    01149     spec->cookie = _free(spec->cookie);
    01150
    01151     /* XXX this should be %_srpmdir */
    01152     {   const char *fn = rpmGetPath("%{_srcrpmdir}/", spec->sourceRpmName,NULL);
    01153
    01154         memset(csa, 0, sizeof(*csa));
    01155         csa->cpioArchiveSize = 0;
    01156         /*@-type@*/ /* LCL: function typedefs */
    01157         csa->cpioFdIn = fdNew("init (packageSources)");
    01158 /*@-assignexpose -newreftrans@*/
    01159         csa->cpioList = rpmfiLink(spec->sourceCpioList, "packageSources");
    01160 /*@=assignexpose =newreftrans@*/
    01161 assert(csa->cpioList != NULL);
    01162
    01163         spec->sourcePkgId = NULL;
    01164         rc = writeRPM(&spec->sourceHeader, &spec->sourcePkgId, fn,
    01165                 csa, spec->passPhrase, &(spec->cookie));
    01166
    01167 /*@-onlytrans@*/
    01168         csa->cpioList->te = _free(csa->cpioList->te);   /* XXX memory leak */
    01169 /*@=onlytrans@*/
    01170         csa->cpioList = rpmfiFree(csa->cpioList);
    01171         csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageSources)");
    01172         /*@=type@*/
    01173         fn = _free(fn);
    01174     }
    01175
    01176     return (rc ? RPMRC_FAIL : RPMRC_OK);
    01177 }