static rpmRC includeFileSignatures(Header *sigp, Header *hdrp) { #ifdef WITH_IMAEVM rpmRC rc; char *key; char *keypass; key = rpmExpand("%{?_file_signing_key}", NULL); keypass = rpmExpand("%{?_file_signing_key_password}", NULL); if (rstreq(keypass, "")) { free(keypass); keypass = NULL; } rc = rpmSignFiles(*sigp, *hdrp, key, keypass); free(keypass); free(key); return rc; #else rpmlog(RPMLOG_ERR, _("file signing support not built in\n")); return RPMRC_FAIL; #endif }
static int checkForValidArchitectures(Spec spec) /*@globals rpmGlobalMacroContext, h_errno, internalState @*/ /*@modifies rpmGlobalMacroContext, internalState @*/ { const char *arch = rpmExpand("%{_target_cpu}", NULL); const char *os = rpmExpand("%{_target_os}", NULL); int rc = RPMRC_FAIL; /* assume failure. */ if (isMemberInEntry(spec->sourceHeader, arch, RPMTAG_EXCLUDEARCH) == 1) { rpmlog(RPMLOG_ERR, _("Architecture is excluded: %s\n"), arch); goto exit; } if (isMemberInEntry(spec->sourceHeader, arch, RPMTAG_EXCLUSIVEARCH) == 0) { rpmlog(RPMLOG_ERR, _("Architecture is not included: %s\n"), arch); goto exit; } if (isMemberInEntry(spec->sourceHeader, os, RPMTAG_EXCLUDEOS) == 1) { rpmlog(RPMLOG_ERR, _("OS is excluded: %s\n"), os); goto exit; } if (isMemberInEntry(spec->sourceHeader, os, RPMTAG_EXCLUSIVEOS) == 0) { rpmlog(RPMLOG_ERR, _("OS is not included: %s\n"), os); goto exit; } rc = 0; exit: arch = _free(arch); os = _free(os); return rc; }
static void addTargets(Package Pkgs) { char *platform = rpmExpand("%{_target_platform}", NULL); char *arch = rpmExpand("%{_target_cpu}", NULL); char *os = rpmExpand("%{_target_os}", NULL); char *optflags = rpmExpand("%{optflags}", NULL); for (Package pkg = Pkgs; pkg != NULL; pkg = pkg->next) { headerPutString(pkg->header, RPMTAG_OS, os); /* noarch subpackages already have arch set here, leave it alone */ if (!headerIsEntry(pkg->header, RPMTAG_ARCH)) { headerPutString(pkg->header, RPMTAG_ARCH, arch); } headerPutString(pkg->header, RPMTAG_PLATFORM, platform); headerPutString(pkg->header, RPMTAG_OPTFLAGS, optflags); /* Add manual dependencies early for rpmspec etc to look at */ addPackageProvides(pkg); for (int i=0; i<PACKAGE_NUM_DEPS; i++) { rpmdsPutToHeader(pkg->dependencies[i], pkg->header); } pkg->ds = rpmdsThis(pkg->header, RPMTAG_REQUIRENAME, RPMSENSE_EQUAL); } free(platform); free(arch); free(os); free(optflags); }
static char *rpmfcAttrMacro(const char *name, const char *attr_prefix, const char *attr) { char *ret; if (attr_prefix && attr_prefix[0] != '\0') ret = rpmExpand("%{?__", name, "_", attr_prefix, "_", attr, "}", NULL); else ret = rpmExpand("%{?__", name, "_", attr, "}", NULL); return rstreq(ret, "") ? _free(ret) : ret; }
/* TODO: permit overriding macro setup on the command line */ static int doSign(poptContext optCon) { int rc = EXIT_FAILURE; char * passPhrase = NULL; char * name = rpmExpand("%{?_gpg_name}", NULL); struct rpmSignArgs sig = {NULL, 0, 0}; char *key = NULL; if (rstreq(name, "")) { fprintf(stderr, _("You must set \"%%_gpg_name\" in your macro file\n")); goto exit; } if (fileSigningKey) { addMacro(NULL, "_file_signing_key", NULL, fileSigningKey, RMIL_GLOBAL); } if (signfiles) { key = rpmExpand("%{?_file_signing_key}", NULL); if (rstreq(key, "")) { fprintf(stderr, _("You must set \"$$_file_signing_key\" in your macro file or on the command line with --fskpath\n")); goto exit; } if (fskpass) { #ifndef WITH_IMAEVM argerror(_("--fskpass may only be specified when signing files")); #else fileSigningKeyPassword = get_fskpass(); #endif } addMacro(NULL, "_file_signing_key_password", NULL, fileSigningKeyPassword, RMIL_CMDLINE); if (fileSigningKeyPassword) { memset(fileSigningKeyPassword, 0, strlen(fileSigningKeyPassword)); free(fileSigningKeyPassword); } sig.signfiles = 1; } const char *arg; rc = 0; while ((arg = poptGetArg(optCon)) != NULL) { rc += rpmPkgSign(arg, &sig); } exit: free(key); free(passPhrase); free(name); return rc; }
rpmRC rpmtsSetupTransactionPlugins(rpmts ts) { rpmRC rc = RPMRC_OK; ARGV_t files = NULL; int nfiles = 0; char *dsoPath = NULL; /* * Assume allocated equals initialized. There are some oddball cases * (verification of non-installed package) where this is not true * currently but that's not a new issue. */ if ((rpmtsFlags(ts) & RPMTRANS_FLAG_NOPLUGINS) || ts->plugins != NULL) return RPMRC_OK; dsoPath = rpmExpand("%{__plugindir}/*.so", NULL); if (rpmGlob(dsoPath, &nfiles, &files) == 0) { rpmPlugins tsplugins = rpmtsPlugins(ts); for (int i = 0; i < nfiles; i++) { char *bn = basename(files[i]); bn[strlen(bn)-strlen(".so")] = '\0'; if (rpmpluginsAddPlugin(tsplugins, "transaction", bn) == RPMRC_FAIL) rc = RPMRC_FAIL; } files = argvFree(files); } free(dsoPath); return rc; }
/* * Add extra provides to package. */ static void addPackageProvides(Header h) { const char *name = NULL, *arch = NULL; char *evr, *isaprov; rpmsenseFlags pflags = RPMSENSE_EQUAL; int noarch = 0; struct rpmtd_s archtd; /* <name> = <evr> provide */ evr = headerGetEVR(h, &name); headerPutString(h, RPMTAG_PROVIDENAME, name); headerPutString(h, RPMTAG_PROVIDEVERSION, evr); headerPutUint32(h, RPMTAG_PROVIDEFLAGS, &pflags, 1); /* * <name>(<isa>) = <evr> provide * FIXME: noarch needs special casing for now as BuildArch: noarch doesn't * cause reading in the noarch macros :-/ */ isaprov = rpmExpand(name, "%{?_isa}", NULL); headerGet(h, RPMTAG_ARCH, &archtd, HEADERGET_MINMEM); arch = rpmtdGetString(&archtd); noarch = (strcmp(arch, "noarch") == 0); if (!noarch && strcmp(name, isaprov)) { headerPutString(h, RPMTAG_PROVIDENAME, isaprov); headerPutString(h, RPMTAG_PROVIDEVERSION, evr); headerPutUint32(h, RPMTAG_PROVIDEFLAGS, &pflags, 1); } free(isaprov); free(evr); }
rpmRC packageSources(rpmSpec spec, char **cookie) { Package sourcePkg = spec->sourcePackage; rpmRC rc; uint32_t one = 1; /* Add some cruft */ headerPutString(sourcePkg->header, RPMTAG_RPMVERSION, VERSION); headerPutString(sourcePkg->header, RPMTAG_BUILDHOST, buildHost()); headerPutUint32(sourcePkg->header, RPMTAG_BUILDTIME, getBuildTime(), 1); headerPutUint32(sourcePkg->header, RPMTAG_SOURCEPACKAGE, &one, 1); /* XXX this should be %_srpmdir */ { char *fn = rpmGetPath("%{_srcrpmdir}/", spec->sourceRpmName,NULL); char *pkgcheck = rpmExpand("%{?_build_pkgcheck_srpm} ", fn, NULL); spec->sourcePkgId = NULL; rc = writeRPM(sourcePkg, &spec->sourcePkgId, fn, cookie); /* Do check SRPM package if enabled */ if (rc == RPMRC_OK && pkgcheck[0] != ' ') { rc = checkPackages(pkgcheck); } free(pkgcheck); free(fn); } return rc; }
static const char * buildHost(void) { static char hostname[1024]; static int oneshot = 0; struct hostent *hbn; char *bhMacro; if (! oneshot) { bhMacro = rpmExpand("%{?_buildhost}", NULL); if (strcmp(bhMacro, "") != 0 && strlen(bhMacro) < 1024) { strcpy(hostname, bhMacro); } else { if (strcmp(bhMacro, "") != 0) rpmlog(RPMLOG_WARNING, _("The _buildhost macro is too long\n")); (void) gethostname(hostname, sizeof(hostname)); hbn = gethostbyname(hostname); if (hbn) strcpy(hostname, hbn->h_name); else rpmlog(RPMLOG_WARNING, _("Could not canonicalize hostname: %s\n"), hostname); } free(bhMacro); oneshot = 1; } return(hostname); }
nsType rpmnsArch(const char * str) { nsType rc = RPMNS_TYPE_UNKNOWN; const char ** av; #if defined(RPM_VENDOR_WINDRIVER) const char * known_arch = rpmExpand("%{?_known_arch}", NULL); const char *p, *pe, *t; for (p = pe = known_arch ; rc == RPMNS_TYPE_UNKNOWN && pe && *pe ; ) { while (*p && xisspace(*p)) p++; pe = p ; while (*pe && !xisspace(*pe)) pe++; if (p == pe) break; t = strndup(p, (pe - p)); p = pe; if (!strcmp(str, t)) rc = RPMNS_TYPE_ARCH; t = _free(t); } known_arch = _free(known_arch); #endif if (rc == RPMNS_TYPE_UNKNOWN) for (av = rpmnsArches; *av != NULL; av++) { if (strcmp(str, *av)) continue; rc = RPMNS_TYPE_ARCH; break; } return rc; }
static const char * rpmcliEvalSlurp(const char * arg) /*@globals rpmGlobalMacroContext @*/ /*@modifies rpmGlobalMacroContext @*/ { const char * pre = ""; const char * post = ""; rpmiob iob = NULL; const char * val = NULL; struct stat sb; int xx; if (!strcmp(arg, "-")) { /* Macros from stdin arg. */ xx = rpmiobSlurp(arg, &iob); } else if ((arg[0] == '/' || strchr(arg, ' ') == NULL) && !Stat(arg, &sb) && S_ISREG(sb.st_mode)) { /* Macros from a file arg. */ xx = rpmiobSlurp(arg, &iob); } else { /* Macros from string arg. */ iob = rpmiobAppend(rpmiobNew(strlen(arg)+1), arg, 0); } val = rpmExpand(pre, iob->b, post, NULL); iob = rpmiobFree(iob); return val; }
static rpmScript rpmScriptNew(Header h, rpmTagVal tag, const char *body, rpmscriptFlags flags) { char *nevra = headerGetAsString(h, RPMTAG_NEVRA); rpmScript script = xcalloc(1, sizeof(*script)); script->tag = tag; script->flags = flags; script->body = (body != NULL) ? xstrdup(body) : NULL; rasprintf(&script->descr, "%s(%s)", tag2sln(tag), nevra); /* macros need to be expanded before possible queryformat */ if (script->body && (script->flags & RPMSCRIPT_FLAG_EXPAND)) { char *body = rpmExpand(script->body, NULL); free(script->body); script->body = body; } if (script->body && (script->flags & RPMSCRIPT_FLAG_QFORMAT)) { /* XXX TODO: handle queryformat errors */ char *body = headerFormat(h, script->body, NULL); free(script->body); script->body = body; } free(nevra); return script; }
int rpmExpandNumeric(const char *arg) { char *val; int rc; if (arg == NULL) return 0; val = rpmExpand(arg, NULL); if (!(val && *val != '%')) rc = 0; else if (*val == 'Y' || *val == 'y') rc = 1; else if (*val == 'N' || *val == 'n') rc = 0; else { char *end; rc = strtol(val, &end, 0); if (!(end && *end == '\0')) rc = 0; } val = _free(val); return rc; }
rpmRC rpmpluginsAddPlugin(rpmPlugins plugins, const char *type, const char *name) { char *path; char *options; rpmRC rc = RPMRC_FAIL; path = rpmExpand("%{?__", type, "_", name, "}", NULL); if (!path || rstreq(path, "")) { rpmlog(RPMLOG_ERR, _("Failed to expand %%__%s_%s macro\n"), type, name); goto exit; } /* split the options from the path */ #define SKIPSPACE(s) { while (*(s) && risspace(*(s))) (s)++; } #define SKIPNONSPACE(s) { while (*(s) && !risspace(*(s))) (s)++; } options = path; SKIPNONSPACE(options); if (risspace(*options)) { *options = '\0'; options++; SKIPSPACE(options); } if (*options == '\0') { options = NULL; } rc = rpmpluginsAdd(plugins, name, path, options); exit: _free(path); return rc; }
static void fillOutMainPackage(Header h) /*@globals rpmGlobalMacroContext, h_errno, internalState @*/ /*@modifies h, rpmGlobalMacroContext, internalState @*/ { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); struct optionalTag *ot; int xx; for (ot = optionalTags; ot->ot_mac != NULL; ot++) { const char * val; rpmTag tag; tag = ot->ot_tag; /* Generate arbitrary tag (if necessary). */ if (tag == 0xffffffff) { val = tagCanonicalize(ot->ot_mac + (sizeof("%{")-1)); tag = tagGenerate(val); val = _free(val); } if (headerIsEntry(h, tag)) continue; val = rpmExpand(ot->ot_mac, NULL); if (val && *val != '%') { he->tag = tag; he->t = RPM_STRING_TYPE; he->p.str = val; he->c = 1; xx = headerPut(h, he, 0); } val = _free(val); } }
int urlGetFile(const char * url, const char * dest) { char *cmd = NULL; const char *target = NULL; char *urlhelper = NULL; int rc; pid_t pid, wait; urlhelper = rpmExpand("%{?_urlhelper}", NULL); if (dest == NULL) { urlPath(url, &target); } else { target = dest; } /* XXX TODO: sanity checks like target == dest... */ rasprintf(&cmd, "%s %s %s", urlhelper, target, url); urlhelper = _free(urlhelper); if ((pid = fork()) == 0) { ARGV_t argv = NULL; argvSplit(&argv, cmd, " "); execvp(argv[0], argv); exit(127); /* exit with 127 for compatibility with bash(1) */ } wait = waitpid(pid, &rc, 0); cmd = _free(cmd); return rc; }
static rpmRC tagValidate(Spec spec, rpmTag tag, const char * value) /*@*/ { const char * tagN = tagName(tag); const char * pattern = rpmExpand("%{?pattern_", tagN, "}", NULL); rpmRC ec = RPMRC_OK; if (pattern && *pattern) { miRE mire; int xx; mire = mireNew(RPMMIRE_REGEX, tag); xx = mireSetCOptions(mire, RPMMIRE_REGEX, 0, 0, NULL); if (!xx) xx = mireRegcomp(mire, pattern); if (!xx) xx = mireRegexec(mire, value, strlen(value)); if (!xx) ec = RPMRC_OK; else { rpmlog(RPMLOG_ERR, _("line %d: invalid tag value(\"%s\") %s: %s\n"), spec->lineNum, pattern, tagN, spec->line); ec = RPMRC_FAIL; } mire = mireFree(mire); } pattern = _free(pattern); return ec; }
/*@null@*/ static FD_t rpmgiOpen(const char * path, const char * fmode) /*@globals rpmGlobalMacroContext, h_errno, errno, internalState @*/ /*@modifies rpmGlobalMacroContext, h_errno, errno, internalState @*/ { const char * fn = rpmExpand(path, NULL); FD_t fd; /* FIXME (see http://rpm5.org/community/rpm-devel/0523.html) */ errno = 0; fd = Fopen(fn, fmode); if (fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), fn, Fstrerror(fd)); if (fd != NULL) (void) Fclose(fd); fd = NULL; } fn = _free(fn); #if defined(POSIX_FADV_WILLNEED) if(fd != NULL) (void) Fadvise(fd, 0, 0, POSIX_FADV_WILLNEED); #endif return fd; }
/*@-globs -internalglobs -mods @*/ char * _GetPass(const char * prompt) { char * pw; /*@-unrecog@*/ pw = getpass( prompt ? prompt : "" ); /*@=unrecog@*/ #if defined(HAVE_KEYUTILS_H) if (_kuKeyring == 0) { const char * _keyutils_keyring = rpmExpand("%{?_keyutils_keyring}", NULL); _kuKeyring = (rpmuint32_t) kuValue(_keyutils_keyring); if (_kuKeyring == 0) _kuKeyring = KEY_SPEC_PROCESS_KEYRING; _keyutils_keyring = _free(_keyutils_keyring); } if (pw && *pw) { key_serial_t keyring = (key_serial_t) _kuKeyring; size_t npw = strlen(pw); (void) add_key("user", "rpm:passwd", pw, npw, keyring); (void) memset(pw, 0, npw); /* burn the password */ pw = (char *) "@u user rpm:passwd"; } #endif /* HAVE_KEYUTILS_H */ assert(pw != NULL); /*@-observertrans -statictrans@*/ return pw; /*@=observertrans =statictrans@*/ }
int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) { char * const * arg; char *qfmt = NULL; int numFailed = 0; int numPackages = 0; rpmVSFlags vsflags, ovsflags; if (argv == NULL) return 0; vsflags = setvsFlags(ia); ovsflags = rpmtsSetVSFlags(ts, vsflags); (void) rpmtsSetFlags(ts, ia->transFlags); setNotifyFlag(ia, ts); qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL); for (arg = argv; *arg; arg++) { rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); int matches = rpmdbGetIteratorCount(mi); int erasing = 1; if (! matches) { rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg); numFailed++; } else { Header h; /* XXX iterator owns the reference */ if (matches > 1 && !(ia->installInterfaceFlags & UNINSTALL_ALLMATCHES)) { rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages:\n"), *arg); numFailed++; erasing = 0; } while ((h = rpmdbNextIterator(mi)) != NULL) { if (erasing) { (void) rpmtsAddEraseElement(ts, h, -1); numPackages++; } else { char *nevra = headerFormat(h, qfmt, NULL); rpmlog(RPMLOG_NOTICE, " %s", nevra); free(nevra); } } } rpmdbFreeIterator(mi); } free(qfmt); if (numFailed) goto exit; numFailed = rpmcliTransaction(ts, ia, numPackages); exit: rpmtsEmpty(ts); rpmtsSetVSFlags(ts, ovsflags); return numFailed; }
rpmRC packageSources(rpmSpec spec, char **cookie) { struct cpioSourceArchive_s csabuf; CSA_t csa = &csabuf; rpmRC rc; /* Add some cruft */ headerPutString(spec->sourceHeader, RPMTAG_RPMVERSION, VERSION); headerPutString(spec->sourceHeader, RPMTAG_BUILDHOST, buildHost()); headerPutUint32(spec->sourceHeader, RPMTAG_BUILDTIME, getBuildTime(), 1); /* XXX this should be %_srpmdir */ { char *fn = rpmGetPath("%{_srcrpmdir}/", spec->sourceRpmName,NULL); char *pkgcheck = rpmExpand("%{?_build_pkgcheck_srpm} ", fn, NULL); memset(csa, 0, sizeof(*csa)); csa->cpioArchiveSize = 0; csa->cpioFdIn = fdNew(); csa->cpioList = rpmfiLink(spec->sourceCpioList); spec->sourcePkgId = NULL; rc = writeRPM(&spec->sourceHeader, &spec->sourcePkgId, fn, csa, cookie); /* Do check SRPM package if enabled */ if (rc == RPMRC_OK && pkgcheck[0] != ' ') { rc = checkPackages(pkgcheck); } csa->cpioList = rpmfiFree(csa->cpioList); csa->cpioFdIn = fdFree(csa->cpioFdIn); pkgcheck = _free(pkgcheck); fn = _free(fn); } return rc; }
/* * Add extra provides to package. */ static void addPackageProvides(Header h) { const char *arch, *name; char *evr, *isaprov; rpmsenseFlags pflags = RPMSENSE_EQUAL; /* <name> = <evr> provide */ name = headerGetString(h, RPMTAG_NAME); arch = headerGetString(h, RPMTAG_ARCH); evr = headerGetAsString(h, RPMTAG_EVR); headerPutString(h, RPMTAG_PROVIDENAME, name); headerPutString(h, RPMTAG_PROVIDEVERSION, evr); headerPutUint32(h, RPMTAG_PROVIDEFLAGS, &pflags, 1); /* * <name>(<isa>) = <evr> provide * FIXME: noarch needs special casing for now as BuildArch: noarch doesn't * cause reading in the noarch macros :-/ */ isaprov = rpmExpand(name, "%{?_isa}", NULL); if (!rstreq(arch, "noarch") && !rstreq(name, isaprov)) { headerPutString(h, RPMTAG_PROVIDENAME, isaprov); headerPutString(h, RPMTAG_PROVIDEVERSION, evr); headerPutUint32(h, RPMTAG_PROVIDEFLAGS, &pflags, 1); } free(isaprov); free(evr); }
/** * @todo Create transaction set *much* earlier. */ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char * fmodeMacro) { rpmts ts = rpmtsCreate(); rpmfi fi = csa->cpioList; rpmte te = NULL; rpmfs fs = NULL; char *failedFile = NULL; FD_t cfd; rpmRC rc = RPMRC_OK; int xx, i; { char *fmode = rpmExpand(fmodeMacro, NULL); if (!(fmode && fmode[0] == 'w')) fmode = xstrdup("w9.gzdio"); (void) Fflush(fdo); cfd = Fdopen(fdDup(Fileno(fdo)), fmode); fmode = _free(fmode); } if (cfd == NULL) return RPMRC_FAIL; /* make up a transaction element for passing to fsm */ rpmtsAddInstallElement(ts, h, NULL, 0, NULL); te = rpmtsElement(ts, 0); fs = rpmteGetFileStates(te); fi = rpmfiInit(fi, 0); while ((i = rpmfiNext(fi)) >= 0) { if (rpmfiFFlags(fi) & RPMFILE_GHOST) rpmfsSetAction(fs, i, FA_SKIP); else rpmfsSetAction(fs, i, FA_COPYOUT); } xx = fsmSetup(rpmfiFSM(fi), FSM_PKGBUILD, ts, te, fi, cfd, &csa->cpioArchiveSize, &failedFile); if (xx) rc = RPMRC_FAIL; (void) Fclose(cfd); xx = fsmTeardown(rpmfiFSM(fi)); if (rc == RPMRC_OK && xx) rc = RPMRC_FAIL; if (rc) { if (failedFile) rpmlog(RPMLOG_ERR, _("create archive failed on file %s: %s\n"), failedFile, cpioStrerror(rc)); else rpmlog(RPMLOG_ERR, _("create archive failed: %s\n"), cpioStrerror(rc)); rc = RPMRC_FAIL; } rpmtsEmpty(ts); failedFile = _free(failedFile); ts = rpmtsFree(ts); return rc; }
static int rpm_expand(lua_State *L) /*@globals rpmGlobalMacroContext, h_errno, internalState @*/ /*@modifies L, rpmGlobalMacroContext, internalState @*/ { const char *str = luaL_checkstring(L, 1); lua_pushstring(L, rpmExpand(str, NULL)); return 1; }
static int rpm_expand(lua_State *L) { const char *str = luaL_checkstring(L, 1); char *val = rpmExpand(str, NULL); lua_pushstring(L, val); free(val); return 1; }
/** * Retrieve i18n text. * @param h header * @param tag tag * @retval td tag data container * @param hgflags header get flags * @return 1 on success */ static int i18nTag(Header h, rpmTag tag, rpmtd td, headerGetFlags hgflags) { int rc; #if defined(ENABLE_NLS) char * dstring = rpmExpand(_macro_i18ndomains, 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'; msgid = dgettext(domain, msgkey); if (msgid != msgkey) break; } /* 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; }
/*@null@*/ /*@observer@*/ static const char * filetriggers_dir(void) /*@globals _filetriggers_dir, rpmGlobalMacroContext, h_errno, internalState @*/ /*@modifies _filetriggers_dir, rpmGlobalMacroContext, internalState @*/ { if (_filetriggers_dir == NULL) _filetriggers_dir = rpmExpand("%{?_filetriggers_dir}", NULL); return (_filetriggers_dir != NULL && _filetriggers_dir[0] != '\0') ? _filetriggers_dir : NULL; }
static void trimChangelog(Header h) { static int oneshot; static int cuttime, minnum, maxnum; int * times; char ** names = 0, ** texts = 0; int i, keep, count = 0; if (!oneshot) { char *binarychangelogtrim = rpmExpand("%{?_binarychangelogtrim}", NULL); oneshot = 1; if (binarychangelogtrim && *binarychangelogtrim) { maxnum = atoi(binarychangelogtrim); binarychangelogtrim = strchr(binarychangelogtrim, ','); if (binarychangelogtrim) binarychangelogtrim++; } if (binarychangelogtrim && *binarychangelogtrim) { cuttime = atoi(binarychangelogtrim); binarychangelogtrim = strchr(binarychangelogtrim, ','); if (binarychangelogtrim) binarychangelogtrim++; } if (binarychangelogtrim && *binarychangelogtrim) { minnum = atoi(binarychangelogtrim); binarychangelogtrim = strchr(binarychangelogtrim, ','); } } if (!cuttime && !minnum && !maxnum) { return; } if (!headerGetEntry(h, RPMTAG_CHANGELOGTIME, NULL, (void **) ×, &count)) return; if ((!cuttime || count <= minnum) && (!maxnum || count <= maxnum)) { return; } keep = count; if (maxnum && keep > maxnum) keep = maxnum; if (cuttime) { for (i = 0; i < keep; i++) { if (i >= minnum && times[i] < cuttime) break; } keep = i; } if (keep >= count) return; headerGetEntry(h, RPMTAG_CHANGELOGNAME, NULL, (void **) &names, &count); headerGetEntry(h, RPMTAG_CHANGELOGTEXT, NULL, (void **) &texts, &count); headerModifyEntry(h, RPMTAG_CHANGELOGTIME, RPM_INT32_TYPE, times, keep); headerModifyEntry(h, RPMTAG_CHANGELOGNAME, RPM_STRING_ARRAY_TYPE, names, keep); headerModifyEntry(h, RPMTAG_CHANGELOGTEXT, RPM_STRING_ARRAY_TYPE, texts, keep); free(names); free(texts); }
static char * expandFormat(rpmtd td) { char *val = NULL; if (rpmtdClass(td) != RPM_STRING_CLASS) { val = xstrdup(_("(not a string)")); } else { val = rpmExpand(td->data, NULL); } return val; }
static PyObject * archScore(PyObject * s, PyObject * args, PyObject * kwds) { char * arch; char * platform; int score; char * kwlist[] = {"arch", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &arch)) return NULL; #if defined(RPM_VENDOR_WINDRIVER) platform = rpmExpand(arch, "-%{_host_vendor}", "-%{_host_os}%{?_gnu}", NULL); #else platform = rpmExpand(arch, "-", "%{_vendor}", "-", "%{_os}", NULL); #endif score = rpmPlatformScore(platform, NULL, 0); platform = _free(platform); return Py_BuildValue("i", score); }