summaryrefslogtreecommitdiffstats
path: root/src/main/main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-07 13:30:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-07 13:30:08 +0000
commit44cf9c6d2d274eac37502e835155f7e985f1b8e6 (patch)
tree9576ba968924c5b9a55ba9e14f4f26184c62c7d4 /src/main/main.c
parentAdding upstream version 1.22.6. (diff)
downloaddpkg-44cf9c6d2d274eac37502e835155f7e985f1b8e6.tar.xz
dpkg-44cf9c6d2d274eac37502e835155f7e985f1b8e6.zip
Adding upstream version 1.22.7.upstream/1.22.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/main/main.c')
-rw-r--r--src/main/main.c25
1 files changed, 21 insertions, 4 deletions
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 <errno.h>
#include <limits.h>
-#if HAVE_LOCALE_H
+#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#include <string.h>
@@ -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);