/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 at bsnet
  • Date: 2011-02-11 19:02:24 UTC
  • mto: (237.7.13 mandos)
  • mto: This revision was merged to the branch mainline in revision 282.
  • Revision ID: teddy@fukt.bsnet.se-20110211190224-62celso7mswtep65
* mandos-monitor: Use unicode string literals.  Update __future__
                  import line to use all available and applicable
                  imports.

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-2010 Teddy Hogeborn
 
6
 * Copyright © 2008-2010 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(),
26
 
                                   O_CLOEXEC */
 
26
                                   asprintf(), O_CLOEXEC */
27
27
#include <stddef.h>             /* size_t, NULL */
28
28
#include <stdlib.h>             /* malloc(), exit(), EXIT_SUCCESS,
29
29
                                   realloc() */
30
30
#include <stdbool.h>            /* bool, true, false */
31
31
#include <stdio.h>              /* fileno(), fprintf(),
32
 
                                   stderr, STDOUT_FILENO, fclose() */
33
 
#include <sys/types.h>          /* DIR, fdopendir(), fstat(), struct
 
32
                                   stderr, STDOUT_FILENO */
 
33
#include <sys/types.h>          /* DIR, fdopendir(), stat(), struct
34
34
                                   stat, waitpid(), WIFEXITED(),
35
35
                                   WEXITSTATUS(), wait(), pid_t,
36
36
                                   uid_t, gid_t, getuid(), getgid(),
40
40
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
41
41
                                   WEXITSTATUS(), WTERMSIG(),
42
42
                                   WCOREDUMP() */
43
 
#include <sys/stat.h>           /* struct stat, fstat(), S_ISREG() */
 
43
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
44
44
#include <iso646.h>             /* and, or, not */
45
45
#include <dirent.h>             /* DIR, struct dirent, fdopendir(),
46
46
                                   readdir(), closedir(), dirfd() */
47
 
#include <unistd.h>             /* fcntl(), F_GETFD, F_SETFD,
48
 
                                   FD_CLOEXEC, write(), STDOUT_FILENO,
49
 
                                   struct stat, fstat(), close(),
50
 
                                   setgid(), setuid(), S_ISREG(),
51
 
                                   faccessat() pipe(), fork(),
52
 
                                   _exit(), dup2(), fexecve(), read()
53
 
                                */
 
47
#include <unistd.h>             /* struct stat, stat(), S_ISREG(),
 
48
                                   fcntl(), setuid(), setgid(),
 
49
                                   F_GETFD, F_SETFD, FD_CLOEXEC,
 
50
                                   access(), pipe(), fork(), close()
 
51
                                   dup2(), STDOUT_FILENO, _exit(),
 
52
                                   execv(), write(), read(),
 
53
                                   close() */
54
54
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
55
 
                                   FD_CLOEXEC, openat() */
56
 
#include <string.h>             /* strsep, strlen(), strsignal(),
57
 
                                   strcmp(), strncmp() */
 
55
                                   FD_CLOEXEC */
 
56
#include <string.h>             /* strsep, strlen(), asprintf(),
 
57
                                   strsignal(), strcmp(), strncmp() */
58
58
#include <errno.h>              /* errno */
59
59
#include <argp.h>               /* struct argp_option, struct
60
60
                                   argp_state, struct argp,
79
79
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
80
80
 
81
81
const char *argp_program_version = "plugin-runner " VERSION;
82
 
const char *argp_program_bug_address = "<mandos@recompile.se>";
 
82
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
83
83
 
