fix: prevent segfault if malicious server sends 1 GB of data through ftpNLST.
[platform/upstream/rpm.git] / lib / transaction.c
index 726c468..d019de4 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <rpmmacro.h>  /* XXX for rpmExpand */
 
+#include "fsm.h"
 #include "psm.h"
 
 #include "rpmdb.h"
 #define        _RPMTS_INTERNAL
 #include "rpmts.h"
 
+#include "cpio.h"
 #include "fprint.h"
 #include "legacy.h"    /* XXX domd5 */
 #include "misc.h" /* XXX stripTrailingChar, splitString, currentDirectory */
 
 #include "debug.h"
 
-/*@access FD_t @*/             /* XXX compared with NULL */
-/*@access Header @*/           /* XXX compared with NULL */
+/*@access Header @*/           /* XXX ts->notify arg1 is void ptr */
 /*@access rpmps @*/    /* XXX need rpmProblemSetOK() */
 /*@access dbiIndexSet @*/
-/*@access rpmdb @*/
 
-/*@access PSM_t @*/
+/*@access rpmpsm @*/
 
 /*@access alKey @*/
 /*@access fnpyKey @*/
@@ -110,9 +110,9 @@ static fileAction decideFileFate(const rpmts ts,
        }
     }
 
-    diskWhat = whatis(sb.st_mode);
-    dbWhat = whatis(ofi->fmodes[ofi->i]);
-    newWhat = whatis(nfi->fmodes[nfi->i]);
+    diskWhat = whatis((int_16)sb.st_mode);
+    dbWhat = whatis(rpmfiFMode(ofi));
+    newWhat = whatis(rpmfiFMode(nfi));
 
     /*
      * RPM >= 2.3.10 shouldn't create config directories -- we'll ignore
@@ -135,38 +135,31 @@ static fileAction decideFileFate(const rpmts ts,
      * possible in case something else (like the timestamp) has changed.
      */
     if (dbWhat == REG) {
-#ifdef DYING
-       if (ofi->md5s != NULL && nfi->md5s != NULL) {
-#endif
-           const unsigned char * omd5 = ofi->md5s + (16 * ofi->i);
-           const unsigned char * nmd5 = nfi->md5s + (16 * nfi->i);
-           if (domd5(fn, buffer, 0, NULL))
-               return FA_CREATE;       /* assume file has been removed */
-           if (!memcmp(omd5, buffer, 16))
-               return FA_CREATE;       /* unmodified config file, replace. */
-           if (!memcmp(omd5, nmd5, 16))
-               return FA_SKIP;         /* identical file, don't bother. */
-#ifdef DYING
-       } else {
-           const char * omd5 = ofi->fmd5s[ofi->i];
-           const char * nmd5 = nfi->fmd5s[nfi->i];
-           if (domd5(fn, buffer, 1, NULL))
-               return FA_CREATE;       /* assume file has been removed */
-           if (!strcmp(omd5, buffer))
-               return FA_CREATE;       /* unmodified config file, replace. */
-           if (!strcmp(omd5, nmd5))
-               return FA_SKIP;         /* identical file, don't bother. */
-       }
-#endif
+       const unsigned char * omd5, * nmd5;
+       if (domd5(fn, buffer, 0, NULL))
+           return FA_CREATE;   /* assume file has been removed */
+       omd5 = rpmfiMD5(ofi);
+       if (omd5 && !memcmp(omd5, buffer, 16))
+           return FA_CREATE;   /* unmodified config file, replace. */
+       nmd5 = rpmfiMD5(nfi);
+/*@-nullpass@*/
+       if (omd5 && nmd5 && !memcmp(omd5, nmd5, 16))
+           return FA_SKIP;     /* identical file, don't bother. */
+/*@=nullpass@*/
     } else /* dbWhat == LINK */ {
+       const char * oFLink, * nFLink;
        memset(buffer, 0, sizeof(buffer));
        if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
            return FA_CREATE;   /* assume file has been removed */
-       if (!strcmp(ofi->flinks[ofi->i], buffer))
+       oFLink = rpmfiFLink(ofi);
+       if (oFLink && !strcmp(oFLink, buffer))
            return FA_CREATE;   /* unmodified config file, replace. */
-       if (!strcmp(ofi->flinks[ofi->i], nfi->flinks[nfi->i]))
+       nFLink = rpmfiFLink(nfi);
+/*@-nullpass@*/
+       if (oFLink && nFLink && !strcmp(oFLink, nFLink))
            return FA_SKIP;     /* identical file, don't bother. */
-     }
+/*@=nullpass@*/
+    }
 
     /*
      * The config file on the disk has been modified, but
@@ -184,29 +177,25 @@ static fileAction decideFileFate(const rpmts ts,
 static int filecmp(rpmfi afi, rpmfi bfi)
        /*@*/
 {
-    fileTypes awhat = whatis(afi->fmodes[afi->i]);
-    fileTypes bwhat = whatis(bfi->fmodes[bfi->i]);
+    fileTypes awhat = whatis(rpmfiFMode(afi));
+    fileTypes bwhat = whatis(rpmfiFMode(bfi));
 
     if (awhat != bwhat) return 1;
 
     if (awhat == LINK) {
-       const char * alink = afi->flinks[afi->i];
-       const char * blink = bfi->flinks[bfi->i];
+       const char * alink = rpmfiFLink(afi);
+       const char * blink = rpmfiFLink(bfi);
+       if (alink == blink) return 0;
+       if (alink == NULL) return 1;
+       if (blink == NULL) return -1;
        return strcmp(alink, blink);
     } else if (awhat == REG) {
-#ifdef DYING
-       if (afi->md5s != NULL && bfi->md5s != NULL) {
-#endif
-           const unsigned char * amd5 = afi->md5s + (16 * afi->i);
-           const unsigned char * bmd5 = bfi->md5s + (16 * bfi->i);
-           return memcmp(amd5, bmd5, 16);
-#ifdef DYING
-       } else {
-           const char * amd5 = afi->fmd5s[afi->i];
-           const char * bmd5 = bfi->fmd5s[bfi->i];
-           return strcmp(amd5, bmd5);
-       }
-#endif
+       const unsigned char * amd5 = rpmfiMD5(afi);
+       const unsigned char * bmd5 = rpmfiMD5(bfi);
+       if (amd5 == bmd5) return 0;
+       if (amd5 == NULL) return 1;
+       if (bmd5 == NULL) return -1;
+       return memcmp(amd5, bmd5, 16);
     }
 
     return 0;
@@ -221,9 +210,12 @@ static int handleInstInstalledFiles(const rpmts ts,
                rpmte p, rpmfi fi,
                sharedFileInfo shared,
                int sharedCount, int reportConflicts)
-       /*@globals fileSystem, internalState @*/
-       /*@modifies ts, fi, fileSystem, internalState @*/
+       /*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
+       /*@modifies ts, fi, rpmGlobalMacroContext, fileSystem, internalState @*/
 {
+    uint_32 tscolor = rpmtsColor(ts);
+    uint_32 otecolor, tecolor;
+    uint_32 oficolor, ficolor;
     const char * altNEVR = NULL;
     rpmfi otherFi = NULL;
     int numReplaced = 0;
@@ -238,12 +230,24 @@ static int handleInstInstalledFiles(const rpmts ts,
                        &shared->otherPkg, sizeof(shared->otherPkg));
        while ((h = rpmdbNextIterator(mi)) != NULL) {
            altNEVR = hGetNEVR(h, NULL);
-           otherFi = rpmfiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem);
+           otherFi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
            break;
        }
        mi = rpmdbFreeIterator(mi);
     }
 
