/mandos/release

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

« back to all changes in this revision

Viewing changes to plugin-runner.c

* Makefile (common.ent): Update "version" entity correctly.

* mandos-clients.conf.xml (OPTIONS): Corrected old mistake.

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() */
 
65
                                   SIG_UNBLOCK, kill(), sig_atomic_t
 
66
                                */
66
67
#include <errno.h>              /* errno, EBADF */
67
 
#include <inttypes.h>           /* intmax_t, SCNdMAX, PRIdMAX,  */
 
68
#include <inttypes.h>           /* intmax_t, PRIdMAX, strtoimax() */
68
69
 
69
70
#define BUFFER_SIZE 256
70
71
 
81
82
  char **environ;
82
83
  int envc;
83
84
  bool disabled;
84
 
 
 
85
  
85
86
  /* Variables used for running processes*/
86
87
  pid_t pid;
87
88
  int fd;
279
280
  }
280
281
  free(plugin_node->environ);
281
282
  free(plugin_node->buffer);
282
 
 
 
283
  
283
284
  /* Removes the plugin from the singly-linked list */
284
285
  if(plugin_node == plugin_list){
285
286
    /* First one - simple */
312
313
  struct dirent *dirst;
313
314
  struct stat st;
314
315
  fd_set rfds_all;
315
 
  int ret, numchars, maxfd = 0;
 
316
  int ret, maxfd = 0;
316
317
  ssize_t sret;
317
318
  intmax_t tmpmax;
318
319
  uid_t uid = 65534;
379
380
  
380
381
  error_t parse_opt(int key, char *arg, __attribute__((unused))
381
382
                    struct argp_state *state){
 
383
    char *tmp;
382
384
    switch(key){
383
385
    case 'g':                   /* --global-options */
384
386
      if(arg != NULL){
461
463
      /* This is already done by parse_opt_config_file() */
462
464
      break;
463
465
    case 130:                   /* --userid */
464
 
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
465
 
      if(ret < 1 or tmpmax != (uid_t)tmpmax
466
 
         or arg[numchars] != '\0'){
 
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){
467
470
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
468
471
                PRIdMAX "\n", arg, (intmax_t)uid);
469
472
      } else {
471
474
      }
472
475
      break;
473
476
    case 131:                   /* --groupid */
474
 
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
475
 
      if(ret < 1 or tmpmax != (gid_t)tmpmax
476
 
         or arg[numchars] != '\0'){
 
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){
477
481
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
478
482
                PRIdMAX "\n", arg, (intmax_t)gid);
479
483
      } else {
565
569
    size_t size = 0;
566
570
    const char whitespace_delims[] = " \r\t\f\v\n";
567
571
    const char comment_delim[] = "#";
568
 
 
 
572
    
569
573
    custom_argc = 1;
570
574
    custom_argv = malloc(sizeof(char*) * 2);
571
575
    if(custom_argv == NULL){
575
579
    }
576
580
    custom_argv[0] = argv[0];
577
581
    custom_argv[1] = NULL;
578
 
 
 
582
    
579
583
    /* for each line in the config file, strip whitespace and ignore
580
584
       commented text */
581
585
    while(true){
583
587
      if(sret == -1){
584
588
        break;
585
589
      }
586
 
 
 
590
      
587
591
      line = org_line;
588
592
      arg = strsep(&line, comment_delim);
589
593
      while((p = strsep(&arg, whitespace_delims)) != NULL){
752
756
        continue;
753
757
      }
754
758
    }
755
 
 
 
759
    
756
760
    char *filename;
757
761
    if(plugindir == NULL){
758
762
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
770
774
      free(filename);
771
775
      continue;
772
776
    }
773
 
 
 
777
    
774
778
    /* Ignore non-executable files */
775
779
    if(not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
776
780
      if(debug){
960
964
        if(not WIFEXITED(proc->status)
961
965
           or WEXITSTATUS(proc->status) != 0){
962
966
          /* Bad exit by plugin */
963
 
 
 
967
          
964
968
          if(debug){
965
969
            if(WIFEXITED(proc->status)){
966
970
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
980
984
          
981
985
          /* Remove the plugin */
982
986
          FD_CLR(proc->fd, &rfds_all);
983
 
 
 
987
          
984
988
          /* Block signal while modifying process_list */
985
989
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
986
990
          if(ret < 0){
1053
1057
      }
1054
1058
    }
1055
1059
  }
1056
 
 
1057
 
 
 
1060
  
 
1061
  
1058
1062
 fallback:
1059
1063
  
1060
1064
  if(plugin_list == NULL or exitstatus != EXIT_SUCCESS){