/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: 2014-03-10 07:04:09 UTC
  • Revision ID: teddy@recompile.se-20140310070409-ho6p1wrnpopi2ny1
White space fix: change "if (" to "if(" in C code.

* plugins.d/askpass-fifo.c (error_plus): White space fix.
* plugins.d/password-prompt.c (error_plus, conflict_detection,
                               main): - '' -
* plugins.d/plymouth.c (error_plus, exec_and_wait, get_pid): - '' -
* plugins.d/splashy.c (error_plus): - '' -
* plugins.d/usplash.c (error_plus): - '' -

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(),
26
 
                                   asprintf() */
 
26
                                   asprintf(), O_CLOEXEC */
27
27
#include <stddef.h>             /* size_t, NULL */
28
 
#include <stdlib.h>             /* malloc(), exit(), EXIT_FAILURE,
29
 
                                   EXIT_SUCCESS, realloc() */
 
28
#include <stdlib.h>             /* malloc(), exit(), EXIT_SUCCESS,
 
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
 
#include <sys/types.h>          /* DIR, opendir(), stat(), struct
 
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(),
42
42
                                   WCOREDUMP() */
43
43
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
44
44
#include <iso646.h>             /* and, or, not */
45
 
#include <dirent.h>             /* DIR, struct dirent, opendir(),
 
45
#include <dirent.h>             /* DIR, struct dirent, fdopendir(),
46
46
                                   readdir(), closedir(), dirfd() */
47
47
#include <unistd.h>             /* struct stat, stat(), S_ISREG(),
48
48
                                   fcntl(), setuid(), setgid(),
68
68
                                */
69
69
#include <errno.h>              /* errno, EBADF */
70
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
#include <errno.h>              /* errno */
 
74
#include <error.h>              /* error() */
71
75
 
72
76
#define BUFFER_SIZE 256
73
77
 
75
79
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
76
80
 
77
81
const char *argp_program_version = "plugin-runner " VERSION;
78
 
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
 
82
const char *argp_program_bug_address = "<mandos@recompile.se>";
79
83
 
80
84
typedef struct plugin{
81
85
  char *name;                   /* can be NULL or any plugin name */
102
106
/* Gets an existing plugin based on name,
103
107
   or if none is found, creates a new one */
104
108
static plugin *getplugin(char *name){
105
 
  /* Check for exiting plugin with that name */
 
109
  /* Check for existing plugin with that name */
106
110
  for(plugin *p = plugin_list; p != NULL; p = p->next){
107
111
    if((p->name == name)
108
112
       or (p->name and name and (strcmp(p->name, name) == 0))){
123
127
      copy_name = strdup(name);
124
128
    } while(copy_name == NULL and errno == EINTR);
125
129
    if(copy_name == NULL){
 
130
      int e = errno;
126
131
      free(new_plugin);
 
132
      errno = e;
127
133
      return NULL;
128
134
    }
129
135
  }
137
143
    new_plugin->argv = malloc(sizeof(char *) * 2);
138
144
  } while(new_plugin->argv == NULL and errno == EINTR);
139
145
  if(new_plugin->argv == NULL){
 
146
    int e = errno;
140
147
    free(copy_name);
141
148
    free(new_plugin);
 
149
    errno = e;
142
150
    return NULL;
143
151
  }
144
152
  new_plugin->argv[0] = copy_name;
148
156
    new_plugin->environ = malloc(sizeof(char *));
149
157
  } while(new_plugin->environ == NULL and errno == EINTR);
150
158
  if(new_plugin->environ == NULL){
 
159
    int e = errno;
151
160
    free(copy_name);
152
161
    free(new_plugin->argv);
153
162
    free(new_plugin);
 
163
    errno = e;
154
164
    return NULL;
155
165
  }
156
166
  new_plugin->environ[0] = NULL;
161
171
}
162
172
 
163
173
/* Helper function for add_argument and add_environment */
 
174
__attribute__((nonnull))
164
175
static bool add_to_char_array(const char *new, char ***array,
165
176
                              int *len){
166
177
  /* Resize the pointed-to array to hold one more pointer */
 
178
  char **new_array = NULL;
167
179
  do {
168
 
    *array = realloc(*array, sizeof(char *)
169
 
                     * (size_t) ((*len) + 2));
170
 
  } while(*array == NULL and errno == EINTR);
 
180
    new_array = realloc(*array, sizeof(char *)
 
181
                        * (size_t) ((*len) + 2));
 
182
  } while(new_array == NULL and errno == EINTR);
171
183
  /* Malloc check */