+    /* Compute package color. */
+    tecolor = rpmteColor(p);
+    tecolor &= tscolor;
+
+    /* Compute other pkg color. */
+    otecolor = 0;
+    otherFi = rpmfiInit(otherFi, 0);
+    if (otherFi != NULL)
+    while (rpmfiNext(otherFi) >= 0)
+       otecolor |= rpmfiFColor(otherFi);
+    otecolor &= tscolor;
+
     if (otherFi == NULL)
        return 1;
 
@@ -252,12 +256,19 @@ static int handleInstInstalledFiles(const rpmts ts,
     ps = rpmtsProblems(ts);
     for (i = 0; i < sharedCount; i++, shared++) {
        int otherFileNum, fileNum;
+       int isCfgFile;
 
        otherFileNum = shared->otherFileNum;
        (void) rpmfiSetFX(otherFi, otherFileNum);
+       oficolor = rpmfiFColor(otherFi);
+       oficolor &= tscolor;
 
        fileNum = shared->pkgFileNum;
        (void) rpmfiSetFX(fi, fileNum);
+       ficolor = rpmfiFColor(fi);
+       ficolor &= tscolor;
+
+       isCfgFile = ((rpmfiFFlags(otherFi) | rpmfiFFlags(fi)) & RPMFILE_CONFIG);
 
 #ifdef DYING
        /* XXX another tedious segfault, assume file state normal. */
@@ -269,6 +280,8 @@ static int handleInstInstalledFiles(const rpmts ts,
            continue;
 
        if (filecmp(otherFi, fi)) {
+           /* Report conflicts only for packages/files of same color. */
+           if (tscolor == 0 || (tecolor == otecolor && ficolor == oficolor))
            if (reportConflicts) {
                rpmpsAppend(ps, RPMPROB_FILE_CONFLICT,
                        rpmteNEVR(p), rpmteKey(p),
@@ -276,7 +289,7 @@ static int handleInstInstalledFiles(const rpmts ts,
                        altNEVR,
                        0);
            }
-           if (!(rpmfiFFlags(otherFi) | rpmfiFFlags(fi)) & RPMFILE_CONFIG) {
+           if (!isCfgFile) {
                /*@-assignexpose@*/ /* FIX: p->replaced, not fi */
                if (!shared->isRemoved)
                    fi->replaced[numReplaced++] = *shared;
@@ -284,18 +297,17 @@ static int handleInstInstalledFiles(const rpmts ts,
            }
        }
 
-       if ((rpmfiFFlags(otherFi) | rpmfiFFlags(fi)) & RPMFILE_CONFIG) {
+       if (isCfgFile) {
            fileAction action;
            action = decideFileFate(ts, otherFi, fi);
            fi->actions[fileNum] = action;
        }
-       fi->replacedSizes[fileNum] = otherFi->fsizes[otherFi->i];
-
+       fi->replacedSizes[fileNum] = rpmfiFSize(otherFi);
     }
     ps = rpmpsFree(ps);
 
     altNEVR = _free(altNEVR);
-    otherFi = rpmfiFree(otherFi, 1);
+    otherFi = rpmfiFree(otherFi);
 
     fi->replaced = xrealloc(fi->replaced,      /* XXX memory leak */
                           sizeof(*fi->replaced) * (numReplaced + 1));
@@ -310,8 +322,8 @@ static int handleInstInstalledFiles(const rpmts ts,
 /* XXX only ts->rpmdb modified */
 static int handleRmvdInstalledFiles(const rpmts ts, rpmfi fi,
                sharedFileInfo shared, int sharedCount)
-       /*@globals fileSystem, internalState @*/
-       /*@modifies ts, fi, fileSystem, internalState @*/
+       /*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
+       /*@modifies ts, fi, rpmGlobalMacroContext, fileSystem, internalState @*/
 {
     HGE_t hge = fi->hge;
     Header h;
@@ -351,7 +363,7 @@ static int handleRmvdInstalledFiles(const rpmts ts, rpmfi fi,
 #define        ISROOT(_d)      (((_d)[0] == '/' && (_d)[1] == '\0') ? "" : (_d))
 
 /*@unchecked@*/
-static int _fps_debug = 0;
+int _fps_debug = 0;
 
 static int fpsCompare (const void * one, const void * two)
        /*@*/
@@ -450,7 +462,7 @@ otherFps->baseName);
 if (otherFileNum == otherFc) {
 /*@-modfilesys@*/
 if (_fps_debug)
-fprintf(stderr, "*** NULL %s/%s%s\n",
+fprintf(stderr, "*** FP_EQUAL NULL %s/%s%s\n",
 ISROOT(fiFps->entry->dirName),
 (fiFps->subDir ? fiFps->subDir : ""),
 fiFps->baseName);
@@ -468,7 +480,8 @@ fiFps->baseName);
 /*@=boundswrite@*/
     if (bingoFps == NULL) {
 /*@-modfilesys@*/
-fprintf(stderr, "*** NULL %s/%s%s\n",
+if (_fps_debug)
+fprintf(stderr, "*** bingoFps NULL %s/%s%s\n",
 ISROOT(fiFps->entry->dirName),
 (fiFps->subDir ? fiFps->subDir : ""),
 fiFps->baseName);
@@ -480,6 +493,7 @@ fiFps->baseName);
     /*@-nullpass@*/    /* LCL: looks good to me */
     if (!(fiFps == bingoFps || FP_EQUAL((*fiFps), (*bingoFps)))) {
 /*@-modfilesys@*/
+if (_fps_debug)
 fprintf(stderr, "***  BAD %s/%s%s\n",
 ISROOT(bingoFps->entry->dirName),
 (bingoFps->subDir ? bingoFps->subDir : ""),
@@ -516,6 +530,8 @@ static void handleOverlappedFiles(const rpmts ts,
        struct fingerPrint_s * fiFps;
        int otherPkgNum, otherFileNum;
        rpmfi otherFi;
+       int_32 FFlags;
+       int_16 FMode;
        const rpmfi * recs;
        int numRecs;
 
@@ -524,6 +540,8 @@ static void handleOverlappedFiles(const rpmts ts,
 
        fn = rpmfiFN(fi);
        fiFps = fi->fps + i;
+       FFlags = rpmfiFFlags(fi);
+       FMode = rpmfiFMode(fi);
 
        fixupSize = 0;
 
@@ -593,10 +611,9 @@ static void handleOverlappedFiles(const rpmts ts,
                /* XXX is this test still necessary? */
                if (fi->actions[i] != FA_UNKNOWN)
                    /*@switchbreak@*/ break;
-               if ((rpmfiFFlags(fi) & RPMFILE_CONFIG) && 
-                       !lstat(fn, &sb)) {
+               if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
                    /* Here is a non-overlapped pre-existing config file. */
-                   fi->actions[i] = (rpmfiFFlags(fi) & RPMFILE_NOREPLACE)
+                   fi->actions[i] = (FFlags & RPMFILE_NOREPLACE)
                        ? FA_ALTNAME : FA_BACKUP;
                } else {
                    fi->actions[i] = FA_CREATE;
@@ -606,7 +623,7 @@ static void handleOverlappedFiles(const rpmts ts,
 
 assert(otherFi != NULL);
            /* Mark added overlapped non-identical files as a conflict. */
-           if ((rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES)
+           if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES)
             && filecmp(otherFi, fi))
            {
                rpmpsAppend(ps, RPMPROB_NEW_FILE_CONFLICT,
@@ -617,11 +634,11 @@ assert(otherFi != NULL);
            }
 
            /* Try to get the disk accounting correct even if a conflict. */
-           fixupSize = otherFi->fsizes[otherFileNum];
+           fixupSize = rpmfiFSize(otherFi);
 
-           if ((rpmfiFFlags(fi) & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
+           if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
                /* Here is an overlapped  pre-existing config file. */
-               fi->actions[i] = (rpmfiFFlags(fi) & RPMFILE_NOREPLACE)
+               fi->actions[i] = (FFlags & RPMFILE_NOREPLACE)
                        ? FA_ALTNAME : FA_SKIP;
            } else {
                fi->actions[i] = FA_CREATE;
@@ -642,17 +659,17 @@ assert(otherFi != NULL);
            }
            if (XFA_SKIPPING(fi->actions[i]))
                /*@switchbreak@*/ break;
-           if (fi->fstates && fi->fstates[i] != RPMFILE_STATE_NORMAL)
+           if (rpmfiFState(fi) != RPMFILE_STATE_NORMAL)
                /*@switchbreak@*/ break;
-           if (!(S_ISREG(fi->fmodes[i]) && (rpmfiFFlags(fi) & RPMFILE_CONFIG))) {
+           if (!(S_ISREG(FMode) && (FFlags & RPMFILE_CONFIG))) {
                fi->actions[i] = FA_ERASE;
                /*@switchbreak@*/ break;
            }
                
            /* Here is a pre-existing modified config file that needs saving. */
            {   char md5sum[50];
-               const unsigned char * md5 = fi->md5s + (16 * i);
-               if (!domd5(fn, md5sum, 0, NULL) && memcmp(md5, md5sum, 16)) {
+               const unsigned char * MD5 = rpmfiMD5(fi);
+               if (!domd5(fn, md5sum, 0, NULL) && memcmp(MD5, md5sum, 16)) {
                    fi->actions[i] = FA_BACKUP;
                    /*@switchbreak@*/ break;
                }
@@ -663,8 +680,8 @@ assert(otherFi != NULL);
 /*@=boundswrite@*/
 
        /* Update disk space info for a file. */
-       rpmtsUpdateDSI(ts, fi->fps[i].entry->dev,
-                fi->fsizes[i], fi->replacedSizes[i], fixupSize, fi->actions[i]);
+       rpmtsUpdateDSI(ts, fiFps->entry->dev, rpmfiFSize(fi),
+               fi->replacedSizes[i], fixupSize, fi->actions[i]);
 
     }
     ps = rpmpsFree(ps);
@@ -703,7 +720,7 @@ static int ensureOlder(rpmts ts,
 /*@=boundswrite@*/
     
     req = rpmdsSingle(RPMTAG_REQUIRENAME, rpmteN(p), reqEVR, reqFlags);
-    rc = headerMatchesDepFlags(h, req);
+    rc = rpmdsNVRMatchesDep(h, req, _rpmds_nopromote);
     req = rpmdsFree(req);
 
     if (rc == 0) {
@@ -724,6 +741,9 @@ static int ensureOlder(rpmts ts,
 }
 
 /**
+ * Skip any files that do not match install policies.
+ * @param ts           transaction set
+ * @param fi           file info set
  */
 /*@-mustmod@*/ /* FIX: fi->actions is modified. */
 /*@-bounds@*/
@@ -731,6 +751,9 @@ static void skipFiles(const rpmts ts, rpmfi fi)
        /*@globals rpmGlobalMacroContext @*/
        /*@modifies fi, rpmGlobalMacroContext @*/
 {
+    uint_32 tscolor = rpmtsColor(ts);
+    uint_32 ficolor;
+    int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS);
     int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS);
     char ** netsharedPaths = NULL;
     const char ** languages;
@@ -775,7 +798,7 @@ static void skipFiles(const rpmts ts, rpmfi fi)
     if (fi != NULL)    /* XXX lclint */
     while ((i = rpmfiNext(fi)) >= 0)
     {
-       char **nsp;
+       char ** nsp;
 
        bn = rpmfiBN(fi);
        bnlen = strlen(bn);
@@ -789,7 +812,15 @@ static void skipFiles(const rpmts ts, rpmfi fi)
 
        /* Don't bother with skipped files */
        if (XFA_SKIPPING(fi->actions[i])) {
-           drc[ix]--;
+           drc[ix]--; dff[ix] = 1;
+           continue;
+       }
+
+       /* Ignore colored files not in our rainbow. */
+       ficolor = rpmfiFColor(fi);
+       if (tscolor && ficolor && !(tscolor & ficolor)) {
+           drc[ix]--;  dff[ix] = 1;
+           fi->actions[i] = FA_SKIPCOLOR;
            continue;
        }
 
@@ -833,7 +864,7 @@ static void skipFiles(const rpmts ts, rpmfi fi)
        /*
         * Skip i18n language specific files.
         */
-       if (fi->flangs && languages && *fi->flangs[i]) {
+       if (languages != NULL && fi->flangs != NULL && *fi->flangs[i]) {
            const char **lang, *l, *le;
            for (lang = languages; *lang != NULL; lang++) {
                if (!strcmp(*lang, "all"))
@@ -856,6 +887,15 @@ static void skipFiles(const rpmts ts, rpmfi fi)
        }
 
        /*
+        * Skip config files if requested.
+        */
+       if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) {
+           drc[ix]--;  dff[ix] = 1;
+           fi->actions[i] = FA_SKIPNSTATE;
+           continue;
+       }
+
+       /*
         * Skip documentation if requested.
         */
        if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) {
@@ -891,20 +931,25 @@ static void skipFiles(const rpmts ts, rpmfi fi)
        fi = rpmfiInit(fi, 0);
        if (fi != NULL)         /* XXX lclint */
        while ((i = rpmfiNext(fi)) >= 0) {
-           const char * dir;
+           const char * fdn, * fbn;
+           int_16 fFMode;
 
            if (XFA_SKIPPING(fi->actions[i]))
                /*@innercontinue@*/ continue;
-           if (whatis(fi->fmodes[i]) != XDIR)
+
+           fFMode = rpmfiFMode(fi);
+
+           if (whatis(fFMode) != XDIR)
                /*@innercontinue@*/ continue;
-           dir = fi->dnl[fi->dil[i]];
-           if (strlen(dir) != dnlen)
+           fdn = rpmfiDN(fi);
+           if (strlen(fdn) != dnlen)
                /*@innercontinue@*/ continue;
-           if (strncmp(dir, dn, dnlen))
+           if (strncmp(fdn, dn, dnlen))
                /*@innercontinue@*/ continue;
-           if (strlen(fi->bnl[i]) != bnlen)
+           fbn = rpmfiBN(fi);
+           if (strlen(fbn) != bnlen)
                /*@innercontinue@*/ continue;
-           if (strncmp(fi->bnl[i], bn, bnlen))
+           if (strncmp(fbn, bn, bnlen))
                /*@innercontinue@*/ continue;
            rpmMessage(RPMMESS_DEBUG, _("excluding directory %s\n"), dn);
            fi->actions[i] = FA_SKIPNSTATE;
@@ -912,11 +957,13 @@ static void skipFiles(const rpmts ts, rpmfi fi)
        }
     }
 
+/*@-dependenttrans@*/
     if (netsharedPaths) freeSplitString(netsharedPaths);
 #ifdef DYING   /* XXX freeFi will deal with this later. */
     fi->flangs = _free(fi->flangs);
 #endif
     if (languages) freeSplitString((char **)languages);
+/*@=dependenttrans@*/
 }
 /*@=bounds@*/
 /*@=mustmod@*/
@@ -951,6 +998,7 @@ rpmfi rpmtsiFi(const rpmtsi tsi)
 
 int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
 {
+    uint_32 tscolor = rpmtsColor(ts);
     int i, j;
     int ourrc = 0;
     int totalFileCount = 0;
@@ -958,23 +1006,26 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
     sharedFileInfo shared, sharedList;
     int numShared;
     int nexti;
-    alKey lastKey;
+    alKey lastFailKey;
     fingerPrintCache fpc;
     rpmps ps;
-    PSM_t psm = memset(alloca(sizeof(*psm)), 0, sizeof(*psm));
+    rpmpsm psm;
     rpmtsi pi; rpmte p;
     rpmtsi qi; rpmte q;
+    int numAdded;
+    int numRemoved;
     int xx;
 
-    /* FIXME: what if the same package is included in ts twice? */
+    /* XXX programmer error segfault avoidance. */
+    if (rpmtsNElements(ts) <= 0)
+       return -1;
 
     if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS)
        (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
     if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS)
        (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers));
 
-    /* XXX MULTILIB is broken, as packages can and do execute /sbin/ldconfig. */
-    if (rpmtsFlags(ts) & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_MULTILIB))
+    if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)
        (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
 
     ts->probs = rpmpsFree(ts->probs);
@@ -1001,9 +1052,6 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
        (void) rpmtsSetTid(ts, tid);
     }
 
-    memset(psm, 0, sizeof(*psm));
-    psm->ts = rpmtsLink(ts, "tsRun");
-
     /* Get available space on mounted file systems. */
     xx = rpmtsInitDSI(ts);
 
@@ -1015,6 +1063,8 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
      * For packages being removed:
      * - count files.
      */
+
+rpmMessage(RPMMESS_DEBUG, _("sanity checking %d elements\n"), rpmtsNElements(ts));
     ps = rpmtsProblems(ts);
     /* The ordering doesn't matter here */
     pi = rpmtsiInit(ts);
@@ -1026,7 +1076,7 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
            continue;   /* XXX can't happen */
        fc = rpmfiFC(fi);
 
-       if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREARCH))
+       if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREARCH) && !tscolor)
            if (!archOkay(rpmteA(p)))
                rpmpsAppend(ps, RPMPROB_BADARCH,
                        rpmteNEVR(p), rpmteKey(p),
@@ -1048,13 +1098,20 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
            mi = rpmdbFreeIterator(mi);
        }
 
-       /* XXX multilib should not display "already installed" problems */
-       if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG) && !rpmteMultiLib(p)) {
+       if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG)) {
            mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
+           xx = rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_DEFAULT,
+                               rpmteE(p));
            xx = rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_DEFAULT,
                                rpmteV(p));
            xx = rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT,
                                rpmteR(p));
+           if (tscolor) {
+               xx = rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_DEFAULT,
+                               rpmteA(p));
+               xx = rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_DEFAULT,
+                               rpmteO(p));
+           }
 
            while (rpmdbNextIterator(mi) != NULL) {
                rpmpsAppend(ps, RPMPROB_PKG_INSTALLED,
@@ -1095,6 +1152,9 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
      * calling fpLookupList only once. I'm not sure that the speedup is
      * worth the trouble though.
      */
+rpmMessage(RPMMESS_DEBUG, _("computing %d file fingerprints\n"), totalFileCount);
+
+    numAdded = numRemoved = 0;
     pi = rpmtsiInit(ts);
     while ((p = rpmtsiNext(pi, 0)) != NULL) {
        int fc;
@@ -1103,20 +1163,17 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
            continue;   /* XXX can't happen */
        fc = rpmfiFC(fi);
 
-#ifdef DYING   /* XXX W2DO? this is now done in rpmtsiFi, okay ??? */
-       fi->magic = RPMFIMAGIC;
-       fi->te = p;
-#endif
-
        /*@-branchstate@*/
        switch (rpmteType(p)) {
        case TR_ADDED:
+           numAdded++;
            fi->record = 0;
            /* Skip netshared paths, not our i18n files, and excluded docs */
            if (fc > 0)
                skipFiles(ts, fi);
            /*@switchbreak@*/ break;
        case TR_REMOVED:
+           numRemoved++;
            fi->record = rpmteDBOffset(p);
            /*@switchbreak@*/ break;
        }
@@ -1146,10 +1203,13 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
     while ((p = rpmtsiNext(pi, 0)) != NULL) {
        int fc;
 
+       (void) rpmdbCheckSignals();
+
        if ((fi = rpmtsiFi(pi)) == NULL)
            continue;   /* XXX can't happen */
        fc = rpmfiFC(fi);
 
+       (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
        fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fc, fi->fps);
        /*@-branchstate@*/
        fi = rpmfiInit(fi, 0);
@@ -1162,6 +1222,8 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
            /*@=dependenttrans@*/
        }
        /*@=branchstate@*/
+       (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc);
+
     }
     pi = rpmtsiFree(pi);
 
@@ -1171,6 +1233,7 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
     /* ===============================================
      * Compute file disposition for each package in transaction set.
      */
+rpmMessage(RPMMESS_DEBUG, _("computing file dispositions\n"));
     ps = rpmtsProblems(ts);
     pi = rpmtsiInit(ts);
     while ((p = rpmtsiNext(pi, 0)) != NULL) {
@@ -1178,6 +1241,8 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
        int knownBad;
        int fc;
 
+       (void) rpmdbCheckSignals();
+
        if ((fi = rpmtsiFi(pi)) == NULL)
            continue;   /* XXX can't happen */
        fc = rpmfiFC(fi);
@@ -1187,10 +1252,10 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
 
        if (fc == 0) continue;
 
+       (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
        /* Extract file info for all files in this package from the database. */
        matches = xcalloc(fc, sizeof(*matches));
        if (rpmdbFindFpList(rpmtsGetRdb(ts), fi->fps, matches, fc)) {
-           psm->ts = rpmtsUnlink(ts, "tsRun (rpmFindFpList fail)");
            ps = rpmpsFree(ps);
            return 1;   /* XXX WTFO? */
        }
@@ -1287,6 +1352,7 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
        case TR_REMOVED:
            /*@switchbreak@*/ break;
        }
+       (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc);
     }
     pi = rpmtsiFree(pi);
     ps = rpmpsFree(ps);
@@ -1328,8 +1394,6 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
                (okProbs != NULL || rpmpsTrim(ts->probs, okProbs)))
        )
     {
-       if (psm->ts != NULL)
-           psm->ts = rpmtsUnlink(psm->ts, "tsRun (problems)");
        return ts->orderCount;
     }
 
@@ -1337,45 +1401,79 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
      * Save removed files before erasing.
      */
     if (rpmtsFlags(ts) & (RPMTRANS_FLAG_DIRSTASH | RPMTRANS_FLAG_REPACKAGE)) {
+       int progress;
+
+       progress = 0;
        pi = rpmtsiInit(ts);
        while ((p = rpmtsiNext(pi, 0)) != NULL) {
-           fi = rpmtsiFi(pi);
+
+           (void) rpmdbCheckSignals();
+
+           if ((fi = rpmtsiFi(pi)) == NULL)
+               continue;       /* XXX can't happen */
            switch (rpmteType(p)) {
            case TR_ADDED:
                /*@switchbreak@*/ break;
            case TR_REMOVED:
                if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_REPACKAGE))
                    /*@switchbreak@*/ break;
-               psm->te = p;
-               psm->fi = rpmfiLink(fi, "tsRepackage");
-               xx = psmStage(psm, PSM_PKGSAVE);
-               (void) rpmfiUnlink(fi, "tsRepackage");
-               psm->fi = NULL;
-               psm->te = NULL;
+               if (!progress)
+                   NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_START,
+                               7, numRemoved, NULL, ts->notifyData));
+
+               NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_PROGRESS, progress,
+                       numRemoved, NULL, ts->notifyData));
+               progress++;
+
+               (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_REPACKAGE), 0);
+
+       /* XXX TR_REMOVED needs CPIO_MAP_{ABSOLUTE,ADDDOT} CPIO_ALL_HARDLINKS */
+               fi->mapflags |= CPIO_MAP_ABSOLUTE;
+               fi->mapflags |= CPIO_MAP_ADDDOT;
+               fi->mapflags |= CPIO_ALL_HARDLINKS;
+               psm = rpmpsmNew(ts, p, fi);
+               xx = rpmpsmStage(psm, PSM_PKGSAVE);
+               psm = rpmpsmFree(psm);
+               fi->mapflags &= ~CPIO_MAP_ABSOLUTE;
+               fi->mapflags &= ~CPIO_MAP_ADDDOT;
+               fi->mapflags &= ~CPIO_ALL_HARDLINKS;
+
+               (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_REPACKAGE), 0);
+
                /*@switchbreak@*/ break;
            }
        }
        pi = rpmtsiFree(pi);
