/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

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
  size_t buffer_size;
90
90
  size_t buffer_length;
91
91
  bool eof;
92
 
  volatile bool completed;
93
 
  volatile int status;
 
92
  volatile sig_atomic_t completed;
 
93
  int status;
94
94
  struct plugin *next;
95
95
} plugin;
96
96
 
120
120
    }
121
121
  }
122
122
  
123
 
  *new_plugin = (plugin) { .name = copy_name,
124
 
                           .argc = 1,
125
 
                           .disabled = false,
126
 
                           .next = plugin_list };
 
123
  *new_plugin = (plugin){ .name = copy_name,
 
124
                          .argc = 1,
 
125
                          .disabled = false,
 
126
                          .next = plugin_list };
127
127
  
128
128
  new_plugin->argv = malloc(sizeof(char *) * 2);
129
129
  if(new_plugin->argv == NULL){
223
223
/* Mark processes as completed when they exit, and save their exit
224
224
   status. */
225
225
static void handle_sigchld(__attribute__((unused)) int sig){
 
226
  int old_errno = errno;
226
227
  while(true){
227
228
    plugin *proc = plugin_list;
228
229
    int status;
232
233
      break;
233
234
    }
234
235
    if(pid == -1){
235
 
      if(errno != ECHILD){
236
 
        perror("waitpid");
 
236
      if(errno == ECHILD){
 
237
        /* No child processes */
 
238
        break;
237
239
      }
238
 
      /* No child processes */
239
 
      break;
 
240
      perror("waitpid");
240
241
    }
241
242
    
242
243
    /* A child exited, find it in process_list */
248
249
      continue;
249
250
    }
250
251
    proc->status = status;
251
 
    proc->completed = true;
 
252
    proc->completed = 1;
252
253
  }
 
254
  errno = old_errno;
253
255
}
254
256
 
255
257
/* Prints out a password to stdout */
376
378
  };
377
379
  
378
380
  error_t parse_opt(int key, char *arg, __attribute__((unused))
379
 
                    struct argp_state *state) {
380
 
    switch(key) {
 
381
                    struct argp_state *state){
 
382
    switch(key){
381
383
    case 'g':                   /* --global-options */
382
384
      if(arg != NULL){
383
385
        char *p;
512
514
     ignores everything but the --config-file option. */
513
515
  error_t parse_opt_config_file(int key, char *arg,
514
516
                                __attribute__((unused))
515
 
                                struct argp_state *state) {
516
 
    switch(key) {
 
517
                                struct argp_state *state){
 
518
    switch(key){
517
519
    case 'g':                   /* --global-options */
518
520
    case 'G':                   /* --global-env */
519
521
    case 'o':                   /* --options-for */
662
664
  }
663
665
  
664
666
  /* Strip permissions down to nobody */
 
667
  setgid(gid);
 
668
  if(ret == -1){
 
669
    perror("setgid");
 
670
  }
665
671
  ret = setuid(uid);
666
672
  if(ret == -1){
667
673
    perror("setuid");
668
 
  }  
669
 
  setgid(gid);
670
 
  if(ret == -1){
671
 
    perror("setgid");
672
674
  }
673
675
  
674
676
  if(plugindir == NULL){
959
961
       from one of them */
960
962
    for(plugin *proc = plugin_list; proc != NULL;){
961
963
      /* Is this process completely done? */
962
 
      if(proc->eof and proc->completed){
 
964
      if(proc->completed and proc->eof){
963
965
        /* Only accept the plugin output if it exited cleanly */
964
966
        if(not WIFEXITED(proc->status)
965
967
           or WEXITSTATUS(proc->status) != 0){
970
972
              fprintf(stderr, "Plugin %" PRIdMAX " exited with status"
971
973
                      " %d\n", (intmax_t) (proc->pid),
972
974
                      WEXITSTATUS(proc->status));
973
 
            } else if(WIFSIGNALED(proc->status)) {
 
975
            } else if(WIFSIGNALED(proc->status)){
974
976
              fprintf(stderr, "Plugin %" PRIdMAX " killed by signal"
975
977
                      " %d\n", (intmax_t) (proc->pid),
976
978
                      WTERMSIG(proc->status));