static rpmVSFlags setvsFlags(struct rpmInstallArguments_s * ia) { rpmVSFlags vsflags; if (ia->installInterfaceFlags & (INSTALL_UPGRADE | INSTALL_ERASE)) vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); else vsflags = rpmExpandNumeric("%{?_vsflags_install}"); vsflags |= rpmcliVSFlags; return vsflags; }
static rpmVSFlags setvsFlags(struct rpmInstallArguments_s * ia) { rpmVSFlags vsflags; if (ia->installInterfaceFlags & (INSTALL_UPGRADE | INSTALL_ERASE)) vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); else vsflags = rpmExpandNumeric("%{?_vsflags_install}"); if (rpmcliQueryFlags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (rpmcliQueryFlags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; if (rpmcliQueryFlags & VERIFY_HDRCHK) vsflags |= RPMVSF_NOHDRCHK; return vsflags; }
int main(int argc, char *argv[]) { rpmts ts = NULL; enum modes bigMode = MODE_INSTALL; struct rpmInstallArguments_s *ia = &rpmIArgs; poptContext optCon; int ec = 0; int ret = 0; char rpmFile[1][PATH_MAX]; memset(&rpmFile,0,PATH_MAX); snprintf(rpmFile[0],PATH_MAX,"%s",argv[1]); char *p[2]; p[0] = ""; p[1] = (char *)&rpmFile[0]; optCon = rpmcliInit(2, p, optionsTable); printf("\n argc[%d],bigmode[%s]\n",argc,bigMode == MODE_UNKNOWN?"unknow":"others"); ia->installInterfaceFlags = INSTALL_INSTALL | INSTALL_LABEL | INSTALL_PERCENT; ts = rpmtsCreate(); rpmtsSetRootDir(ts, rpmcliRootDir); if (!ia->incldocs) { if (rpmExpandNumeric("%{_excludedocs}")) ia->transFlags |= RPMTRANS_FLAG_NODOCS; } if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; if (ia->prefix) { ia->relocations = malloc(2 * sizeof(*ia->relocations)); ia->relocations[0].oldPath = NULL; /* special case magic */ ia->relocations[0].newPath = ia->prefix; ia->relocations[1].oldPath = NULL; ia->relocations[1].newPath = NULL; } else if (ia->relocations) { ia->relocations = realloc(ia->relocations, sizeof(*ia->relocations) * (ia->numRelocations + 1)); ia->relocations[ia->numRelocations].oldPath = NULL; ia->relocations[ia->numRelocations].newPath = NULL; } ret= rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon)); printf("\n ret[%d]\n",ret); rpmtsFree(ts); ts = NULL; rpmcliFini(optCon); return 0; }
int rpmcliVerify(rpmts ts, QVA_t qva, char * const * argv) { rpmVSFlags vsflags, ovsflags; int ec = 0, xx; const char * rootDir = rpmtsRootDir(ts); /* * Open the DB + indices explicitly before possible chroot, * otherwises BDB is going to be unhappy... */ rpmtsOpenDB(ts, O_RDONLY); rpmdbOpenAll(rpmtsGetRdb(ts)); if (rootDir && strcmp(rootDir, "/") != 0) { if (chroot(rootDir) == -1) { rpmlog(RPMLOG_ERR, _("Unable to change root directory: %m\n")); ec = 1; goto exit; } else { rpmtsSetChrootDone(ts, 1); } } if (qva->qva_showPackage == NULL) qva->qva_showPackage = showVerifyPackage; /* XXX verify flags are inverted from query. */ vsflags = rpmExpandNumeric("%{?_vsflags_verify}"); if (!(qva->qva_flags & VERIFY_DIGEST)) vsflags |= _RPMVSF_NODIGESTS; if (!(qva->qva_flags & VERIFY_SIGNATURE)) vsflags |= _RPMVSF_NOSIGNATURES; if (!(qva->qva_flags & VERIFY_HDRCHK)) vsflags |= RPMVSF_NOHDRCHK; vsflags &= ~RPMVSF_NEEDPAYLOAD; ovsflags = rpmtsSetVSFlags(ts, vsflags); ec = rpmcliArgIter(ts, qva, argv); vsflags = rpmtsSetVSFlags(ts, ovsflags); if (qva->qva_showPackage == showVerifyPackage) qva->qva_showPackage = NULL; rpmtsEmpty(ts); if (rpmtsChrootDone(ts)) { /* only done if previous chroot succeeded, assume success */ xx = chroot("."); rpmtsSetChrootDone(ts, 0); } exit: return ec; }
int rpmcliVerify(rpmts ts, QVA_t qva, char * const * argv) { rpmVSFlags vsflags, ovsflags; int ec = 0; FD_t scriptFd = fdDup(STDOUT_FILENO); /* * Open the DB + indices explicitly before possible chroot, * otherwises BDB is going to be unhappy... */ rpmtsOpenDB(ts, O_RDONLY); rpmdbOpenAll(rpmtsGetRdb(ts)); if (rpmChrootSet(rpmtsRootDir(ts)) || rpmChrootIn()) { ec = 1; goto exit; } if (qva->qva_showPackage == NULL) qva->qva_showPackage = showVerifyPackage; vsflags = rpmExpandNumeric("%{?_vsflags_verify}"); if (rpmcliQueryFlags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (rpmcliQueryFlags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; if (rpmcliQueryFlags & VERIFY_HDRCHK) vsflags |= RPMVSF_NOHDRCHK; vsflags &= ~RPMVSF_NEEDPAYLOAD; rpmtsSetScriptFd(ts, scriptFd); ovsflags = rpmtsSetVSFlags(ts, vsflags); ec = rpmcliArgIter(ts, qva, argv); vsflags = rpmtsSetVSFlags(ts, ovsflags); rpmtsSetScriptFd(ts, NULL); if (qva->qva_showPackage == showVerifyPackage) qva->qva_showPackage = NULL; rpmtsEmpty(ts); if (rpmChrootOut() || rpmChrootSet(NULL)) ec = 1; exit: Fclose(scriptFd); return ec; }
static int rpmts_init(rpmtsObject *s, PyObject *args, PyObject *kwds) { char * rootDir = "/"; rpmVSFlags vsflags = rpmExpandNumeric("%{?__vsflags}"); char * kwlist[] = {"rootdir", "vsflags", 0}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|si:rpmts_new", kwlist, &rootDir, &vsflags)) return -1; (void) rpmtsSetRootDir(s->ts, rootDir); /* XXX: make this use common code with rpmts_SetVSFlags() to check the * python objects */ (void) rpmtsSetVSFlags(s->ts, vsflags); return 0; }
static rpmRC checkPackages(char *pkgcheck) { int fail = rpmExpandNumeric("%{?_nonzero_exit_pkgcheck_terminate_build}"); int xx; rpmlog(RPMLOG_NOTICE, _("Executing \"%s\":\n"), pkgcheck); xx = system(pkgcheck); if (WEXITSTATUS(xx) == -1 || WEXITSTATUS(xx) == 127) { rpmlog(RPMLOG_ERR, _("Execution of \"%s\" failed.\n"), pkgcheck); if (fail) return RPMRC_NOTFOUND; } if (WEXITSTATUS(xx) != 0) { rpmlog(RPMLOG_ERR, _("Package check \"%s\" failed.\n"), pkgcheck); if (fail) return RPMRC_FAIL; } return RPMRC_OK; }
static void wfd_close(FD_t *wfdp) { if (wfdp && *wfdp) { int myerrno = errno; static int oneshot = 0; static int flush_io = 0; if (!oneshot) { flush_io = rpmExpandNumeric("%{?_flush_io}"); oneshot = 1; } if (flush_io) { int fdno = Fileno(*wfdp); fsync(fdno); } Fclose(*wfdp); *wfdp = NULL; errno = myerrno; } }
PyObject * rpmmacro_ExpandMacro(PyObject * self, PyObject * args, PyObject * kwds) { const char *macro; PyObject *res; int num = 0; char * kwlist[] = {"macro", "numeric", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwlist, ¯o, &num)) return NULL; if (num) { res = Py_BuildValue("i", rpmExpandNumeric(macro)); } else { char *str = rpmExpand(macro, NULL); res = Py_BuildValue("s", str); free(str); } return res; }
int rpmcliVerify(rpmts ts, QVA_t qva, const char ** argv) { rpmdepFlags depFlags = qva->depFlags, odepFlags; rpmtransFlags transFlags = qva->transFlags, otransFlags; rpmVSFlags vsflags, ovsflags; int ec = 0; #if defined(_OPENMP) (void) tagName(0); /* XXX instantiate the tagname store. */ omp_set_nested(1); /* XXX permit nested thread teams. */ #endif if (qva->qva_showPackage == NULL) qva->qva_showPackage = showVerifyPackage; /* XXX verify flags are inverted from query. */ vsflags = rpmExpandNumeric("%{?_vsflags_verify}"); if (!(qva->qva_flags & VERIFY_DIGEST)) vsflags |= _RPMVSF_NODIGESTS; if (!(qva->qva_flags & VERIFY_SIGNATURE)) vsflags |= _RPMVSF_NOSIGNATURES; if (!(qva->qva_flags & VERIFY_HDRCHK)) vsflags |= RPMVSF_NOHDRCHK; vsflags &= ~RPMVSF_NEEDPAYLOAD; odepFlags = rpmtsSetDFlags(ts, depFlags); otransFlags = rpmtsSetFlags(ts, transFlags); ovsflags = rpmtsSetVSFlags(ts, vsflags); ec = rpmcliArgIter(ts, qva, argv); vsflags = rpmtsSetVSFlags(ts, ovsflags); transFlags = rpmtsSetFlags(ts, otransFlags); depFlags = rpmtsSetDFlags(ts, odepFlags); if (qva->qva_showPackage == showVerifyPackage) qva->qva_showPackage = NULL; rpmtsEmpty(ts); return ec; }
/** @todo Generalize --freshen policies. */ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv) { struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu)); rpmps ps; rpmprobFilterFlags probFilter; rpmRelocation * relocations; char * fileURL = NULL; int stopInstall = 0; rpmVSFlags vsflags, ovsflags, tvsflags; int rc; int xx; int i; if (fileArgv == NULL) goto exit; rpmcliPackagesTotal = 0; (void) rpmtsSetFlags(ts, ia->transFlags); probFilter = ia->probFilter; relocations = ia->relocations; if (ia->installInterfaceFlags & INSTALL_UPGRADE) vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); else vsflags = rpmExpandNumeric("%{?_vsflags_install}"); if (ia->qva_flags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (ia->qva_flags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; if (ia->qva_flags & VERIFY_HDRCHK) vsflags |= RPMVSF_NOHDRCHK; ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD)); { int notifyFlags; notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 ); xx = rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags)); } if ((eiu->relocations = relocations) != NULL) { while (eiu->relocations->oldPath) eiu->relocations++; if (eiu->relocations->newPath == NULL) eiu->relocations = NULL; } /* Build fully globbed list of arguments in argv[argc]. */ for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) { ARGV_t av = NULL; int ac = 0; char * fn; fn = rpmEscapeSpaces(*eiu->fnp); rc = rpmGlob(fn, &ac, &av); fn = _free(fn); if (rc || ac == 0) { rpmlog(RPMLOG_ERR, _("File not found by glob: %s\n"), *eiu->fnp); eiu->numFailed++; continue; } argvAppend(&(eiu->argv), av); argvFree(av); eiu->argc += ac; } restart: /* Allocate sufficient storage for next set of args. */ if (eiu->pkgx >= eiu->numPkgs) { eiu->numPkgs = eiu->pkgx + eiu->argc; eiu->pkgURL = xrealloc(eiu->pkgURL, (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL)); memset(eiu->pkgURL + eiu->pkgx, 0, ((eiu->argc + 1) * sizeof(*eiu->pkgURL))); eiu->pkgState = xrealloc(eiu->pkgState, (eiu->numPkgs + 1) * sizeof(*eiu->pkgState)); memset(eiu->pkgState + eiu->pkgx, 0, ((eiu->argc + 1) * sizeof(*eiu->pkgState))); } /* Retrieve next set of args, cache on local storage. */ for (i = 0; i < eiu->argc; i++) { fileURL = _free(fileURL); fileURL = eiu->argv[i]; eiu->argv[i] = NULL; switch (urlIsURL(fileURL)) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: { char *tfn; FD_t tfd; if (rpmIsVerbose()) fprintf(stdout, _("Retrieving %s\n"), fileURL); tfd = rpmMkTempFile(rpmtsRootDir(ts), &tfn); if (tfd && tfn) { Fclose(tfd); rc = urlGetFile(fileURL, tfn); } else { rc = -1; } if (rc != 0) { rpmlog(RPMLOG_ERR, _("skipping %s - transfer failed\n"), fileURL); eiu->numFailed++; eiu->pkgURL[eiu->pkgx] = NULL; tfn = _free(tfn); break; } eiu->pkgState[eiu->pkgx] = 1; eiu->pkgURL[eiu->pkgx] = tfn; eiu->pkgx++; } break; case URL_IS_PATH: case URL_IS_DASH: /* WRONG WRONG WRONG */ case URL_IS_HKP: /* WRONG WRONG WRONG */ default: eiu->pkgURL[eiu->pkgx] = fileURL; fileURL = NULL; eiu->pkgx++; break; } } fileURL = _free(fileURL); if (eiu->numFailed) goto exit; /* Continue processing file arguments, building transaction set. */ for (eiu->fnp = eiu->pkgURL+eiu->prevx; *eiu->fnp != NULL; eiu->fnp++, eiu->prevx++) { const char * fileName; rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp); (void) urlPath(*eiu->fnp, &fileName); /* Try to read the header from a package file. */ eiu->fd = Fopen(*eiu->fnp, "r.ufdio"); if (eiu->fd == NULL || Ferror(eiu->fd)) { rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp, Fstrerror(eiu->fd)); if (eiu->fd != NULL) { xx = Fclose(eiu->fd); eiu->fd = NULL; } eiu->numFailed++; *eiu->fnp = NULL; continue; } /* Read the header, verifying signatures (if present). */ tvsflags = rpmtsSetVSFlags(ts, vsflags); eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h); tvsflags = rpmtsSetVSFlags(ts, tvsflags); xx = Fclose(eiu->fd); eiu->fd = NULL; switch (eiu->rpmrc) { case RPMRC_FAIL: rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp); eiu->numFailed++; *eiu->fnp = NULL; continue; break; case RPMRC_NOTFOUND: goto maybe_manifest; break; case RPMRC_NOTTRUSTED: case RPMRC_NOKEY: case RPMRC_OK: default: break; } eiu->isSource = headerIsSource(eiu->h); if (eiu->isSource) { rpmlog(RPMLOG_DEBUG, "\tadded source package [%d]\n", eiu->numSRPMS); eiu->sourceURL = xrealloc(eiu->sourceURL, (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL)); eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp; *eiu->fnp = NULL; eiu->numSRPMS++; eiu->sourceURL[eiu->numSRPMS] = NULL; continue; } if (eiu->relocations) { struct rpmtd_s prefixes; headerGet(eiu->h, RPMTAG_PREFIXES, &prefixes, HEADERGET_DEFAULT); if (rpmtdCount(&prefixes) == 1) { eiu->relocations->oldPath = xstrdup(rpmtdGetString(&prefixes)); rpmtdFreeData(&prefixes); } else { const char * name; xx = headerNVR(eiu->h, &name, NULL, NULL); rpmlog(RPMLOG_ERR, _("package %s is not relocatable\n"), name); eiu->numFailed++; goto exit; } } /* On --freshen, verify package is installed and newer */ if (ia->installInterfaceFlags & INSTALL_FRESHEN) { rpmdbMatchIterator mi; const char * name; Header oldH; int count; xx = headerNVR(eiu->h, &name, NULL, NULL); mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0); count = rpmdbGetIteratorCount(mi); while ((oldH = rpmdbNextIterator(mi)) != NULL) { if (rpmVersionCompare(oldH, eiu->h) < 0) continue; /* same or newer package already installed */ count = 0; break; } mi = rpmdbFreeIterator(mi); if (count == 0) { eiu->h = headerFree(eiu->h); continue; } /* Package is newer than those currently installed. */ } rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName, (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0, relocations); /* XXX reference held by transaction set */ eiu->h = headerFree(eiu->h); if (eiu->relocations) eiu->relocations->oldPath = _free(eiu->relocations->oldPath); switch(rc) { case 0: rpmlog(RPMLOG_DEBUG, "\tadded binary package [%d]\n", eiu->numRPMS); break; case 1: rpmlog(RPMLOG_ERR, _("error reading from file %s\n"), *eiu->fnp); eiu->numFailed++; goto exit; break; case 2: rpmlog(RPMLOG_ERR, _("file %s requires a newer version of RPM\n"), *eiu->fnp); eiu->numFailed++; goto exit; break; default: eiu->numFailed++; goto exit; break; } eiu->numRPMS++; continue; maybe_manifest: /* Try to read a package manifest. */ eiu->fd = Fopen(*eiu->fnp, "r.fpio"); if (eiu->fd == NULL || Ferror(eiu->fd)) { rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp, Fstrerror(eiu->fd)); if (eiu->fd != NULL) { xx = Fclose(eiu->fd); eiu->fd = NULL; } eiu->numFailed++; *eiu->fnp = NULL; break; } /* Read list of packages from manifest. */ /* FIX: *eiu->argv can be NULL */ rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv); if (rc != RPMRC_OK) rpmlog(RPMLOG_ERR, _("%s: not an rpm package (or package manifest): %s\n"), *eiu->fnp, Fstrerror(eiu->fd)); xx = Fclose(eiu->fd); eiu->fd = NULL; /* If successful, restart the query loop. */ if (rc == RPMRC_OK) { eiu->prevx++; goto restart; } eiu->numFailed++; *eiu->fnp = NULL; break; } rpmlog(RPMLOG_DEBUG, "found %d source and %d binary packages\n", eiu->numSRPMS, eiu->numRPMS); if (eiu->numFailed) goto exit; if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) { if (rpmtsCheck(ts)) { eiu->numFailed = eiu->numPkgs; stopInstall = 1; } ps = rpmtsProblems(ts); if (!stopInstall && rpmpsNumProblems(ps) > 0) { rpmlog(RPMLOG_ERR, _("Failed dependencies:\n")); rpmpsPrint(NULL, ps); eiu->numFailed = eiu->numPkgs; stopInstall = 1; } ps = rpmpsFree(ps); } if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) { if (rpmtsOrder(ts)) { eiu->numFailed = eiu->numPkgs; stopInstall = 1; } } if (eiu->numRPMS && !stopInstall) { rpmcliPackagesTotal += eiu->numSRPMS; rpmlog(RPMLOG_DEBUG, "installing binary packages\n"); /* Drop added/available package indices and dependency sets. */ rpmtsClean(ts); rc = rpmtsRun(ts, NULL, probFilter); ps = rpmtsProblems(ts); if (rc < 0) { eiu->numFailed += eiu->numRPMS; } else if (rc > 0) { eiu->numFailed += rc; if (rpmpsNumProblems(ps) > 0) rpmpsPrint(stderr, ps); } ps = rpmpsFree(ps); } if (eiu->numSRPMS && !stopInstall) { if (eiu->sourceURL != NULL) for (i = 0; i < eiu->numSRPMS; i++) { rpmdbCheckSignals(); if (eiu->sourceURL[i] == NULL) continue; eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio"); if (eiu->fd == NULL || Ferror(eiu->fd)) { rpmlog(RPMLOG_ERR, _("cannot open file %s: %s\n"), eiu->sourceURL[i], Fstrerror(eiu->fd)); if (eiu->fd != NULL) { xx = Fclose(eiu->fd); eiu->fd = NULL; } continue; } if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) { eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL); if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++; } xx = Fclose(eiu->fd); eiu->fd = NULL; } } exit: if (eiu->pkgURL != NULL) for (i = 0; i < eiu->numPkgs; i++) { if (eiu->pkgURL[i] == NULL) continue; if (eiu->pkgState[i] == 1) (void) unlink(eiu->pkgURL[i]); eiu->pkgURL[i] = _free(eiu->pkgURL[i]); } eiu->pkgState = _free(eiu->pkgState); eiu->pkgURL = _free(eiu->pkgURL); eiu->argv = _free(eiu->argv); rc = eiu->numFailed; free(eiu); rpmtsEmpty(ts); return rc; }
int main(int argc, char *argv[]) { rpmts ts = NULL; struct rpmInstallArguments_s *ia = &rpmIArgs; poptContext optCon = NULL; int ec = 0; int ret = 0; char **arg = NULL; arg = malloc(sizeof(char *) * argc); memset(arg, 0, sizeof(char *) * argc); for (int i = 0; i < argc; i++) { arg[i] = malloc(sizeof(char) * PATH_MAX); memset(arg[i], 0, sizeof(char) * PATH_MAX); snprintf(arg[i], strlen(arg[i]) - 1, argv[i]); } optCon = rpmcliInit(argc, arg, optionsTable); ia->installInterfaceFlags = INSTALL_INSTALL | INSTALL_LABEL | INSTALL_PERCENT; ts = rpmtsCreate(); rpmtsSetRootDir(ts, rpmcliRootDir); if (!ia->incldocs) { if (rpmExpandNumeric("%{_excludedocs}")) ia->transFlags |= RPMTRANS_FLAG_NODOCS; } if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; if (ia->prefix) { ia->relocations = malloc(2 * sizeof(*ia->relocations)); ia->relocations[0].oldPath = NULL; /* special case magic */ ia->relocations[0].newPath = ia->prefix; ia->relocations[1].oldPath = NULL; ia->relocations[1].newPath = NULL; } else if (ia->relocations) { ia->relocations = realloc(ia->relocations, sizeof(*ia->relocations) * (ia->numRelocations + 1)); ia->relocations[ia->numRelocations].oldPath = NULL; ia->relocations[ia->numRelocations].newPath = NULL; } rpmInstallISoftApp(ts, ia, (ARGV_t) poptGetArgs(optCon), NULL); rpmtsFree(ts); ts = NULL; rpmcliFini(optCon); optCon = NULL; if (arg) { for (int i = 0; i < argc; i++) { if (arg[i]) { free(arg[i]); arg[i] = NULL; } } free(arg); arg = NULL; } return 0; }
/** * Skip any files that do not match install policies. * @param ts transaction set * @param files file info set * @param fs file states */ static void skipInstallFiles(const rpmts ts, rpmfiles files, rpmfs fs) { rpm_color_t tscolor = rpmtsColor(ts); rpm_color_t FColor; int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS); int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS); int * drc; char * dff; int dc; int i, j, ix; rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD); if (!noDocs) noDocs = rpmExpandNumeric("%{_excludedocs}"); /* Compute directory refcount, skip directory if now empty. */ dc = rpmfiDC(fi); drc = xcalloc(dc, sizeof(*drc)); dff = xcalloc(dc, sizeof(*dff)); fi = rpmfiInit(fi, 0); while ((i = rpmfiNext(fi)) >= 0) { char ** nsp; const char *flangs; ix = rpmfiDX(fi); drc[ix]++; /* Don't bother with skipped files */ if (XFA_SKIPPING(rpmfsGetAction(fs, i))) { drc[ix]--; dff[ix] = 1; continue; } /* Ignore colored files not in our rainbow. */ FColor = rpmfiFColor(fi); if (tscolor && FColor && !(tscolor & FColor)) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPCOLOR); continue; } /* * Skip net shared paths. * Net shared paths are not relative to the current root (though * they do need to take package relocations into account). */ if (ts->netsharedPaths) { nsp = matchNetsharedpath(ts, fi); if (nsp && *nsp) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNETSHARED); continue; } } /* * Skip i18n language specific files. */ flangs = (ts->installLangs != NULL) ? rpmfiFLangs(fi) : NULL; if (flangs != NULL && *flangs != '\0') { const char *l, *le; char **lang; for (lang = ts->installLangs; *lang != NULL; lang++) { for (l = flangs; *l != '\0'; l = le) { for (le = l; *le != '\0' && *le != '|'; le++) {}; if ((le-l) > 0 && rstreqn(*lang, l, (le-l))) break; if (*le == '|') le++; /* skip over | */ } if (*l != '\0') break; } if (*lang == NULL) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNSTATE); continue; } } /* * Skip config files if requested. */ if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNSTATE); continue; } /* * Skip documentation if requested. */ if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNSTATE); continue; } } /* Skip (now empty) directories that had skipped files. */ /* Iterate over dirs in reversed order to solve subdirs at first */ for (j = dc - 1; j >= 0; j--) { const char * dn, * bn; size_t dnlen, bnlen; if (drc[j]) continue; /* dir still has files. */ if (!dff[j]) continue; /* dir was not emptied here. */ /* Find parent directory and basename. */ dn = rpmfilesDN(files, j); dnlen = strlen(dn) - 1; bn = dn + dnlen; bnlen = 0; while (bn > dn && bn[-1] != '/') { bnlen++; dnlen--; bn--; } /* If explicitly included in the package, skip the directory. */ fi = rpmfiInit(fi, 0); while ((i = rpmfiNext(fi)) >= 0) { const char * fdn, * fbn; rpm_mode_t fFMode; if (XFA_SKIPPING(rpmfsGetAction(fs, i))) continue; fFMode = rpmfiFMode(fi); if (rpmfiWhatis(fFMode) != XDIR) continue; fdn = rpmfiDN(fi); if (strlen(fdn) != dnlen) continue; if (!rstreqn(fdn, dn, dnlen)) continue; fbn = rpmfiBN(fi); if (strlen(fbn) != bnlen) continue; if (!rstreqn(fbn, bn, bnlen)) continue; rpmlog(RPMLOG_DEBUG, "excluding directory %s\n", dn); rpmfsSetAction(fs, i, FA_SKIPNSTATE); ix = rpmfiDX(fi); /* Decrease count of files for parent directory */ drc[ix]--; /* Mark directory because something was removed from them */ dff[ix] = 1; break; } } free(drc); free(dff); rpmfiFree(fi); }
/** * Skip any files that do not match install policies. * @param ts transaction set * @param fi file info set */ static void skipFiles(const rpmts ts, rpmte p) { rpm_color_t tscolor = rpmtsColor(ts); rpm_color_t FColor; int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS); int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS); const char * dn, * bn; size_t dnlen, bnlen; char * s; int * drc; char * dff; int dc; int i, j, ix; rpmfi fi = rpmteFI(p); rpmfs fs = rpmteGetFileStates(p); if (!noDocs) noDocs = rpmExpandNumeric("%{_excludedocs}"); /* Compute directory refcount, skip directory if now empty. */ dc = rpmfiDC(fi); drc = xcalloc(dc, sizeof(*drc)); dff = xcalloc(dc, sizeof(*dff)); fi = rpmfiInit(fi, 0); if (fi != NULL) /* XXX lclint */ while ((i = rpmfiNext(fi)) >= 0) { char ** nsp; const char *flangs; bn = rpmfiBN(fi); bnlen = strlen(bn); ix = rpmfiDX(fi); dn = rpmfiDN(fi); dnlen = strlen(dn); if (dn == NULL) continue; /* XXX can't happen */ drc[ix]++; /* Don't bother with skipped files */ if (XFA_SKIPPING(rpmfsGetAction(fs, i))) { drc[ix]--; dff[ix] = 1; continue; } /* Ignore colored files not in our rainbow. */ FColor = rpmfiFColor(fi); if (tscolor && FColor && !(tscolor & FColor)) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPCOLOR); continue; } /* * Skip net shared paths. * Net shared paths are not relative to the current root (though * they do need to take package relocations into account). */ for (nsp = ts->netsharedPaths; nsp && *nsp; nsp++) { size_t len; len = strlen(*nsp); if (dnlen >= len) { if (strncmp(dn, *nsp, len)) continue; /* Only directories or complete file paths can be net shared */ if (!(dn[len] == '/' || dn[len] == '\0')) continue; } else { if (len < (dnlen + bnlen)) continue; if (strncmp(dn, *nsp, dnlen)) continue; /* Insure that only the netsharedpath basename is compared. */ if ((s = strchr((*nsp) + dnlen, '/')) != NULL && s[1] != '\0') continue; if (strncmp(bn, (*nsp) + dnlen, bnlen)) continue; len = dnlen + bnlen; /* Only directories or complete file paths can be net shared */ if (!((*nsp)[len] == '/' || (*nsp)[len] == '\0')) continue; } break; } if (nsp && *nsp) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNETSHARED); continue; } /* * Skip i18n language specific files. */ if (ts->installLangs != NULL && (flangs = rpmfiFLangs(fi)) != NULL) { const char *l, *le; char **lang; for (lang = ts->installLangs; *lang != NULL; lang++) { for (l = flangs; *l != '\0'; l = le) { for (le = l; *le != '\0' && *le != '|'; le++) {}; if ((le-l) > 0 && !strncmp(*lang, l, (le-l))) break; if (*le == '|') le++; /* skip over | */ } if (*l != '\0') break; } if (*lang == NULL) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNSTATE); continue; } } /* * Skip config files if requested. */ if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNSTATE); continue; } /* * Skip documentation if requested. */ if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) { drc[ix]--; dff[ix] = 1; rpmfsSetAction(fs, i, FA_SKIPNSTATE); continue; } } /* Skip (now empty) directories that had skipped files. */ #ifndef NOTYET if (fi != NULL) /* XXX can't happen */ for (j = 0; j < dc; j++) #else if ((fi = rpmfiInitD(fi)) != NULL) while (j = rpmfiNextD(fi) >= 0) #endif { if (drc[j]) continue; /* dir still has files. */ if (!dff[j]) continue; /* dir was not emptied here. */ /* Find parent directory and basename. */ dn = rpmfiDNIndex(fi, j); dnlen = strlen(dn) - 1; bn = dn + dnlen; bnlen = 0; while (bn > dn && bn[-1] != '/') { bnlen++; dnlen--; bn--; } /* If explicitly included in the package, skip the directory. */ fi = rpmfiInit(fi, 0); if (fi != NULL) /* XXX lclint */ while ((i = rpmfiNext(fi)) >= 0) { const char * fdn, * fbn; rpm_mode_t fFMode; if (XFA_SKIPPING(rpmfsGetAction(fs, i))) continue; fFMode = rpmfiFMode(fi); if (rpmfiWhatis(fFMode) != XDIR) continue; fdn = rpmfiDN(fi); if (strlen(fdn) != dnlen) continue; if (strncmp(fdn, dn, dnlen)) continue; fbn = rpmfiBN(fi); if (strlen(fbn) != bnlen) continue; if (strncmp(fbn, bn, bnlen)) continue; rpmlog(RPMLOG_DEBUG, "excluding directory %s\n", dn); rpmfsSetAction(fs, i, FA_SKIPNSTATE); break; } } free(drc); free(dff); }
/** * Parse %patch line. * @param spec build info * @param line current line from spec file * @return RPMRC_OK on success */ static rpmRC doPatchMacro(Spec spec, const char * line) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies spec->prep, rpmGlobalMacroContext, fileSystem, internalState @*/ { char *s; char *opt_b; char *opt_d; rpmuint32_t opt_P, opt_p, opt_R, opt_E, opt_F; char buf[BUFSIZ], *bp; rpmuint32_t patch_nums[1024]; /* XXX - we can only handle 1024 patches! */ int patch_index, x; memset(patch_nums, 0, sizeof(patch_nums)); opt_P = opt_p = opt_R = opt_E = 0; opt_F = rpmExpandNumeric("%{?_default_patch_fuzz}%{!?_default_patch_fuzz:-1}"); opt_b = NULL; opt_d = NULL; patch_index = 0; if (! strchr(" \t\n", line[6])) { /* %patchN */ sprintf(buf, "%%patch -P %s", line + 6); } else { strncpy(buf, line, sizeof(buf)-1); buf[sizeof(buf)-1] = '\0'; } /*@-internalglobs@*/ /* FIX: strtok has state */ for (bp = buf; (s = strtok(bp, " \t\n")) != NULL;) { if (bp) { /* remove 1st token (%patch) */ bp = NULL; continue; } if (!strcmp(s, "-P")) { opt_P = 1; } else if (!strcmp(s, "-R")) { opt_R = 1; } else if (!strcmp(s, "-E")) { opt_E = 1; } else if (!strcmp(s, "-b")) { /* orig suffix */ opt_b = strtok(NULL, " \t\n"); if (! opt_b) { rpmlog(RPMLOG_ERR, _("line %d: Need arg to %%patch -b: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } } else if (!strcmp(s, "-z")) { /* orig suffix */ opt_b = strtok(NULL, " \t\n"); if (! opt_b) { rpmlog(RPMLOG_ERR, _("line %d: Need arg to %%patch -z: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } } else if (!strcmp(s, "-F")) { /* fuzz factor */ const char * fnum = (!strchr(" \t\n", s[2]) ? s+2 : strtok(NULL, " \t\n")); char * end = NULL; opt_F = (fnum ? strtol(fnum, &end, 10) : 0); if (! opt_F || *end) { rpmlog(RPMLOG_ERR, _("line %d: Bad arg to %%patch -F: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } } else if (!strcmp(s, "-d")) { /* subdirectory */ opt_d = strtok(NULL, " \t\n"); if (! opt_d) { rpmlog(RPMLOG_ERR, _("line %d: Need arg to %%patch -d: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } } else if (!strncmp(s, "-p", sizeof("-p")-1)) { /* unfortunately, we must support -pX */ if (! strchr(" \t\n", s[2])) { s = s + 2; } else { s = strtok(NULL, " \t\n"); if (s == NULL) { rpmlog(RPMLOG_ERR, _("line %d: Need arg to %%patch -p: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } } if (parseNum(s, &opt_p)) { rpmlog(RPMLOG_ERR, _("line %d: Bad arg to %%patch -p: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } } else { /* Must be a patch num */ if (patch_index == 1024) { rpmlog(RPMLOG_ERR, _("Too many patches!\n")); return RPMRC_FAIL; } if (parseNum(s, &(patch_nums[patch_index]))) { rpmlog(RPMLOG_ERR, _("line %d: Bad arg to %%patch: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } patch_index++; } } /*@=internalglobs@*/ /* All args processed */ if (! opt_P) { s = doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E, opt_F, opt_d); if (s == NULL) return RPMRC_FAIL; spec->prep = rpmiobAppend(spec->prep, s, 1); } for (x = 0; x < patch_index; x++) { s = doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E, opt_F, opt_d); if (s == NULL) return RPMRC_FAIL; spec->prep = rpmiobAppend(spec->prep, s, 1); } return RPMRC_OK; }
Spec newSpec(void) { static const char _spec_line_buffer_size[] = "%{?_spec_line_buffer_size}%{!?_spec_line_buffer_size:100000}"; Spec spec = specGetPool(_specPool); spec->specFile = NULL; spec->sl = newSl(); spec->st = newSt(); spec->fileStack = NULL; spec->lbuf_len = (size_t)rpmExpandNumeric(_spec_line_buffer_size); spec->lbuf = (char *)xmalloc(spec->lbuf_len); spec->lbuf[0] = '\0'; spec->line = spec->lbuf; spec->nextline = NULL; spec->nextpeekc = '\0'; spec->lineNum = 0; spec->readStack = xmalloc(sizeof(*spec->readStack)); spec->readStack->next = NULL; spec->readStack->reading = 1; spec->rootURL = NULL; memset(&spec->sstates, 0, sizeof(spec->sstates)); memset(&spec->smetrics, 0, sizeof(spec->smetrics)); spec->prep = NULL; spec->build = NULL; spec->install = NULL; spec->check = NULL; spec->clean = NULL; spec->foo = NULL; spec->nfoo = 0; spec->dig = NULL; spec->sources = NULL; spec->packages = NULL; spec->noSource = 0; spec->numSources = 0; spec->sourceRpmName = NULL; spec->sourcePkgId = NULL; spec->sourceHeader = headerNew(); spec->fi = NULL; spec->buildSubdir = NULL; spec->passPhrase = NULL; spec->timeCheck = 0; spec->cookie = NULL; spec->BANames = NULL; spec->BACount = 0; spec->recursing = 0; spec->toplevel = 1; spec->BASpecs = NULL; spec->force = 0; spec->anyarch = 0; /*@i@*/ spec->macros = rpmGlobalMacroContext; spec->_parseRCPOT = parseRCPOT; /* XXX hack around backward linkage. */ return (Spec)rpmioLinkPoolItem((rpmioItem)spec, __FUNCTION__, __FILE__, __LINE__); }
rpmRC checkForEncoding(Header h, int addtag) { rpmRC rc = RPMRC_OK; #if HAVE_ICONV const char *encoding = "utf-8"; rpmTagVal tag; iconv_t ic = (iconv_t) -1; char *dest = NULL; size_t destlen = 0; int strict = rpmExpandNumeric("%{_invalid_encoding_terminates_build}"); HeaderIterator hi = headerInitIterator(h); ic = iconv_open(encoding, encoding); if (ic == (iconv_t) -1) { rpmlog(RPMLOG_WARNING, _("encoding %s not supported by system\n"), encoding); goto exit; } while ((tag = headerNextTag(hi)) != RPMTAG_NOT_FOUND) { struct rpmtd_s td; const char *src = NULL; if (rpmTagGetClass(tag) != RPM_STRING_CLASS) continue; headerGet(h, tag, &td, (HEADERGET_RAW|HEADERGET_MINMEM)); while ((src = rpmtdNextString(&td)) != NULL) { size_t srclen = strlen(src); size_t outlen, inlen = srclen; char *out, *in = (char *) src; if (destlen < srclen) { destlen = srclen * 2; dest = xrealloc(dest, destlen); } out = dest; outlen = destlen; /* reset conversion state */ iconv(ic, NULL, &inlen, &out, &outlen); if (iconv(ic, &in, &inlen, &out, &outlen) == (size_t) -1) { rpmlog(strict ? RPMLOG_ERR : RPMLOG_WARNING, _("Package %s: invalid %s encoding in %s: %s - %s\n"), headerGetString(h, RPMTAG_NAME), encoding, rpmTagGetName(tag), src, strerror(errno)); rc = RPMRC_FAIL; } } rpmtdFreeData(&td); } /* Stomp "known good utf" mark in header if requested */ if (rc == RPMRC_OK && addtag) headerPutString(h, RPMTAG_ENCODING, encoding); if (!strict) rc = RPMRC_OK; exit: if (ic != (iconv_t) -1) iconv_close(ic); headerFreeIterator(hi); free(dest); #endif /* HAVE_ICONV */ return rc; }
rpmts rpmtsCreate(void) { rpmts ts; tsMembers tsmem; ts = xcalloc(1, sizeof(*ts)); memset(&ts->ops, 0, sizeof(ts->ops)); (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_TOTAL), -1); ts->dsi = NULL; ts->solve = NULL; ts->solveData = NULL; ts->rdb = NULL; ts->dbmode = O_RDONLY; ts->scriptFd = NULL; ts->tid = (rpm_tid_t) time(NULL); ts->color = rpmExpandNumeric("%{?_transaction_color}"); ts->prefcolor = rpmExpandNumeric("%{?_prefer_color}")?:2; ts->netsharedPaths = NULL; ts->installLangs = NULL; { char *tmp = rpmExpand("%{_netsharedpath}", NULL); if (tmp && *tmp != '%') { argvSplit(&ts->netsharedPaths, tmp, ":"); } free(tmp); tmp = rpmExpand("%{_install_langs}", NULL); if (tmp && *tmp != '%') { ARGV_t langs = NULL; argvSplit(&langs, tmp, ":"); /* If we'll be installing all languages anyway, don't bother */ for (ARGV_t l = langs; *l; l++) { if (rstreq(*l, "all")) { langs = argvFree(langs); break; } } ts->installLangs = langs; } free(tmp); } tsmem = xcalloc(1, sizeof(*ts->members)); tsmem->pool = NULL; tsmem->delta = 5; tsmem->addedPackages = NULL; tsmem->removedPackages = removedHashCreate(128, uintId, uintCmp, NULL, NULL); tsmem->orderAlloced = 0; tsmem->orderCount = 0; tsmem->order = NULL; ts->members = tsmem; ts->rootDir = NULL; ts->keyring = NULL; ts->nrefs = 0; ts->plugins = NULL; return rpmtsLink(ts); }
/** * Parse %patch line. * This supports too many crazy syntaxes: * - %patchN is equal to %patch -P<N> * - -P<N> -P<N+1>... can be used to apply several patch on a single line * - Any trailing arguments are treated as patch numbers * - Any combination of the above, except unless at least one -P is specified, * %patch is treated as %patch -P0 so that "%patch 1" is actually * equal to "%patch -P0 -P1". * * @param spec build info * @param line current line from spec file * @return RPMRC_OK on success */ static rpmRC doPatchMacro(rpmSpec spec, const char *line) { char *opt_b, *opt_P, *opt_d; char *buf = NULL; int opt_p, opt_R, opt_E, opt_F; int argc, c; const char **argv = NULL; ARGV_t patch, patchnums = NULL; rpmRC rc = RPMRC_FAIL; /* assume failure */ struct poptOption const patchOpts[] = { { NULL, 'P', POPT_ARG_STRING, &opt_P, 'P', NULL, NULL }, { NULL, 'p', POPT_ARG_INT, &opt_p, 'p', NULL, NULL }, { NULL, 'R', POPT_ARG_NONE, &opt_R, 'R', NULL, NULL }, { NULL, 'E', POPT_ARG_NONE, &opt_E, 'E', NULL, NULL }, { NULL, 'b', POPT_ARG_STRING, &opt_b, 'b', NULL, NULL }, { NULL, 'z', POPT_ARG_STRING, &opt_b, 'z', NULL, NULL }, { NULL, 'F', POPT_ARG_INT, &opt_F, 'F', NULL, NULL }, { NULL, 'd', POPT_ARG_STRING, &opt_d, 'd', NULL, NULL }, { NULL, 0, 0, NULL, 0, NULL, NULL } }; poptContext optCon = NULL; opt_p = opt_R = opt_E = 0; opt_F = rpmExpandNumeric("%{_default_patch_fuzz}"); /* get default fuzz factor for %patch */ opt_b = opt_d = NULL; /* Convert %patchN to %patch -PN to simplify further processing */ if (! strchr(" \t\n", line[6])) { rasprintf(&buf, "%%patch -P %s", line + 6); } else { if (strstr(line+6, " -P") == NULL) rasprintf(&buf, "%%patch -P %d %s", INT_MAX, line + 6); /* INT_MAX denotes not numbered %patch */ else buf = xstrdup(line); /* it is not numberless patch because -P is present */ } poptParseArgvString(buf, &argc, &argv); free(buf); /* * Grab all -P<N> numbers for later processing. Stored as strings * at this point so we only have to worry about conversion in one place. */ optCon = poptGetContext(NULL, argc, argv, patchOpts, 0); while ((c = poptGetNextOpt(optCon)) > 0) { switch (c) { case 'P': { char *arg = poptGetOptArg(optCon); if (arg) { argvAdd(&patchnums, arg); free(arg); } break; } default: break; } } if (c < -1) { rpmlog(RPMLOG_ERR, _("%s: %s: %s\n"), poptStrerror(c), poptBadOption(optCon, POPT_BADOPTION_NOALIAS), line); goto exit; } /* Any trailing arguments are treated as patch numbers */ argvAppend(&patchnums, (ARGV_const_t) poptGetArgs(optCon)); /* Convert to number, generate patch command and append to %prep script */ for (patch = patchnums; *patch; patch++) { uint32_t pnum; char *s; if (parseUnsignedNum(*patch, &pnum)) { rpmlog(RPMLOG_ERR, _("Invalid patch number %s: %s\n"), *patch, line); goto exit; } s = doPatch(spec, pnum, opt_p, opt_b, opt_R, opt_E, opt_F, opt_d); if (s == NULL) { goto exit; } appendLineStringBuf(spec->prep, s); free(s); } rc = RPMRC_OK; exit: argvFree(patchnums); free(argv); poptFreeContext(optCon); return rc; }
int main(int argc, char *argv[]) { rpmts ts = NULL; enum modes bigMode = MODE_UNKNOWN; #if defined(IAM_RPMQV) QVA_t qva = &rpmQVKArgs; #endif #ifdef IAM_RPMEIU struct rpmInstallArguments_s * ia = &rpmIArgs; #endif poptContext optCon; int ec = 0; #ifdef IAM_RPMEIU int i; #endif xsetprogname(argv[0]); /* Portability call -- see system.h */ optCon = rpmcliInit(argc, argv, optionsTable); /* Set the major mode based on argv[0] */ #ifdef IAM_RPMQV if (rstreq(xgetprogname(), "rpmquery")) bigMode = MODE_QUERY; if (rstreq(xgetprogname(), "rpmverify")) bigMode = MODE_VERIFY; #endif #if defined(IAM_RPMQV) /* Jumpstart option from argv[0] if necessary. */ switch (bigMode) { case MODE_QUERY: qva->qva_mode = 'q'; break; case MODE_VERIFY: qva->qva_mode = 'V'; break; case MODE_INSTALL: case MODE_ERASE: case MODE_UNKNOWN: default: break; } #endif #ifdef IAM_RPMQV if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) { switch (qva->qva_mode) { case 'q': bigMode = MODE_QUERY; break; case 'V': bigMode = MODE_VERIFY; break; } if (qva->qva_sourceCount) { if (qva->qva_sourceCount > 1) argerror(_("one type of query/verify may be performed at a " "time")); } if (qva->qva_flags && (bigMode & ~MODES_QV)) argerror(_("unexpected query flags")); if (qva->qva_queryFormat && (bigMode & ~MODES_QV)) argerror(_("unexpected query format")); if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV)) argerror(_("unexpected query source")); } #endif /* IAM_RPMQV */ #ifdef IAM_RPMEIU if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE)) { int iflags = (ia->installInterfaceFlags & (INSTALL_UPGRADE|INSTALL_FRESHEN| INSTALL_INSTALL|INSTALL_REINSTALL)); int eflags = (ia->installInterfaceFlags & INSTALL_ERASE); if (iflags & eflags) argerror(_("only one major mode may be specified")); else if (iflags) bigMode = MODE_INSTALL; else if (eflags) bigMode = MODE_ERASE; } #endif /* IAM_RPMEIU */ #if defined(IAM_RPMEIU) if (!( bigMode == MODE_INSTALL ) && (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE))) argerror(_("only installation and upgrading may be forced")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE)) argerror(_("files may only be relocated during package installation")); if (ia->relocations && ia->prefix) argerror(_("cannot use --prefix with --relocate or --excludepath")); if (bigMode != MODE_INSTALL && ia->relocations) argerror(_("--relocate and --excludepath may only be used when installing new packages")); if (bigMode != MODE_INSTALL && ia->prefix) argerror(_("--prefix may only be used when installing new packages")); if (ia->prefix && ia->prefix[0] != '/') argerror(_("arguments to --prefix must begin with a /")); if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_HASH)) argerror(_("--hash (-h) may only be specified during package " "installation and erasure")); if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_PERCENT)) argerror(_("--percent may only be specified during package " "installation and erasure")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG)) argerror(_("--replacepkgs may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) argerror(_("--excludedocs may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && ia->incldocs) argerror(_("--includedocs may only be specified during package " "installation")); if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) argerror(_("only one of --excludedocs and --includedocs may be " "specified")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH)) argerror(_("--ignorearch may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS)) argerror(_("--ignoreos may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES))) argerror(_("--ignoresize may only be specified during package " "installation")); if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE) argerror(_("--allmatches may only be specified during package " "erasure")); if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL) argerror(_("--allfiles may only be specified during package " "installation")); if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) && bigMode != MODE_INSTALL && bigMode != MODE_ERASE) argerror(_("--justdb may only be specified during package " "installation and erasure")); if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY && (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers))) argerror(_("script disabling options may only be specified during " "package installation and erasure")); if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY && (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers))) argerror(_("trigger disabling options may only be specified during " "package installation and erasure")); if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS)) argerror(_("--nodeps may only be specified during package " "installation, erasure, and verification")); if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST)) argerror(_("--test may only be specified during package installation " "and erasure")); #endif /* IAM_RPMEIU */ if (rpmcliRootDir && rpmcliRootDir[0] != '/') { argerror(_("arguments to --root (-r) must begin with a /")); } if (quiet) rpmSetVerbosity(RPMLOG_WARNING); if (rpmcliPipeOutput && initPipe()) exit(EXIT_FAILURE); ts = rpmtsCreate(); (void) rpmtsSetRootDir(ts, rpmcliRootDir); switch (bigMode) { #ifdef IAM_RPMEIU case MODE_ERASE: if (ia->noDeps) ia->installInterfaceFlags |= UNINSTALL_NODEPS; if (!poptPeekArg(optCon)) { argerror(_("no packages given for erase")); } else { ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon)); } break; case MODE_INSTALL: /* RPMTRANS_FLAG_KEEPOBSOLETE */ if (!ia->incldocs) { if (ia->transFlags & RPMTRANS_FLAG_NODOCS) { ; } else if (rpmExpandNumeric("%{_excludedocs}")) ia->transFlags |= RPMTRANS_FLAG_NODOCS; } if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; /* we've already ensured !(!ia->prefix && !ia->relocations) */ if (ia->prefix) { ia->relocations = xmalloc(2 * sizeof(*ia->relocations)); ia->relocations[0].oldPath = NULL; /* special case magic */ ia->relocations[0].newPath = ia->prefix; ia->relocations[1].oldPath = NULL; ia->relocations[1].newPath = NULL; } else if (ia->relocations) { ia->relocations = xrealloc(ia->relocations, sizeof(*ia->relocations) * (ia->numRelocations + 1)); ia->relocations[ia->numRelocations].oldPath = NULL; ia->relocations[ia->numRelocations].newPath = NULL; } if (!poptPeekArg(optCon)) { argerror(_("no packages given for install")); } else { /* FIX: ia->relocations[0].newPath undefined */ ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon)); } break; #endif /* IAM_RPMEIU */ #ifdef IAM_RPMQV case MODE_QUERY: if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL)) argerror(_("no arguments given for query")); ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); break; case MODE_VERIFY: { rpmVerifyFlags verifyFlags = VERIFY_ALL; verifyFlags &= ~qva->qva_flags; qva->qva_flags = (rpmQueryFlags) verifyFlags; if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL)) argerror(_("no arguments given for verify")); ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); } break; #endif /* IAM_RPMQV */ #if !defined(IAM_RPMQV) case MODE_QUERY: case MODE_VERIFY: #endif #if !defined(IAM_RPMEIU) case MODE_INSTALL: case MODE_ERASE: #endif case MODE_UNKNOWN: if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) { printUsage(optCon, stderr, 0); ec = argc; } break; } rpmtsFree(ts); if (finishPipe()) ec = EXIT_FAILURE; #ifdef IAM_RPMQV free(qva->qva_queryFormat); #endif #ifdef IAM_RPMEIU if (ia->relocations != NULL) { for (i = 0; i < ia->numRelocations; i++) free(ia->relocations[i].oldPath); free(ia->relocations); } #endif rpmcliFini(optCon); return RETVAL(ec); }
static int doIcon(Spec spec, Header h) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies h, rpmGlobalMacroContext, fileSystem, internalState @*/ { static size_t iconsize = 0; HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); const char *fn, *Lurlfn = NULL; struct Source *sp; size_t nb; rpmuint8_t * icon; FD_t fd = NULL; int rc = RPMRC_FAIL; /* assume error */ int urltype; int xx; if (iconsize == 0) { iconsize = rpmExpandNumeric("%{?_build_iconsize}"); if (iconsize < 2048) iconsize = 2048; } icon = alloca(iconsize+1); for (sp = spec->sources; sp != NULL; sp = sp->next) { if (sp->flags & RPMFILE_ICON) break; } if (sp == NULL) { rpmlog(RPMLOG_ERR, _("No icon file in sources\n")); goto exit; } #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ /* support splitted source directories, i.e., source files which are alternatively placed into the .spec directory and picked up from there, too. */ Lurlfn = rpmGenPath(NULL, "%{_specdir}/", sp->source); if (access(Lurlfn, F_OK) == -1) { Lurlfn = _free(Lurlfn); Lurlfn = rpmGenPath(NULL, "%{_icondir}/", sp->source); } #else Lurlfn = rpmGenPath(NULL, "%{_icondir}/", sp->source); #endif fn = NULL; urltype = urlPath(Lurlfn, &fn); switch (urltype) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: case URL_IS_PATH: case URL_IS_UNKNOWN: break; case URL_IS_DASH: case URL_IS_HKP: case URL_IS_MONGO: /* XXX FIXME */ rpmlog(RPMLOG_ERR, _("Invalid icon URL: %s\n"), Lurlfn); goto exit; /*@notreached@*/ break; } fd = Fopen(fn, "r%{?_rpmgio}"); if (fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("Unable to open icon %s: %s\n"), fn, Fstrerror(fd)); rc = RPMRC_FAIL; goto exit; } *icon = '\0'; nb = Fread(icon, sizeof(icon[0]), iconsize, fd); if (Ferror(fd) || nb == 0) { rpmlog(RPMLOG_ERR, _("Unable to read icon %s: %s\n"), fn, Fstrerror(fd)); goto exit; } if (nb >= iconsize) { rpmlog(RPMLOG_ERR, _("Icon %s is too big (max. %d bytes)\n"), fn, (int)iconsize); goto exit; } if (icon[0] == 'G' && icon[1] == 'I' && icon[2] == 'F') he->tag = RPMTAG_GIF; else if (icon[0] == '/' && icon[1] == '*' && icon[2] == ' ' && icon[3] == 'X' && icon[4] == 'P' && icon[5] == 'M') he->tag = RPMTAG_XPM; else he->tag = tagValue("Icon"); he->t = RPM_BIN_TYPE; he->p.ui8p = icon; he->c = (rpmTagCount)nb; xx = headerPut(h, he, 0); rc = 0; exit: if (fd) { (void) Fclose(fd); fd = NULL; } Lurlfn = _free(Lurlfn); return rc; }
int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) { char * const * arg; char *qfmt = NULL; int numFailed = 0; int stopUninstall = 0; int numPackages = 0; rpmVSFlags vsflags, ovsflags; rpmps ps; if (argv == NULL) return 0; vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); if (ia->qva_flags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (ia->qva_flags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; if (ia->qva_flags & VERIFY_HDRCHK) vsflags |= RPMVSF_NOHDRCHK; ovsflags = rpmtsSetVSFlags(ts, vsflags); /* XXX suggest mechanism only meaningful when installing */ ia->transFlags |= RPMTRANS_FLAG_NOSUGGEST; (void) rpmtsSetFlags(ts, ia->transFlags); #ifdef NOTYET /* XXX no callbacks on erase yet */ { int notifyFlags, xx; notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 ); xx = rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags)); } #endif qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL); for (arg = argv; *arg; arg++) { rpmdbMatchIterator mi; int matches = 0; int erasing = 1; /* Iterator count isn't reliable with labels, count manually... */ mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); while (rpmdbNextIterator(mi) != NULL) { matches++; } rpmdbFreeIterator(mi); 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->eraseInterfaceFlags & UNINSTALL_ALLMATCHES)) { rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages:\n"), *arg); numFailed++; erasing = 0; } mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 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); } } mi = rpmdbFreeIterator(mi); } } free(qfmt); if (numFailed) goto exit; if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) { if (rpmtsCheck(ts)) { numFailed = numPackages; stopUninstall = 1; } ps = rpmtsProblems(ts); if (!stopUninstall && rpmpsNumProblems(ps) > 0) { rpmlog(RPMLOG_ERR, _("Failed dependencies:\n")); rpmpsPrint(NULL, ps); numFailed += numPackages; stopUninstall = 1; } ps = rpmpsFree(ps); } if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) { if (rpmtsOrder(ts)) { numFailed += numPackages; stopUninstall = 1; } } if (numPackages && !stopUninstall) { (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE)); /* Drop added/available package indices and dependency sets. */ rpmtsClean(ts); numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)); ps = rpmtsProblems(ts); if (rpmpsNumProblems(ps) > 0) rpmpsPrint(NULL, ps); numFailed += numPackages; stopUninstall = 1; ps = rpmpsFree(ps); } exit: rpmtsEmpty(ts); return numFailed; }
int parseSpec(rpmts ts, const char *specFile, const char *rootDir, const char *buildRoot, int recursing, const char *passPhrase, const char *cookie, int anyarch, int force) { rpmParseState parsePart = PART_PREAMBLE; int initialPackage = 1; Package pkg; rpmSpec spec; /* Set up a new Spec structure with no packages. */ spec = newSpec(); spec->specFile = rpmGetPath(specFile, NULL); spec->fileStack = newOpenFileInfo(); spec->fileStack->fileName = xstrdup(spec->specFile); /* If buildRoot not specified, use default %{buildroot} */ if (buildRoot) { spec->buildRoot = xstrdup(buildRoot); } else { spec->buildRoot = rpmGetPath("%{?buildroot:%{buildroot}}", NULL); } addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC); spec->recursing = recursing; spec->anyarch = anyarch; spec->force = force; if (rootDir) spec->rootDir = xstrdup(rootDir); if (passPhrase) spec->passPhrase = xstrdup(passPhrase); if (cookie) spec->cookie = xstrdup(cookie); spec->timeCheck = rpmExpandNumeric("%{_timecheck}"); /* All the parse*() functions expect to have a line pre-read */ /* in the spec's line buffer. Except for parsePreamble(), */ /* which handles the initial entry into a spec file. */ while (parsePart != PART_NONE) { int goterror = 0; switch (parsePart) { /* XXX Trap unexpected RPMRC_FAIL returns for now */ case RPMRC_FAIL: rpmlog(RPMLOG_ERR, "FIXME: got RPMRC_FAIL from spec parse\n"); abort(); case PART_ERROR: /* fallthrough */ default: goterror = 1; break; case PART_PREAMBLE: parsePart = parsePreamble(spec, initialPackage); initialPackage = 0; break; case PART_PREP: parsePart = parsePrep(spec); break; case PART_BUILD: case PART_INSTALL: case PART_CHECK: case PART_CLEAN: parsePart = parseBuildInstallClean(spec, parsePart); break; case PART_CHANGELOG: parsePart = parseChangelog(spec); break; case PART_DESCRIPTION: parsePart = parseDescription(spec); break; case PART_PRE: case PART_POST: case PART_PREUN: case PART_POSTUN: case PART_PRETRANS: case PART_POSTTRANS: case PART_VERIFYSCRIPT: case PART_TRIGGERPREIN: case PART_TRIGGERIN: case PART_TRIGGERUN: case PART_TRIGGERPOSTUN: parsePart = parseScript(spec, parsePart); break; case PART_FILES: parsePart = parseFiles(spec); break; case PART_NONE: /* XXX avoid gcc whining */ case PART_LAST: case PART_BUILDARCHITECTURES: break; } if (goterror || parsePart >= PART_LAST) { goto errxit; } if (parsePart == PART_BUILDARCHITECTURES) { int index; int x; closeSpec(spec); spec->BASpecs = xcalloc(spec->BACount, sizeof(*spec->BASpecs)); index = 0; if (spec->BANames != NULL) for (x = 0; x < spec->BACount; x++) { /* Skip if not arch is not compatible. */ if (!rpmMachineScore(RPM_MACHTABLE_BUILDARCH, spec->BANames[x])) continue; addMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC); spec->BASpecs[index] = NULL; if (parseSpec(ts, specFile, spec->rootDir, buildRoot, 1, passPhrase, cookie, anyarch, force) || (spec->BASpecs[index] = rpmtsSetSpec(ts, NULL)) == NULL) { spec->BACount = index; goto errxit; } delMacro(NULL, "_target_cpu"); index++; } spec->BACount = index; if (! index) { rpmlog(RPMLOG_ERR, _("No compatible architectures found for build\n")); goto errxit; } /* * Return the 1st child's fully parsed Spec structure. * The restart of the parse when encountering BuildArch * causes problems for "rpm -q --specfile". This is * still a hack because there may be more than 1 arch * specified (unlikely but possible.) There's also the * further problem that the macro context, particularly * %{_target_cpu}, disagrees with the info in the header. */ if (spec->BACount >= 1) { rpmSpec nspec = spec->BASpecs[0]; spec->BASpecs = _free(spec->BASpecs); spec = freeSpec(spec); spec = nspec; } (void) rpmtsSetSpec(ts, spec); return 0; } } if (spec->clean == NULL) { char *body = rpmExpand("%{?buildroot: %{__rm} -rf %{buildroot}}", NULL); spec->clean = newStringBuf(); appendLineStringBuf(spec->clean, body); free(body); } /* Check for description in each package and add arch and os */ { char *platform = rpmExpand("%{_target_platform}", NULL); char *arch = rpmExpand("%{_target_cpu}", NULL); char *os = rpmExpand("%{_target_os}", NULL); for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) { if (!headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) { rpmlog(RPMLOG_ERR, _("Package has no %%description: %s\n"), headerGetString(pkg->header, RPMTAG_NAME)); goto errxit; } 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); pkg->ds = rpmdsThis(pkg->header, RPMTAG_REQUIRENAME, RPMSENSE_EQUAL); } platform = _free(platform); arch = _free(arch); os = _free(os); } closeSpec(spec); (void) rpmtsSetSpec(ts, spec); return 0; errxit: spec = freeSpec(spec); return PART_ERROR; }
int build(rpmts ts, BTA_t ba, const char * rcfile) { const char *t, *te; int rc = 0; const char * targets = rpmcliTargets; char *target; #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC) int cleanFlags = ba->buildAmount & buildCleanMask; rpmVSFlags vsflags, ovsflags; int nbuilds = 0; vsflags = rpmExpandNumeric("%{_vsflags_build}"); if (ba->qva_flags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (ba->qva_flags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; if (ba->qva_flags & VERIFY_HDRCHK) vsflags |= RPMVSF_NOHDRCHK; ovsflags = rpmtsSetVSFlags(ts, vsflags); if (targets == NULL) { rc = buildForTarget(ts, ba); nbuilds++; goto exit; } /* parse up the build operators */ printf(_("Building target platforms: %s\n"), targets); ba->buildAmount &= ~buildCleanMask; for (t = targets; *t != '\0'; t = te) { /* Parse out next target platform. */ if ((te = strchr(t, ',')) == NULL) te = t + strlen(t); target = alloca(te-t+1); strncpy(target, t, (te-t)); target[te-t] = '\0'; if (*te != '\0') te++; else /* XXX Perform clean-up after last target build. */ ba->buildAmount |= cleanFlags; rpmlog(RPMLOG_DEBUG, _(" target platform: %s\n"), target); /* Read in configuration for target. */ if (t != targets) { rpmFreeMacros(NULL); rpmFreeRpmrc(); (void) rpmReadConfigFiles(rcfile, target); } rc = buildForTarget(ts, ba); nbuilds++; if (rc) break; } exit: /* Restore original configuration. */ if (nbuilds > 1) { t = targets; if ((te = strchr(t, ',')) == NULL) te = t + strlen(t); target = alloca(te-t+1); strncpy(target, t, (te-t)); target[te-t] = '\0'; if (*te != '\0') te++; rpmFreeMacros(NULL); rpmFreeRpmrc(); (void) rpmReadConfigFiles(rcfile, target); } vsflags = rpmtsSetVSFlags(ts, ovsflags); return rc; }
rpmRC rpmGenerateSignature(char *SHA1, uint8_t *MD5, rpm_loff_t size, rpm_loff_t payloadSize, FD_t fd) { Header sig = headerNew(); struct rpmtd_s td; rpmRC rc = RPMRC_OK; char *reservedSpace; int spaceSize = 32; /* always reserve a bit of space */ int gpgSize = rpmExpandNumeric("%{__gpg_reserved_space}"); /* Prepare signature */ rpmtdReset(&td); td.tag = RPMSIGTAG_SHA1; td.count = 1; td.type = RPM_STRING_TYPE; td.data = SHA1; headerPut(sig, &td, HEADERPUT_DEFAULT); rpmtdReset(&td); td.tag = RPMSIGTAG_MD5; td.count = 16; td.type = RPM_BIN_TYPE; td.data = MD5; headerPut(sig, &td, HEADERPUT_DEFAULT); rpmtdReset(&td); td.count = 1; if (payloadSize < UINT32_MAX) { rpm_off_t p = payloadSize; rpm_off_t s = size; td.type = RPM_INT32_TYPE; td.tag = RPMSIGTAG_PAYLOADSIZE; td.data = &p; headerPut(sig, &td, HEADERPUT_DEFAULT); td.tag = RPMSIGTAG_SIZE; td.data = &s; headerPut(sig, &td, HEADERPUT_DEFAULT); } else { rpm_loff_t p = payloadSize; rpm_loff_t s = size; td.type = RPM_INT64_TYPE; td.tag = RPMSIGTAG_LONGARCHIVESIZE; td.data = &p; headerPut(sig, &td, HEADERPUT_DEFAULT); td.tag = RPMSIGTAG_LONGSIZE; td.data = &s; headerPut(sig, &td, HEADERPUT_DEFAULT); /* adjust for the size difference between 64- and 32bit tags */ spaceSize -= 8; } if (gpgSize > 0) spaceSize += gpgSize; if(spaceSize > 0) { reservedSpace = xcalloc(spaceSize, sizeof(char)); rpmtdReset(&td); td.tag = RPMSIGTAG_RESERVEDSPACE; td.count = spaceSize; td.type = RPM_BIN_TYPE; td.data = reservedSpace; headerPut(sig, &td, HEADERPUT_DEFAULT); free(reservedSpace); } /* Reallocate the signature into one contiguous region. */ sig = headerReload(sig, RPMTAG_HEADERSIGNATURES); if (sig == NULL) { /* XXX can't happen */ rpmlog(RPMLOG_ERR, _("Unable to reload signature header.\n")); rc = RPMRC_FAIL; goto exit; } /* Write the signature section into the package. */ if (rpmWriteSignature(fd, sig)) { rc = RPMRC_FAIL; goto exit; } exit: headerFree(sig); return rc; }
int main(int argc, const char ** argv) #endif /*@globals rpmEVR, RPMVERSION, rpmGlobalMacroContext, rpmCLIMacroContext, h_errno, fileSystem, internalState@*/ /*@modifies fileSystem, internalState@*/ { poptContext optCon = rpmcliInit(argc, (char *const *)argv, optionsTable); rpmts ts = NULL; enum modes bigMode = MODE_UNKNOWN; #if defined(IAM_RPMQV) QVA_t qva = &rpmQVKArgs; #endif #ifdef IAM_RPMBT BTA_t ba = &rpmBTArgs; #endif #ifdef IAM_RPMEIU QVA_t ia = &rpmIArgs; #endif #if defined(IAM_RPMDB) QVA_t da = &rpmDBArgs; #endif #if defined(IAM_RPMK) QVA_t ka = &rpmQVKArgs; #endif #if defined(IAM_RPMBT) || defined(IAM_RPMK) char * passPhrase = ""; #endif pid_t pipeChild = 0; int ec = 0; int status; int p[2]; #ifdef IAM_RPMEIU int xx; #endif #if !defined(__GLIBC__) && !defined(__LCLINT__) environ = envp; #else /* XXX limit the fiddle up to linux for now. */ #if !defined(HAVE_SETPROCTITLE) && defined(__linux__) (void) initproctitle(argc, (char **)argv, environ); #endif #endif /* Set the major mode based on argv[0] */ /*@-nullpass@*/ #ifdef IAM_RPMBT if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD; if (!strcmp(__progname, "lt-rpmb")) bigMode = MODE_BUILD; if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD; if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD; #endif #ifdef IAM_RPMQV if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY; if (!strcmp(__progname, "lt-rpmq")) bigMode = MODE_QUERY; if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY; if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY; if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY; #endif #ifdef RPMEIU if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE; if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL; if (!strcmp(__progname, "lt-rpmi")) bigMode = MODE_INSTALL; if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL; #endif /*@=nullpass@*/ #if defined(IAM_RPMQV) /* Jumpstart option from argv[0] if necessary. */ switch (bigMode) { case MODE_QUERY: qva->qva_mode = 'q'; break; case MODE_VERIFY: qva->qva_mode = 'V'; break; case MODE_CHECKSIG: qva->qva_mode = 'K'; break; case MODE_RESIGN: qva->qva_mode = 'R'; break; case MODE_INSTALL: case MODE_ERASE: case MODE_BUILD: case MODE_REBUILD: case MODE_RECOMPILE: case MODE_TARBUILD: case MODE_REBUILDDB: case MODE_UNKNOWN: default: break; } #endif rpmcliConfigured(); #ifdef IAM_RPMBT switch (ba->buildMode) { case 'b': bigMode = MODE_BUILD; break; case 't': bigMode = MODE_TARBUILD; break; case 'B': bigMode = MODE_REBUILD; break; case 'C': bigMode = MODE_RECOMPILE; break; } if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN) bigMode = MODE_BUILD; if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN) bigMode = MODE_BUILD; #endif /* IAM_RPMBT */ #ifdef IAM_RPMDB if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) { if (da->rebuild) { if (bigMode != MODE_UNKNOWN) argerror(_("only one major mode may be specified")); else bigMode = MODE_REBUILDDB; } } #endif /* IAM_RPMDB */ #ifdef IAM_RPMQV if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) { switch (qva->qva_mode) { case 'q': bigMode = MODE_QUERY; break; case 'V': bigMode = MODE_VERIFY; break; } if (qva->qva_sourceCount) { if (qva->qva_sourceCount > 2) argerror(_("one type of query/verify may be performed at a " "time")); } if (qva->qva_flags && (bigMode & ~MODES_QV)) argerror(_("unexpected query flags")); if (qva->qva_queryFormat && (bigMode & ~MODES_QV)) argerror(_("unexpected query format")); if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV)) argerror(_("unexpected query source")); } #endif /* IAM_RPMQV */ #ifdef IAM_RPMEIU if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE)) { int iflags = (ia->installInterfaceFlags & (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)); int eflags = (ia->installInterfaceFlags & INSTALL_ERASE); if (iflags & eflags) argerror(_("only one major mode may be specified")); else if (iflags) bigMode = MODE_INSTALL; else if (eflags) bigMode = MODE_ERASE; } #endif /* IAM_RPMEIU */ #ifdef IAM_RPMK if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) { switch (ka->qva_mode) { case RPMSIGN_NONE: ka->sign = 0; break; case RPMSIGN_IMPORT_PUBKEY: case RPMSIGN_CHK_SIGNATURE: bigMode = MODE_CHECKSIG; ka->sign = 0; break; case RPMSIGN_ADD_SIGNATURE: case RPMSIGN_NEW_SIGNATURE: case RPMSIGN_DEL_SIGNATURE: bigMode = MODE_RESIGN; ka->sign = (ka->qva_mode != RPMSIGN_DEL_SIGNATURE); break; } } #endif /* IAM_RPMK */ #if defined(IAM_RPMEIU) if (!( bigMode == MODE_INSTALL ) && (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE))) argerror(_("only installation, upgrading, rmsource and rmspec may be forced")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE)) argerror(_("files may only be relocated during package installation")); if (ia->relocations && ia->qva_prefix) argerror(_("cannot use --prefix with --relocate or --excludepath")); if (bigMode != MODE_INSTALL && ia->relocations) argerror(_("--relocate and --excludepath may only be used when installing new packages")); if (bigMode != MODE_INSTALL && ia->qva_prefix) argerror(_("--prefix may only be used when installing new packages")); if (ia->qva_prefix && ia->qva_prefix[0] != '/') argerror(_("arguments to --prefix must begin with a /")); if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH)) argerror(_("--hash (-h) may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT)) argerror(_("--percent may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG)) argerror(_("--replacepkgs may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) argerror(_("--excludedocs may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && ia->incldocs) argerror(_("--includedocs may only be specified during package " "installation")); if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) argerror(_("only one of --excludedocs and --includedocs may be " "specified")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH)) argerror(_("--ignorearch may only be specified during package " "installation")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS)) argerror(_("--ignoreos may only be specified during package " "installation")); if ((ia->installInterfaceFlags & INSTALL_ALLMATCHES) && bigMode != MODE_ERASE) argerror(_("--allmatches may only be specified during package " "erasure")); if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL) argerror(_("--allfiles may only be specified during package " "installation")); if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) && bigMode != MODE_INSTALL && bigMode != MODE_ERASE) argerror(_("--justdb may only be specified during package " "installation and erasure")); if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers))) argerror(_("script disabling options may only be specified during " "package installation and erasure")); if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers))) argerror(_("trigger disabling options may only be specified during " "package installation and erasure")); if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS)) argerror(_("--nodeps may only be specified during package " "building, rebuilding, recompilation, installation, " "erasure, and verification")); if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST)) argerror(_("--test may only be specified during package installation, " "erasure, and building")); #endif /* IAM_RPMEIU */ if (rpmioRootDir && rpmioRootDir[1] && (bigMode & ~MODES_FOR_ROOT)) argerror(_("--root (-r) may only be specified during " "installation, erasure, querying, and " "database rebuilds")); if (rpmioRootDir) { switch (urlIsURL(rpmioRootDir)) { default: if (bigMode & MODES_FOR_ROOT) break; /*@fallthrough@*/ case URL_IS_UNKNOWN: if (rpmioRootDir[0] != '/') argerror(_("arguments to --root (-r) must begin with a /")); break; } } #if defined(RPM_VENDOR_OPENPKG) /* integrity-checking */ integrity_check(__progname, bigMode); #endif #if defined(IAM_RPMBT) || defined(IAM_RPMK) if (0 #if defined(IAM_RPMBT) || ba->sign #endif #if defined(IAM_RPMK) || ka->sign #endif ) /*@-branchstate@*/ { if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD || bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) { const char ** av; struct stat sb; int errors = 0; if ((av = poptGetArgs(optCon)) == NULL) { fprintf(stderr, _("no files to sign\n")); errors++; } else while (*av) { if (Stat(*av, &sb)) { fprintf(stderr, _("cannot access file %s\n"), *av); errors++; } av++; } if (errors) { ec = errors; goto exit; } if (poptPeekArg(optCon) #if defined(IAM_RPMBT) && !ba->nopassword #endif #if defined(IAM_RPMK) && !ka->nopassword #endif ) { passPhrase = Getpass(_("Enter pass phrase: ")); if (rpmCheckPassPhrase(passPhrase)) { fprintf(stderr, _("Pass phrase check failed\n")); ec = EXIT_FAILURE; goto exit; } fprintf(stderr, _("Pass phrase is good.\n")); /* XXX Getpass() should realloc instead. */ passPhrase = xstrdup(passPhrase); } } } /*@=branchstate@*/ #endif /* IAM_RPMBT || IAM_RPMK */ if (rpmioPipeOutput) { if (pipe(p) < 0) { fprintf(stderr, _("creating a pipe for --pipe failed: %m\n")); goto exit; } if (!(pipeChild = fork())) { (void) close(p[1]); (void) dup2(p[0], STDIN_FILENO); (void) close(p[0]); (void) execl("/bin/sh", "/bin/sh", "-c", rpmioPipeOutput, NULL); fprintf(stderr, _("exec failed\n")); } (void) close(p[0]); (void) dup2(p[1], STDOUT_FILENO); (void) close(p[1]); } ts = rpmtsCreate(); (void) rpmtsSetRootDir(ts, rpmioRootDir); switch (bigMode) { #ifdef IAM_RPMDB case MODE_REBUILDDB: { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}"); rpmVSFlags ovsflags; if (rpmcliQueryFlags & VERIFY_DIGEST) vsflags |= _RPMVSF_NODIGESTS; if (rpmcliQueryFlags & VERIFY_SIGNATURE) vsflags |= _RPMVSF_NOSIGNATURES; ovsflags = rpmtsSetVSFlags(ts, vsflags); ec = rpmtsRebuildDB(ts); vsflags = rpmtsSetVSFlags(ts, ovsflags); } break; #endif /* IAM_RPMDB */ #ifdef IAM_RPMBT case MODE_REBUILD: case MODE_RECOMPILE: { const char * pkg; int nbuilds = 0; while (!rpmIsVerbose()) rpmIncreaseVerbosity(); if (!poptPeekArg(optCon)) argerror(_("no packages files given for rebuild")); ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK; if (bigMode == MODE_REBUILD) { ba->buildAmount |= RPMBUILD_PACKAGEBINARY; ba->buildAmount |= RPMBUILD_RMSOURCE; ba->buildAmount |= RPMBUILD_RMSPEC; ba->buildAmount |= RPMBUILD_CLEAN; ba->buildAmount |= RPMBUILD_RMBUILD; } while ((pkg = poptGetArg(optCon))) { if (nbuilds++ > 0) { rpmFreeMacros(NULL); rpmFreeRpmrc(); (void) rpmReadConfigFiles(NULL, NULL); } ba->specFile = NULL; ba->cookie = NULL; ec = rpmInstallSource(ts, pkg, &ba->specFile, &ba->cookie); if (ec == 0) { ba->rootdir = rpmioRootDir; ba->passPhrase = passPhrase; ec = build(ts, ba, NULL); } ba->cookie = _free(ba->cookie); ba->specFile = _free(ba->specFile); if (ec) /*@loopbreak@*/ break; } } break; case MODE_BUILD: case MODE_TARBUILD: { int nbuilds = 0; #if defined(RPM_VENDOR_OPENPKG) /* no-auto-verbose-increase-for-track-and-fetch */ if (ba->buildChar != 't' && ba->buildChar != 'f') #endif while (!rpmIsVerbose()) rpmIncreaseVerbosity(); switch (ba->buildChar) { case 'a': ba->buildAmount |= RPMBUILD_PACKAGESOURCE; /*@fallthrough@*/ case 'b': ba->buildAmount |= RPMBUILD_PACKAGEBINARY; ba->buildAmount |= RPMBUILD_CLEAN; #if defined(RPM_VENDOR_MANDRIVA) if ((ba->buildChar == 'a' || ba->buildChar == 'b') && ba->shortCircuit) #else if ((ba->buildChar == 'b') && ba->shortCircuit) #endif /*@innerbreak@*/ break; /*@fallthrough@*/ case 'i': ba->buildAmount |= RPMBUILD_INSTALL; ba->buildAmount |= RPMBUILD_CHECK; if ((ba->buildChar == 'i') && ba->shortCircuit) /*@innerbreak@*/ break; /*@fallthrough@*/ case 'c': ba->buildAmount |= RPMBUILD_BUILD; if ((ba->buildChar == 'c') && ba->shortCircuit) /*@innerbreak@*/ break; /*@fallthrough@*/ case 'p': ba->buildAmount |= RPMBUILD_PREP; /*@innerbreak@*/ break; case 'l': ba->buildAmount |= RPMBUILD_FILECHECK; /*@innerbreak@*/ break; case 's': ba->buildAmount |= RPMBUILD_PACKAGESOURCE; #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK) /* no-deps-on-building-srpms */ /* enforce no dependency checking when rolling a source RPM */ ba->noDeps = 1; #endif /*@innerbreak@*/ break; case 't': /* support extracting the "%track" script/section */ ba->buildAmount |= RPMBUILD_TRACK; /* enforce no dependency checking and expansion of %setup, %patch and %prep macros */ ba->noDeps = 1; rpmDefineMacro(NULL, "setup #", RMIL_CMDLINE); rpmDefineMacro(NULL, "patch #", RMIL_CMDLINE); rpmDefineMacro(NULL, "prep %%prep", RMIL_CMDLINE); /*@innerbreak@*/ break; case 'f': ba->buildAmount |= RPMBUILD_FETCHSOURCE; ba->noDeps = 1; /*@innerbreak@*/ break; } if (!poptPeekArg(optCon)) { if (bigMode == MODE_BUILD) argerror(_("no spec files given for build")); else argerror(_("no tar files given for build")); } while ((ba->specFile = poptGetArg(optCon))) { if (nbuilds++ > 0) { rpmFreeMacros(NULL); rpmFreeRpmrc(); (void) rpmReadConfigFiles(NULL, NULL); } ba->rootdir = rpmioRootDir; ba->passPhrase = passPhrase; ba->cookie = NULL; ec = build(ts, ba, NULL); if (ec) /*@loopbreak@*/ break; } } break; #endif /* IAM_RPMBT */ #ifdef IAM_RPMEIU case MODE_ERASE: ia->depFlags = global_depFlags; if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; if (!poptPeekArg(optCon)) { if (ia->rbtid == 0) argerror(_("no packages given for erase")); ia->transFlags |= RPMTRANS_FLAG_NOFDIGESTS; ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE; ia->rbCheck = rpmcliInstallCheck; ia->rbOrder = rpmcliInstallOrder; ia->rbRun = rpmcliInstallRun; ec += rpmRollback(ts, ia, NULL); } else { ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon)); } break; case MODE_INSTALL: /* RPMTRANS_FLAG_KEEPOBSOLETE */ ia->depFlags = global_depFlags; if (!ia->incldocs) { if (ia->transFlags & RPMTRANS_FLAG_NODOCS) { ; } else if (rpmExpandNumeric("%{_excludedocs}")) ia->transFlags |= RPMTRANS_FLAG_NODOCS; } if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; /* we've already ensured !(!ia->prefix && !ia->relocations) */ /*@-branchstate@*/ if (ia->qva_prefix) { xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, NULL, ia->qva_prefix); xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, NULL, NULL); } else if (ia->relocations) { xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, NULL, NULL); } /*@=branchstate@*/ if (!poptPeekArg(optCon)) { if (ia->rbtid == 0) argerror(_("no packages given for install")); ia->transFlags |= RPMTRANS_FLAG_NOFDIGESTS; ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE; ia->rbCheck = rpmcliInstallCheck; ia->rbOrder = rpmcliInstallOrder; ia->rbRun = rpmcliInstallRun; /*@i@*/ ec += rpmRollback(ts, ia, NULL); } else { /*@-compdef -compmempass@*/ /* FIX: ia->relocations[0].newPath undefined */ ec += rpmcliInstall(ts, ia, (const char **)poptGetArgs(optCon)); /*@=compdef =compmempass@*/ } break; #endif /* IAM_RPMEIU */ #ifdef IAM_RPMQV case MODE_QUERY: if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) argerror(_("no arguments given for query")); qva->depFlags = global_depFlags; qva->qva_specQuery = rpmspecQuery; ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon)); qva->qva_specQuery = NULL; break; case MODE_VERIFY: { rpmVerifyFlags verifyFlags = VERIFY_ALL; qva->depFlags = global_depFlags; verifyFlags &= ~qva->qva_flags; qva->qva_flags = (rpmQueryFlags) verifyFlags; if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) argerror(_("no arguments given for verify")); ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon)); } break; #endif /* IAM_RPMQV */ #ifdef IAM_RPMK case MODE_CHECKSIG: { rpmVerifyFlags verifyFlags = (VERIFY_FDIGEST|VERIFY_HDRCHK|VERIFY_DIGEST|VERIFY_SIGNATURE); verifyFlags &= ~ka->qva_flags; ka->qva_flags = (rpmQueryFlags) verifyFlags; } /*@fallthrough@*/ case MODE_RESIGN: if (!poptPeekArg(optCon)) argerror(_("no arguments given")); ka->passPhrase = passPhrase; ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon)); break; #endif /* IAM_RPMK */ #if !defined(IAM_RPMQV) case MODE_QUERY: case MODE_VERIFY: #endif #if !defined(IAM_RPMK) case MODE_CHECKSIG: case MODE_RESIGN: #endif #if !defined(IAM_RPMDB) case MODE_REBUILDDB: #endif #if !defined(IAM_RPMBT) case MODE_BUILD: case MODE_REBUILD: case MODE_RECOMPILE: case MODE_TARBUILD: #endif #if !defined(IAM_RPMEIU) case MODE_INSTALL: case MODE_ERASE: #endif case MODE_UNKNOWN: #ifdef DYING /* XXX rpmIsVerbose alone stops usage spewage with every --eval */ if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) { printUsage(optCon, stderr, 0); ec = argc; } #endif break; } #if defined(IAM_RPMBT) || defined(IAM_RPMK) exit: #endif /* IAM_RPMBT || IAM_RPMK */ (void)rpmtsFree(ts); ts = NULL; if (pipeChild) { (void) fclose(stdout); (void) waitpid(pipeChild, &status, 0); } #ifdef IAM_RPMQV qva->qva_queryFormat = _free(qva->qva_queryFormat); #endif #ifdef IAM_RPMBT freeNames(); /* XXX _specPool/_pkgPool teardown should be done somewhere else. */ { extern rpmioPool _pkgPool; extern rpmioPool _specPool; _pkgPool = rpmioFreePool(_pkgPool); _specPool = rpmioFreePool(_specPool); } #endif #ifdef IAM_RPMEIU ia->relocations = rpmfiFreeRelocations(ia->relocations); #endif optCon = rpmcliFini(optCon); /* XXX limit the fiddle up to linux for now. */ #if !defined(HAVE_SETPROCTITLE) && defined(__linux__) (void) finiproctitle(); #endif /* XXX don't overflow single byte exit status */ /* XXX status 255 is special to xargs(1) */ if (ec > 254) ec = 254; rpmlog(RPMLOG_DEBUG, D_("exit code: %d\n"), ec); /*@-globstate@*/ return ec; /*@=globstate@*/ }
/** * Add %changelog section to header. * @param h header * @param sb changelog strings * @return RPMRC_OK on success */ static rpmRC addChangelog(Header h, StringBuf sb) { char *s; int i; time_t time; time_t lastTime = 0; time_t trimtime = rpmExpandNumeric("%{?_changelog_trimtime}"); char *date, *name, *text, *next; s = getStringBuf(sb); /* skip space */ SKIPSPACE(s); while (*s != '\0') { if (*s != '*') { rpmlog(RPMLOG_ERR, _("%%changelog entries must start with *\n")); return RPMRC_FAIL; } /* find end of line */ date = s; while(*s && *s != '\n') s++; if (! *s) { rpmlog(RPMLOG_ERR, _("incomplete %%changelog entry\n")); return RPMRC_FAIL; } *s = '\0'; text = s + 1; /* 4 fields of date */ date++; s = date; for (i = 0; i < 4; i++) { SKIPSPACE(s); SKIPNONSPACE(s); } SKIPSPACE(date); if (dateToTimet(date, &time)) { rpmlog(RPMLOG_ERR, _("bad date in %%changelog: %s\n"), date); return RPMRC_FAIL; } if (lastTime && lastTime < time) { rpmlog(RPMLOG_ERR, _("%%changelog not in descending chronological order\n")); return RPMRC_FAIL; } lastTime = time; /* skip space to the name */ SKIPSPACE(s); if (! *s) { rpmlog(RPMLOG_ERR, _("missing name in %%changelog\n")); return RPMRC_FAIL; } /* name */ name = s; while (*s != '\0') s++; while (s > name && risspace(*s)) { *s-- = '\0'; } if (s == name) { rpmlog(RPMLOG_ERR, _("missing name in %%changelog\n")); return RPMRC_FAIL; } /* text */ SKIPSPACE(text); if (! *text) { rpmlog(RPMLOG_ERR, _("no description in %%changelog\n")); return RPMRC_FAIL; } /* find the next leading '*' (or eos) */ s = text; do { s++; } while (*s && (*(s-1) != '\n' || *s != '*')); next = s; s--; /* backup to end of description */ while ((s > text) && risspace(*s)) { *s-- = '\0'; } if ( !trimtime || time >= trimtime ) { addChangelogEntry(h, time, name, text); } else break; s = next; } return RPMRC_OK; }
static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag) { struct Source *p; int flag = 0; const char *name = NULL; char *nump; char *fieldp = NULL; char *buf = NULL; uint32_t num = 0; switch (tag) { case RPMTAG_SOURCE: flag = RPMBUILD_ISSOURCE; name = "source"; fieldp = spec->line + 6; break; case RPMTAG_PATCH: flag = RPMBUILD_ISPATCH; name = "patch"; fieldp = spec->line + 5; break; case RPMTAG_ICON: flag = RPMBUILD_ISICON; fieldp = NULL; break; default: return -1; break; } /* Get the number */ if (tag != RPMTAG_ICON) { /* We already know that a ':' exists, and that there */ /* are no spaces before it. */ /* This also now allows for spaces and tabs between */ /* the number and the ':' */ char ch; char *fieldp_backup = fieldp; while ((*fieldp != ':') && (*fieldp != ' ') && (*fieldp != '\t')) { fieldp++; } ch = *fieldp; *fieldp = '\0'; nump = fieldp_backup; SKIPSPACE(nump); if (nump == NULL || *nump == '\0') { num = flag == RPMBUILD_ISSOURCE ? 0 : INT_MAX; } else { if (parseUnsignedNum(fieldp_backup, &num)) { rpmlog(RPMLOG_ERR, _("line %d: Bad %s number: %s\n"), spec->lineNum, name, spec->line); *fieldp = ch; return RPMRC_FAIL; } } *fieldp = ch; } /* Check whether tags of the same number haven't already been defined */ for (p = spec->sources; p != NULL; p = p->next) { if ( p->num != num ) continue; if ((tag == RPMTAG_SOURCE && p->flags == RPMBUILD_ISSOURCE) || (tag == RPMTAG_PATCH && p->flags == RPMBUILD_ISPATCH)) { rpmlog(RPMLOG_ERR, _("%s %d defined multiple times\n"), name, num); return RPMRC_FAIL; } } /* Create the entry and link it in */ p = xmalloc(sizeof(*p)); p->num = num; p->fullSource = xstrdup(field); p->flags = flag; p->source = strrchr(p->fullSource, '/'); if (p->source) { if ((buf = strrchr(p->source,'='))) p->source = buf; p->source++; } else { p->source = p->fullSource; } if (tag != RPMTAG_ICON) { p->next = spec->sources; spec->sources = p; } else { p->next = pkg->icon; pkg->icon = p; } spec->numSources++; if (tag != RPMTAG_ICON) { char *body = rpmGetPath("%{_sourcedir}/", p->source, NULL); struct stat st; int nofetch = (spec->flags & RPMSPEC_FORCE) || rpmExpandNumeric("%{_disable_source_fetch}"); /* try to download source/patch if it's missing */ if (lstat(body, &st) != 0 && errno == ENOENT && !nofetch) { char *url = NULL; if (urlIsURL(p->fullSource) != URL_IS_UNKNOWN) { url = rstrdup(p->fullSource); } else { url = rpmExpand("%{_default_source_url}", NULL); rstrcat(&url, p->source); if (*url == '%') url = _free(url); } if (url) { rpmlog(RPMLOG_WARNING, _("Downloading %s to %s\n"), url, body); if (urlGetFile(url, body) != 0) { free(url); rpmlog(RPMLOG_ERR, _("Couldn't download %s\n"), p->fullSource); return RPMRC_FAIL; } free(url); } } rasprintf(&buf, "%s%d", (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); rpmPushMacro(spec->macros, buf, NULL, body, RMIL_SPEC); free(buf); rasprintf(&buf, "%sURL%d", (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC); free(buf); #ifdef WITH_LUA { rpmlua lua = NULL; /* global state */ const char * what = (flag & RPMBUILD_ISPATCH) ? "patches" : "sources"; rpmluaPushTable(lua, what); rpmluav var = rpmluavNew(); rpmluavSetListMode(var, 1); rpmluavSetValue(var, RPMLUAV_STRING, body); rpmluaSetVar(lua, var); rpmluavFree(var); rpmluaPop(lua); } #endif free(body); } return 0; }