/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

* network-hooks.d/openvpn: Tolerate relative MANDOSNETHOOKDIR path.
  (stop): Bug fix: Fix quote escapes.
* network-hooks.d/openvpn.conf: Remove compression.

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-2012 Teddy Hogeborn
13
 
 * Copyright © 2008-2012 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
41
41
 
42
42
#include <stdio.h>              /* fprintf(), stderr, fwrite(),
43
43
                                   stdout, ferror(), remove() */
44
 
#include <stdint.h>             /* uint16_t, uint32_t, intptr_t */
 
44
#include <stdint.h>             /* uint16_t, uint32_t */
45
45
#include <stddef.h>             /* NULL, size_t, ssize_t */
46
46
#include <stdlib.h>             /* free(), EXIT_SUCCESS, srand(),
47
47
                                   strtof(), abort() */
170
170
 
171
171
/* Function to use when printing errors */
172
172
void perror_plus(const char *print_text){
173
 
  int e = errno;
174
173
  fprintf(stderr, "Mandos plugin %s: ",
175
174
          program_invocation_short_name);
176
 
  errno = e;
177
175
  perror(print_text);
178
176
}
179
177
 
180
 
__attribute__((format (gnu_printf, 2, 3)))
181
178
int fprintf_plus(FILE *stream, const char *format, ...){
182
179
  va_list ap;
183
180
  va_start (ap, format);
205
202
}
206
203
 
207
204
/* Add server to set of servers to retry periodically */
208
 
bool add_server(const char *ip, uint16_t port, AvahiIfIndex if_index,
209
 
                int af){
 
205
int add_server(const char *ip, uint16_t port, AvahiIfIndex if_index,
 
206
               int af){
210
207
  int ret;
211
208
  server *new_server = malloc(sizeof(server));
212
209
  if(new_server == NULL){
213
210
    perror_plus("malloc");
214
 
    return false;
 
211
    return -1;
215
212
  }
216
213
  *new_server = (server){ .ip = strdup(ip),
217
214
                          .port = port,
219
216
                          .af = af };
220
217
  if(new_server->ip == NULL){
221
218
    perror_plus("strdup");
222
 
    return false;
 
219
    return -1;
223
220
  }
224
221
  /* Special case of first server */
225
222
  if (mc.current_server == NULL){
236
233
  ret = clock_gettime(CLOCK_MONOTONIC, &mc.current_server->last_seen);
237
234
  if(ret == -1){
238
235
    perror_plus("clock_gettime");
239
 
    return false;
 
236
    return -1;
240
237
  }
241
 
  return true;
 
238
  return 0;
242
239
}
243
240
 
244
241
/* 
821
818
    goto mandos_end;
822
819
  }
823
820
  
824
 
  /* This casting via intptr_t is to eliminate warning about casting
825
 
     an int to a pointer type.  This is exactly how the GnuTLS Guile
826
 
     function "set-session-transport-fd!" does it. */
827
 
  gnutls_transport_set_ptr(session,
828
 
                           (gnutls_transport_ptr_t)(intptr_t)tcp_sd);
 
821
  /* Spurious warning from -Wint-to-pointer-cast */
 
822
  gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) tcp_sd);
829
823
  
830
824
  if(quit_now){
831
825
    errno = EINTR;
1036
1030
      if(ret == 0){
1037
1031
        avahi_simple_poll_quit(mc.simple_poll);
1038
1032
      } else {
1039
 
        if(not add_server(ip, port, interface,
1040
 
                          avahi_proto_to_af(proto))){
1041
 
          fprintf_plus(stderr, "Failed to add server \"%s\" to server"
1042
 
                       " list\n", name);
1043
 
        }
 
1033
        ret = add_server(ip, port, interface,
 
1034
                         avahi_proto_to_af(proto));
1044
1035
      }
1045
1036
    }
1046
1037
  }
1453
1444
          perror_plus("setenv");
1454
1445
          _exit(EX_OSERR);
1455
1446
        }
1456
 
        ret = setenv("VERBOSITY", debug ? "1" : "0", 1);
 
1447
        ret = setenv("VERBOSE", debug ? "1" : "0", 1);
1457
1448
        if(ret == -1){
1458
1449
          perror_plus("setenv");
1459
1450
          _exit(EX_OSERR);
1476
1467
          _exit(EX_OSERR);
1477
1468
        }
1478
1469
        free(delaystring);
1479
 
        if(connect_to != NULL){
1480
 
          ret = setenv("CONNECT", connect_to, 1);
1481
 
          if(ret == -1){
1482
 
            perror_plus("setenv");
1483
 
            _exit(EX_OSERR);
1484
 
          }
1485
 
        }
1486
 
        if(execl(fullname, direntry->d_name, mode, NULL) == -1){
1487
 
          perror_plus("execl");
1488
 
          _exit(EXIT_FAILURE);
1489
 
        }
 
1470
        ret = execl(fullname, direntry->d_name, mode, NULL);
 
1471
        perror_plus("execl");
1490
1472
      } else {
1491
1473
        int status;
1492
1474
        if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
1611
1593
        .group = 2 },
1612
1594
      { .name = "retry", .key = 132,
1613
1595
        .arg = "SECONDS",
1614
 
        .doc = "Retry interval used when denied by the Mandos server",
 
1596
        .doc = "Retry interval used when denied by the mandos server",
1615
1597
        .group = 2 },
1616
1598
      { .name = "network-hook-dir", .key = 133,
1617
1599
        .arg = "DIR",
1689
1671
        argp_state_help(state, state->out_stream,
1690
1672
                        ARGP_HELP_USAGE | ARGP_HELP_EXIT_ERR);
1691
1673
      case 'V':                 /* --version */
 
1674
        fprintf_plus(state->out_stream,
 
1675
                     "Mandos plugin mandos-client: ");
1692
1676
        fprintf_plus(state->out_stream, "%s\n", argp_program_version);
1693
1677
        exit(argp_err_exit_status);
1694
1678
        break;