/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-01-01 05:42:51 UTC
  • mfrom: (237.4.22 release)
  • Revision ID: teddy@recompile.se-20120101054251-26jflhej4znq2mzq
Merge from release branch.

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-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
170
170
 
171
171
/* Function to use when printing errors */
172
172
void perror_plus(const char *print_text){
 
173
  int e = errno;
173
174
  fprintf(stderr, "Mandos plugin %s: ",
174
175
          program_invocation_short_name);
 
176
  errno = e;
175
177
  perror(print_text);
176
178
}
177
179
 
 
180
__attribute__((format (gnu_printf, 2, 3)))
178
181
int fprintf_plus(FILE *stream, const char *format, ...){
179
182
  va_list ap;
180
183
  va_start (ap, format);
202
205
}
203
206
 
204
207
/* Add server to set of servers to retry periodically */
205
 
int add_server(const char *ip, uint16_t port, AvahiIfIndex if_index,
206
 
               int af){
 
208
bool add_server(const char *ip, uint16_t port, AvahiIfIndex if_index,
 
209
                int af){
207
210
  int ret;
208
211
  server *new_server = malloc(sizeof(server));
209
212
  if(new_server == NULL){
210
213
    perror_plus("malloc");
211
 
    return -1;
 
214
    return false;
212
215
  }
213
216
  *new_server = (server){ .ip = strdup(ip),
214
217
                          .port = port,
216
219
                          .af = af };
217
220
  if(new_server->ip == NULL){
218
221
    perror_plus("strdup");
219
 
    return -1;
 
222
    return false;
220
223
  }
221
224
  /* Special case of first server */
222
225
  if (mc.current_server == NULL){
233
236
  ret = clock_gettime(CLOCK_MONOTONIC, &mc.current_server->last_seen);
234
237
  if(ret == -1){
235
238
    perror_plus("clock_gettime");
236
 
    return -1;
 
239
    return false;
237
240
  }
238
 
  return 0;
 
241
  return true;
239
242
}
240
243
 
241
244
/* 
1030
1033
      if(ret == 0){
1031
1034
        avahi_simple_poll_quit(mc.simple_poll);
1032
1035
      } else {
1033
 
        ret = add_server(ip, port, interface,
1034
 
                         avahi_proto_to_af(proto));
 
1036
        if(not add_server(ip, port, interface,
 
1037
                          avahi_proto_to_af(proto))){
 
1038
          fprintf_plus(stderr, "Failed to add server \"%s\" to server"
 
1039
                       " list\n", name);
 
1040
        }
1035
1041
      }
1036
1042
    }
1037
1043
  }
1444
1450
          perror_plus("setenv");
1445
1451
          _exit(EX_OSERR);
1446
1452
        }
1447
 
        ret = setenv("VERBOSE", debug ? "1" : "0", 1);
 
1453
        ret = setenv("VERBOSITY", debug ? "1" : "0", 1);
1448
1454
        if(ret == -1){
1449
1455
          perror_plus("setenv");
1450
1456
          _exit(EX_OSERR);
1467
1473
          _exit(EX_OSERR);
1468
1474
        }
1469
1475
        free(delaystring);
1470
 
        ret = execl(fullname, direntry->d_name, mode, NULL);
1471
 
        perror_plus("execl");
 
1476
        if(connect_to != NULL){
 
1477
          ret = setenv("CONNECT", connect_to, 1);
 
1478
          if(ret == -1){
 
1479
            perror_plus("setenv");
 
1480
            _exit(EX_OSERR);
 
1481
          }
 
1482
        }
 
1483
        if(execl(fullname, direntry->d_name, mode, NULL) == -1){
 
1484
          perror_plus("execl");
 
1485
          _exit(EXIT_FAILURE);
 
1486
        }
1472
1487
      } else {
1473
1488
        int status;
1474
1489
        if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
1593
1608
        .group = 2 },
1594
1609
      { .name = "retry", .key = 132,
1595
1610
        .arg = "SECONDS",
1596
 
        .doc = "Retry interval used when denied by the mandos server",
 
1611
        .doc = "Retry interval used when denied by the Mandos server",
1597
1612
        .group = 2 },
1598
1613
      { .name = "network-hook-dir", .key = 133,
1599
1614
        .arg = "DIR",
1671
1686
        argp_state_help(state, state->out_stream,
1672
1687
                        ARGP_HELP_USAGE | ARGP_HELP_EXIT_ERR);
1673
1688
      case 'V':                 /* --version */
1674
 
        fprintf_plus(state->out_stream,
1675
 
                     "Mandos plugin mandos-client: ");
1676
1689
        fprintf_plus(state->out_stream, "%s\n", argp_program_version);
1677
1690
        exit(argp_err_exit_status);
1678
1691
        break;