/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: 2009-09-05 17:40:18 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090905174018-3w6q5uqk8ti5fqq6
* plugins.d/mandos-client.c (init_gpgme): Move variable "ret" into the
                                          innermost scope possible.
  (start_mandos_communication): Move variable "decrypted_buffer_size"
                                into the innermost scope possible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8 -*- */
 
1
/*  -*- coding: utf-8; mode: c; mode: orgtbl -*- */
2
2
/*
3
3
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
38
38
#include <sys/select.h>         /* fd_set, select(), FD_ZERO(),
39
39
                                   FD_SET(), FD_ISSET(), FD_CLR */
40
40
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
41
 
                                   WEXITSTATUS() */
 
41
                                   WEXITSTATUS(), WTERMSIG(),
 
42
                                   WCOREDUMP() */
42
43
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
43
44
#include <iso646.h>             /* and, or, not */
44
45
#include <dirent.h>             /* DIR, struct dirent, opendir(),
52
53
                                   close() */
53
54
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
54
55
                                   FD_CLOEXEC */
55
 
#include <string.h>             /* strsep, strlen(), asprintf() */
 
56
#include <string.h>             /* strsep, strlen(), asprintf(),
 
57
                                   strsignal() */
56
58
#include <errno.h>              /* errno */
57
59
#include <argp.h>               /* struct argp_option, struct
58
60
                                   argp_state, struct argp,
208
210
/*
209
211
 * Based on the example in the GNU LibC manual chapter 13.13 "File
210
212
 * Descriptor Flags".
211
 
 * *Note File Descriptor Flags:(libc)Descriptor Flags.
 
213
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
212
214
 */
213
215
static int set_cloexec_flag(int fd){
214
216
  int ret = fcntl(fd, F_GETFD, 0);
315
317
  fd_set rfds_all;
316
318
  int ret, maxfd = 0;
317
319
  ssize_t sret;
318
 
  intmax_t tmpmax;
319
320
  uid_t uid = 65534;
320
321
  gid_t gid = 65534;
321
322
  bool debug = false;
380
381
  
381
382
  error_t parse_opt(int key, char *arg, __attribute__((unused))
382
383
                    struct argp_state *state){
383
 
    char *tmp;
384
384
    switch(key){
 
385
      char *tmp;
 
386
      intmax_t tmpmax;
385
387
    case 'g':                   /* --global-options */
386
388
      if(arg != NULL){
387
389
        char *plugin_option;
457
459
      plugindir = strdup(arg);
458
460
      if(plugindir == NULL){
459
461
        perror("strdup");
460
 
      }      
 
462
      }
461
463
      break;
462
464
    case 129:                   /* --config-file */
463
465
      /* This is already done by parse_opt_config_file() */
527
529
      if(argfile == NULL){
528
530
        perror("strdup");
529
531
      }
530
 
      break;      
 
532
      break;
531
533
    case 130:                   /* --userid */
532
534
    case 131:                   /* --groupid */
533
535
    case 132:                   /* --debug */
562
564
    conffp = fopen(AFILE, "r");
563
565
  } else {
564
566
    conffp = fopen(argfile, "r");
565
 
  }  
 
567
  }
566
568
  if(conffp != NULL){
567
569
    char *org_line = NULL;
568
570
    char *p, *arg, *new_arg, *line;
612
614
          goto fallback;
613
615
        }
614
616
        custom_argv[custom_argc-1] = new_arg;
615
 
        custom_argv[custom_argc] = NULL;        
 
617
        custom_argv[custom_argc] = NULL;
616
618
      }
617
619
    }
 
620
    do{
 
621
      ret = fclose(conffp);
 
622
    }while(ret == EOF and errno == EINTR);
 
623
    if(ret == EOF){
 
624
      perror("fclose");
 
625
      exitstatus = EXIT_FAILURE;
 
626
      goto fallback;
 
627
    }
618
628
    free(org_line);
619
629
  } else {
620
630
    /* Check for harmful errors and go to fallback. Other errors might
973
983
                      WEXITSTATUS(proc->status));
974
984
            } else if(WIFSIGNALED(proc->status)){
975
985
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
976
 
                      " signal %d\n", proc->name,
 
986
                      " signal %d: %s\n", proc->name,
977
987
                      (intmax_t) (proc->pid),
978
 
                      WTERMSIG(proc->status));
 
988
                      WTERMSIG(proc->status),
 
989
                      strsignal(WTERMSIG(proc->status)));
979
990
            } else if(WCOREDUMP(proc->status)){
980
991
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
981
992
                      " core\n", proc->name, (intmax_t) (proc->pid));