/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugin-runner.c

added configfile as a optional argument to plugin-runner

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
#include <errno.h>              /* errno, EBADF */
66
66
 
67
67
#define BUFFER_SIZE 256
68
 
#define ARGFILE "/conf/conf.d/mandos/plugin-runner.conf"
 
68
 
 
69
#define PDIR "/lib/mandos/plugins.d"
 
70
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
69
71
 
70
72
const char *argp_program_version = "plugin-runner 1.0";
71
73
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
263
265
}
264
266
 
265
267
int main(int argc, char *argv[]){
266
 
  const char *plugindir = "/lib/mandos/plugins.d";
267
 
  const char *argfile = ARGFILE;
 
268
  char *plugindir = NULL;
 
269
  char *argfile = NULL;
268
270
  FILE *conffp;
269
271
  size_t d_name_len;
270
272
  DIR *dir = NULL;
317
319
    { .name = "plugin-dir", .key = 128,
318
320
      .arg = "DIRECTORY",
319
321
      .doc = "Specify a different plugin directory", .group = 2 },
320
 
    { .name = "userid", .key = 129,
321
 
      .arg = "ID", .flags = 0,
322
 
      .doc = "User ID the plugins will run as", .group = 2 },
323
 
    { .name = "groupid", .key = 130,
324
 
      .arg = "ID", .flags = 0,
325
 
      .doc = "Group ID the plugins will run as", .group = 2 },
326
 
    { .name = "debug", .key = 131,
327
 
      .doc = "Debug mode", .group = 3 },
 
322
    { .name = "config-file", .key = 129,
 
323
      .arg = "FILE",
 
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 },
328
333
    { .name = NULL }
329
334
  };
330
335
  
414
419
      }
415
420
      break;
416
421
    case 128:
417
 
      plugindir = arg;
 
422
      plugindir = strdup(arg);
 
423
      if(plugindir == NULL){
 
424
        perror("strdup");
 
425
      }      
418
426
      break;
419
427
    case 129:
 
428
      argfile = strdup(arg);
 
429
      if(argfile == NULL){
 
430
        perror("strdup");
 
431
      }
 
432
      break;      
 
433
    case 130:
420
434
      uid = (uid_t)strtol(arg, NULL, 10);
421
435
      break;
422
 
    case 130:
 
436
    case 131:
423
437
      gid = (gid_t)strtol(arg, NULL, 10);
424
438
      break;
425
 
    case 131:
 
439
    case 132:
426
440
      debug = true;
427
441
      break;
428
442
    case ARGP_KEY_ARG:
449
463
    goto fallback;
450
464
  }
451
465
 
452
 
  conffp = fopen(argfile, "r");
 
466
  if (argfile == NULL){
 
467
    conffp = fopen(AFILE, "r");
 
468
  } else {
 
469
    conffp = fopen(argfile, "r");
 
470
  }
 
471
  
453
472
  if(conffp != NULL){
454
473
    char *org_line = NULL;
455
474
    char *p, *arg, *new_arg, *line;
481
500
          continue;
482
501
        }
483
502
        new_arg = strdup(p);
484
 
 
 
503
        if(new_arg == NULL){
 
504
          perror("strdup");
 
505
          exitstatus = EXIT_FAILURE;
 
506
          free(org_line);
 
507
          goto fallback;
 
508
        }
 
509
        
485
510
        custom_argc += 1;
486
511
        custom_argv = realloc(custom_argv, sizeof(char *)
487
512
                              * ((unsigned int) custom_argc + 1));
538
563
  if (ret == -1){
539
564
    perror("setgid");
540
565
  }
 
566
 
 
567
  if (plugindir == NULL){
 
568
    dir = opendir(PDIR);
 
569
  } else {
 
570
    dir = opendir(plugindir);
 
571
  }
541
572
  
542
 
  dir = opendir(plugindir);
543
573
  if(dir == NULL){
544
574
    perror("Could not open plugin dir");
545
575
    exitstatus = EXIT_FAILURE;
795
825
    }
796
826
    
797
827
  }
798
 
  
 
828
 
799
829
  free_plugin_list(plugin_list);
800
830
  plugin_list = NULL;
801
831
  
970
1000
  if(errno != ECHILD){
971
1001
    perror("wait");
972
1002
  }
 
1003
 
 
1004
  free(plugindir);
 
1005
  free(argfile);
973
1006
  
974
1007
  return exitstatus;
975
1008
}