/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 (run-client): Pass $(CLIENTARGS) to plugin-runner.
  (run-server): Pass $(SERVERARGS) to server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  -*- coding: utf-8 -*- */
2
2
/*
3
 
 * Mandos-client - get and decrypt data from a Mandos server
 
3
 * Mandos client - get and decrypt data from a Mandos server
4
4
 *
5
5
 * This program is partly derived from an example program for an Avahi
6
6
 * service browser, downloaded from
36
36
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), asprintf() */
37
37
 
38
38
#include <stdio.h>              /* fprintf(), stderr, fwrite(),
39
 
                                   stdout, ferror(), sscanf */
 
39
                                   stdout, ferror() */
40
40
#include <stdint.h>             /* uint16_t, uint32_t */
41
41
#include <stddef.h>             /* NULL, size_t, ssize_t */
42
42
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
55
55
                                   connect() */
56
56
#include <fcntl.h>              /* open() */
57
57
#include <dirent.h>             /* opendir(), struct dirent, readdir() */
58
 
#include <inttypes.h>           /* PRIu16, SCNu16 */
 
58
#include <inttypes.h>           /* PRIu16 */
59
59
#include <assert.h>             /* assert() */
60
60
#include <errno.h>              /* perror(), errno */
61
61
#include <time.h>               /* time() */
67
67
                                   getuid(), getgid(), setuid(),
68
68
                                   setgid() */
69
69
#include <arpa/inet.h>          /* inet_pton(), htons */
70
 
#include <iso646.h>             /* not, and, or */
 
70
#include <iso646.h>             /* not, and */
71
71
#include <argp.h>               /* struct argp_option, error_t, struct
72
72
                                   argp_state, struct argp,
73
73
                                   argp_parse(), ARGP_KEY_ARG,
866
866
      
867
867
      error_t parse_opt (int key, char *arg,
868
868
                         struct argp_state *state) {
 
869
        /* Get the INPUT argument from `argp_parse', which we know is
 
870
           a pointer to our plugin list pointer. */
869
871
        switch (key) {
870
872
        case 128:               /* --debug */
871
873
          debug = true;
883
885
          pubkey = arg;
884
886
          break;
885
887
        case 129:               /* --dh-bits */
886
 
          ret = sscanf(arg, "%u", &mc.dh_bits);
887
 
          if(ret != 1){
888
 
            fprintf(stderr, "Bad number of DH bits\n");
 
888
          errno = 0;
 
889
          mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
 
890
          if (errno){
 
891
            perror("strtol");
889
892
            exit(EXIT_FAILURE);
890
893
          }
891
894
          break;
995
998
        exitcode = EXIT_FAILURE;
996
999
        goto end;
997
1000
      }
998
 
      uint16_t port;
999
 
      ret = sscanf(address+1, "%" SCNu16, &port);
1000
 
      if(ret != 1){
1001
 
        fprintf(stderr, "Bad port number\n");
 
1001
      errno = 0;
 
1002
      uint16_t port = (uint16_t) strtol(address+1, NULL, 10);
 
1003
      if(errno){
 
1004
        perror("Bad port number");
1002
1005
        exitcode = EXIT_FAILURE;
1003
1006
        goto end;
1004
1007
      }
1107
1110
      struct dirent *direntry;
1108
1111
      d = opendir(tempdir);
1109
1112
      if(d == NULL){
1110
 
        if(errno != ENOENT){
1111
 
          perror("opendir");
1112
 
        }
 
1113
        perror("opendir");
1113
1114
      } else {
1114
1115
        while(true){
1115
1116
          direntry = readdir(d);
1135
1136
        closedir(d);
1136
1137
      }
1137
1138
      ret = rmdir(tempdir);
1138
 
      if(ret == -1 and errno != ENOENT){
 
1139
      if(ret == -1){
1139
1140
        perror("rmdir");
1140
1141
      }
1141
1142
    }