65
65
#include <errno.h> /* errno, EBADF */
67
67
#define BUFFER_SIZE 256
68
#define ARGFILE "/conf/conf.d/mandos/plugin-runner.conf"
69
#define PDIR "/lib/mandos/plugins.d"
70
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
70
72
const char *argp_program_version = "plugin-runner 1.0";
71
73
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
250
char **add_to_argv(char **argv, int *argc, char *arg){
253
argv = malloc(sizeof(char*) * 2);
257
argv[0] = NULL; /* Will be set to argv[0] in main before
262
argv = realloc(argv, sizeof(char *)
263
* ((unsigned int) *argc + 1));
272
252
static void free_plugin_list(plugin *plugin_list){
273
253
for(plugin *next; plugin_list != NULL; plugin_list = next){
274
254
next = plugin_list->next;
339
319
{ .name = "plugin-dir", .key = 128,
340
320
.arg = "DIRECTORY",
341
321
.doc = "Specify a different plugin directory", .group = 2 },
342
{ .name = "userid", .key = 129,
343
.arg = "ID", .flags = 0,
344
.doc = "User ID the plugins will run as", .group = 2 },
345
{ .name = "groupid", .key = 130,
346
.arg = "ID", .flags = 0,
347
.doc = "Group ID the plugins will run as", .group = 2 },
348
{ .name = "debug", .key = 131,
349
.doc = "Debug mode", .group = 3 },
322
{ .name = "config-file", .key = 129,
324
.doc = "Specify a different configuration file", .group = 2 },
325
{ .name = "userid", .key = 130,
326
.arg = "ID", .flags = 0,
327
.doc = "User ID the plugins will run as", .group = 3 },
328
{ .name = "groupid", .key = 131,
329
.arg = "ID", .flags = 0,
330
.doc = "Group ID the plugins will run as", .group = 3 },
331
{ .name = "debug", .key = 132,
332
.doc = "Debug mode", .group = 4 },
474
conffp = fopen(argfile, "r");
466
if (argfile == NULL){
467
conffp = fopen(AFILE, "r");
469
conffp = fopen(argfile, "r");
475
472
if(conffp != NULL){
476
473
char *org_line = NULL;
477
474
char *p, *arg, *new_arg, *line;
480
477
const char whitespace_delims[] = " \r\t\f\v\n";
481
478
const char comment_delim[] = "#";
481
custom_argv = malloc(sizeof(char*) * 2);
482
if(custom_argv == NULL){
484
exitstatus = EXIT_FAILURE;
487
custom_argv[0] = argv[0];
488
custom_argv[1] = NULL;
484
491
sret = getline(&org_line, &size, conffp);
495
502
new_arg = strdup(p);
496
custom_argv = add_to_argv(custom_argv, &custom_argc, new_arg);
497
if (custom_argv == NULL){
498
perror("add_to_argv");
499
exitstatus = EXIT_FAILURE;
505
exitstatus = EXIT_FAILURE;
511
custom_argv = realloc(custom_argv, sizeof(char *)
512
* ((unsigned int) custom_argc + 1));
513
if(custom_argv == NULL){
515
exitstatus = EXIT_FAILURE;
519
custom_argv[custom_argc-1] = new_arg;
520
custom_argv[custom_argc] = NULL;
515
534
if(custom_argv != NULL){
516
custom_argv[0] = argv[0];
517
ret = argp_parse (&argp, custom_argc, custom_argv, 0, 0,
535
ret = argp_parse (&argp, custom_argc, custom_argv, 0, 0, &plugin_list);
519
536
if (ret == ARGP_ERR_UNKNOWN){
520
537
fprintf(stderr, "Unknown error while parsing arguments\n");
521
538
exitstatus = EXIT_FAILURE;