static rpmRC doRmSource(rpmSpec spec) { struct Source *p; Package pkg; int rc = 0; for (p = spec->sources; p != NULL; p = p->next) { if (! (p->flags & RPMBUILD_ISNO)) { char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL); rc = unlink(fn); fn = _free(fn); if (rc) goto exit; } } for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) { for (p = pkg->icon; p != NULL; p = p->next) { if (! (p->flags & RPMBUILD_ISNO)) { char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL); rc = unlink(fn); fn = _free(fn); if (rc) goto exit; } } } exit: return !rc ? RPMRC_OK : RPMRC_FAIL; }
char * rpmGenPath(const char * urlroot, const char * urlmdir, const char *urlfile) { char * xroot = rpmGetPath(urlroot, NULL); const char * root = xroot; char * xmdir = rpmGetPath(urlmdir, NULL); const char * mdir = xmdir; char * xfile = rpmGetPath(urlfile, NULL); const char * file = xfile; char * result; char * url = NULL; int nurl = 0; int ut; ut = urlPath(xroot, &root); if (url == NULL && ut > URL_IS_DASH) { url = xroot; nurl = root - xroot; } if (root == NULL || *root == '\0') root = "/"; ut = urlPath(xmdir, &mdir); if (url == NULL && ut > URL_IS_DASH) { url = xmdir; nurl = mdir - xmdir; } if (mdir == NULL || *mdir == '\0') mdir = "/"; ut = urlPath(xfile, &file); if (url == NULL && ut > URL_IS_DASH) { url = xfile; nurl = file - xfile; } if (url && nurl > 0) { char *t = rstrcat(NULL, url); t[nurl] = '\0'; url = t; } else url = xstrdup(""); result = rpmGetPath(url, root, "/", mdir, "/", file, NULL); free(xroot); free(xmdir); free(xfile); free(url); return result; }
static StringBuf addFileToTagAux(rpmSpec spec, const char * file, StringBuf sb) { char buf[BUFSIZ]; char * fn; FILE * f; fn = rpmGetPath("%{_builddir}/%{?buildsubdir:%{buildsubdir}/}", file, NULL); f = fopen(fn, "r"); if (f == NULL || ferror(f)) { sb = freeStringBuf(sb); goto exit; } while (fgets(buf, sizeof(buf), f)) { if (expandMacros(spec, spec->macros, buf, sizeof(buf))) { rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf); sb = freeStringBuf(sb); break; } appendStringBuf(sb, buf); } (void) fclose(f); exit: free(fn); return sb; }
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 int loadKeyringFromFiles(rpmts ts) { ARGV_t files = NULL; /* XXX TODO: deal with chroot path issues */ char *pkpath = rpmGetPath(ts->rootDir, "%{_keyringpath}/*.key", NULL); int nkeys = 0; rpmlog(RPMLOG_DEBUG, "loading keyring from pubkeys in %s\n", pkpath); if (rpmGlob(pkpath, NULL, &files)) { rpmlog(RPMLOG_DEBUG, "couldn't find any keys in %s\n", pkpath); goto exit; } for (char **f = files; *f; f++) { rpmPubkey key = rpmPubkeyRead(*f); if (!key) { rpmlog(RPMLOG_ERR, _("%s: reading of public key failed.\n"), *f); continue; } if (rpmKeyringAddKey(ts->keyring, key) == 0) { nkeys++; rpmlog(RPMLOG_DEBUG, "added key %s to keyring\n", *f); } rpmPubkeyFree(key); } exit: free(pkpath); argvFree(files); return nkeys; }
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; }
FD_t rpmMkTempFile(const char * prefix, char **fn) { const char *tpmacro = "%{_tmppath}"; /* always set from rpmrc */ char *tempfn; static int _initialized = 0; FD_t tfd = NULL; if (!prefix) prefix = ""; /* Create the temp directory if it doesn't already exist. */ if (!_initialized) { _initialized = 1; tempfn = rpmGenPath(prefix, tpmacro, NULL); if (rpmioMkpath(tempfn, 0755, (uid_t) -1, (gid_t) -1)) goto exit; free(tempfn); } tempfn = rpmGetPath(prefix, tpmacro, "/rpm-tmp.XXXXXX", NULL); tfd = rpmMkTemp(tempfn); if (tfd == NULL || Ferror(tfd)) { rpmlog(RPMLOG_ERR, _("error creating temporary file %s: %m\n"), tempfn); goto exit; } exit: if (tfd != NULL && fn) *fn = tempfn; else free(tempfn); return tfd; }
static JSBool rpmaug_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); rpmaug aug = ptr; jsint tiny = JSVAL_TO_INT(id); _PROP_DEBUG_ENTRY(_debug < 0); /* XXX the class has ptr == NULL, instances have ptr != NULL. */ if (ptr == NULL) return JS_TRUE; switch (tiny) { case _DEBUG: *vp = INT_TO_JSVAL(_debug); break; default: if (JSVAL_IS_STRING(id) && *vp == JSVAL_VOID) { const char * name = JS_GetStringBytes(JS_ValueToString(cx, id)); const char * _path = rpmGetPath(_defvar, "/", name, NULL); const char * _value = NULL; if (rpmaugGet(aug, _path, &_value) >= 0 && _value != NULL) *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)); _path = _free(_path); _value = _free(_value); break; } break; } return JS_TRUE; }
int mayAddToFilesAwaitingFiletriggers(const char * rootDir, rpmfi fi, int install_or_erase) { const char * fn; FILE * fp; int rc = RPMRC_FAIL; int xx; if (filetriggers_dir() == NULL) return RPMRC_OK; fn = rpmGetPath(rootDir ? rootDir : "/", files_awaiting_filetriggers, NULL); fp = fopen(fn, "a"); if (fp == NULL) { rpmlog(RPMLOG_ERR, _("%s: open failed: %s\n"), fn, strerror(errno)); goto exit; } fi = rpmfiInit(fi, 0); if (fi != NULL) while (rpmfiNext(fi) >= 0) { xx = fputc(install_or_erase ? '+' : '-', fp); xx = fputs(rpmfiFN(fi), fp); xx = fputc('\n', fp); } xx = fclose(fp); rc = RPMRC_OK; exit: fn = _free(fn); return rc; }
const char * getSourceDir(rpmfileAttrs attr) #endif { const char * dir = NULL; #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ const char *fn; /* support splitted source directories, i.e., source files which are alternatively placed into the .spec directory and picked up from there, too. */ if (attr & (RPMFILE_SOURCE|RPMFILE_PATCH|RPMFILE_ICON) && filename != NULL) { fn = rpmGetPath("%{_specdir}/", filename, NULL); if (access(fn, F_OK) == 0) dir = "%{_specdir}/"; fn = _free(fn); } if (dir != NULL) { } else #endif if (attr & RPMFILE_SOURCE) dir = "%{_sourcedir}/"; else if (attr & RPMFILE_PATCH) dir = "%{_patchdir}/"; else if (attr & RPMFILE_ICON) dir = "%{_icondir}/"; return dir; }
/*@only@*/ static rpmvf rpmvfNew(rpmts ts, rpmfi fi, int i, rpmVerifyAttrs omitMask) /*@*/ { rpmvf vf = DRD_xcalloc(1, sizeof(*vf)); #ifdef NOTYET vf->_item.use = yarnNewLock(1); vf->_item.pool = NULL; #endif /*@-mods@*/ vf->fn = rpmGetPath(rpmtsRootDir(ts), fi->dnl[fi->dil[i]], fi->bnl[i], NULL); /*@=mods@*/ vf->flink = fi->flinks[i]; vf->fuser = fi->fuser[i]; vf->fgroup = fi->fgroup[i]; { struct stat *st = &vf->sb; st->st_dev = st->st_rdev = fi->frdevs[i]; st->st_ino = fi->finodes[i]; st->st_mode = fi->fmodes[i]; #ifdef NOTNEEDED st->st_nlink = rpmfiFNlink(fi) + (int)S_ISDIR(st->st_mode); #endif if (unameToUid(vf->fuser, &st->st_uid) == -1) st->st_uid = 0; /* XXX */ if (gnameToGid(vf->fgroup, &st->st_gid) == -1) st->st_gid = 0; /* XXX */ st->st_size = fi->fsizes[i]; st->st_blksize = 4 * 1024; /* XXX */ st->st_blocks = (st->st_size + (st->st_blksize - 1)) / st->st_blksize; st->st_atime = st->st_ctime = st->st_mtime = fi->fmtimes[i]; } vf->fflags = fi->fflags[i]; vf->fstate = fi->fstates[i]; vf->vflags = fi->vflags[i]; vf->dalgo = fi->fdigestalgos ? fi->fdigestalgos[i] : fi->digestalgo; vf->dlen = fi->digestlen; vf->digest = fi->digests + (fi->digestlen * i); /* Don't verify any features in omitMask. */ vf->vflags &= ~(omitMask | RPMVERIFY_FAILURES); /* Content checks of %ghost files are meaningless. */ if (vf->fflags & RPMFILE_GHOST) vf->vflags &= ~(RPMVERIFY_FDIGEST | RPMVERIFY_FILESIZE | RPMVERIFY_MTIME | RPMVERIFY_LINKTO | RPMVERIFY_HMAC); return vf; }
void init_hr_swinst(void) { #if defined(HAVE_LIBRPM) || defined(_PATH_HRSW_directory) SWI_t *swi = &_myswi; /* XXX static for now */ #endif #ifdef HAVE_LIBRPM struct stat stat_buf; #endif /* * Read settings from config file, * or take system-specific defaults */ #ifdef HAVE_LIBRPM if (swi->swi_directory == NULL) { char path[SNMP_MAXPATH]; /* * XXX distinguish between rpm-2.5.x and rpm-2.9x */ #ifdef HAVE_RPMGETPATH rpmReadConfigFiles(NULL, NULL); swi->swi_dbpath = rpmGetPath("%{_dbpath}", NULL); #else rpmReadConfigFiles(NULL, NULL, NULL, 0); swi->swi_dbpath = rpmGetVar(RPMVAR_DBPATH); #endif if (swi->swi_directory != NULL) free(swi->swi_directory); snprintf(path, sizeof(path), "%s/Packages", swi->swi_dbpath); if (stat(path, &stat_buf) == -1) snprintf(path, sizeof(path), "%s/packages.rpm", swi->swi_dbpath); path[ sizeof(path)-1 ] = 0; swi->swi_directory = strdup(path); } #else # ifdef _PATH_HRSW_directory if (swi->swi_directory == NULL) { swi->swi_directory = _PATH_HRSW_directory; } strcpy(swi->swi_name, "[installed name]"); /* default name */ # else /* * XXX SunOS4 package directory is ?? -MJS */ return; /* packages not known - don't register */ # endif #endif REGISTER_MIB("host/hr_swinst", hrswinst_variables, variable4, hrswinst_variables_oid); }
static rpmRC readIcon(Header h, const char * file) { char *fn = NULL; uint8_t *icon = NULL; FD_t fd = NULL; rpmRC rc = RPMRC_FAIL; /* assume failure */ off_t size; size_t nb, iconsize; /* XXX use rpmGenPath(rootdir, "%{_sourcedir}/", file) for icon path. */ fn = rpmGetPath("%{_sourcedir}/", file, NULL); fd = Fopen(fn, "r.ufdio"); if (fd == NULL) { rpmlog(RPMLOG_ERR, _("Unable to open icon %s: %s\n"), fn, Fstrerror(fd)); goto exit; } size = fdSize(fd); iconsize = (size >= 0 ? size : (8 * BUFSIZ)); if (iconsize == 0) { rc = RPMRC_OK; /* XXX Eh? */ goto exit; } icon = xmalloc(iconsize + 1); *icon = '\0'; nb = Fread(icon, sizeof(icon[0]), iconsize, fd); if (Ferror(fd) || (size >= 0 && nb != size)) { rpmlog(RPMLOG_ERR, _("Unable to read icon %s: %s\n"), fn, Fstrerror(fd)); goto exit; } if (rstreqn((char*)icon, "GIF", sizeof("GIF")-1)) { headerPutBin(h, RPMTAG_GIF, icon, iconsize); } else if (rstreqn((char*)icon, "/* XPM", sizeof("/* XPM")-1)) { headerPutBin(h, RPMTAG_XPM, icon, iconsize); } else { rpmlog(RPMLOG_ERR, _("Unknown icon type: %s\n"), file); goto exit; } rc = RPMRC_OK; exit: Fclose(fd); free(fn); free(icon); return rc; }
static rpmRC addFileToTag(rpmSpec spec, const char * file, Header h, rpmTagVal tag, int append) { StringBuf sb = NULL; char buf[BUFSIZ]; char * fn; FILE * f; rpmRC rc = RPMRC_FAIL; /* assume failure */ /* no script file is not an error */ if (file == NULL) return RPMRC_OK; fn = rpmGetPath("%{_builddir}/%{?buildsubdir:%{buildsubdir}/}", file, NULL); f = fopen(fn, "r"); if (f == NULL) { rpmlog(RPMLOG_ERR,_("Could not open %s file: %s\n"), rpmTagGetName(tag), file); goto exit; } sb = newStringBuf(); if (append) { const char *s = headerGetString(h, tag); if (s) { appendLineStringBuf(sb, s); headerDel(h, tag); } } while (fgets(buf, sizeof(buf), f)) { char *expanded; if (rpmExpandMacros(spec->macros, buf, &expanded, 0) < 0) { rpmlog(RPMLOG_ERR, _("%s: line: %s\n"), fn, buf); goto exit; } appendStringBuf(sb, expanded); free(expanded); } headerPutString(h, tag, getStringBuf(sb)); rc = RPMRC_OK; exit: if (f) fclose(f); free(fn); freeStringBuf(sb); return rc; }
int rpmtsSetRootDir(rpmts ts, const char * rootDir) { if (ts == NULL || (rootDir && rootDir[0] != '/')) { return -1; } ts->rootDir = _free(ts->rootDir); /* Ensure clean path with a trailing slash */ ts->rootDir = rootDir ? rpmGetPath(rootDir, NULL) : xstrdup("/"); if (!rstreq(ts->rootDir, "/")) { rstrcat(&ts->rootDir, "/"); } return 0; }
/* * There is no function for creating unique temporary fifos so create * unique temporary directory and then create fifo in it. */ static char *mkTempFifo(void) { char *tmppath = NULL, *tmpdir = NULL, *fifofn = NULL; mode_t mode; tmppath = rpmExpand("%{_tmppath}", NULL); if (rpmioMkpath(tmppath, 0755, (uid_t) -1, (gid_t) -1)) goto exit; tmpdir = rpmGetPath(tmppath, "/rpm-tmp.XXXXXX", NULL); mode = umask(0077); tmpdir = mkdtemp(tmpdir); umask(mode); if (tmpdir == NULL) { rpmlog(RPMLOG_ERR, _("error creating temp directory %s: %m\n"), tmpdir); tmpdir = _free(tmpdir); goto exit; } fifofn = rpmGetPath(tmpdir, "/fifo", NULL); if (mkfifo(fifofn, 0600) == -1) { rpmlog(RPMLOG_ERR, _("error creating fifo %s: %m\n"), fifofn); fifofn = _free(fifofn); } exit: if (fifofn == NULL && tmpdir != NULL) unlink(tmpdir); free(tmppath); free(tmpdir); return fifofn; }
static void mayStartFiletrigger(const char * rootDir, struct filetrigger * trigger) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies trigger, rpmGlobalMacroContext, fileSystem, internalState @*/ { if (!trigger->command_pipe) { const char * dn = filetriggers_dir(); const char * cmd; if (dn == NULL) return; cmd = rpmGetPath(dn, "/", trigger->name, ".script", NULL); rpmlog(RPMLOG_DEBUG, D_("[filetriggers] spawning %s\n"), cmd); trigger->command_pipe = popen_with_root(rootDir, cmd, &trigger->command_pid); cmd = _free(cmd); } }
int rpmtsOpenDB(rpmts ts, int dbmode) { int rc = 0; if (ts->rdb != NULL && ts->dbmode == dbmode) return 0; (void) rpmtsCloseDB(ts); /* XXX there's a potential db lock race here. */ ts->dbmode = dbmode; rc = rpmdbOpen(ts->rootDir, &ts->rdb, ts->dbmode, 0644); if (rc) { char * dn = rpmGetPath(ts->rootDir, "%{_dbpath}", NULL); rpmlog(RPMLOG_ERR, _("cannot open Packages database in %s\n"), dn); free(dn); } return rc; }
rpmsx rpmsxNew(const char * fn, unsigned int flags) { rpmsx sx = rpmsxGetPool(_rpmsxPool); sx->fn = NULL; sx->flags = flags; #if defined(WITH_SELINUX) if (fn == NULL) fn = selinux_file_context_path(); if (sx->flags) set_matchpathcon_flags(sx->flags); { int rc; sx->fn = rpmGetPath(fn, NULL); rc = matchpathcon_init(sx->fn); /* If matchpathcon_init fails, turn off SELinux functionality. */ if (rc < 0) sx->fn = _free(sx->fn); } #endif return rpmsxLink(sx); }
/* --------------------------------------------------------------------- */ void netsnmp_swinst_arch_init(void) { char *rpmdbpath = NULL; const char *dbpath; struct stat stat_buf; #ifdef HAVE_RPMGETPATH rpmReadConfigFiles( NULL, NULL ); rpmdbpath = rpmGetPath( "%{_dbpath}", NULL ); dbpath = rpmdbpath; #else dbpath = "/var/lib/rpm"; /* Most likely */ #endif snprintf( pkg_directory, SNMP_MAXPATH, "%s/Packages", dbpath ); SNMP_FREE(rpmdbpath); dbpath = NULL; if (-1 == stat( pkg_directory, &stat_buf )) { snmp_log(LOG_ERR, "Can't find directory of RPM packages"); pkg_directory[0] = '\0'; } }
int rpmMkdirs(const char *root, const char *pathstr) { ARGV_t dirs = NULL; int rc = 0; argvSplit(&dirs, pathstr, ":"); for (char **d = dirs; *d; d++) { char *path = rpmGetPath(root ? root : "", *d, NULL); if ((rc = rpmioMkpath(path, 0755, -1, -1)) != 0) { const char *msg = _("failed to create directory"); /* try to be more informative if the failing part was a macro */ if (**d == '%') { rpmlog(RPMLOG_ERR, "%s %s: %s: %m\n", msg, *d, path); } else { rpmlog(RPMLOG_ERR, "%s %s: %m\n", msg, path); } } free(path); if (rc) break; } argvFree(dirs); return rc; }
/*@-globs -mods@*/ /* XXX hide rpmGlobalMacroContext mods for now. */ rpmlua rpmluaNew(void) { rpmlua lua = rpmluaGetPool(_rpmluaPool); lua_State *L = lua_open(); /*@-readonlytrans -nullassign @*/ /*@observer@*/ /*@unchecked@*/ static const luaL_reg lualibs[] = { /* standard LUA libraries */ {"", luaopen_base}, /* XXX 5.1.4 internal has not */ #if defined(LUA_COLIBNAME) && LUA_VERSION_NUM > 501 {LUA_COLIBNAME, luaopen_coroutine}, #endif #if defined(LUA_TABLIBNAME) {LUA_TABLIBNAME, luaopen_table}, #endif #if defined(LUA_IOLIBNAME) {LUA_IOLIBNAME, luaopen_io}, #endif #if defined(LUA_OSLIBNAME) {LUA_OSLIBNAME, luaopen_os}, #endif #if defined(LUA_STRLIBNAME) {LUA_STRLIBNAME, luaopen_string}, #endif #if defined(LUA_BITLIBNAME) /* XXX lua >= 5.2.0 only */ {LUA_BITLIBNAME, luaopen_bit32}, #endif #if defined(LUA_MATHLIBNAME) {LUA_MATHLIBNAME, luaopen_math}, #endif #if defined(LUA_DBLIBNAME) {LUA_DBLIBNAME, luaopen_debug}, #endif #if defined(LUA_LOADLIBNAME) {LUA_LOADLIBNAME, luaopen_package}, #endif #ifdef WITH_SYCK {"lsyck", luaopen_syck}, #endif /* WITH_SYCK */ /* local LUA libraries (RPM only) */ #ifdef WITH_LUA_INTERNAL {"posix", luaopen_posix}, #ifdef HACK {"rex_posix", luaopen_rex_posix}, {"rex_pcre", luaopen_rex_pcre}, #endif {"uuid", luaopen_uuid}, {"wrs", luaopen_wrs}, #ifdef USE_LUA_CRYPTO /* XXX external lua modules instead. */ {"crypto", luaopen_crypto}, {"lxp", luaopen_lxp}, #endif #ifdef USE_LUA_SOCKET /* XXX external lua modules instead. */ {"socket", luaopen_socket_core}, #endif {"local", luaopen_local}, #endif {"rpm", luaopen_rpm}, {NULL, NULL}, }; /*@=readonlytrans =nullassign @*/ /*@observer@*/ /*@unchecked@*/ const luaL_reg *lib = lualibs; char *path_buf; char *path_next; char *path; lua->L = L; lua->pushsize = 0; lua->storeprint = 0; /* XXX TODO: use an rpmiob here. */ lua->printbufsize = 0; lua->printbufused = 0; lua->printbuf = NULL; for (; lib->name; lib++) { /*@-noeffectuncon@*/ lua_pushcfunction(L, lib->func); lua_pushstring(L, lib->name); lua_call(L, 1, 0); /*@=noeffectuncon@*/ } { const char * _lua_path = rpmGetPath(rpmluaPath, NULL); if (_lua_path != NULL) { lua_pushliteral(L, "LUA_PATH"); lua_pushstring(L, _lua_path); _lua_path = _free(_lua_path); } } #if defined(LUA_GLOBALSINDEX) lua_rawset(L, LUA_GLOBALSINDEX); #else lua_pushglobaltable(L); #endif lua_pushliteral(L, "print"); lua_pushcfunction(L, rpm_print); #if defined(LUA_GLOBALSINDEX) lua_rawset(L, LUA_GLOBALSINDEX); #else lua_pushglobaltable(L); #endif rpmluaSetData(lua, "lua", lua); /* load all standard RPM Lua script files */ path_buf = xstrdup(rpmluaFiles); for (path = path_buf; path != NULL && *path != '\0'; path = path_next) { const char **av; struct stat st; int ac, i; /* locate start of next path element */ path_next = strchr(path, ':'); if (path_next != NULL && *path_next == ':') *path_next++ = '\0'; else path_next = path + strlen(path); /* glob-expand the path element */ ac = 0; av = NULL; if ((i = rpmGlob(path, &ac, &av)) != 0) continue; /* work-off each resulting file from the path element */ for (i = 0; i < ac; i++) { const char *fn = av[i]; if (fn[0] == '@' /* attention */) { fn++; #if defined(RPM_VENDOR_OPENPKG) /* stick-with-rpm-file-sanity-checking */ || \ !defined(POPT_ERROR_BADCONFIG) /* XXX POPT 1.15 retrofit */ if (!rpmSecuritySaneFile(fn)) #else if (!poptSaneFile(fn)) #endif { rpmlog(RPMLOG_WARNING, "existing RPM Lua script file \"%s\" considered INSECURE -- not loaded\n", fn); /*@innercontinue@*/ continue; } } if (Stat(fn, &st) != -1) (void)rpmluaRunScriptFile(lua, fn); av[i] = _free(av[i]); } av = _free(av); } path_buf = _free(path_buf); return ((rpmlua)rpmioLinkPoolItem((rpmioItem)lua, __FUNCTION__, __FILE__, __LINE__)); }
static JSBool rpmaug_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); rpmaug aug = ptr; _RESOLVE_DEBUG_ENTRY(_debug); if (ptr == NULL) { /* don't resolve to parent prototypes objects. */ *objp = NULL; goto exit; } /* Lazily resolve new strings, with duplication to Augeas defvar too. */ if ((flags & JSRESOLVE_ASSIGNING) && JSVAL_IS_STRING(id)) { const char *name = JS_GetStringBytes(JS_ValueToString(cx, id)); const char * _path; const char * _value; int xx; JSFunctionSpec *fsp; /* XXX avoid "aug.print" method namess duped into defvar space? */ for (fsp = rpmaug_funcs; fsp->name != NULL; fsp++) { if (!strcmp(fsp->name, name)) { *objp = obj; /* XXX always resolve in this object. */ goto exit; } } /* See if NAME exists in DEFVAR path. */ _path = rpmGetPath(_defvar, "/", name, NULL); _value = NULL; switch (rpmaugGet(aug, _path, &_value)) { /* XXX For now, force all defvar's to be single valued strings. */ case -1:/* multiply defined */ case 0: /* not found */ /* Create an empty Augeas defvar for NAME */ xx = rpmaugDefvar(aug, name, ""); /*@fallthrough@*/ case 1: /* found */ /* Reflect the Augeas defvar NAME into JS Aug properties. */ if (JS_DefineProperty(cx, obj, name, (_value != NULL ? STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)) : JSVAL_VOID), NULL, NULL, JSPROP_ENUMERATE)) break; /*@fallthrough@*/ default: assert(0); break; } _path = _free(_path); _value = _free(_value); } *objp = obj; /* XXX always resolve in this object. */ exit: return JS_TRUE; }
/*@-globstate@*/ poptContext rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable) /*@globals rpmpoptfiles @*/ /*@modifies rpmpoptfiles @*/ { poptContext optCon; int rc; int xx; int i; #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE) /*@-noeffect@*/ mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ /*@=noeffect@*/ #endif /*@-globs -mods@*/ setprogname(argv[0]); /* Retrofit glibc __progname */ /* XXX glibc churn sanity */ if (__progname == NULL) { if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++; else __progname = argv[0]; } /*@=globs =mods@*/ /* Insure that stdin/stdout/stderr are open, lest stderr end up in rpmdb. */ { static const char _devnull[] = "/dev/null"; #if defined(STDIN_FILENO) (void) checkfd(_devnull, STDIN_FILENO, O_RDONLY); #endif #if defined(STDOUT_FILENO) (void) checkfd(_devnull, STDOUT_FILENO, O_WRONLY); #endif #if defined(STDERR_FILENO) (void) checkfd(_devnull, STDERR_FILENO, O_WRONLY); #endif } #if defined(RPM_VENDOR_WINDRIVER) (void) setRuntimeRelocPaths(); #endif #if defined(ENABLE_NLS) && !defined(__LCLINT__) (void) setlocale(LC_ALL, "" ); (void) bindtextdomain(PACKAGE, __localedir); (void) textdomain(PACKAGE); #endif rpmSetVerbosity(RPMLOG_NOTICE); if (optionsTable == NULL) { /* Read rpm configuration (if not already read). */ rpmcliConfigured(); return NULL; } /* read all RPM POPT configuration files */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--rpmpopt") == 0 && i+1 < argc) { rpmpoptfiles = argv[i+1]; break; } else if (strncmp(argv[i], "--rpmpopt=", 10) == 0) { rpmpoptfiles = argv[i]+10; break; } } /* XXX strip off the "lt-" prefix so that rpmpopt aliases "work". */ { static const char lt_[] = "lt-"; const char * s = __progname; if (!strncmp(s, lt_, sizeof(lt_)-1)) s += sizeof(lt_)-1; /*@-nullpass -temptrans@*/ optCon = poptGetContext(s, argc, (const char **)argv, optionsTable, 0); /*@=nullpass =temptrans@*/ } #if defined(RPM_VENDOR_OPENPKG) /* stick-with-rpm-file-sanity-checking */ || \ !defined(POPT_ERROR_BADCONFIG) /* XXX POPT 1.15 retrofit */ { char * path_buf = xstrdup(rpmpoptfiles); char *path; char *path_next; for (path = path_buf; path != NULL && *path != '\0'; path = path_next) { const char **av; int ac; /* locate start of next path element */ path_next = strchr(path, ':'); if (path_next != NULL && *path_next == ':') *path_next++ = '\0'; else path_next = path + strlen(path); /* glob-expand the path element */ ac = 0; av = NULL; if ((xx = rpmGlob(path, &ac, &av)) != 0) continue; /* work-off each resulting file from the path element */ for (i = 0; i < ac; i++) { const char *fn = av[i]; if (fn[0] == '@' /* attention */) { fn++; if (!rpmSecuritySaneFile(fn)) { rpmlog(RPMLOG_WARNING, "existing POPT configuration file \"%s\" considered INSECURE -- not loaded\n", fn); /*@innercontinue@*/ continue; } } (void) poptReadConfigFile(optCon, fn); av[i] = _free(av[i]); } av = _free(av); } path_buf = _free(path_buf); } #else /* XXX FIXME: better error message is needed. */ if ((xx = poptReadConfigFiles(optCon, rpmpoptfiles)) != 0) rpmlog(RPMLOG_WARNING, "existing POPT configuration file \"%s\" considered INSECURE -- not loaded\n", rpmpoptfiles); #endif #if defined(RPM_VENDOR_WINDRIVER) { const char * poptAliasFn = rpmGetPath(__usrlibrpm, "/rpmpopt", NULL); (void) poptReadConfigFile(optCon, poptAliasFn); poptAliasFn = _free(poptAliasFn); } #endif /* read standard POPT configuration files */ /* XXX FIXME: the 2nd arg useEnv flag is UNUSED. */ (void) poptReadDefaultConfig(optCon, 1); #if defined(RPM_VENDOR_WINDRIVER) { const char * poptExecPath = rpmGetPath(__usrlibrpm, NULL); poptSetExecPath(optCon, poptExecPath, 1); poptExecPath = _free(poptExecPath); } #else poptSetExecPath(optCon, USRLIBRPM, 1); #endif /* Process all options, whine if unknown. */ while ((rc = poptGetNextOpt(optCon)) > 0) { const char * optArg = poptGetOptArg(optCon); /*@-dependenttrans -observertrans@*/ /* Avoid popt memory leaks. */ optArg = _free(optArg); /*@=dependenttrans =observertrans @*/ switch (rc) { default: /*@-nullpass@*/ fprintf(stderr, _("%s: option table misconfigured (%d)\n"), __progname, rc); /*@=nullpass@*/ exit(EXIT_FAILURE); /*@notreached@*/ /*@switchbreak@*/ break; } } if (rc < -1) { /*@-nullpass@*/ fprintf(stderr, "%s: %s: %s\n", __progname, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(rc)); /*@=nullpass@*/ exit(EXIT_FAILURE); } /* Read rpm configuration (if not already read). */ rpmcliConfigured(); if (_debug) { rpmIncreaseVerbosity(); rpmIncreaseVerbosity(); } /* Initialize header stat collection. */ /*@-mods@*/ _hdr_stats = _rpmts_stats; /*@=mods@*/ return optCon; }
rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating) { struct cpioSourceArchive_s csabuf; CSA_t csa = &csabuf; rpmRC rc; const char *errorString; Package pkg; char *pkglist = NULL; trimChangelog(spec->packages->header); for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) { char *fn; if (pkg->fileList == NULL) continue; if ((rc = processScriptFiles(spec, pkg))) return rc; if (cookie) { headerPutString(pkg->header, RPMTAG_COOKIE, cookie); } /* Copy changelog from src rpm */ headerCopyTags(spec->packages->header, pkg->header, copyTags); headerPutString(pkg->header, RPMTAG_RPMVERSION, VERSION); headerPutString(pkg->header, RPMTAG_BUILDHOST, buildHost()); headerPutUint32(pkg->header, RPMTAG_BUILDTIME, getBuildTime(), 1); addPackageProvides(pkg->header); { char * optflags = rpmExpand("%{optflags}", NULL); headerPutString(pkg->header, RPMTAG_OPTFLAGS, optflags); optflags = _free(optflags); } if (spec->sourcePkgId != NULL) { headerPutBin(pkg->header, RPMTAG_SOURCEPKGID, spec->sourcePkgId,16); } if (cheating) { (void) rpmlibNeedsFeature(pkg->header, "ShortCircuited", "4.9.0-1"); } { char *binFormat = rpmGetPath("%{_rpmfilename}", NULL); char *binRpm, *binDir; binRpm = headerFormat(pkg->header, binFormat, &errorString); binFormat = _free(binFormat); if (binRpm == NULL) { rpmlog(RPMLOG_ERR, _("Could not generate output " "filename for package %s: %s\n"), headerGetString(pkg->header, RPMTAG_NAME), errorString); return RPMRC_FAIL; } fn = rpmGetPath("%{_rpmdir}/", binRpm, NULL); if ((binDir = strchr(binRpm, '/')) != NULL) { struct stat st; char *dn; *binDir = '\0'; dn = rpmGetPath("%{_rpmdir}/", binRpm, NULL); if (stat(dn, &st) < 0) { switch(errno) { case ENOENT: if (mkdir(dn, 0755) == 0) break; default: rpmlog(RPMLOG_ERR,_("cannot create %s: %s\n"), dn, strerror(errno)); break; } } dn = _free(dn); } binRpm = _free(binRpm); } memset(csa, 0, sizeof(*csa)); csa->cpioArchiveSize = 0; csa->cpioFdIn = fdNew(); csa->cpioList = rpmfiLink(pkg->cpioList); rc = writeRPM(&pkg->header, NULL, fn, csa, NULL); csa->cpioList = rpmfiFree(csa->cpioList); csa->cpioFdIn = fdFree(csa->cpioFdIn); if (rc == RPMRC_OK) { /* Do check each written package if enabled */ char *pkgcheck = rpmExpand("%{?_build_pkgcheck} ", fn, NULL); if (pkgcheck[0] != ' ') { rc = checkPackages(pkgcheck); } pkgcheck = _free(pkgcheck); rstrcat(&pkglist, fn); rstrcat(&pkglist, " "); } fn = _free(fn); if (rc != RPMRC_OK) { pkglist = _free(pkglist); return rc; } } /* Now check the package set if enabled */ if (pkglist != NULL) { char *pkgcheck_set = rpmExpand("%{?_build_pkgcheck_set} ", pkglist, NULL); if (pkgcheck_set[0] != ' ') { /* run only if _build_pkgcheck_set is defined */ checkPackages(pkgcheck_set); } pkgcheck_set = _free(pkgcheck_set); pkglist = _free(pkglist); } return RPMRC_OK; }
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 parseFiles(rpmSpec spec) { int nextPart, res = PART_ERROR; Package pkg; int rc, argc; int arg; const char ** argv = NULL; const char *name = NULL; int flag = PART_SUBNAME; poptContext optCon = NULL; struct poptOption optionsTable[] = { { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL}, { NULL, 'f', POPT_ARG_STRING, NULL, 'f', NULL, NULL}, { 0, 0, 0, 0, 0, NULL, NULL} }; /* XXX unmask %license while parsing %files */ rpmPushMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC); if ((rc = poptParseArgvString(spec->line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"), spec->lineNum, poptStrerror(rc)); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { if (arg == 'n') { flag = PART_NAME; } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); goto exit; } if (poptPeekArg(optCon)) { if (name == NULL) name = poptGetArg(optCon); if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"), spec->lineNum, spec->line); goto exit; } } if (lookupPackage(spec, name, flag, &pkg)) goto exit; /* * This should be an error, but its surprisingly commonly abused for the * effect of multiple -f arguments in versions that dont support it. * Warn but preserve behavior, except for leaking memory. */ if (pkg->fileList != NULL) { rpmlog(RPMLOG_WARNING, _("line %d: multiple %%files for package '%s'\n"), spec->lineNum, rpmstrPoolStr(pkg->pool, pkg->name)); pkg->fileList = argvFree(pkg->fileList); } for (arg=1; arg<argc; arg++) { if (rstreq(argv[arg], "-f") && argv[arg+1]) { char *file = rpmGetPath(argv[arg+1], NULL); argvAdd(&(pkg->fileFile), file); free(file); } } pkg->fileList = argvNew(); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; } else if (rc < 0) { goto exit; } else { while (! (nextPart = isPart(spec->line))) { argvAdd(&(pkg->fileList), spec->line); if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { nextPart = PART_NONE; break; } else if (rc < 0) { goto exit; } } } res = nextPart; exit: rpmPopMacro(NULL, "license"); free(argv); poptFreeContext(optCon); return res; }
static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags, const char *buildRoot, int recursing) { int parsePart = PART_PREAMBLE; int initialPackage = 1; rpmSpec spec; /* Set up a new Spec structure with no packages. */ spec = newSpec(); spec->specFile = rpmGetPath(specFile, NULL); pushOFI(spec, 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); addMacro(NULL, "_licensedir", NULL, "%{_defaultlicensedir}", RMIL_SPEC); spec->recursing = recursing; spec->flags = flags; /* 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) { 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: case PART_FILETRIGGERIN: case PART_FILETRIGGERUN: case PART_FILETRIGGERPOSTUN: case PART_TRANSFILETRIGGERIN: case PART_TRANSFILETRIGGERUN: case PART_TRANSFILETRIGGERPOSTUN: parsePart = parseScript(spec, parsePart); break; case PART_FILES: parsePart = parseFiles(spec); break; case PART_POLICIES: parsePart = parsePolicies(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] = parseSpec(specFile, flags, buildRoot, 1); if (spec->BASpecs[index] == 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); rpmSpecFree(spec); spec = nspec; } goto exit; } } 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 */ for (Package 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; } } /* Add arch, os and platform, self-provides etc for each package */ addTargets(spec->packages); /* Check for encoding in each package unless disabled */ if (!(spec->flags & RPMSPEC_NOUTF8)) { int badenc = 0; for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) { if (checkForEncoding(pkg->header, 0) != RPMRC_OK) { badenc = 1; } } if (badenc) goto errxit; } closeSpec(spec); exit: /* Assemble source header from parsed components */ initSourceHeader(spec); return spec; errxit: rpmSpecFree(spec); return NULL; }
rpmRC buildSpec(rpmts ts, Spec spec, int what, int test) { rpmRC rc = RPMRC_OK; /* Generate a keypair lazily. */ if (spec->dig == NULL) spec->dig = pgpDigNew(RPMVSF_DEFAULT, PGPPUBKEYALGO_DSA); if (!spec->recursing && spec->BACount) { int x; /* When iterating over BANames, do the source */ /* packaging on the first run, and skip RMSOURCE altogether */ if (spec->BASpecs != NULL) for (x = 0; x < spec->BACount; x++) { if ((rc = buildSpec(ts, spec->BASpecs[x], (what & ~RPMBUILD_RMSOURCE) | (x ? 0 : (what & RPMBUILD_PACKAGESOURCE)), test))) { goto exit; } } } else { /* support "%track" script/section */ if ((what & RPMBUILD_TRACK) && (rc = doScript(spec, RPMBUILD_TRACK, NULL, NULL, test))) goto exit; if ((what & RPMBUILD_PREP) && (rc = doScript(spec, RPMBUILD_PREP, NULL, NULL, test))) goto exit; if ((what & RPMBUILD_BUILD) && (rc = doScript(spec, RPMBUILD_BUILD, NULL, NULL, test))) goto exit; if ((what & RPMBUILD_INSTALL) && (rc = doScript(spec, RPMBUILD_INSTALL, NULL, NULL, test))) goto exit; if ((what & RPMBUILD_CHECK) && (rc = doScript(spec, RPMBUILD_CHECK, NULL, NULL, test))) goto exit; if ((what & RPMBUILD_PACKAGESOURCE) && (rc = processSourceFiles(spec))) goto exit; if (((what & RPMBUILD_INSTALL) || (what & RPMBUILD_PACKAGEBINARY) || (what & RPMBUILD_FILECHECK)) && (rc = processBinaryFiles(spec, what & RPMBUILD_INSTALL, test))) goto exit; if (((what & RPMBUILD_PACKAGESOURCE) && !test) && (rc = packageSources(spec))) return rc; if (((what & RPMBUILD_PACKAGEBINARY) && !test) && (rc = packageBinaries(spec))) goto exit; if ((what & RPMBUILD_CLEAN) && (rc = doScript(spec, RPMBUILD_CLEAN, NULL, NULL, test))) goto exit; if ((what & RPMBUILD_RMBUILD) && (rc = doScript(spec, RPMBUILD_RMBUILD, NULL, NULL, test))) goto exit; } if (what & RPMBUILD_RMSOURCE) doRmSource(spec); if (what & RPMBUILD_RMSPEC) (void) Unlink(spec->specFile); #if defined(RPM_VENDOR_OPENPKG) /* auto-remove-source-directories */ /* In OpenPKG we use per-package %{_sourcedir} and %{_specdir} definitions (macros have trailing ".../%{name}"). On removal of source(s) and .spec file, this per-package directory would be kept (usually <prefix>/RPM/SRC/<name>/), because RPM does not know about this OpenPKG convention. So, let RPM try(!) to remove the two directories (if they are empty) and just ignore removal failures (if they are still not empty). */ if (what & RPMBUILD_RMSOURCE) { const char *pn; pn = rpmGetPath("%{_sourcedir}", NULL); Rmdir(pn); /* ignore error, it is ok if it fails (usually with ENOTEMPTY) */ pn = _free(pn); } if (what & RPMBUILD_RMSPEC) { const char *pn; pn = rpmGetPath("%{_specdir}", NULL); Rmdir(pn); /* ignore error, it is ok if it fails (usually with ENOTEMPTY) */ pn = _free(pn); } #endif exit: if (rc != RPMRC_OK && rpmlogGetNrecs() > 0) { rpmlog(RPMLOG_NOTICE, _("\n\nRPM build errors:\n")); rpmlogPrint(NULL); } return rc; }
int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) { rpm_color_t tscolor = rpmtsColor(ts); int i; int rc = 0; int totalFileCount = 0; rpmfi fi; fingerPrintCache fpc; rpmps ps; rpmtsi pi; rpmte p; int numAdded; int numRemoved; void * lock = NULL; int xx; /* XXX programmer error segfault avoidance. */ if (rpmtsNElements(ts) <= 0) return -1; /* If we are in test mode, then there's no need for transaction lock. */ if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) { lock = rpmtsAcquireLock(ts); if (lock == NULL) return -1; /* XXX W2DO? */ } if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS) (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers)); if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS) (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers)); if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers)); /* if SELinux isn't enabled or init fails, don't bother... */ if (!rpmtsSELinuxEnabled(ts)) { rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_NOCONTEXTS)); } if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONTEXTS)) { char *fn = rpmGetPath("%{?_install_file_context_path}", NULL); if (matchpathcon_init(fn) == -1) { rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_NOCONTEXTS)); } free(fn); } ts->probs = rpmpsFree(ts->probs); ts->probs = rpmpsCreate(); /* XXX Make sure the database is open RDWR for package install/erase. */ { int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) ? O_RDONLY : (O_RDWR|O_CREAT); /* Open database RDWR for installing packages. */ if (rpmtsOpenDB(ts, dbmode)) { rpmtsFreeLock(lock); return -1; /* XXX W2DO? */ } } ts->ignoreSet = ignoreSet; { char * currDir = rpmGetCwd(); rpmtsSetCurrDir(ts, currDir); currDir = _free(currDir); } (void) rpmtsSetChrootDone(ts, 0); { rpm_tid_t tid = (rpm_tid_t) time(NULL); (void) rpmtsSetTid(ts, tid); } /* Get available space on mounted file systems. */ xx = rpmtsInitDSI(ts); /* =============================================== * For packages being installed: * - verify package arch/os. * - verify package epoch:version-release is newer. * - count files. * For packages being removed: * - count files. */ rpmlog(RPMLOG_DEBUG, "sanity checking %d elements\n", rpmtsNElements(ts)); ps = rpmtsProblems(ts); /* The ordering doesn't matter here */ pi = rpmtsiInit(ts); /* XXX Only added packages need be checked. */ while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) { rpmdbMatchIterator mi; int fc; if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREARCH)) if (!archOkay(rpmteA(p))) rpmpsAppend(ps, RPMPROB_BADARCH, rpmteNEVRA(p), rpmteKey(p), rpmteA(p), NULL, NULL, 0); if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREOS)) if (!osOkay(rpmteO(p))) rpmpsAppend(ps, RPMPROB_BADOS, rpmteNEVRA(p), rpmteKey(p), rpmteO(p), NULL, NULL, 0); if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_OLDPACKAGE)) { Header h; mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0); while ((h = rpmdbNextIterator(mi)) != NULL) xx = ensureOlder(ts, p, h); mi = rpmdbFreeIterator(mi); } if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG)) { mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0); xx = rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(p)); xx = rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(p)); xx = rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(p)); if (tscolor) { xx = rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, rpmteA(p)); xx = rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP, rpmteO(p)); } while (rpmdbNextIterator(mi) != NULL) { rpmpsAppend(ps, RPMPROB_PKG_INSTALLED, rpmteNEVRA(p), rpmteKey(p), NULL, NULL, NULL, 0); break; } mi = rpmdbFreeIterator(mi); } /* Count no. of files (if any). */ totalFileCount += fc; } pi = rpmtsiFree(pi); ps = rpmpsFree(ps); /* The ordering doesn't matter here */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, TR_REMOVED)) != NULL) { int fc; if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); totalFileCount += fc; } pi = rpmtsiFree(pi); /* Run pre-transaction scripts, but only if there are no known * problems up to this point and not disabled otherwise. */ if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_NOPRE)) || (rpmpsNumProblems(ts->probs) && (okProbs == NULL || rpmpsTrim(ts->probs, okProbs))))) { rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n"); runTransScripts(ts, RPMTAG_PRETRANS); } /* =============================================== * Initialize transaction element file info for package: */ /* * FIXME?: we'd be better off assembling one very large file list and * calling fpLookupList only once. I'm not sure that the speedup is * worth the trouble though. */ rpmlog(RPMLOG_DEBUG, "computing %d file fingerprints\n", totalFileCount); numAdded = numRemoved = 0; pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { int fc; if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); switch (rpmteType(p)) { case TR_ADDED: numAdded++; /* Skip netshared paths, not our i18n files, and excluded docs */ if (fc > 0) skipFiles(ts, p); break; case TR_REMOVED: numRemoved++; break; } } pi = rpmtsiFree(pi); if (!rpmtsChrootDone(ts)) { const char * rootDir = rpmtsRootDir(ts); xx = chdir("/"); if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/') { /* opening db before chroot not optimal, see rhbz#103852 c#3 */ xx = rpmdbOpenAll(ts->rdb); if (chroot(rootDir) == -1) { rpmlog(RPMLOG_ERR, _("Unable to change root directory: %m\n")); return -1; } } (void) rpmtsSetChrootDone(ts, 1); } ts->ht = rpmFpHashCreate(totalFileCount/2+1, fpHashFunction, fpEqual, NULL, NULL); rpmFpHash symlinks = rpmFpHashCreate(totalFileCount/16+16, fpHashFunction, fpEqual, NULL, NULL); fpc = fpCacheCreate(totalFileCount/2 + 10001); /* =============================================== * Add fingerprint for each file not skipped. */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { int fc; (void) rpmdbCheckSignals(); if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fc = rpmfiFC(fi); (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); rpmfiFpLookup(fi, fpc); /* collect symbolic links */ fi = rpmfiInit(fi, 0); if (fi != NULL) /* XXX lclint */ while ((i = rpmfiNext(fi)) >= 0) { struct rpmffi_s ffi; char const *linktarget; linktarget = rpmfiFLink(fi); if (!(linktarget && *linktarget != '\0')) continue; if (XFA_SKIPPING(rpmfsGetAction(rpmteGetFileStates(p), i))) continue; ffi.p = p; ffi.fileno = i; rpmFpHashAddEntry(symlinks, rpmfiFpsIndex(fi, i), ffi); } (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc); } pi = rpmtsiFree(pi); /* =============================================== * Check fingerprints if they contain symlinks * and add them to the ts->ht hash table */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { (void) rpmdbCheckSignals(); if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ fi = rpmfiInit(fi, 0); (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); if (fi != NULL) /* XXX lclint */ while ((i = rpmfiNext(fi)) >= 0) { if (XFA_SKIPPING(rpmfsGetAction(rpmteGetFileStates(p), i))) continue; fpLookupSubdir(symlinks, ts->ht, fpc, p, i); } (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); } pi = rpmtsiFree(pi); rpmFpHashFree(symlinks); /* =============================================== * Compute file disposition for each package in transaction set. */ rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_START, 6, ts->orderCount); /* check against files in the rpmdb */ checkInstalledFiles(ts, fpc); pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { if ((fi = rpmteFI(p)) == NULL) continue; /* XXX can't happen */ (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); /* check files in ts against each other and update disk space needs on each partition for this package. */ handleOverlappedFiles(ts, p, fi); /* Check added package has sufficient space on each partition used. */ if (rpmteType(p) == TR_ADDED) { rpmtsCheckDSIProblems(ts, p); } (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); } pi = rpmtsiFree(pi); if (rpmtsChrootDone(ts)) { const char * rootDir = rpmtsRootDir(ts); const char * currDir = rpmtsCurrDir(ts); if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/') xx = chroot("."); (void) rpmtsSetChrootDone(ts, 0); if (currDir != NULL) xx = chdir(currDir); } rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_STOP, 6, ts->orderCount); /* =============================================== * Free unused memory as soon as possible. */ pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { rpmteSetFI(p, NULL); } pi = rpmtsiFree(pi); fpc = fpCacheFree(fpc); ts->ht = rpmFpHashFree(ts->ht); /* =============================================== * If unfiltered problems exist, free memory and return. */ if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(ts->probs) && (okProbs == NULL || rpmpsTrim(ts->probs, okProbs))) ) { rpmtsFreeLock(lock); return ts->orderCount; } /* Actually install and remove packages */ rc = rpmtsProcess(ts); if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_NOPOST))) { rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n"); runTransScripts(ts, RPMTAG_POSTTRANS); } if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONTEXTS)) { matchpathcon_fini(); } rpmtsFreeLock(lock); /* FIX: ts->flList may be NULL */ if (rc) return -1; else return 0; }