172
 
  if(*array == NULL){
 
184
  if(new_array == NULL){
173
185
    return false;
174
186
  }
 
187
  *array = new_array;
175
188
  /* Make a copy of the new string */
176
189
  char *copy;
177
190
  do {
189
202
}
190
203
 
191
204
/* Add to a plugin's argument vector */
 
205
__attribute__((nonnull(2)))
192
206
static bool add_argument(plugin *p, const char *arg){
193
207
  if(p == NULL){
194
208
    return false;
197
211
}
198
212
 
199
213
/* Add to a plugin's environment */
 
214
__attribute__((nonnull(2)))
200
215
static bool add_environment(plugin *p, const char *def, bool replace){
201
216
  if(p == NULL){
202
217
    return false;
204
219
  /* namelen = length of name of environment variable */
205
220
  size_t namelen = (size_t)(strchrnul(def, '=') - def);
206
221
  /* Search for this environment variable */
207
 
  for(char **e = p->environ; *e != NULL; e++){
208
 
    if(strncmp(*e, def, namelen + 1) == 0){
 
222
  for(char **envdef = p->environ; *envdef != NULL; envdef++){
 
223
    if(strncmp(*envdef, def, namelen + 1) == 0){
209
224
      /* It already exists */
210
225
      if(replace){
211
 
        char *new;
 
226
        char *new_envdef;
212
227
        do {
213
 
          new = realloc(*e, strlen(def) + 1);
214
 
        } while(new == NULL and errno == EINTR);
215
 
        if(new == NULL){
 
228
          new_envdef = realloc(*envdef, strlen(def) + 1);
 
229
        } while(new_envdef == NULL and errno == EINTR);
 
230
        if(new_envdef == NULL){
216
231
          return false;
217
232
        }
218
 
        *e = new;
219
 
        strcpy(*e, def);
 
233
        *envdef = new_envdef;
 
234
        strcpy(*envdef, def);
220
235
      }
221
236
      return true;
222
237
    }
230
245
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
231
246
 */
232
247
static int set_cloexec_flag(int fd){
233
 
  int ret = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
 
248
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
234
249
  /* If reading the flags failed, return error indication now. */
235
250
  if(ret < 0){
236
251
    return ret;
237
252
  }
238
253
  /* Store modified flag word in the descriptor. */
239
 
  return TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, ret | FD_CLOEXEC));
 
254
  return (int)TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD,
 
255
                                       ret | FD_CLOEXEC));
240
256
}
241
257
 
242
258
 
257
273
        /* No child processes */
258
274
        break;
259
275
      }
260
 
      perror("waitpid");
 
276
      error(0, errno, "waitpid");
261
277
    }
262
278
    
263
279
    /* A child exited, find it in process_list */
275
291
}
276
292
 
277
293
/* Prints out a password to stdout */
 
294
__attribute__((nonnull))
278
295
static bool print_out_password(const char *buffer, size_t length){
279
296
  ssize_t ret;
280
297
  for(size_t written = 0; written < length; written += (size_t)ret){
288
305
}
289
306
 
290
307
/* Removes and free a plugin from the plugin list */
 
308
__attribute__((nonnull))
291
309
static void free_plugin(plugin *plugin_node){
292
310
  
293
311
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
348
366
  sigemptyset(&sigchld_action.sa_mask);
349
367
  ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
350
368
  if(ret == -1){
351
 
    perror("sigaddset");
352
 
    exitstatus = EXIT_FAILURE;
 
369
    error(0, errno, "sigaddset");
 
370
    exitstatus = EX_OSERR;
353
371
    goto fallback;
354
372
  }
355
373
  ret = sigaction(SIGCHLD, &sigchld_action, &old_sigchld_action);
356
374
  if(ret == -1){
357
 
    perror("sigaction");
358
 
    exitstatus = EXIT_FAILURE;
 
375
    error(0, errno, "sigaction");
 
376
    exitstatus = EX_OSERR;
359
377
    goto fallback;
360
378
  }
361
379
  
393
411
      .doc = "Group ID the plugins will run as", .group = 3 },
394
412
    { .name = "debug", .key = 132,
395
413
      .doc = "Debug mode", .group = 4 },
 
414
    /*
 
415
     * These reproduce what we would get without ARGP_NO_HELP
 
416
     */
 
417
    { .name = "help", .key = '?',
 
418
      .doc = "Give this help list", .group = -1 },
 
419
    { .name = "usage", .key = -3,
 
420
      .doc = "Give a short usage message", .group = -1 },
 
421
    { .name = "version", .key = 'V',
 
422
      .doc = "Print program version", .group = -1 },
396
423
    { .name = NULL }
397
424
  };
398
425
  
