/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: Björn Påhlsson
  • Date: 2010-09-01 18:03:03 UTC
  • mto: (237.4.3 mandos-release)
  • mto: This revision was merged to the branch mainline in revision 421.
  • Revision ID: belorn@fukt.bsnet.se-20100901180303-u47edb73fczu56ob
bug fixes that prevent problems when runing server as root

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-2013 Teddy Hogeborn
6
 
 * Copyright © 2008-2013 Björn Påhlsson
 
5
 * Copyright © 2008,2009 Teddy Hogeborn
 
6
 * Copyright © 2008,2009 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
19
19
 * along with this program.  If not, see
20
20
 * <http://www.gnu.org/licenses/>.
21
21
 * 
22
 
 * Contact the authors at <mandos@recompile.se>.
 
22
 * Contact the authors at <mandos@fukt.bsnet.se>.
23
23
 */
24
24
 
25
25
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), getline(),
28
28
#include <stdlib.h>             /* malloc(), exit(), EXIT_SUCCESS,
29
29
                                   realloc() */
30
30
#include <stdbool.h>            /* bool, true, false */
31
 
#include <stdio.h>              /* fileno(), fprintf(),
 
31
#include <stdio.h>              /* perror, fileno(), fprintf(),
32
32
                                   stderr, STDOUT_FILENO */
33
33
#include <sys/types.h>          /* DIR, fdopendir(), stat(), struct
34
34
                                   stat, waitpid(), WIFEXITED(),
70
70
#include <inttypes.h>           /* intmax_t, PRIdMAX, strtoimax() */
71
71
#include <sysexits.h>           /* EX_OSERR, EX_USAGE, EX_IOERR,
72
72
                                   EX_CONFIG, EX_UNAVAILABLE, EX_OK */
73
 
#include <errno.h>              /* errno */
74
 
#include <error.h>              /* error() */
75
73
 
76
74
#define BUFFER_SIZE 256
77
75
 
79
77
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
80
78
 
81
79
const char *argp_program_version = "plugin-runner " VERSION;
82
 
const char *argp_program_bug_address = "<mandos@recompile.se>";
 
80
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
83
81
 
84
82
typedef struct plugin{
85
83
  char *name;                   /* can be NULL or any plugin name */
171
169
}
172
170
 
173
171
/* Helper function for add_argument and add_environment */
174
 
__attribute__((nonnull))
175
172
static bool add_to_char_array(const char *new, char ***array,
176
173
                              int *len){
177
174
  /* Resize the pointed-to array to hold one more pointer */
200
197
}
201
198
 
202
199
/* Add to a plugin's argument vector */
203
 
__attribute__((nonnull(2)))
204
200
static bool add_argument(plugin *p, const char *arg){
205
201
  if(p == NULL){
206
202
    return false;
209
205
}
210
206
 
211
207
/* Add to a plugin's environment */
212
 
__attribute__((nonnull(2)))
213
208
static bool add_environment(plugin *p, const char *def, bool replace){
214
209
  if(p == NULL){
215
210
    return false;
271
266
        /* No child processes */
272
267
        break;
273
268
      }
274
 
      error(0, errno, "waitpid");
 
269
      perror("waitpid");
275
270
    }
276
271
    
277
272
    /* A child exited, find it in process_list */
289
284
}
290
285
 
291
286
/* Prints out a password to stdout */
292
 
