13 #define _RPMDIR_INTERNAL
18 #define _RPMAV_INTERNAL
24 #define _FPRINT_INTERNAL
27 #define _IOSM_INTERNAL
28 #define _RPMFI_INTERNAL
34 #define _RPMTE_INTERNAL
81 for (t = s + strlen(s) - 1; *t == c && t >= s; t--)
89 return (fi != NULL ? fi->fc : 0);
94 return (fi != NULL ? fi->dc : 0);
105 return (fi != NULL ? fi->i : -1);
112 if (fi != NULL && fx >= 0 && fx < (
int)fi->fc) {
115 fi->j = fi->dil[fi->i];
122 return (fi != NULL ? fi->j : -1);
129 if (fi != NULL && dx >= 0 && dx < (
int)fi->dc) {
138 return (fi != NULL ? fi->isSource : 0);
143 const char * BN = NULL;
145 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
154 const char * DN = NULL;
156 if (fi != NULL && fi->j >= 0 && fi->j < (
int)fi->dc) {
165 const char * FN =
"";
167 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
171 fi->fn = (
char *)
xmalloc(fi->fnlen + 1);
173 (void)
urlPath(fi->dnl[fi->dil[fi->i]], &dn);
176 t =
stpcpy(t, fi->bnl[fi->i]);
185 if (fi->_fnbf == NULL) {
186 char * fn = (
char *)
alloca(fi->fnlen + 1);
187 static double e = 1.0e-4;
188 size_t n = (fi->fc > 10 ? fi->fc : 10);
194 rpmbfParams(n, e, &m, &k);
195 bf = rpmbfNew(m, k, 0);
196 for (i = 0; i < (int)fi->fc; i++) {
200 (void)
urlPath(fi->dnl[fi->dil[i]], &dn);
202 xx = rpmbfAdd(bf, fn, (
size_t)(dn - fn));
214 return (fi ? fi->fnlen : 0);
221 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
222 if (fi->fflags != NULL)
223 FFlags = fi->fflags[fi->i];
232 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
233 if (fi->fflags != NULL && fi->h == NULL) {
234 oFFlags = fi->fflags[fi->i];
245 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
246 if (fi->vflags != NULL)
247 VFlags = fi->vflags[fi->i];
256 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
257 if (fi->vflags != NULL && fi->h == NULL) {
258 oVFlags = fi->vflags[fi->i];
269 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
270 if (fi->fmodes != NULL)
271 fmode = fi->fmodes[fi->i];
280 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
281 if (fi->fstates != NULL)
291 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
292 if (fi->fstates != NULL) {
293 ofstate = fi->fstates[fi->i];
294 fi->fstates[fi->i] = fstate;
302 unsigned char * digest = NULL;
304 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
305 if (fi->digests != NULL) {
306 digest = fi->digests + (fi->digestlen * fi->i);
308 *algop = (fi->fdigestalgos
309 ? fi->fdigestalgos[fi->i] : fi->digestalgo);
311 *lenp = fi->digestlen;
319 const char * flink = NULL;
321 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
322 if (fi->flinks != NULL)
323 flink = fi->flinks[fi->i];
332 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
333 if (fi->fsizes != NULL)
334 fsize = fi->fsizes[fi->i];
343 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
344 if (fi->frdevs != NULL)
345 frdev = fi->frdevs[fi->i];
354 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
355 if (fi->finodes != NULL)
356 finode = fi->finodes[fi->i];
367 color = fi->color & 0xf;
375 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
376 if (fi->fcolors != NULL)
378 fcolor = (fi->fcolors[fi->i] & 0x0f);
385 const char * fclass = NULL;
387 if (fi != NULL && fi->fcdictx != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
388 int cdictx = fi->fcdictx[fi->i];
389 if (fi->cdict != NULL && cdictx >= 0 && cdictx < (
int)fi->ncdict)
390 fclass = fi->cdict[cdictx];
397 const char * fcontext = NULL;
399 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
400 if (fi->fcontexts != NULL)
401 fcontext = fi->fcontexts[fi->i];
412 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
413 if (fi->fddictn != NULL)
414 fddictn = fi->fddictn[fi->i];
415 if (fddictn > 0 && fi->fddictx != NULL)
416 fddictx = fi->fddictx[fi->i];
417 if (fi->ddict != NULL && fddictx >= 0 && (fddictx+fddictn) <= (
int)fi->nddict)
418 fddict = fi->ddict + fddictx;
431 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
433 if (fi->finodes && fi->frdevs) {
438 for (j = 0; j < (int)fi->fc; j++) {
439 if (fi->frdevs[j] == frdev && fi->finodes[j] == finode)
451 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
452 if (fi->fmtimes != NULL)
453 fmtime = fi->fmtimes[fi->i];
460 const char * fuser = NULL;
463 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
464 if (fi->fuser != NULL)
465 fuser = fi->fuser[fi->i];
472 const char * fgroup = NULL;
475 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
476 if (fi->fgroup != NULL)
477 fgroup = fi->fgroup[fi->i];
485 return (fi != NULL ? fi->_fnbf : NULL);
491 return (fi != NULL ? fi->exclude : NULL);
496 return (fi != NULL ? fi->nexclude : 0);
501 return (fi != NULL ? fi->include : NULL);
506 return (fi != NULL ? fi->ninclude : 0);
512 if (fi != NULL && fi->fps != NULL && ix >= 0 && ix < (
int)fi->fc) {
520 if (fi->fc > 0 && fi->fps == NULL) {
523 fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fi->fc, fi->fps);
530 if (fi != NULL && ++fi->i >= 0) {
531 if (fi->i < (
int)fi->fc) {
534 fi->j = fi->dil[fi->i];
539 if (_rpmfi_debug < 0 && i != -1)
540 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] :
""));
551 if (fx >= 0 && fx < (
int)fi->fc) {
566 if (fi != NULL && ++fi->j >= 0) {
567 if (fi->j < (
int)fi->dc)
573 if (_rpmfi_debug < 0 && j != -1)
574 fprintf(stderr,
"*** fi %p\t%s[%d]\n", fi, (fi->Type ? fi->Type :
"?Type?"), j);
585 if (dx >= 0 && dx < (
int)fi->fc)
606 case XDIR:
return "directory";
607 case CDEV:
return "char dev";
608 case BDEV:
return "block dev";
609 case LINK:
return "link";
610 case SOCK:
return "sock";
611 case PIPE:
return "fifo/pipe";
612 case REG:
return "file";
613 default:
return "unknown file type";
626 if (S_ISDIR(mode))
return XDIR;
627 if (S_ISCHR(mode))
return CDEV;
628 if (S_ISBLK(mode))
return BDEV;
633 if (S_ISFIFO(mode))
return PIPE;
643 if (awhat != bwhat)
return 1;
648 if (alink == blink)
return 0;
649 if (alink == NULL)
return 1;
650 if (blink == NULL)
return -1;
651 return strcmp(alink, blink);
652 }
else if (awhat ==
REG) {
655 const unsigned char * adigest =
rpmfiDigest(afi, &aalgo, &alen);
658 const unsigned char * bdigest =
rpmfiDigest(bfi, &balgo, &blen);
660 if (!(aalgo == balgo && alen == blen))
662 if (adigest == bdigest)
return 0;
663 if (adigest == NULL)
return 1;
664 if (bdigest == NULL)
return -1;
665 return memcmp(adigest, bdigest, alen);
673 const char * fn =
rpmfiFN(nfi);
680 if (
Lstat(fn, &sb)) {
705 if (diskWhat != newWhat && dbWhat !=
REG && dbWhat !=
LINK)
707 else if (newWhat != dbWhat && diskWhat != dbWhat)
709 else if (dbWhat != newWhat)
711 else if (dbWhat !=
LINK && dbWhat !=
REG)
718 memset(buffer, 0,
sizeof(buffer));
722 const unsigned char * odigest;
725 const unsigned char * ndigest;
727 if (diskWhat ==
REG) {
729 if (
dodigest(oalgo, fn, (
unsigned char *)buffer, 0, NULL))
731 if (odigest && !memcmp(odigest, buffer, olen))
736 if (odigest && ndigest && oalgo == nalgo && olen == nlen
737 && !memcmp(odigest, ndigest, nlen))
741 const char * oFLink, * nFLink;
743 if (diskWhat ==
LINK) {
744 if (
Readlink(fn, buffer,
sizeof(buffer) - 1) == -1)
746 buffer[
sizeof(buffer)-1] =
'\0';
747 if (oFLink && !strcmp(oFLink, buffer))
752 if (oFLink && nFLink && !strcmp(oFLink, nFLink))
772 default:
return "???";
777 #define alloca_strdup(_s) strcpy((char *)alloca(strlen(_s)+1), (_s))
798 static int _printed = 0;
802 const char ** validRelocations;
805 const char ** baseNames;
806 const char ** dirNames;
817 size_t fileAlloced = 0;
819 int haveRelocatedFile = 0;
828 validRelocations = he->
p.
argv;
836 while (p->relocs[numRelocations].newPath ||
837 p->relocs[numRelocations].oldPath)
846 if (p->relocs == NULL || numRelocations == 0) {
851 he->
p.
argv = validRelocations;
855 validRelocations =
_free(validRelocations);
870 for (i = 0; i < numRelocations; i++) {
877 if (p->relocs[i].oldPath == NULL)
continue;
882 relocations[i].
oldPath = (t[0] ==
'/' && t[1] ==
'\0')
887 if (p->relocs[i].newPath) {
891 relocations[i].
newPath = (t[0] ==
'/' && t[1] ==
'\0')
897 for (j = 0; j < numValid; j++) {
898 if (!strcmp(validRelocations[j], relocations[i].oldPath))
903 if (j == numValid && !allowBadRelocate && actions) {
907 relocations[i].oldPath, NULL, NULL, 0);
911 (int)strlen(relocations[i].newPath) - (int)strlen(relocations[i].oldPath);
922 for (i = 0; i < numRelocations; i++) {
925 for (j = 1; j < numRelocations; j++) {
927 if (relocations[j - 1].
oldPath == NULL ||
928 relocations[j ].
oldPath == NULL ||
932 tmpReloc = relocations[j - 1];
933 relocations[j - 1] = relocations[j];
934 relocations[j] = tmpReloc;
938 if (!madeSwap)
break;
944 for (i = 0; i < numRelocations; i++) {
945 if (relocations[i].
oldPath == NULL)
continue;
946 if (relocations[i].
newPath == NULL)
951 i, relocations[i].oldPath, relocations[i].
newPath);
957 const char ** actualRelocations;
960 actualRelocations = (
const char **)
xmalloc(numValid *
sizeof(*actualRelocations));
962 for (i = 0; i < numValid; i++) {
963 for (j = 0; j < numRelocations; j++) {
964 if (relocations[j].
oldPath == NULL ||
965 strcmp(validRelocations[i], relocations[j].
oldPath))
969 actualRelocations[numActual] = relocations[j].
newPath;
974 if (j == numRelocations) {
975 actualRelocations[numActual] = validRelocations[i];
983 he->
p.
argv = actualRelocations;
988 actualRelocations =
_free(actualRelocations);
989 validRelocations =
_free(validRelocations);
994 baseNames = he->
p.
argv;
1001 dirNames = he->
p.
argv;
1014 memset(dColors, 0, dirCount *
sizeof(*dColors));
1024 for (i = fileCount - 1; i >= 0; i--) {
1029 strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
1030 if (len >= fileAlloced) {
1031 fileAlloced = len * 2;
1032 fn = (
char *)
xrealloc(fn, fileAlloced);
1037 fnlen =
stpcpy(
stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;
1039 if (fColors != NULL) {
1041 for (j = 0; j < (int)dirCount; j++) {
1042 if (strcmp(dirNames[dirIndexes[i]], dirNames[j]))
continue;
1043 dColors[j] |= fColors[i];
1054 for (j = numRelocations - 1; j >= 0; j--) {
1055 if (relocations[j].
oldPath == NULL)
1057 len = strcmp(relocations[j].
oldPath,
"/")
1058 ? strlen(relocations[j].oldPath)
1067 if (!(fn[len] ==
'/' || fnlen == len))
1070 if (strncmp(relocations[j].oldPath, fn, len))
1074 if (j < 0)
continue;
1081 if (relocations[j].
newPath == NULL) {
1084 for (j = dirIndexes[i]; j < (int)dirCount; j++) {
1085 len = strlen(dirNames[j]) - 1;
1086 while (len > 0 && dirNames[j][len-1] ==
'/') len--;
1089 if (strncmp(fn, dirNames[j], fnlen))
1103 if (fnlen != len)
continue;
1110 strcpy(fn, relocations[j].newPath);
1111 {
char * te = strrchr(fn,
'/');
1116 te = fn + strlen(fn);
1118 if (strcmp(baseNames[i], te))
1125 for (j = 0; j < (int)dirCount; j++) {
1126 if (fnlen != strlen(dirNames[j]))
1128 if (strncmp(fn, dirNames[j], fnlen))
1133 if (j < (
int)dirCount) {
1139 if (!haveRelocatedFile) {
1140 const char ** newDirList;
1142 haveRelocatedFile = 1;
1143 newDirList = (
const char **)
xmalloc((dirCount + 1) *
sizeof(*newDirList));
1144 for (j = 0; j < (int)dirCount; j++)
1146 dirNames =
_free(dirNames);
1147 dirNames = newDirList;
1149 dirNames = (
const char **)
xrealloc(dirNames,
1150 sizeof(*dirNames) * (dirCount + 1));
1154 dirIndexes[i] = dirCount;
1159 for (i = dirCount - 1; i >= 0; i--) {
1160 for (j = numRelocations - 1; j >= 0; j--) {
1163 if (j == p->autorelocatex
1164 && (dColors[i] == 0 || !(dColors[i] & mydColor)))
1167 if (relocations[j].
oldPath == NULL)
1169 len = strcmp(relocations[j].
oldPath,
"/")
1170 ? strlen(relocations[j].oldPath)
1173 if (len && strncmp(relocations[j].oldPath, dirNames[i], len))
1180 if (dirNames[i][len] !=
'/')
1184 const char * s = relocations[j].
newPath;
1185 size_t slen = strlen(s) + strlen(dirNames[i]) - len;
1186 char * t = (
char *)
alloca(slen + 1);
1198 D_(
"relocating directory %s to %s\n"), dirNames[i], t);
1227 he->
p.
argv = baseNames;
1230 fi->bnl =
_free(fi->bnl);
1233 fi->bnl = he->
p.
argv;
1239 he->
p.
argv = dirNames;
1242 fi->dnl =
_free(fi->dnl);
1244 fi->dnl = he->
p.
argv;
1249 he->
p.
ui32p = dirIndexes;
1252 fi->dil =
_free(fi->dil);
1259 baseNames =
_free(baseNames);
1260 dirIndexes =
_free(dirIndexes);
1261 dirNames =
_free(dirNames);
1262 fFlags =
_free(fFlags);
1263 fColors =
_free(fColors);
1264 fModes =
_free(fModes);
1293 fi->pretrans =
_free(fi->pretrans);
1294 fi->pretransprog =
_free(fi->pretransprog);
1295 fi->posttrans =
_free(fi->posttrans);
1296 fi->posttransprog =
_free(fi->posttransprog);
1297 fi->verifyscript =
_free(fi->verifyscript);
1298 fi->verifyscriptprog =
_free(fi->verifyscriptprog);
1301 fi->bnl =
_free(fi->bnl);
1302 fi->dnl =
_free(fi->dnl);
1304 fi->flinks =
_free(fi->flinks);
1305 fi->flangs =
_free(fi->flangs);
1306 fi->fdigests =
_free(fi->fdigests);
1307 fi->digests =
_free(fi->digests);
1309 fi->cdict =
_free(fi->cdict);
1311 fi->fuser =
_free(fi->fuser);
1312 fi->fgroup =
_free(fi->fgroup);
1314 fi->fstates =
_free(fi->fstates);
1316 fi->fmtimes =
_free(fi->fmtimes);
1317 fi->fmodes =
_free(fi->fmodes);
1318 fi->fflags =
_free(fi->fflags);
1319 fi->vflags =
_free(fi->vflags);
1320 fi->fsizes =
_free(fi->fsizes);
1321 fi->frdevs =
_free(fi->frdevs);
1322 fi->finodes =
_free(fi->finodes);
1323 fi->dil =
_free(fi->dil);
1325 fi->fcolors =
_free(fi->fcolors);
1326 fi->fcdictx =
_free(fi->fcdictx);
1327 fi->ddict =
_free(fi->ddict);
1328 fi->fddictx =
_free(fi->fddictx);
1329 fi->fddictn =
_free(fi->fddictn);
1336 fi->_fnbf = rpmbfFree((rpmbf)fi->_fnbf);
1340 fi->fn =
_free(fi->fn);
1341 fi->apath =
_free(fi->apath);
1342 fi->fmapflags =
_free(fi->fmapflags);
1344 fi->obnl =
_free(fi->obnl);
1345 fi->odnl =
_free(fi->odnl);
1347 fi->fcontexts =
_free(fi->fcontexts);
1349 fi->actions =
_free(fi->actions);
1350 fi->replacedSizes =
_free(fi->replacedSizes);
1365 if (_rpmfiPool == NULL) {
1366 _rpmfiPool =
rpmioNewPool(
"fi",
sizeof(*fi), -1, _rpmfi_debug,
1371 memset(((
char *)fi)+
sizeof(fi->_item), 0,
sizeof(*fi)-
sizeof(fi->_item));
1383 if (c >=
'0' && c <=
'9')
1385 if (c >=
'A' && c <=
'F')
1386 return (c -
'A') + 10;
1387 if (c >=
'a' && c <=
'f')
1388 return (c -
'a') + 10;
1392 #define _fdupestring(_h, _tag, _data) \
1394 xx = headerGet((_h), he, 0); \
1397 #define _fdupedata(_h, _tag, _cast, _data) \
1399 xx = headerGet((_h), he, 0); \
1400 _data = (_cast) he->p.ptr;
1408 int scareMem = (flags & 0x1);
1418 assert(scareMem == 0);
1430 fi->magic = RPMFIMAGIC;
1441 if (fi->fsm == NULL)
1450 fi->archiveSize = (xx && he->
p.
ui32p ? he->
p.
ui32p[0] : 0);
1464 if (xx == 0 && fi->isSource) {
1468 fi->bnl = he->
p.
argv;
1478 if (fi->dc == 0 && fi->isSource) {
1480 fi->dnl = (
const char **)
xcalloc(3,
sizeof(*fi->dnl));
1481 fi->dnl[0] = (
const char *)&fi->dnl[2];
1493 if (fi->fcolors != NULL)
1494 for (i = 0; i < (int)fi->fc; i++)
1495 fi->color |= fi->fcolors[i];
1506 if (xx == 0 || fi->fstates == NULL)
1512 if (fi->actions == NULL)
1513 fi->actions = (
int *)
xcalloc(fi->fc,
sizeof(*fi->actions));
1523 fi->fdigestalgos = NULL;
1525 if (fi->fdigestalgos) {
1527 for (i = 0; i < (int)fi->fc; i++) {
1528 if (fi->fdigestalgos[i] == 0)
1531 dalgo = (
pgpHashAlgo) (fi->fdigestalgos[i] & 0xff);
1533 assert(dalgo == (
pgpHashAlgo)fi->fdigestalgos[i]);
1535 fi->fdigestalgos =
_free(fi->fdigestalgos);
1559 fi->digestalgo = dalgo;
1564 t = (
unsigned char *)
xmalloc(fi->fc * fi->digestlen);
1566 for (i = 0; i < (int)fi->fc; i++) {
1567 const char * fdigests;
1570 fdigests = fi->fdigests[i];
1571 if (!(fdigests && *fdigests !=
'\0')) {
1572 memset(t, 0, fi->digestlen);
1576 for (j = 0; j < (int)fi->digestlen; j++, t++, fdigests += 2)
1579 fi->fdigests =
_free(fi->fdigests);
1599 const char * fmt =
rpmGetPath(
"%{?_autorelocate_path}", NULL);
1600 const char * errstr;
1610 if (newPath != NULL && *newPath !=
'\0' && p->relocs != NULL)
1611 for (i = 0; i < p->nrelocs; i++) {
1613 if (strcmp(p->relocs[i].oldPath,
"/"))
1615 if (strcmp(p->relocs[i].newPath, newPath))
1623 if (newPath != NULL && *newPath !=
'\0' && i == p->nrelocs) {
1627 p->relocs[p->nrelocs].oldPath =
xstrdup(
"/");
1628 p->relocs[p->nrelocs].newPath =
xstrdup(newPath);
1629 p->autorelocatex = p->nrelocs;
1631 p->relocs[p->nrelocs].oldPath = NULL;
1632 p->relocs[p->nrelocs].newPath = NULL;
1634 newPath =
_free(newPath);
1637 if (fi->actions == NULL)
1638 fi->actions = (
int *)
xcalloc(fi->fc,
sizeof(*fi->actions));
1649 if (fi->isSource && fi->dc == 1 && *fi->dnl[0] ==
'\0') {
1650 const char ** av = (
const char **)
xcalloc(4+1,
sizeof(*av));
1663 fi->dnl =
_free(fi->dnl);
1665 nb = fi->dc *
sizeof(*av);
1666 for (i = 0; i < (int)fi->dc; i++)
1667 nb += strlen(av[i]) +
sizeof(
"/");
1669 fi->dnl = (
const char **)
xmalloc(nb);
1670 te = (
char *) (&fi->dnl[fi->dc]);
1672 for (i = 0; i < (int)fi->dc; i++) {
1680 for (i = 0; i < (int)fi->fc; i++) {
1690 const char * b = fi->bnl[i];
1691 const char * be = b + strlen(b) -
sizeof(
".spec") - 1;
1693 fi->dil[i] = (be > b && !strcmp(be,
".spec") ? 1 : 0);
1704 for (i = 0; i < (int)fi->fc; i++) {
1705 size_t fnlen = strlen(fi->dnl[fi->dil[i]]) + strlen(fi->bnl[i]);
1707 if (fnlen > fi->fnlen)
1716 if (_rpmfi_debug < 0)
1717 fprintf(stderr,
"*** fi %p\t%s[%d]\n", fi, Type, (fi ? fi->fc : 0));
1721 return rpmfiLink(fi, (fi ? fi->Type : NULL));
1732 (*relp)[*nrelp].oldPath = (oldPath ?
xstrdup(oldPath) : NULL);
1733 (*relp)[*nrelp].newPath = (newPath ?
xstrdup(newPath) : NULL);
1746 relocs =
_free(relocs);
1772 *nrelocsp = nrelocs;
1780 if (st != NULL && fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
1781 memset(st, 0,
sizeof(*st));
1783 st->st_rdev = fi->frdevs[fi->i];
1784 st->st_ino = fi->finodes[fi->i];
1785 st->st_mode = fi->fmodes[fi->i];
1786 st->st_nlink =
rpmfiFNlink(fi) + (int)S_ISDIR(st->st_mode);
1787 if (
unameToUid(fi->fuser[fi->i], &st->st_uid) == -1)
1789 if (
gnameToGid(fi->fgroup[fi->i], &st->st_gid) == -1)
1791 st->st_size = fi->fsizes[fi->i];
1792 st->st_blksize = 4 * 1024;
1793 st->st_blocks = (st->st_size + (st->st_blksize - 1)) / st->st_blksize;
1796 st->st_mtime = fi->fmtimes[fi->i];
1805 size_t pathlen = strlen(path);
1809 while (pathlen > 0 && path[pathlen-1] ==
'/')
1813 if (!(fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc))
1817 const char * fn =
rpmfiFN(fi);
1818 size_t fnlen = strlen(fn);
1820 if (pathlen != fnlen || strncmp(path, fn, fnlen))
1828 fprintf(stderr,
"*** rpmfiStat(%p, %s, %p) rc %d\n", fi, path, st, rc);
1836 const char * dn =
name;
1837 size_t dnlen = strlen(dn);
1838 const char ** fnames = NULL;
1850 const char * fn =
rpmfiFN(fi);
1851 size_t fnlen = strlen(fn);
1855 if (strncmp(dn, fn, dnlen) || fn[dnlen] !=
'/')
1860 xx =
argvAdd(&fnames, fn + dnlen + 1);
1861 fmodes[j++] = fi->fmodes[i];
1865 dir = (DIR *) avOpendir(name, fnames, fmodes);
1868 fmodes =
_free(fmodes);
1872 fprintf(stderr,
"*** rpmfiOpendir(%p, %s) dir %p\n", fi, name, dir);
1883 const char * FClass;
1889 if ((ac =
rpmfiFC(fi)) <= 0) {
1896 nb = (ac + 1) *
sizeof(*av);
1901 if (FClass && *FClass !=
'\0')
1902 nb += strlen(FClass);
1907 av = (
const char **)
xmalloc(nb);
1908 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
1915 if (FClass && *FClass !=
'\0')
1931 void rpmfiBuildFContexts(
Header h,
1936 const char * fcontext;
1942 if ((ac =
rpmfiFC(fi)) <= 0) {
1949 nb = (ac + 1) *
sizeof(*av);
1954 if (fcontext && *fcontext !=
'\0')
1955 nb += strlen(fcontext);
1960 av = (
const char **)
xmalloc(nb);
1961 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
1968 if (fcontext && *fcontext !=
'\0')
1983 void rpmfiBuildFSContexts(
Header h,
1992 char * fctxt = NULL;
1993 size_t fctxtlen = 0;
1996 if ((ac =
rpmfiFC(fi)) <= 0) {
2003 nb = ac *
sizeof(*fcnb);
2004 fcnb = memset(
alloca(nb), 0, nb);
2010 security_context_t scon = NULL;
2013 fcnb[ac] = lgetfilecon(fn, &scon);
2015 fctxt = (
char *)
xrealloc(fctxt, fctxtlen + fcnb[ac]);
2016 memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
2017 fctxtlen += fcnb[ac];
2024 nb = (ac + 1) *
sizeof(*av) + fctxtlen;
2025 av = (
const char **)
xmalloc(nb);
2026 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
2027 if (fctxt != NULL && fctxtlen > 0)
2028 (void) memcpy(t, fctxt, fctxtlen);
2051 void rpmfiBuildREContexts(
Header h,
2056 const char ** av = NULL;
2060 char * fctxt = NULL;
2061 size_t fctxtlen = 0;
2064 if ((ac =
rpmfiFC(fi)) <= 0) {
2070 {
const char *fn =
rpmGetPath(
"%{?__file_context_path}", NULL);
2072 if (fn != NULL && *fn !=
'\0')
2073 (void)matchpathcon_init(fn);
2079 nb = ac *
sizeof(*fcnb);
2080 fcnb = memset(
alloca(nb), 0, nb);
2087 security_context_t scon;
2093 if (matchpathcon(fn, fmode, &scon) == 0 && scon != NULL) {
2094 fcnb[ac] = strlen(scon) + 1;
2096 fctxt = (
char *)
xrealloc(fctxt, fctxtlen + fcnb[ac]);
2097 memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
2098 fctxtlen += fcnb[ac];
2107 nb = (ac + 1) *
sizeof(*av) + fctxtlen;
2108 av = (
const char **)
xmalloc(nb);
2109 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
2110 (void) memcpy(t, fctxt, fctxtlen);
2126 matchpathcon_fini();
2154 if ((ac =
rpmfiFC(fi)) <= 0) {
2168 nb = (ac + 1) *
sizeof(*av);
2177 mydt = ((ix >> 24) & 0xff);
2178 if (mydt != deptype)
2186 nb += strlen(DNEVR+2) + 1;
2192 av = (
const char **)
xmalloc(nb);
2193 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
2204 mydt = ((ix >> 24) & 0xff);
2205 if (mydt != deptype)
2212 if (DNEVR != NULL) {