399
 
  error_t parse_opt(int key, char *arg, __attribute__((unused))
400
 
                    struct argp_state *state){
 
426
  __attribute__((nonnull(3)))
 
427
  error_t parse_opt(int key, char *arg, struct argp_state *state){
 
428
    errno = 0;
401
429
    switch(key){
402
430
      char *tmp;
403
 
      intmax_t tmpmax;
 
431
      intmax_t tmp_id;
404
432
    case 'g':                   /* --global-options */
405
 
      if(arg != NULL){
 
433
      {
406
434
        char *plugin_option;
407
435
        while((plugin_option = strsep(&arg, ",")) != NULL){
408
 
          if(plugin_option[0] == '\0'){
409
 
            continue;
410
 
          }
411
436
          if(not add_argument(getplugin(NULL), plugin_option)){
412
 
            perror("add_argument");
413
 
            return ARGP_ERR_UNKNOWN;
 
437
            break;
414
438
          }
415
439
        }
416
440
      }
417
441
      break;
418
442
    case 'G':                   /* --global-env */
419
 
      if(arg == NULL){
420
 
        break;
421
 
      }
422
 
      if(not add_environment(getplugin(NULL), arg, true)){
423
 
        perror("add_environment");
424
 
      }
 
443
      add_environment(getplugin(NULL), arg, true);
425
444
      break;
426
445
    case 'o':                   /* --options-for */
427
 
      if(arg != NULL){
428
 
        char *plugin_name = strsep(&arg, ":");
429
 
        if(plugin_name[0] == '\0'){
430
 
          break;
431
 
        }
432
 
        char *plugin_option;
433
 
        while((plugin_option = strsep(&arg, ",")) != NULL){
434
 
          if(not add_argument(getplugin(plugin_name), plugin_option)){
435
 
            perror("add_argument");
436
 
            return ARGP_ERR_UNKNOWN;
 
446
      {
 
447
        char *option_list = strchr(arg, ':');
 
448
        if(option_list == NULL){
 
449
          argp_error(state, "No colon in \"%s\"", arg);
 
450
          errno = EINVAL;
 
451
          break;
 
452
        }
 
453
        *option_list = '\0';
 
454
        option_list++;
 
455
        if(arg[0] == '\0'){
 
456
          argp_error(state, "Empty plugin name");
 
457
          errno = EINVAL;
 
458
          break;
 
459
        }
 
460
        char *option;
 
461
        while((option = strsep(&option_list, ",")) != NULL){
 
462
          if(not add_argument(getplugin(arg), option)){
 
463
            break;
437
464
          }
438
465
        }
439
466
      }
440
467
      break;
441
468
    case 'E':                   /* --env-for */
442
 
      if(arg == NULL){
443
 
        break;
444
 
      }
445
469
      {
446
470
        char *envdef = strchr(arg, ':');
447
471
        if(envdef == NULL){
 
472
          argp_error(state, "No colon in \"%s\"", arg);
 
473
          errno = EINVAL;
448
474
          break;
449
475
        }
450
476
        *envdef = '\0';
451
 
        if(not add_environment(getplugin(arg), envdef+1, true)){
452
 
          perror("add_environment");
 
477
        envdef++;
 
478
        if(arg[0] == '\0'){
 
479
          argp_error(state, "Empty plugin name");
 
480
          errno = EINVAL;
 
481
          break;
453
482
        }
 
483
        add_environment(getplugin(arg), envdef, true);
454
484
      }
455
485
      break;
456
486
    case 'd':                   /* --disable */
457
 
      if(arg != NULL){
 
487
      {
458
488
        plugin *p = getplugin(arg);
459
 
        if(p == NULL){
460
 
          return ARGP_ERR_UNKNOWN;
 
489
        if(p != NULL){
 
490
          p->disabled = true;
461
491
        }
462
 
        p->disabled = true;
463
492
      }
464
493
      break;
465
494
    case 'e':                   /* --enable */
466
 
      if(arg != NULL){
 
495
      {
467
496
        plugin *p = getplugin(arg);
468
 
        if(p == NULL){
469
 
          return ARGP_ERR_UNKNOWN;
 
497
        if(p != NULL){
 
498
          p->disabled = false;
470
499
        }
471
 
        p->disabled = false;
472
500
      }
473
501
      break;
474
502
    case 128:                   /* --plugin-dir */
475
503
      free(plugindir);
476
504
      plugindir = strdup(arg);
477
 
      if(plugindir == NULL){
478
 
        perror("strdup");
479
 
      }
480
505
      break;
481
506
    case 129:                   /* --config-file */
482
507
      /* This is already done by parse_opt_config_file() */
483
508
      break;
484
509
    case 130:                   /* --userid */
485
 
      errno = 0;
486
 
      tmpmax = strtoimax(arg, &tmp, 10);
 
510
      tmp_id = strtoimax(arg, &tmp, 10);
487
511
      if(errno != 0 or tmp == arg or *tmp != '\0'
488
 
         or tmpmax != (uid_t)tmpmax){
489
 
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
490
 
                PRIdMAX "\n", arg, (intmax_t)uid);
491
 
      } else {
492
 
        uid = (uid_t)tmpmax;
 
512
         or tmp_id != (uid_t)tmp_id){
 
513
        argp_error(state, "Bad user ID number: \"%s\", using %"
 
514
                   PRIdMAX, arg, (intmax_t)uid);
 
515
        break;
493
516
      }
 
517
      uid = (uid_t)tmp_id;
494
518
      break;
495
519
    case 131:                   /* --groupid */
496
 
      errno = 0;
497
 
      tmpmax = strtoimax(arg, &tmp, 10);
 
520
      tmp_id = strtoimax(arg, &tmp, 10);
498
521
      if(errno != 0 or tmp == arg or *tmp != '\0'
499
 
         or tmpmax != (gid_t)tmpmax){
500
 
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
501
 
                PRIdMAX "\n", arg, (intmax_t)gid);
502
 
      } else {
503
 
        gid = (gid_t)tmpmax;
 
522
         or tmp_id != (gid_t)tmp_id){
 
523
        argp_error(state, "Bad group ID number: \"%s\", using %"
 
524
                   PRIdMAX, arg, (intmax_t)gid);
 
525
        break;
504
526
      }
 
527
      gid = (gid_t)tmp_id;
505
528
      break;
506
529
    case 132:                   /* --debug */
507
530
      debug = true;
508
531
      break;
 
532
      /*
 
533
       * These reproduce what we would get without ARGP_NO_HELP
 
534
       */
 
535
    case '?':                   /* --help */
 
536
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
 
537
      argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
 
538
    case -3:                    /* --usage */
 
539
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
 
540
      argp_state_help(state, state->out_stream,
 
541
                      ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
 
542
    case 'V':                   /* --version */
 
543
      fprintf(state->out_stream, "%s\n", argp_program_version);
 
544
      exit(EXIT_SUCCESS);
 
545
      break;
509
546
/*
510
547
 * When adding more options before this line, remember to also add a
511
548
 * "case" to the "parse_opt_config_file" function below.
514
551
      /* Cryptsetup always passes an argument, which is an empty
515
552
         string if "none" was specified in /etc/crypttab.  So if
516
553
         argument was empty, we ignore it silently. */
517
 
      if(arg[0] != '\0'){
518
 
        fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
 
554
      if(arg[0] == '\0'){
 
555
        break;
519
556
      }
520
 
      break;
521
 
    case ARGP_KEY_END:
522
 
      break;
523
557
    default:
524
558
      return ARGP_ERR_UNKNOWN;
525
559
    }
526
 
    return 0;
 
560
    return errno;               /* Set to 0 at start */
527
561
  }
528
562
  
529
563
  /* This option parser is the same as parse_opt() above, except it
531
565
  error_t parse_opt_config_file(int key, char *arg,
532
566
                                __attribute__((unused))
533
567
                                struct argp_state *state){
 
568
    errno = 0;
534
569
    switch(key){
535
570
    case 'g':                   /* --global-options */
536
571
    case 'G':                   /* --global-env */
543
578
    case 129:                   /* --config-file */
544
579
      free(argfile);
545
580
      argfile = strdup(arg);
546
 
      if(argfile == NULL){
547
 
        perror("strdup");
548
 
      }
549
581
      break;
550
582
    case 130:                   /* --userid */
551
583
    case 131:                   /* --groupid */
552
584
    case 132:                   /* --debug */
 
585
    case '?':                   /* --help */
 
586
    case -3:                    /* --usage */
 
587
    case 'V':                   /* --version */
553
588
    case ARGP_KEY_ARG:
554
 
    case ARGP_KEY_END:
555
589
      break;
556
590
    default:
557
591
      return ARGP_ERR_UNKNOWN;
558
592
    }
559
 
    return 0;
 
593
    return errno;
560
594
  }
561
595
  
562
596
  struct argp argp = { .options = options,
566
600
  
567
601
  /* Parse using parse_opt_config_file() in order to get the custom
568
602
     config file location, if any. */
569
 
  ret = argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, NULL);
570
 
  if(ret == ARGP_ERR_UNKNOWN){
571
 
    fprintf(stderr, "Unknown error while parsing arguments\n");
572
 
    exitstatus = EXIT_FAILURE;
 
603
  ret = argp_parse(&argp, argc, argv,
 
604
                   ARGP_IN_ORDER | ARGP_NO_EXIT | ARGP_NO_HELP,
 
605
                   NULL, NULL);
 
606
  switch(ret){
 
607
  case 0:
 
608
    break;
 
609
  case ENOMEM:
 
610
  default:
 
611
    errno = ret;
 
612
    error(0, errno, "argp_parse");
 
613
    exitstatus = EX_OSERR;
 
614
    goto fallback;
 
615
  case EINVAL:
 
616
    exitstatus = EX_USAGE;
573
617
    goto fallback;
574
618
  }
575
619
  
592
636
    custom_argc = 1;
593
637
    custom_argv = malloc(sizeof(char*) * 2);
594
638
    if(custom_argv == NULL){
595
 
      perror("malloc");
596
 
      exitstatus = EXIT_FAILURE;
 
639
      error(0, errno, "malloc");
 
640
      exitstatus = EX_OSERR;
597
641
      goto fallback;
598
642
    }
599
643
    custom_argv[0] = argv[0];
615
659
        }
616
660
        new_arg = strdup(p);
617
661
        if(new_arg == NULL){
618
 
          perror("strdup");
619
 
          exitstatus = EXIT_FAILURE;
 
662
          error(0, errno, "strdup");
 
663
          exitstatus = EX_OSERR;
620
664
          free(org_line);
621
665
          goto fallback;
622
666
        }
623
667
        
624
668
        custom_argc += 1;
625
 
        custom_argv = realloc(custom_argv, sizeof(char *)
626
 
                              * ((unsigned int) custom_argc + 1));
627
 
        if(custom_argv == NULL){
628
 
          perror("realloc");
629
 
          exitstatus = EXIT_FAILURE;
630
 
          free(org_line);
631
 
          goto fallback;
 
669
        {
 
670
          char **new_argv = realloc(custom_argv, sizeof(char *)
 
671
                                    * ((unsigned int)
 
672
                                       custom_argc + 1));
 
673
          if(new_argv == NULL){
 
674
            error(0, errno, "realloc");
 
675
            exitstatus = EX_OSERR;
 
676
            free(new_arg);
 
677
            free(org_line);
 
678
            goto fallback;
 
679
          } else {
 
680
            custom_argv = new_argv;
 
681
          }
632
682
        }
633
683
        custom_argv[custom_argc-1] = new_arg;
634
684
        custom_argv[custom_argc] = NULL;
638
688
      ret = fclose(conffp);
639
689
    } while(ret == EOF and errno == EINTR);
640
690
    if(ret == EOF){
641
 
      perror("fclose");
642
 
      exitstatus = EXIT_FAILURE;
 
691
      error(0, errno, "fclose");
 
692
      exitstatus = EX_IOERR;
643
693
      goto fallback;
644
694
    }
645
695
    free(org_line);
647
697
    /* Check for harmful errors and go to fallback. Other errors might
648
698
       not affect opening plugins */
649
699
    if(errno == EMFILE or errno == ENFILE or errno == ENOMEM){
650
 
      perror("fopen");
651
 
      exitstatus = EXIT_FAILURE;
 
700
      error(0, errno, "fopen");
 
701
      exitstatus = EX_OSERR;
652
702
      goto fallback;
653
703
    }
654
704
  }
655
 
  /* If there was any arguments from configuration file,
656
 
     pass them to parser as command arguments */
 
705
  /* If there were any arguments from the configuration file, pass
 
706
     them to parser as command line arguments */
657
707
  if(custom_argv != NULL){
658
 
    ret = argp_parse(&argp, custom_argc, custom_argv, ARGP_IN_ORDER,
659
 
                     0, NULL);
660
 
    if(ret == ARGP_ERR_UNKNOWN){
661
 
      fprintf(stderr, "Unknown error while parsing arguments\n");
662
 
      exitstatus = EXIT_FAILURE;
 
708
    ret = argp_parse(&argp, custom_argc, custom_argv,
 
709
                     ARGP_IN_ORDER | ARGP_NO_EXIT | ARGP_NO_HELP,
 
710
                     NULL, NULL);
 
711
    switch(ret){
 
712
    case 0:
 
713
      break;
 
714
    case ENOMEM:
 
715
    default:
 
716
      errno = ret;
 
717
      error(0, errno, "argp_parse");
 
718
      exitstatus = EX_OSERR;
 
719
      goto fallback;
 
720
    case EINVAL:
 
721
      exitstatus = EX_CONFIG;
663
722
      goto fallback;
664
723
    }
665
724
  }
666
725
  
667
726
  /* Parse actual command line arguments, to let them override the
668
727
     config file */
669
 
  ret = argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, NULL);
670
 
  if(ret == ARGP_ERR_UNKNOWN){
671
 
    fprintf(stderr, "Unknown error while parsing arguments\n");
672
 
    exitstatus = EXIT_FAILURE;
 
728
  ret = argp_parse(&argp, argc, argv,
 
729
                   ARGP_IN_ORDER | ARGP_NO_EXIT | ARGP_NO_HELP,
 
730
                   NULL, NULL);
 
731
  switch(ret){
 
732
  case 0:
 
733
    break;
 
734
  case ENOMEM:
 
735
  default:
 
736
    errno = ret;
 
737
    error(0, errno, "argp_parse");
 
738
    exitstatus = EX_OSERR;
 
739
    goto fallback;
 
740
  case EINVAL:
 
741
    exitstatus = EX_USAGE;
673
742
    goto fallback;
674
743
  }
675
744
  
687
756
    }
688
757
  }
689
758
  
690
 
  /* Strip permissions down to nobody */
691
 
  setgid(gid);
 
759
  if(getuid() == 0){
 
760
    /* Work around Debian bug #633582:
 
761
       <http://bugs.debian.org/633582> */
 
762
    int plugindir_fd = open(/* plugindir or */ PDIR, O_RDONLY);
 
763
    if(plugindir_fd == -1){
 
764
      error(0, errno, "open");
 
765
    } else {
 
766
      ret = (int)TEMP_FAILURE_RETRY(fstat(plugindir_fd, &st));
 
767
      if(ret == -1){
 
768
        error(0, errno, "fstat");
 
769
      } else {
 
770
        if(S_ISDIR(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
 
771
          ret = fchown(plugindir_fd, uid, gid);
 
772
          if(ret == -1){
 
773
            error(0, errno, "fchown");
 
774
          }
 
775
        }
 
776
      }
 
777
      TEMP_FAILURE_RETRY(close(plugindir_fd));
 
778
    }
 
779
  }
 
780
  
 
781
  /* Lower permissions */
 
782
  ret = setgid(gid);
692
783
  if(ret == -1){
693
 
    perror("setgid");
 
784
    error(0, errno, "setgid");
694
785
  }
695
786
  ret = setuid(uid);
696
787
  if(ret == -1){
697
 
    perror("setuid");
698
 
  }
699
 
  
700
 
  if(plugindir == NULL){
701
 
    dir = opendir(PDIR);
702
 
  } else {
703
 
    dir = opendir(plugindir);
704
 
  }
705
 
  
706
 
  if(dir == NULL){
707
 
    perror("Could not open plugin dir");
708
 
    exitstatus = EXIT_FAILURE;
709
 
    goto fallback;
710
 
  }
711
 
  
712
 
  /* Set the FD_CLOEXEC flag on the directory, if possible */
 
788
    error(0, errno, "setuid");
 
789
  }
 
790
  
 
791
  /* Open plugin directory with close_on_exec flag */
713
792
  {
714
 
    int dir_fd = dirfd(dir);
715
 
    if(dir_fd >= 0){
716
 
      ret = set_cloexec_flag(dir_fd);
717
 
      if(ret < 0){
718
 
        perror("set_cloexec_flag");
719
 
        exitstatus = EXIT_FAILURE;
720
 
        goto fallback;
721
 
      }
 
793
    int dir_fd = -1;
 
794
    if(plugindir == NULL){
 
795
      dir_fd = open(PDIR, O_RDONLY |
 
796
#ifdef O_CLOEXEC
 
797
                    O_CLOEXEC
 
798
#else  /* not O_CLOEXEC */
 
799
                    0
 
800
#endif  /* not O_CLOEXEC */
 
801
                    );
 
802
    } else {
 
803
      dir_fd = open(plugindir, O_RDONLY |
 
804
#ifdef O_CLOEXEC
 
805
                    O_CLOEXEC
 
806
#else  /* not O_CLOEXEC */
 
807
                    0
 
808
#endif  /* not O_CLOEXEC */
 
809
                    );
 
810
    }
 
811
    if(dir_fd == -1){
 
812
      error(0, errno, "Could not open plugin dir");
 
813
      exitstatus = EX_UNAVAILABLE;
 
814
      goto fallback;
 
815
    }
 
816
    
 
817
#ifndef O_CLOEXEC
 
818
  /* Set the FD_CLOEXEC flag on the directory */
 
819
    ret = set_cloexec_flag(dir_fd);
 
820
    if(ret < 0){
 
821
      error(0, errno, "set_cloexec_flag");
 
822
      TEMP_FAILURE_RETRY(close(dir_fd));
 
823
      exitstatus = EX_OSERR;
 
824
      goto fallback;
 
825
    }
 
826
#endif  /* O_CLOEXEC */
 
827
    
 
828
    dir = fdopendir(dir_fd);
 
829
    if(dir == NULL){
 
830
      error(0, errno, "Could not open plugin dir");
 
831
      TEMP_FAILURE_RETRY(close(dir_fd));
 
832
      exitstatus = EX_OSERR;
 
833
      goto fallback;
722
834
    }
723
835
  }
724
836
  
733
845
    /* All directory entries have been processed */
734
846
    if(dirst == NULL){
735
847
      if(errno == EBADF){
736
 
        perror("readdir");
737
 
        exitstatus = EXIT_FAILURE;
 
848
        error(0, errno, "readdir");
 
849
        exitstatus = EX_IOERR;
738
850
        goto fallback;
739
851
      }
740
852
      break;
746
858
    {
747
859
      bool bad_name = false;
748
860
      
749
 
      const char const *bad_prefixes[] = { ".", "#", NULL };
 
861
      const char * const bad_prefixes[] = { ".", "#", NULL };
750
862
      
751
 
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
 
863
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
752
864
                                           ".dpkg-old",
753
865
                                           ".dpkg-bak",
754
866
                                           ".dpkg-divert", NULL };
755
 
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
 
867
#ifdef __GNUC__
 
868
#pragma GCC diagnostic push
 
869
#pragma GCC diagnostic ignored "-Wcast-qual"
 
870
#endif
 
871
      for(const char **pre = (const char **)bad_prefixes;
 
872
          *pre != NULL; pre++){
 
873
#ifdef __GNUC__
 
874
#pragma GCC diagnostic pop
 
875
#endif
756
876
        size_t pre_len = strlen(*pre);
757
877
        if((d_name_len >= pre_len)
758
878
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
767
887
      if(bad_name){
768
888
        continue;
769
889
      }
770
 
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
 
890
#ifdef __GNUC__
 
891
#pragma GCC diagnostic push
 
892
#pragma GCC diagnostic ignored "-Wcast-qual"
 
893
#endif
 
894
      for(const char **suf = (const char **)bad_suffixes;
 
895
          *suf != NULL; suf++){
 
896
#ifdef __GNUC__
 
897
#pragma GCC diagnostic pop
 
898
#endif
771
899
        size_t suf_len = strlen(*suf);
772
900
        if((d_name_len >= suf_len)
773
901
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
788
916
    
789
917
    char *filename;
790
918
    if(plugindir == NULL){
791
 
      ret = TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
792
 
                                        dirst->d_name));
 
919
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
 
920
                                             dirst->d_name));
793
921
    } else {
794
 
      ret = TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s", plugindir,
795
 
                                        dirst->d_name));
 
922
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
 
923
                                             plugindir,
 
924
                                             dirst->d_name));
796
925
    }
797
926
    if(ret < 0){
798
 
      perror("asprintf");
 
927
      error(0, errno, "asprintf");
799
928
      continue;
800
929
    }
801
930
    
802
 
    ret = TEMP_FAILURE_RETRY(stat(filename, &st));
 
931
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
803
932
    if(ret == -1){
804
 
      perror("stat");
 
933
      error(0, errno, "stat");
805
934
      free(filename);
806
935
      continue;
807
936
    }
819
948
    
820
949
    plugin *p = getplugin(dirst->d_name);
821
950
    if(p == NULL){
822
 
      perror("getplugin");
 
951
      error(0, errno, "getplugin");
823
952
      free(filename);
824
953
      continue;
825
954
    }
837
966
      if(g != NULL){
838
967
        for(char **a = g->argv + 1; *a != NULL; a++){
839
968
          if(not add_argument(p, *a)){
840
 
            perror("add_argument");
 
969
            error(0, errno, "add_argument");
841
970
          }
842
971
        }
843
972
        /* Add global environment variables */
844
973
        for(char **e = g->environ; *e != NULL; e++){
845
974
          if(not add_environment(p, *e, false)){
846
 
            perror("add_environment");
 
975
            error(0, errno, "add_environment");
847
976
          }
848
977
        }
849
978
      }
854
983
    if(p->environ[0] != NULL){
855
984
      for(char **e = environ; *e != NULL; e++){
856
985
        if(not add_environment(p, *e, false)){
857
 
          perror("add_environment");
 
986
          error(0, errno, "add_environment");
858
987
        }
859
988
      }
860
989
    }
861
990
    
862
991
    int pipefd[2];
863
 
    ret = TEMP_FAILURE_RETRY(pipe(pipefd));
 
992
    ret = (int)TEMP_FAILURE_RETRY(pipe(pipefd));
864
993
    if(ret == -1){
865
 
      perror("pipe");
866
 
      exitstatus = EXIT_FAILURE;
 
994
      error(0, errno, "pipe");
 
995
      exitstatus = EX_OSERR;
867
996
      goto fallback;
868
997
    }
869
998
    /* Ask OS to automatic close the pipe on exec */
870
999
    ret = set_cloexec_flag(pipefd[0]);
871
1000
    if(ret < 0){
872
 
      perror("set_cloexec_flag");
873
 
      exitstatus = EXIT_FAILURE;
 
1001
      error(0, errno, "set_cloexec_flag");
 
1002
      exitstatus = EX_OSERR;
874
1003
      goto fallback;
875
1004
    }
876
1005
    ret = set_cloexec_flag(pipefd[1]);
877
1006
    if(ret < 0){
878
 
      perror("set_cloexec_flag");
879
 
      exitstatus = EXIT_FAILURE;
 
1007
      error(0, errno, "set_cloexec_flag");
 
1008
      exitstatus = EX_OSERR;
880
1009
      goto fallback;
881
1010
    }
882
1011
    /* Block SIGCHLD until process is safely in process list */
883
 
    ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
884
 
                                         &sigchld_action.sa_mask,
885
 
                                         NULL));
 
1012
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
 
1013
                                              &sigchld_action.sa_mask,
 
1014
                                              NULL));