__attribute__((nonnull))
293
287
static bool print_out_password(const char *buffer, size_t length){
294
288
  ssize_t ret;
295
289
  for(size_t written = 0; written < length; written += (size_t)ret){
303
297
}
304
298
 
305
299
/* Removes and free a plugin from the plugin list */
306
 
__attribute__((nonnull))
307
300
static void free_plugin(plugin *plugin_node){
308
301
  
309
302
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
364
357
  sigemptyset(&sigchld_action.sa_mask);
365
358
  ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
366
359
  if(ret == -1){
367
 
    error(0, errno, "sigaddset");
 
360
    perror("sigaddset");
368
361
    exitstatus = EX_OSERR;
369
362
    goto fallback;
370
363
  }
371
364
  ret = sigaction(SIGCHLD, &sigchld_action, &old_sigchld_action);
372
365
  if(ret == -1){
373
 
    error(0, errno, "sigaction");
 
366
    perror("sigaction");
374
367
    exitstatus = EX_OSERR;
375
368
    goto fallback;
376
369
  }
421
414
    { .name = NULL }
422
415
  };
423
416
  
424
 
  __attribute__((nonnull(3)))
425
417
  error_t parse_opt(int key, char *arg, struct argp_state *state){
426
418
    errno = 0;
427
419
    switch(key){
428
420
      char *tmp;
429
 
      intmax_t tmp_id;
 
421
      intmax_t tmpmax;
430
422
    case 'g':                   /* --global-options */
431
423
      {
432
424
        char *plugin_option;
505
497
      /* This is already done by parse_opt_config_file() */
506
498
      break;
507
499
    case 130:                   /* --userid */
508
 
      tmp_id = strtoimax(arg, &tmp, 10);
 
500
      tmpmax = strtoimax(arg, &tmp, 10);
509
501
      if(errno != 0 or tmp == arg or *tmp != '\0'
510
 
         or tmp_id != (uid_t)tmp_id){
 
502
         or tmpmax != (uid_t)tmpmax){
511
503
        argp_error(state, "Bad user ID number: \"%s\", using %"
512
504
                   PRIdMAX, arg, (intmax_t)uid);
513
505
        break;
514
506
      }
515
 
      uid = (uid_t)tmp_id;
 
507
      uid = (uid_t)tmpmax;
516
508
      break;
517
509
    case 131:                   /* --groupid */
518
 
      tmp_id = strtoimax(arg, &tmp, 10);
 
510
      tmpmax = strtoimax(arg, &tmp, 10);
519
511
      if(errno != 0 or tmp == arg or *tmp != '\0'
520
 
         or tmp_id != (gid_t)tmp_id){
 
512
         or tmpmax != (gid_t)tmpmax){
521
513
        argp_error(state, "Bad group ID number: \"%s\", using %"
522
514
                   PRIdMAX, arg, (intmax_t)gid);
523
515
        break;
524
516
      }
525
 
      gid = (gid_t)tmp_id;
 
517
      gid = (gid_t)tmpmax;
526
518
      break;
527
519
    case 132:                   /* --debug */
528
520
      debug = true;
607
599
  case ENOMEM:
608
600
  default:
609
601
    errno = ret;
610
 
    error(0, errno, "argp_parse");
 
602
    perror("argp_parse");
611
603
    exitstatus = EX_OSERR;
612
604
    goto fallback;
613
605
  case EINVAL:
634
626
    custom_argc = 1;
635
627
    custom_argv = malloc(sizeof(char*) * 2);
636
628
    if(custom_argv == NULL){
637
 
      error(0, errno, "malloc");
 
629
      perror("malloc");
638
630
      exitstatus = EX_OSERR;
639
631
      goto fallback;
640
632
    }
657
649
        }
658
650
        new_arg = strdup(p);
659
651
        if(new_arg == NULL){
660
 
          error(0, errno, "strdup");
 
652
          perror("strdup");
661
653
          exitstatus = EX_OSERR;
662
654
          free(org_line);
663
655
          goto fallback;
667
659
        custom_argv = realloc(custom_argv, sizeof(char *)
668
660
                              * ((unsigned int) custom_argc + 1));
669
661
        if(custom_argv == NULL){
670
 
          error(0, errno, "realloc");
 
662
          perror("realloc");
671
663
          exitstatus = EX_OSERR;
672
664
          free(org_line);
673
665
          goto fallback;
680
672
      ret = fclose(conffp);
681
673
    } while(ret == EOF and errno == EINTR);
682
674
    if(ret == EOF){
683
 
      error(0, errno, "fclose");
 
675
      perror("fclose");
684
676
      exitstatus = EX_IOERR;
685
677
      goto fallback;
686
678
    }
689
681
    /* Check for harmful errors and go to fallback. Other errors might
690
682
       not affect opening plugins */
691
683
    if(errno == EMFILE or errno == ENFILE or errno == ENOMEM){
692
 
      error(0, errno, "fopen");
 
684
      perror("fopen");
693
685
      exitstatus = EX_OSERR;
694
686
      goto fallback;
695
687
    }
706
698
    case ENOMEM:
707
699
    default:
708
700
      errno = ret;
709
 
      error(0, errno, "argp_parse");
 
701
      perror("argp_parse");
710
702
      exitstatus = EX_OSERR;
711
703
      goto fallback;
712
704
    case EINVAL:
726
718
  case ENOMEM:
727
719
  default:
728
720
    errno = ret;
729
 
    error(0, errno, "argp_parse");
 
721
    perror("argp_parse");
730
722
    exitstatus = EX_OSERR;
731
723
    goto fallback;
732
724
  case EINVAL:
748
740
    }
749
741
  }
750
742
  
751
 
  if(getuid() == 0){
752
 
    /* Work around Debian bug #633582:
753
 
       <http://bugs.debian.org/633582> */
754
 
    int plugindir_fd = open(/* plugindir or */ PDIR, O_RDONLY);
755
 
    if(plugindir_fd == -1){
756
 
      error(0, errno, "open");
757
 
    } else {
758
 
      ret = (int)TEMP_FAILURE_RETRY(fstat(plugindir_fd, &st));
759
 
      if(ret == -1){
760
 
        error(0, errno, "fstat");
761
 
      } else {
762
 
        if(S_ISDIR(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
763
 
          ret = fchown(plugindir_fd, uid, gid);
764
 
          if(ret == -1){
765
 
            error(0, errno, "fchown");
766
 
          }
767
 
        }
768
 
      }
769
 
      TEMP_FAILURE_RETRY(close(plugindir_fd));
770
 
    }
771
 
  }
772
 
  
773
 
  /* Lower permissions */
774
 
  ret = setgid(gid);
 
743
  /* Strip permissions down to nobody */
 
744
  setgid(gid);
775
745
  if(ret == -1){
776
 
    error(0, errno, "setgid");
 
746
    perror("setgid");
777
747
  }
778
748
  ret = setuid(uid);
779
749
  if(ret == -1){
780
 
    error(0, errno, "setuid");
 
750
    perror("setuid");
781
751
  }
782
752
  
783
753
  /* Open plugin directory with close_on_exec flag */
801
771
                    );
802
772
    }
803
773
    if(dir_fd == -1){
804
 
      error(0, errno, "Could not open plugin dir");
 
774
      perror("Could not open plugin dir");
805
775
      exitstatus = EX_UNAVAILABLE;
806
776
      goto fallback;
807
777
    }
810
780
  /* Set the FD_CLOEXEC flag on the directory */
811
781
    ret = set_cloexec_flag(dir_fd);
812
782
    if(ret < 0){
813
 
      error(0, errno, "set_cloexec_flag");
 
783
      perror("set_cloexec_flag");
814
784
      TEMP_FAILURE_RETRY(close(dir_fd));
815
785
      exitstatus = EX_OSERR;
816
786
      goto fallback;
819
789
    
820
790
    dir = fdopendir(dir_fd);
821
791
    if(dir == NULL){
822
 
      error(0, errno, "Could not open plugin dir");
 
792
      perror("Could not open plugin dir");
823
793
      TEMP_FAILURE_RETRY(close(dir_fd));
824
794
      exitstatus = EX_OSERR;
825
795
      goto fallback;
837
807
    /* All directory entries have been processed */
838
808
    if(dirst == NULL){
839
809
      if(errno == EBADF){
840
 
        error(0, errno, "readdir");
 
810
        perror("readdir");
841
811
        exitstatus = EX_IOERR;
842
812
        goto fallback;
843
813
      }
850
820
    {
851
821
      bool bad_name = false;
852
822
      
853
 
      const char * const bad_prefixes[] = { ".", "#", NULL };
 
823
      const char const *bad_prefixes[] = { ".", "#", NULL };
854
824
      
855
 
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
 
825
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
856
826
                                           ".dpkg-old",
857
827
                                           ".dpkg-bak",
858
828
                                           ".dpkg-divert", NULL };
859
 
#pragma GCC diagnostic push
860
 
#pragma GCC diagnostic ignored "-Wcast-qual"
861
 
      for(const char **pre = (const char **)bad_prefixes;
862
 
          *pre != NULL; pre++){
863
 
#pragma GCC diagnostic pop
 
829
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
864
830
        size_t pre_len = strlen(*pre);
865
831
        if((d_name_len >= pre_len)
866
832
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
875
841
      if(bad_name){
876
842
        continue;
877
843
      }
878
 
#pragma GCC diagnostic push
879
 
#pragma GCC diagnostic ignored "-Wcast-qual"
880
 
      for(const char **suf = (const char **)bad_suffixes;
881
 
          *suf != NULL; suf++){
882
 
#pragma GCC diagnostic pop
 
844
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
883
845
        size_t suf_len = strlen(*suf);
884
846
        if((d_name_len >= suf_len)
885
847
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
908
870
                                             dirst->d_name));
909
871
    }
910
872
    if(ret < 0){
911
 
      error(0, errno, "asprintf");
 
873
      perror("asprintf");
912
874
      continue;
913
875
    }
914
876
    
915
877
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
916
878
    if(ret == -1){
917
 
      error(0, errno, "stat");
 
879
      perror("stat");
918
880
      free(filename);
919
881
      continue;
920
882
    }
932
894
    
933
895
    plugin *p = getplugin(dirst->d_name);
934
896
    if(p == NULL){
935
 
      error(0, errno, "getplugin");
 
897
      perror("getplugin");
936
898
      free(filename);
937
899
      continue;
938
900
    }
950
912
      if(g != NULL){
951
913
        for(char **a = g->argv + 1; *a != NULL; a++){
952
914
          if(not add_argument(p, *a)){
953
 
            error(0, errno, "add_argument");
 
915
            perror("add_argument");
954
916
          }
955
917
        }
956
918
        /* Add global environment variables */
957
919
        for(char **e = g->environ; *e != NULL; e++){
958
920
          if(not add_environment(p, *e, false)){
959
 
            error(0, errno, "add_environment");
 
921
            perror("add_environment");
960
922
          }
961
923
        }
962
924
      }
967
929
    if(p->environ[0] != NULL){
968
930
      for(char **e = environ; *e != NULL; e++){
969
931
        if(not add_environment(p, *e, false)){
970
 
          error(0, errno, "add_environment");
 
932
          perror("add_environment");
971
933
        }
972
934
      }
973
935
    }
975
937
    int pipefd[2];
976
938
    ret = (int)TEMP_FAILURE_RETRY(pipe(pipefd));
977
939
    if(ret == -1){
978
 
      error(0, errno, "pipe");
 
940
      perror("pipe");
979
941
      exitstatus = EX_OSERR;
980
942
      goto fallback;
981
943
    }
982
944
    /* Ask OS to automatic close the pipe on exec */
983
945
    ret = set_cloexec_flag(pipefd[0]);
984
946
    if(ret < 0){
985
 
      error(0, errno, "set_cloexec_flag");
 
947
      perror("set_cloexec_flag");
986
948
      exitstatus = EX_OSERR;
987
949
      goto fallback;
988
950
    }
989
951
    ret = set_cloexec_flag(pipefd[1]);
990
952
    if(ret < 0){
991
 
      error(0, errno, "set_cloexec_flag");
 
953
      perror("set_cloexec_flag");
992
954
      exitstatus = EX_OSERR;
993
955
      goto fallback;
994
956
    }
997
959
                                              &sigchld_action.sa_mask,
998
960
                                              NULL));
999
961
    if(ret < 0){
1000
 
      error(0, errno, "sigprocmask");
 
962
      perror("sigprocmask");
1001
963
      exitstatus = EX_OSERR;
1002
964
      goto fallback;
1003
965
    }
1007
969
      pid = fork();
1008
970
    } while(pid == -1 and errno == EINTR);
1009
971
    if(pid == -1){
1010
 
      error(0, errno, "fork");
 
972
      perror("fork");
1011
973
      exitstatus = EX_OSERR;
1012
974
      goto fallback;
1013
975
    }
1015
977
      /* this is the child process */
1016
978
      ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
1017
979
      if(ret < 0){
1018
 
        error(0, errno, "sigaction");
 
980
        perror("sigaction");
1019
981
        _exit(EX_OSERR);
1020
982
      }
1021
983
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
1022
984
      if(ret < 0){
1023
 
        error(0, errno, "sigprocmask");
 
985
        perror("sigprocmask");
1024
986
        _exit(EX_OSERR);
1025
987
      }
1026
988
      
1027
989
      ret = dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
1028
990
      if(ret == -1){
1029
 
        error(0, errno, "dup2");
 
991
        perror("dup2");
1030
992
        _exit(EX_OSERR);
1031
993
      }
1032
994
      
1037
999
      }
1038
1000
      if(p->environ[0] == NULL){
1039
1001
        if(execv(filename, p->argv) < 0){
1040
 
          error(0, errno, "execv for %s", filename);
 
1002
          perror("execv");
1041
1003
          _exit(EX_OSERR);
1042
1004
        }
1043
1005
      } else {
1044
1006
        if(execve(filename, p->argv, p->environ) < 0){
1045
 
          error(0, errno, "execve for %s", filename);
 
1007
          perror("execve");
1046
1008
          _exit(EX_OSERR);
1047
1009
        }
1048
1010
      }
1054
1016
    free(filename);
1055
1017
    plugin *new_plugin = getplugin(dirst->d_name);
1056
1018
    if(new_plugin == NULL){
1057
 
      error(0, errno, "getplugin");
 
1019
      perror("getplugin");
1058
1020
      ret = (int)(TEMP_FAILURE_RETRY
1059
1021
                  (sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
1060
1022
                               NULL)));
1061
1023
      if(ret < 0){
1062
 
        error(0, errno, "sigprocmask");
 
1024
        perror("sigprocmask");
1063
1025
      }
1064
1026
      exitstatus = EX_OSERR;
1065
1027
      goto fallback;
1074
1036
                                              &sigchld_action.sa_mask,
1075
1037
                                              NULL));
