/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-10-01 15:29:01 UTC
  • Revision ID: teddy@fukt.bsnet.se-20081001152901-fh30whl3m4vb7m24
* debian/changelog: New Debian revision.

* debian/mandos-client.lintian-overrides: Added comments.
* debian/mandos.lintian-overrides: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8; mode: c; mode: orgtbl -*- */
 
1
/*  -*- coding: utf-8 -*- */
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 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
23
22
 */
24
23
 
25
24
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), getline(),
26
 
                                   asprintf(), O_CLOEXEC */
 
25
                                   asprintf() */
27
26
#include <stddef.h>             /* size_t, NULL */
28
 
#include <stdlib.h>             /* malloc(), exit(), EXIT_SUCCESS,
29
 
                                   realloc() */
 
27
#include <stdlib.h>             /* malloc(), exit(), EXIT_FAILURE,
 
28
                                   EXIT_SUCCESS, realloc() */
30
29
#include <stdbool.h>            /* bool, true, false */
31
30
#include <stdio.h>              /* perror, fileno(), fprintf(),
32
31
                                   stderr, STDOUT_FILENO */
33
 
#include <sys/types.h>          /* DIR, fdopendir(), stat(), struct
 
32
#include <sys/types.h>          /* DIR, opendir(), stat(), struct
34
33
                                   stat, waitpid(), WIFEXITED(),
35
34
                                   WEXITSTATUS(), wait(), pid_t,
36
35
                                   uid_t, gid_t, getuid(), getgid(),
38
37
#include <sys/select.h>         /* fd_set, select(), FD_ZERO(),
39
38
                                   FD_SET(), FD_ISSET(), FD_CLR */
40
39
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
41
 
                                   WEXITSTATUS(), WTERMSIG(),
42
 
                                   WCOREDUMP() */
 
40
                                   WEXITSTATUS() */
43
41
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
44
42
#include <iso646.h>             /* and, or, not */
45
 
#include <dirent.h>             /* DIR, struct dirent, fdopendir(),
 
43
#include <dirent.h>             /* DIR, struct dirent, opendir(),
46
44
                                   readdir(), closedir(), dirfd() */
47
45
#include <unistd.h>             /* struct stat, stat(), S_ISREG(),
48
46
                                   fcntl(), setuid(), setgid(),
53
51
                                   close() */
54
52
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
55
53
                                   FD_CLOEXEC */
56
 
#include <string.h>             /* strsep, strlen(), asprintf(),
57
 
                                   strsignal(), strcmp(), strncmp() */
 
54
#include <string.h>             /* strsep, strlen(), asprintf() */
58
55
#include <errno.h>              /* errno */
59
56
#include <argp.h>               /* struct argp_option, struct
60
57
                                   argp_state, struct argp,
64
61
#include <signal.h>             /* struct sigaction, sigemptyset(),
65
62
                                   sigaddset(), sigaction(),
66
63
                                   sigprocmask(), SIG_BLOCK, SIGCHLD,
67
 
                                   SIG_UNBLOCK, kill(), sig_atomic_t
68
 
                                */
 
64
                                   SIG_UNBLOCK, kill() */
69
65
#include <errno.h>              /* errno, EBADF */
70
 
#include <inttypes.h>           /* intmax_t, PRIdMAX, strtoimax() */
71
 
#include <sysexits.h>           /* EX_OSERR, EX_USAGE, EX_IOERR,
72
 
                                   EX_CONFIG, EX_UNAVAILABLE, EX_OK */
73
66
 
74
67
#define BUFFER_SIZE 256
75
68
 
86
79
  char **environ;
87
80
  int envc;
88
81
  bool disabled;
89
 
  
 
82
 
90
83
  /* Variables used for running processes*/
91
84
  pid_t pid;
92
85
  int fd;
94
87
  size_t buffer_size;
95
88
  size_t buffer_length;
96
89
  bool eof;
97
 
  volatile sig_atomic_t completed;
98
 
  int status;
 
90
  volatile bool completed;
 
91
  volatile int status;
99
92
  struct plugin *next;
100
93
} plugin;
101
94
 
104
97
/* Gets an existing plugin based on name,
105
98
   or if none is found, creates a new one */
