/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: 2011-07-13 01:11:12 UTC
  • Revision ID: teddy@fukt.bsnet.se-20110713011112-bgf3tenqq60uoyyb
* Makefile (plugins.d/mandos-client): Bug fix: Put $^ before all
                                      libraries.  Remove "$(COMMON)".
                                      Thanks to Angel Abad
                                      <angelabad@ubuntu.com>.
* initramfs-tools-script: Work around change in initramfs-tools,
                          Debian bug #633582.
* plugins.d/mandos-client.c (init_gnutls_global): Bug fix: check for
                errors from gnutls_certificate_allocate_credentials().

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
11
 * Everything else is
12
 
 * Copyright © 2008,2009 Teddy Hogeborn
13
 
 * Copyright © 2008,2009 Björn Påhlsson
 
12
 * Copyright © 2008-2011 Teddy Hogeborn
 
13
 * Copyright © 2008-2011 Björn Påhlsson
14
14
 * 
15
15
 * This program is free software: you can redistribute it and/or
16
16
 * modify it under the terms of the GNU General Public License as
63
63
                                   strtoimax() */
64
64
#include <assert.h>             /* assert() */
65
65
#include <errno.h>              /* perror(), errno */
66
 
#include <time.h>               /* nanosleep(), time() */
 
66
#include <time.h>               /* nanosleep(), time(), sleep() */
67
67
#include <net/if.h>             /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
68
68
                                   SIOCSIFFLAGS, if_indextoname(),
69
69
                                   if_nametoindex(), IF_NAMESIZE */
73
73
#include <unistd.h>             /* close(), SEEK_SET, off_t, write(),
74
74
                                   getuid(), getgid(), seteuid(),
75
75
                                   setgid(), pause() */
76
 
#include <arpa/inet.h>          /* inet_pton(), htons */
 
76
#include <arpa/inet.h>          /* inet_pton(), htons, inet_ntop() */
77
77
#include <iso646.h>             /* not, or, and */
78
78
#include <argp.h>               /* struct argp_option, error_t, struct
79
79
                                   argp_state, struct argp,
423
423
  }
424
424
  
425
425
  /* OpenPGP credentials */
426
 
  gnutls_certificate_allocate_credentials(&mc.cred);
 
426
  ret = gnutls_certificate_allocate_credentials(&mc.cred);
427
427
  if(ret != GNUTLS_E_SUCCESS){
428
 
    fprintf(stderr, "GnuTLS memory error: %s\n", /* Spurious warning
429
 
                                                    from
430
 
                                                    -Wunreachable-code
431
 
                                                 */
 
428
    fprintf(stderr, "GnuTLS memory error: %s\n",
432
429
            safer_gnutls_strerror(ret));
433
430
    gnutls_global_deinit();
434
431
    return -1;
690
687
    ret = connect(tcp_sd, &to.in, sizeof(to)); /* IPv4 */
691
688
  }
692
689
  if(ret < 0){
693
 
    int e = errno;
694
 
    perror("connect");
695
 
    errno = e;
 
690
    if ((errno != ECONNREFUSED and errno != ENETUNREACH) or debug){
 
691
      int e = errno;
 
692
      perror("connect");
 
693
      errno = e;
 
694
    }
696
695
    goto mandos_end;
697
696
  }
698
697
  
1030
1029
int good_interface(const struct dirent *if_entry){
1031
1030
  ssize_t ssret;
1032
1031
  char *flagname = NULL;
 
1032
  if(if_entry->d_name[0] == '.'){
 
1033
    return 0;
 
1034
  }
1033
1035
  int ret = asprintf(&flagname, "%s/%s/flags", sys_class_net,
1034
1036
                     if_entry->d_name);
1035
1037
  if(ret < 0){
1036
1038
    perror("asprintf");
1037
1039
    return 0;
1038
1040
  }
1039
 
  if(if_entry->d_name[0] == '.'){
1040
 
    return 0;
1041
 
  }
1042
1041
  int flags_fd = (int)TEMP_FAILURE_RETRY(open(flagname, O_RDONLY));
1043
1042
  if(flags_fd == -1){
1044
1043
    perror("open");
 
1044
    free(flagname);
1045
1045
    return 0;
1046
1046
  }
 
1047
  free(flagname);
1047
1048
  typedef short ifreq_flags;    /* ifreq.ifr_flags in netdevice(7) */
1048
1049
  /* read line from flags_fd */
1049
 
  ssize_t to_read = (sizeof(ifreq_flags)*2)+3; /* "0x1003\n" */
 
1050
  ssize_t to_read = 2+(sizeof(ifreq_flags)*2)+1; /* "0x1003\n" */
1050
1051
  char *flagstring = malloc((size_t)to_read+1); /* +1 for final \0 */
1051
1052
  flagstring[(size_t)to_read] = '\0';
1052
1053
  if(flagstring == NULL){
1109
1110
    }
1110
1111
    return 0;
1111
1112
  }
 
1113
  /* Reject non-ARP interfaces (including dummy interfaces) */
 
1114
  if(flags & IFF_NOARP){
 
1115
    if(debug){
 
1116
      fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n",
 
1117
              if_entry->d_name);
 
1118
    }
 
1119
    return 0;
 
1120
  }
1112
1121
  /* Accept this device */
1113
1122
  if(debug){
1114
1123
    fprintf(stderr, "Interface \"%s\" is acceptable\n",
1618
1627
    if(quit_now){
1619
1628
      goto end;
1620
1629
    }
1621
 
    
1622
 
    ret = start_mandos_communication(address, port, if_index, af);
1623
 
    if(ret < 0){
1624
 
      switch(errno){
1625
 
      case ENETUNREACH:
1626
 
      case EHOSTDOWN:
1627
 
      case EHOSTUNREACH:
1628
 
        exitcode = EX_NOHOST;
1629
 
        break;
1630
 
      case EINVAL:
1631
 
        exitcode = EX_USAGE;
1632
 
        break;
1633
 
      case EIO:
1634
 
        exitcode = EX_IOERR;
1635
 
        break;
1636
 
      case EPROTO:
1637
 
        exitcode = EX_PROTOCOL;
1638
 
        break;
1639
 
      default:
1640
 
        exitcode = EX_OSERR;
 
1630
 
 
1631
    while(not quit_now){
 
1632
      ret = start_mandos_communication(address, port, if_index, af);
 
1633
      if(quit_now or ret == 0){
1641
1634
        break;
1642
1635
      }
1643
 
    } else {
 
1636
      sleep(15);
 
1637
    };
 
1638
 
 
1639
    if (not quit_now){
1644
1640
      exitcode = EXIT_SUCCESS;
1645
1641
    }
 
1642
 
1646
1643
    goto end;
1647
1644
  }
1648
1645