1076
1038
    if(ret < 0){
1077
 
      error(0, errno, "sigprocmask");
 
1039
      perror("sigprocmask");
1078
1040
      exitstatus = EX_OSERR;
1079
1041
      goto fallback;
1080
1042
    }
1081
1043
    
1082
 
#if defined (__GNUC__) and defined (__GLIBC__)
1083
 
#if not __GLIBC_PREREQ(2, 16)
1084
 
#pragma GCC diagnostic push
1085
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1086
 
#endif
1087
 
#endif
1088
1044
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
1089
 
                                          -Wconversion in GNU libc
1090
 
                                          before 2.16 */
1091
 
#if defined (__GNUC__) and defined (__GLIBC__)
1092
 
#if not __GLIBC_PREREQ(2, 16)
1093
 
#pragma GCC diagnostic pop
1094
 
#endif
1095
 
#endif
 
1045
                                          -Wconversion */
1096
1046
    
1097
1047
    if(maxfd < new_plugin->fd){
1098
1048
      maxfd = new_plugin->fd;
1119
1069
    fd_set rfds = rfds_all;
1120
1070
    int select_ret = select(maxfd+1, &rfds, NULL, NULL, NULL);
1121
1071
    if(select_ret == -1 and errno != EINTR){
1122
 
      error(0, errno, "select");
 
1072
      perror("select");
1123
1073
      exitstatus = EX_OSERR;
1124
1074
      goto fallback;
1125
1075
    }
1152
1102
          }
