/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

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 */
31
31
 
32
32
/* Needed by GPGME, specifically gpgme_data_seek() */
 
33
#ifndef _LARGEFILE_SOURCE
33
34
#define _LARGEFILE_SOURCE
 
35
#endif
 
36
#ifndef _FILE_OFFSET_BITS
34
37
#define _FILE_OFFSET_BITS 64
 
38
#endif
35
39
 
36
40
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), asprintf() */
37
41
 
38
42
#include <stdio.h>              /* fprintf(), stderr, fwrite(),
39
 
                                   stdout, ferror(), sscanf(),
40
 
                                   remove() */
 
43
                                   stdout, ferror(), remove() */
41
44
#include <stdint.h>             /* uint16_t, uint32_t */
42
45
#include <stddef.h>             /* NULL, size_t, ssize_t */
43
46
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
44
 
                                   srand() */
 
47
                                   srand(), strtof() */
45
48
#include <stdbool.h>            /* bool, false, true */
46
49
#include <string.h>             /* memset(), strcmp(), strlen(),
47
50
                                   strerror(), asprintf(), strcpy() */
56
59
#include <fcntl.h>              /* open() */
57
60
#include <dirent.h>             /* opendir(), struct dirent, readdir()
58
61
                                 */
59
 
#include <inttypes.h>           /* PRIu16, intmax_t, SCNdMAX */
 
62
#include <inttypes.h>           /* PRIu16, PRIdMAX, intmax_t,
 
63
                                   strtoimax() */
60
64
#include <assert.h>             /* assert() */
61
65
#include <errno.h>              /* perror(), errno */
62
66
#include <time.h>               /* nanosleep(), time() */
562
566
  
563
567
  memset(&to, 0, sizeof(to));
564
568
  if(af == AF_INET6){
565
 
    to.in6.sin6_family = (uint16_t)af;
 
569
    to.in6.sin6_family = (sa_family_t)af;
566
570
    ret = inet_pton(af, ip, &to.in6.sin6_addr);
567
571
  } else {                      /* IPv4 */
568
572
    to.in.sin_family = (sa_family_t)af;
854
858
       the callback function is called the Avahi server will free the
855
859
       resolver for us. */
856
860
    
857
 
    if(!(avahi_s_service_resolver_new(mc.server, interface,
858
 
                                       protocol, name, type, domain,
859
 
                                       AVAHI_PROTO_INET6, 0,
860
 
                                       resolve_callback, NULL)))
 
861
    if(avahi_s_service_resolver_new(mc.server, interface, protocol,
 
862
                                    name, type, domain, protocol, 0,
 
863
                                    resolve_callback, NULL) == NULL)
861
864
      fprintf(stderr, "Avahi: Failed to resolve service '%s': %s\n",
862
865
              name, avahi_strerror(avahi_server_errno(mc.server)));
863
866
    break;
894
897
  int error;
895
898
  int ret;
896
899
  intmax_t tmpmax;
897
 
  int numchars;
 
900
  char *tmp;
898
901
  int exitcode = EXIT_SUCCESS;
899
902
  const char *interface = "eth0";
900
903
  struct ifreq network;
908
911
  const char *seckey = PATHDIR "/" SECKEY;
909
912
  const char *pubkey = PATHDIR "/" PUBKEY;
910
913
  
911
 
  /* Initialize Mandos context */
912
 
  mc = (mandos_context){ .simple_poll = NULL, .server = NULL,
913
 
                         .dh_bits = 1024, .priority = "SECURE256"
914
 
                         ":!CTYPE-X.509:+CTYPE-OPENPGP" };
915
914
  bool gnutls_initialized = false;
916
915
  bool gpgme_initialized = false;
917
 
  double delay = 2.5;
918
 
 
 
916
  float delay = 2.5f;
 
917
  
919
918
  struct sigaction old_sigterm_action;
920
919
  struct sigaction sigterm_action = { .sa_handler = handle_sigterm };
921
920
  
975
974
        pubkey = arg;
976
975
        break;
977
976
      case 129:                 /* --dh-bits */
978
 
        ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
979
 
        if(ret < 1 or tmpmax != (typeof(mc.dh_bits))tmpmax
980
 
           or arg[numchars] != '\0'){
 
977
        errno = 0;
 
978
        tmpmax = strtoimax(arg, &tmp, 10);
 
979
        if(errno != 0 or tmp == arg or *tmp != '\0'
 
980
           or tmpmax != (typeof(mc.dh_bits))tmpmax){
981
981
          fprintf(stderr, "Bad number of DH bits\n");
982
982
          exit(EXIT_FAILURE);
983
983
        }
987
987
        mc.priority = arg;
988
988
        break;
989
989
      case 131:                 /* --delay */
990
 
        ret = sscanf(arg, "%lf%n", &delay, &numchars);
991
 
        if(ret < 1 or arg[numchars] != '\0'){
 
990
        errno = 0;
 
991
        delay = strtof(arg, &tmp);
 
992
        if(errno != 0 or tmp == arg or *tmp != '\0'){
992
993
          fprintf(stderr, "Bad delay\n");
993
994
          exit(EXIT_FAILURE);
994
995
        }
1200
1201
      goto end;
1201
1202
    }
1202
1203
    uint16_t port;
1203
 
    ret = sscanf(address+1, "%" SCNdMAX "%n", &tmpmax, &numchars);
1204
 
    if(ret < 1 or tmpmax != (uint16_t)tmpmax
1205
 
       or address[numchars+1] != '\0'){
 
1204
    errno = 0;
 
1205
    tmpmax = strtoimax(address+1, &tmp, 10);
 
1206
    if(errno != 0 or tmp == address+1 or *tmp != '\0'
 
1207
       or tmpmax != (uint16_t)tmpmax){
1206
1208
      fprintf(stderr, "Bad port number\n");
1207
1209
      exitcode = EXIT_FAILURE;
1208
1210
      goto end;
1254
1256
  
1255
1257
  /* Create the Avahi service browser */
1256
1258
  sb = avahi_s_service_browser_new(mc.server, if_index,
1257
 
                                   AVAHI_PROTO_INET6, "_mandos._tcp",
 
1259
                                   AVAHI_PROTO_UNSPEC, "_mandos._tcp",
1258
1260
                                   NULL, 0, browse_callback, NULL);
1259
1261
  if(sb == NULL){
1260
1262
    fprintf(stderr, "Failed to create service browser: %s\n",