84
84
typedef struct plugin{
85
85
  char *name;                   /* can be NULL or any plugin name */
105
105
 
106
106
/* Gets an existing plugin based on name,
107
107
   or if none is found, creates a new one */
108
 
__attribute__((warn_unused_result))
109
108
static plugin *getplugin(char *name){
110
109
  /* Check for existing plugin with that name */
111
110
  for(plugin *p = plugin_list; p != NULL; p = p->next){
172
171
}
173
172
 
174
173
/* Helper function for add_argument and add_environment */
175
 
__attribute__((nonnull, warn_unused_result))
176
174
static bool add_to_char_array(const char *new, char ***array,
177
175
                              int *len){
178
176
  /* Resize the pointed-to array to hold one more pointer */
179
 
  char **new_array = NULL;
180
177
  do {
181
 
    new_array = realloc(*array, sizeof(char *)
182
 
                        * (size_t) ((*len) + 2));
183
 
  } while(new_array == NULL and errno == EINTR);
 
178
    *array = realloc(*array, sizeof(char *)
 
179
                     * (size_t) ((*len) + 2));
 
180
  } while(*array == NULL and errno == EINTR);
184
181
  /* Malloc check */
185
 
  if(new_array == NULL){
 
182
  if(*array == NULL){
186
183
    return false;
187
184
  }
188
 
  *array = new_array;
189
185
  /* Make a copy of the new string */
190
186
  char *copy;
191
187
  do {
203
199
}
204
200
 
205
201
/* Add to a plugin's argument vector */
206
 
__attribute__((nonnull(2), warn_unused_result))
207
202
static bool add_argument(plugin *p, const char *arg){
208
203
  if(p == NULL){
209
204
    return false;
212
207
}
213
208
 
214
209
/* Add to a plugin's environment */
215
 
__attribute__((nonnull(2), warn_unused_result))
216
210
static bool add_environment(plugin *p, const char *def, bool replace){
217
211
  if(p == NULL){
218
212
    return false;
220
214
  /* namelen = length of name of environment variable */
221
215
  size_t namelen = (size_t)(strchrnul(def, '=') - def);
222
216
  /* Search for this environment variable */
223
 
  for(char **envdef = p->environ; *envdef != NULL; envdef++){
224
 
    if(strncmp(*envdef, def, namelen + 1) == 0){
 
217
  for(char **e = p->environ; *e != NULL; e++){
 
218
    if(strncmp(*e, def, namelen + 1) == 0){
225
219
      /* It already exists */
226
220
      if(replace){
227
 
        char *new_envdef;
 
221
        char *new;
228
222
        do {
229
 
          new_envdef = realloc(*envdef, strlen(def) + 1);
230
 
        } while(new_envdef == NULL and errno == EINTR);
231
 
        if(new_envdef == NULL){
 
223
          new = realloc(*e, strlen(def) + 1);
 
224
        } while(new == NULL and errno == EINTR);
 
225
        if(new == NULL){
232
226
          return false;
233
227
        }
234
 
        *envdef = new_envdef;
235
 
        strcpy(*envdef, def);
 
228
        *e = new;
 
229
        strcpy(*e, def);
236
230
      }
237
231
      return true;
238
232
    }
245
239
 * Descriptor Flags".
246
240
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
247
241
 */
248
 
__attribute__((warn_unused_result))
249
242
static int set_cloexec_flag(int fd){
250
243
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
251
244
  /* If reading the flags failed, return error indication now. */
293
286
}
294
287
 
295
288
/* Prints out a password to stdout */
296
 
__attribute__((nonnull, warn_unused_result))
297
289
static bool print_out_password(const char *buffer, size_t length){
298
290
  ssize_t ret;
299
291
  for(size_t written = 0; written < length; written += (size_t)ret){
307
299
}
308
300
 
309
301
/* Removes and free a plugin from the plugin list */
310
 
__attribute__((nonnull))
311
302
static void free_plugin(plugin *plugin_node){
312
303
  
313
304
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
363
354
                                      .sa_flags = SA_NOCLDSTOP };
364
355
  char **custom_argv = NULL;
365
356
  int custom_argc = 0;
366
 
  int dir_fd;
367
357
  
368
358
  /* Establish a signal handler */
369
359
  sigemptyset(&sigchld_action.sa_mask);
426
416
    { .name = NULL }
427
417
  };
428
418
  
429
 
  __attribute__((nonnull(3)))
430
419
  error_t parse_opt(int key, char *arg, struct argp_state *state){
431
420
    errno = 0;
432
421
    switch(key){
433
422
      char *tmp;
434
 
      intmax_t tmp_id;
 
423
      intmax_t tmpmax;
435
424
    case 'g':                   /* --global-options */
436
425
      {
437
426
        char *plugin_option;
440
429
            break;
441
430
          }
442
431
        }
443
 
        errno = 0;
444
432
      }
445
433
      break;
446
434
    case 'G':                   /* --global-env */
447
 
      if(add_environment(getplugin(NULL), arg, true)){
448
 
        errno = 0;
449
 
      }
 
435
      add_environment(getplugin(NULL), arg, true);
450
436
      break;
451
437
    case 'o':                   /* --options-for */
452
438
      {
469
455
            break;
470
456
          }
471
457
        }
472
 
        errno = 0;
473
458
      }
474
459
      break;
475
460
    case 'E':                   /* --env-for */
487
472
          errno = EINVAL;
488
473
          break;
489
474
        }
490
 
        if(add_environment(getplugin(arg), envdef, true)){
491
 
          errno = 0;
492
 
        }
 
475
        add_environment(getplugin(arg), envdef, true);
493
476
      }
494
477
      break;
495
478
    case 'd':                   /* --disable */
497
480
        plugin *p = getplugin(arg);
498
481
        if(p != NULL){
499
482
          p->disabled = true;
500
 
          errno = 0;
501
483
        }
502
484
      }
503
485
      break;
506
488
        plugin *p = getplugin(arg);
507
489
        if(p != NULL){
508
490
          p->disabled = false;
509
 
          errno = 0;
510
491
        }
511
492
      }
512
493
      break;
513
494
    case 128:                   /* --plugin-dir */
514
495
      free(plugindir);
515
496
      plugindir = strdup(arg);
516
 
      if(plugindir != NULL){
517
 
        errno = 0;
518
 
      }
519
497
      break;
520
498
    case 129:                   /* --config-file */
521
499
      /* This is already done by parse_opt_config_file() */
522
500
      break;
523
501
    case 130:                   /* --userid */
524
 
      tmp_id = strtoimax(arg, &tmp, 10);
 
502
      tmpmax = strtoimax(arg, &tmp, 10);
525
503
      if(errno != 0 or tmp == arg or *tmp != '\0'
526
 
         or tmp_id != (uid_t)tmp_id){
 
504
         or tmpmax != (uid_t)tmpmax){
527
505
        argp_error(state, "Bad user ID number: \"%s\", using %"
528
506
                   PRIdMAX, arg, (intmax_t)uid);
529
507
        break;
530
508
      }
531
 
      uid = (uid_t)tmp_id;
532
 
      errno = 0;
 
509
      uid = (uid_t)tmpmax;
533
510
      break;
534
511
    case 131:                   /* --groupid */
535
 
      tmp_id = strtoimax(arg, &tmp, 10);
 
512
      tmpmax = strtoimax(arg, &tmp, 10);
536
513
      if(errno != 0 or tmp == arg or *tmp != '\0'
537
 
         or tmp_id != (gid_t)tmp_id){
 
514
         or tmpmax != (gid_t)tmpmax){
538
515
        argp_error(state, "Bad group ID number: \"%s\", using %"
539
516
                   PRIdMAX, arg, (intmax_t)gid);
540
517
        break;
541
518
      }
542
 
      gid = (gid_t)tmp_id;
543
 
      errno = 0;
 
519
      gid = (gid_t)tmpmax;
544
520
      break;
545
521
    case 132:                   /* --debug */
546
522
      debug = true;
594
570
    case 129:                   /* --config-file */
595
571
      free(argfile);
596
572
      argfile = strdup(arg);
597
 
      if(argfile != NULL){
598
 
        errno = 0;
599
 
      }
600
573
      break;
601
574
    case 130:                   /* --userid */
602
575
    case 131:                   /* --groupid */
685
658
        }
686
659
        
687
660
        custom_argc += 1;
688
 
        {
689
 
          char **new_argv = realloc(custom_argv, sizeof(char *)
690
 
                                    * ((unsigned int)
691
 
                                       custom_argc + 1));
692
 
          if(new_argv == NULL){
693
 
            error(0, errno, "realloc");
694
 
            exitstatus = EX_OSERR;
695
 
            free(new_arg);
696
 
            free(org_line);
697
 
            goto fallback;
698
 
          } else {
699
 
            custom_argv = new_argv;
700
 
          }
 
661
        custom_argv = realloc(custom_argv, sizeof(char *)
 
662
                              * ((unsigned int) custom_argc + 1));
 
663
        if(custom_argv == NULL){
 
664
          error(0, errno, "realloc");
 
665
          exitstatus = EX_OSERR;
 
666
          free(org_line);
 
667
          goto fallback;
701
668
        }
702
669
        custom_argv[custom_argc-1] = new_arg;
703
670
        custom_argv[custom_argc] = NULL;
775
742
    }
776
743
  }
777
744
  
778
 
  if(getuid() == 0){
779
 
    /* Work around Debian bug #633582:
780
 
       <http://bugs.debian.org/633582> */
781
 
    int plugindir_fd = open(/* plugindir or */ PDIR, O_RDONLY);
782
 
    if(plugindir_fd == -1){
783
 
      if(errno != ENOENT){
784
 
        error(0, errno, "open(\"" PDIR "\")");
785
 
      }
786
 
    } else {
787
 
      ret = (int)TEMP_FAILURE_RETRY(fstat(plugindir_fd, &st));
788
 
      if(ret == -1){
789
 
        error(0, errno, "fstat");
790
 
      } else {
791
 
        if(S_ISDIR(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
792
 
          ret = fchown(plugindir_fd, uid, gid);
793
 
          if(ret == -1){
794
 
            error(0, errno, "fchown");
795
 
          }
796
 
        }
797
 
      }
798
 
      TEMP_FAILURE_RETRY(close(plugindir_fd));
799
 
    }
800
 
  }
801
 
  
802
 
  /* Lower permissions */
803
 
  ret = setgid(gid);
 
745
  /* Strip permissions down to nobody */
 
746
  setgid(gid);
804
747
  if(ret == -1){
805
748
    error(0, errno, "setgid");
806
749
  }
811
754
  
812
755
  /* Open plugin directory with close_on_exec flag */
813
756
  {
814
 
    dir_fd = open(plugindir != NULL ? plugindir : PDIR, O_RDONLY |
815
 
#ifdef O_CLOEXEC
816
 
                  O_CLOEXEC
817
 
#else  /* not O_CLOEXEC */
818
 
                  0
819
 
#endif  /* not O_CLOEXEC */
820
 
                  );
 
757
    int dir_fd = -1;
 
758
    if(plugindir == NULL){
 
759
      dir_fd = open(PDIR, O_RDONLY |
 
760
#ifdef O_CLOEXEC
 
761
                    O_CLOEXEC
 
762
#else  /* not O_CLOEXEC */
 
763
                    0
 
764
#endif  /* not O_CLOEXEC */
 
765
                    );
 
766
    } else {
 
767
      dir_fd = open(plugindir, O_RDONLY |
 
768
#ifdef O_CLOEXEC
 
769
                    O_CLOEXEC
 
770
#else  /* not O_CLOEXEC */
 
771
                    0
 
772
#endif  /* not O_CLOEXEC */
 
773
                    );
 
774
    }
821
775
    if(dir_fd == -1){
822
776
      error(0, errno, "Could not open plugin dir");
823
777
      exitstatus = EX_UNAVAILABLE;
868
822
    {
869
823
      bool bad_name = false;
870
824
      
871
 
      const char * const bad_prefixes[] = { ".", "#", NULL };
 
825
      const char const *bad_prefixes[] = { ".", "#", NULL };
872
826
      
873
 
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
 
827
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
874
828
                                           ".dpkg-old",
875
829
                                           ".dpkg-bak",
876
830
                                           ".dpkg-divert", NULL };
877
 
#ifdef __GNUC__
878
 
#pragma GCC diagnostic push
879
 
#pragma GCC diagnostic ignored "-Wcast-qual"
880
 
#endif
881
 
      for(const char **pre = (const char **)bad_prefixes;
882
 
          *pre != NULL; pre++){
883
 
#ifdef __GNUC__
884
 
#pragma GCC diagnostic pop
885
 
#endif
 
831
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
886
832
        size_t pre_len = strlen(*pre);
887
833
        if((d_name_len >= pre_len)
888
834
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
897
843
      if(bad_name){
898
844
        continue;
899
845
      }
900
 
#ifdef __GNUC__
901
 
#pragma GCC diagnostic push
902
 
#pragma GCC diagnostic ignored "-Wcast-qual"
903
 
#endif
904
 
      for(const char **suf = (const char **)bad_suffixes;
905
 
          *suf != NULL; suf++){
906
 
#ifdef __GNUC__
907
 
#pragma GCC diagnostic pop
908
 
#endif
 
846
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
909
847
        size_t suf_len = strlen(*suf);
910
848
        if((d_name_len >= suf_len)
911
849
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
924
862
      }
925
863
    }
926
864
    
927
 
    int plugin_fd = openat(dir_fd, dirst->d_name, O_RDONLY |
928
 
#ifdef O_CLOEXEC
929
 
                            O_CLOEXEC
930
 
#else  /* not O_CLOEXEC */
931
 
                            0
932
 
#endif  /* not O_CLOEXEC */
933
 
                            );
934
 
    if(plugin_fd == -1){
935
 
      error(0, errno, "Could not open plugin");
936
 
      continue;
 
865
    char *filename;
 
866
    if(plugindir == NULL){
 
867
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
 
868
                                             dirst->d_name));
 
869
    } else {
 
870
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
 
871
                                             plugindir,
 
872
                                             dirst->d_name));
937
873
    }
938
 
#ifndef O_CLOEXEC
939
 
  /* Set the FD_CLOEXEC flag on the plugin FD */
940
 
    ret = set_cloexec_flag(plugin_fd);
941
874
    if(ret < 0){
942
 
      error(0, errno, "set_cloexec_flag");
943
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
875
      error(0, errno, "asprintf");
944
876
      continue;
945
877
    }
946
 
#endif  /* O_CLOEXEC */
947
 
    ret = (int)TEMP_FAILURE_RETRY(fstat(plugin_fd, &st));
 
878
    
 
879
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
948
880
    if(ret == -1){
949
881
      error(0, errno, "stat");
950
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
882
      free(filename);
951
883
      continue;
952
884
    }
953
885
    
954
886
    /* Ignore non-executable files */
955
887
    if(not S_ISREG(st.st_mode)
956
 
       or (TEMP_FAILURE_RETRY(faccessat(dir_fd, dirst->d_name, X_OK,
957
 
                                        0)) != 0)){
 
888
       or (TEMP_FAILURE_RETRY(access(filename, X_OK)) != 0)){
958
889
      if(debug){
959
 
        fprintf(stderr, "Ignoring plugin dir entry \"%s/%s\""
960
 
                " with bad type or mode\n",
961
 
                plugindir != NULL ? plugindir : PDIR, dirst->d_name);
 
890
        fprintf(stderr, "Ignoring plugin dir entry \"%s\""
 
891
                " with bad type or mode\n", filename);
962
892
      }
963
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
893
      free(filename);
964
894
      continue;
965
895
    }
966
896
    
967
897
    plugin *p = getplugin(dirst->d_name);
968
898
    if(p == NULL){
969
899
      error(0, errno, "getplugin");
970
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
900
      free(filename);
971
901
      continue;
972
902
    }
973
903
    if(p->disabled){
975
905
        fprintf(stderr, "Ignoring disabled plugin \"%s\"\n",
976
906
                dirst->d_name);
977
907
      }
978
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
908
      free(filename);
979
909
      continue;
980
910
    }
981
911
    {
995
925
        }
996
926
      }
997
927
    }