1153
1103
          
1154
1104
          /* Remove the plugin */
1155
 
#if defined (__GNUC__) and defined (__GLIBC__)
1156
 
#if not __GLIBC_PREREQ(2, 16)
1157
 
#pragma GCC diagnostic push
1158
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1159
 
#endif
1160
 
#endif
1161
1105
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
1162
 
                                          -Wconversion in GNU libc
1163
 
                                          before 2.16 */
1164
 
#if defined (__GNUC__) and defined (__GLIBC__)
1165
 
#if not __GLIBC_PREREQ(2, 16)
1166
 
#pragma GCC diagnostic pop
1167
 
#endif
1168
 
#endif
 
1106
                                          -Wconversion */
1169
1107
          
1170
1108
          /* Block signal while modifying process_list */
1171
1109
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1173
1111
                                         &sigchld_action.sa_mask,
1174
1112
                                         NULL));
1175
1113
          if(ret < 0){
1176
 
            error(0, errno, "sigprocmask");
 
1114
            perror("sigprocmask");
1177
1115
            exitstatus = EX_OSERR;
1178
1116
            goto fallback;
1179
1117
          }
1187
1125
                      (sigprocmask(SIG_UNBLOCK,
1188
1126
                                   &sigchld_action.sa_mask, NULL)));
