/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 plugins.d/mandos-client.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:
57
57
#include <fcntl.h>              /* open() */
58
58
#include <dirent.h>             /* opendir(), struct dirent, readdir()
59
59
                                 */
60
 
#include <inttypes.h>           /* PRIu16, SCNu16 */
 
60
#include <inttypes.h>           /* PRIu16, intmax_t, SCNdMAX */
61
61
#include <assert.h>             /* assert() */
62
62
#include <errno.h>              /* perror(), errno */
63
63
#include <time.h>               /* time() */
754
754
      avahi_address_snprint(ip, sizeof(ip), address);
755
755
      if(debug){
756
756
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
757
 
                PRIu16 ") on port %d\n", name, host_name, ip,
758
 
                interface, port);
 
757
                PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
 
758
                ip, (intmax_t)interface, port);
759
759
      }
760
760
      int ret = start_mandos_communication(ip, port, interface, mc);
761
761
      if(ret == 0){
821
821
    AvahiSServiceBrowser *sb = NULL;
822
822
    int error;
823
823
    int ret;
 
824
    intmax_t tmpmax;
 
825
    int numchars;
824
826
    int exitcode = EXIT_SUCCESS;
825
827
    const char *interface = "eth0";
826
828
    struct ifreq network;
891
893
          pubkey = arg;
892
894
          break;
893
895
        case 129:               /* --dh-bits */
894
 
          ret = sscanf(arg, "%u", &mc.dh_bits);
895
 
          if(ret != 1){
 
896
          ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
897
          if(ret < 1 or tmpmax != (typeof(mc.dh_bits))tmpmax
 
898
             or arg[numchars] != '\0'){
896
899
            fprintf(stderr, "Bad number of DH bits\n");
897
900
            exit(EXIT_FAILURE);
898
901
          }
 
902
          mc.dh_bits = (typeof(mc.dh_bits))tmpmax;
899
903
          break;
900
904
        case 130:               /* --priority */
901
905
          mc.priority = arg;
1004
1008
        goto end;
1005
1009
      }
1006
1010
      uint16_t port;
1007
 
      ret = sscanf(address+1, "%" SCNu16, &port);
1008
 
      if(ret != 1){
 
1011
      ret = sscanf(address+1, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
1012
      if(ret < 1 or tmpmax != (uint16_t)tmpmax
 
1013
         or address[numchars+1] != '\0'){
1009
1014
        fprintf(stderr, "Bad port number\n");
1010
1015
        exitcode = EXIT_FAILURE;
1011
1016
        goto end;
1012
1017
      }
 
1018
      port = (uint16_t)tmpmax;
1013
1019
      *address = '\0';
1014
1020
      address = connect_to;
1015
1021
      ret = start_mandos_communication(address, port, if_index, &mc);