886
1015
    if(ret < 0){
887
 
      perror("sigprocmask");
888
 
      exitstatus = EXIT_FAILURE;
 
1016
      error(0, errno, "sigprocmask");
 
1017
      exitstatus = EX_OSERR;
889
1018
      goto fallback;
890
1019
    }
891
1020
    /* Starting a new process to be watched */
894
1023
      pid = fork();
895
1024
    } while(pid == -1 and errno == EINTR);
896
1025
    if(pid == -1){
897
 
      perror("fork");
898
 
      exitstatus = EXIT_FAILURE;
 
1026
      error(0, errno, "fork");
 
1027
      exitstatus = EX_OSERR;
899
1028
      goto fallback;
900
1029
    }
901
1030
    if(pid == 0){
902
1031
      /* this is the child process */
903
1032
      ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
904
1033
      if(ret < 0){
905
 
        perror("sigaction");
906
 
        _exit(EXIT_FAILURE);
 
1034
        error(0, errno, "sigaction");
 
1035
        _exit(EX_OSERR);
907
1036
      }
908
1037
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
909
1038
      if(ret < 0){
910
 
        perror("sigprocmask");
911
 
        _exit(EXIT_FAILURE);
 
1039
        error(0, errno, "sigprocmask");
 
1040
        _exit(EX_OSERR);
912
1041
      }
913
1042
      
914
1043
      ret = dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
915
1044
      if(ret == -1){
916
 
        perror("dup2");
917
 
        _exit(EXIT_FAILURE);
 
1045
        error(0, errno, "dup2");
 
1046
        _exit(EX_OSERR);
918
1047
      }
919
1048
      
920
1049
      if(dirfd(dir) < 0){
924
1053
      }
925
1054
      if(p->environ[0] == NULL){
926
1055
        if(execv(filename, p->argv) < 0){
927
 
          perror("execv");
928
 
          _exit(EXIT_FAILURE);
 
1056
          error(0, errno, "execv for %s", filename);
 
1057
          _exit(EX_OSERR);
929
1058
        }
930
1059
      } else {
931
1060
        if(execve(filename, p->argv, p->environ) < 0){
932
 
          perror("execve");
933
 
          _exit(EXIT_FAILURE);
 
1061
          error(0, errno, "execve for %s", filename);
 
1062
          _exit(EX_OSERR);
934
1063
        }
935
1064
      }
936
1065
      /* no return */
941
1070
    free(filename);
942
1071
    plugin *new_plugin = getplugin(dirst->d_name);
943
1072
    if(new_plugin == NULL){
944
 
      perror("getplugin");
945
 
      ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
946
 
                                           &sigchld_action.sa_mask,
947
 
                                           NULL));
 