1189
1127
          if(ret < 0){
1190
 
            error(0, errno, "sigprocmask");
 
1128
            perror("sigprocmask");
1191
1129
            exitstatus = EX_OSERR;
1192
1130
            goto fallback;
1193
1131
          }
1204
1142
        bool bret = print_out_password(proc->buffer,
1205
1143
                                       proc->buffer_length);
1206
1144
        if(not bret){
1207
 
          error(0, errno, "print_out_password");
 
1145
          perror("print_out_password");
1208
1146
          exitstatus = EX_IOERR;
1209
1147
        }
1210
1148
        goto fallback;
1211
1149
      }
1212
1150
      
1213
1151
      /* This process has not completed.  Does it have any output? */
1214
 
#if defined (__GNUC__) and defined (__GLIBC__)
1215
 
#if not __GLIBC_PREREQ(2, 16)
1216
 
#pragma GCC diagnostic push
1217
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1218
 
#endif
1219
 
#endif
1220
1152
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
1221
1153
                                                         warning from
1222
 
                                                         -Wconversion
1223
 
                                                         in GNU libc
1224
 
                                                         before
1225
 
                                                         2.16 */
1226
 
#if defined (__GNUC__) and defined (__GLIBC__)
1227
 
#if not __GLIBC_PREREQ(2, 16)
1228
 
