/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: 2014-03-01 09:47:01 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 311.
  • Revision ID: teddy@recompile.se-20140301094701-j0vpnc0fyil6tpdn
* plugin-runner.c (main): Declare "bad_prefixes" and "bad_suffixes"
                          correctly.  Also fix resulting issues with
                          casting to non-const and suppress the
                          warnings thereof.

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