From 97c26c1924b076ef23ebe4381558e8aa025712b2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 16:54:37 +0200 Subject: Adding upstream version 1:4.13+dfsg1. Signed-off-by: Daniel Baumann --- lib/run_part.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 lib/run_part.c (limited to 'lib/run_part.c') diff --git a/lib/run_part.c b/lib/run_part.c new file mode 100644 index 0000000..bce11d3 --- /dev/null +++ b/lib/run_part.c @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "run_part.h" +#include "shadowlog_internal.h" + +int run_part (char *script_path, const char *name, const char *action) +{ + int pid; + int wait_status; + int pid_status; + char *args[] = { script_path, NULL }; + + pid=fork(); + if (pid==-1) { + perror ("Could not fork"); + return 1; + } + if (pid==0) { + setenv ("ACTION",action,1); + setenv ("SUBJECT",name,1); + execv (script_path,args); + perror ("execv"); + exit(1); + } + + pid_status = wait (&wait_status); + if (pid_status == pid) { + return (wait_status); + } + + perror ("waitpid"); + return (1); +} + +int run_parts (const char *directory, const char *name, const char *action) +{ + struct dirent **namelist; + int scanlist; + int n; + int execute_result = 0; + + scanlist = scandir (directory, &namelist, 0, alphasort); + if (scanlist<=0) { + return (0); + } + + for (n=0; nd_name) + 2; + char *s = (char*)malloc(path_length); + if (!s) { + printf ("could not allocate memory\n"); + for (; nd_name); + + execute_result = 0; + if (stat (s, &sb) == -1) { + perror ("stat"); + free (s); + for (; nd_name); + for (; n