/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-02-05 02:33:05 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090205023305-o7rkhr55e7w4pe1m
* plugins.d/password-prompt.c (quit_now): Changed type to "volatile
                             sig_atomic_t".  All uses changed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
                                   sigprocmask(), SIG_BLOCK, SIGCHLD,
65
65
                                   SIG_UNBLOCK, kill() */
66
66
#include <errno.h>              /* errno, EBADF */
 
67
#include <inttypes.h>           /* intmax_t, SCNdMAX, PRIdMAX,  */
67
68
 
68
69
#define BUFFER_SIZE 256
69
70
 
114
115
  if(name != NULL){
115
116
    copy_name = strdup(name);
116
117
    if(copy_name == NULL){
 
118
      free(new_plugin);
117
119
      return NULL;
118
120
    }
119
121
  }
120
122
  
121
 
  *new_plugin = (plugin) { .name = copy_name,
122
 
                           .argc = 1,
123
 
                           .disabled = false,
124
 
                           .next = plugin_list };
 
123
  *new_plugin = (plugin){ .name = copy_name,
 
124
                          .argc = 1,
 
125
                          .disabled = false,
 
126
                          .next = plugin_list };
125
127
  
126
128
  new_plugin->argv = malloc(sizeof(char *) * 2);
127
129
  if(new_plugin->argv == NULL){
308
310
  struct dirent *dirst;
309
311
  struct stat st;
310
312
  fd_set rfds_all;
311
 
  int ret, maxfd = 0;
 
313
  int ret, numchars, maxfd = 0;
312
314
  ssize_t sret;
 
315
  intmax_t tmpmax;
313
316
  uid_t uid = 65534;
314
317
  gid_t gid = 65534;
315
318
  bool debug = false;
373
376
  };
374
377
  
375
378
  error_t parse_opt(int key, char *arg, __attribute__((unused))
376
 
                    struct argp_state *state) {
377
 
    switch(key) {
 
379
                    struct argp_state *state){
 
380
    switch(key){
378
381
    case 'g':                   /* --global-options */
379
382
      if(arg != NULL){
380
383
        char *p;
463
466
      /* This is already done by parse_opt_config_file() */
464
467
      break;
465
468
    case 130:                   /* --userid */
466
 
      /* In the GNU C library, uid_t is always unsigned int */
467
 
      ret = sscanf(arg, "%u", &uid);
468
 
      if(ret != 1){
469
 
        fprintf(stderr, "Bad user ID number: \"%s\", using %u\n", arg,
470
 
                uid);
 
469
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
470
      if(ret < 1 or tmpmax != (uid_t)tmpmax
 
471
         or arg[numchars] != '\0'){
 
472
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
 
473
                PRIdMAX "\n", arg, (intmax_t)uid);
 
474
      } else {
 
475
        uid = (uid_t)tmpmax;
471
476
      }
472
477
      break;
473
478
    case 131:                   /* --groupid */
474
 
      /* In the GNU C library, gid_t is always unsigned int */
475
 
      ret = sscanf(arg, "%u", &gid);
476
 
      if(ret != 1){
477
 
        fprintf(stderr, "Bad group ID number: \"%s\", using %u\n",
478
 
                arg, gid);
 
479
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
480
      if(ret < 1 or tmpmax != (gid_t)tmpmax
 
481
         or arg[numchars] != '\0'){
 
482
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
 
483
                PRIdMAX "\n", arg, (intmax_t)gid);
 
484
      } else {
 
485
        gid = (gid_t)tmpmax;
479
486
      }
480
487
      break;
481
488
    case 132:                   /* --debug */
505
512
     ignores everything but the --config-file option. */
506
513
  error_t parse_opt_config_file(int key, char *arg,
507
514
                                __attribute__((unused))
508
 
                                struct argp_state *state) {
509
 
    switch(key) {
 
515
                                struct argp_state *state){
 
516
    switch(key){
510
517
    case 'g':                   /* --global-options */
511
518
    case 'G':                   /* --global-env */
512
519
    case 'o':                   /* --options-for */
647
654
      for(char **a = p->argv; *a != NULL; a++){
648
655
        fprintf(stderr, "\tArg: %s\n", *a);
649
656
      }
650
 
      fprintf(stderr, "...and %u environment variables\n", p->envc);
 
657
      fprintf(stderr, "...and %d environment variables\n", p->envc);
651
658
      for(char **a = p->environ; *a != NULL; a++){
652
659
        fprintf(stderr, "\t%s\n", *a);
653
660
      }
960
967
 
961
968
          if(debug){
962
969
            if(WIFEXITED(proc->status)){
963
 
              fprintf(stderr, "Plugin %u exited with status %d\n",
964
 
                      (unsigned int) (proc->pid),
 
970
              fprintf(stderr, "Plugin %" PRIdMAX " exited with status"
 
971
                      " %d\n", (intmax_t) (proc->pid),
965
972
                      WEXITSTATUS(proc->status));
966
 
            } else if(WIFSIGNALED(proc->status)) {
967
 
              fprintf(stderr, "Plugin %u killed by signal %d\n",
968
 
                      (unsigned int) (proc->pid),
 
973
            } else if(WIFSIGNALED(proc->status)){
 
974
              fprintf(stderr, "Plugin %" PRIdMAX " killed by signal"
 
975
                      " %d\n", (intmax_t) (proc->pid),
969
976
                      WTERMSIG(proc->status));
970
977
            } else if(WCOREDUMP(proc->status)){
971
 
              fprintf(stderr, "Plugin %u dumped core\n",
972
 
                      (unsigned int) (proc->pid));
 
978
              fprintf(stderr, "Plugin %" PRIdMAX " dumped core\n",
 
979
                      (intmax_t) (proc->pid));
973
980
            }
974
981
          }
975
982