/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/password-request.c

Added manual pages for:
      clients.conf
      mandos.conf
      mandos
      mandos-client
      password-prompt
      password-request

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY() */
36
36
 
37
 
#include <stdio.h>              /* fprintf(), stderr, fwrite(), stdout,
38
 
                                   ferror() */
39
 
#include <stdint.h>             /* uint16_t, uint32_t */
40
 
#include <stddef.h>             /* NULL, size_t, ssize_t */
41
 
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
42
 
                                   srand() */
43
 
#include <stdbool.h>            /* bool, true */
44
 
#include <string.h>             /* memset(), strcmp(), strlen(),
45
 
                                   strerror(), memcpy(), strcpy() */
46
 
#include <sys/ioctl.h>          /* ioctl */
47
 
#include <net/if.h>             /* ifreq, SIOCGIFFLAGS, SIOCSIFFLAGS,
48
 
                                   IFF_UP */
49
 
#include <sys/types.h>          /* socket(), inet_pton(), sockaddr,
50
 
                                   sockaddr_in6, PF_INET6,
51
 
                                   SOCK_STREAM, INET6_ADDRSTRLEN,
52
 
                                   uid_t, gid_t */
53
 
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
54
 
                                   struct in6_addr, inet_pton(),
55
 
                                   connect() */
56
 
#include <assert.h>             /* assert() */
57
 
#include <errno.h>              /* perror(), errno */
58
 
#include <time.h>               /* time() */
 
37
#include <stdio.h>
 
38
#include <assert.h>
 
39
#include <stdlib.h>
 
40
#include <time.h>
 
41
#include <net/if.h>             /* if_nametoindex */
 
42
#include <sys/ioctl.h>          /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
 
43
                                   SIOCSIFFLAGS */
59
44
#include <net/if.h>             /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
60
 
                                   SIOCSIFFLAGS, if_indextoname(),
61
 
                                   if_nametoindex(), IF_NAMESIZE */
62
 
#include <unistd.h>             /* close(), SEEK_SET, off_t, write(),
63
 
                                   getuid(), getgid(), setuid(),
64
 
                                   setgid() */
65
 
#include <netinet/in.h>
66
 
#include <arpa/inet.h>          /* inet_pton(), htons */
67
 
#include <iso646.h>             /* not, and */
68
 
#include <argp.h>               /* struct argp_option, error_t, struct
69
 
                                   argp_state, struct argp,
70
 
                                   argp_parse(), ARGP_KEY_ARG,
71
 
                                   ARGP_KEY_END, ARGP_ERR_UNKNOWN */
 
45
                                   SIOCSIFFLAGS */
72
46
 
73
 
/* Avahi */
74
 
/* All Avahi types, constants and functions
75
 
 Avahi*, avahi_*,
76
 
 AVAHI_* */
77
47
#include <avahi-core/core.h>
78
48
#include <avahi-core/lookup.h>
79
49
#include <avahi-core/log.h>
81
51
#include <avahi-common/malloc.h>
82
52
#include <avahi-common/error.h>
83
53
 
84
 
/* GnuTLS */
85
 
#include <gnutls/gnutls.h>      /* All GnuTLS types, constants and functions
86
 
                                   gnutls_*
87
 
                                   init_gnutls_session(),
88
 
                                   GNUTLS_* */
89
 
#include <gnutls/openpgp.h>     /* gnutls_certificate_set_openpgp_key_file(),
90
 
                                   GNUTLS_OPENPGP_FMT_BASE64 */
 
54
/* Mandos client part */
 
55
#include <sys/types.h>          /* socket(), inet_pton() */
 
56
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
 
57
                                   struct in6_addr, inet_pton() */
 
58
#include <gnutls/gnutls.h>      /* All GnuTLS stuff */
 
59
#include <gnutls/openpgp.h>     /* GnuTLS with openpgp stuff */
91
60
 
 
61
#include <unistd.h>             /* close() */
 
62
#include <netinet/in.h>
 
63
#include <stdbool.h>            /* true */
 
64
#include <string.h>             /* memset */
 
65
#include <arpa/inet.h>          /* inet_pton() */
 
66
#include <iso646.h>             /* not */
 
