/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

* Makefile: Merge branch adding warning messages to "run-*" targets.

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-2011 Teddy Hogeborn
13
 
 * Copyright © 2008-2011 Björn Påhlsson
 
12
 * Copyright © 2008,2009 Teddy Hogeborn
 
13
 * Copyright © 2008,2009 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(), sleep() */
 
66
#include <time.h>               /* nanosleep(), time() */
67
67
#include <net/if.h>             /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
68
68
                                   SIOCSIFFLAGS, if_indextoname(),
69
69
                                   if_nametoindex(), IF_NAMESIZE */
690
690
    ret = connect(tcp_sd, &to.in, sizeof(to)); /* IPv4 */
691
691
  }
692
692
  if(ret < 0){
693
 
    if ((errno != ECONNREFUSED and errno != ENETUNREACH) or debug){
694
 
      int e = errno;
695
 
      perror("connect");
696
 
      errno = e;
697
 
    }
 
693
    int e = errno;
 
694
    perror("connect");
 
695
    errno = e;
698
696
    goto mandos_end;
699
697
  }
700
698
  
1032
1030
int good_interface(const struct dirent *if_entry){
1033
1031
  ssize_t ssret;
1034
1032
  char *flagname = NULL;
1035
 
  if(if_entry->d_name[0] == '.'){
1036
 
    return 0;
1037
 
  }
1038
1033
  int ret = asprintf(&flagname, "%s/%s/flags", sys_class_net,
1039
1034
                     if_entry->d_name);
1040
1035
  if(ret < 0){
1041
1036
    perror("asprintf");
1042
1037
    return 0;
1043
1038
  }
 
1039
  if(if_entry->d_name[0] == '.'){
 
1040
    return 0;
 
1041
  }
1044
1042
  int flags_fd = (int)TEMP_FAILURE_RETRY(open(flagname, O_RDONLY));
1045
1043
  if(flags_fd == -1){
1046
1044
    perror("open");
1047
 
    free(flagname);
1048
1045
    return 0;
1049
1046
  }
1050
 
  free(flagname);
1051
1047
  typedef short ifreq_flags;    /* ifreq.ifr_flags in netdevice(7) */
1052
1048
  /* read line from flags_fd */
1053
1049
  ssize_t to_read = (sizeof(ifreq_flags)*2)+3; /* "0x1003\n" */
1113
1109
    }
1114
1110
    return 0;
1115
1111
  }
1116
 
  /* Reject non-ARP interfaces (including dummy interfaces) */
1117
 
  if(flags & IFF_NOARP){
1118
 
    if(debug){
1119
 
      fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n",
1120
 
              if_entry->d_name);
1121
 
    }
1122
 
    return 0;
1123
 
  }
1124
1112
  /* Accept this device */
1125
1113
  if(debug){
1126
1114
    fprintf(stderr, "Interface \"%s\" is acceptable\n",
1630
1618
    if(quit_now){
1631
1619
      goto end;
1632
1620
    }
1633
 
 
1634
 
    while(not quit_now){
1635
 
      ret = start_mandos_communication(address, port, if_index, af);
1636
 
      if(quit_now or ret == 0){
 
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;
1637
1641
        break;
1638
1642
      }
1639
 
      sleep(15);
1640
 
    };
1641
 
 
1642
 
    if (not quit_now){
 
1643
    } else {
1643
1644
      exitcode = EXIT_SUCCESS;
1644
1645
    }
1645
 
 
1646
1646
    goto end;
1647
1647
  }
1648
1648