/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-01-14 14:20:17 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090114142017-84t4kfw56bsftjlo
Fixes for sscanf usage:

* plugin-runner.c (main): Parse numbers correctly and portably using
                          an intermediate "intmax_t".  Cast "pid_t" to
                          "intmax_t" before passing it to "printf()".
* plugins.d/mandos-client.c (main): Parse numbers correctly and
                                    portably using an intermediate
                                    "intmax_t".  Bug fix: cast
                                    "AvahiIfIndex" to "intmax_t" and
                                    use "PRIdMAX" instead of using
                                    "PRIu16", and use "PRIu16" to
                                    format port number.
* plugins.d/splashy.c (main): Parse numbers correctly and portably
                              using an intermediate "intmax_t".
* plugins.d/usplash.c (main): - '' -

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
 
308
309
  struct dirent *dirst;
309
310
  struct stat st;
310
311
  fd_set rfds_all;
311
 
  int ret, maxfd = 0;
 
312
  int ret, numchars, maxfd = 0;
312
313
  ssize_t sret;
 
314
  intmax_t tmpmax;
313
315
  uid_t uid = 65534;
314
316
  gid_t gid = 65534;
315
317
  bool debug = false;
463
465
      /* This is already done by parse_opt_config_file() */
464
466
      break;
465
467
    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);
 
468
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
469
      if(ret < 1 or tmpmax != (uid_t)tmpmax
 
470
         or arg[numchars] != '\0'){
 
471
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
 
472
                PRIdMAX "\n", arg, (intmax_t)uid);
 
473
      } else {
 
474
        uid = (uid_t)tmpmax;
471
475
      }
472
476
      break;
473
477
    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);
 
478
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
479
      if(ret < 1 or tmpmax != (gid_t)tmpmax
 
480
         or arg[numchars] != '\0'){
 
481
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
 
482
                PRIdMAX "\n", arg, (intmax_t)gid);
 
483
      } else {
 
484
        gid = (gid_t)tmpmax;
479
485
      }
480
486
      break;
481
487
    case 132:                   /* --debug */
647
653
      for(char **a = p->argv; *a != NULL; a++){
648
654
        fprintf(stderr, "\tArg: %s\n", *a);
649
655
      }
650
 
      fprintf(stderr, "...and %u environment variables\n", p->envc);
 
656
      fprintf(stderr, "...and %d environment variables\n", p->envc);
651
657
      for(char **a = p->environ; *a != NULL; a++){
652
658
        fprintf(stderr, "\t%s\n", *a);
653
659
      }
960
966
 
961
967
          if(debug){
962
968
            if(WIFEXITED(proc->status)){
963
 
              fprintf(stderr, "Plugin %u exited with status %d\n",
964
 
                      (unsigned int) (proc->pid),
 
969
              fprintf(stderr, "Plugin %" PRIdMAX " exited with status"
 
970
                      " %d\n", (intmax_t) (proc->pid),
965
971
                      WEXITSTATUS(proc->status));
966
972
            } else if(WIFSIGNALED(proc->status)) {
967
 
              fprintf(stderr, "Plugin %u killed by signal %d\n",
968
 
                      (unsigned int) (proc->pid),
 
973
              fprintf(stderr, "Plugin %" PRIdMAX " killed by signal"
 
974
                      " %d\n", (intmax_t) (proc->pid),
969
975
                      WTERMSIG(proc->status));
970
976
            } else if(WCOREDUMP(proc->status)){
971
 
              fprintf(stderr, "Plugin %u dumped core\n",
972
 
                      (unsigned int) (proc->pid));
 
977
              fprintf(stderr, "Plugin %" PRIdMAX " dumped core\n",
 
978
                      (intmax_t) (proc->pid));
973
979
            }
974
980
          }
975
981