/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-09-05 01:46:42 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090905014642-36108sqop1ci0z0m
* plugins.d/mandos-client.c (start_mandos_communication): Check
                                                         "quit_now"
                                                         throughout.
                                                         Always close
                                                         socket and
                                                         deinit GnuTLS
                                                         properly.
  (browse_callback): Return immediately if "quit_now" is set.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <sys/select.h>         /* fd_set, select(), FD_ZERO(),
39
39
                                   FD_SET(), FD_ISSET(), FD_CLR */
40
40
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
41
 
                                   WEXITSTATUS() */
 
41
                                   WEXITSTATUS(), WTERMSIG(),
 
42
                                   WCOREDUMP() */
42
43
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
43
44
#include <iso646.h>             /* and, or, not */
44
45
#include <dirent.h>             /* DIR, struct dirent, opendir(),
52
53
                                   close() */
53
54
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
54
55
                                   FD_CLOEXEC */
55
 
#include <string.h>             /* strsep, strlen(), asprintf() */
 
56
#include <string.h>             /* strsep, strlen(), asprintf(),
 
57
                                   strsignal() */
56
58
#include <errno.h>              /* errno */
57
59
#include <argp.h>               /* struct argp_option, struct
58
60
                                   argp_state, struct argp,
82
84
  char **environ;
83
85
  int envc;
84
86
  bool disabled;
85
 
 
 
87
  
86
88
  /* Variables used for running processes*/
87
89
  pid_t pid;
88
90
  int fd;
280
282
  }
281
283
  free(plugin_node->environ);
282
284
  free(plugin_node->buffer);
283
 
 
 
285
  
284
286
  /* Removes the plugin from the singly-linked list */
285
287
  if(plugin_node == plugin_list){
286
288
    /* First one - simple */
457
459
      plugindir = strdup(arg);
458
460
      if(plugindir == NULL){
459
461
        perror("strdup");
460
 
      }      
 
462
      }
461
463
      break;
462
464
    case 129:                   /* --config-file */
463
465
      /* This is already done by parse_opt_config_file() */
527
529
      if(argfile == NULL){
528
530
        perror("strdup");
529
531
      }
530
 
      break;      
 
532
      break;
531
533
    case 130:                   /* --userid */
532
534
    case 131:                   /* --groupid */
533
535
    case 132:                   /* --debug */
562
564
    conffp = fopen(AFILE, "r");
563
565
  } else {
564
566
    conffp = fopen(argfile, "r");
565
 
  }  
 
567
  }
566
568
  if(conffp != NULL){
567
569
    char *org_line = NULL;
568
570
    char *p, *arg, *new_arg, *line;
569
571
    size_t size = 0;
570
572
    const char whitespace_delims[] = " \r\t\f\v\n";
571
573
    const char comment_delim[] = "#";
572
 
 
 
574
    
573
575
    custom_argc = 1;
574
576
    custom_argv = malloc(sizeof(char*) * 2);
575
577
    if(custom_argv == NULL){
579
581
    }
580
582
    custom_argv[0] = argv[0];
581
583
    custom_argv[1] = NULL;
582
 
 
 
584
    
583
585
    /* for each line in the config file, strip whitespace and ignore
584
586
       commented text */
585
587
    while(true){
587
589
      if(sret == -1){
588
590
        break;
589
591
      }
590
 
 
 
592
      
591
593
      line = org_line;
592
594
      arg = strsep(&line, comment_delim);
593
595
      while((p = strsep(&arg, whitespace_delims)) != NULL){
612
614
          goto fallback;
613
615
        }
614
616
        custom_argv[custom_argc-1] = new_arg;
615
 
        custom_argv[custom_argc] = NULL;        
 
617
        custom_argv[custom_argc] = NULL;
616
618
      }
617
619
    }
618
620
    free(org_line);
756
758
        continue;
757
759
      }
758
760
    }
759
 
 
 
761
    
760
762
    char *filename;
761
763
    if(plugindir == NULL){
762
764
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
774
776
      free(filename);
775
777
      continue;
776
778
    }
777
 
 
 
779
    
778
780
    /* Ignore non-executable files */
779
781
    if(not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
780
782
      if(debug){
964
966
        if(not WIFEXITED(proc->status)
965
967
           or WEXITSTATUS(proc->status) != 0){
966
968
          /* Bad exit by plugin */
967
 
 
 
969
          
968
970
          if(debug){
969
971
            if(WIFEXITED(proc->status)){
970
972
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
973
975
                      WEXITSTATUS(proc->status));
974
976
            } else if(WIFSIGNALED(proc->status)){
975
977
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
976
 
                      " signal %d\n", proc->name,
 
978
                      " signal %d: %s\n", proc->name,
977
979
                      (intmax_t) (proc->pid),
978
 
                      WTERMSIG(proc->status));
 
980
                      WTERMSIG(proc->status),
 
981
                      strsignal(WTERMSIG(proc->status)));
979
982
            } else if(WCOREDUMP(proc->status)){
980
983
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
981
984
                      " core\n", proc->name, (intmax_t) (proc->pid));
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){