summaryrefslogtreecommitdiffstats
path: root/src/main/main.c
diff options
context:
space:
mode:
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);