106
99
static plugin *getplugin(char *name){
107
 
  /* Check for existing plugin with that name */
108
 
  for(plugin *p = plugin_list; p != NULL; p = p->next){
109
 
    if((p->name == name)
110
 
       or (p->name and name and (strcmp(p->name, name) == 0))){
 
100
  /* Check for exiting plugin with that name */
 
101
  for (plugin *p = plugin_list; p != NULL; p = p->next){
 
102
    if ((p->name == name)
 
103
        or (p->name and name and (strcmp(p->name, name) == 0))){
111
104
      return p;
112
105
    }
113
106
  }
114
107
  /* Create a new plugin */
115
 
  plugin *new_plugin = NULL;
116
 
  do {
117
 
    new_plugin = malloc(sizeof(plugin));
118
 
  } while(new_plugin == NULL and errno == EINTR);
119
 
  if(new_plugin == NULL){
 
108
  plugin *new_plugin = malloc(sizeof(plugin));
 
109
  if (new_plugin == NULL){
120
110
    return NULL;
121
111
  }
122
112
  char *copy_name = NULL;
123
113
  if(name != NULL){
124
 
    do {
125
 
      copy_name = strdup(name);
126
 
    } while(copy_name == NULL and errno == EINTR);
 
114
    copy_name = strdup(name);
127
115
    if(copy_name == NULL){
128
 
      int e = errno;
129
 
      free(new_plugin);
130
 
      errno = e;
131
116
      return NULL;
132
117
    }
133
118
  }
134
119
  
135
 
  *new_plugin = (plugin){ .name = copy_name,
136
 
                          .argc = 1,
137
 
                          .disabled = false,
138
 
                          .next = plugin_list };
 
120
  *new_plugin = (plugin) { .name = copy_name,
 
121
                           .argc = 1,
 
122
                           .disabled = false,
 
123
                           .next = plugin_list };
139
124
  
140
 
  do {
141
 
    new_plugin->argv = malloc(sizeof(char *) * 2);
142
 
  } while(new_plugin->argv == NULL and errno == EINTR);
143
 
  if(new_plugin->argv == NULL){
144
 
    int e = errno;
 
125
  new_plugin->argv = malloc(sizeof(char *) * 2);
 
126
  if (new_plugin->argv == NULL){
145
127
    free(copy_name);
146
128
    free(new_plugin);
147
 
    errno = e;
148
129
    return NULL;
149
130
  }
150
131
  new_plugin->argv[0] = copy_name;
151
132
  new_plugin->argv[1] = NULL;
152
133
  
153
 
  do {
154
 
    new_plugin->environ = malloc(sizeof(char *));
155
 
  } while(new_plugin->environ == NULL and errno == EINTR);
 
134
  new_plugin->environ = malloc(sizeof(char *));
156
135
  if(new_plugin->environ == NULL){
157
 
    int e = errno;
158
136
    free(copy_name);
159
137
    free(new_plugin->argv);
160
138
    free(new_plugin);
161
 
    errno = e;
162
139
    return NULL;
163
140
  }
164
141
  new_plugin->environ[0] = NULL;
172
149
static bool add_to_char_array(const char *new, char ***array,
173
150
                              int *len){
174
151
  /* Resize the pointed-to array to hold one more pointer */
175
 
  do {
176
 
    *array = realloc(*array, sizeof(char *)
177
 
                     * (size_t) ((*len) + 2));
178
 
  } while(*array == NULL and errno == EINTR);
 
152
  *array = realloc(*array, sizeof(char *)
 
153
                   * (size_t) ((*len) + 2));
179
154
  /* Malloc check */
180
155
  if(*array == NULL){
181
156
    return false;
182
157
  }
183
158
  /* Make a copy of the new string */
184
 
  char *copy;
185
 
  do {
186
 
    copy = strdup(new);
187
 
  } while(copy == NULL and errno == EINTR);
 
159
  char *copy = strdup(new);
188
160
  if(copy == NULL){
189
161
    return false;
190
162
  }
216
188
    if(strncmp(*e, def, namelen + 1) == 0){
217
189
      /* It already exists */
218
190
      if(replace){
219
 
        char *new;
220
 
        do {
221
 
          new = realloc(*e, strlen(def) + 1);
222
 
        } while(new == NULL and errno == EINTR);
 
191
        char *new = realloc(*e, strlen(def) + 1);
223
192
        if(new == NULL){
224
193
          return false;
225
194
        }
235
204
/*
236
205
 * Based on the example in the GNU LibC manual chapter 13.13 "File
237
206
 * Descriptor Flags".
238
 
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
 
207
 * *Note File Descriptor Flags:(libc)Descriptor Flags.
239
208
 */
240
209
static int set_cloexec_flag(int fd){
241
 
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
 
210
  int ret = fcntl(fd, F_GETFD, 0);
242
211
  /* If reading the flags failed, return error indication now. */
243
212
  if(ret < 0){
244
213
    return ret;
245
214
  }
246
215
  /* Store modified flag word in the descriptor. */
247
 
  return (int)TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD,
248
 
                                       ret | FD_CLOEXEC));
 
216
  return fcntl(fd, F_SETFD, ret | FD_CLOEXEC);
249
217
}
250
218
 
251
219
 
252
220
/* Mark processes as completed when they exit, and save their exit
253
221
   status. */
254
222
static void handle_sigchld(__attribute__((unused)) int sig){
255
 
  int old_errno = errno;
256
223
  while(true){
257
224
    plugin *proc = plugin_list;
258
225
    int status;
262
229
      break;
263
230
    }
264
231
    if(pid == -1){
265
 
      if(errno == ECHILD){
266
 
        /* No child processes */
267
 
        break;
 
232
      if (errno != ECHILD){
 
233
        perror("waitpid");
268
234
      }
269
 
      perror("waitpid");
 
235
      /* No child processes */
 
236
      break;
270
237
    }
271
238
    
272
239
    /* A child exited, find it in process_list */
278
245
      continue;
279
246
    }
280
247
    proc->status = status;
281
 
    proc->completed = 1;
 
248
    proc->completed = true;
282
249
  }
283
 
  errno = old_errno;
284
250
}
285
251
 
286
252
/* Prints out a password to stdout */
308
274
  }
309
275
  free(plugin_node->environ);
310
276
  free(plugin_node->buffer);
311
 
  
 
277
 
312
278
  /* Removes the plugin from the singly-linked list */
313
279
  if(plugin_node == plugin_list){
314
280
    /* First one - simple */
342
308
  struct stat st;
343
309
  fd_set rfds_all;
344
310
  int ret, maxfd = 0;
345
 
  ssize_t sret;
346
311
  uid_t uid = 65534;
347
312
  gid_t gid = 65534;
348
313
  bool debug = false;
358
323
  ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
359
324
  if(ret == -1){
360
325
    perror("sigaddset");
361
 
    exitstatus = EX_OSERR;
 
326
    exitstatus = EXIT_FAILURE;
362
327
    goto fallback;
363
328
  }
364
329
  ret = sigaction(SIGCHLD, &sigchld_action, &old_sigchld_action);
365
330
  if(ret == -1){
366
331
    perror("sigaction");
367
 
    exitstatus = EX_OSERR;
 
332
    exitstatus = EXIT_FAILURE;
368
333
    goto fallback;
369
334
  }
370
335
  
402
367
      .doc = "Group ID the plugins will run as", .group = 3 },
403
368
    { .name = "debug", .key = 132,
404
369
      .doc = "Debug mode", .group = 4 },
405
 
    /*
406
 
     * These reproduce what we would get without ARGP_NO_HELP
407
 
     */
408
 
    { .name = "help", .key = '?',
409
 
      .doc = "Give this help list", .group = -1 },
410
 
    { .name = "usage", .key = -3,
411
 
      .doc = "Give a short usage message", .group = -1 },
412
 
    { .name = "version", .key = 'V',
413
 
      .doc = "Print program version", .group = -1 },
414
370
    { .name = NULL }
415
371
  };
416
372
  
417
 
  error_t parse_opt(int key, char *arg, struct argp_state *state){
418
 
    errno = 0;
419
 
    switch(key){
420
 
      char *tmp;
421
 
      intmax_t tmpmax;
 
373
  error_t parse_opt (int key, char *arg, __attribute__((unused))
 
374
                     struct argp_state *state) {
 
375
    switch (key) {
422
376
    case 'g':                   /* --global-options */
423
 
      {
424
 
        char *plugin_option;
425
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
426
 
          if(not add_argument(getplugin(NULL), plugin_option)){
427
 
            break;
 
377
      if (arg != NULL){
 
378
        char *p;
 
379
        while((p = strsep(&arg, ",")) != NULL){
 
380
          if(p[0] == '\0'){
 
381
            continue;
 
382
          }
 
383
          if(not add_argument(getplugin(NULL), p)){
 
384
            perror("add_argument");
 
385
            return ARGP_ERR_UNKNOWN;
428
386
          }
429
387
        }
430
388
      }
431
389
      break;
432
390
    case 'G':                   /* --global-env */
433
 
      add_environment(getplugin(NULL), arg, true);
 
391
      if(arg == NULL){
 
392
        break;
 
393
      }
 
394
      if(not add_environment(getplugin(NULL), arg, true)){
 
395
        perror("add_environment");
 
396
      }
434
397
      break;
435
398
    case 'o':                   /* --options-for */
436
 
      {
437
 
        char *option_list = strchr(arg, ':');
438
 
        if(option_list == NULL){
439
 
          argp_error(state, "No colon in \"%s\"", arg);
440
 
          errno = EINVAL;
441
 
          break;
442
 
        }
443
 
        *option_list = '\0';
444
 
        option_list++;
445
 
        if(arg[0] == '\0'){
446
 
          argp_error(state, "Empty plugin name");
447
 
          errno = EINVAL;
448
 
          break;
449
 
        }
450
 
        char *option;
451
 
        while((option = strsep(&option_list, ",")) != NULL){
452
 
          if(not add_argument(getplugin(arg), option)){
453
 
            break;
 
399
      if (arg != NULL){
 
400
        char *p_name = strsep(&arg, ":");
 
401
        if(p_name[0] == '\0' or arg == NULL){
 
402
          break;
 
403
        }
 
404
        char *opt = strsep(&arg, ":");
 
405
        if(opt[0] == '\0' or opt == NULL){
 
406
          break;
 
407
        }
 
408
        char *p;
 
409
        while((p = strsep(&opt, ",")) != NULL){
 
410
          if(p[0] == '\0'){
 
411
            continue;
 
412
          }
 
413
          if(not add_argument(getplugin(p_name), p)){
 
414
            perror("add_argument");
 
415
            return ARGP_ERR_UNKNOWN;
454
416
          }
455
417
        }
456
418
      }
457
419
      break;
458
420
    case 'E':                   /* --env-for */
 
421
      if(arg == NULL){
 
422
        break;
 
423
      }
459
424
      {
460
425
        char *envdef = strchr(arg, ':');
461
426
        if(envdef == NULL){
462
 
          argp_error(state, "No colon in \"%s\"", arg);
463
 
          errno = EINVAL;
464
427
          break;
465
428
        }
466
429
        *envdef = '\0';
467
 
        envdef++;
468
 
        if(arg[0] == '\0'){
469
 
          argp_error(state, "Empty plugin name");
470
 
          errno = EINVAL;
471
 
          break;
 
430
        if(not add_environment(getplugin(arg), envdef+1, true)){
 
431
          perror("add_environment");
472
432
        }
473
 
        add_environment(getplugin(arg), envdef, true);
474
433
      }
475
434
      break;
476
435
    case 'd':                   /* --disable */
477
 
      {
 
436
      if (arg != NULL){
478
437
        plugin *p = getplugin(arg);
479
 
        if(p != NULL){
480
 
          p->disabled = true;
 
438
        if(p == NULL){
 
439
          return ARGP_ERR_UNKNOWN;
481
440
        }
 
441
        p->disabled = true;
482
442
      }
483
443
      break;
484
444
    case 'e':                   /* --enable */
485
 
      {
 
445
      if (arg != NULL){
486
446
        plugin *p = getplugin(arg);
487
 
        if(p != NULL){
488
 
          p->disabled = false;
 
447
        if(p == NULL){
 
448
          return ARGP_ERR_UNKNOWN;
489
449
        }
 
450
        p->disabled = false;
490
451
      }
491
452
      break;
492
453
    case 128:                   /* --plugin-dir */
493
454
      free(plugindir);
494
455
      plugindir = strdup(arg);
 
456
      if(plugindir == NULL){
 
457
        perror("strdup");
 
458
      }      
495
459
      break;
496
460
    case 129:                   /* --config-file */
497
461
      /* This is already done by parse_opt_config_file() */
498
462
      break;
499
463
    case 130:                   /* --userid */
500
 
      tmpmax = strtoimax(arg, &tmp, 10);
501
 
      if(errno != 0 or tmp == arg or *tmp != '\0'
502
 
         or tmpmax != (uid_t)tmpmax){
503
 
        argp_error(state, "Bad user ID number: \"%s\", using %"
504
 
                   PRIdMAX, arg, (intmax_t)uid);
505
 
        break;
506
 
      }
507
 
      uid = (uid_t)tmpmax;
 
464
      uid = (uid_t)strtol(arg, NULL, 10);
508
465
      break;
509
466
    case 131:                   /* --groupid */
510
 
      tmpmax = strtoimax(arg, &tmp, 10);
511
 
      if(errno != 0 or tmp == arg or *tmp != '\0'
512
 
         or tmpmax != (gid_t)tmpmax){
513
 
        argp_error(state, "Bad group ID number: \"%s\", using %"
514
 
                   PRIdMAX, arg, (intmax_t)gid);
515
 
        break;
516
 
      }
517
 
      gid = (gid_t)tmpmax;
 
467
      gid = (gid_t)strtol(arg, NULL, 10);
518
468
      break;
519
469
    case 132:                   /* --debug */
520
470
      debug = true;
521
471
      break;
522
 
      /*
523
 
       * These reproduce what we would get without ARGP_NO_HELP
524
 
       */
525
 
    case '?':                   /* --help */
526
 
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
527
 
      argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
528
 
    case -3:                    /* --usage */
529
 
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
530
 
      argp_state_help(state, state->out_stream,
531
 
                      ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
532
 
    case 'V':                   /* --version */
533
 
      fprintf(state->out_stream, "%s\n", argp_program_version);
534
 
      exit(EXIT_SUCCESS);
535
 
      break;
536
 
/*
537
 
 * When adding more options before this line, remember to also add a
538
 
 * "case" to the "parse_opt_config_file" function below.
539
 
 */
540
472
    case ARGP_KEY_ARG:
541
473
      /* Cryptsetup always passes an argument, which is an empty
542
474
         string if "none" was specified in /etc/crypttab.  So if
543
475
         argument was empty, we ignore it silently. */
544
 
      if(arg[0] == '\0'){
545
 
        break;
 
476
      if(arg[0] != '\0'){
 
477
        fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
546
478
      }
 
479
      break;
 
480
    case ARGP_KEY_END:
 
481
      break;
547
482
    default:
548
483
      return ARGP_ERR_UNKNOWN;
549
484
    }
550
 
    return errno;               /* Set to 0 at start */
 
485
    return 0;
551
486
  }
552
487
  
553
488
  /* This option parser is the same as parse_opt() above, except it
554
489
     ignores everything but the --config-file option. */
555
 
  error_t parse_opt_config_file(int key, char *arg,
556
 
                                __attribute__((unused))
557
 
                                struct argp_state *state){
558
 
    errno = 0;
559
 
    switch(key){
 
490
  error_t parse_opt_config_file (int key, char *arg,
 
491
                                 __attribute__((unused))
 
492
                                 struct argp_state *state) {
 
493
    switch (key) {
560
494
    case 'g':                   /* --global-options */
561
495
    case 'G':                   /* --global-env */
562
496
    case 'o':                   /* --options-for */
568
502
    case 129:                   /* --config-file */
569
503
      free(argfile);
570
504
      argfile = strdup(arg);
571
 
      break;
 
505
      if(argfile == NULL){
 
506
        perror("strdup");
 
507
      }
 
508
      break;      
572
509
    case 130:                   /* --userid */
573
510
    case 131:                   /* --groupid */
574
511
    case 132:                   /* --debug */
575
 
    case '?':                   /* --help */
576
 
    case -3:                    /* --usage */
577
 
    case 'V':                   /* --version */
578
512
    case ARGP_KEY_ARG:
 
513
    case ARGP_KEY_END:
579
514
      break;
580
515
    default:
581
516
      return ARGP_ERR_UNKNOWN;
582
517
    }
583
 
    return errno;
 
518
    return 0;
584
519
  }
585
520
  
586
521
  struct argp argp = { .options = options,
588
523
                       .args_doc = "",
589
524
                       .doc = "Mandos plugin runner -- Run plugins" };
590
525
  
591
 
  /* Parse using parse_opt_config_file() in order to get the custom
 
526
  /* Parse using the parse_opt_config_file in order to get the custom
592
527
     config file location, if any. */
593
 
  ret = argp_parse(&argp, argc, argv,
594
 
                   ARGP_IN_ORDER | ARGP_NO_EXIT | ARGP_NO_HELP,
595
 
                   NULL, NULL);
596
 
  switch(ret){
597
 
  case 0:
598
 
    break;
599
 
  case ENOMEM:
600
 
  default:
601
 
    errno = ret;
602
 
    perror("argp_parse");
603
 
    exitstatus = EX_OSERR;
604
 
    goto fallback;
605
 
  case EINVAL:
606
 
    exitstatus = EX_USAGE;
 
528
  ret = argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, NULL);
 
529
  if (ret == ARGP_ERR_UNKNOWN){
 
530
    fprintf(stderr, "Unknown error while parsing arguments\n");
 
531
    exitstatus = EXIT_FAILURE;
607
532
    goto fallback;
608
533
  }
609
534
  
611
536
  argp.parser = parse_opt;
612
537
  
613
538
  /* Open the configfile if available */
614
 
  if(argfile == NULL){
 
539
  if (argfile == NULL){
615
540
    conffp = fopen(AFILE, "r");
616
541
  } else {
617
542
    conffp = fopen(argfile, "r");
618
 
  }
 
543
  }  
619
544
  if(conffp != NULL){
620
545
    char *org_line = NULL;
621
546
    char *p, *arg, *new_arg, *line;
622
547
    size_t size = 0;
 
548
    ssize_t sret;
623
549
    const char whitespace_delims[] = " \r\t\f\v\n";
624
550
    const char comment_delim[] = "#";
625
 
    
 
551
 
626
552
    custom_argc = 1;
627
553
    custom_argv = malloc(sizeof(char*) * 2);
628
554
    if(custom_argv == NULL){
629
555
      perror("malloc");
630
 
      exitstatus = EX_OSERR;
 
556
      exitstatus = EXIT_FAILURE;
631
557
      goto fallback;
632
558
    }
633
559
    custom_argv[0] = argv[0];
634
560
    custom_argv[1] = NULL;
635
 
    
 
561
 
636
562
    /* for each line in the config file, strip whitespace and ignore
637
563
       commented text */
638
564
    while(true){
640
566
      if(sret == -1){
641
567
        break;
642
568
      }
643
 
      
 
569
 
644
570
      line = org_line;
645
571
      arg = strsep(&line, comment_delim);
646
572
      while((p = strsep(&arg, whitespace_delims)) != NULL){
650
576
        new_arg = strdup(p);
651
577
        if(new_arg == NULL){
652
578
          perror("strdup");
653
 
          exitstatus = EX_OSERR;
 
579
          exitstatus = EXIT_FAILURE;
654
580
          free(org_line);
655
581
          goto fallback;
656
582
        }
660
586
                              * ((unsigned int) custom_argc + 1));
661
587
        if(custom_argv == NULL){
662
588
          perror("realloc");
663
 
          exitstatus = EX_OSERR;
 
589
          exitstatus = EXIT_FAILURE;
664
590
          free(org_line);
665
591
          goto fallback;
666
592
        }
667
593
        custom_argv[custom_argc-1] = new_arg;
668
 
        custom_argv[custom_argc] = NULL;
 
594
        custom_argv[custom_argc] = NULL;        
669
595
      }
670
596
    }
671
 
    do {
672
 
      ret = fclose(conffp);
673
 
    } while(ret == EOF and errno == EINTR);
674
 
    if(ret == EOF){
675
 
      perror("fclose");
676
 
      exitstatus = EX_IOERR;
677
 
      goto fallback;
678
 
    }
679
597
    free(org_line);
680
598
  } else {
681
599
    /* Check for harmful errors and go to fallback. Other errors might
682
600
       not affect opening plugins */
683
 
    if(errno == EMFILE or errno == ENFILE or errno == ENOMEM){
 
601
    if (errno == EMFILE or errno == ENFILE or errno == ENOMEM){
684
602
      perror("fopen");
685
 
      exitstatus = EX_OSERR;
 
603
      exitstatus = EXIT_FAILURE;
686
604
      goto fallback;
687
605
    }
688
606
  }
689
 
  /* If there were any arguments from the configuration file, pass
690
 
     them to parser as command line arguments */
 
607
  /* If there was any arguments from configuration file,
 
608
     pass them to parser as command arguments */
691
609
  if(custom_argv != NULL){
692
 
    ret = argp_parse(&argp, custom_argc, custom_argv,
693
 
                     ARGP_IN_ORDER | ARGP_NO_EXIT | ARGP_NO_HELP,
694
 
                     NULL, NULL);
695
 
    switch(ret){
696
 
    case 0:
697
 
      break;
698
 
    case ENOMEM:
699
 
    default:
700
 
      errno = ret;
701
 
      perror("argp_parse");
702
 
      exitstatus = EX_OSERR;
703
 
      goto fallback;
704
 
    case EINVAL:
705
 
      exitstatus = EX_CONFIG;
 
610
    ret = argp_parse (&argp, custom_argc, custom_argv, ARGP_IN_ORDER,
 
611
                      0, NULL);
 
612
    if (ret == ARGP_ERR_UNKNOWN){
 
613
      fprintf(stderr, "Unknown error while parsing arguments\n");
 
614
      exitstatus = EXIT_FAILURE;
706
615
      goto fallback;
707
616
    }
708
617
  }
709
618
  
710
619
  /* Parse actual command line arguments, to let them override the
711
620
     config file */
712
 
  ret = argp_parse(&argp, argc, argv,
713
 
                   ARGP_IN_ORDER | ARGP_NO_EXIT | ARGP_NO_HELP,
714
 
                   NULL, NULL);
715
 
  switch(ret){
716
 
  case 0:
717
 
    break;
718
 
  case ENOMEM:
719
 
  default:
720
 
    errno = ret;
721
 
    perror("argp_parse");
722
 
    exitstatus = EX_OSERR;
723
 
    goto fallback;
724
 
  case EINVAL:
725
 
    exitstatus = EX_USAGE;
 
621
  ret = argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, NULL);
 
622
  if (ret == ARGP_ERR_UNKNOWN){
 
623
    fprintf(stderr, "Unknown error while parsing arguments\n");
 
624
    exitstatus = EXIT_FAILURE;
726
625
    goto fallback;
727
626
  }
728
627
  
733
632
      for(char **a = p->argv; *a != NULL; a++){
734
633
        fprintf(stderr, "\tArg: %s\n", *a);
735
634
      }
736
 
      fprintf(stderr, "...and %d environment variables\n", p->envc);
 
635
      fprintf(stderr, "...and %u environment variables\n", p->envc);
737
636
      for(char **a = p->environ; *a != NULL; a++){
738
637
        fprintf(stderr, "\t%s\n", *a);
739
638
      }
741
640
  }
742
641
  
743
642
  /* Strip permissions down to nobody */
 
643
  ret = setuid(uid);
 
644
  if (ret == -1){
 
645
    perror("setuid");
 
646
  }  
744
647
  setgid(gid);
745
 
  if(ret == -1){
 
648
  if (ret == -1){
746
649
    perror("setgid");
747
650
  }
748
 
  ret = setuid(uid);
749
 
  if(ret == -1){
750
 
    perror("setuid");
751
 
  }
752
 
  
753
 
  /* Open plugin directory with close_on_exec flag */
 
651
  
 
652
  if (plugindir == NULL){
 
653
    dir = opendir(PDIR);
 
654
  } else {
 
655
    dir = opendir(plugindir);
 
656
  }
 
657
  
 
658
  if(dir == NULL){
 
659
    perror("Could not open plugin dir");
 
660
    exitstatus = EXIT_FAILURE;
 
661
    goto fallback;
 
662
  }
 
663
  
 
664
  /* Set the FD_CLOEXEC flag on the directory, if possible */
754
665
  {
755
 
    int dir_fd = -1;
756
 
    if(plugindir == NULL){
757
 
      dir_fd = open(PDIR, O_RDONLY |
758
 
#ifdef O_CLOEXEC
759
 
                    O_CLOEXEC
760
 
#else  /* not O_CLOEXEC */
761
 
                    0
762
 
#endif  /* not O_CLOEXEC */
763
 
                    );
764
 
    } else {
765
 
      dir_fd = open(plugindir, O_RDONLY |
766
 
#ifdef O_CLOEXEC
767
 
                    O_CLOEXEC
768
 
#else  /* not O_CLOEXEC */
769
 
                    0
770
 
#endif  /* not O_CLOEXEC */
771
 
                    );
772
 
    }
773
 
    if(dir_fd == -1){
774
 
      perror("Could not open plugin dir");
775
 
      exitstatus = EX_UNAVAILABLE;
776
 
      goto fallback;
777
 
    }
778
 
    
779
 
#ifndef O_CLOEXEC
780
 
  /* Set the FD_CLOEXEC flag on the directory */
781
 
    ret = set_cloexec_flag(dir_fd);
782
 
    if(ret < 0){
783
 
      perror("set_cloexec_flag");
784
 
      TEMP_FAILURE_RETRY(close(dir_fd));
785
 
      exitstatus = EX_OSERR;
786
 
      goto fallback;
787
 
    }
788
 
#endif  /* O_CLOEXEC */
789
 
    
790
 
    dir = fdopendir(dir_fd);
791
 
    if(dir == NULL){
792
 
      perror("Could not open plugin dir");
793
 
      TEMP_FAILURE_RETRY(close(dir_fd));
794
 
      exitstatus = EX_OSERR;
795
 
      goto fallback;
 
666
    int dir_fd = dirfd(dir);
 
667
    if(dir_fd >= 0){
 
668
      ret = set_cloexec_flag(dir_fd);
 
669
      if(ret < 0){
 
670
        perror("set_cloexec_flag");
 
671
        exitstatus = EXIT_FAILURE;
 
672
        goto fallback;
 
673
      }
796
674
    }
797
675
  }
798
676
  
800
678
  
801
679
  /* Read and execute any executable in the plugin directory*/
802
680
  while(true){
803
 
    do {
804
 
      dirst = readdir(dir);
805
 
    } while(dirst == NULL and errno == EINTR);
 
681
    dirst = readdir(dir);
806
682
    
807
683
    /* All directory entries have been processed */
808
684
    if(dirst == NULL){
809
 
      if(errno == EBADF){
 
685
      if (errno == EBADF){
810
686
        perror("readdir");
811
 
        exitstatus = EX_IOERR;
 
687
        exitstatus = EXIT_FAILURE;
812
688
        goto fallback;
813
689
      }
814
690
      break;
824
700
      
825
701
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
826
702
                                           ".dpkg-old",
827
 
                                           ".dpkg-bak",
828
703
                                           ".dpkg-divert", NULL };
829
704
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
830
705
        size_t pre_len = strlen(*pre);
844
719
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
845
720
        size_t suf_len = strlen(*suf);
846
721
        if((d_name_len >= suf_len)
847
 
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
 
722
           and (strcmp((dirst->d_name)+d_name_len-suf_len, *suf)
848
723
                == 0)){
849
724
          if(debug){
850
725
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
859
734
        continue;
860
735
      }
861
736
    }
862
 
    
 
737
 
863
738
    char *filename;
864
739
    if(plugindir == NULL){
865
 
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
866
 
                                             dirst->d_name));
 
740
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
867
741
    } else {
868
 
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
869
 
                                             plugindir,
870
 
                                             dirst->d_name));
 
742
      ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
871
743
    }
872
744
    if(ret < 0){
873
745
      perror("asprintf");
874
746
      continue;
875
747
    }
876
748
    
877
 
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
878
 
    if(ret == -1){
 
749
    ret = stat(filename, &st);
 
750
    if (ret == -1){
879
751
      perror("stat");
880
752
      free(filename);
881
753
      continue;
882
754
    }
883
 
    
 
755
 
884
756
    /* Ignore non-executable files */
885
 
    if(not S_ISREG(st.st_mode)
886
 
       or (TEMP_FAILURE_RETRY(access(filename, X_OK)) != 0)){
 
757
    if (not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
887
758
      if(debug){
888
759
        fprintf(stderr, "Ignoring plugin dir entry \"%s\""
889
760
                " with bad type or mode\n", filename);
935
806
    }
936
807
    
937
808
    int pipefd[2];
938
 
    ret = (int)TEMP_FAILURE_RETRY(pipe(pipefd));
939
 
    if(ret == -1){
 
809
    ret = pipe(pipefd);
 
810
    if (ret == -1){
940
811
      perror("pipe");
941
 
      exitstatus = EX_OSERR;
 
812
      exitstatus = EXIT_FAILURE;
942
813
      goto fallback;
943
814
    }
944
815
    /* Ask OS to automatic close the pipe on exec */
945
816
    ret = set_cloexec_flag(pipefd[0]);
946
817
    if(ret < 0){
947
818
      perror("set_cloexec_flag");
948
 
      exitstatus = EX_OSERR;
 
819
      exitstatus = EXIT_FAILURE;
949
820
      goto fallback;
950
821
    }
951
822
    ret = set_cloexec_flag(pipefd[1]);
952
823
    if(ret < 0){
953
824
      perror("set_cloexec_flag");
954
 
      exitstatus = EX_OSERR;
 
825
      exitstatus = EXIT_FAILURE;
955
826
      goto fallback;
956
827
    }
957
828
    /* Block SIGCHLD until process is safely in process list */
958
 
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
959
 
                                              &sigchld_action.sa_mask,
960
 
                                              NULL));
 
829
    ret = sigprocmask (SIG_BLOCK, &sigchld_action.sa_mask, NULL);
961
830
    if(ret < 0){
962
831
      perror("sigprocmask");
963
 
      exitstatus = EX_OSERR;
 
832
      exitstatus = EXIT_FAILURE;
964
833
      goto fallback;
965
834
    }
966
835
    /* Starting a new process to be watched */
967
 
    pid_t pid;
968
 
    do {
969
 
      pid = fork();
970
 
    } while(pid == -1 and errno == EINTR);
 
836
    pid_t pid = fork();
971
837
    if(pid == -1){
972
838
      perror("fork");
973
 
      exitstatus = EX_OSERR;
 
839
      exitstatus = EXIT_FAILURE;
974
840
      goto fallback;
975
841
    }
976
842
    if(pid == 0){
978
844
      ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
979
845
      if(ret < 0){
980
846
        perror("sigaction");
981
 
        _exit(EX_OSERR);
 
847
        _exit(EXIT_FAILURE);
982
848
      }
983
849
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
984
850
      if(ret < 0){
985
851
        perror("sigprocmask");
986
 
        _exit(EX_OSERR);
 
852
        _exit(EXIT_FAILURE);
987
853
      }
988
854
      
989
855
      ret = dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
990
856
      if(ret == -1){
991
857
        perror("dup2");
992
 
        _exit(EX_OSERR);
 
858
        _exit(EXIT_FAILURE);
993
859
      }
994
860
      
995
861
      if(dirfd(dir) < 0){
1000
866
      if(p->environ[0] == NULL){
1001
867
        if(execv(filename, p->argv) < 0){
1002
868
          perror("execv");
1003
 
          _exit(EX_OSERR);
 
869
          _exit(EXIT_FAILURE);
1004
870
        }
1005
871
      } else {
1006
872
        if(execve(filename, p->argv, p->environ) < 0){
1007
873
          perror("execve");
1008
 
          _exit(EX_OSERR);
 
874
          _exit(EXIT_FAILURE);
1009
875
        }
1010
876
      }
1011
877
      /* no return */
1012
878
    }
1013
879
    /* Parent process */
1014
 
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
1015
 
                                             pipe */
 
880
    close(pipefd[1]);           /* Close unused write end of pipe */
1016
881
    free(filename);
1017
882
    plugin *new_plugin = getplugin(dirst->d_name);
1018
 
    if(new_plugin == NULL){
 
883
    if (new_plugin == NULL){
1019
884
      perror("getplugin");
1020
 
      ret = (int)(TEMP_FAILURE_RETRY
1021
 
                  (sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
1022
 
                               NULL)));
 
885
      ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
1023
886
      if(ret < 0){
1024
887
        perror("sigprocmask");
1025
888
      }
1026
 
      exitstatus = EX_OSERR;
 
889
      exitstatus = EXIT_FAILURE;
1027
890
      goto fallback;
1028
891
    }
1029
892
    
1032
895
    
1033
896
    /* Unblock SIGCHLD so signal handler can be run if this process
1034
897
       has already completed */
1035
 
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
1036
 
                                              &sigchld_action.sa_mask,
1037
 
                                              NULL));
 
898
    ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
1038
899
    if(ret < 0){
1039
900
      perror("sigprocmask");
1040
 
      exitstatus = EX_OSERR;
 
901
      exitstatus = EXIT_FAILURE;
1041
902
      goto fallback;
1042
903
    }
1043
904
    
1044
 
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
1045
 
                                          -Wconversion */
 
905
    FD_SET(new_plugin->fd, &rfds_all);
1046
906
    
1047
 
    if(maxfd < new_plugin->fd){
 
907
    if (maxfd < new_plugin->fd){
1048
908
      maxfd = new_plugin->fd;
1049
909
    }
1050
910
  }
1051
911
  
1052
 
  TEMP_FAILURE_RETRY(closedir(dir));
 
912
  closedir(dir);
1053
913
  dir = NULL;
1054
 
  free_plugin(getplugin(NULL));
1055
914
  
1056
915
  for(plugin *p = plugin_list; p != NULL; p = p->next){
1057
916
    if(p->pid != 0){
1068
927
  while(plugin_list){
1069
928
    fd_set rfds = rfds_all;
1070
929
    int select_ret = select(maxfd+1, &rfds, NULL, NULL, NULL);
1071
 
    if(select_ret == -1 and errno != EINTR){
 
930
    if (select_ret == -1){
1072
931
      perror("select");
1073
 
      exitstatus = EX_OSERR;
 
932
      exitstatus = EXIT_FAILURE;
1074
933
      goto fallback;
1075
934
    }
1076
935
    /* OK, now either a process completed, or something can be read
1077
936
       from one of them */
1078
937
    for(plugin *proc = plugin_list; proc != NULL;){
1079
938
      /* Is this process completely done? */
1080
 
      if(proc->completed and proc->eof){
 
939
      if(proc->eof and proc->completed){
1081
940
        /* Only accept the plugin output if it exited cleanly */
1082
941
        if(not WIFEXITED(proc->status)
1083
942
           or WEXITSTATUS(proc->status) != 0){
1084
943
          /* Bad exit by plugin */
1085
 
          
 
944
 
1086
945
          if(debug){
1087
946
            if(WIFEXITED(proc->status)){
1088
 
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
1089
 
                      " status %d\n", proc->name,
1090
 
                      (intmax_t) (proc->pid),
 
947
              fprintf(stderr, "Plugin %u exited with status %d\n",
 
948
                      (unsigned int) (proc->pid),
1091
949
                      WEXITSTATUS(proc->status));
1092
 
            } else if(WIFSIGNALED(proc->status)){
1093
 
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
1094
 
                      " signal %d: %s\n", proc->name,
1095
 
                      (intmax_t) (proc->pid),
1096
 
                      WTERMSIG(proc->status),
1097
 
                      strsignal(WTERMSIG(proc->status)));
 
950
            } else if(WIFSIGNALED(proc->status)) {
 
951
              fprintf(stderr, "Plugin %u killed by signal %d\n",
 
952
                      (unsigned int) (proc->pid),
 
953
                      WTERMSIG(proc->status));
1098
954
            } else if(WCOREDUMP(proc->status)){
1099
 
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
1100
 
                      " core\n", proc->name, (intmax_t) (proc->pid));
 
955
              fprintf(stderr, "Plugin %d dumped core\n",
 
956
                      (unsigned int) (proc->pid));
1101
957
            }
1102
958
          }
1103
959
          
1104
960
          /* Remove the plugin */
1105
 
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
1106
 
                                          -Wconversion */
1107
 
          
 
961
          FD_CLR(proc->fd, &rfds_all);
 
962
 
1108
963
          /* Block signal while modifying process_list */
1109
 
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1110
 
                                        (SIG_BLOCK,
1111
 
                                         &sigchld_action.sa_mask,
1112
 
                                         NULL));
 
964
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
1113
965
          if(ret < 0){
1114
966
            perror("sigprocmask");
1115
 
            exitstatus = EX_OSERR;
 
967
            exitstatus = EXIT_FAILURE;
1116
968
            goto fallback;
1117
969
          }
1118
970
          
1121
973
          proc = next_plugin;
1122
974
          
1123
975
          /* We are done modifying process list, so unblock signal */
1124
 
          ret = (int)(TEMP_FAILURE_RETRY
1125
 
                      (sigprocmask(SIG_UNBLOCK,
1126
 
                                   &sigchld_action.sa_mask, NULL)));
 
976
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
 
977
                             NULL);
1127
978
          if(ret < 0){
1128
979
            perror("sigprocmask");
1129
 
            exitstatus = EX_OSERR;
 
980
            exitstatus = EXIT_FAILURE;
1130
981
            goto fallback;
1131
982
          }
1132
983
          
1143
994
                                       proc->buffer_length);
1144
995
        if(not bret){
1145
996
          perror("print_out_password");
1146
 
          exitstatus = EX_IOERR;
 
997
          exitstatus = EXIT_FAILURE;
1147
998
        }
1148
999
        goto fallback;
1149
1000
      }
1150
1001
      
1151
1002
      /* This process has not completed.  Does it have any output? */
1152
 
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
1153
 
                                                         warning from
1154
 
                                                         -Wconversion */
 
1003
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1155
1004
        /* This process had nothing to say at this time */
1156
1005
        proc = proc->next;
1157
1006
        continue;
1160
1009
      if(proc->buffer_length + BUFFER_SIZE > proc->buffer_size){
1161
1010
        proc->buffer = realloc(proc->buffer, proc->buffer_size
1162
1011
                               + (size_t) BUFFER_SIZE);
1163
 
        if(proc->buffer == NULL){
 
1012
        if (proc->buffer == NULL){
1164
1013
          perror("malloc");
1165
 
          exitstatus = EX_OSERR;
 
1014
          exitstatus = EXIT_FAILURE;
1166
1015
          goto fallback;
1167
1016
        }
1168
1017
        proc->buffer_size += BUFFER_SIZE;
1169
1018
      }
1170
1019
      /* Read from the process */
1171
 
      sret = TEMP_FAILURE_RETRY(read(proc->fd,
1172
 
                                     proc->buffer
1173
 
                                     + proc->buffer_length,
1174
 
                                     BUFFER_SIZE));
1175
 
      if(sret < 0){
 
1020
      ret = read(proc->fd, proc->buffer + proc->buffer_length,
 
1021
                 BUFFER_SIZE);
 
1022
      if(ret < 0){
1176
1023
        /* Read error from this process; ignore the error */
1177
1024
        proc = proc->next;
1178
1025
        continue;
1179
1026
      }
1180
 
      if(sret == 0){
 
1027
      if(ret == 0){
1181
1028
        /* got EOF */
1182
1029
        proc->eof = true;
1183
1030
      } else {
1184
 
        proc->buffer_length += (size_t) sret;
 
1031
        proc->buffer_length += (size_t) ret;
1185
1032
      }
1186
1033
    }
1187
1034
  }
1188
 
  
1189
 
  
 
1035
 
 
1036
 
1190
1037
 fallback:
1191
1038
  
1192
 
  if(plugin_list == NULL or (exitstatus != EXIT_SUCCESS
1193
 
                             and exitstatus != EX_OK)){
 
1039
  if(plugin_list == NULL or exitstatus != EXIT_SUCCESS){
1194
1040
    /* Fallback if all plugins failed, none are found or an error
1195
1041
       occured */
1196
1042
    bool bret;
1205
1051
    bret = print_out_password(passwordbuffer, len);
1206
1052
    if(not bret){
1207
1053
      perror("print_out_password");
1208
 
      exitstatus = EX_IOERR;
 
1054
      exitstatus = EXIT_FAILURE;
1209
1055
    }
1210
1056
  }
1211
1057
  
1213
1059
  ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
1214
1060
  if(ret == -1){
1215
1061
    perror("sigaction");
1216
 
    exitstatus = EX_OSERR;
 
1062
    exitstatus = EXIT_FAILURE;
1217
1063
  }
1218
1064
  
1219
1065
  if(custom_argv != NULL){
1240
1086
  }
1241
1087
  
1242
1088
  /* Wait for any remaining child processes to terminate */
1243
 
  do {
 
1089
  do{
1244
1090
    ret = wait(NULL);
1245
1091
  } while(ret >= 0);
1246
1092
  if(errno != ECHILD){