+       if (progress) {
+           NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_STOP, 7, numRemoved,
+                       NULL, ts->notifyData));
+       }
     }
 
     /* ===============================================
      * Install and remove packages.
      */
-    lastKey = (alKey)-2;       /* erased packages have -1 */
+    lastFailKey = (alKey)-2;   /* erased packages have -1 */
     pi = rpmtsiInit(ts);
     /*@-branchstate@*/ /* FIX: fi reload needs work */
     while ((p = rpmtsiNext(pi, 0)) != NULL) {
        alKey pkgKey;
        int gotfd;
 
+       (void) rpmdbCheckSignals();
+
        gotfd = 0;
        if ((fi = rpmtsiFi(pi)) == NULL)
            continue;   /* XXX can't happen */
        
-       psm->te = p;
-       psm->fi = rpmfiLink(fi, "tsInstall");
+       psm = rpmpsmNew(ts, p, fi);
+assert(psm != NULL);
+       psm->unorderedSuccessor =
+               (rpmtsiOc(pi) >= rpmtsUnorderedSuccessors(ts, -1) ? 1 : 0);
+
        switch (rpmteType(p)) {
        case TR_ADDED:
+           (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_INSTALL), 0);
 
            pkgKey = rpmteAddedKey(p);
 
@@ -1384,23 +1482,33 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
            /*@-type@*/ /* FIX: rpmte not opaque */
            {
                /*@-noeffectuncon@*/ /* FIX: notify annotations */
-               p->fd = ts->notify(fi->h, RPMCALLBACK_INST_OPEN_FILE, 0, 0,
+               p->fd = ts->notify(p->h, RPMCALLBACK_INST_OPEN_FILE, 0, 0,
                                rpmteKey(p), ts->notifyData);
                /*@=noeffectuncon@*/
                if (rpmteFd(p) != NULL) {
+                   rpmVSFlags ovsflags = rpmtsVSFlags(ts);
+                   rpmVSFlags vsflags = ovsflags | RPMVSF_NEEDPAYLOAD;
                    rpmRC rpmrc;
 
+                   ovsflags = rpmtsSetVSFlags(ts, vsflags);
                    rpmrc = rpmReadPackageFile(ts, rpmteFd(p),
-                               "rpmtsRun", &p->h);
+                               rpmteNEVR(p), &p->h);
+                   vsflags = rpmtsSetVSFlags(ts, ovsflags);
 
-                   if (!(rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE)) {
+                   switch (rpmrc) {
+                   default:
                        /*@-noeffectuncon@*/ /* FIX: notify annotations */
-                       p->fd = ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE,
+                       p->fd = ts->notify(p->h, RPMCALLBACK_INST_CLOSE_FILE,
                                        0, 0,
                                        rpmteKey(p), ts->notifyData);
                        /*@=noeffectuncon@*/
                        p->fd = NULL;
                        ourrc++;
+                       /*@innerbreak@*/ break;
+                   case RPMRC_NOTTRUSTED:
+                   case RPMRC_NOKEY:
+                   case RPMRC_OK:
+                       /*@innerbreak@*/ break;
                    }
                    if (rpmteFd(p) != NULL) gotfd = 1;
                }
@@ -1408,76 +1516,95 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
            /*@=type@*/
 
            if (rpmteFd(p) != NULL) {
+               /*
+                * XXX Sludge necessary to tranfer existing fstates/actions
+                * XXX around a recreated file info set.
+                */
+               psm->fi = rpmfiFree(psm->fi);
                {
-char * fstates = fi->fstates;
-fileAction * actions = fi->actions;
-
-fi->fstates = NULL;
-fi->actions = NULL;
-                   psm->fi = rpmfiFree(psm->fi, 1);
-                   (void) rpmfiFree(fi, 0);
-/*@-usereleased@*/
-fi->magic = RPMFIMAGIC;
-fi->te = p;
-fi->record = 0;
-                   (void) rpmfiNew(ts, fi, p->h, RPMTAG_BASENAMES, 1);
-                   psm->fi = rpmfiLink(fi, "tsInstall");
-fi->fstates = _free(fi->fstates);
-fi->fstates = fstates;
-fi->actions = _free(fi->actions);
-fi->actions = actions;
-/*@=usereleased@*/
-
+                   char * fstates = fi->fstates;
+                   fileAction * actions = fi->actions;
+                   rpmte savep;
+
+                   fi->fstates = NULL;
+                   fi->actions = NULL;
+/*@-nullstate@*/ /* FIX: fi->actions is NULL */
+                   fi = rpmfiFree(fi);
+/*@=nullstate@*/
+
+                   savep = rpmtsSetRelocateElement(ts, p);
+                   fi = rpmfiNew(ts, p->h, RPMTAG_BASENAMES, 1);
+                   (void) rpmtsSetRelocateElement(ts, savep);
+
+                   if (fi != NULL) {   /* XXX can't happen */
+                       fi->te = p;
+                       fi->fstates = _free(fi->fstates);
+                       fi->fstates = fstates;
+                       fi->actions = _free(fi->actions);
+                       fi->actions = actions;
+                       p->fi = fi;
+                   }
                }
-               if (rpmteMultiLib(p))
-                   (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_MULTILIB));
-               else
-                   (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) & ~RPMTRANS_FLAG_MULTILIB));
+               psm->fi = rpmfiLink(p->fi, NULL);
 
-               if (psmStage(psm, PSM_PKGINSTALL)) {
+/*@-nullstate@*/ /* FIX: psm->fi may be NULL */
+               if (rpmpsmStage(psm, PSM_PKGINSTALL)) {
                    ourrc++;
-                   lastKey = pkgKey;
+                   lastFailKey = pkgKey;
                }
-               fi->h = headerFree(fi->h);
+/*@=nullstate@*/
            } else {
                ourrc++;
-               lastKey = pkgKey;
+               lastFailKey = pkgKey;
            }
 
-           p->h = headerFree(p->h);
-
            if (gotfd) {
                /*@-noeffectuncon @*/ /* FIX: check rc */
-               (void) ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
+               (void) ts->notify(p->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
                        rpmteKey(p), ts->notifyData);
                /*@=noeffectuncon @*/
                /*@-type@*/
                p->fd = NULL;
                /*@=type@*/
            }
+
+           p->h = headerFree(p->h);
+
+           (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_INSTALL), 0);
+
            /*@switchbreak@*/ break;
