74
72
struct plugin *next;
77
static plugin *getplugin(char *name, plugin **plugin_list){
75
plugin *getplugin(char *name, plugin **plugin_list){
78
76
for (plugin *p = *plugin_list; p != NULL; p = p->next){
79
77
if ((p->name == name)
80
78
or (p->name and name and (strcmp(p->name, name) == 0))){
103
101
return new_plugin;
106
static void addargument(plugin *p, char *arg){
104
void addargument(plugin *p, char *arg){
107
105
p->argv[p->argc] = arg;
108
106
p->argv = realloc(p->argv, sizeof(char *) * (size_t)(p->argc + 2));
109
107
if (p->argv == NULL){
119
117
* Descriptor Flags".
120
118
* *Note File Descriptor Flags:(libc)Descriptor Flags.
122
static int set_cloexec_flag(int fd)
120
int set_cloexec_flag(int fd)
124
122
int ret = fcntl(fd, F_GETFD, 0);
125
123
/* If reading the flags failed, return error indication now. */
167
167
struct sigaction old_sigchld_action;
168
168
struct sigaction sigchld_action = { .sa_handler = handle_sigchld,
169
169
.sa_flags = SA_NOCLDSTOP };
170
char *plus_options = NULL;
171
char **plus_argv = NULL;
173
171
/* Establish a signal handler */
174
172
sigemptyset(&sigchld_action.sa_mask);
175
173
ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
220
218
addargument(getplugin(NULL, plugins), p);
221
219
p = strtok(NULL, ",");
226
224
if (arg != NULL){
227
225
char *name = strtok(arg, ":");
228
226
char *p = strtok(NULL, ":");
230
228
p = strtok(p, ",");
232
230
addargument(getplugin(name, plugins), p);
233
231
p = strtok(NULL, ",");
269
264
plugin *plugin_list = NULL;
271
266
struct argp argp = { .options = options, .parser = parse_opt,
272
.args_doc = "[+PLUS_SEPARATED_OPTIONS]",
273
268
.doc = "Mandos plugin runner -- Run plugins" };
275
270
argp_parse (&argp, argc, argv, 0, 0, &plugin_list);
278
/* This is a mangled argument in the form of
279
"+--option+--other-option=parameter+--yet-another-option", etc */
280
/* Make new argc and argv vars, and call argp_parse() again. */
281
plus_options++; /* skip the first '+' character */
282
const char delims[] = "+";
285
plus_argv = malloc(sizeof(char*) * 2);
286
if(plus_argv == NULL){
288
exitstatus = EXIT_FAILURE;
291
plus_argv[0] = argv[0];
293
arg = strtok(plus_options, delims); /* Get first argument */
296
plus_argv = realloc(plus_argv, sizeof(char *)
297
* ((unsigned int) new_argc + 1));
298
if(plus_argv == NULL){
300
exitstatus = EXIT_FAILURE;
303
plus_argv[new_argc-1] = arg;
304
plus_argv[new_argc] = NULL;
305
arg = strtok(NULL, delims); /* Get next argument */
307
argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
311
273
for(plugin *p = plugin_list; p != NULL; p=p->next){
312
274
fprintf(stderr, "Plugin: %s has %d arguments\n",
662
624
/* Restore old signal handler */
663
625
sigaction(SIGCHLD, &old_sigchld_action, NULL);
667
627
/* Free the plugin list */
668
628
for(plugin *next; plugin_list != NULL; plugin_list = next){
669
629
next = plugin_list->next;