1073
      error(0, errno, "getplugin");
 
1074
      ret = (int)(TEMP_FAILURE_RETRY
 
1075
                  (sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
 
1076
                               NULL)));
948
1077
      if(ret < 0){
949
 
        perror("sigprocmask");
 
1078
        error(0, errno, "sigprocmask");
950
1079
      }
951
 
      exitstatus = EXIT_FAILURE;
 
1080
      exitstatus = EX_OSERR;
952
1081
      goto fallback;
953
1082
    }
954
1083
    
957
1086
    
958
1087
    /* Unblock SIGCHLD so signal handler can be run if this process
959
1088
       has already completed */
960
 
    ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
961
 
                                         &sigchld_action.sa_mask,
962
 
                                         NULL));
 
1089
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
 
1090
                                              &sigchld_action.sa_mask,
 
1091
                                              NULL));
963
1092
    if(ret < 0){
964
 
      perror("sigprocmask");
965
 
      exitstatus = EXIT_FAILURE;
 
1093
      error(0, errno, "sigprocmask");
 
1094
      exitstatus = EX_OSERR;
966
1095
      goto fallback;
967
1096
    }
968
1097
    
969
 
    FD_SET(new_plugin->fd, &rfds_all);
 
1098
#if defined (__GNUC__) and defined (__GLIBC__)
 
