Make rpmscript machinery chroot-aware

Normally all scriptlets are of course chrooted when the installation is,
but we're about to get an exception to that. No functional changes, just
adding necessary infrastructure for the next steps.
This commit is contained in:
Panu Matilainen 2023-03-15 11:27:48 +02:00
parent afad3167cc
commit fc09ee9d60
3 changed files with 44 additions and 2 deletions

View File

@ -17,6 +17,7 @@
#include "lib/rpmscript.h"
#include "rpmio/rpmio_internal.h"
#include "lib/rpmchroot.h"
#include "lib/rpmplugins.h" /* rpm plugins hooks */
#include "debug.h"
@ -35,6 +36,7 @@ struct rpmScript_s {
char *body; /* script body */
char *descr; /* description for logging */
rpmscriptFlags flags; /* flags to control operation */
int chroot; /* chrooted script? */
struct scriptNextFileFunc_s *nextFileFunc; /* input function */
};
@ -108,6 +110,21 @@ static int next_file(lua_State *L)
return 1;
}
int rpmScriptChrootIn(rpmScript script)
{
int rc = 0;
if (script->chroot)
rc = rpmChrootIn();
return rc;
}
int rpmScriptChrootOut(rpmScript script)
{
int rc = 0;
if (script->chroot)
rc = rpmChrootOut();
return rc;
}
/**
* Run internal Lua script.
*/
@ -510,6 +527,7 @@ static rpmScript rpmScriptNew(Header h, rpmTagVal tag, const char *body,
script->type = getScriptType(tag);
script->flags = getDefFlags(tag) | flags;
script->body = (body != NULL) ? xstrdup(body) : NULL;
script->chroot = 1;
rasprintf(&script->descr, "%%%s%s(%s)", prefix, tag2sln(tag), nevra);
/* macros need to be expanded before possible queryformat */
@ -645,6 +663,19 @@ rpmScript rpmScriptFromTriggerTag(Header h, rpmTagVal triggerTag,
return script;
}
rpmScript rpmScriptFromArgv(Header h, rpmTagVal scriptTag, ARGV_t argv, rpmscriptFlags flags, int chroot)
{
rpmScript script = NULL;
if (h && argv) {
char *body = argvJoin(argv, " ");
script = rpmScriptNew(h, scriptTag, body, flags, "");
script->chroot = chroot;
free(body);
}
return script;
}
rpmScript rpmScriptFromTag(Header h, rpmTagVal scriptTag)
{
rpmScript script = NULL;

View File

@ -19,6 +19,7 @@ enum rpmscriptTypes_e {
RPMSCRIPT_POSTTRANS = (1 << 9),
RPMSCRIPT_PREUNTRANS = (1 << 10),
RPMSCRIPT_POSTUNTRANS = (1 << 11),
RPMSCRIPT_SYSUSERS = (1 << 12),
/* ... */
RPMSCRIPT_VERIFY = (1 << 24),
};
@ -59,6 +60,9 @@ rpmscriptTriggerModes triggerMode(rpmTagVal tag);
RPM_GNUC_INTERNAL
rpmTagVal triggertag(rpmsenseFlags sense);
RPM_GNUC_INTERNAL
rpmScript rpmScriptFromArgv(Header h, rpmTagVal scriptTag, ARGV_t argv, rpmscriptFlags flags, int chroot);
RPM_GNUC_INTERNAL
rpmScript rpmScriptFromTag(Header h, rpmTagVal scriptTag);
@ -85,6 +89,13 @@ rpmscriptFlags rpmScriptFlags(rpmScript script);
RPM_GNUC_INTERNAL
void rpmScriptSetNextFileFunc(rpmScript script, nextfilefunc func,
void *param);
RPM_GNUC_INTERNAL
int rpmScriptChrootIn(rpmScript script);
RPM_GNUC_INTERNAL
int rpmScriptChrootOut(rpmScript script);
#ifdef __cplusplus
}
#endif

View File

@ -1702,7 +1702,7 @@ rpmRC runScript(rpmts ts, rpmte te, Header h, ARGV_const_t prefixes,
FD_t sfd = NULL;
int warn_only = !(rpmScriptFlags(script) & RPMSCRIPT_FLAG_CRITICAL);
if (rpmChrootIn())
if (rpmScriptChrootIn(script))
return RPMRC_FAIL;
/* Create a temporary transaction element for triggers from rpmdb */
@ -1736,7 +1736,7 @@ rpmRC runScript(rpmts ts, rpmte te, Header h, ARGV_const_t prefixes,
rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_ERROR, stag, rc);
}
rpmChrootOut();
rpmScriptChrootOut(script);
if (te != xte)
rpmteFree(te);