/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

  • Committer: Teddy Hogeborn
  • Date: 2008-09-19 16:29:40 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080919162940-25hzbrw8adxi3b5v
* Makefile (install-server): Conceal exit code from "test".

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
5
 
 * Copyright © 2008 Teddy Hogeborn & Björn Påhlsson
 
5
 * Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
6
6
 * 
7
7
 * This program is free software: you can redistribute it and/or
8
8
 * modify it under the terms of the GNU General Public License as
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, fileno(), fprintf(),
31
 
                                   stderr, STDOUT_FILENO */
 
30
#include <stdio.h>              /* perror, popen(), fileno(),
 
31
                                   fprintf(), 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 " VERSION;
 
72
const char *argp_program_version = "plugin-runner 1.0";
73
73
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
74
74
 
75
75
typedef struct plugin{
700
700
      
701
701
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
702
702
                                           ".dpkg-old",
703
 
                                           ".dpkg-bak",
704
703
                                           ".dpkg-divert", NULL };
705
704
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
706
705
        size_t pre_len = strlen(*pre);
847
846
        perror("sigaction");
848
847
        _exit(EXIT_FAILURE);
849
848
      }
850
 
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
 
849
      ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
851
850
      if(ret < 0){
852
851
        perror("sigprocmask");
853
852
        _exit(EXIT_FAILURE);
854
853
      }
855
 
      
 
854
 
856
855
      ret = dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
857
856
      if(ret == -1){
858
857
        perror("dup2");
908
907
    if (maxfd < new_plugin->fd){
909
908
      maxfd = new_plugin->fd;
910
909
    }
 
910
    
911
911
  }
912
912
  
913
913
  closedir(dir);
914
914
  dir = NULL;
915
 
  
 
915
 
916
916
  for(plugin *p = plugin_list; p != NULL; p = p->next){
917
917
    if(p->pid != 0){
918
918
      break;
923
923
      free_plugin_list();
924
924
    }
925
925
  }
926
 
  
 
926
 
927
927
  /* Main loop while running plugins exist */
928
928
  while(plugin_list){
929
929
    fd_set rfds = rfds_all;
969
969
            goto fallback;
970
970
          }
971
971
          
972
 
          plugin *next_plugin = proc->next;
973
 
          free_plugin(proc);
974
 
          proc = next_plugin;
975
 
          
976
972
          /* We are done modifying process list, so unblock signal */
977
973
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
978
974
                             NULL);
986
982
            break;
987
983
          }
988
984
          
 
985
          plugin *next_plugin = proc->next;
 
986
          free_plugin(proc);
 
987
          proc = next_plugin;
989
988
          continue;
990
989
        }
991
990
        
992
991
        /* This process exited nicely, so print its buffer */
993
 
        
 
992
 
994
993
        bool bret = print_out_password(proc->buffer,
995
994
                                       proc->buffer_length);
996
995
        if(not bret){
1062
1061
    perror("sigaction");
1063
1062
    exitstatus = EXIT_FAILURE;
1064
1063
  }
1065
 
  
 
1064
 
1066
1065
  if(custom_argv != NULL){
1067
1066
    for(char **arg = custom_argv+1; *arg != NULL; arg++){
1068
1067
      free(*arg);
1074
1073
    closedir(dir);
1075
1074
  }
1076
1075
  
1077
 
  /* Kill the processes */
 
1076
  /* Free the process list and kill the processes */
1078
1077
  for(plugin *p = plugin_list; p != NULL; p = p->next){
1079
1078
    if(p->pid != 0){
1080
1079
      close(p->fd);
1093
1092
  if(errno != ECHILD){
1094
1093
    perror("wait");
1095
1094
  }
1096
 
  
 
1095
 
1097
1096
  free_plugin_list();
1098
1097
  
1099
1098
  free(plugindir);