From 44cf9c6d2d274eac37502e835155f7e985f1b8e6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 7 Aug 2024 15:30:08 +0200 Subject: Adding upstream version 1.22.7. Signed-off-by: Daniel Baumann --- src/main/main.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/main/main.c') diff --git a/src/main/main.c b/src/main/main.c index 02887c2..ecaed5f 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -29,7 +29,7 @@ #include #include -#if HAVE_LOCALE_H +#ifdef HAVE_LOCALE_H #include #endif #include @@ -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, @@ -672,7 +690,6 @@ commandfd(const char *const *argv) if (c == EOF) ohshit(_("unexpected end of file before end of line %d"), lno); if (!argc) continue; - varbuf_end_str(&linevb); newargs = m_realloc(newargs, sizeof(const char *) * (argc + 1)); argc= 1; ptr= linevb.buf; @@ -761,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); -- cgit v1.2.3