1099
#if not __GLIBC_PREREQ(2, 16)
 
1100
#pragma GCC diagnostic push
 
1101
#pragma GCC diagnostic ignored "-Wsign-conversion"
 
1102
#endif
 
1103
#endif
 
1104
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
 
1105
                                          -Wconversion in GNU libc
 
1106
                                          before 2.16 */
 
1107
#if defined (__GNUC__) and defined (__GLIBC__)
 
1108
#if not __GLIBC_PREREQ(2, 16)
 
1109
#pragma GCC diagnostic pop
 
1110
#endif
 
1111
#endif
970
1112
    
971
1113
    if(maxfd < new_plugin->fd){
972
1114
      maxfd = new_plugin->fd;
993
1135
    fd_set rfds = rfds_all;
994
1136
    int select_ret = select(maxfd+1, &rfds, NULL, NULL, NULL);
995
1137
    if(select_ret == -1 and errno != EINTR){
996
 
      perror("select");
997
 
      exitstatus = EXIT_FAILURE;
 
1138
      error(0, errno, "select");
 
1139
      exitstatus = EX_OSERR;
998
1140
      goto fallback;
999
1141
    }
1000
1142
    /* OK, now either a process completed, or something can be read
1026
1168
          }
1027
1169
          
1028
1170
          /* Remove the plugin */
1029
 
          FD_CLR(proc->fd, &rfds_all);
 
1171
#if defined (__GNUC__) and defined (__GLIBC__)
 
1172
#if not __GLIBC_PREREQ(2, 16)
 
1173
#pragma GCC diagnostic push
 
1174
#pragma GCC diagnostic ignored "-Wsign-conversion"
 
1175
#endif
 
1176
#endif
 
1177
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
 
1178
                                          -Wconversion in GNU libc
 
1179
                                          before 2.16 */
 
1180
#if defined (__GNUC__) and defined (__GLIBC__)
 
1181
#if not __GLIBC_PREREQ(2, 16)
 
1182
#pragma GCC diagnostic pop
 
1183
#endif
 
1184
#endif
1030
1185
          
1031
1186
          /* Block signal while modifying process_list */
1032
 
          ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
1033
 
                                               &sigchld_action.sa_mask,
1034
 
                                               NULL));
 