+
        case TR_REMOVED:
+           (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_ERASE), 0);
+
            rpmMessage(RPMMESS_DEBUG, "========== --- %s\n", rpmteNEVR(p));
-           /* If install failed, then we shouldn't erase. */
-           if (rpmteDependsOnKey(p) != lastKey) {
-               if (psmStage(psm, PSM_PKGERASE))
+           /*
+            * XXX This has always been a hack, now mostly broken.
+            * If install failed, then we shouldn't erase.
+            */
+           if (rpmteDependsOnKey(p) != lastFailKey) {
+               if (rpmpsmStage(psm, PSM_PKGERASE))
                    ourrc++;
            }
+
+           (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_ERASE), 0);
+
            /*@switchbreak@*/ break;
        }
        xx = rpmdbSync(rpmtsGetRdb(ts));
-       (void) rpmfiUnlink(psm->fi, "tsInstall");
-       psm->fi = NULL;
-       psm->te = NULL;
+
+/*@-nullstate@*/ /* FIX: psm->fi may be NULL */
+       psm = rpmpsmFree(psm);
+/*@=nullstate@*/
+
 /*@-type@*/ /* FIX: p is almost opaque */
-       p->fi = rpmfiFree(fi, 1);
+       p->fi = rpmfiFree(p->fi);
 /*@=type@*/
+
     }
     /*@=branchstate@*/
     pi = rpmtsiFree(pi);
 
-    psm->ts = rpmtsUnlink(psm->ts, "tsRun");
-
     /*@-nullstate@*/ /* FIX: ts->flList may be NULL */
     if (ourrc)
        return -1;