/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: 2012-06-23 00:58:49 UTC
  • Revision ID: teddy@recompile.se-20120623005849-02wj82cng433rt2k
* clients.conf: Convert all time intervals to new RFC 3339 syntax.
* mandos: All client options for time intervals now take an RFC 3339
          duration.
  (rfc3339_duration_to_delta): New function.
  (string_to_delta): Try rfc3339_duration_to_delta first.
* mandos-clients.conf.xml (OPTIONS/timeout): Document new format.
  (EXAMPLE): Update to new interval format.
  (SEE ALSO): Reference RFC 3339.

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-2013 Teddy Hogeborn
13
 
 * Copyright © 2008-2013 Björn Påhlsson
 
12
 * Copyright © 2008-2012 Teddy Hogeborn
 
13
 * Copyright © 2008-2012 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
187
187
  
188
188
  TEMP_FAILURE_RETRY(fprintf(stream, "Mandos plugin %s: ",
189
189
                             program_invocation_short_name));
190
 
  return (int)TEMP_FAILURE_RETRY(vfprintf(stream, format, ap));
 
190
  return TEMP_FAILURE_RETRY(vfprintf(stream, format, ap));
191
191
}
192
192
 
193
193
/*
198
198
size_t incbuffer(char **buffer, size_t buffer_length,
199
199
                 size_t buffer_capacity){
200
200
  if(buffer_length + BUFFER_SIZE > buffer_capacity){
201
 
    char *new_buf = realloc(*buffer, buffer_capacity + BUFFER_SIZE);
202
 
    if(new_buf == NULL){
203
 
      int old_errno = errno;
204
 
      free(*buffer);
205
 
      errno = old_errno;
206
 
      *buffer = NULL;
 
201
    *buffer = realloc(*buffer, buffer_capacity + BUFFER_SIZE);
 
202
    if(buffer == NULL){
207
203
      return 0;
208
204
    }
209
 
    *buffer = new_buf;
210
205
    buffer_capacity += BUFFER_SIZE;
211
206
  }
212
207
  return buffer_capacity;
741
736
  }
742
737
  if(af == AF_INET6){
743
738
    to.in6.sin6_port = htons(port);    
744
 
#ifdef __GNUC__
745
 
#pragma GCC diagnostic push
746
 
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
747
 
#endif
748
739
    if(IN6_IS_ADDR_LINKLOCAL /* Spurious warnings from */
749
 
       (&to.in6.sin6_addr)){ /* -Wstrict-aliasing=2 or lower */
750
 
#ifdef __GNUC__
751
 
#pragma GCC diagnostic pop
752
 
#endif
 
740
       (&to.in6.sin6_addr)){ /* -Wstrict-aliasing=2 or lower and
 
741
                                -Wunreachable-code*/
753
742
      if(if_index == AVAHI_IF_UNSPEC){
754
743
        fprintf_plus(stderr, "An IPv6 link-local address is"
755
744
                     " incomplete without a network interface\n");
760
749
      to.in6.sin6_scope_id = (uint32_t)if_index;
761
750
    }
762
751
  } else {
763
 
    to.in.sin_port = htons(port);
 
752
    to.in.sin_port = htons(port); /* Spurious warnings from
 
753
                                     -Wconversion and
 
754
                                     -Wunreachable-code */
764
755
  }
765
756
  
