/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-23 20:09:55 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090123200955-h9oy2hwyv8uly1op
* mandos (main): Bug fix: use "getint" on the "port" config file
                 option.
* plugins.d/mandos-client.c (main): Fixed spelling of
                                    "gnutls_initalized" and
                                    "gpgme_initalized".

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() */
365
365
}
366
366
 
367
367
static const char * safer_gnutls_strerror(int value) {
368
 
  const char *ret = gnutls_strerror(value); /* Spurious warning */
 
368
  const char *ret = gnutls_strerror(value); /* Spurious warning from
 
369
                                               -Wunreachable-code */
369
370
  if(ret == NULL)
370
371
    ret = "(unknown)";
371
372
  return ret;
404
405
  /* OpenPGP credentials */
405
406
  gnutls_certificate_allocate_credentials(&mc->cred);
406
407
  if(ret != GNUTLS_E_SUCCESS){
407
 
    fprintf(stderr, "GnuTLS memory error: %s\n", /* Spurious
408
 
                                                    warning */
 
408
    fprintf(stderr, "GnuTLS memory error: %s\n", /* Spurious warning
 
409
                                                  * from
 
410
                                                  * -Wunreachable-code
 
411
                                                  */
409
412
            safer_gnutls_strerror(ret));
410
413
    gnutls_global_deinit();
411
414
    return -1;
553
556
    fprintf(stderr, "Bad address: %s\n", ip);
554
557
    return -1;
555
558
  }
556
 
  to.in6.sin6_port = htons(port); /* Spurious warning */
 
559
  to.in6.sin6_port = htons(port); /* Spurious warnings from
 
560
                                     -Wconversion and
 
561
                                     -Wunreachable-code */
557
562
  
558
563
  to.in6.sin6_scope_id = (uint32_t)if_index;
559
564
  
749
754
      avahi_address_snprint(ip, sizeof(ip), address);
750
755
      if(debug){
751
756
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
752
 
                PRIu16 ") on port %d\n", name, host_name, ip,
753
 
                interface, port);
 
757
                PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
 
758
                ip, (intmax_t)interface, port);
754
759
      }
755
760
      int ret = start_mandos_communication(ip, port, interface, mc);
756
761
      if(ret == 0){
816
821
    AvahiSServiceBrowser *sb = NULL;
817
822
    int error;
818
823
    int ret;
 
824
    intmax_t tmpmax;
 
825
    int numchars;
819
826
    int exitcode = EXIT_SUCCESS;
820
827
    const char *interface = "eth0";
821
828
    struct ifreq network;
831
838
    mandos_context mc = { .simple_poll = NULL, .server = NULL,
832
839
                          .dh_bits = 1024, .priority = "SECURE256"
833
840
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
834
 
    bool gnutls_initalized = false;
835
 
    bool gpgme_initalized = false;
 
841
    bool gnutls_initialized = false;
 
842
    bool gpgme_initialized = false;
836
843
    
837
844
    {
838
845
      struct argp_option options[] = {
886
893
          pubkey = arg;
887
894
          break;
888
895
        case 129:               /* --dh-bits */
889
 
          ret = sscanf(arg, "%u", &mc.dh_bits);
890
 
          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'){
891
899
            fprintf(stderr, "Bad number of DH bits\n");
892
900
            exit(EXIT_FAILURE);
893
901
          }
 
902
          mc.dh_bits = (typeof(mc.dh_bits))tmpmax;
894
903
          break;
895
904
        case 130:               /* --priority */
896
905
          mc.priority = arg;
966
975
      exitcode = EXIT_FAILURE;
967
976
      goto end;
968
977
    } else {
969
 
      gnutls_initalized = true;
 
978
      gnutls_initialized = true;
970
979
    }
971
980
    
972
981
    if(mkdtemp(tempdir) == NULL){
976
985
    }
977
986
    
978
987
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
979
 
      fprintf(stderr, "gpgme_initalized failed\n");
 
988
      fprintf(stderr, "init_gpgme failed\n");
980
989
      exitcode = EXIT_FAILURE;
981
990
      goto end;
982
991
    } else {
983
 
      gpgme_initalized = true;
 
992
      gpgme_initialized = true;
984
993
    }
985
994
    
986
995
    if_index = (AvahiIfIndex) if_nametoindex(interface);
999
1008
        goto end;
1000
1009
      }
1001
1010
      uint16_t port;
1002
 
      ret = sscanf(address+1, "%" SCNu16, &port);
1003
 
      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'){
1004
1014
        fprintf(stderr, "Bad port number\n");
1005
1015
        exitcode = EXIT_FAILURE;
1006
1016
        goto end;
1007
1017
      }
 
1018
      port = (uint16_t)tmpmax;
1008
1019
      *address = '\0';
1009
1020
      address = connect_to;
1010
1021
      ret = start_mandos_communication(address, port, if_index, &mc);
1094
1105
    if(mc.simple_poll != NULL)
1095
1106
        avahi_simple_poll_free(mc.simple_poll);
1096
1107
    
1097
 
    if(gnutls_initalized){
 
1108
    if(gnutls_initialized){
1098
1109
      gnutls_certificate_free_credentials(mc.cred);
1099
1110
      gnutls_global_deinit();
1100
1111
      gnutls_dh_params_deinit(mc.dh_params);
1101
1112
    }
1102
1113
    
1103
 
    if(gpgme_initalized){
 
1114
    if(gpgme_initialized){
1104
1115
      gpgme_release(mc.ctx);
1105
1116
    }
1106
1117