00001
00006 #include "system.h"
00007
00008 #include <rpmio_internal.h>
00009 #include <rpmlib.h>
00010
00011 #include "cpio.h"
00012 #include "fsm.h"
00013
00014 #include "rpmds.h"
00015
00016 #include "legacy.h"
00017
00018 #define _RPMFI_INTERNAL
00019 #include "rpmfi.h"
00020
00021 #include "rpmsx.h"
00022
00023 #define _RPMTE_INTERNAL
00024 #include "rpmte.h"
00025 #include "rpmts.h"
00026
00027 #include "misc.h"
00028 #include "rpmmacro.h"
00029
00030 #include "debug.h"
00031
00032
00033
00034
00035
00036 int _rpmfi_debug = 0;
00037
00038 rpmfi XrpmfiUnlink(rpmfi fi, const char * msg, const char * fn, unsigned ln)
00039 {
00040 if (fi == NULL) return NULL;
00041
00042 if (_rpmfi_debug && msg != NULL)
00043 fprintf(stderr, "--> fi %p -- %d %s at %s:%u\n", fi, fi->nrefs, msg, fn, ln);
00044
00045 fi->nrefs--;
00046 return NULL;
00047 }
00048
00049 rpmfi XrpmfiLink(rpmfi fi, const char * msg, const char * fn, unsigned ln)
00050 {
00051 if (fi == NULL) return NULL;
00052 fi->nrefs++;
00053
00054 if (_rpmfi_debug && msg != NULL)
00055 fprintf(stderr, "--> fi %p ++ %d %s at %s:%u\n", fi, fi->nrefs, msg, fn, ln);
00056
00057 return fi;
00058 }
00059
00060 int rpmfiFC(rpmfi fi)
00061 {
00062 return (fi != NULL ? fi->fc : 0);
00063 }
00064
00065 int rpmfiDC(rpmfi fi)
00066 {
00067 return (fi != NULL ? fi->dc : 0);
00068 }
00069
00070 #ifdef NOTYET
00071 int rpmfiDI(rpmfi fi)
00072 {
00073 }
00074 #endif
00075
00076 int rpmfiFX(rpmfi fi)
00077 {
00078 return (fi != NULL ? fi->i : -1);
00079 }
00080
00081 int rpmfiSetFX(rpmfi fi, int fx)
00082 {
00083 int i = -1;
00084
00085 if (fi != NULL && fx >= 0 && fx < fi->fc) {
00086 i = fi->i;
00087 fi->i = fx;
00088
00089 fi->j = fi->dil[fi->i];
00090
00091 }
00092 return i;
00093 }
00094
00095 int rpmfiDX(rpmfi fi)
00096 {
00097 return (fi != NULL ? fi->j : -1);
00098 }
00099
00100 int rpmfiSetDX(rpmfi fi, int dx)
00101 {
00102 int j = -1;
00103
00104 if (fi != NULL && dx >= 0 && dx < fi->dc) {
00105 j = fi->j;
00106 fi->j = dx;
00107 }
00108 return j;
00109 }
00110
00111 const char * rpmfiBN(rpmfi fi)
00112 {
00113 const char * BN = NULL;
00114
00115 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00116
00117 if (fi->bnl != NULL)
00118 BN = fi->bnl[fi->i];
00119
00120 }
00121 return BN;
00122 }
00123
00124 const char * rpmfiDN(rpmfi fi)
00125 {
00126 const char * DN = NULL;
00127
00128 if (fi != NULL && fi->j >= 0 && fi->j < fi->dc) {
00129
00130 if (fi->dnl != NULL)
00131 DN = fi->dnl[fi->j];
00132
00133 }
00134 return DN;
00135 }
00136
00137 const char * rpmfiFN(rpmfi fi)
00138 {
00139 const char * FN = "";
00140
00141
00142 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00143 const char *dn;
00144 char * t;
00145 if (fi->fn == NULL)
00146 fi->fn = xmalloc(fi->fnlen);
00147 FN = t = fi->fn;
00148 (void) urlPath(fi->dnl[fi->dil[fi->i]], &dn);
00149
00150 *t = '\0';
00151 t = stpcpy(t, dn);
00152 t = stpcpy(t, fi->bnl[fi->i]);
00153
00154 }
00155
00156 return FN;
00157 }
00158
00159 uint_32 rpmfiFFlags(rpmfi fi)
00160 {
00161 uint_32 FFlags = 0;
00162
00163 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00164
00165 if (fi->fflags != NULL)
00166 FFlags = fi->fflags[fi->i];
00167
00168 }
00169 return FFlags;
00170 }
00171
00172 uint_32 rpmfiSetFFlags(rpmfi fi, uint_32 FFlags)
00173 {
00174 uint_32 oFFlags = 0;
00175
00176 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00177
00178 if (fi->fflags != NULL && fi->h == NULL) {
00179 oFFlags = fi->fflags[fi->i];
00180 *((uint_32 *)(fi->fflags + fi->i)) = FFlags;
00181 }
00182
00183 }
00184 return oFFlags;
00185 }
00186
00187 uint_32 rpmfiVFlags(rpmfi fi)
00188 {
00189 uint_32 VFlags = 0;
00190
00191 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00192
00193 if (fi->vflags != NULL)
00194 VFlags = fi->vflags[fi->i];
00195
00196 }
00197 return VFlags;
00198 }
00199
00200 uint_32 rpmfiSetVFlags(rpmfi fi, uint_32 VFlags)
00201 {
00202 uint_32 oVFlags = 0;
00203
00204 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00205
00206 if (fi->vflags != NULL && fi->h == NULL) {
00207 oVFlags = fi->vflags[fi->i];
00208 *((uint_32 *)(fi->vflags + fi->i)) = VFlags;
00209 }
00210
00211 }
00212 return oVFlags;
00213 }
00214
00215 int_16 rpmfiFMode(rpmfi fi)
00216 {
00217 int_16 fmode = 0;
00218
00219 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00220
00221 if (fi->fmodes != NULL)
00222 fmode = fi->fmodes[fi->i];
00223
00224 }
00225 return fmode;
00226 }
00227
00228 rpmfileState rpmfiFState(rpmfi fi)
00229 {
00230 rpmfileState fstate = RPMFILE_STATE_MISSING;
00231
00232 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00233
00234 if (fi->fstates != NULL)
00235 fstate = fi->fstates[fi->i];
00236
00237 }
00238 return fstate;
00239 }
00240
00241 rpmfileState rpmfiSetFState(rpmfi fi, rpmfileState fstate)
00242 {
00243 int_32 ofstate = 0;
00244
00245 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00246
00247 if (fi->fstates != NULL) {
00248 ofstate = fi->fstates[fi->i];
00249 fi->fstates[fi->i] = fstate;
00250 }
00251
00252 }
00253 return ofstate;
00254 }
00255
00256 const unsigned char * rpmfiDigest(rpmfi fi, int * algop, size_t * lenp)
00257 {
00258 unsigned char * digest = NULL;
00259
00260 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00261
00262 if (fi->digests != NULL) {
00263 digest = fi->digests + (fi->digestlen * fi->i);
00264 if (algop != NULL)
00265 *algop = (fi->fdigestalgos
00266 ? fi->fdigestalgos[fi->i] : fi->digestalgo);
00267 if (lenp != NULL)
00268 *lenp = fi->digestlen;
00269 }
00270
00271 }
00272 return digest;
00273 }
00274
00275 const char * rpmfiFLink(rpmfi fi)
00276 {
00277 const char * flink = NULL;
00278
00279 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00280
00281 if (fi->flinks != NULL)
00282 flink = fi->flinks[fi->i];
00283
00284 }
00285 return flink;
00286 }
00287
00288 int_32 rpmfiFSize(rpmfi fi)
00289 {
00290 int_32 fsize = 0;
00291
00292 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00293
00294 if (fi->fsizes != NULL)
00295 fsize = fi->fsizes[fi->i];
00296
00297 }
00298 return fsize;
00299 }
00300
00301 int_16 rpmfiFRdev(rpmfi fi)
00302 {
00303 int_16 frdev = 0;
00304
00305 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00306
00307 if (fi->frdevs != NULL)
00308 frdev = fi->frdevs[fi->i];
00309
00310 }
00311 return frdev;
00312 }
00313
00314 int_32 rpmfiFInode(rpmfi fi)
00315 {
00316 int_32 finode = 0;
00317
00318 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00319
00320 if (fi->finodes != NULL)
00321 finode = fi->finodes[fi->i];
00322
00323 }
00324 return finode;
00325 }
00326
00327 uint_32 rpmfiColor(rpmfi fi)
00328 {
00329 uint_32 color = 0;
00330
00331 if (fi != NULL)
00332
00333 color = fi->color & 0xf;
00334 return color;
00335 }
00336
00337 uint_32 rpmfiFColor(rpmfi fi)
00338 {
00339 uint_32 fcolor = 0;
00340
00341 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00342
00343 if (fi->fcolors != NULL)
00344
00345 fcolor = (fi->fcolors[fi->i] & 0x0f);
00346
00347 }
00348 return fcolor;
00349 }
00350
00351 const char * rpmfiFClass(rpmfi fi)
00352 {
00353 const char * fclass = NULL;
00354 int cdictx;
00355
00356 if (fi != NULL && fi->fcdictx != NULL && fi->i >= 0 && fi->i < fi->fc) {
00357
00358 cdictx = fi->fcdictx[fi->i];
00359 if (fi->cdict != NULL && cdictx >= 0 && cdictx < fi->ncdict)
00360 fclass = fi->cdict[cdictx];
00361
00362 }
00363 return fclass;
00364 }
00365
00366 const char * rpmfiFContext(rpmfi fi)
00367 {
00368 const char * fcontext = NULL;
00369
00370 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00371
00372 if (fi->fcontexts != NULL)
00373 fcontext = fi->fcontexts[fi->i];
00374
00375 }
00376 return fcontext;
00377 }
00378
00379 int_32 rpmfiFDepends(rpmfi fi, const uint_32 ** fddictp)
00380 {
00381 int fddictx = -1;
00382 int fddictn = 0;
00383 const uint_32 * fddict = NULL;
00384
00385 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00386
00387 if (fi->fddictn != NULL)
00388 fddictn = fi->fddictn[fi->i];
00389 if (fddictn > 0 && fi->fddictx != NULL)
00390 fddictx = fi->fddictx[fi->i];
00391 if (fi->ddict != NULL && fddictx >= 0 && (fddictx+fddictn) <= fi->nddict)
00392 fddict = fi->ddict + fddictx;
00393
00394 }
00395
00396 if (fddictp)
00397 *fddictp = fddict;
00398
00399 return fddictn;
00400 }
00401
00402 int_32 rpmfiFNlink(rpmfi fi)
00403 {
00404 int_32 nlink = 0;
00405
00406 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00407
00408
00409 if (fi->finodes && fi->frdevs) {
00410 int_32 finode = fi->finodes[fi->i];
00411 int_16 frdev = fi->frdevs[fi->i];
00412 int j;
00413
00414 for (j = 0; j < fi->fc; j++) {
00415 if (fi->frdevs[j] == frdev && fi->finodes[j] == finode)
00416 nlink++;
00417 }
00418 }
00419
00420 }
00421 return nlink;
00422 }
00423
00424 int_32 rpmfiFMtime(rpmfi fi)
00425 {
00426 int_32 fmtime = 0;
00427
00428 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00429
00430 if (fi->fmtimes != NULL)
00431 fmtime = fi->fmtimes[fi->i];
00432
00433 }
00434 return fmtime;
00435 }
00436
00437 const char * rpmfiFUser(rpmfi fi)
00438 {
00439 const char * fuser = NULL;
00440
00441
00442 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00443
00444 if (fi->fuser != NULL)
00445 fuser = fi->fuser[fi->i];
00446
00447 }
00448 return fuser;
00449 }
00450
00451 const char * rpmfiFGroup(rpmfi fi)
00452 {
00453 const char * fgroup = NULL;
00454
00455
00456 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00457
00458 if (fi->fgroup != NULL)
00459 fgroup = fi->fgroup[fi->i];
00460
00461 }
00462 return fgroup;
00463 }
00464
00465 int rpmfiNext(rpmfi fi)
00466 {
00467 int i = -1;
00468
00469 if (fi != NULL && ++fi->i >= 0) {
00470 if (fi->i < fi->fc) {
00471 i = fi->i;
00472
00473 if (fi->dil != NULL)
00474 fi->j = fi->dil[fi->i];
00475
00476 } else
00477 fi->i = -1;
00478
00479
00480 if (_rpmfi_debug < 0 && i != -1)
00481 fprintf(stderr, "*** fi %p\t%s[%d] %s%s\n", fi, (fi->Type ? fi->Type : "?Type?"), i, (i >= 0 ? fi->dnl[fi->j] : ""), (i >= 0 ? fi->bnl[fi->i] : ""));
00482
00483
00484 }
00485
00486 return i;
00487 }
00488
00489 rpmfi rpmfiInit(rpmfi fi, int fx)
00490 {
00491 if (fi != NULL) {
00492 if (fx >= 0 && fx < fi->fc) {
00493 fi->i = fx - 1;
00494 fi->j = -1;
00495 }
00496 }
00497
00498
00499 return fi;
00500
00501 }
00502
00503 int rpmfiNextD(rpmfi fi)
00504 {
00505 int j = -1;
00506
00507 if (fi != NULL && ++fi->j >= 0) {
00508 if (fi->j < fi->dc)
00509 j = fi->j;
00510 else
00511 fi->j = -1;
00512
00513
00514 if (_rpmfi_debug < 0 && j != -1)
00515 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, (fi->Type ? fi->Type : "?Type?"), j);
00516
00517
00518 }
00519
00520 return j;
00521 }
00522
00523 rpmfi rpmfiInitD(rpmfi fi, int dx)
00524 {
00525 if (fi != NULL) {
00526 if (dx >= 0 && dx < fi->fc)
00527 fi->j = dx - 1;
00528 else
00529 fi = NULL;
00530 }
00531
00532
00533 return fi;
00534
00535 }
00536
00542 static
00543 const char * ftstring (fileTypes ft)
00544
00545 {
00546 switch (ft) {
00547 case XDIR: return "directory";
00548 case CDEV: return "char dev";
00549 case BDEV: return "block dev";
00550 case LINK: return "link";
00551 case SOCK: return "sock";
00552 case PIPE: return "fifo/pipe";
00553 case REG: return "file";
00554 default: return "unknown file type";
00555 }
00556
00557 }
00558
00559 fileTypes whatis(uint_16 mode)
00560 {
00561 if (S_ISDIR(mode)) return XDIR;
00562 if (S_ISCHR(mode)) return CDEV;
00563 if (S_ISBLK(mode)) return BDEV;
00564 if (S_ISLNK(mode)) return LINK;
00565
00566 if (S_ISSOCK(mode)) return SOCK;
00567
00568 if (S_ISFIFO(mode)) return PIPE;
00569 return REG;
00570 }
00571
00572
00573 int rpmfiCompare(const rpmfi afi, const rpmfi bfi)
00574
00575 {
00576 fileTypes awhat = whatis(rpmfiFMode(afi));
00577 fileTypes bwhat = whatis(rpmfiFMode(bfi));
00578
00579 if (awhat != bwhat) return 1;
00580
00581 if (awhat == LINK) {
00582 const char * alink = rpmfiFLink(afi);
00583 const char * blink = rpmfiFLink(bfi);
00584 if (alink == blink) return 0;
00585 if (alink == NULL) return 1;
00586 if (blink == NULL) return -1;
00587 return strcmp(alink, blink);
00588 } else if (awhat == REG) {
00589 int aalgo = 0;
00590 size_t alen = 0;
00591 const unsigned char * adigest = rpmfiDigest(afi, &aalgo, &alen);
00592 int balgo = 0;
00593 size_t blen = 0;
00594 const unsigned char * bdigest = rpmfiDigest(bfi, &balgo, &blen);
00595
00596 if (!(aalgo == balgo && alen == blen))
00597 return -1;
00598 if (adigest == bdigest) return 0;
00599 if (adigest == NULL) return 1;
00600 if (bdigest == NULL) return -1;
00601 return memcmp(adigest, bdigest, alen);
00602 }
00603
00604 return 0;
00605 }
00606
00607
00608
00609 fileAction rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
00610 {
00611 const char * fn = rpmfiFN(nfi);
00612 int newFlags = rpmfiFFlags(nfi);
00613 char buffer[1024+1];
00614 fileTypes dbWhat, newWhat, diskWhat;
00615 struct stat sb;
00616 int save = (newFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SAVE;
00617
00618 if (lstat(fn, &sb)) {
00619
00620
00621
00622
00623 if (skipMissing && (newFlags & RPMFILE_MISSINGOK)) {
00624 rpmMessage(RPMMESS_DEBUG, _("%s skipped due to missingok flag\n"),
00625 fn);
00626 return FA_SKIP;
00627 } else {
00628 return FA_CREATE;
00629 }
00630 }
00631
00632 diskWhat = whatis((int_16)sb.st_mode);
00633 dbWhat = whatis(rpmfiFMode(ofi));
00634 newWhat = whatis(rpmfiFMode(nfi));
00635
00636
00637
00638
00639
00640 if (newWhat == XDIR)
00641 return FA_CREATE;
00642
00643 if (diskWhat != newWhat && dbWhat != REG && dbWhat != LINK)
00644 return save;
00645 else if (newWhat != dbWhat && diskWhat != dbWhat)
00646 return save;
00647 else if (dbWhat != newWhat)
00648 return FA_CREATE;
00649 else if (dbWhat != LINK && dbWhat != REG)
00650 return FA_CREATE;
00651
00652
00653
00654
00655
00656 memset(buffer, 0, sizeof(buffer));
00657 if (dbWhat == REG) {
00658 int oalgo = 0;
00659 size_t olen = 0;
00660 const unsigned char * odigest;
00661 int nalgo = 0;
00662 size_t nlen = 0;
00663 const unsigned char * ndigest;
00664 odigest = rpmfiDigest(ofi, &oalgo, &olen);
00665 if (diskWhat == REG) {
00666 if (!(newFlags & RPMFILE_SPARSE))
00667 if (dodigest(oalgo, fn, buffer, 0, NULL))
00668 return FA_CREATE;
00669 if (odigest && !memcmp(odigest, buffer, olen))
00670 return FA_CREATE;
00671 }
00672 ndigest = rpmfiDigest(nfi, &nalgo, &nlen);
00673
00674 if (odigest && ndigest && oalgo == nalgo && olen == nlen
00675 && !memcmp(odigest, ndigest, nlen))
00676 return FA_SKIP;
00677
00678 } else {
00679 const char * oFLink, * nFLink;
00680 oFLink = rpmfiFLink(ofi);
00681 if (diskWhat == LINK) {
00682 if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
00683 return FA_CREATE;
00684 buffer[sizeof(buffer)-1] = '\0';
00685 if (oFLink && !strcmp(oFLink, buffer))
00686 return FA_CREATE;
00687 }
00688 nFLink = rpmfiFLink(nfi);
00689
00690 if (oFLink && nFLink && !strcmp(oFLink, nFLink))
00691 return FA_SKIP;
00692
00693 }
00694
00695
00696
00697
00698
00699
00700
00701 return save;
00702 }
00703
00704
00705
00706 const char * rpmfiTypeString(rpmfi fi)
00707 {
00708 switch(rpmteType(fi->te)) {
00709 case TR_ADDED: return " install";
00710 case TR_REMOVED: return " erase";
00711 default: return "???";
00712 }
00713
00714 }
00715
00716 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
00717
00727
00728 static
00729 Header relocateFileList(const rpmts ts, rpmfi fi,
00730 Header origH, fileAction * actions)
00731
00732
00733 {
00734 rpmte p = rpmtsRelocateElement(ts);
00735 HGE_t hge = fi->hge;
00736 HAE_t hae = fi->hae;
00737 HME_t hme = fi->hme;
00738 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00739 static int _printed = 0;
00740 int allowBadRelocate = (rpmtsFilterFlags(ts) & RPMPROB_FILTER_FORCERELOCATE);
00741 rpmRelocation relocations = NULL;
00742 int numRelocations;
00743 const char ** validRelocations;
00744 rpmTagType validType;
00745 int numValid;
00746 const char ** baseNames;
00747 const char ** dirNames;
00748 int_32 * dirIndexes;
00749 int_32 * newDirIndexes;
00750 int_32 fileCount;
00751 int_32 dirCount;
00752 uint_32 mydColor = rpmExpandNumeric("%{?_autorelocate_dcolor}");
00753 uint_32 * fFlags = NULL;
00754 uint_32 * fColors = NULL;
00755 uint_32 * dColors = NULL;
00756 uint_16 * fModes = NULL;
00757 Header h;
00758 int nrelocated = 0;
00759 int fileAlloced = 0;
00760 char * fn = NULL;
00761 int haveRelocatedFile = 0;
00762 int reldel = 0;
00763 int len;
00764 int i, j, xx;
00765
00766 if (!hge(origH, RPMTAG_PREFIXES, &validType,
00767 (void **) &validRelocations, &numValid))
00768 numValid = 0;
00769
00770 assert(p != NULL);
00771 numRelocations = 0;
00772 if (p->relocs)
00773 while (p->relocs[numRelocations].newPath ||
00774 p->relocs[numRelocations].oldPath)
00775 numRelocations++;
00776
00777
00778
00779
00780
00781
00782
00783 if (p->relocs == NULL || numRelocations == 0) {
00784 if (numValid) {
00785 if (!headerIsEntry(origH, RPMTAG_INSTPREFIXES))
00786 xx = hae(origH, RPMTAG_INSTPREFIXES,
00787 validType, validRelocations, numValid);
00788 validRelocations = hfd(validRelocations, validType);
00789 }
00790
00791 return headerLink(origH);
00792 }
00793
00794 h = headerLink(origH);
00795
00796 relocations = alloca(sizeof(*relocations) * numRelocations);
00797
00798
00799 for (i = 0; i < numRelocations; i++) {
00800 char * t;
00801
00802
00803
00804
00805
00806 if (p->relocs[i].oldPath == NULL) continue;
00807
00808
00809
00810 t = alloca_strdup(p->relocs[i].oldPath);
00811
00812 relocations[i].oldPath = (t[0] == '/' && t[1] == '\0')
00813 ? t
00814 : stripTrailingChar(t, '/');
00815
00816
00817
00818 if (p->relocs[i].newPath) {
00819 int del;
00820
00821 t = alloca_strdup(p->relocs[i].newPath);
00822
00823 relocations[i].newPath = (t[0] == '/' && t[1] == '\0')
00824 ? t
00825 : stripTrailingChar(t, '/');
00826
00827
00828
00829
00830 for (j = 0; j < numValid; j++) {
00831 if (!strcmp(validRelocations[j], relocations[i].oldPath))
00832 break;
00833 }
00834
00835
00836 if (j == numValid && !allowBadRelocate && actions) {
00837 rpmps ps = rpmtsProblems(ts);
00838 rpmpsAppend(ps, RPMPROB_BADRELOCATE,
00839 rpmteNEVR(p), rpmteKey(p),
00840 relocations[i].oldPath, NULL, NULL, 0);
00841 ps = rpmpsFree(ps);
00842 }
00843 del =
00844 strlen(relocations[i].newPath) - strlen(relocations[i].oldPath);
00845
00846
00847 if (del > reldel)
00848 reldel = del;
00849 } else {
00850 relocations[i].newPath = NULL;
00851 }
00852 }
00853
00854
00855 for (i = 0; i < numRelocations; i++) {
00856 int madeSwap;
00857 madeSwap = 0;
00858 for (j = 1; j < numRelocations; j++) {
00859 struct rpmRelocation_s tmpReloc;
00860 if (relocations[j - 1].oldPath == NULL ||
00861 relocations[j ].oldPath == NULL ||
00862 strcmp(relocations[j - 1].oldPath, relocations[j].oldPath) <= 0)
00863 continue;
00864
00865 tmpReloc = relocations[j - 1];
00866 relocations[j - 1] = relocations[j];
00867 relocations[j] = tmpReloc;
00868
00869 madeSwap = 1;
00870 }
00871 if (!madeSwap) break;
00872 }
00873
00874 if (!_printed) {
00875 _printed = 1;
00876 rpmMessage(RPMMESS_DEBUG, _("========== relocations\n"));
00877 for (i = 0; i < numRelocations; i++) {
00878 if (relocations[i].oldPath == NULL) continue;
00879 if (relocations[i].newPath == NULL)
00880 rpmMessage(RPMMESS_DEBUG, _("%5d exclude %s\n"),
00881 i, relocations[i].oldPath);
00882 else
00883 rpmMessage(RPMMESS_DEBUG, _("%5d relocate %s -> %s\n"),
00884 i, relocations[i].oldPath, relocations[i].newPath);
00885 }
00886 }
00887
00888
00889 if (numValid) {
00890 const char ** actualRelocations;
00891 int numActual;
00892
00893 actualRelocations = xmalloc(numValid * sizeof(*actualRelocations));
00894 numActual = 0;
00895 for (i = 0; i < numValid; i++) {
00896 for (j = 0; j < numRelocations; j++) {
00897 if (relocations[j].oldPath == NULL ||
00898 strcmp(validRelocations[i], relocations[j].oldPath))
00899 continue;
00900
00901 if (relocations[j].newPath) {
00902 actualRelocations[numActual] = relocations[j].newPath;
00903 numActual++;
00904 }
00905 break;
00906 }
00907 if (j == numRelocations) {
00908 actualRelocations[numActual] = validRelocations[i];
00909 numActual++;
00910 }
00911 }
00912
00913 if (numActual)
00914 xx = hae(h, RPMTAG_INSTPREFIXES, RPM_STRING_ARRAY_TYPE,
00915 (void **) actualRelocations, numActual);
00916
00917 actualRelocations = _free(actualRelocations);
00918 validRelocations = hfd(validRelocations, validType);
00919 }
00920
00921 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &baseNames, &fileCount);
00922 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes, NULL);
00923 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &dirNames, &dirCount);
00924 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fFlags, NULL);
00925 xx = hge(h, RPMTAG_FILECOLORS, NULL, (void **) &fColors, NULL);
00926 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fModes, NULL);
00927
00928 dColors = alloca(dirCount * sizeof(*dColors));
00929 memset(dColors, 0, dirCount * sizeof(*dColors));
00930
00931 newDirIndexes = alloca(sizeof(*newDirIndexes) * fileCount);
00932 memcpy(newDirIndexes, dirIndexes, sizeof(*newDirIndexes) * fileCount);
00933 dirIndexes = newDirIndexes;
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943 for (i = fileCount - 1; i >= 0; i--) {
00944 fileTypes ft;
00945 int fnlen;
00946
00947 len = reldel +
00948 strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
00949
00950 if (len >= fileAlloced) {
00951 fileAlloced = len * 2;
00952 fn = xrealloc(fn, fileAlloced);
00953 }
00954
00955
00956 assert(fn != NULL);
00957 *fn = '\0';
00958 fnlen = stpcpy( stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;
00959
00960 if (fColors != NULL) {
00961
00962 for (j = 0; j < dirCount; j++) {
00963 if (strcmp(dirNames[dirIndexes[i]], dirNames[j])) continue;
00964 dColors[j] |= fColors[i];
00965 }
00966 }
00967
00968
00969
00970
00971
00972
00973
00974
00975 for (j = numRelocations - 1; j >= 0; j--) {
00976 if (relocations[j].oldPath == NULL)
00977 continue;
00978 len = strcmp(relocations[j].oldPath, "/")
00979 ? strlen(relocations[j].oldPath)
00980 : 0;
00981
00982 if (fnlen < len)
00983 continue;
00984
00985
00986
00987
00988 if (!(fn[len] == '/' || fnlen == len))
00989 continue;
00990
00991 if (strncmp(relocations[j].oldPath, fn, len))
00992 continue;
00993 break;
00994 }
00995 if (j < 0) continue;
00996
00997
00998 ft = whatis(fModes[i]);
00999
01000
01001
01002 if (relocations[j].newPath == NULL) {
01003 if (ft == XDIR) {
01004
01005 for (j = dirIndexes[i]; j < dirCount; j++) {
01006 len = strlen(dirNames[j]) - 1;
01007 while (len > 0 && dirNames[j][len-1] == '/') len--;
01008 if (fnlen != len)
01009 continue;
01010 if (strncmp(fn, dirNames[j], fnlen))
01011 continue;
01012 break;
01013 }
01014 }
01015 if (actions) {
01016 actions[i] = FA_SKIPNSTATE;
01017 rpmMessage(RPMMESS_DEBUG, _("excluding %s %s\n"),
01018 ftstring(ft), fn);
01019 }
01020 continue;
01021 }
01022
01023
01024 if (fnlen != len) continue;
01025
01026 if (actions)
01027 rpmMessage(RPMMESS_DEBUG, _("relocating %s to %s\n"),
01028 fn, relocations[j].newPath);
01029 nrelocated++;
01030
01031 strcpy(fn, relocations[j].newPath);
01032 { char * te = strrchr(fn, '/');
01033 if (te) {
01034 if (te > fn) te++;
01035 fnlen = te - fn;
01036 } else
01037 te = fn + strlen(fn);
01038
01039 if (strcmp(baseNames[i], te))
01040 baseNames[i] = alloca_strdup(te);
01041 *te = '\0';
01042
01043 }
01044
01045
01046 for (j = 0; j < dirCount; j++) {
01047 if (fnlen != strlen(dirNames[j]))
01048 continue;
01049 if (strncmp(fn, dirNames[j], fnlen))
01050 continue;
01051 break;
01052 }
01053
01054 if (j < dirCount) {
01055 dirIndexes[i] = j;
01056 continue;
01057 }
01058
01059
01060 if (!haveRelocatedFile) {
01061 const char ** newDirList;
01062
01063 haveRelocatedFile = 1;
01064 newDirList = xmalloc((dirCount + 1) * sizeof(*newDirList));
01065 for (j = 0; j < dirCount; j++)
01066 newDirList[j] = alloca_strdup(dirNames[j]);
01067 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
01068 dirNames = newDirList;
01069 } else {
01070 dirNames = xrealloc(dirNames,
01071 sizeof(*dirNames) * (dirCount + 1));
01072 }
01073
01074 dirNames[dirCount] = alloca_strdup(fn);
01075 dirIndexes[i] = dirCount;
01076 dirCount++;
01077 }
01078
01079
01080 for (i = dirCount - 1; i >= 0; i--) {
01081 for (j = numRelocations - 1; j >= 0; j--) {
01082
01083
01084 if (j == p->autorelocatex
01085 && (dColors[i] == 0 || !(dColors[i] & mydColor)))
01086 continue;
01087
01088 if (relocations[j].oldPath == NULL)
01089 continue;
01090 len = strcmp(relocations[j].oldPath, "/")
01091 ? strlen(relocations[j].oldPath)
01092 : 0;
01093
01094 if (len && strncmp(relocations[j].oldPath, dirNames[i], len))
01095 continue;
01096
01097
01098
01099
01100
01101 if (dirNames[i][len] != '/')
01102 continue;
01103
01104 if (relocations[j].newPath) {
01105 const char * s = relocations[j].newPath;
01106 char * t = alloca(strlen(s) + strlen(dirNames[i]) - len + 1);
01107 size_t slen;
01108
01109 (void) stpcpy( stpcpy(t, s) , dirNames[i] + len);
01110
01111
01112 (void) rpmCleanPath(t);
01113 slen = strlen(t);
01114 t[slen] = '/';
01115 t[slen+1] = '\0';
01116
01117 if (actions)
01118 rpmMessage(RPMMESS_DEBUG,
01119 _("relocating directory %s to %s\n"), dirNames[i], t);
01120 dirNames[i] = t;
01121 nrelocated++;
01122 }
01123 }
01124 }
01125
01126
01127 if (nrelocated) {
01128 int c;
01129 void * d;
01130 rpmTagType t;
01131
01132 d = NULL;
01133 xx = hge(h, RPMTAG_BASENAMES, &t, &d, &c);
01134 xx = hae(h, RPMTAG_ORIGBASENAMES, t, d, c);
01135 d = hfd(d, t);
01136
01137 d = NULL;
01138 xx = hge(h, RPMTAG_DIRNAMES, &t, &d, &c);
01139 xx = hae(h, RPMTAG_ORIGDIRNAMES, t, d, c);
01140 d = hfd(d, t);
01141
01142 d = NULL;
01143 xx = hge(h, RPMTAG_DIRINDEXES, &t, &d, &c);
01144 xx = hae(h, RPMTAG_ORIGDIRINDEXES, t, d, c);
01145 d = hfd(d, t);
01146
01147 xx = hme(h, RPMTAG_BASENAMES, RPM_STRING_ARRAY_TYPE,
01148 baseNames, fileCount);
01149 fi->bnl = hfd(fi->bnl, RPM_STRING_ARRAY_TYPE);
01150 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc);
01151
01152 xx = hme(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
01153 dirNames, dirCount);
01154 fi->dnl = hfd(fi->dnl, RPM_STRING_ARRAY_TYPE);
01155 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
01156
01157 xx = hme(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE,
01158 dirIndexes, fileCount);
01159 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
01160 }
01161
01162 baseNames = hfd(baseNames, RPM_STRING_ARRAY_TYPE);
01163 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
01164
01165 fn = _free(fn);
01166
01167
01168 return h;
01169 }
01170
01171
01172 rpmfi rpmfiFree(rpmfi fi)
01173 {
01174 HFD_t hfd = headerFreeData;
01175
01176 if (fi == NULL) return NULL;
01177
01178 if (fi->nrefs > 1)
01179 return rpmfiUnlink(fi, fi->Type);
01180
01181
01182 if (_rpmfi_debug < 0)
01183 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
01184
01185
01186
01187 fi->pretrans = _free(fi->pretrans);
01188 fi->pretransprog = _free(fi->pretransprog);
01189 fi->posttrans = _free(fi->posttrans);
01190 fi->posttransprog = _free(fi->posttransprog);
01191
01192
01193 if (fi->fc > 0) {
01194 fi->bnl = hfd(fi->bnl, -1);
01195 fi->dnl = hfd(fi->dnl, -1);
01196
01197 fi->flinks = hfd(fi->flinks, -1);
01198 fi->flangs = hfd(fi->flangs, -1);
01199 fi->fdigests = hfd(fi->fdigests, -1);
01200 fi->digests = _free(fi->digests);
01201
01202 fi->cdict = hfd(fi->cdict, -1);
01203
01204 fi->fuser = hfd(fi->fuser, -1);
01205 fi->fgroup = hfd(fi->fgroup, -1);
01206
01207 fi->fstates = _free(fi->fstates);
01208
01209
01210 if (!fi->keep_header && fi->h == NULL) {
01211 fi->fmtimes = _free(fi->fmtimes);
01212 fi->fmodes = _free(fi->fmodes);
01213 fi->fflags = _free(fi->fflags);
01214 fi->vflags = _free(fi->vflags);
01215 fi->fsizes = _free(fi->fsizes);
01216 fi->frdevs = _free(fi->frdevs);
01217 fi->finodes = _free(fi->finodes);
01218 fi->dil = _free(fi->dil);
01219
01220 fi->fcolors = _free(fi->fcolors);
01221 fi->fcdictx = _free(fi->fcdictx);
01222 fi->ddict = _free(fi->ddict);
01223 fi->fddictx = _free(fi->fddictx);
01224 fi->fddictn = _free(fi->fddictn);
01225
01226 }
01227
01228 }
01229
01230
01231 fi->fsm = freeFSM(fi->fsm);
01232
01233 fi->fn = _free(fi->fn);
01234 fi->apath = _free(fi->apath);
01235 fi->fmapflags = _free(fi->fmapflags);
01236
01237 fi->obnl = hfd(fi->obnl, -1);
01238 fi->odnl = hfd(fi->odnl, -1);
01239
01240 fi->fcontexts = hfd(fi->fcontexts, -1);
01241
01242 fi->actions = _free(fi->actions);
01243 fi->replacedSizes = _free(fi->replacedSizes);
01244 fi->replaced = _free(fi->replaced);
01245
01246 fi->h = headerFree(fi->h);
01247
01248
01249 (void) rpmfiUnlink(fi, fi->Type);
01250 memset(fi, 0, sizeof(*fi));
01251 fi = _free(fi);
01252
01253
01254 return NULL;
01255 }
01256
01262 static inline unsigned char nibble(char c)
01263
01264 {
01265 if (c >= '0' && c <= '9')
01266 return (c - '0');
01267 if (c >= 'A' && c <= 'F')
01268 return (c - 'A') + 10;
01269 if (c >= 'a' && c <= 'f')
01270 return (c - 'a') + 10;
01271 return 0;
01272 }
01273
01274 #define _fdupe(_fi, _data) \
01275 if ((_fi)->_data != NULL) \
01276 (_fi)->_data = memcpy(xmalloc((_fi)->fc * sizeof(*(_fi)->_data)), \
01277 (_fi)->_data, (_fi)->fc * sizeof(*(_fi)->_data))
01278
01279
01280 #define _fdupestring(_h, _tag, _data) \
01281 if (hge((_h), (_tag), NULL, (void **) &(_data), NULL)) \
01282 _data = xstrdup(_data)
01283
01284 rpmfi rpmfiNew(const rpmts ts, Header h, rpmTag tagN, int flags)
01285 {
01286 HFD_t hfd = headerFreeData;
01287 int scareMem = (flags & 0x1);
01288 HGE_t hge =
01289 (scareMem ? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry);
01290 rpmte p;
01291 rpmfi fi = NULL;
01292 const char * Type;
01293 uint_32 * uip;
01294 int dnlmax, bnlmax;
01295 unsigned char * t;
01296 int len;
01297 int xx;
01298 int i;
01299
01300 #ifdef NOTYET
01301 assert(scareMem == 0);
01302 #endif
01303 if (tagN == RPMTAG_BASENAMES) {
01304 Type = "Files";
01305 } else {
01306 Type = "?Type?";
01307 goto exit;
01308 }
01309
01310 fi = xcalloc(1, sizeof(*fi));
01311 if (fi == NULL)
01312 goto exit;
01313
01314 fi->magic = RPMFIMAGIC;
01315 fi->Type = Type;
01316 fi->i = -1;
01317 fi->tagN = tagN;
01318
01319 fi->hge = hge;
01320 fi->hae = (HAE_t) headerAddEntry;
01321 fi->hme = (HME_t) headerModifyEntry;
01322 fi->hre = (HRE_t) headerRemoveEntry;
01323 fi->hfd = headerFreeData;
01324
01325 fi->h = (h != NULL && scareMem ? headerLink(h) : NULL);
01326
01327 if (fi->fsm == NULL)
01328 fi->fsm = newFSM();
01329
01330 fi->fsm->repackaged = (headerIsEntry(h, RPMTAG_REMOVETID) ? 1 : 0);
01331
01332
01333 xx = hge(h, RPMTAG_ARCHIVESIZE, NULL, (void **) &uip, NULL);
01334 fi->archivePos = 0;
01335 fi->archiveSize = (xx ? *uip : 0);
01336
01337
01338 _fdupestring(h, RPMTAG_PRETRANS, fi->pretrans);
01339 _fdupestring(h, RPMTAG_PRETRANSPROG, fi->pretransprog);
01340 _fdupestring(h, RPMTAG_POSTTRANS, fi->posttrans);
01341 _fdupestring(h, RPMTAG_POSTTRANSPROG, fi->posttransprog);
01342
01343 if (!hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc)) {
01344 fi->fc = 0;
01345 fi->dc = 0;
01346 goto exit;
01347 }
01348 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
01349 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
01350 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fi->fmodes, NULL);
01351 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fi->fflags, NULL);
01352 xx = hge(h, RPMTAG_FILEVERIFYFLAGS, NULL, (void **) &fi->vflags, NULL);
01353 xx = hge(h, RPMTAG_FILESIZES, NULL, (void **) &fi->fsizes, NULL);
01354
01355 xx = hge(h, RPMTAG_FILECOLORS, NULL, (void **) &fi->fcolors, NULL);
01356 fi->color = 0;
01357 if (fi->fcolors != NULL)
01358 for (i = 0; i < fi->fc; i++)
01359 fi->color |= fi->fcolors[i];
01360 xx = hge(h, RPMTAG_CLASSDICT, NULL, (void **) &fi->cdict, &fi->ncdict);
01361 xx = hge(h, RPMTAG_FILECLASS, NULL, (void **) &fi->fcdictx, NULL);
01362
01363 xx = hge(h, RPMTAG_DEPENDSDICT, NULL, (void **) &fi->ddict, &fi->nddict);
01364 xx = hge(h, RPMTAG_FILEDEPENDSX, NULL, (void **) &fi->fddictx, NULL);
01365 xx = hge(h, RPMTAG_FILEDEPENDSN, NULL, (void **) &fi->fddictn, NULL);
01366
01367 xx = hge(h, RPMTAG_FILESTATES, NULL, (void **) &fi->fstates, NULL);
01368 if (xx == 0 || fi->fstates == NULL)
01369 fi->fstates = xcalloc(fi->fc, sizeof(*fi->fstates));
01370 else
01371 _fdupe(fi, fstates);
01372
01373 fi->action = FA_UNKNOWN;
01374 fi->flags = 0;
01375
01376 if (fi->actions == NULL)
01377 fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
01378
01379 fi->keep_header = (scareMem ? 1 : 0);
01380
01381
01382 fi->mapflags =
01383 CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
01384
01385 xx = hge(h, RPMTAG_FILELINKTOS, NULL, (void **) &fi->flinks, NULL);
01386 xx = hge(h, RPMTAG_FILELANGS, NULL, (void **) &fi->flangs, NULL);
01387
01388 fi->digestalgo = PGPHASHALGO_MD5;
01389 fi->digestlen = 16;
01390 fi->fdigestalgos = NULL;
01391 xx = hge(h, RPMTAG_FILEDIGESTALGOS, NULL, (void **) &fi->fdigestalgos, NULL);
01392 if (fi->fdigestalgos) {
01393 int dalgo = 0;
01394
01395 for (i = 0; i < fi->fc; i++) {
01396 if (fi->fdigestalgos[i] == 0)
01397 continue;
01398 if (dalgo == 0)
01399 dalgo = fi->fdigestalgos[i];
01400 else
01401 assert(dalgo == fi->fdigestalgos[i]);
01402 }
01403 fi->digestalgo = dalgo;
01404 switch (dalgo) {
01405 case PGPHASHALGO_MD5: fi->digestlen = 128/8; break;
01406 case PGPHASHALGO_SHA1: fi->digestlen = 160/8; break;
01407 case PGPHASHALGO_RIPEMD128: fi->digestlen = 128/8; break;
01408 case PGPHASHALGO_RIPEMD160: fi->digestlen = 160/8; break;
01409 case PGPHASHALGO_SHA256: fi->digestlen = 256/8; break;
01410 case PGPHASHALGO_SHA384: fi->digestlen = 384/8; break;
01411 case PGPHASHALGO_SHA512: fi->digestlen = 512/8; break;
01412 case PGPHASHALGO_CRC32: fi->digestlen = 32/8; break;
01413 }
01414 fi->fdigestalgos = NULL;
01415 }
01416
01417 fi->fdigests = NULL;
01418 xx = hge(h, RPMTAG_FILEDIGESTS, NULL, (void **) &fi->fdigests, NULL);
01419
01420 fi->digests = NULL;
01421 if (fi->fdigests) {
01422 t = xmalloc(fi->fc * fi->digestlen);
01423 fi->digests = t;
01424 for (i = 0; i < fi->fc; i++) {
01425 const char * fdigests;
01426 int j;
01427
01428 fdigests = fi->fdigests[i];
01429 if (!(fdigests && *fdigests != '\0')) {
01430 memset(t, 0, fi->digestlen);
01431 t += fi->digestlen;
01432 continue;
01433 }
01434 for (j = 0; j < fi->digestlen; j++, t++, fdigests += 2)
01435 *t = (nibble(fdigests[0]) << 4) | nibble(fdigests[1]);
01436 }
01437 fi->fdigests = hfd(fi->fdigests, -1);
01438 }
01439
01440
01441 xx = hge(h, RPMTAG_FILEMTIMES, NULL, (void **) &fi->fmtimes, NULL);
01442 xx = hge(h, RPMTAG_FILERDEVS, NULL, (void **) &fi->frdevs, NULL);
01443 xx = hge(h, RPMTAG_FILEINODES, NULL, (void **) &fi->finodes, NULL);
01444 xx = hge(h, RPMTAG_FILECONTEXTS, NULL, (void **) &fi->fcontexts, NULL);
01445
01446 fi->replacedSizes = xcalloc(fi->fc, sizeof(*fi->replacedSizes));
01447
01448 xx = hge(h, RPMTAG_FILEUSERNAME, NULL, (void **) &fi->fuser, NULL);
01449 xx = hge(h, RPMTAG_FILEGROUPNAME, NULL, (void **) &fi->fgroup, NULL);
01450
01451 if (ts != NULL)
01452 if (fi != NULL)
01453 if ((p = rpmtsRelocateElement(ts)) != NULL && rpmteType(p) == TR_ADDED
01454 && headerIsEntry(h, RPMTAG_SOURCERPM)
01455 && !headerIsEntry(h, RPMTAG_ORIGBASENAMES))
01456 {
01457 const char * fmt = rpmGetPath("%{?_autorelocate_path}", NULL);
01458 const char * errstr;
01459 char * newPath;
01460 Header foo;
01461
01462
01463 newPath = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
01464 fmt = _free(fmt);
01465
01466 #if __ia64__
01467
01468 if (newPath != NULL && *newPath != '\0'
01469 && strlen(newPath) >= (sizeof("/emul/i386")-1)
01470 && newPath[0] == '/' && newPath[1] == 'e' && newPath[2] == 'm'
01471 && newPath[3] == 'u' && newPath[4] == 'l' && newPath[5] == '/'
01472 && newPath[6] == 'i' && newPath[8] == '8' && newPath[9] == '6')
01473 {
01474 newPath[7] = 'a';
01475 newPath[8] = '3';
01476 newPath[9] = '2';
01477 }
01478 #endif
01479
01480
01481 i = p->nrelocs;
01482 if (newPath != NULL && *newPath != '\0' && p->relocs != NULL)
01483 for (i = 0; i < p->nrelocs; i++) {
01484
01485 if (strcmp(p->relocs[i].oldPath, "/"))
01486 continue;
01487 if (strcmp(p->relocs[i].newPath, newPath))
01488 continue;
01489
01490 break;
01491 }
01492
01493
01494
01495 if (newPath != NULL && *newPath != '\0' && i == p->nrelocs) {
01496
01497 p->relocs =
01498 xrealloc(p->relocs, (p->nrelocs + 2) * sizeof(*p->relocs));
01499 p->relocs[p->nrelocs].oldPath = xstrdup("/");
01500 p->relocs[p->nrelocs].newPath = xstrdup(newPath);
01501 p->autorelocatex = p->nrelocs;
01502 p->nrelocs++;
01503 p->relocs[p->nrelocs].oldPath = NULL;
01504 p->relocs[p->nrelocs].newPath = NULL;
01505 }
01506 newPath = _free(newPath);
01507
01508
01509 if (fi->actions == NULL)
01510 fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
01511
01512 foo = relocateFileList(ts, fi, h, fi->actions);
01513
01514 fi->h = headerFree(fi->h);
01515 fi->h = headerLink(foo);
01516 foo = headerFree(foo);
01517 }
01518
01519 if (!scareMem) {
01520 _fdupe(fi, fmtimes);
01521 _fdupe(fi, frdevs);
01522 _fdupe(fi, finodes);
01523 _fdupe(fi, fsizes);
01524 _fdupe(fi, fflags);
01525 _fdupe(fi, vflags);
01526 _fdupe(fi, fmodes);
01527 _fdupe(fi, dil);
01528
01529 _fdupe(fi, fcolors);
01530 _fdupe(fi, fcdictx);
01531
01532 if (fi->ddict != NULL)
01533 fi->ddict = memcpy(xmalloc(fi->nddict * sizeof(*fi->ddict)),
01534 fi->ddict, fi->nddict * sizeof(*fi->ddict));
01535
01536 _fdupe(fi, fddictx);
01537 _fdupe(fi, fddictn);
01538
01539 fi->h = headerFree(fi->h);
01540 }
01541
01542 dnlmax = -1;
01543 for (i = 0; i < fi->dc; i++) {
01544 if ((len = strlen(fi->dnl[i])) > dnlmax)
01545 dnlmax = len;
01546 }
01547 bnlmax = -1;
01548 for (i = 0; i < fi->fc; i++) {
01549 if ((len = strlen(fi->bnl[i])) > bnlmax)
01550 bnlmax = len;
01551 }
01552 fi->fnlen = dnlmax + bnlmax + 1;
01553 fi->fn = NULL;
01554
01555 fi->dperms = 0755;
01556 fi->fperms = 0644;
01557
01558 exit:
01559
01560 if (_rpmfi_debug < 0)
01561 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, Type, (fi ? fi->fc : 0));
01562
01563
01564
01565 return rpmfiLink(fi, (fi ? fi->Type : NULL));
01566
01567 }
01568
01569 void rpmfiBuildFClasses(Header h,
01570 const char *** fclassp, int * fcp)
01571 {
01572 int scareMem = 0;
01573 rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
01574 const char * FClass;
01575 const char ** av;
01576 int ac;
01577 size_t nb;
01578 char * t;
01579
01580 if ((ac = rpmfiFC(fi)) <= 0) {
01581 av = NULL;
01582 ac = 0;
01583 goto exit;
01584 }
01585
01586
01587 nb = (ac + 1) * sizeof(*av);
01588 fi = rpmfiInit(fi, 0);
01589 if (fi != NULL)
01590 while (rpmfiNext(fi) >= 0) {
01591 FClass = rpmfiFClass(fi);
01592 if (FClass && *FClass != '\0')
01593 nb += strlen(FClass);
01594 nb += 1;
01595 }
01596
01597
01598 av = xmalloc(nb);
01599 t = ((char *) av) + ((ac + 1) * sizeof(*av));
01600 ac = 0;
01601 fi = rpmfiInit(fi, 0);
01602 if (fi != NULL)
01603 while (rpmfiNext(fi) >= 0) {
01604 FClass = rpmfiFClass(fi);
01605 av[ac++] = t;
01606 if (FClass && *FClass != '\0')
01607 t = stpcpy(t, FClass);
01608 *t++ = '\0';
01609 }
01610 av[ac] = NULL;
01611
01612
01613 exit:
01614 fi = rpmfiFree(fi);
01615
01616 if (fclassp)
01617 *fclassp = av;
01618 else
01619 av = _free(av);
01620
01621 if (fcp) *fcp = ac;
01622 }
01623
01624 void rpmfiBuildFContexts(Header h,
01625 const char *** fcontextp, int * fcp)
01626 {
01627 int scareMem = 0;
01628 rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
01629 const char * fcontext;
01630 const char ** av;
01631 int ac;
01632 size_t nb;
01633 char * t;
01634
01635 if ((ac = rpmfiFC(fi)) <= 0) {
01636 av = NULL;
01637 ac = 0;
01638 goto exit;
01639 }
01640
01641
01642 nb = (ac + 1) * sizeof(*av);
01643 fi = rpmfiInit(fi, 0);
01644 if (fi != NULL)
01645 while (rpmfiNext(fi) >= 0) {
01646 fcontext = rpmfiFContext(fi);
01647 if (fcontext && *fcontext != '\0')
01648 nb += strlen(fcontext);
01649 nb += 1;
01650 }
01651
01652
01653 av = xmalloc(nb);
01654 t = ((char *) av) + ((ac + 1) * sizeof(*av));
01655 ac = 0;
01656 fi = rpmfiInit(fi, 0);
01657 if (fi != NULL)
01658 while (rpmfiNext(fi) >= 0) {
01659 fcontext = rpmfiFContext(fi);
01660 av[ac++] = t;
01661 if (fcontext && *fcontext != '\0')
01662 t = stpcpy(t, fcontext);
01663 *t++ = '\0';
01664 }
01665 av[ac] = NULL;
01666
01667
01668 exit:
01669 fi = rpmfiFree(fi);
01670
01671 if (fcontextp)
01672 *fcontextp = av;
01673 else
01674 av = _free(av);
01675
01676 if (fcp) *fcp = ac;
01677 }
01678
01679 void rpmfiBuildFSContexts(Header h,
01680 const char *** fcontextp, int * fcp)
01681 {
01682 int scareMem = 0;
01683 rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
01684 const char ** av;
01685 int ac;
01686 size_t nb;
01687 char * t;
01688 char * fctxt = NULL;
01689 size_t fctxtlen = 0;
01690 int * fcnb;
01691
01692 if ((ac = rpmfiFC(fi)) <= 0) {
01693 av = NULL;
01694 ac = 0;
01695 goto exit;
01696 }
01697
01698
01699 nb = ac * sizeof(*fcnb);
01700 fcnb = memset(alloca(nb), 0, nb);
01701 ac = 0;
01702 fi = rpmfiInit(fi, 0);
01703 if (fi != NULL)
01704 while (rpmfiNext(fi) >= 0) {
01705 const char * fn = rpmfiFN(fi);
01706 security_context_t scon;
01707
01708 fcnb[ac] = lgetfilecon(fn, &scon);
01709
01710 if (fcnb[ac] > 0) {
01711 fctxt = xrealloc(fctxt, fctxtlen + fcnb[ac]);
01712 memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
01713 fctxtlen += fcnb[ac];
01714 freecon(scon);
01715 }
01716
01717 ac++;
01718 }
01719
01720
01721 nb = (ac + 1) * sizeof(*av) + fctxtlen;
01722 av = xmalloc(nb);
01723 t = ((char *) av) + ((ac + 1) * sizeof(*av));
01724 if (fctxt != NULL && fctxtlen > 0)
01725 (void) memcpy(t, fctxt, fctxtlen);
01726 ac = 0;
01727 fi = rpmfiInit(fi, 0);
01728 if (fi != NULL)
01729 while (rpmfiNext(fi) >= 0) {
01730 av[ac] = "";
01731 if (fcnb[ac] > 0) {
01732 av[ac] = t;
01733 t += fcnb[ac];
01734 }
01735 ac++;
01736 }
01737 av[ac] = NULL;
01738
01739 exit:
01740 fi = rpmfiFree(fi);
01741
01742 if (fcontextp)
01743 *fcontextp = av;
01744 else
01745 av = _free(av);
01746
01747 if (fcp) *fcp = ac;
01748 }
01749
01750 void rpmfiBuildREContexts(Header h,
01751 const char *** fcontextp, int * fcp)
01752 {
01753 int scareMem = 0;
01754 rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
01755 rpmsx sx = NULL;
01756 const char ** av = NULL;
01757 int ac;
01758 size_t nb;
01759 char * t;
01760 char * fctxt = NULL;
01761 size_t fctxtlen = 0;
01762 int * fcnb;
01763
01764 if ((ac = rpmfiFC(fi)) <= 0) {
01765 ac = 0;
01766 goto exit;
01767 }
01768
01769
01770 sx = rpmsxNew(NULL);
01771
01772
01773 nb = ac * sizeof(*fcnb);
01774 fcnb = memset(alloca(nb), 0, nb);
01775 ac = 0;
01776 fi = rpmfiInit(fi, 0);
01777 if (fi != NULL)
01778 while (rpmfiNext(fi) >= 0) {
01779 const char * fn = rpmfiFN(fi);
01780 mode_t fmode = rpmfiFMode(fi);
01781 const char * scon;
01782
01783 scon = rpmsxFContext(sx, fn, fmode);
01784 if (scon != NULL) {
01785 fcnb[ac] = strlen(scon) + 1;
01786
01787 if (fcnb[ac] > 0) {
01788 fctxt = xrealloc(fctxt, fctxtlen + fcnb[ac]);
01789 memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
01790 fctxtlen += fcnb[ac];
01791 }
01792
01793 }
01794 ac++;
01795 }
01796
01797
01798 nb = (ac + 1) * sizeof(*av) + fctxtlen;
01799 av = xmalloc(nb);
01800 t = ((char *) av) + ((ac + 1) * sizeof(*av));
01801 (void) memcpy(t, fctxt, fctxtlen);
01802 ac = 0;
01803 fi = rpmfiInit(fi, 0);
01804 if (fi != NULL)
01805 while (rpmfiNext(fi) >= 0) {
01806 av[ac] = "";
01807 if (fcnb[ac] > 0) {
01808 av[ac] = t;
01809 t += fcnb[ac];
01810 }
01811 ac++;
01812 }
01813 av[ac] = NULL;
01814
01815 exit:
01816 fi = rpmfiFree(fi);
01817 sx = rpmsxFree(sx);
01818
01819 if (fcontextp)
01820 *fcontextp = av;
01821 else
01822 av = _free(av);
01823
01824 if (fcp) *fcp = ac;
01825 }
01826
01827 void rpmfiBuildFDeps(Header h, rpmTag tagN,
01828 const char *** fdepsp, int * fcp)
01829 {
01830 int scareMem = 0;
01831 rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
01832 rpmds ds = NULL;
01833 const char ** av;
01834 int ac;
01835 size_t nb;
01836 char * t;
01837 char deptype = 'R';
01838 char mydt;
01839 const char * DNEVR;
01840 const uint_32 * ddict;
01841 unsigned ix;
01842 int ndx;
01843
01844 if ((ac = rpmfiFC(fi)) <= 0) {
01845 av = NULL;
01846 ac = 0;
01847 goto exit;
01848 }
01849
01850 if (tagN == RPMTAG_PROVIDENAME)
01851 deptype = 'P';
01852 else if (tagN == RPMTAG_REQUIRENAME)
01853 deptype = 'R';
01854
01855 ds = rpmdsNew(h, tagN, scareMem);
01856
01857
01858 nb = (ac + 1) * sizeof(*av);
01859 fi = rpmfiInit(fi, 0);
01860 if (fi != NULL)
01861 while (rpmfiNext(fi) >= 0) {
01862 ddict = NULL;
01863 ndx = rpmfiFDepends(fi, &ddict);
01864 if (ddict != NULL)
01865 while (ndx-- > 0) {
01866 ix = *ddict++;
01867 mydt = ((ix >> 24) & 0xff);
01868 if (mydt != deptype)
01869 continue;
01870 ix &= 0x00ffffff;
01871 (void) rpmdsSetIx(ds, ix-1);
01872 if (rpmdsNext(ds) < 0)
01873 continue;
01874 DNEVR = rpmdsDNEVR(ds);
01875 if (DNEVR != NULL)
01876 nb += strlen(DNEVR+2) + 1;
01877 }
01878 nb += 1;
01879 }
01880
01881
01882 av = xmalloc(nb);
01883 t = ((char *) av) + ((ac + 1) * sizeof(*av));
01884 ac = 0;
01885
01886 fi = rpmfiInit(fi, 0);
01887 if (fi != NULL)
01888 while (rpmfiNext(fi) >= 0) {
01889 av[ac++] = t;
01890 ddict = NULL;
01891 ndx = rpmfiFDepends(fi, &ddict);
01892 if (ddict != NULL)
01893 while (ndx-- > 0) {
01894 ix = *ddict++;
01895 mydt = ((ix >> 24) & 0xff);
01896 if (mydt != deptype)
01897 continue;
01898 ix &= 0x00ffffff;
01899 (void) rpmdsSetIx(ds, ix-1);
01900 if (rpmdsNext(ds) < 0)
01901 continue;
01902 DNEVR = rpmdsDNEVR(ds);
01903 if (DNEVR != NULL) {
01904 t = stpcpy(t, DNEVR+2);
01905 *t++ = ' ';
01906 *t = '\0';
01907 }
01908 }
01909 *t++ = '\0';
01910 }
01911
01912 av[ac] = NULL;
01913
01914 exit:
01915 fi = rpmfiFree(fi);
01916 ds = rpmdsFree(ds);
01917
01918 if (fdepsp)
01919 *fdepsp = av;
01920 else
01921 av = _free(av);
01922
01923 if (fcp) *fcp = ac;
01924 }