/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-02-12 06:09:24 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090212060924-vwxgitxnwr14w9e4
* mandos (Client.start_checker): Bug fix: Add extra check in case the
                                 checker process completed quickly.

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