This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=6d6488a9ed96967a0568890c0929b9ac5e7cdbed commit 6d6488a9ed96967a0568890c0929b9ac5e7cdbed Author: Guillem Jover <[email protected]> AuthorDate: Wed May 15 01:55:57 2024 +0200 dpkg: Do not run hooks or loggers with --dry-run or unprivileged If we have been told to run in dry mode, we should not be executing the invocation hooks, as those might have side effects. We should not run either if we are running as an unprivileged user without --force-not-root. Closes: #1071124 --- man/dpkg.pod | 6 ++++++ src/main/main.c | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/man/dpkg.pod b/man/dpkg.pod index c1cf602e9..ea587c5fe 100644 --- a/man/dpkg.pod +++ b/man/dpkg.pod @@ -1042,6 +1042,9 @@ is preserved, with the ones from the configuration files taking precedence. The environment variable B<DPKG_HOOK_ACTION> is set for the hooks to the current B<dpkg> action. +The invoke hooks are not executed when B<--no-act> is specified, +or when running as non-root without B<--force-not-root>. + B<Note>: Front-ends might call B<dpkg> several times per invocation, which might run the hooks more times than expected. @@ -1220,6 +1223,9 @@ shell I<command>'s standard input, to be run via ā%DPKG_DEFAULT_SHELL% -cā This option can be specified multiple times. The output format used is the same as in B<--status-fd>. +The status loggers are not executed when B<--no-act> is specified, +or when running as non-root without B<--force-not-root>. + =item B<--log=>I<filename> Log status change updates and actions to I<filename>, instead of diff --git a/src/main/main.c b/src/main/main.c index fe6c29b43..15918fb7f 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -337,6 +337,24 @@ is_invoke_action(enum action action) } } +static bool +can_invoke_hooks(enum action action) +{ + if (!is_invoke_action(action)) + return false; + + if (f_noact) + return false; + + if (in_force(FORCE_NON_ROOT)) + return true; + + if (getuid() || geteuid()) + return false; + + return true; +} + static struct invoke_list pre_invoke_hooks = { .head = NULL, .tail = &pre_invoke_hooks.head, @@ -760,14 +778,14 @@ int main(int argc, const char *const *argv) { if (!f_triggers) f_triggers = (cipaction->arg_int == act_triggers && *argv) ? -1 : 1; - if (is_invoke_action(cipaction->arg_int)) { + if (can_invoke_hooks(cipaction->arg_int)) { run_invoke_hooks(cipaction->olong, &pre_invoke_hooks); run_status_loggers(&status_loggers); } ret = cipaction->action(argv); - if (is_invoke_action(cipaction->arg_int)) + if (can_invoke_hooks(cipaction->arg_int)) run_invoke_hooks(cipaction->olong, &post_invoke_hooks); free_invoke_hooks(&pre_invoke_hooks); -- Dpkg.Org's dpkg

