/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: 2008-09-21 12:04:02 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080921120402-mgd2jl8xo634jw18
* Makefile: Put the init script before avahi-daemon.

* debian/mandos.prerm: Bug fix: stop mandos, not ssh.

* debian/rules (install-indep): Put the init script before
                                avahi-daemon.

* init.d/mandos: Require "avahi-daemon".

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,2009 Teddy Hogeborn
6
 
 * Copyright © 2008,2009 Björn Påhlsson
 
5
 * Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
7
6
 * 
8
7
 * This program is free software: you can redistribute it and/or
9
8
 * modify it under the terms of the GNU General Public License as
28
27
#include <stdlib.h>             /* malloc(), exit(), EXIT_FAILURE,
29
28
                                   EXIT_SUCCESS, realloc() */
30
29
#include <stdbool.h>            /* bool, true, false */
31
 
#include <stdio.h>              /* perror, fileno(), fprintf(),
32
 
                                   stderr, STDOUT_FILENO */
 
30
#include <stdio.h>              /* perror, popen(), fileno(),
 
31
                                   fprintf(), stderr, STDOUT_FILENO */
33
32
#include <sys/types.h>          /* DIR, opendir(), stat(), struct
34
33
                                   stat, waitpid(), WIFEXITED(),
35
34
                                   WEXITSTATUS(), wait(), pid_t,
47
46
                                   fcntl(), setuid(), setgid(),
48
47
                                   F_GETFD, F_SETFD, FD_CLOEXEC,
49
48
                                   access(), pipe(), fork(), close()
50
 
                                   dup2(), STDOUT_FILENO, _exit(),
 
49
                                   dup2, STDOUT_FILENO, _exit(),
51
50
                                   execv(), write(), read(),
52
51
                                   close() */
53
52
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
70
69
#define PDIR "/lib/mandos/plugins.d"
71
70
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
72
71
 
73
 
const char *argp_program_version = "plugin-runner " VERSION;
 
72
const char *argp_program_version = "plugin-runner 1.0";
74
73
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
75
74
 
76
75
typedef struct plugin{
701
700
      
702
701
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
703
702
                                           ".dpkg-old",
704
 
                                           ".dpkg-bak",
705
703
                                           ".dpkg-divert", NULL };
706
704
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
707
705
        size_t pre_len = strlen(*pre);
848
846
        perror("sigaction");
849
847
        _exit(EXIT_FAILURE);
850
848
      }
851
 
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
 
849
      ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
852
850
      if(ret < 0){
853
851
        perror("sigprocmask");
854
852
        _exit(EXIT_FAILURE);
855
853
      }
856
 
      
 
854
 
857
855
      ret = dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
858
856
      if(ret == -1){
859
857
        perror("dup2");
909
907
    if (maxfd < new_plugin->fd){
910
908
      maxfd = new_plugin->fd;
911
909
    }
 
910
    
912
911
  }
913
912
  
914
913
  closedir(dir);
915
914
  dir = NULL;
916
 
  
 
915
 
917
916
  for(plugin *p = plugin_list; p != NULL; p = p->next){
918
917
    if(p->pid != 0){
919
918
      break;
924
923
      free_plugin_list();
925
924
    }
926
925
  }
927
 
  
 
926
 
928
927
  /* Main loop while running plugins exist */
929
928
  while(plugin_list){
930
929
    fd_set rfds = rfds_all;
970
969
            goto fallback;
971
970
          }
972
971
          
973
 
          plugin *next_plugin = proc->next;
974
 
          free_plugin(proc);
975
 
          proc = next_plugin;
976
 
          
977
972
          /* We are done modifying process list, so unblock signal */
978
973
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
979
974
                             NULL);
987
982
            break;
988
983
          }
989
984
          
 
985
          plugin *next_plugin = proc->next;
 
986
          free_plugin(proc);
 
987
          proc = next_plugin;
990
988
          continue;
991
989
        }
992
990
        
993
991
        /* This process exited nicely, so print its buffer */
994
 
        
 
992
 
995
993
        bool bret = print_out_password(proc->buffer,
996
994
                                       proc->buffer_length);
997
995
        if(not bret){
1063
1061
    perror("sigaction");
1064
1062
    exitstatus = EXIT_FAILURE;
1065
1063
  }
1066
 
  
 
1064
 
1067
1065
  if(custom_argv != NULL){
1068
1066
    for(char **arg = custom_argv+1; *arg != NULL; arg++){
1069
1067
      free(*arg);
1075
1073
    closedir(dir);
1076
1074
  }
1077
1075
  
1078
 
  /* Kill the processes */
 
1076
  /* Free the process list and kill the processes */
1079
1077
  for(plugin *p = plugin_list; p != NULL; p = p->next){
1080
1078
    if(p->pid != 0){
1081
1079
      close(p->fd);
1094
1092
  if(errno != ECHILD){
1095
1093
    perror("wait");
1096
1094
  }
1097
 
  
 
1095
 
1098
1096
  free_plugin_list();
1099
1097
  
1100
1098
  free(plugindir);