/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

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <stdlib.h>             /* malloc(), exit(), EXIT_FAILURE,
28
28
                                   EXIT_SUCCESS, realloc() */
29
29
#include <stdbool.h>            /* bool, true, false */
30
 
#include <stdio.h>              /* perror, popen(), fileno(),
31
 
                                   fprintf(), stderr, STDOUT_FILENO */
 
30
#include <stdio.h>              /* perror, fileno(), fprintf(),
 
31
                                   stderr, STDOUT_FILENO */
32
32
#include <sys/types.h>          /* DIR, opendir(), stat(), struct
33
33
                                   stat, waitpid(), WIFEXITED(),
34
34
                                   WEXITSTATUS(), wait(), pid_t,
46
46
                                   fcntl(), setuid(), setgid(),
47
47
                                   F_GETFD, F_SETFD, FD_CLOEXEC,
48
48
                                   access(), pipe(), fork(), close()
49
 
                                   dup2, STDOUT_FILENO, _exit(),
 
49
                                   dup2(), STDOUT_FILENO, _exit(),
50
50
                                   execv(), write(), read(),
51
51
                                   close() */
52
52
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
69
69
#define PDIR "/lib/mandos/plugins.d"
70
70
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
71
71
 
72
 
const char *argp_program_version = "plugin-runner 1.0";
 
72
const char *argp_program_version = "plugin-runner " VERSION;
73
73
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
74
74
 
75
75
typedef struct plugin{
846
846
        perror("sigaction");
847
847
        _exit(EXIT_FAILURE);
848
848
      }
849
 
      ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
 
849
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
850
850
      if(ret < 0){
851
851
        perror("sigprocmask");
852
852
        _exit(EXIT_FAILURE);
853
853
      }
854
 
 
 
854
      
855
855
      ret = dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
856
856
      if(ret == -1){
857
857
        perror("dup2");
907
907
    if (maxfd < new_plugin->fd){
908
908
      maxfd = new_plugin->fd;
909
909
    }
910
 
    
911
910
  }
912
911
  
913
912
  closedir(dir);
914
913
  dir = NULL;
915
 
 
 
914
  
916
915
  for(plugin *p = plugin_list; p != NULL; p = p->next){
917
916
    if(p->pid != 0){
918
917
      break;
923
922
      free_plugin_list();
924
923
    }
925
924
  }
926
 
 
 
925
  
927
926
  /* Main loop while running plugins exist */
928
927
  while(plugin_list){
929
928
    fd_set rfds = rfds_all;
969
968
            goto fallback;
970
969
          }
971
970
          
 
971
          plugin *next_plugin = proc->next;
 
972
          free_plugin(proc);
 
973
          proc = next_plugin;
 
974
          
972
975
          /* We are done modifying process list, so unblock signal */
973
976
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
974
977
                             NULL);
982
985
            break;
983
986
          }
984
987
          
985
 
          plugin *next_plugin = proc->next;
986
 
          free_plugin(proc);
987
 
          proc = next_plugin;
988
988
          continue;
989
989
        }
990
990
        
991
991
        /* This process exited nicely, so print its buffer */
992
 
 
 
992
        
993
993
        bool bret = print_out_password(proc->buffer,
994
994
                                       proc->buffer_length);
995
995
        if(not bret){
1061
1061
    perror("sigaction");
1062
1062
    exitstatus = EXIT_FAILURE;
1063
1063
  }
1064
 
 
 
1064
  
1065
1065
  if(custom_argv != NULL){
1066
1066
    for(char **arg = custom_argv+1; *arg != NULL; arg++){
1067
1067
      free(*arg);
1073
1073
    closedir(dir);
1074
1074
  }
1075
1075
  
1076
 
  /* Free the process list and kill the processes */
 
1076
  /* Kill the processes */
1077
1077
  for(plugin *p = plugin_list; p != NULL; p = p->next){
1078
1078
    if(p->pid != 0){
1079
1079
      close(p->fd);
1092
1092
  if(errno != ECHILD){
1093
1093
    perror("wait");
1094
1094
  }
1095
 
 
 
1095
  
1096
1096
  free_plugin_list();
1097
1097
  
1098
1098
  free(plugindir);