189
char ** addcustomargument(char **argv, int *argc, char *arg){
193
argv = malloc(sizeof(char*) * 2);
197
argv[0] = NULL; /* Will be set to argv[0] in main before parsing */
201
argv = realloc(argv, sizeof(char *)
202
* ((unsigned int) *argc + 1));
188
211
int main(int argc, char *argv[]){
189
212
const char *plugindir = "/conf/conf.d/mandos/plugins.d";
213
const char *conffile = CONFFILE;
190
215
size_t d_name_len;
192
217
struct dirent *dirst;
200
225
struct sigaction old_sigchld_action;
201
226
struct sigaction sigchld_action = { .sa_handler = handle_sigchld,
202
227
.sa_flags = SA_NOCLDSTOP };
203
char *plus_options = NULL;
204
char **plus_argv = NULL;
228
char **custom_argv = NULL;
206
231
/* Establish a signal handler */
207
232
sigemptyset(&sigchld_action.sa_mask);
208
233
ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
261
286
if (arg != NULL){
262
287
char *name = strsep(&arg, ":");
263
if(strcmp(name, "") == 0){
266
291
char *opt = strsep(&arg, ":");
267
if(strcmp(opt, "") == 0){
272
297
while((p = strsep(&opt, ",")) != NULL){
273
if(strcmp(p, "") == 0){
276
301
addargument(getplugin(name, plugins), p);
321
343
exitstatus = EXIT_FAILURE;
326
/* This is a mangled argument in the form of
327
"+--option+--other-option=parameter+--yet-another-option", etc */
328
/* Make new argc and argv vars, and call argp_parse() again. */
329
plus_options++; /* skip the first '+' character */
330
const char delims[] = "+";
333
plus_argv = malloc(sizeof(char*) * 2);
334
if(plus_argv == NULL){
347
conffp = fopen(conffile, "r");
349
char *org_line = NULL;
352
char *p, *arg, *new_arg, *line;
353
const char whitespace_delims[] = " \r\t\f\v\n";
354
const char comment_delim[] = "#";
357
sret = getline(&org_line, &size, conffp);
363
arg = strsep(&line, comment_delim);
364
while((p = strsep(&arg, whitespace_delims)) != NULL){
369
custom_argv = addcustomargument(custom_argv, &custom_argc, new_arg);
370
if (custom_argv == NULL){
371
perror("addcustomargument");
372
exitstatus = EXIT_FAILURE;
379
/* check for harmfull errors */
380
if (errno == EMFILE or errno == ENFILE or errno == ENOMEM){
336
382
exitstatus = EXIT_FAILURE;
339
plus_argv[0] = argv[0];
342
while((arg = strsep(&plus_options, delims)) != NULL){
344
plus_argv = realloc(plus_argv, sizeof(char *)
345
* ((unsigned int) new_argc + 1));
346
if(plus_argv == NULL){
348
exitstatus = EXIT_FAILURE;
351
plus_argv[new_argc-1] = arg;
352
plus_argv[new_argc] = NULL;
355
ret = argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
387
if(custom_argv != NULL){
388
custom_argv[0] = argv[0];
389
ret = argp_parse (&argp, custom_argc, custom_argv, 0, 0, &plugin_list);
356
390
if (ret == ARGP_ERR_UNKNOWN){
357
391
fprintf(stderr, "Unknown error while parsing arguments\n");
358
392
exitstatus = EXIT_FAILURE;