/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

transformed a function to a part of main

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