/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

  • Committer: Teddy Hogeborn
  • Date: 2008-09-02 06:03:08 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080902060308-8uhgsfjiwixuvz6j
* plugin-runner.c (main/parse_opt): Removed code for "--config-file".
  (main/parse_opt_config_file): New function only for "--config-file".
  (main): Parse options first using "parse_opt_config_file", then from
          the config file, and lastly from the command line.

Show diffs side-by-side

added added

removed removed

Lines of Context:
375
375
  
376
376
  error_t parse_opt (int key, char *arg, __attribute__((unused))
377
377
                     struct argp_state *state) {
378
 
    /* Get the INPUT argument from `argp_parse', which we know is a
379
 
       pointer to our plugin list pointer. */
380
378
    switch (key) {
381
379
    case 'g':                   /* --global-options */
382
380
      if (arg != NULL){
465
463
      }      
466
464
      break;
467
465
    case 129:                   /* --config-file */
468
 
      argfile = strdup(arg);
469
 
      if(argfile == NULL){
470
 
        perror("strdup");
471
 
      }
472
 
      break;      
 
466
      /* This is already done by parse_opt_config_file() */
 
467
      break;
473
468
    case 130:                   /* --userid */
474
469
      uid = (uid_t)strtol(arg, NULL, 10);
475
470
      break;
490
485
    return 0;
491
486
  }
492
487
  
493
 
  struct argp argp = { .options = options, .parser = parse_opt,
 
488
  /* This option parser is the same as parse_opt() above, except it
 
489
     ignores everything but the --config-file option. */
 
490
  error_t parse_opt_config_file (int key, char *arg,
 
491
                                 __attribute__((unused))
 
492
                                 struct argp_state *state) {
 
493
    switch (key) {
 
494
    case 'g':                   /* --global-options */
 
495
    case 'e':                   /* --global-env */
 
496
    case 'o':                   /* --options-for */
 
497
    case 'f':                   /* --env-for */
 
498
    case 'd':                   /* --disable */
 
499
    case 128:                   /* --plugin-dir */
 
500
      break;
 
501
    case 129:                   /* --config-file */
 
502
      argfile = strdup(arg);
 
503
      if(argfile == NULL){
 
504
        perror("strdup");
 
505
      }
 
506
      break;      
 
507
    case 130:                   /* --userid */
 
508
    case 131:                   /* --groupid */
 
509
    case 132:                   /* --debug */
 
510
    case ARGP_KEY_ARG:
 
511
    case ARGP_KEY_END:
 
512
      break;
 
513
    default:
 
514
      return ARGP_ERR_UNKNOWN;
 
515
    }
 
516
    return 0;
 
517
  }
 
518
  
 
519
  struct argp argp = { .options = options,
 
520
                       .parser = parse_opt_config_file,
494
521
                       .args_doc = "",
495
522
                       .doc = "Mandos plugin runner -- Run plugins" };
496
523
  
 
524
  /* Parse using the parse_opt_config_file in order to get the custom
 
525
     config file location, if any. */
 
526
  ret = argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, NULL);
 
527
  if (ret == ARGP_ERR_UNKNOWN){
 
528
    fprintf(stderr, "Unknown error while parsing arguments\n");
 
529
    exitstatus = EXIT_FAILURE;
 
530
    goto fallback;
 
531
  }
 
532
  
 
533
  /* Reset to the normal argument parser */
 
534
  argp.parser = parse_opt;
 
535
  
497
536
  /* Open the configfile if available */
498
537
  if (argfile == NULL){
499
538
    conffp = fopen(AFILE, "r");