/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: 2009-02-09 02:17:59 UTC
  • mfrom: (24.1.133 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20090209021759-15raw68l6q0yegtc
Merge from Björn:

* mandos-ctl: Changed domain to "se.bsnet.fukt".

* plugin-runner.c (main): Bug fix: remove pseudo-plugin for global
                          plugin arguments after it is no longer
                          needed.

* plugins.d/mandos-client.c (adjustbuffer): Renamed to "incbuffer",
                                            all callers changed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
#include <signal.h>             /* struct sigaction, sigemptyset(),
63
63
                                   sigaddset(), sigaction(),
64
64
                                   sigprocmask(), SIG_BLOCK, SIGCHLD,
65
 
                                   SIG_UNBLOCK, kill(), sig_atomic_t
66
 
                                */
 
65
                                   SIG_UNBLOCK, kill() */
67
66
#include <errno.h>              /* errno, EBADF */
68
 
#include <inttypes.h>           /* intmax_t, PRIdMAX, strtoimax() */
 
67
#include <inttypes.h>           /* intmax_t, SCNdMAX, PRIdMAX,  */
69
68
 
70
69
#define BUFFER_SIZE 256
71
70
 
82
81
  char **environ;
83
82
  int envc;
84
83
  bool disabled;
85
 
  
 
84
 
86
85
  /* Variables used for running processes*/
87
86
  pid_t pid;
88
87
  int fd;
280
279
  }
281
280
  free(plugin_node->environ);
282
281
  free(plugin_node->buffer);
283
 
  
 
282
 
284
283
  /* Removes the plugin from the singly-linked list */
285
284
  if(plugin_node == plugin_list){
286
285
    /* First one - simple */
313
312
  struct dirent *dirst;
314
313
  struct stat st;
315
314
  fd_set rfds_all;
316
 
  int ret, maxfd = 0;
 
315
  int ret, numchars, maxfd = 0;
317
316
  ssize_t sret;
318
317
  intmax_t tmpmax;
319
318
  uid_t uid = 65534;
380
379
  
381
380
  error_t parse_opt(int key, char *arg, __attribute__((unused))
382
381
                    struct argp_state *state){
383
 
    char *tmp;
384
382
    switch(key){
385
383
    case 'g':                   /* --global-options */
386
384
      if(arg != NULL){
387
 
        char *plugin_option;
388
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
389
 
          if(plugin_option[0] == '\0'){
 
385
        char *p;
 
386
        while((p = strsep(&arg, ",")) != NULL){
 
387
          if(p[0] == '\0'){
390
388
            continue;
391
389
          }
392
 
          if(not add_argument(getplugin(NULL), plugin_option)){
 
390
          if(not add_argument(getplugin(NULL), p)){
393
391
            perror("add_argument");
394
392
            return ARGP_ERR_UNKNOWN;
395
393
          }
406
404
      break;
407
405
    case 'o':                   /* --options-for */
408
406
      if(arg != NULL){
409
 
        char *plugin_name = strsep(&arg, ":");
410
 
        if(plugin_name[0] == '\0'){
411
 
          break;
412
 
        }
413
 
        char *plugin_option;
414
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
415
 
          if(not add_argument(getplugin(plugin_name), plugin_option)){
 
407
        char *p_name = strsep(&arg, ":");
 
408
        if(p_name[0] == '\0' or arg == NULL){
 
409
          break;
 
410
        }
 
411
        char *opt = strsep(&arg, ":");
 
412
        if(opt[0] == '\0' or opt == NULL){
 
413
          break;
 
414
        }
 
415
        char *p;
 
416
        while((p = strsep(&opt, ",")) != NULL){
 
417
          if(p[0] == '\0'){
 
418
            continue;
 
419
          }
 
420
          if(not add_argument(getplugin(p_name), p)){
416
421
            perror("add_argument");
417
422
            return ARGP_ERR_UNKNOWN;
418
423
          }
463
468
      /* This is already done by parse_opt_config_file() */
464
469
      break;
465
470
    case 130:                   /* --userid */
466
 
      errno = 0;
467
 
      tmpmax = strtoimax(arg, &tmp, 10);
468
 
      if(errno != 0 or tmp == arg or *tmp != '\0'
469
 
         or tmpmax != (uid_t)tmpmax){
 
471
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
472
      if(ret < 1 or tmpmax != (uid_t)tmpmax
 
473
         or arg[numchars] != '\0'){
470
474
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
471
475
                PRIdMAX "\n", arg, (intmax_t)uid);
472
476
      } else {
474
478
      }
475
479
      break;
476
480
    case 131:                   /* --groupid */
477
 
      errno = 0;
478
 
      tmpmax = strtoimax(arg, &tmp, 10);
479
 
      if(errno != 0 or tmp == arg or *tmp != '\0'
480
 
         or tmpmax != (gid_t)tmpmax){
 
481
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
482
      if(ret < 1 or tmpmax != (gid_t)tmpmax
 
483
         or arg[numchars] != '\0'){
481
484
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
482
485
                PRIdMAX "\n", arg, (intmax_t)gid);
483
486
      } else {
569
572
    size_t size = 0;
570
573
    const char whitespace_delims[] = " \r\t\f\v\n";
571
574
    const char comment_delim[] = "#";
572
 
    
 
575
 
573
576
    custom_argc = 1;
574
577
    custom_argv = malloc(sizeof(char*) * 2);
575
578
    if(custom_argv == NULL){
579
582
    }
580
583
    custom_argv[0] = argv[0];
581
584
    custom_argv[1] = NULL;
582
 
    
 
585
 
583
586
    /* for each line in the config file, strip whitespace and ignore
584
587
       commented text */
585
588
    while(true){
587
590
      if(sret == -1){
588
591
        break;
589
592
      }
590
 
      
 
593
 
591
594
      line = org_line;
592
595
      arg = strsep(&line, comment_delim);
593
596
      while((p = strsep(&arg, whitespace_delims)) != NULL){
756
759
        continue;
757
760
      }
758
761
    }
759
 
    
 
762
 
760
763
    char *filename;
761
764
    if(plugindir == NULL){
762
765
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
774
777
      free(filename);
775
778
      continue;
776
779
    }
777
 
    
 
780
 
778
781
    /* Ignore non-executable files */
779
782
    if(not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
780
783
      if(debug){
964
967
        if(not WIFEXITED(proc->status)
965
968
           or WEXITSTATUS(proc->status) != 0){
966
969
          /* Bad exit by plugin */
967
 
          
 
970
 
968
971
          if(debug){
969
972
            if(WIFEXITED(proc->status)){
970
973
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
984
987
          
985
988
          /* Remove the plugin */
986
989
          FD_CLR(proc->fd, &rfds_all);
987
 
          
 
990
 
988
991
          /* Block signal while modifying process_list */
989
992
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
990
993
          if(ret < 0){
1057
1060
      }
1058
1061
    }
1059
1062
  }
1060
 
  
1061
 
  
 
1063
 
 
1064
 
1062
1065
 fallback:
1063
1066
  
1064
1067
  if(plugin_list == NULL or exitstatus != EXIT_SUCCESS){