diff --git a/build/files.c b/build/files.c index 2178587..ca3e4a9 100644 --- a/build/files.c +++ b/build/files.c @@ -1737,28 +1737,6 @@ static int addNewIDSymlink(ARGV_t *files, return rc; } -static int haveModinfo(Elf *elf) -{ - Elf_Scn * scn = NULL; - size_t shstrndx; - int have_modinfo = 0; - const char *sname; - - if (elf_getshdrstrndx(elf, &shstrndx) == 0) { - while ((scn = elf_nextscn(elf, scn)) != NULL) { - GElf_Shdr shdr_mem, *shdr = gelf_getshdr(scn, &shdr_mem); - if (shdr == NULL) - continue; - sname = elf_strptr(elf, shstrndx, shdr->sh_name); - if (sname && rstreq(sname, ".modinfo")) { - have_modinfo = 1; - break; - } - } - } - return have_modinfo; -} - static int generateBuildIDs(FileList fl, ARGV_t *files) { int rc = 0; @@ -1823,18 +1801,15 @@ static int generateBuildIDs(FileList fl, ARGV_t *files) int fd = open (flp->diskPath, O_RDONLY); if (fd >= 0) { /* Only real ELF files, that are ET_EXEC, ET_DYN or - kernel modules (ET_REL files with .modinfo section) + kernel modules (ET_REL files with names ending in .ko) should have build-ids. */ GElf_Ehdr ehdr; -#if HAVE_DWELF_ELF_BEGIN - Elf *elf = dwelf_elf_begin(fd); -#else Elf *elf = elf_begin (fd, ELF_C_READ, NULL); -#endif if (elf != NULL && elf_kind(elf) == ELF_K_ELF && gelf_getehdr(elf, &ehdr) != NULL && (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN - || (ehdr.e_type == ET_REL && haveModinfo(elf)))) { + || (ehdr.e_type == ET_REL + && rpmFileHasSuffix (flp->diskPath, ".ko")))) { const void *build_id; ssize_t len = dwelf_elf_gnu_build_id (elf, &build_id); /* len == -1 means error. Zero means no diff --git a/build/pack.c b/build/pack.c index c7c1d8f..1348b5f 100644 --- a/build/pack.c +++ b/build/pack.c @@ -281,36 +281,12 @@ exit: return rc; } -struct charInDepData { - char c; - int present; -}; - -static rpmRC charInDepCb(void *cbdata, rpmrichParseType type, - const char *n, int nl, const char *e, int el, rpmsenseFlags sense, - rpmrichOp op, char **emsg) { - struct charInDepData *data = cbdata; - if (memchr(e, data->c, el)) - data->present = 1; - - return RPMRC_OK; -} - -static int haveCharInDep(Package pkg, char c) +static int haveTildeDep(Package pkg) { - struct charInDepData data = {c, 0}; for (int i = 0; i < PACKAGE_NUM_DEPS; i++) { rpmds ds = rpmdsInit(pkg->dependencies[i]); while (rpmdsNext(ds) >= 0) { - if (rpmdsIsRich(ds)) { - const char *depstr = rpmdsN(ds); - rpmrichParse(&depstr, NULL, charInDepCb, &data); - } else { - const char *evr = rpmdsEVR(ds); - if (strchr(evr, c)) - data.present = 1; - } - if (data.present) + if (strchr(rpmdsEVR(ds), '~')) return 1; } } @@ -399,13 +375,9 @@ exit: static void finalizeDeps(Package pkg) { /* check if the package has a dependency with a '~' */ - if (haveCharInDep(pkg, '~')) + if (haveTildeDep(pkg)) (void) rpmlibNeedsFeature(pkg, "TildeInVersions", "4.10.0-1"); - /* check if the package has a dependency with a '^' */ - if (haveCharInDep(pkg, '^')) - (void) rpmlibNeedsFeature(pkg, "CaretInVersions", "4.15.0-1"); - /* check if the package has a rich dependency */ if (haveRichDep(pkg)) (void) rpmlibNeedsFeature(pkg, "RichDependencies", "4.12.0-1"); diff --git a/build/parsePreamble.c b/build/parsePreamble.c index c4145d2..a9bd5c3 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -22,6 +22,8 @@ #define SKIPWHITE(_x) {while (*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;} #define SKIPNONWHITE(_x){while (*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;} +#define WHITELIST_NAME ".-_+%{}" + /** */ static const rpmTagVal copyTagsDuringParse[] = { @@ -43,7 +45,6 @@ static const rpmTagVal copyTagsDuringParse[] = { RPMTAG_DISTTAG, RPMTAG_BUGURL, RPMTAG_GROUP, - RPMTAG_MODULARITYLABEL, 0 }; @@ -522,7 +523,6 @@ static struct optionalTag { { RPMTAG_DISTURL, "%{disturl}" }, { RPMTAG_DISTTAG, "%{disttag}" }, { RPMTAG_BUGURL, "%{bugurl}" }, - { RPMTAG_MODULARITYLABEL, "%{modularitylabel}"}, { -1, NULL } }; @@ -769,14 +769,13 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag, case RPMTAG_VERSION: case RPMTAG_RELEASE: SINGLE_TOKEN_ONLY; - if (rpmCharCheck(spec, field, WHITELIST_VERREL)) + if (rpmCharCheck(spec, field, "._+%{}~")) goto exit; headerPutString(pkg->header, tag, field); break; case RPMTAG_URL: case RPMTAG_DISTTAG: case RPMTAG_BUGURL: - case RPMTAG_MODULARITYLABEL: /* XXX TODO: validate format somehow */ case RPMTAG_VCS: SINGLE_TOKEN_ONLY; @@ -1016,7 +1015,6 @@ static struct PreambleRec_s const preambleList[] = { {RPMTAG_BUGURL, 0, 0, LEN_AND_STR("bugurl")}, {RPMTAG_ORDERNAME, 2, 0, LEN_AND_STR("orderwithrequires")}, {RPMTAG_REMOVEPATHPOSTFIXES,0, 0, LEN_AND_STR("removepathpostfixes")}, - {RPMTAG_MODULARITYLABEL, 0, 0, LEN_AND_STR("modularitylabel")}, {0, 0, 0, 0} }; diff --git a/build/parseReqs.c b/build/parseReqs.c index ea46331..705d4cb 100644 --- a/build/parseReqs.c +++ b/build/parseReqs.c @@ -57,7 +57,7 @@ static rpmRC checkDep(rpmSpec spec, char *N, char *EVR, char **emsg) rasprintf(emsg, _("Versioned file name not permitted")); return RPMRC_FAIL; } - if (rpmCharCheck(spec, EVR, WHITELIST_EVR)) + if (rpmCharCheck(spec, EVR, ".-_+:%{}~")) return RPMRC_FAIL; if (checkSep(EVR, '-', emsg) != RPMRC_OK || checkSep(EVR, ':', emsg) != RPMRC_OK || diff --git a/build/parseSpec.c b/build/parseSpec.c index 51f7ee2..606a0d8 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -517,7 +517,6 @@ static const rpmTagVal sourceTags[] = { RPMTAG_BUGURL, RPMTAG_HEADERI18NTABLE, RPMTAG_VCS, - RPMTAG_MODULARITYLABEL, 0 }; diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h index bcd05b4..439b7d3 100644 --- a/build/rpmbuild_internal.h +++ b/build/rpmbuild_internal.h @@ -17,10 +17,6 @@ #undef HTKEYTYPE #undef HTDATATYPE -#define WHITELIST_NAME ".-_+%{}" -#define WHITELIST_VERREL "._+%{}~^" -#define WHITELIST_EVR WHITELIST_VERREL "-:" - struct TriggerFileEntry { int index; char * fileName; diff --git a/configure.ac b/configure.ac index 9622a78..09af7c4 100644 --- a/configure.ac +++ b/configure.ac @@ -312,27 +312,6 @@ fi AC_SUBST(WITH_BEECRYPT_LIB) AC_SUBST(WITH_BEECRYPT_INCLUDE) - -#================= -# Check for audit library. -AC_ARG_WITH(audit, -AS_HELP_STRING([--with-audit],[log results using Linux Audit]), -with_audit=$withval, -with_audit=auto) - -WITH_AUDIT_LIB= -AS_IF([test "x$with_audit" != xno],[ - AC_SEARCH_LIBS([audit_open],[audit],[ - WITH_AUDIT_LIB="$ac_res" - AC_DEFINE(WITH_AUDIT, 1, [libaudit support]) - ], - [if test "x$with_audit" != xauto; then - AC_MSG_ERROR([missing audit library]) - fi - ]) -]) -AC_SUBST(WITH_AUDIT_LIB) - #================= # Check for OpenSSL library. # We need evp.h from OpenSSL. @@ -522,10 +501,6 @@ AS_IF([test "$WITH_LIBELF" = yes],[ # If possible we also want the strtab functions from elfutils 0.167. # But we can fall back on the (unsupported) ebl alternatives if not. AC_CHECK_LIB(dw, dwelf_strtab_init, [HAVE_LIBDW_STRTAB=yes]) - # whether libdw supports compressed ELF objects - AC_CHECK_LIB(dw, dwelf_elf_begin, [ - AC_DEFINE(HAVE_DWELF_ELF_BEGIN, 1, [Have dwelf_elf_begin?]) - ]) ]) ]) ]) @@ -825,7 +800,7 @@ esac], WITH_PYTHON_SUBPACKAGE=0 AS_IF([test "$enable_python" = yes],[ - AM_PATH_PYTHON([2.7],[ + AM_PATH_PYTHON([2.6],[ PKG_CHECK_MODULES([PYTHON], [python-${PYTHON_VERSION}], [WITH_PYTHON_SUBPACKAGE=1]) AC_SUBST(PYTHON_CFLAGS) AC_SUBST(PYTHON_LIB) diff --git a/doc/rpm.8 b/doc/rpm.8 index ecc4a36..42d617f 100644 --- a/doc/rpm.8 +++ b/doc/rpm.8 @@ -104,7 +104,7 @@ Scripts and triggers: [\fB--ignoresize\fR] [\fB--ignorearch\fR] [\fB--ignoreos\fR] [\fB--includedocs\fR] [\fB--justdb\fR] [\fB--nodeps\fR] [\fB--nodigest\fR] [\fB--noplugins\fR] - [\fB--nocaps\fR] [\fB--noorder\fR] [\fB--noverify\fR] + [\fB--nocaps\fR] [\fB--noorder\fR] [\fB--nosignature\fR] [\fB--noscripts\fR] [\fB--notriggers\fR] [\fB--oldpackage\fR] [\fB--percent\fR] [\fB--prefix \fINEWPATH\fB\fR] [\fB--relocate \fIOLDPATH\fB=\fINEWPATH\fB\fR] @@ -311,9 +311,6 @@ Don't set file capabilities. Don't reorder the packages for an install. The list of packages would normally be reordered to satisfy dependencies. .TP -\fB--noverify\fR -Don't perform verify package files prior to installation. -.TP \fB--noplugins\fR Do not load and execute plugins. .TP diff --git a/doc/rpmsign.8 b/doc/rpmsign.8 index d895a3b..80ffb6a 100644 --- a/doc/rpmsign.8 +++ b/doc/rpmsign.8 @@ -21,9 +21,6 @@ options generate and insert new signatures for each package existing signatures. There are two options for historical reasons, there is no difference in behavior currently. -To create a signature rpm needs to verify the package's checksum. As a result -packages with a MD5/SHA1 checksums cannot be signed in FIPS mode. - \fBrpm\fR \fB--delsign\fR \fB\fIPACKAGE_FILE\fB\fR\fI ...\fR .PP diff --git a/lib/Makefile.am b/lib/Makefile.am index c055962..baf3238 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -51,7 +51,6 @@ librpm_la_LIBADD = \ @WITH_POPT_LIB@ \ @WITH_CAP_LIB@ \ @WITH_ACL_LIB@ \ - @WITH_AUDIT_LIB@ \ @LIBINTL@ if WITH_LUA diff --git a/lib/depends.c b/lib/depends.c index 094864f..9f4db8f 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -121,8 +121,7 @@ static int removePackage(rpmts ts, Header h, rpmte depends) /* Filter out duplicate erasures. */ if (packageHashGetEntry(tsmem->removedPackages, dboffset, &pp, NULL, NULL)) { - if (depends) - rpmteSetDependsOn(pp[0], depends); + rpmteSetDependsOn(pp[0], depends); return 0; } diff --git a/lib/fprint.c b/lib/fprint.c index ab18919..b810e4d 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -488,7 +488,7 @@ void fpCachePopulate(fingerPrintCache fpc, rpmts ts, int fileCount) (void) rpmsqPoll(); if ((fi = rpmteFiles(p)) == NULL) - continue; + continue; /* XXX can't happen */ (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); rpmfilesFpLookup(fi, fpc); @@ -522,9 +522,6 @@ void fpCachePopulate(fingerPrintCache fpc, rpmts ts, int fileCount) while ((p = rpmtsiNext(pi, 0)) != NULL) { (void) rpmsqPoll(); - if ((fi = rpmteFiles(p)) == NULL) - continue; - fs = rpmteGetFileStates(p); fc = rpmfsFC(fs); (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); @@ -534,7 +531,6 @@ void fpCachePopulate(fingerPrintCache fpc, rpmts ts, int fileCount) fpLookupSubdir(symlinks, fpc, p, i); } (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); - rpmfilesFree(fi); } rpmtsiFree(pi); diff --git a/lib/fsm.c b/lib/fsm.c index 1279989..44b4e1d 100644 --- a/lib/fsm.c +++ b/lib/fsm.c @@ -894,12 +894,12 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files, action = rpmfsGetAction(fs, rpmfiFX(fi)); skip = XFA_SKIPPING(action); + suffix = S_ISDIR(rpmfiFMode(fi)) ? NULL : tid; if (action != FA_TOUCH) { - suffix = S_ISDIR(rpmfiFMode(fi)) ? NULL : tid; + fpath = fsmFsPath(fi, suffix); } else { - suffix = NULL; + fpath = fsmFsPath(fi, ""); } - fpath = fsmFsPath(fi, suffix); /* Remap file perms, owner, and group. */ rc = rpmfiStat(fi, 1, &sb); @@ -922,10 +922,6 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files, if (!skip) { int setmeta = 1; - /* When touching we don't need any of this... */ - if (action == FA_TOUCH) - goto touch; - /* Directories replacing something need early backup */ if (!suffix) { rc = fsmBackup(fi, action); @@ -934,7 +930,7 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files, if (!suffix) { rc = fsmVerify(fpath, fi); } else { - rc = RPMERR_ENOENT; + rc = (action == FA_TOUCH) ? 0 : RPMERR_ENOENT; } if (S_ISREG(sb.st_mode)) { @@ -970,14 +966,11 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files, if (!IS_DEV_LOG(fpath)) rc = RPMERR_UNKNOWN_FILETYPE; } - -touch: /* Set permissions, timestamps etc for non-hardlink entries */ if (!rc && setmeta) { rc = fsmSetmeta(fpath, fi, plugins, action, &sb, nofcaps); } } else if (firsthardlink >= 0 && rpmfiArchiveHasContent(fi)) { - /* On FA_TOUCH no hardlinks are created thus this is skipped. */ /* we skip the hard linked file containing the content */ /* write the content to the first used instead */ char *fn = rpmfilesFN(files, firsthardlink); @@ -990,7 +983,7 @@ touch: if (rc) { if (!skip) { /* XXX only erase if temp fn w suffix is in use */ - if (suffix) { + if (suffix && (action != FA_TOUCH)) { (void) fsmRemove(fpath, sb.st_mode); } errno = saveerrno; diff --git a/lib/header.c b/lib/header.c index 616c062..5b09f83 100644 --- a/lib/header.c +++ b/lib/header.c @@ -2016,7 +2016,7 @@ rpmRC hdrblobGet(hdrblob blob, uint32_t tag, rpmtd td) memset(&einfo, 0, sizeof(einfo)); rpmtdReset(td); - for (int i = 0; i < blob->il; i++, pe++) { + for (int i = 1; i < blob->il; i++, pe++) { if (pe->tag != ntag) continue; ei2h(pe, &einfo); diff --git a/lib/poptALL.c b/lib/poptALL.c index c48067a..f8fe230 100644 --- a/lib/poptALL.c +++ b/lib/poptALL.c @@ -137,10 +137,6 @@ static void rpmcliAllArgCallback( poptContext con, break; case POPT_DBPATH: rpmcliConfigured(); - if (arg && arg[0] != '/') { - fprintf(stderr, _("arguments to --dbpath must begin with '/'\n")); - exit(EXIT_FAILURE); - } rpmPushMacro(NULL, "_dbpath", NULL, arg, RMIL_CMDLINE); break; case POPT_SHOWVERSION: diff --git a/lib/query.c b/lib/query.c index 26cdecf..8c8299b 100644 --- a/lib/query.c +++ b/lib/query.c @@ -576,19 +576,16 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv) break; default: for (ARGV_const_t arg = argv; arg && *arg; arg++) { - int ecLocal; rpmdbMatchIterator mi = initQueryIterator(qva, ts, *arg); - ecLocal = rpmcliShowMatches(qva, ts, mi); + ec += rpmcliShowMatches(qva, ts, mi); if (mi == NULL && qva->qva_source == RPMQV_PACKAGE) { size_t l = strlen(*arg); if (l > 4 && !strcmp(*arg + l - 4, ".rpm")) { - char * const argFirst[2] = { arg[0], NULL }; - rpmgi gi = rpmgiNew(ts, giFlags, argFirst); - ecLocal = rpmgiShowMatches(qva, ts, gi); + rpmgi gi = rpmgiNew(ts, giFlags, argv); + ec += rpmgiShowMatches(qva, ts, gi); rpmgiFree(gi); } } - ec += ecLocal; rpmdbFreeIterator(mi); } break; diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index 3df456f..6bc6a61 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -187,11 +187,11 @@ rpmRC rpmpkgRead(struct rpmvs_s *vs, FD_t fd, /* Finalize header range */ rpmvsFiniRange(vs, RPMSIG_HEADER); - /* Fish interesting tags from the main header. This is a bit hacky... */ - rpmvsAppendTag(vs, blob, RPMTAG_PAYLOADDIGEST); + /* Unless disabled, read the payload, generating digest(s) on the fly. */ + if (!(rpmvsFlags(vs) & RPMVSF_NEEDPAYLOAD)) { + /* Fish interesting tags from the main header. This is a bit hacky... */ + rpmvsAppendTag(vs, blob, RPMTAG_PAYLOADDIGEST); - /* If needed and not explicitly disabled, read the payload as well. */ - if (rpmvsRange(vs) & RPMSIG_PAYLOAD) { /* Initialize digests ranging over the payload only */ rpmvsInitRange(vs, RPMSIG_PAYLOAD); diff --git a/lib/rpmds.c b/lib/rpmds.c index 6fa41e4..823c722 100644 --- a/lib/rpmds.c +++ b/lib/rpmds.c @@ -1272,9 +1272,6 @@ static const struct rpmlibProvides_s rpmlibProvides[] = { { "rpmlib(TildeInVersions)", "4.10.0-1", ( RPMSENSE_EQUAL), N_("dependency comparison supports versions with tilde.") }, - { "rpmlib(CaretInVersions)", "4.15.0-1", - ( RPMSENSE_EQUAL), - N_("dependency comparison supports versions with caret.") }, { "rpmlib(LargeFiles)", "4.12.0-1", ( RPMSENSE_EQUAL), N_("support files larger than 4GB") }, diff --git a/lib/rpmtag.h b/lib/rpmtag.h index 57b10a7..8c718b3 100644 --- a/lib/rpmtag.h +++ b/lib/rpmtag.h @@ -368,7 +368,6 @@ typedef enum rpmTag_e { RPMTAG_FILESIGNATURELENGTH = 5091, /* i */ RPMTAG_PAYLOADDIGEST = 5092, /* s[] */ RPMTAG_PAYLOADDIGESTALGO = 5093, /* i */ - RPMTAG_MODULARITYLABEL = 5096, /* s */ RPMTAG_FIRSTFREE_TAG /*!< internal */ } rpmTag; diff --git a/lib/rpmte.c b/lib/rpmte.c index 0f3c81d..d980a37 100644 --- a/lib/rpmte.c +++ b/lib/rpmte.c @@ -69,7 +69,6 @@ struct rpmte_s { int nrelocs; /*!< (TR_ADDED) No. of relocations. */ uint8_t *badrelocs; /*!< (TR_ADDED) Bad relocations (or NULL) */ FD_t fd; /*!< (TR_ADDED) Payload file descriptor. */ - int verified; /*!< (TR_ADDED) Verification status */ #define RPMTE_HAVE_PRETRANS (1 << 0) #define RPMTE_HAVE_POSTTRANS (1 << 1) @@ -697,7 +696,6 @@ static void appendProblem(rpmte te, rpmProblemType type, if (te->probs == NULL) te->probs = rpmpsCreate(); rpmpsAppendProblem(te->probs, p); - rpmteMarkFailed(te); } rpmProblemFree(p); } @@ -755,16 +753,6 @@ rpmfs rpmteGetFileStates(rpmte te) return te->fs; } -void rpmteSetVerified(rpmte te, int verified) -{ - te->verified = verified; -} - -int rpmteGetVerified(rpmte te) -{ - return te->verified; -} - int rpmteProcess(rpmte te, pkgGoal goal, int num) { /* Only install/erase resets pkg file info */ diff --git a/lib/rpmte_internal.h b/lib/rpmte_internal.h index 2895925..a5a991e 100644 --- a/lib/rpmte_internal.h +++ b/lib/rpmte_internal.h @@ -86,12 +86,6 @@ int rpmteHaveTransScript(rpmte te, rpmTagVal tag); /* XXX should be internal too but build code needs for now... */ rpmfs rpmteGetFileStates(rpmte te); -RPM_GNUC_INTERNAL -void rpmteSetVerified(rpmte te, int verified); - -RPM_GNUC_INTERNAL -int rpmteGetVerified(rpmte te); - /** \ingroup rpmte * Retrieve size in bytes of package header. * @param te transaction element diff --git a/lib/rpmtriggers.c b/lib/rpmtriggers.c index 0827af0..23a913d 100644 --- a/lib/rpmtriggers.c +++ b/lib/rpmtriggers.c @@ -154,7 +154,6 @@ void rpmtriggersPrepPostUnTransFileTrigs(rpmts ts, rpmte te) } } rpmdbFreeIterator(mi); - rpmfilesFree(files); } int runPostUnTransFileTrigs(rpmts ts) diff --git a/lib/rpmvercmp.c b/lib/rpmvercmp.c index 13857e1..b3d08fa 100644 --- a/lib/rpmvercmp.c +++ b/lib/rpmvercmp.c @@ -33,8 +33,8 @@ int rpmvercmp(const char * a, const char * b) /* loop through each version segment of str1 and str2 and compare them */ while (*one || *two) { - while (*one && !risalnum(*one) && *one != '~' && *one != '^') one++; - while (*two && !risalnum(*two) && *two != '~' && *two != '^') two++; + while (*one && !risalnum(*one) && *one != '~') one++; + while (*two && !risalnum(*two) && *two != '~') two++; /* handle the tilde separator, it sorts before everything else */ if (*one == '~' || *two == '~') { @@ -45,21 +45,6 @@ int rpmvercmp(const char * a, const char * b) continue; } - /* - * Handle caret separator. Concept is the same as tilde, - * except that if one of the strings ends (base version), - * the other is considered as higher version. - */ - if (*one == '^' || *two == '^') { - if (!*one) return -1; - if (!*two) return 1; - if (*one != '^') return 1; - if (*two != '^') return -1; - one++; - two++; - continue; - } - /* If we ran to the end of either, we are finished with the loop */ if (!(*one && *two)) break; diff --git a/lib/rpmvs.c b/lib/rpmvs.c index 0d475af..7b5b86f 100644 --- a/lib/rpmvs.c +++ b/lib/rpmvs.c @@ -388,26 +388,11 @@ void rpmvsFiniRange(struct rpmvs_s *sis, int range) if (sinfo->range == range && sinfo->rc == RPMRC_OK) { sinfo->ctx = rpmDigestBundleDupCtx(sis->bundle, sinfo->id); - /* Handle unsupported digests the same as disabled ones */ - if (sinfo->ctx == NULL) - sinfo->rc = RPMRC_NOTFOUND; rpmDigestBundleFinal(sis->bundle, sinfo->id, NULL, NULL, 0); } } } -int rpmvsRange(struct rpmvs_s *vs) -{ - int range = 0; - for (int i = 0; i < vs->nsigs; i++) { - if (rpmsinfoDisabled(&vs->sigs[i], vs->vsflags)) - continue; - range |= vs->sigs[i].range; - } - - return range; -} - static int sinfoCmp(const void *a, const void *b) { const struct rpmsinfo_s *sa = a; diff --git a/lib/rpmvs.h b/lib/rpmvs.h index 0258955..b27d9a6 100644 --- a/lib/rpmvs.h +++ b/lib/rpmvs.h @@ -48,29 +48,38 @@ typedef int (*rpmsinfoCb)(struct rpmsinfo_s *sinfo, void *cbdata); extern "C" { #endif +RPM_GNUC_INTERNAL const char *rpmsinfoDescr(struct rpmsinfo_s *sinfo); +RPM_GNUC_INTERNAL char *rpmsinfoMsg(struct rpmsinfo_s *sinfo); +RPM_GNUC_INTERNAL struct rpmvs_s *rpmvsCreate(int vfylevel, rpmVSFlags vsflags, rpmKeyring keyring); +RPM_GNUC_INTERNAL void rpmvsInit(struct rpmvs_s *vs, hdrblob blob, rpmDigestBundle bundle); +RPM_GNUC_INTERNAL rpmVSFlags rpmvsFlags(struct rpmvs_s *vs); +RPM_GNUC_INTERNAL struct rpmvs_s *rpmvsFree(struct rpmvs_s *sis); +RPM_GNUC_INTERNAL void rpmvsAppendTag(struct rpmvs_s *sis, hdrblob blob, rpmTagVal tag); +RPM_GNUC_INTERNAL void rpmvsInitRange(struct rpmvs_s *sis, int range); +RPM_GNUC_INTERNAL void rpmvsFiniRange(struct rpmvs_s *sis, int range); -int rpmvsRange(struct rpmvs_s *vs); - +RPM_GNUC_INTERNAL int rpmvsVerify(struct rpmvs_s *sis, int type, rpmsinfoCb cb, void *cbdata); +RPM_GNUC_INTERNAL rpmRC rpmpkgRead(struct rpmvs_s *vs, FD_t fd, hdrblob *sigblobp, hdrblob *blobp, char **emsg); diff --git a/lib/tagexts.c b/lib/tagexts.c index 2c0b179..f72ff60 100644 --- a/lib/tagexts.c +++ b/lib/tagexts.c @@ -535,6 +535,15 @@ static int filerequireTag(Header h, rpmtd td, headerGetFlags hgflags) return filedepTag(h, RPMTAG_REQUIRENAME, td, hgflags); } +/* I18N look aside diversions */ + +#if defined(ENABLE_NLS) +extern int _nl_msg_cat_cntr; /* XXX GNU gettext voodoo */ +#endif +static const char * const language = "LANGUAGE"; + +static const char * const _macro_i18ndomains = "%{?_i18ndomains}"; + /** * Retrieve i18n text. * @param h header @@ -545,30 +554,59 @@ static int filerequireTag(Header h, rpmtd td, headerGetFlags hgflags) */ static int i18nTag(Header h, rpmTag tag, rpmtd td, headerGetFlags hgflags) { - int rc = headerGet(h, tag, td, HEADERGET_ALLOC); + int rc; #if defined(ENABLE_NLS) - if (rc) { - static const char * const _macro_i18ndomains = "%{?_i18ndomains}"; - char *de, *dstring = rpmExpand(_macro_i18ndomains, NULL); - const char *domain; + char * dstring = rpmExpand(_macro_i18ndomains, NULL); - for (domain = dstring; domain != NULL; domain = de) { - const char *msgid = td->data; - const char *msg = NULL; + td->type = RPM_STRING_TYPE; + td->data = NULL; + td->count = 0; + + if (dstring && *dstring) { + char *domain, *de; + const char * langval; + char * msgkey; + const char * msgid; + rasprintf(&msgkey, "%s(%s)", headerGetString(h, RPMTAG_NAME), + rpmTagGetName(tag)); + + /* change to en_US for msgkey -> msgid resolution */ + langval = getenv(language); + (void) setenv(language, "en_US", 1); + ++_nl_msg_cat_cntr; + + msgid = NULL; + for (domain = dstring; domain != NULL; domain = de) { de = strchr(domain, ':'); if (de) *de++ = '\0'; - msg = dgettext(domain, td->data); - if (msg != msgid) { - free(td->data); - td->data = xstrdup(msg); - break; - } + msgid = dgettext(domain, msgkey); + if (msgid != msgkey) break; } - free(dstring); + + /* restore previous environment for msgid -> msgstr resolution */ + if (langval) + (void) setenv(language, langval, 1); + else + unsetenv(language); + ++_nl_msg_cat_cntr; + + if (domain && msgid) { + td->data = dgettext(domain, msgid); + td->data = xstrdup(td->data); /* XXX xstrdup has side effects. */ + td->count = 1; + td->flags = RPMTD_ALLOCED; + } + dstring = _free(dstring); + free(msgkey); + if (td->data) + return 1; } + + free(dstring); #endif + rc = headerGet(h, tag, td, HEADERGET_ALLOC); return rc; } diff --git a/lib/transaction.c b/lib/transaction.c index 2db74ef..e16fed5 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -7,10 +7,6 @@ #include #include -#if WITH_AUDIT -#include -#endif - #include /* rpmMachineScore, rpmReadPackageFile */ #include /* XXX for rpmExpand */ #include @@ -1199,17 +1195,12 @@ static rpm_loff_t countPkgs(rpmts ts, rpmElementTypes types) struct vfydata_s { char *msg; - int signature; int vfylevel; }; static int vfyCb(struct rpmsinfo_s *sinfo, void *cbdata) { struct vfydata_s *vd = cbdata; - - if (sinfo->type == RPMSIG_SIGNATURE_TYPE && sinfo->rc == RPMRC_OK) - vd->signature = RPMRC_OK; - switch (sinfo->rc) { case RPMRC_OK: break; @@ -1224,10 +1215,8 @@ static int vfyCb(struct rpmsinfo_s *sinfo, void *cbdata) */ if (!(vd->vfylevel & RPMSIG_SIGNATURE_TYPE)) sinfo->rc = RPMRC_OK; - /* fallthrough */ default: - if (sinfo->rc) - vd->msg = rpmsinfoMsg(sinfo); + vd->msg = rpmsinfoMsg(sinfo); break; } return (sinfo->rc == 0); @@ -1252,7 +1241,6 @@ static int verifyPackageFiles(rpmts ts, rpm_loff_t total) struct rpmvs_s *vs = rpmvsCreate(vfylevel, vsflags, keyring); struct vfydata_s vd = { .msg = NULL, - .signature = RPMRC_NOTFOUND, .vfylevel = vfylevel, }; rpmRC prc = RPMRC_FAIL; @@ -1267,14 +1255,10 @@ static int verifyPackageFiles(rpmts ts, rpm_loff_t total) if (prc == RPMRC_OK) prc = rpmvsVerify(vs, RPMSIG_VERIFIABLE_TYPE, vfyCb, &vd); - /* Record verify result, signatures only for now */ - rpmteSetVerified(p, vd.signature == RPMRC_OK); - if (prc) rpmteAddProblem(p, RPMPROB_VERIFY, NULL, vd.msg, 0); vd.msg = _free(vd.msg); - rpmvsFree(vs); } rpmtsNotify(ts, NULL, RPMCALLBACK_VERIFY_STOP, total, total); @@ -1634,95 +1618,6 @@ rpmRC runScript(rpmts ts, rpmte te, Header h, ARGV_const_t prefixes, return rc; } -#if WITH_AUDIT -struct teop { - rpmte te; - const char *op; -}; - -/* - * Figure out the actual operations: - * Install and remove are straightforward. Updates need to discovered - * via their erasure element: locate the updating element, adjust it's - * op to update and silence the erasure part. Obsoletion is handled as - * as install + remove, which it technically is. - */ -static void getAuditOps(rpmts ts, struct teop *ops, int nelem) -{ - rpmtsi pi = rpmtsiInit(ts); - rpmte p; - int i = 0; - while ((p = rpmtsiNext(pi, 0)) != NULL) { - const char *op = NULL; - if (rpmteType(p) == TR_ADDED) { - op = "install"; - } else { - op = "remove"; - rpmte d = rpmteDependsOn(p); - /* Fixup op on updating elements, silence the cleanup stage */ - if (d != NULL && rstreq(rpmteN(d), rpmteN(p))) { - /* Linear lookup, but we're only dealing with a few thousand */ - for (int x = 0; x < i; x++) { - if (ops[x].te == d) { - ops[x].op = "update"; - op = NULL; - break; - } - } - } - } - ops[i].te = p; - ops[i].op = op; - i++; - } - rpmtsiFree(pi); -} - -/* - * If enabled, log audit events for the operations in this transaction. - * In the event values, 1 means true/success and 0 false/failure. Shockingly. - */ -static void rpmtsAudit(rpmts ts) -{ - int auditFd = audit_open(); - if (auditFd < 0) - return; - - int nelem = rpmtsNElements(ts); - struct teop *ops = xcalloc(nelem, sizeof(*ops)); - char *dir = audit_encode_nv_string("root_dir", rpmtsRootDir(ts), 0); - int enforce = (rpmtsVfyLevel(ts) & RPMSIG_SIGNATURE_TYPE) != 0; - - getAuditOps(ts, ops, nelem); - - for (int i = 0; i < nelem; i++) { - const char *op = ops[i].op; - if (op) { - rpmte p = ops[i].te; - char *nevra = audit_encode_nv_string("sw", rpmteNEVRA(p), 0); - char eventTxt[256]; - int verified = rpmteGetVerified(p); - int result = (rpmteFailed(p) == 0); - - snprintf(eventTxt, sizeof(eventTxt), - "op=%s %s sw_type=rpm key_enforce=%u gpg_res=%u %s", - op, nevra, enforce, verified, dir); - audit_log_user_comm_message(auditFd, AUDIT_SOFTWARE_UPDATE, - eventTxt, NULL, NULL, NULL, NULL, result); - free(nevra); - } - } - - free(dir); - free(ops); - audit_close(auditFd); -} -#else -static void rpmtsAudit(rpmts ts) -{ -} -#endif - int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) { int rc = -1; /* assume failure */ @@ -1836,8 +1731,6 @@ exit: rpmpluginsCallTsmPost(rpmtsPlugins(ts), ts, rc); /* Finish up... */ - if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))) - rpmtsAudit(ts); (void) umask(oldmask); (void) rpmtsFinish(ts); rpmpsFree(tsprobs); diff --git a/macros.in b/macros.in index 5246b84..a3aa7a9 100644 --- a/macros.in +++ b/macros.in @@ -32,7 +32,7 @@ %__cp @__CP@ %__cpio @__CPIO@ %__file @__FILE@ -%__gpg /usr/bin/gpg2 +%__gpg @__GPG@ %__grep @__GREP@ %__gzip @__GZIP@ %__id @__ID@ @@ -50,7 +50,7 @@ %__mv @__MV@ %__patch @__PATCH@ %__perl @__PERL@ -%__python %{error:attempt to use unversioned python, define %%__python to %{_bindir}/python2 or %{_bindir}/python3 explicitly} +%__python @__PYTHON@ %__restorecon @__RESTORECON@ %__rm @__RM@ %__rsh @__RSH@ @@ -360,11 +360,6 @@ package or when debugging this package.\ %_javadir %{_datadir}/java %_javadocdir %{_datadir}/javadoc - -# Set ModularityLabel: for packages being build -# -#%modularitylabel - # A colon separated list of paths where files should *not* be installed. # Usually, these are network file system mount points. # @@ -804,11 +799,9 @@ package or when debugging this package.\ RPM_SOURCE_DIR=\"%{u2p:%{_sourcedir}}\"\ RPM_BUILD_DIR=\"%{u2p:%{_builddir}}\"\ RPM_OPT_FLAGS=\"%{optflags}\"\ - RPM_LD_FLAGS=\"%{?__global_ldflags}\"\ RPM_ARCH=\"%{_arch}\"\ RPM_OS=\"%{_os}\"\ - RPM_BUILD_NCPUS=\"%{_smp_build_ncpus}\"\ - export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_LD_FLAGS RPM_ARCH RPM_OS RPM_BUILD_NCPUS\ + export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\ RPM_DOC_DIR=\"%{_docdir}\"\ export RPM_DOC_DIR\ RPM_PACKAGE_NAME=\"%{NAME}\"\ @@ -824,10 +817,6 @@ package or when debugging this package.\ export CLASSPATH}\ PKG_CONFIG_PATH=\"${PKG_CONFIG_PATH}:%{_libdir}/pkgconfig:%{_datadir}/pkgconfig\"\ export PKG_CONFIG_PATH\ - CONFIG_SITE=${CONFIG_SITE:-NONE}\ - export CONFIG_SITE\ - PYTHON_DISALLOW_AMBIGUOUS_VERSION=warn\ - export PYTHON_DISALLOW_AMBIGUOUS_VERSION\ \ %{verbose:set -x}%{!verbose:exec > /dev/null}\ umask 022\ diff --git a/platform.in b/platform.in index a3d95fc..6ccdaf2 100644 --- a/platform.in +++ b/platform.in @@ -50,14 +50,11 @@ # Maximum number of CPU's to use when building, 0 for unlimited. #%_smp_ncpus_max 0 - -%_smp_build_ncpus %([ -z "$RPM_BUILD_NCPUS" ] \\\ +%_smp_mflags %([ -z "$RPM_BUILD_NCPUS" ] \\\ && RPM_BUILD_NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`"; \\\ ncpus_max=%{?_smp_ncpus_max}; \\\ if [ -n "$ncpus_max" ] && [ "$ncpus_max" -gt 0 ] && [ "$RPM_BUILD_NCPUS" -gt "$ncpus_max" ]; then RPM_BUILD_NCPUS="$ncpus_max"; fi; \\\ - echo "$RPM_BUILD_NCPUS";) - -%_smp_mflags -j%{_smp_build_ncpus} + if [ "$RPM_BUILD_NCPUS" -gt 1 ]; then echo "-j$RPM_BUILD_NCPUS"; fi) #============================================================================== # ---- Build policy macros. @@ -68,7 +65,7 @@ %__arch_install_post @ARCH_INSTALL_POST@ %_python_bytecompile_errors_terminate_build 0 -%_python_bytecompile_extra 0 +%_python_bytecompile_extra 1 # Standard brp-macro naming: # convert all '-' in basename to '_', add two leading underscores. diff --git a/plugins/selinux.c b/plugins/selinux.c index f1caf25..3c9d9e4 100644 --- a/plugins/selinux.c +++ b/plugins/selinux.c @@ -12,11 +12,6 @@ static struct selabel_handle * sehandle = NULL; -static inline rpmlogLvl loglvl(int iserror) -{ - return iserror ? RPMLOG_ERR : RPMLOG_DEBUG; -} - static void sehandle_fini(int close_status) { if (sehandle) { @@ -52,7 +47,7 @@ static rpmRC sehandle_init(int open_status) sehandle = selabel_open(SELABEL_CTX_FILE, opts, 1); - rpmlog(loglvl(sehandle == NULL), "selabel_open: (%s) %s\n", + rpmlog(RPMLOG_DEBUG, "selabel_open: (%s) %s\n", path, (sehandle == NULL ? strerror(errno) : "")); return (sehandle != NULL) ? RPMRC_OK : RPMRC_FAIL; @@ -130,8 +125,10 @@ static rpmRC selinux_scriptlet_fork_post(rpmPlugin plugin, if ((xx = setexeccon(newcon)) == 0) rc = RPMRC_OK; - rpmlog(loglvl(xx < 0), "setexeccon: (%s, %s) %s\n", + if (rpmIsDebug()) { + rpmlog(RPMLOG_DEBUG, "setexeccon: (%s, %s) %s\n", path, newcon, (xx < 0 ? strerror(errno) : "")); + } exit: context_free(con); @@ -146,8 +143,10 @@ exit: if ((xx = setexecfilecon(path, "rpm_script_t") == 0)) rc = RPMRC_OK; - rpmlog(loglvl(xx < 0), "setexecfilecon: (%s) %s\n", + if (rpmIsDebug()) { + rpmlog(RPMLOG_DEBUG, "setexecfilecon: (%s) %s\n", path, (xx < 0 ? strerror(errno) : "")); + } #endif /* If selinux is not enforcing, we don't care either */ if (rc && security_getenforce() < 1) @@ -168,8 +167,10 @@ static rpmRC selinux_fsm_file_prepare(rpmPlugin plugin, rpmfi fi, if (selabel_lookup_raw(sehandle, &scon, dest, file_mode) == 0) { int conrc = lsetfilecon(path, scon); - rpmlog(loglvl(conrc < 0), "lsetfilecon: (%s, %s) %s\n", - path, scon, (conrc < 0 ? strerror(errno) : "")); + if (rpmIsDebug()) { + rpmlog(RPMLOG_DEBUG, "lsetfilecon: (%s, %s) %s\n", + path, scon, (rc < 0 ? strerror(errno) : "")); + } if (conrc == 0 || (conrc < 0 && errno == EOPNOTSUPP)) rc = RPMRC_OK; diff --git a/python/header-py.c b/python/header-py.c index 93c241c..628b485 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -231,7 +231,7 @@ static PyObject * hdrFormat(hdrObject * s, PyObject * args, PyObject * kwds) return NULL; } - result = utf8FromString(r); + result = Py_BuildValue("s", r); free(r); return result; @@ -376,8 +376,8 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) if (obj == NULL) { h = headerNew(); - } else if (PyCapsule_CheckExact(obj)) { - h = PyCapsule_GetPointer(obj, "rpm._C_Header"); + } else if (CAPSULE_CHECK(obj)) { + h = CAPSULE_EXTRACT(obj, "rpm._C_Header"); headerLink(h); } else if (hdrObject_Check(obj)) { h = headerCopy(((hdrObject*) obj)->h); diff --git a/python/rpm/__init__.py b/python/rpm/__init__.py index 6d69eda..54728bb 100644 --- a/python/rpm/__init__.py +++ b/python/rpm/__init__.py @@ -61,9 +61,6 @@ except ImportError: # backwards compatibility + give the same class both ways ts = TransactionSet -def _fakedecode(self, encoding='utf-8', errors='strict'): - warnings.warn("decode() called on unicode string, see https://bugzilla.redhat.com/show_bug.cgi?id=1693751", UnicodeWarning, stacklevel=2) - return self def headerLoad(*args, **kwds): """DEPRECATED! Use rpm.hdr() instead.""" diff --git a/python/rpmds-py.c b/python/rpmds-py.c index 584e41c..9eae9a2 100644 --- a/python/rpmds-py.c +++ b/python/rpmds-py.c @@ -31,19 +31,19 @@ rpmds_Ix(rpmdsObject * s) static PyObject * rpmds_DNEVR(rpmdsObject * s) { - return utf8FromString(rpmdsDNEVR(s->ds)); + return Py_BuildValue("s", rpmdsDNEVR(s->ds)); } static PyObject * rpmds_N(rpmdsObject * s) { - return utf8FromString(rpmdsN(s->ds)); + return Py_BuildValue("s", rpmdsN(s->ds)); } static PyObject * rpmds_EVR(rpmdsObject * s) { - return utf8FromString(rpmdsEVR(s->ds)); + return Py_BuildValue("s", rpmdsEVR(s->ds)); } static PyObject * @@ -237,7 +237,7 @@ rpmds_subscript(rpmdsObject * s, PyObject * key) ix = (int) PyInt_AsLong(key); rpmdsSetIx(s->ds, ix); - return utf8FromString(rpmdsDNEVR(s->ds)); + return Py_BuildValue("s", rpmdsDNEVR(s->ds)); } static PyMappingMethods rpmds_as_mapping = { diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c index 4b05cce..85fb0cd 100644 --- a/python/rpmfd-py.c +++ b/python/rpmfd-py.c @@ -327,17 +327,17 @@ static PyObject *rpmfd_get_closed(rpmfdObject *s) static PyObject *rpmfd_get_name(rpmfdObject *s) { /* XXX: rpm returns non-paths with [mumble], python files use */ - return utf8FromString(Fdescr(s->fd)); + return Py_BuildValue("s", Fdescr(s->fd)); } static PyObject *rpmfd_get_mode(rpmfdObject *s) { - return utf8FromString(s->mode); + return Py_BuildValue("s", s->mode); } static PyObject *rpmfd_get_flags(rpmfdObject *s) { - return utf8FromString(s->flags); + return Py_BuildValue("s", s->flags); } static PyGetSetDef rpmfd_getseters[] = { diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c index 68eb5ce..a1a743a 100644 --- a/python/rpmfi-py.c +++ b/python/rpmfi-py.c @@ -41,19 +41,19 @@ rpmfi_DX(rpmfiObject * s, PyObject * unused) static PyObject * rpmfi_BN(rpmfiObject * s, PyObject * unused) { - return utf8FromString(rpmfiBN(s->fi)); + return Py_BuildValue("s", rpmfiBN(s->fi)); } static PyObject * rpmfi_DN(rpmfiObject * s, PyObject * unused) { - return utf8FromString(rpmfiDN(s->fi)); + return Py_BuildValue("s", rpmfiDN(s->fi)); } static PyObject * rpmfi_FN(rpmfiObject * s, PyObject * unused) { - return utf8FromString(rpmfiFN(s->fi)); + return Py_BuildValue("s", rpmfiFN(s->fi)); } static PyObject * @@ -98,7 +98,7 @@ rpmfi_Digest(rpmfiObject * s, PyObject * unused) { char *digest = rpmfiFDigestHex(s->fi, NULL); if (digest) { - PyObject *dig = utf8FromString(digest); + PyObject *dig = Py_BuildValue("s", digest); free(digest); return dig; } else { @@ -109,7 +109,7 @@ rpmfi_Digest(rpmfiObject * s, PyObject * unused) static PyObject * rpmfi_FLink(rpmfiObject * s, PyObject * unused) { - return utf8FromString(rpmfiFLink(s->fi)); + return Py_BuildValue("s", rpmfiFLink(s->fi)); } static PyObject * @@ -133,13 +133,13 @@ rpmfi_FMtime(rpmfiObject * s, PyObject * unused) static PyObject * rpmfi_FUser(rpmfiObject * s, PyObject * unused) { - return utf8FromString(rpmfiFUser(s->fi)); + return Py_BuildValue("s", rpmfiFUser(s->fi)); } static PyObject * rpmfi_FGroup(rpmfiObject * s, PyObject * unused) { - return utf8FromString(rpmfiFGroup(s->fi)); + return Py_BuildValue("s", rpmfiFGroup(s->fi)); } static PyObject * @@ -155,7 +155,7 @@ rpmfi_FClass(rpmfiObject * s, PyObject * unused) if ((FClass = rpmfiFClass(s->fi)) == NULL) FClass = ""; - return utf8FromString(FClass); + return Py_BuildValue("s", FClass); } static PyObject * @@ -208,7 +208,7 @@ rpmfi_iternext(rpmfiObject * s) Py_INCREF(Py_None); PyTuple_SET_ITEM(result, 0, Py_None); } else - PyTuple_SET_ITEM(result, 0, utf8FromString(FN)); + PyTuple_SET_ITEM(result, 0, Py_BuildValue("s", FN)); PyTuple_SET_ITEM(result, 1, PyLong_FromLongLong(FSize)); PyTuple_SET_ITEM(result, 2, PyInt_FromLong(FMode)); PyTuple_SET_ITEM(result, 3, PyInt_FromLong(FMtime)); @@ -222,12 +222,12 @@ rpmfi_iternext(rpmfiObject * s) Py_INCREF(Py_None); PyTuple_SET_ITEM(result, 10, Py_None); } else - PyTuple_SET_ITEM(result, 10, utf8FromString(FUser)); + PyTuple_SET_ITEM(result, 10, Py_BuildValue("s", FUser)); if (FGroup == NULL) { Py_INCREF(Py_None); PyTuple_SET_ITEM(result, 11, Py_None); } else - PyTuple_SET_ITEM(result, 11, utf8FromString(FGroup)); + PyTuple_SET_ITEM(result, 11, Py_BuildValue("s", FGroup)); PyTuple_SET_ITEM(result, 12, rpmfi_Digest(s, NULL)); } else @@ -313,7 +313,7 @@ rpmfi_subscript(rpmfiObject * s, PyObject * key) ix = (int) PyInt_AsLong(key); rpmfiSetFX(s->fi, ix); - return utf8FromString(rpmfiFN(s->fi)); + return Py_BuildValue("s", rpmfiFN(s->fi)); } static PyMappingMethods rpmfi_as_mapping = { diff --git a/python/rpmfiles-py.c b/python/rpmfiles-py.c index edb1694..d69d1f2 100644 --- a/python/rpmfiles-py.c +++ b/python/rpmfiles-py.c @@ -41,37 +41,37 @@ static PyObject *rpmfile_dx(rpmfileObject *s) static PyObject *rpmfile_name(rpmfileObject *s) { char * fn = rpmfilesFN(s->files, s->ix); - PyObject *o = utf8FromString(fn); + PyObject *o = Py_BuildValue("s", fn); free(fn); return o; } static PyObject *rpmfile_basename(rpmfileObject *s) { - return utf8FromString(rpmfilesBN(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesBN(s->files, s->ix)); } static PyObject *rpmfile_dirname(rpmfileObject *s) { - return utf8FromString(rpmfilesDN(s->files, rpmfilesDI(s->files, s->ix))); + return Py_BuildValue("s", rpmfilesDN(s->files, rpmfilesDI(s->files, s->ix))); } static PyObject *rpmfile_orig_name(rpmfileObject *s) { char * fn = rpmfilesOFN(s->files, s->ix); - PyObject *o = utf8FromString(fn); + PyObject *o = Py_BuildValue("s", fn); free(fn); return o; } static PyObject *rpmfile_orig_basename(rpmfileObject *s) { - return utf8FromString(rpmfilesOBN(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesOBN(s->files, s->ix)); } static PyObject *rpmfile_orig_dirname(rpmfileObject *s) { - return utf8FromString(rpmfilesODN(s->files, rpmfilesODI(s->files, s->ix))); + return Py_BuildValue("s", rpmfilesODN(s->files, rpmfilesODI(s->files, s->ix))); } static PyObject *rpmfile_mode(rpmfileObject *s) { @@ -105,17 +105,17 @@ static PyObject *rpmfile_nlink(rpmfileObject *s) static PyObject *rpmfile_linkto(rpmfileObject *s) { - return utf8FromString(rpmfilesFLink(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesFLink(s->files, s->ix)); } static PyObject *rpmfile_user(rpmfileObject *s) { - return utf8FromString(rpmfilesFUser(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesFUser(s->files, s->ix)); } static PyObject *rpmfile_group(rpmfileObject *s) { - return utf8FromString(rpmfilesFGroup(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesFGroup(s->files, s->ix)); } static PyObject *rpmfile_fflags(rpmfileObject *s) @@ -145,7 +145,7 @@ static PyObject *rpmfile_digest(rpmfileObject *s) NULL, &diglen); if (digest) { char * hex = pgpHexStr(digest, diglen); - PyObject *o = utf8FromString(hex); + PyObject *o = Py_BuildValue("s", hex); free(hex); return o; } @@ -154,17 +154,17 @@ static PyObject *rpmfile_digest(rpmfileObject *s) static PyObject *rpmfile_class(rpmfileObject *s) { - return utf8FromString(rpmfilesFClass(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesFClass(s->files, s->ix)); } static PyObject *rpmfile_caps(rpmfileObject *s) { - return utf8FromString(rpmfilesFCaps(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesFCaps(s->files, s->ix)); } static PyObject *rpmfile_langs(rpmfileObject *s) { - return utf8FromString(rpmfilesFLangs(s->files, s->ix)); + return Py_BuildValue("s", rpmfilesFLangs(s->files, s->ix)); } static PyObject *rpmfile_links(rpmfileObject *s) diff --git a/python/rpmkeyring-py.c b/python/rpmkeyring-py.c index 8968e05..d5f131e 100644 --- a/python/rpmkeyring-py.c +++ b/python/rpmkeyring-py.c @@ -38,7 +38,7 @@ static PyObject *rpmPubkey_new(PyTypeObject *subtype, static PyObject * rpmPubkey_Base64(rpmPubkeyObject *s) { char *b64 = rpmPubkeyBase64(s->pubkey); - PyObject *res = utf8FromString(b64); + PyObject *res = Py_BuildValue("s", b64); free(b64); return res; } diff --git a/python/rpmmacro-py.c b/python/rpmmacro-py.c index d8a3655..3cb1a51 100644 --- a/python/rpmmacro-py.c +++ b/python/rpmmacro-py.c @@ -52,7 +52,7 @@ rpmmacro_ExpandMacro(PyObject * self, PyObject * args, PyObject * kwds) if (rpmExpandMacros(NULL, macro, &str, 0) < 0) PyErr_SetString(pyrpmError, "error expanding macro"); else - res = utf8FromString(str); + res = Py_BuildValue("s", str); free(str); } return res; diff --git a/python/rpmmodule.c b/python/rpmmodule.c index b43d7af..c27952c 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -28,7 +28,6 @@ */ PyObject * pyrpmError; -PyObject * fakedecode = NULL; static PyObject * archScore(PyObject * self, PyObject * arg) { @@ -238,7 +237,7 @@ static void addRpmTags(PyObject *module) PyModule_AddIntConstant(module, tagname, tagval); pyval = PyInt_FromLong(tagval); - pyname = utf8FromString(shortname); + pyname = Py_BuildValue("s", shortname); PyDict_SetItem(dict, pyval, pyname); Py_DECREF(pyval); Py_DECREF(pyname); diff --git a/python/rpmps-py.c b/python/rpmps-py.c index 902b2ae..bdc899a 100644 --- a/python/rpmps-py.c +++ b/python/rpmps-py.c @@ -18,12 +18,12 @@ static PyObject *rpmprob_get_type(rpmProblemObject *s, void *closure) static PyObject *rpmprob_get_pkgnevr(rpmProblemObject *s, void *closure) { - return utf8FromString(rpmProblemGetPkgNEVR(s->prob)); + return Py_BuildValue("s", rpmProblemGetPkgNEVR(s->prob)); } static PyObject *rpmprob_get_altnevr(rpmProblemObject *s, void *closure) { - return utf8FromString(rpmProblemGetAltNEVR(s->prob)); + return Py_BuildValue("s", rpmProblemGetAltNEVR(s->prob)); } static PyObject *rpmprob_get_key(rpmProblemObject *s, void *closure) @@ -38,7 +38,7 @@ static PyObject *rpmprob_get_key(rpmProblemObject *s, void *closure) static PyObject *rpmprob_get_str(rpmProblemObject *s, void *closure) { - return utf8FromString(rpmProblemGetStr(s->prob)); + return Py_BuildValue("s", rpmProblemGetStr(s->prob)); } static PyObject *rpmprob_get_num(rpmProblemObject *s, void *closure) @@ -59,7 +59,7 @@ static PyGetSetDef rpmprob_getseters[] = { static PyObject *rpmprob_str(rpmProblemObject *s) { char *str = rpmProblemString(s->prob); - PyObject *res = utf8FromString(str); + PyObject *res = Py_BuildValue("s", str); free(str); return res; } diff --git a/python/rpmstrpool-py.c b/python/rpmstrpool-py.c index a56e2b5..356bd1d 100644 --- a/python/rpmstrpool-py.c +++ b/python/rpmstrpool-py.c @@ -44,7 +44,7 @@ static PyObject *strpool_id2str(rpmstrPoolObject *s, PyObject *item) const char *str = rpmstrPoolStr(s->pool, id); if (str) - ret = utf8FromString(str); + ret = PyBytes_FromString(str); else PyErr_SetObject(PyExc_KeyError, item); } diff --git a/python/rpmsystem-py.h b/python/rpmsystem-py.h index cf0e7b1..c8423e3 100644 --- a/python/rpmsystem-py.h +++ b/python/rpmsystem-py.h @@ -9,6 +9,39 @@ #include #include +#if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) < 0x0205 +typedef ssize_t Py_ssize_t; +typedef Py_ssize_t (*lenfunc)(PyObject *); +#endif + +/* Compatibility macros for Python < 2.6 */ +#ifndef PyVarObject_HEAD_INIT +#define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, +#endif + +#ifndef Py_TYPE +#define Py_TYPE(o) ((o)->ob_type) +#endif + +#if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) < 0x0206 +#define PyBytes_Check PyString_Check +#define PyBytes_FromString PyString_FromString +#define PyBytes_FromStringAndSize PyString_FromStringAndSize +#define PyBytes_Size PyString_Size +#define PyBytes_AsString PyString_AsString +#endif + +#if ((PY_MAJOR_VERSION << 8) | (PY_MINOR_VERSION << 0)) >= 0x0207 +#define CAPSULE_BUILD(ptr,name) PyCapsule_New(ptr, name, NULL) +#define CAPSULE_CHECK(obj) PyCapsule_CheckExact(obj) +#define CAPSULE_EXTRACT(obj,name) PyCapsule_GetPointer(obj, name) +#else +#define CAPSULE_BUILD(ptr,name) PyCObject_FromVoidPtr(ptr, NULL) +#define CAPSULE_CHECK(obj) PyCObject_Check(obj) +#define CAPSULE_EXTRACT(obj,name) PyCObject_AsVoidPtr(obj) +#endif + /* For Python 3, use the PyLong type throughout in place of PyInt */ #if PY_MAJOR_VERSION >= 3 #define PyInt_Check PyLong_Check @@ -19,34 +52,4 @@ #define PyInt_AsSsize_t PyLong_AsSsize_t #endif -PyObject * fakedecode; - -static inline PyObject * utf8FromString(const char *s) -{ -/* In Python 3, we return all strings as surrogate-escaped utf-8 */ -#if PY_MAJOR_VERSION >= 3 - if (s != NULL) { - PyObject *o = PyUnicode_DecodeUTF8(s, strlen(s), "surrogateescape"); - /* fish the fake decode function from python side if not done yet */ - if (fakedecode == NULL) { - PyObject *n = PyUnicode_FromString("rpm"); - PyObject *m = PyImport_Import(n); - PyObject *md = PyModule_GetDict(m); - fakedecode = PyDict_GetItemString(md, "_fakedecode"); - Py_DECREF(m); - Py_DECREF(n); - } - if (fakedecode && o) { - /* monkey-patch it into the string object as "decode" */ - PyDict_SetItemString(Py_TYPE(o)->tp_dict, "decode", fakedecode); - } - return o; - } -#else - if (s != NULL) - return PyBytes_FromString(s); -#endif - Py_RETURN_NONE; -} - #endif /* H_SYSTEM_PYTHON */ diff --git a/python/rpmtd-py.c b/python/rpmtd-py.c index 23ca105..247c750 100644 --- a/python/rpmtd-py.c +++ b/python/rpmtd-py.c @@ -17,7 +17,7 @@ PyObject * rpmtd_ItemAsPyobj(rpmtd td, rpmTagClass tclass) switch (tclass) { case RPM_STRING_CLASS: - res = utf8FromString(rpmtdGetString(td)); + res = PyBytes_FromString(rpmtdGetString(td)); break; case RPM_NUMERIC_CLASS: res = PyLong_FromLongLong(rpmtdGetNumber(td)); diff --git a/python/rpmte-py.c b/python/rpmte-py.c index 69cda5f..6936e75 100644 --- a/python/rpmte-py.c +++ b/python/rpmte-py.c @@ -56,49 +56,49 @@ rpmte_TEType(rpmteObject * s, PyObject * unused) static PyObject * rpmte_N(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteN(s->te)); + return Py_BuildValue("s", rpmteN(s->te)); } static PyObject * rpmte_E(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteE(s->te)); + return Py_BuildValue("s", rpmteE(s->te)); } static PyObject * rpmte_V(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteV(s->te)); + return Py_BuildValue("s", rpmteV(s->te)); } static PyObject * rpmte_R(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteR(s->te)); + return Py_BuildValue("s", rpmteR(s->te)); } static PyObject * rpmte_A(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteA(s->te)); + return Py_BuildValue("s", rpmteA(s->te)); } static PyObject * rpmte_O(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteO(s->te)); + return Py_BuildValue("s", rpmteO(s->te)); } static PyObject * rpmte_NEVR(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteNEVR(s->te)); + return Py_BuildValue("s", rpmteNEVR(s->te)); } static PyObject * rpmte_NEVRA(rpmteObject * s, PyObject * unused) { - return utf8FromString(rpmteNEVRA(s->te)); + return Py_BuildValue("s", rpmteNEVRA(s->te)); } static PyObject * diff --git a/python/rpmts-py.c b/python/rpmts-py.c index 96e3bb2..e4c5e12 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -230,9 +230,8 @@ rpmts_SolveCallback(rpmts ts, rpmds ds, const void * data) PyEval_RestoreThread(cbInfo->_save); - args = Py_BuildValue("(OiNNi)", cbInfo->tso, - rpmdsTagN(ds), utf8FromString(rpmdsN(ds)), - utf8FromString(rpmdsEVR(ds)), rpmdsFlags(ds)); + args = Py_BuildValue("(Oissi)", cbInfo->tso, + rpmdsTagN(ds), rpmdsN(ds), rpmdsEVR(ds), rpmdsFlags(ds)); result = PyEval_CallObject(cbInfo->cb, args); Py_DECREF(args); @@ -410,7 +409,7 @@ rpmts_HdrCheck(rpmtsObject * s, PyObject *obj) rpmrc = headerCheck(s->ts, uh, uc, &msg); Py_END_ALLOW_THREADS; - return Py_BuildValue("(iN)", rpmrc, utf8FromString(msg)); + return Py_BuildValue("(is)", rpmrc, msg); } static PyObject * @@ -496,12 +495,10 @@ rpmtsCallback(const void * hd, const rpmCallbackType what, if (cbInfo->cb == Py_None) return NULL; - PyEval_RestoreThread(cbInfo->_save); - /* Synthesize a python object for callback (if necessary). */ if (pkgObj == NULL) { if (h) { - pkgObj = utf8FromString(headerGetString(h, RPMTAG_NAME)); + pkgObj = Py_BuildValue("s", headerGetString(h, RPMTAG_NAME)); } else { pkgObj = Py_None; Py_INCREF(pkgObj); @@ -509,6 +506,8 @@ rpmtsCallback(const void * hd, const rpmCallbackType what, } else Py_INCREF(pkgObj); + PyEval_RestoreThread(cbInfo->_save); + args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, cbInfo->data); result = PyEval_CallObject(cbInfo->cb, args); Py_DECREF(args); @@ -846,7 +845,7 @@ static PyObject *rpmts_get_tid(rpmtsObject *s, void *closure) static PyObject *rpmts_get_rootDir(rpmtsObject *s, void *closure) { - return utf8FromString(rpmtsRootDir(s->ts)); + return Py_BuildValue("s", rpmtsRootDir(s->ts)); } static int rpmts_set_scriptFd(rpmtsObject *s, PyObject *value, void *closure) diff --git a/python/spec-py.c b/python/spec-py.c index 70b7965..fa7e589 100644 --- a/python/spec-py.c +++ b/python/spec-py.c @@ -34,7 +34,7 @@ static PyObject *makeHeader(Header h) PyObject *rpmmod = PyImport_ImportModuleNoBlock("rpm"); if (rpmmod == NULL) return NULL; - PyObject *ptr = PyCapsule_New(h, "rpm._C_Header", NULL); + PyObject *ptr = CAPSULE_BUILD(h, "rpm._C_Header"); PyObject *hdr = PyObject_CallMethod(rpmmod, "hdr", "(O)", ptr); Py_XDECREF(ptr); Py_XDECREF(rpmmod); @@ -57,7 +57,7 @@ static PyObject *pkgGetSection(rpmSpecPkg pkg, int section) { char *sect = rpmSpecPkgGetSection(pkg, section); if (sect != NULL) { - PyObject *ps = utf8FromString(sect); + PyObject *ps = PyBytes_FromString(sect); free(sect); if (ps != NULL) return ps; @@ -158,7 +158,7 @@ static PyObject * getSection(rpmSpec spec, int section) { const char *sect = rpmSpecGetSection(spec, section); if (sect) { - return utf8FromString(sect); + return Py_BuildValue("s", sect); } Py_RETURN_NONE; } @@ -208,8 +208,8 @@ static PyObject * spec_get_sources(specObject *s, void *closure) rpmSpecSrcIter iter = rpmSpecSrcIterInit(s->spec); while ((source = rpmSpecSrcIterNext(iter)) != NULL) { - PyObject *srcUrl = Py_BuildValue("(Nii)", - utf8FromString(rpmSpecSrcFilename(source, 1)), + PyObject *srcUrl = Py_BuildValue("(sii)", + rpmSpecSrcFilename(source, 1), rpmSpecSrcNum(source), rpmSpecSrcFlags(source)); if (!srcUrl) { diff --git a/rpm2cpio.c b/rpm2cpio.c index c2400a3..9949f38 100644 --- a/rpm2cpio.c +++ b/rpm2cpio.c @@ -89,12 +89,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - /* - * XXX HACK for #1142949: should be equality test, but archive size - * short by cpio trailer size in packages built with rpm 4.12.0 - * and its pre-releases. - */ - rc = (ufdCopy(gzdi, fdo) >= payload_size) ? EXIT_SUCCESS : EXIT_FAILURE; + rc = (ufdCopy(gzdi, fdo) == payload_size) ? EXIT_SUCCESS : EXIT_FAILURE; Fclose(fdo); diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index ce1be4e..e051c98 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -1128,13 +1128,13 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode) if ((flags & O_ACCMODE) == O_RDONLY) { /* decompressing */ if ((_stream = (void *) ZSTD_createDStream()) == NULL || ZSTD_isError(ZSTD_initDStream(_stream))) { - goto err; + return NULL; } nb = ZSTD_DStreamInSize(); } else { /* compressing */ if ((_stream = (void *) ZSTD_createCStream()) == NULL || ZSTD_isError(ZSTD_initCStream(_stream, level))) { - goto err; + return NULL; } nb = ZSTD_CStreamOutSize(); } @@ -1149,14 +1149,6 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode) zstd->b = xmalloc(nb); return zstd; - -err: - fclose(fp); - if ((flags & O_ACCMODE) == O_RDONLY) - ZSTD_freeDStream(_stream); - else - ZSTD_freeCStream(_stream); - return NULL; } static FD_t zstdFdopen(FD_t fd, int fdno, const char * fmode) diff --git a/rpmio/rpmpgp.c b/rpmio/rpmpgp.c index 46cd0f3..061751a 100644 --- a/rpmio/rpmpgp.c +++ b/rpmio/rpmpgp.c @@ -1289,10 +1289,9 @@ static pgpArmor decodePkts(uint8_t *b, uint8_t **pkt, size_t *pktlen) goto exit; } t += (sizeof("-----")-1); - /* Handle EOF without EOL here, *t == '\0' at EOF */ - if (*t && (t >= te)) continue; + if (t >= te) continue; /* XXX permitting \r here is not RFC-2440 compliant */ - if (!(*t == '\n' || *t == '\r' || *t == '\0')) continue; + if (!(*t == '\n' || *t == '\r')) continue; crcdec = NULL; crclen = 0; diff --git a/rpmpopt.in b/rpmpopt.in index 67fcabf..3e44937 100644 --- a/rpmpopt.in +++ b/rpmpopt.in @@ -44,26 +44,21 @@ rpm alias --scripts --qf '\ --POPTdesc=$"list install/erase scriptlets from package(s)" rpm alias --setperms -q --qf '[\[ -L %{FILENAMES:shescape} \] || \ - ( \[ $((%{FILEFLAGS} & 2#1001000)) != 0 \] && \[ ! -e %{FILENAMES:shescape} \] ) || \ + \[ $((%{FILEFLAGS} & 2#1001000)) != 0 \] && \[ ! -e %{FILENAMES:shescape} \] || \ chmod %7{FILEMODES:octal} %{FILENAMES:shescape}\n]' \ --pipe "grep -v \(none\) | grep '^. -L ' | sed 's/chmod .../chmod /' | sh" \ --POPTdesc=$"set permissions of files in a package" rpm alias --setugids -q --qf \ '[ch %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} %{FILENAMES:shescape} %{FILEFLAGS}\n]' \ - --pipe "(echo 'ch() { ( \[ $(($4 & 2#1001000)) != 0 \] && \[ ! -e \"$3\" \] ) || \ + --pipe "(echo 'ch() { \[ $(($4 & 2#1001000)) != 0 \] && \[ ! -e \"$3\" \] || \ (chown -h -- \"$1\" \"$3\";chgrp -h -- \"$2\" \"$3\";) }'; \ grep '^ch '|grep -v \(none\))|sh" \ --POPTdesc=$"set user/group ownership of files in a package" rpm alias --setcaps -q --qf \ - "[if \[ -f %{FILENAMES:shescape} -a ! -L %{FILENAMES:shescape} \]; then\n\ -%|FILECAPS?{ if \[ -n %{FILECAPS:shescape} \]; then\n\ - setcap %{FILECAPS:shescape} %{FILENAMES:shescape}\n\ - el}:{ }|if \[ -n \"\$(getcap %{FILENAMES:shescape})\" \]; then\n\ - setcap -r %{FILENAMES:shescape}\n\ - fi\n\ -fi\n]" \ + "[\[ -f %{FILENAMES:shescape} -a ! -L %{FILENAMES:shescape} \] \ + && setcap %|FILECAPS?{%{FILECAPS:shescape}}:{''}| %{FILENAMES:shescape}\n]" \ --pipe "sh" \ --POPTdesc=$"set capabilities of files in a package" diff --git a/rpmrc.in b/rpmrc.in index 3a5b1e6..5fe289c 100644 --- a/rpmrc.in +++ b/rpmrc.in @@ -392,7 +392,7 @@ arch_compat: alphaev5: alpha arch_compat: alpha: axp noarch arch_compat: athlon: i686 -arch_compat: geode: i686 +arch_compat: geode: i586 arch_compat: pentium4: pentium3 arch_compat: pentium3: i686 arch_compat: i686: i586 diff --git a/rpmsign.c b/rpmsign.c index 1a5cd59..ae86f66 100644 --- a/rpmsign.c +++ b/rpmsign.c @@ -134,8 +134,7 @@ static int doSign(poptContext optCon, struct rpmSignArgs *sargs) const char *arg; rc = 0; while ((arg = poptGetArg(optCon)) != NULL) { - if (rpmPkgSign(arg, sargs) < 0) - rc++; + rc += rpmPkgSign(arg, sargs); } exit: @@ -176,8 +175,7 @@ int main(int argc, char *argv[]) case MODE_DELSIGN: ec = 0; while ((arg = poptGetArg(optCon)) != NULL) { - if (rpmPkgDelSign(arg, &sargs) < 0) - ec++; + ec += rpmPkgDelSign(arg, &sargs); } break; case MODE_NONE: @@ -190,5 +188,5 @@ int main(int argc, char *argv[]) exit: rpmcliFini(optCon); - return RETVAL(ec); + return ec; } diff --git a/scripts/brp-python-bytecompile b/scripts/brp-python-bytecompile index 4a9b49e..c06bdfa 100644 --- a/scripts/brp-python-bytecompile +++ b/scripts/brp-python-bytecompile @@ -61,9 +61,6 @@ shopt -s nullglob for python_libdir in `find "$RPM_BUILD_ROOT" -type d|grep -E "/usr/lib(64)?/python[0-9]\.[0-9]$"`; do python_binary=/usr/bin/$(basename $python_libdir) - if [ "$python_binary" = "/usr/bin/python3.6" ]; then - python_binary=/usr/libexec/platform-python - fi real_libdir=${python_libdir/$RPM_BUILD_ROOT/} echo "Bytecompiling .py files below $python_libdir using $python_binary" diff --git a/scripts/brp-strip-static-archive b/scripts/brp-strip-static-archive index f7fb26b..ddd3b24 100755 --- a/scripts/brp-strip-static-archive +++ b/scripts/brp-strip-static-archive @@ -5,7 +5,6 @@ if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then fi STRIP=${1:-strip} -NCPUS=${RPM_BUILD_NCPUS:-1} case `uname -a` in Darwin*) exit 0 ;; @@ -13,6 +12,9 @@ Darwin*) exit 0 ;; esac # Strip static libraries. -find "$RPM_BUILD_ROOT" -type f | \ - grep -v "^${RPM_BUILD_ROOT}/\?usr/lib/debug" | \ - xargs -d '\n' -r -P$NCPUS -n32 sh -c "file \"\$@\" | sed 's/: */: /' | grep 'current ar archive' | sed -n -e 's/^\(.*\):[ ]*current ar archive/\1/p' | xargs -d '\n' -I\{\} $STRIP -g \{\}" ARG0 +for f in `find "$RPM_BUILD_ROOT" -type f -a -exec file {} \; | \ + grep -v "^${RPM_BUILD_ROOT}/\?usr/lib/debug" | \ + grep 'current ar archive' | \ + sed -n -e 's/^\(.*\):[ ]*current ar archive/\1/p'`; do + $STRIP -g "$f" +done diff --git a/scripts/check-buildroot b/scripts/check-buildroot index f91dc76..0cfb34f 100755 --- a/scripts/check-buildroot +++ b/scripts/check-buildroot @@ -24,12 +24,11 @@ fi tmp=$(mktemp ${TMPDIR:-/tmp}/cbr.XXXXXX) trap "rm -f $tmp" EXIT -NCPUS=${RPM_BUILD_NCPUS:-1} find "$RPM_BUILD_ROOT" \! \( \ -name '*.pyo' -o -name '*.pyc' -o -name '*.elc' -o -name '.packlist' \ \) -type f -print0 | \ - LANG=C xargs -0r -P$NCPUS -n16 grep -F "$RPM_BUILD_ROOT" >>$tmp + LANG=C xargs -0r grep -F "$RPM_BUILD_ROOT" >$tmp test -s "$tmp" && { cat "$tmp" diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh index d8ac0c8..73275a1 100755 --- a/scripts/find-debuginfo.sh +++ b/scripts/find-debuginfo.sh @@ -4,7 +4,6 @@ # # Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m] [-i] [-n] # [--keep-section SECTION] [--remove-section SECTION] -# [--g-libs] # [-j N] [--jobs N] # [-o debugfiles.list] # [-S debugsourcefiles.list] @@ -17,8 +16,6 @@ # [builddir] # # The -g flag says to use strip -g instead of full strip on DSOs or EXEs. -# The --g-libs flag says to use strip -g instead of full strip ONLY on DSOs. -# Options -g and --g-libs are mutually exclusive. # The -r flag says to use eu-strip --reloc-debug-sections. # Use --keep-section SECTION or --remove-section SECTION to explicitly # keep a (non-allocated) section in the main executable or explicitly @@ -71,9 +68,6 @@ lib_rpm_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # With -g arg, pass it to strip on libraries or executables. strip_g=false -# With --g-libs arg, pass it to strip on libraries. -strip_glibs=false - # with -r arg, pass --reloc-debug-sections to eu-strip. strip_r=false @@ -141,9 +135,6 @@ while [ $# -gt 0 ]; do unique_debug_src_base=$2 shift ;; - --g-libs) - strip_glibs=true - ;; -g) strip_g=true ;; @@ -213,11 +204,6 @@ if test -n "$build_id_seed" -a "$no_recompute_build_id" = "true"; then exit 2 fi -if [ "$strip_g" = "true" ] && [ "$strip_glibs" = "true" ]; then - echo >&2 "*** ERROR: -g and --g-libs cannot be used together" - exit 2 -fi - i=0 while ((i < nout)); do outs[$i]="$BUILDDIR/${outs[$i]}" @@ -251,9 +237,6 @@ strip_to_debug() application/x-executable*) g=-g ;; application/x-pie-executable*) g=-g ;; esac - $strip_glibs && case "$(file -bi "$2")" in - application/x-sharedlib*) g=-g ;; - esac eu-strip --remove-comment $r $g ${keep_remove_args} -f "$1" "$2" || exit chmod 444 "$1" || exit } @@ -350,7 +333,7 @@ trap 'rm -rf "$temp"' EXIT touch "$temp/primary" find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \ \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \ - -print | LC_ALL=C sort | + -print | file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped.*/\1/p' | xargs --no-run-if-empty stat -c '%h %D_%i %n' | while read nlinks inum f; do @@ -405,10 +388,6 @@ do_file() fi fi - # Compress any annobin notes in the original binary. - # Ignore any errors, since older objcopy don't support --merge-notes. - objcopy --merge-notes "$f" 2>/dev/null || true - # A binary already copied into /usr/lib/debug doesn't get stripped, # just has its file names collected and adjusted. case "$dn" in @@ -430,12 +409,8 @@ do_file() # libraries. Other executable ELF files (like kernel modules) don't need it. if [ "$include_minidebug" = "true" -a "$strip_g" = "false" ]; then skip_mini=true - if [ "$strip_glibs" = "false" ]; then - case "$(file -bi "$f")" in - application/x-sharedlib*) skip_mini=false ;; - esac - fi case "$(file -bi "$f")" in + application/x-sharedlib*) skip_mini=false ;; application/x-executable*) skip_mini=false ;; esac $skip_mini || add_minidebug "${debugfn}" "$f" diff --git a/scripts/find-lang.sh b/scripts/find-lang.sh index 0635f55..fdca18e 100755 --- a/scripts/find-lang.sh +++ b/scripts/find-lang.sh @@ -248,7 +248,7 @@ s:%lang(C) :: find "$TOP_DIR" -type d|sed ' s:'"$TOP_DIR"':: '"$ALL_NAME$MAN"'s:\(.*/man/\([^/_]\+\).*/man[a-z0-9]\+/\):: -'"$ALL_NAME$MAN"'s:\(.*/man/\([^/_]\+\).*/man[a-z0-9]\+$\):%lang(\2) \1/*: +'"$ALL_NAME$MAN"'s:\(.*/man/\([^/_]\+\).*/man[a-z0-9]\+$\):%lang(\2) \1*: s:^\([^%].*\):: s:%lang(C) :: /^$/d' >> $MO_NAME diff --git a/sign/rpmgensig.c b/sign/rpmgensig.c index e129058..771d010 100644 --- a/sign/rpmgensig.c +++ b/sign/rpmgensig.c @@ -21,7 +21,6 @@ #include "lib/rpmlead.h" #include "lib/signature.h" -#include "lib/rpmvs.h" #include "sign/rpmsignfiles.h" #include "debug.h" @@ -642,31 +641,6 @@ exit: #endif } -static int msgCb(struct rpmsinfo_s *sinfo, void *cbdata) -{ - char **msg = cbdata; - if (sinfo->rc && *msg == NULL) - *msg = rpmsinfoMsg(sinfo); - return (sinfo->rc != RPMRC_FAIL); -} - -/* Require valid digests on entire package for signing. */ -static int checkPkg(FD_t fd, char **msg) -{ - int rc; - struct rpmvs_s *vs = rpmvsCreate(RPMSIG_DIGEST_TYPE, 0, NULL); - off_t offset = Ftell(fd); - - Fseek(fd, 0, SEEK_SET); - rc = rpmpkgRead(vs, fd, NULL, NULL, msg); - if (!rc) - rc = rpmvsVerify(vs, RPMSIG_DIGEST_TYPE, msgCb, msg); - Fseek(fd, offset, SEEK_SET); - - rpmvsFree(vs); - return rc; -} - /** \ingroup rpmcli * Create/modify elements in signature header. * @param rpm path to package @@ -697,12 +671,6 @@ static int rpmSign(const char *rpm, int deleting, int signfiles) if (manageFile(&fd, rpm, O_RDWR)) goto exit; - /* Ensure package is intact before attempting to sign */ - if ((rc = checkPkg(fd, &msg))) { - rpmlog(RPMLOG_ERR, "not signing corrupt package %s: %s\n", rpm, msg); - goto exit; - } - if ((rc = rpmLeadRead(fd, &msg)) != RPMRC_OK) { rpmlog(RPMLOG_ERR, "%s: %s\n", rpm, msg); goto exit; diff --git a/tests/Makefile.am b/tests/Makefile.am index 547416f..eaf817c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -117,7 +117,6 @@ atlocal: atlocal.in Makefile -e "s,[@]usrlibdir[@],$(libdir)," \ -e "s,[@]execprefix[@],$(exec_prefix)," \ -e "s,[@]RPMCONFIGDIR[@],$(rpmconfigdir)," \ - -e "s,[@]PYTHON[@],$(PYTHON)," \ < $(srcdir)/atlocal.in > atlocal DISTCLEANFILES = atlocal EXTRA_DIST += atlocal.in @@ -138,7 +137,7 @@ testing$(bindir)/rpmbuild: ../rpmbuild for d in dev etc magic tmp var; do if [ ! -d testing/$${d} ]; then mkdir testing/$${d}; fi; done for node in urandom stdin stderr stdout null full; do ln -s /dev/$${node} testing/dev/$${node}; done for cf in hosts resolv.conf passwd shadow group gshadow mtab ; do [ -f /etc/$${cf} ] && ln -s /etc/$${cf} testing/etc/$${cf}; done - for prog in gzip cat patch tar sh ln chmod rm mkdir uname grep sed find file ionice mktemp nice cut sort diff touch install wc coreutils xargs; do p=`which $${prog}`; if [ "$${p}" != "" ]; then ln -s $${p} testing/$(bindir)/; fi; done + for prog in gzip cat patch tar sh ln chmod rm mkdir uname grep sed find file ionice mktemp nice cut sort diff touch install wc coreutils; do p=`which $${prog}`; if [ "$${p}" != "" ]; then ln -s $${p} testing/$(bindir)/; fi; done for d in /proc /sys /selinux /etc/selinux; do if [ -d $${d} ]; then ln -s $${d} testing/$${d}; fi; done (cd testing/magic && file -C) HOME=$(abs_builddir)/testing gpg2 --import ${abs_srcdir}/data/keys/*.secret diff --git a/tests/atlocal.in b/tests/atlocal.in index 3b1474b..d7d837f 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -3,8 +3,7 @@ export LD_LIBRARY_PATH PATH="${abs_builddir}/testing@rpmbindir@:${abs_builddir}/testing@usrbindir@:$PATH" export PATH -PYTHON=@PYTHON@ -PYLIBDIR=$(${PYTHON} -c "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib(1,0,'@execprefix@'))") +PYLIBDIR=`python -c "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib(1,0,'@execprefix@'))"` PYTHONPATH="${abs_builddir}/testing${PYLIBDIR}" export PYTHONPATH diff --git a/tests/data/SPECS/replacetest.spec b/tests/data/SPECS/replacetest.spec index d5a1729..5497456 100644 --- a/tests/data/SPECS/replacetest.spec +++ b/tests/data/SPECS/replacetest.spec @@ -46,4 +46,4 @@ rm -rf $RPM_BUILD_ROOT %files %defattr(-,%{user},%{grp},-) -%{?fileattr} /opt/* +/opt/* diff --git a/tests/local.at b/tests/local.at index a6fd1ce..48c5d3f 100644 --- a/tests/local.at +++ b/tests/local.at @@ -10,7 +10,6 @@ rm -rf "${abs_builddir}"/testing`rpm --eval '%_dbpath'`/* m4_define([RPMPY_RUN],[[ cat << EOF > test.py -# coding=utf-8 import rpm, sys dbpath=rpm.expandMacro('%_dbpath') rpm.addMacro('_dbpath', '${abs_builddir}/testing%s' % dbpath) @@ -18,7 +17,7 @@ def myprint(msg = ''): sys.stdout.write('%s\n' % msg) $1 EOF -${PYTHON} test.py +python test.py ]]) m4_define([RPMPY_CHECK],[ diff --git a/tests/rpmgeneral.at b/tests/rpmgeneral.at index 45d3869..509277f 100644 --- a/tests/rpmgeneral.at +++ b/tests/rpmgeneral.at @@ -150,7 +150,6 @@ LONGARCHIVESIZE LONGFILESIZES LONGSIGSIZE LONGSIZE -MODULARITYLABEL N NAME NEVR diff --git a/tests/rpmpython.at b/tests/rpmpython.at index 5d51c74..3a7c251 100644 --- a/tests/rpmpython.at +++ b/tests/rpmpython.at @@ -33,7 +33,7 @@ prexp(mname) []) RPMPY_TEST([basic rpmio],[ -msg = b'Killroy was here\n' +msg = 'Killroy was here\n' data = msg * 10 # TODO: test other compression types too if built in for iot in [ 'fpio', 'fdio', 'ufdio', 'gzdio' ]: @@ -92,39 +92,21 @@ h['arch'] = 'noarch' myprint(h['nevra']) del h['epoch'] myprint(h['nevra']) -for a in ['name', 'bugurl', '__foo__', ]: +for a in ['name', 'bugurl', '__class__', '__foo__', ]: try: x = getattr(h, a) myprint(x) - except AttributeError as exc: + except AttributeError, exc: myprint(exc) ], [testpkg-5:1.0-1.noarch testpkg-1.0-1.noarch testpkg None + 'rpm.hdr' object has no attribute '__foo__'] ) -RPMPY_TEST([non-utf8 data in header],[ -str = u'älämölö' -enc = 'iso-8859-1' -b = str.encode(enc) -h = rpm.hdr() -h['group'] = b -d = h['group'] -try: - # python 3 - t = bytes(d, 'utf-8', 'surrogateescape') -except TypeError: - # python 2 - t = bytes(d) -res = t.decode(enc) -myprint(str == res) -], -[True] -) - RPMPY_TEST([invalid header data],[ h1 = rpm.hdr() h1['basenames'] = ['bing', 'bang', 'bong'] @@ -137,28 +119,13 @@ h2['dirindexes'] = [ 0, 0, 1 ] for h in [h1, h2]: try: myprint(','.join(h['filenames'])) - except rpm.error as exc: + except rpm.error, exc: myprint(exc) ], [invalid header data /opt/bing,/opt/bang,/flopt/bong] ) -RPMPY_TEST([labelCompare],[ -v = '1.0' -r = '1' -e = 3 -h = rpm.hdr() -h['name'] = 'testpkg' -h['version'] = v -h['release'] = r -h['epoch'] = e -myprint(rpm.labelCompare((str(h['epoch']), h['version'], h['release']), - (str(e), v, r))) -], -[0] -) - RPMPY_TEST([vfyflags API],[ ts = rpm.ts() dlv = ts.getVfyFlags() @@ -197,7 +164,7 @@ rpm.setLogFile(sink) try: h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-2.0-1.x86_64-signed.rpm') myprint(h['arch']) -except rpm.error as e: +except rpm.error, e: myprint(e) ], [public key not available @@ -206,7 +173,7 @@ except rpm.error as e: RPMPY_TEST([reading a signed package file 2],[ -keydata = open('${RPMDATA}/keys/rpm.org-rsa-2048-test.pub', 'rb').read() +keydata = open('${RPMDATA}/keys/rpm.org-rsa-2048-test.pub').read() pubkey = rpm.pubkey(keydata) keyring = rpm.keyring() keyring.addKey(pubkey) @@ -216,7 +183,7 @@ ts.setKeyring(keyring) try: h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-2.0-1.x86_64-signed.rpm') myprint(h['arch']) -except rpm.error as e: +except rpm.error, e: myprint(e) ], [x86_64] @@ -240,7 +207,7 @@ h = rpm.hdr() h['name'] = "foo" try: ts.addInstall(h, 'foo', 'u') -except rpm.error as err: +except rpm.error, err: myprint(err) for e in ts: myprint(e.NEVRA()) @@ -261,7 +228,7 @@ h['dirnames'] = ['/opt' '/flopt'] h['dirindexes'] = [ 1, 2, 3 ] try: ts.addInstall(h, 'foo', 'u') -except rpm.error as err: +except rpm.error, err: myprint(err) for e in ts: myprint(e.NEVRA()) diff --git a/tests/rpmquery.at b/tests/rpmquery.at index 0dc6d78..ab7bb3c 100644 --- a/tests/rpmquery.at +++ b/tests/rpmquery.at @@ -62,24 +62,6 @@ hello.spec AT_CLEANUP # ------------------------------ -AT_SETUP([rpm -ql multiple *.rpm]) -AT_KEYWORDS([query]) -AT_CHECK([ -runroot rpm \ - -ql \ - /data/SRPMS/hello-1.0-1.src.rpm /data/RPMS/hello-1.0-1.i386.rpm -], -[0], -[hello-1.0.tar.gz -hello.spec -/usr/local/bin/hello -/usr/share/doc/hello-1.0 -/usr/share/doc/hello-1.0/FAQ -], -[ignore]) -AT_CLEANUP - -# ------------------------------ AT_SETUP([rpmspec -q]) AT_KEYWORDS([query]) AT_CHECK([ diff --git a/tests/rpmsigdig.at b/tests/rpmsigdig.at index 880e5ed..09fcdd5 100644 --- a/tests/rpmsigdig.at +++ b/tests/rpmsigdig.at @@ -467,23 +467,3 @@ run rpmsign --key-id 1964C5FC --addsign "${RPMTEST}"/tmp/hello-2.0-1.x86_64-sign [], []) AT_CLEANUP - -AT_SETUP([rpmsign --addsign ]) -AT_KEYWORDS([rpmsign signature]) -AT_CHECK([ -RPMDB_CLEAR -RPMDB_INIT -rm -rf "${TOPDIR}" - -pkg="hello-2.0-1.x86_64.rpm" -cp "${RPMTEST}"/data/RPMS/${pkg} "${RPMTEST}"/tmp/${pkg} -dd if=/dev/zero of="${RPMTEST}"/tmp/${pkg} \ - conv=notrunc bs=1 seek=333 count=4 2> /dev/null -run rpmsign --key-id 1964C5FC --addsign "${RPMTEST}/tmp/${pkg}" -], -[1], -[/home/pmatilai/repos/rpm/tests/testing/tmp/hello-2.0-1.x86_64.rpm: -], -[error: not signing corrupt package /home/pmatilai/repos/rpm/tests/testing/tmp/hello-2.0-1.x86_64.rpm: MD5 digest: BAD (Expected 007ca1d8b35cca02a1854ba301c5432e != 137ca1d8b35cca02a1854ba301c5432e) -]) -AT_CLEANUP diff --git a/tests/rpmvercmp.at b/tests/rpmvercmp.at index a5b63ba..2a25bdd 100644 --- a/tests/rpmvercmp.at +++ b/tests/rpmvercmp.at @@ -100,32 +100,6 @@ RPMVERCMP(1.0~rc1~git123, 1.0~rc1~git123, 0) RPMVERCMP(1.0~rc1~git123, 1.0~rc1, -1) RPMVERCMP(1.0~rc1, 1.0~rc1~git123, 1) -dnl Basic testcases for caret sorting -RPMVERCMP(1.0^, 1.0^, 0) -RPMVERCMP(1.0^, 1.0, 1) -RPMVERCMP(1.0, 1.0^, -1) -RPMVERCMP(1.0^git1, 1.0^git1, 0) -RPMVERCMP(1.0^git1, 1.0, 1) -RPMVERCMP(1.0, 1.0^git1, -1) -RPMVERCMP(1.0^git1, 1.0^git2, -1) -RPMVERCMP(1.0^git2, 1.0^git1, 1) -RPMVERCMP(1.0^git1, 1.01, -1) -RPMVERCMP(1.01, 1.0^git1, 1) -RPMVERCMP(1.0^20160101, 1.0^20160101, 0) -RPMVERCMP(1.0^20160101, 1.0.1, -1) -RPMVERCMP(1.0.1, 1.0^20160101, 1) -RPMVERCMP(1.0^20160101^git1, 1.0^20160101^git1, 0) -RPMVERCMP(1.0^20160102, 1.0^20160101^git1, 1) -RPMVERCMP(1.0^20160101^git1, 1.0^20160102, -1) - -dnl Basic testcases for tilde and caret sorting -RPMVERCMP(1.0~rc1^git1, 1.0~rc1^git1, 0) -RPMVERCMP(1.0~rc1^git1, 1.0~rc1, 1) -RPMVERCMP(1.0~rc1, 1.0~rc1^git1, -1) -RPMVERCMP(1.0^git1~pre, 1.0^git1~pre, 0) -RPMVERCMP(1.0^git1, 1.0^git1~pre, 1) -RPMVERCMP(1.0^git1~pre, 1.0^git1, -1) - dnl These are included here to document current, arguably buggy behaviors dnl for reference purposes and for easy checking against unintended dnl behavior changes. diff --git a/tests/rpmverify.at b/tests/rpmverify.at index 245c848..6099764 100644 --- a/tests/rpmverify.at +++ b/tests/rpmverify.at @@ -575,39 +575,3 @@ fox ], []) AT_CLEANUP - -AT_SETUP([Upgraded verification with min_writes 5 (suid files)]) -AT_KEYWORDS([upgrade verify min_writes]) -AT_CHECK([ -RPMDB_CLEAR -RPMDB_INIT -tf="${RPMTEST}"/opt/foo -rm -rf "${tf}" "${tf}".rpm* -rm -rf "${TOPDIR}" - -for v in "1.0" "2.0"; do - runroot rpmbuild --quiet -bb \ - --define "ver $v" \ - --define "filetype file" \ - --define "filedata foo" \ - --define "fileattr %attr(2755,-,-)" \ - /data/SPECS/replacetest.spec -done - -runroot rpm -U /build/RPMS/noarch/replacetest-1.0-1.noarch.rpm -runroot rpm -Va --nouser --nogroup replacetest -runroot rpm -U \ - --define "_minimize_writes 1" \ - /build/RPMS/noarch/replacetest-2.0-1.noarch.rpm -runroot rpm -Va --nouser --nogroup replacetest -chmod 777 "${tf}" -runroot rpm -U \ - --oldpackage \ - --define "_minimize_writes 1" \ - /build/RPMS/noarch/replacetest-1.0-1.noarch.rpm -runroot rpm -Va --nouser --nogroup replacetest -], -[0], -[], -[]) -AT_CLEANUP diff --git a/tools/debugedit.c b/tools/debugedit.c index 4ec431f..84568dd 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -41,7 +41,6 @@ #include #include - /* Unfortunately strtab manipulation functions were only officially added to elfutils libdw in 0.167. Before that there were internal unsupported ebl variants. While libebl.h isn't supported we'll try to use it anyway @@ -400,18 +399,13 @@ dwarf2_write_be32 (unsigned char *p, uint32_t v) relend). Might just update the addend. So relocations need to be updated at the end. */ -static bool rel_updated; - #define do_write_32_relocated(ptr,val) ({ \ if (relptr && relptr < relend && relptr->ptr == ptr) \ { \ if (reltype == SHT_REL) \ do_write_32 (ptr, val - relptr->addend); \ else \ - { \ - relptr->addend = val; \ - rel_updated = true; \ - } \ + relptr->addend = val; \ } \ else \ do_write_32 (ptr,val); \ @@ -422,19 +416,14 @@ static bool rel_updated; ptr += 4; \ }) -typedef struct debug_section +static struct { const char *name; unsigned char *data; Elf_Data *elf_data; size_t size; int sec, relsec; - REL *relbuf; - REL *relend; - struct debug_section *next; /* Only happens for COMDAT .debug_macro. */ - } debug_section; - -static debug_section debug_sections[] = + } debug_sections[] = { #define DEBUG_INFO 0 #define DEBUG_ABBREV 1 @@ -467,201 +456,6 @@ static debug_section debug_sections[] = { NULL, NULL, NULL, 0, 0, 0 } }; -static int -rel_cmp (const void *a, const void *b) -{ - REL *rela = (REL *) a, *relb = (REL *) b; - - if (rela->ptr < relb->ptr) - return -1; - - if (rela->ptr > relb->ptr) - return 1; - - return 0; -} - -/* Returns a malloced REL array, or NULL when there are no relocations - for this section. When there are relocations, will setup relend, - as the last REL, and reltype, as SHT_REL or SHT_RELA. */ -static void -setup_relbuf (DSO *dso, debug_section *sec, int *reltype) -{ - int ndx, maxndx; - GElf_Rel rel; - GElf_Rela rela; - GElf_Sym sym; - GElf_Addr base = dso->shdr[sec->sec].sh_addr; - Elf_Data *symdata = NULL; - int rtype; - REL *relbuf; - Elf_Scn *scn; - Elf_Data *data; - int i = sec->relsec; - - /* No relocations, or did we do this already? */ - if (i == 0 || sec->relbuf != NULL) - { - relptr = sec->relbuf; - relend = sec->relend; - return; - } - - scn = dso->scn[i]; - data = elf_getdata (scn, NULL); - assert (data != NULL && data->d_buf != NULL); - assert (elf_getdata (scn, data) == NULL); - assert (data->d_off == 0); - assert (data->d_size == dso->shdr[i].sh_size); - maxndx = dso->shdr[i].sh_size / dso->shdr[i].sh_entsize; - relbuf = malloc (maxndx * sizeof (REL)); - *reltype = dso->shdr[i].sh_type; - if (relbuf == NULL) - error (1, errno, "%s: Could not allocate memory", dso->filename); - - symdata = elf_getdata (dso->scn[dso->shdr[i].sh_link], NULL); - assert (symdata != NULL && symdata->d_buf != NULL); - assert (elf_getdata (dso->scn[dso->shdr[i].sh_link], symdata) == NULL); - assert (symdata->d_off == 0); - assert (symdata->d_size == dso->shdr[dso->shdr[i].sh_link].sh_size); - - for (ndx = 0, relend = relbuf; ndx < maxndx; ++ndx) - { - if (dso->shdr[i].sh_type == SHT_REL) - { - gelf_getrel (data, ndx, &rel); - rela.r_offset = rel.r_offset; - rela.r_info = rel.r_info; - rela.r_addend = 0; - } - else - gelf_getrela (data, ndx, &rela); - gelf_getsym (symdata, ELF64_R_SYM (rela.r_info), &sym); - /* Relocations against section symbols are uninteresting in REL. */ - if (dso->shdr[i].sh_type == SHT_REL && sym.st_value == 0) - continue; - /* Only consider relocations against .debug_str, .debug_line - and .debug_abbrev. */ - if (sym.st_shndx != debug_sections[DEBUG_STR].sec - && sym.st_shndx != debug_sections[DEBUG_LINE].sec - && sym.st_shndx != debug_sections[DEBUG_ABBREV].sec) - continue; - rela.r_addend += sym.st_value; - rtype = ELF64_R_TYPE (rela.r_info); - switch (dso->ehdr.e_machine) - { - case EM_SPARC: - case EM_SPARC32PLUS: - case EM_SPARCV9: - if (rtype != R_SPARC_32 && rtype != R_SPARC_UA32) - goto fail; - break; - case EM_386: - if (rtype != R_386_32) - goto fail; - break; - case EM_PPC: - case EM_PPC64: - if (rtype != R_PPC_ADDR32 && rtype != R_PPC_UADDR32) - goto fail; - break; - case EM_S390: - if (rtype != R_390_32) - goto fail; - break; - case EM_IA_64: - if (rtype != R_IA64_SECREL32LSB) - goto fail; - break; - case EM_X86_64: - if (rtype != R_X86_64_32) - goto fail; - break; - case EM_ALPHA: - if (rtype != R_ALPHA_REFLONG) - goto fail; - break; -#if defined(EM_AARCH64) && defined(R_AARCH64_ABS32) - case EM_AARCH64: - if (rtype != R_AARCH64_ABS32) - goto fail; - break; -#endif - case EM_68K: - if (rtype != R_68K_32) - goto fail; - break; -#if defined(EM_RISCV) && defined(R_RISCV_32) - case EM_RISCV: - if (rtype != R_RISCV_32) - goto fail; - break; -#endif - default: - fail: - error (1, 0, "%s: Unhandled relocation %d in %s section", - dso->filename, rtype, sec->name); - } - relend->ptr = sec->data - + (rela.r_offset - base); - relend->addend = rela.r_addend; - relend->ndx = ndx; - ++(relend); - } - if (relbuf == relend) - { - free (relbuf); - relbuf = NULL; - relend = NULL; - } - else - qsort (relbuf, relend - relbuf, sizeof (REL), rel_cmp); - - sec->relbuf = relbuf; - sec->relend = relend; - relptr = relbuf; -} - -/* Updates SHT_RELA section associated with the given section based on - the relbuf data. The relbuf data is freed at the end. */ -static void -update_rela_data (DSO *dso, struct debug_section *sec) -{ - Elf_Data *symdata; - int relsec_ndx = sec->relsec; - Elf_Data *data = elf_getdata (dso->scn[relsec_ndx], NULL); - symdata = elf_getdata (dso->scn[dso->shdr[relsec_ndx].sh_link], - NULL); - - relptr = sec->relbuf; - relend = sec->relend; - while (relptr < relend) - { - GElf_Sym sym; - GElf_Rela rela; - int ndx = relptr->ndx; - - if (gelf_getrela (data, ndx, &rela) == NULL) - error (1, 0, "Couldn't get relocation: %s", - elf_errmsg (-1)); - - if (gelf_getsym (symdata, GELF_R_SYM (rela.r_info), - &sym) == NULL) - error (1, 0, "Couldn't get symbol: %s", elf_errmsg (-1)); - - rela.r_addend = relptr->addend - sym.st_value; - - if (gelf_update_rela (data, ndx, &rela) == 0) - error (1, 0, "Couldn't update relocations: %s", - elf_errmsg (-1)); - - ++relptr; - } - elf_flagdata (data, ELF_C_SET, ELF_F_DIRTY); - - free (sec->relbuf); -} - struct abbrev_attr { unsigned int attr; @@ -1175,7 +969,6 @@ get_line_table (DSO *dso, size_t off, struct line_table **table) *table = NULL; t->old_idx = off; - t->new_idx = off; t->size_diff = 0; t->replace_dirs = false; t->replace_files = false; @@ -1949,6 +1742,20 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase) } static int +rel_cmp (const void *a, const void *b) +{ + REL *rela = (REL *) a, *relb = (REL *) b; + + if (rela->ptr < relb->ptr) + return -1; + + if (rela->ptr > relb->ptr) + return 1; + + return 0; +} + +static int line_rel_cmp (const void *a, const void *b) { LINE_REL *rela = (LINE_REL *) a, *relb = (LINE_REL *) b; @@ -1990,35 +1797,11 @@ edit_dwarf2 (DSO *dso) for (j = 0; debug_sections[j].name; ++j) if (strcmp (name, debug_sections[j].name) == 0) { - struct debug_section *debug_sec = &debug_sections[j]; if (debug_sections[j].data) { - if (j != DEBUG_MACRO) - { - error (0, 0, "%s: Found two copies of %s section", - dso->filename, name); - return 1; - } - else - { - /* In relocatable files .debug_macro might - appear multiple times as COMDAT - section. */ - struct debug_section *sec; - sec = calloc (sizeof (struct debug_section), 1); - if (sec == NULL) - error (1, errno, - "%s: Could not allocate more macro sections", - dso->filename); - sec->name = ".debug_macro"; - - struct debug_section *macro_sec = debug_sec; - while (macro_sec->next != NULL) - macro_sec = macro_sec->next; - - macro_sec->next = sec; - debug_sec = sec; - } + error (0, 0, "%s: Found two copies of %s section", + dso->filename, name); + return 1; } scn = dso->scn[i]; @@ -2027,10 +1810,10 @@ edit_dwarf2 (DSO *dso) assert (elf_getdata (scn, data) == NULL); assert (data->d_off == 0); assert (data->d_size == dso->shdr[i].sh_size); - debug_sec->data = data->d_buf; - debug_sec->elf_data = data; - debug_sec->size = data->d_size; - debug_sec->sec = i; + debug_sections[j].data = data->d_buf; + debug_sections[j].elf_data = data; + debug_sections[j].size = data->d_size; + debug_sections[j].sec = i; break; } @@ -2053,26 +1836,7 @@ edit_dwarf2 (DSO *dso) + (dso->shdr[i].sh_type == SHT_RELA), debug_sections[j].name) == 0) { - if (j == DEBUG_MACRO) - { - /* Pick the correct one. */ - int rel_target = dso->shdr[i].sh_info; - struct debug_section *macro_sec = &debug_sections[j]; - while (macro_sec != NULL) - { - if (macro_sec->sec == rel_target) - { - macro_sec->relsec = i; - break; - } - macro_sec = macro_sec->next; - } - if (macro_sec == NULL) - error (0, 1, "No .debug_macro reloc section: %s", - dso->filename); - } - else - debug_sections[j].relsec = i; + debug_sections[j].relsec = i; break; } } @@ -2105,8 +1869,132 @@ edit_dwarf2 (DSO *dso) htab_t abbrev; struct abbrev_tag tag, *t; int phase; - bool info_rel_updated = false; - bool macro_rel_updated = false; + REL *relbuf = NULL; + + if (debug_sections[DEBUG_INFO].relsec) + { + int ndx, maxndx; + GElf_Rel rel; + GElf_Rela rela; + GElf_Sym sym; + GElf_Addr base = dso->shdr[debug_sections[DEBUG_INFO].sec].sh_addr; + Elf_Data *symdata = NULL; + int rtype; + + i = debug_sections[DEBUG_INFO].relsec; + scn = dso->scn[i]; + data = elf_getdata (scn, NULL); + assert (data != NULL && data->d_buf != NULL); + assert (elf_getdata (scn, data) == NULL); + assert (data->d_off == 0); + assert (data->d_size == dso->shdr[i].sh_size); + maxndx = dso->shdr[i].sh_size / dso->shdr[i].sh_entsize; + relbuf = malloc (maxndx * sizeof (REL)); + reltype = dso->shdr[i].sh_type; + if (relbuf == NULL) + error (1, errno, "%s: Could not allocate memory", dso->filename); + + symdata = elf_getdata (dso->scn[dso->shdr[i].sh_link], NULL); + assert (symdata != NULL && symdata->d_buf != NULL); + assert (elf_getdata (dso->scn[dso->shdr[i].sh_link], symdata) + == NULL); + assert (symdata->d_off == 0); + assert (symdata->d_size + == dso->shdr[dso->shdr[i].sh_link].sh_size); + + for (ndx = 0, relend = relbuf; ndx < maxndx; ++ndx) + { + if (dso->shdr[i].sh_type == SHT_REL) + { + gelf_getrel (data, ndx, &rel); + rela.r_offset = rel.r_offset; + rela.r_info = rel.r_info; + rela.r_addend = 0; + } + else + gelf_getrela (data, ndx, &rela); + gelf_getsym (symdata, ELF64_R_SYM (rela.r_info), &sym); + /* Relocations against section symbols are uninteresting + in REL. */ + if (dso->shdr[i].sh_type == SHT_REL && sym.st_value == 0) + continue; + /* Only consider relocations against .debug_str, .debug_line + and .debug_abbrev. */ + if (sym.st_shndx != debug_sections[DEBUG_STR].sec + && sym.st_shndx != debug_sections[DEBUG_LINE].sec + && sym.st_shndx != debug_sections[DEBUG_ABBREV].sec) + continue; + rela.r_addend += sym.st_value; + rtype = ELF64_R_TYPE (rela.r_info); + switch (dso->ehdr.e_machine) + { + case EM_SPARC: + case EM_SPARC32PLUS: + case EM_SPARCV9: + if (rtype != R_SPARC_32 && rtype != R_SPARC_UA32) + goto fail; + break; + case EM_386: + if (rtype != R_386_32) + goto fail; + break; + case EM_PPC: + case EM_PPC64: + if (rtype != R_PPC_ADDR32 && rtype != R_PPC_UADDR32) + goto fail; + break; + case EM_S390: + if (rtype != R_390_32) + goto fail; + break; + case EM_IA_64: + if (rtype != R_IA64_SECREL32LSB) + goto fail; + break; + case EM_X86_64: + if (rtype != R_X86_64_32) + goto fail; + break; + case EM_ALPHA: + if (rtype != R_ALPHA_REFLONG) + goto fail; + break; +#if defined(EM_AARCH64) && defined(R_AARCH64_ABS32) + case EM_AARCH64: + if (rtype != R_AARCH64_ABS32) + goto fail; + break; +#endif + case EM_68K: + if (rtype != R_68K_32) + goto fail; + break; +#if defined(EM_RISCV) && defined(R_RISCV_32) + case EM_RISCV: + if (rtype != R_RISCV_32) + goto fail; + break; +#endif + default: + fail: + error (1, 0, "%s: Unhandled relocation %d in .debug_info section", + dso->filename, rtype); + } + relend->ptr = debug_sections[DEBUG_INFO].data + + (rela.r_offset - base); + relend->addend = rela.r_addend; + relend->ndx = ndx; + ++relend; + } + if (relbuf == relend) + { + free (relbuf); + relbuf = NULL; + relend = NULL; + } + else + qsort (relbuf, relend - relbuf, sizeof (REL), rel_cmp); + } for (phase = 0; phase < 2; phase++) { @@ -2118,8 +2006,7 @@ edit_dwarf2 (DSO *dso) break; ptr = debug_sections[DEBUG_INFO].data; - setup_relbuf(dso, &debug_sections[DEBUG_INFO], &reltype); - rel_updated = false; + relptr = relbuf; endsec = ptr + debug_sections[DEBUG_INFO].size; while (ptr < endsec) { @@ -2207,10 +2094,6 @@ edit_dwarf2 (DSO *dso) htab_delete (abbrev); } - /* Remember whether any .debug_info relocations might need - to be updated. */ - info_rel_updated = rel_updated; - /* We might have to recalculate/rewrite the debug_line section. We need to do that before going into phase one so we have all new offsets. We do this separately from @@ -2324,113 +2207,6 @@ edit_dwarf2 (DSO *dso) } } - /* The .debug_macro section also contains offsets into the - .debug_str section and references to the .debug_line - tables, so we need to update those as well if we update - the strings or the stmts. */ - if ((need_strp_update || need_stmt_update) - && debug_sections[DEBUG_MACRO].data) - { - /* There might be multiple (COMDAT) .debug_macro sections. */ - struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO]; - while (macro_sec != NULL) - { - setup_relbuf(dso, macro_sec, &reltype); - rel_updated = false; - - ptr = macro_sec->data; - endsec = ptr + macro_sec->size; - int op = 0, macro_version, macro_flags; - int offset_len = 4, line_offset = 0; - - while (ptr < endsec) - { - if (!op) - { - macro_version = read_16 (ptr); - macro_flags = read_8 (ptr); - if (macro_version < 4 || macro_version > 5) - error (1, 0, "unhandled .debug_macro version: %d", - macro_version); - if ((macro_flags & ~2) != 0) - error (1, 0, "unhandled .debug_macro flags: 0x%x", - macro_flags); - - offset_len = (macro_flags & 0x01) ? 8 : 4; - line_offset = (macro_flags & 0x02) ? 1 : 0; - - if (offset_len != 4) - error (0, 1, - "Cannot handle 8 byte macro offsets: %s", - dso->filename); - - /* Update the line_offset if it is there. */ - if (line_offset) - { - if (phase == 0) - ptr += offset_len; - else - { - size_t idx, new_idx; - idx = do_read_32_relocated (ptr); - new_idx = find_new_list_offs (&dso->lines, - idx); - write_32_relocated (ptr, new_idx); - } - } - } - - op = read_8 (ptr); - if (!op) - continue; - switch(op) - { - case DW_MACRO_GNU_define: - case DW_MACRO_GNU_undef: - read_uleb128 (ptr); - ptr = ((unsigned char *) strchr ((char *) ptr, '\0') - + 1); - break; - case DW_MACRO_GNU_start_file: - read_uleb128 (ptr); - read_uleb128 (ptr); - break; - case DW_MACRO_GNU_end_file: - break; - case DW_MACRO_GNU_define_indirect: - case DW_MACRO_GNU_undef_indirect: - read_uleb128 (ptr); - if (phase == 0) - { - size_t idx = read_32_relocated (ptr); - record_existing_string_entry_idx (&dso->strings, - idx); - } - else - { - struct stridxentry *entry; - size_t idx, new_idx; - idx = do_read_32_relocated (ptr); - entry = string_find_entry (&dso->strings, idx); - new_idx = strent_offset (entry->entry); - write_32_relocated (ptr, new_idx); - } - break; - case DW_MACRO_GNU_transparent_include: - ptr += offset_len; - break; - default: - error (1, 0, "Unhandled DW_MACRO op 0x%x", op); - break; - } - } - - if (rel_updated) - macro_rel_updated = true; - macro_sec = macro_sec->next; - } - } - /* Same for the debug_str section. Make sure everything is in place for phase 1 updating of debug_info references. */ @@ -2460,24 +2236,43 @@ edit_dwarf2 (DSO *dso) new strp, strings and/or linep offsets. */ if (need_strp_update || need_string_replacement || need_stmt_update) dirty_section (DEBUG_INFO); - if (need_strp_update || need_stmt_update) - dirty_section (DEBUG_MACRO); - if (need_stmt_update) - dirty_section (DEBUG_LINE); - /* Update any relocations addends we might have touched. */ - if (info_rel_updated) - update_rela_data (dso, &debug_sections[DEBUG_INFO]); - - if (macro_rel_updated) + /* Update any debug_info relocations addends we might have touched. */ + if (relbuf != NULL && reltype == SHT_RELA) { - struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO]; - while (macro_sec != NULL) + Elf_Data *symdata; + int relsec_ndx = debug_sections[DEBUG_INFO].relsec; + data = elf_getdata (dso->scn[relsec_ndx], NULL); + symdata = elf_getdata (dso->scn[dso->shdr[relsec_ndx].sh_link], + NULL); + + relptr = relbuf; + while (relptr < relend) { - update_rela_data (dso, macro_sec); - macro_sec = macro_sec->next; + GElf_Sym sym; + GElf_Rela rela; + int ndx = relptr->ndx; + + if (gelf_getrela (data, ndx, &rela) == NULL) + error (1, 0, "Couldn't get relocation: %s", + elf_errmsg (-1)); + + if (gelf_getsym (symdata, GELF_R_SYM (rela.r_info), + &sym) == NULL) + error (1, 0, "Couldn't get symbol: %s", elf_errmsg (-1)); + + rela.r_addend = relptr->addend - sym.st_value; + + if (gelf_update_rela (data, ndx, &rela) == 0) + error (1, 0, "Couldn't update relocations: %s", + elf_errmsg (-1)); + + ++relptr; } + elf_flagdata (data, ELF_C_SET, ELF_F_DIRTY); } + + free (relbuf); } return 0; @@ -3001,17 +2796,6 @@ main (int argc, char *argv[]) destroy_lines (&dso->lines); free (dso); - /* In case there were multiple (COMDAT) .debug_macro sections, - free them. */ - struct debug_section *macro_sec = &debug_sections[DEBUG_MACRO]; - macro_sec = macro_sec->next; - while (macro_sec != NULL) - { - struct debug_section *next = macro_sec->next; - free (macro_sec); - macro_sec = next; - } - poptFreeContext (optCon); return 0;