998
 
    /* If this plugin has any environment variables, we need to
999
 
       duplicate the environment from this process, too. */
 
928
    /* If this plugin has any environment variables, we will call
 
929
       using execve and need to duplicate the environment from this
 
930
       process, too. */
1000
931
    if(p->environ[0] != NULL){
1001
932
      for(char **e = environ; *e != NULL; e++){
1002
933
        if(not add_environment(p, *e, false)){
1068
999
           above and must now close it manually here. */
1069
1000
        closedir(dir);
1070
1001
      }
1071
 
      if(fexecve(plugin_fd, p->argv,
1072
 
                (p->environ[0] != NULL) ? p->environ : environ) < 0){
1073
 
        error(0, errno, "fexecve for %s/%s",
1074
 
              plugindir != NULL ? plugindir : PDIR, dirst->d_name);
1075
 
        _exit(EX_OSERR);
 
1002
      if(p->environ[0] == NULL){
 
1003
        if(execv(filename, p->argv) < 0){
 
1004
          error(0, errno, "execv for %s", filename);
 
1005
          _exit(EX_OSERR);
 
1006
        }
 
1007
      } else {
 
1008
        if(execve(filename, p->argv, p->environ) < 0){
 
1009
          error(0, errno, "execve for %s", filename);
 
1010
          _exit(EX_OSERR);
 
1011
        }
1076
1012
      }
1077
1013
      /* no return */
1078
1014
    }
1079
1015
    /* Parent process */
1080
1016
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
1081
1017
                                             pipe */
1082
 
    TEMP_FAILURE_RETRY(close(plugin_fd));
 
1018
    free(filename);
1083
1019
    plugin *new_plugin = getplugin(dirst->d_name);
1084
1020
    if(new_plugin == NULL){
1085
1021
      error(0, errno, "getplugin");
1107
1043
      goto fallback;
1108
1044
    }
1109
1045
    
1110
 
#if defined (__GNUC__) and defined (__GLIBC__)
1111
 
#if not __GLIBC_PREREQ(2, 16)
1112
 
#pragma GCC diagnostic push
1113
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1114
 
#endif
1115
 
#endif
1116
1046
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
1117
 
                                          -Wconversion in GNU libc
1118
 
                                          before 2.16 */
1119
 
#if defined (__GNUC__) and defined (__GLIBC__)
1120
 
#if not __GLIBC_PREREQ(2, 16)
1121
 
#pragma GCC diagnostic pop
1122
 
#endif
1123
 
#endif
 
1047
                                          -Wconversion */
1124
1048
    
1125
1049
    if(maxfd < new_plugin->fd){
1126
1050
      maxfd = new_plugin->fd;
1180
1104
          }
1181
1105
          
1182
1106
          /* Remove the plugin */
1183
 
#if defined (__GNUC__) and defined (__GLIBC__)
1184
 
#if not __GLIBC_PREREQ(2, 16)
1185
 
#pragma GCC diagnostic push
1186
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1187
 
#endif
1188
 
#endif
1189
1107
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
1190
 
                                          -Wconversion in GNU libc
1191
 
                                          before 2.16 */
1192
 
#if defined (__GNUC__) and defined (__GLIBC__)
1193
 
#if not __GLIBC_PREREQ(2, 16)
1194
 
#pragma GCC diagnostic pop
1195
 
#endif
1196
 
#endif
 
1108
                                          -Wconversion */
1197
1109
          
1198
1110
          /* Block signal while modifying process_list */
1199
1111
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1239
1151
      }
1240
1152
      
1241
1153
      /* This process has not completed.  Does it have any output? */
1242
 
#if defined (__GNUC__) and defined (__GLIBC__)
1243
 
#if not __GLIBC_PREREQ(2, 16)
1244
 
#pragma GCC diagnostic push
1245
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1246
 
#endif
1247
 
#endif
1248
1154
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
1249
1155
                                                         warning from
1250
 
                                                         -Wconversion
1251
 
                                                         in GNU libc
1252
 
                                                         before
1253
 
                                                         2.16 */
1254
 
#if defined (__GNUC__) and defined (__GLIBC__)
1255
 
#if not __GLIBC_PREREQ(2, 16)
1256
 
#pragma GCC diagnostic pop
1257
 
#endif
1258
 
#endif
 
1156
                                                         -Wconversion */
1259
1157
        /* This process had nothing to say at this time */
1260
1158
        proc = proc->next;
1261
1159
        continue;
1262
1160
      }
1263
1161
      /* Before reading, make the process' data buffer large enough */
1264
1162
      if(proc->buffer_length + BUFFER_SIZE > proc->buffer_size){
1265
 
        char *new_buffer = realloc(proc->buffer, proc->buffer_size
1266
 
                                   + (size_t) BUFFER_SIZE);
1267
 
        if(new_buffer == NULL){
 
1163
        proc->buffer = realloc(proc->buffer, proc->buffer_size
 
1164
                               + (size_t) BUFFER_SIZE);
 
1165
        if(proc->buffer == NULL){
1268
1166
          error(0, errno, "malloc");
1269
1167
          exitstatus = EX_OSERR;
1270
1168
          goto fallback;
1271
1169
        }
1272
 
        proc->buffer = new_buffer;
1273
1170
        proc->buffer_size += BUFFER_SIZE;
1274
1171
      }
1275
1172
      /* Read from the process */