67
#include <net/if.h>             /* IF_NAMESIZE */
 
68
#include <argp.h>               /* struct argp_option,
 
69
                                   struct argp_state, struct argp,
 
70
                                   argp_parse() */
92
71
/* GPGME */
93
 
#include <gpgme.h>              /* All GPGME types, constants and functions
94
 
                                   gpgme_*
95
 
                                   GPGME_PROTOCOL_OpenPGP,
96
 
                                   GPG_ERR_NO_* */
 
72
#include <errno.h>              /* perror() */
 
73
#include <gpgme.h>
97
74
 
98
75
#define BUFFER_SIZE 256
99
76
 
100
77
bool debug = false;
101
78
static const char *keydir = "/conf/conf.d/mandos";
102
79
static const char mandos_protocol_version[] = "1";
103
 
const char *argp_program_version = "mandosclient 1.0";
 
80
const char *argp_program_version = "mandosclient 0.9";
104
81
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
105
82
 
106
83
/* Used for passing in values through the Avahi callback functions */
321
298
  if(debug){
322
299
    fprintf(stderr, "Initializing GnuTLS\n");
323
300
  }
324
 
  
325
 
  ret = gnutls_global_init();
326
 
  if (ret != GNUTLS_E_SUCCESS) {
 
301
 
 
302
  if ((ret = gnutls_global_init ())
 
303
      != GNUTLS_E_SUCCESS) {
327
304
    fprintf (stderr, "GnuTLS global_init: %s\n",
328
305
             safer_gnutls_strerror(ret));
329
306
    return -1;
338
315
  }
339
316
  
340
317
  /* OpenPGP credentials */
341
 
  gnutls_certificate_allocate_credentials(&mc->cred);
342
 
  if (ret != GNUTLS_E_SUCCESS){
 
318
  if ((ret = gnutls_certificate_allocate_credentials (&mc->cred))
 
319
      != GNUTLS_E_SUCCESS) {
343
320
    fprintf (stderr, "GnuTLS memory error: %s\n",
344
321
             safer_gnutls_strerror(ret));
345
322
    gnutls_global_deinit ();
383
360
 
384
361
 globalfail:
385
362
 
386
 
  gnutls_certificate_free_credentials(mc->cred);
387
 
  gnutls_global_deinit();
 
363
  gnutls_certificate_free_credentials (mc->cred);
 
364
  gnutls_global_deinit ();
388
365
  return -1;
389
366
 
390
367
}
538
515
  }
539
516
  
540
517
  gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) tcp_sd);
541
 
 
542
 
  do{
543
 
    ret = gnutls_handshake (session);
544
 
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
 
518
  
 
519
  ret = gnutls_handshake (session);
545
520
  
546
521
  if (ret != GNUTLS_E_SUCCESS){
547
522
    if(debug){
579
554
      case GNUTLS_E_AGAIN:
580
555
        break;
581
556
      case GNUTLS_E_REHANDSHAKE:
582
 
        do{
583
 
          ret = gnutls_handshake (session);
584
 
        } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
 
557
        ret = gnutls_handshake (session);
585
558
        if (ret < 0){
586
559
          fprintf(stderr, "*** GnuTLS Re-handshake failed ***\n");
587
560
          gnutls_perror (ret);
862
835
                           .args_doc = "",
863
836
                           .doc = "Mandos client -- Get and decrypt"
864
837
                           " passwords from mandos server" };
865
 
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
866
 
      if (ret == ARGP_ERR_UNKNOWN){
867
 
        fprintf(stderr, "Unkown error while parsing arguments\n");
868
 
        exitcode = EXIT_FAILURE;
869
 
        goto end;
870
 
      }
 
838
      argp_parse (&argp, argc, argv, 0, 0, NULL);
871
839
    }
872
840
      
873
841
    pubkeyfile = combinepath(keydir, pubkeyfile);
1045
1013
    free(seckeyfile);
1046
1014
 
1047
1015
    if (gnutls_initalized){
1048
 
      gnutls_certificate_free_credentials(mc.cred);
 
1016
      gnutls_certificate_free_credentials (mc.cred);
1049
1017
      gnutls_global_deinit ();
1050
1018
    }
1051
1019