Skip to content

Commit

Permalink
Don't run plugins on src.rpm unpacking
Browse files Browse the repository at this point in the history
Historically, we've been running all plugin hooks also when "installing"
source packages, due to them going through the same portions of the code
path used for binary packages, specifically rpmPackageFilesInstall().

However, source packages aren't really installed (deployed) onto the end
user system, they're just unpacked into %_topdir for packaging purposes,
so none of the tsm/fsm/psm/scriptlet hooks should apply to them, really.

Fix that by disabling all but the init and cleanup hooks for source
packages.  Those two would need to run anyway if there were any binary
packages supplied as well (e.g. "rpm -i binary.rpm source.rpm") and are
only supposed to perform reversible actions such as open/close files.

This also fixes source package installations on systems using a plugin
that requires root privileges, such as the ima plugin, as these installs
are typically done as a regular user (see RhBug:2316785).

Extending rpmtsPlugins() for this purpose would be nicer but it's part
of the public API and would require a soname bump just to pass the extra
"te" argument, hence the static wrapper instead.

Reuse the plugin development test, it's just about the only plugin test
we currently have and happens to be a good fit here, too.
  • Loading branch information
dmnks committed Dec 4, 2024
1 parent 2adaddc commit bfc7265
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/fsm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -875,13 +875,21 @@ static rpmfi fsmIterFini(rpmfi fi, struct diriter_s *di)
return rpmfiFree(fi);
}

static rpmPlugins fsmPlugins(rpmts ts, rpmte te)
{
if (headerIsSource(rpmteHeader(te)))
return NULL;
else
return rpmtsPlugins(ts);
}

int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
rpmpsm psm, char ** failedFile)
{
FD_t payload = rpmtePayload(te);
rpmfi fi = NULL;
rpmfs fs = rpmteGetFileStates(te);
rpmPlugins plugins = rpmtsPlugins(ts);
rpmPlugins plugins = fsmPlugins(ts, te);
int rc = 0;
int fx = -1;
int fc = rpmfilesFC(files);
Expand Down Expand Up @@ -1123,7 +1131,7 @@ int rpmPackageFilesRemove(rpmts ts, rpmte te, rpmfiles files,
struct diriter_s di = { -1, -1 };
rpmfi fi = fsmIter(NULL, files, RPMFI_ITER_BACK, &di);
rpmfs fs = rpmteGetFileStates(te);
rpmPlugins plugins = rpmtsPlugins(ts);
rpmPlugins plugins = fsmPlugins(ts, te);
int fc = rpmfilesFC(files);
int fx = -1;
struct filedata_s *fdata = (struct filedata_s *)xcalloc(fc, sizeof(*fdata));
Expand Down
14 changes: 13 additions & 1 deletion tests/rpmdevel.at
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ runroot rpmbuild --quiet -bb \
/data/SPECS/simple.spec \
/data/SPECS/fakeshell.spec

runroot rpmbuild --quiet -bs \
/data/SPECS/simple.spec

runroot rpm -U /build/RPMS/noarch/fakeshell-1.0-1.noarch.rpm

cmake /data/debugplugin && make && make install DESTDIR=${RPMTEST}
Expand Down Expand Up @@ -70,5 +73,14 @@ debug_psm_post: simple-1.0-1.noarch:0
debug_tsm_post: 0
debug_cleanup
])
RPMTEST_CLEANUP

RPMTEST_CHECK([
runroot rpm -i /build/SRPMS/simple-1.0-1.src.rpm
],
[0],
[],
[debug_init
debug_cleanup
])

RPMTEST_CLEANUP

0 comments on commit bfc7265

Please sign in to comment.