1187
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
 
1188
                                        (SIG_BLOCK,
 
1189
                                         &sigchld_action.sa_mask,
 
1190
                                         NULL));
1035
1191
          if(ret < 0){
1036
 
            perror("sigprocmask");
1037
 
            exitstatus = EXIT_FAILURE;
 
1192
            error(0, errno, "sigprocmask");
 
1193
            exitstatus = EX_OSERR;
1038
1194
            goto fallback;
1039
1195
          }
1040
1196
          
1043
1199
          proc = next_plugin;
1044
1200
          
1045
1201
          /* We are done modifying process list, so unblock signal */
1046
 
          ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
1047
 
                                               &sigchld_action.sa_mask,
1048
 
                                               NULL));
 
1202
          ret = (int)(TEMP_FAILURE_RETRY
 
1203
                      (sigprocmask(SIG_UNBLOCK,
 
1204
                                   &sigchld_action.sa_mask, NULL)));
1049
1205
          if(ret < 0){
1050
 
            perror("sigprocmask");
1051
 
            exitstatus = EXIT_FAILURE;
 
1206
            error(0, errno, "sigprocmask");
 
1207
            exitstatus = EX_OSERR;
1052
1208
            goto fallback;
1053
1209
          }
1054
1210
          
1064
1220
        bool bret = print_out_password(proc->buffer,
1065
1221
                                       proc->buffer_length);
