diff options
-rw-r--r-- | lib/fsm.c | 43 | ||||
-rw-r--r-- | lib/fsm.h | 2 |
2 files changed, 16 insertions, 29 deletions
@@ -597,7 +597,6 @@ static int fsmSetup(FSM_t fsm, fileStage goal, } fsm->cpioPos = 0; fsm->iter = mapInitIterator(ts, te, fi); - fsm->digestalgo = rpmfiDigestAlgo(fi); fsm->psm = psm; fsm->sehandle = rpmtsSELabelHandle(ts); @@ -753,18 +752,6 @@ static int fsmMapAttrs(FSM_t fsm) st->st_uid = uid; if (fsm->mapFlags & CPIO_MAP_GID) st->st_gid = gid; - - { rpmts ts = fsmGetTs(fsm); - - /* - * Set file digest (if not disabled). - */ - if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOFILEDIGEST)) { - fsm->digest = rpmfiFDigestIndex(fi, i, NULL, NULL); - } else { - fsm->digest = NULL; - } - } } return 0; } @@ -778,14 +765,22 @@ static int expandRegular(FSM_t fsm) { const struct stat * st = &fsm->sb; rpm_loff_t left = st->st_size; + const unsigned char * fidigest = NULL; + pgpHashAlgo digestalgo = 0; int rc = 0; rc = fsmNext(fsm, FSM_WOPEN); if (rc) goto exit; - if (st->st_size > 0 && fsm->digest != NULL) - fdInitDigest(fsm->wfd, fsm->digestalgo, 0); + if (!(rpmtsFlags(fsmGetTs(fsm)) & RPMTRANS_FLAG_NOFILEDIGEST)) { + rpmfi fi = fsmGetFi(fsm); + digestalgo = rpmfiDigestAlgo(fi); + fidigest = rpmfiFDigestIndex(fi, fsm->ix, NULL, NULL); + } + + if (st->st_size > 0 && fidigest) + fdInitDigest(fsm->wfd, digestalgo, 0); while (left) { @@ -805,26 +800,20 @@ static int expandRegular(FSM_t fsm) (void) fsmNext(fsm, FSM_NOTIFY); } - if (st->st_size > 0 && fsm->digest) { + if (st->st_size > 0 && fidigest) { void * digest = NULL; - int asAscii = (fsm->digest == NULL ? 1 : 0); (void) Fflush(fsm->wfd); - fdFiniDigest(fsm->wfd, fsm->digestalgo, &digest, NULL, asAscii); - - if (digest == NULL) { - rc = CPIOERR_DIGEST_MISMATCH; - goto exit; - } + fdFiniDigest(fsm->wfd, digestalgo, &digest, NULL, 0); - if (fsm->digest != NULL) { - size_t diglen = rpmDigestLength(fsm->digestalgo); - if (memcmp(digest, fsm->digest, diglen)) + if (digest != NULL && fidigest != NULL) { + size_t diglen = rpmDigestLength(digestalgo); + if (memcmp(digest, fidigest, diglen)) rc = CPIOERR_DIGEST_MISMATCH; } else { rc = CPIOERR_DIGEST_MISMATCH; } - digest = _free(digest); + free(digest); } exit: @@ -144,9 +144,7 @@ struct fsm_s { cpioMapFlags mapFlags; /*!< Bit(s) to control mapping. */ const char * dirName; /*!< File directory name. */ const char * baseName; /*!< File base name. */ - const unsigned char * digest; /*!< Binary digest (NULL disables). */ struct selabel_handle *sehandle; /*!< SELinux label handle (if any). */ - pgpHashAlgo digestalgo; /*!< File digest algorithm */ unsigned fflags; /*!< File flags. */ rpmFileAction action; /*!< File disposition. */ |