766
757
  if(quit_now){
1493
1484
bool run_network_hooks(const char *mode, const char *interface,
1494
1485
                       const float delay){
1495
1486
  struct dirent **direntries;
 
1487
  struct dirent *direntry;
 
1488
  int ret;
1496
1489
  int numhooks = scandir(hookdir, &direntries, runnable_hook,
1497
1490
                         alphasort);
1498
1491
  if(numhooks == -1){
1505
1498
      perror_plus("scandir");
1506
1499
    }
1507
1500
  } else {
1508
 
    struct dirent *direntry;
1509
 
    int ret;
1510
1501
    int devnull = open("/dev/null", O_RDONLY);
1511
1502
    for(int i = 0; i < numhooks; i++){
1512
1503
      direntry = direntries[i];
1732
1723
}
1733
1724
 
1734
1725
error_t take_down_interface(const char *const interface){
 
1726
  int sd = -1;
1735
1727
  error_t old_errno = errno;
 
1728
  error_t ret_errno = 0;
 
1729
  int ret, ret_setflags;
1736
1730
  struct ifreq network;
1737
1731
  unsigned int if_index = if_nametoindex(interface);
1738
1732
  if(if_index == 0){
1741
1735
    return ENXIO;
1742
1736
  }
1743
1737
  if(interface_is_up(interface)){
1744
 
    error_t ret_errno = 0;
1745
1738
    if(not get_flags(interface, &network) and debug){
1746
1739
      ret_errno = errno;
1747
1740
      fprintf_plus(stderr, "Failed to get flags for interface "
1750
1743
    }
1751
1744
    network.ifr_flags &= ~(short)IFF_UP; /* clear flag */
1752
1745
    
1753
 
    int sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
 
1746
    sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1754
1747
    if(sd < 0){
1755
1748
      ret_errno = errno;
1756
1749
      perror_plus("socket");
1766
1759
    /* Raise priviliges */
1767
1760
    raise_privileges();
1768
1761
    
1769
 
    int ret_setflags = ioctl(sd, SIOCSIFFLAGS, &network);
 
1762
    ret_setflags = ioctl(sd, SIOCSIFFLAGS, &network);
1770
1763
    ret_errno = errno;
1771
1764
    
1772
1765
    /* Lower privileges */
1773
1766
    lower_privileges();
1774
1767
    
1775
1768
    /* Close the socket */
1776
 
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1769
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
1777
1770
    if(ret == -1){
1778
1771
      perror_plus("close");
1779
1772
    }
1812
1805
  const char *seckey = PATHDIR "/" SECKEY;
1813
1806
  const char *pubkey = PATHDIR "/" PUBKEY;
1814
1807
  char *interfaces_hooks = NULL;
 
1808
  size_t interfaces_hooks_size = 0;
1815
1809
  
1816
1810
  bool gnutls_initialized = false;
1817
1811
  bool gpgme_initialized = false;
2072
2066
        goto end;
2073
2067
      }
2074
2068
      memcpy(interfaces_hooks, mc.interfaces, mc.interfaces_size);
2075
 
      argz_stringify(interfaces_hooks, mc.interfaces_size, (int)',');
 
2069
      interfaces_hooks_size = mc.interfaces_size;
 
2070
      argz_stringify(interfaces_hooks, interfaces_hooks_size,
 
2071
                     (int)',');
2076
2072
    }
2077
2073
    if(not run_network_hooks("start", interfaces_hooks != NULL ?
2078
2074
                             interfaces_hooks : "", delay)){
2171
2167
        ret_errno = argz_add(&mc.interfaces, &mc.interfaces_size,
2172
2168
                             direntries[i]->d_name);
2173
2169
        if(ret_errno != 0){
2174
 
          errno = ret_errno;
2175
2170
          perror_plus("argz_add");
2176
2171
          continue;
2177
2172
        }
2220
2215
          ret_errno = argz_add(&interfaces_to_take_down,
2221
2216
                               &interfaces_to_take_down_size,
2222
2217
                               interface);
2223
 
          if(ret_errno != 0){
2224
 
            errno = ret_errno;
2225
 
            perror_plus("argz_add");
2226
 
          }
2227
2218
        }
2228
2219
      }
2229
2220
    }
2340
2331
        fprintf_plus(stderr, "Retrying in %d seconds\n",
2341
2332
                     (int)retry_interval);
2342
2333
      }
2343
 
      sleep((unsigned int)retry_interval);
 
2334
      sleep((int)retry_interval);
2344
2335
    }
2345
2336
    
2346
2337
    if (not quit_now){