1066
1222
        if(not bret){
1067
 
          perror("print_out_password");
1068
 
          exitstatus = EXIT_FAILURE;
 
1223
          error(0, errno, "print_out_password");
 
1224
          exitstatus = EX_IOERR;
1069
1225
        }
1070
1226
        goto fallback;
1071
1227
      }
1072
1228
      
1073
1229
      /* This process has not completed.  Does it have any output? */
1074
 
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
 
1230
#if defined (__GNUC__) and defined (__GLIBC__)
 
1231
#if not __GLIBC_PREREQ(2, 16)
 
1232
#pragma GCC diagnostic push
 
1233
#pragma GCC diagnostic ignored "-Wsign-conversion"
 
1234
#endif
 
1235
#endif
 
1236
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
 
1237
                                                         warning from
 
1238
                                                         -Wconversion
 
1239
                                                         in GNU libc
 
1240
                                                         before
 
1241
                                                         2.16 */
 
1242
#if defined (__GNUC__) and defined (__GLIBC__)
 
1243
#if not __GLIBC_PREREQ(2, 16)
 
1244
#pragma GCC diagnostic pop
 
1245
#endif
 
1246
#endif
1075
1247
        /* This process had nothing to say at this time */
1076
1248
        proc = proc->next;
1077
1249
        continue;
1078
1250
      }
1079
1251
      /* Before reading, make the process' data buffer large enough */
1080
1252
      if(proc->buffer_length + BUFFER_SIZE > proc->buffer_size){
1081
 
        proc->buffer = realloc(proc->buffer, proc->buffer_size
1082
 
                               + (size_t) BUFFER_SIZE);
1083
 
        if(proc->buffer == NULL){
1084
 
          perror("malloc");
1085
 
          exitstatus = EXIT_FAILURE;
 
1253
        char *new_buffer = realloc(proc->buffer, proc->buffer_size
 
1254
                                   + (size_t) BUFFER_SIZE);
 
1255
        if(new_buffer == NULL){
 
1256
          error(0, errno, "malloc");
 
1257
          exitstatus = EX_OSERR;
1086
1258
          goto fallback;
1087
1259
        }
 
1260
        proc->buffer = new_buffer;
1088
1261
        proc->buffer_size += BUFFER_SIZE;
1089
1262
      }
1090
1263
      /* Read from the process */
1109
1282
  
1110
1283
 fallback:
1111
1284
  
1112
 
  if(plugin_list == NULL or exitstatus != EXIT_SUCCESS){
 
1285
  if(plugin_list == NULL or (exitstatus != EXIT_SUCCESS
 
1286
                             and exitstatus != EX_OK)){
1113
1287
    /* Fallback if all plugins failed, none are found or an error
1114
1288
       occured */
1115
1289
    bool bret;
1123
1297
    }
1124
1298
    bret = print_out_password(passwordbuffer, len);
1125
1299
    if(not bret){
1126
 
      perror("print_out_password");
1127
 
      exitstatus = EXIT_FAILURE;
 
1300
      error(0, errno, "print_out_password");
 
1301
      exitstatus = EX_IOERR;
1128
1302
    }
1129
1303
  }
1130
1304
  
1131
1305
  /* Restore old signal handler */
1132
1306
  ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
1133
1307
  if(ret == -1){
1134
 
    perror("sigaction");
1135
 
    exitstatus = EXIT_FAILURE;
 
1308
    error(0, errno, "sigaction");
 
1309
    exitstatus = EX_OSERR;
1136
1310
  }
1137
1311
  
1138
1312
  if(custom_argv != NULL){
1153
1327
      ret = kill(p->pid, SIGTERM);
1154
1328
      if(ret == -1 and errno != ESRCH){
1155
1329
        /* Set-uid proccesses might not get closed */
1156
 
        perror("kill");
 
1330
        error(0, errno, "kill");
1157
1331
      }
1158
1332
    }
1159
1333
  }
1163
1337
    ret = wait(NULL);
1164
1338
  } while(ret >= 0);
1165
1339
  if(errno != ECHILD){
1166
 
    perror("wait");
 
1340
    error(0, errno, "wait");
1167
1341
  }
1168
1342
  
1169
1343
  free_plugin_list();