/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

* plugin-runner.c: Only space changes.
* plugins.d/mandos-client.c: - '' -
* plugins.d/password-prompt.c: - '' -

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