#pragma GCC diagnostic pop
1229
 
#endif
1230
 
#endif
 
1154
                                                         -Wconversion */
1231
1155
        /* This process had nothing to say at this time */
1232
1156
        proc = proc->next;
1233
1157
        continue;
1237
1161
        proc->buffer = realloc(proc->buffer, proc->buffer_size
1238
1162
                               + (size_t) BUFFER_SIZE);
1239
1163
        if(proc->buffer == NULL){
1240
 
          error(0, errno, "malloc");
 
1164
          perror("malloc");
1241
1165
          exitstatus = EX_OSERR;
1242
1166
          goto fallback;
1243
1167
        }
1280
1204
    }
1281
1205
    bret = print_out_password(passwordbuffer, len);
1282
1206
    if(not bret){
1283
 
      error(0, errno, "print_out_password");
 
1207
      perror("print_out_password");
1284
1208
      exitstatus = EX_IOERR;
1285
1209
    }
1286
1210
  }
1288
1212
  /* Restore old signal handler */
1289
1213
  ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
1290
1214
  if(ret == -1){
1291
 
    error(0, errno, "sigaction");
 
1215
    perror("sigaction");
1292
1216
    exitstatus = EX_OSERR;
1293
1217
  }
1294
1218
  
1310
1234
      ret = kill(p->pid, SIGTERM);
1311
1235
      if(ret == -1 and errno != ESRCH){
1312
1236
        /* Set-uid proccesses might not get closed */
1313
 
        error(0, errno, "kill");
 
1237
        perror("kill");
1314
1238
      }
1315
1239
    }
1316
1240
  }
1320
1244
    ret = wait(NULL);
1321
1245
  } while(ret >= 0);
1322
1246
  if(errno != ECHILD){
1323
 
    error(0, errno, "wait");
 
1247
    perror("wait");
1324
1248
  }
1325
1249
  
1326
1250
  free_plugin_list();