diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2023-03-15 11:27:48 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2023-03-30 13:59:28 +0300 |
commit | fc09ee9d60cce879e521ac522b24817de32b3611 (patch) | |
tree | 27db64086e89cf240b0fc8ff2feabe979107862c | |
parent | afad3167ccfda3c0d3200b918dd8b391d621f408 (diff) | |
download | rpm-fc09ee9d60cce879e521ac522b24817de32b3611.tar.gz |
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.
-rw-r--r-- | lib/rpmscript.c | 31 | ||||
-rw-r--r-- | lib/rpmscript.h | 11 | ||||
-rw-r--r-- | lib/transaction.c | 4 |
3 files changed, 44 insertions, 2 deletions
diff --git a/lib/rpmscript.c b/lib/rpmscript.c index 16186feee..9bcdbb0f2 100644 --- a/lib/rpmscript.c +++ b/lib/rpmscript.c @@ -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; diff --git a/lib/rpmscript.h b/lib/rpmscript.h index 0d08c8815..01962a4de 100644 --- a/lib/rpmscript.h +++ b/lib/rpmscript.h @@ -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), }; @@ -60,6 +61,9 @@ 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); RPM_GNUC_INTERNAL @@ -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 diff --git a/lib/transaction.c b/lib/transaction.c index 3fac23b6e..d6693049a 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -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); |