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

  • Committer: Björn Påhlsson
  • Date: 2008-08-08 01:31:58 UTC
  • mto: (237.7.1 mandos) (24.1.154 mandos)
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: belorn@braxen-20080808013158-weqgqkxni7du1ke5
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 <inttypes.h>           /* PRIu16 */
54
 
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
55
 
                                   struct in6_addr, inet_pton(),
56
 
                                   connect() */
57
 
#include <assert.h>             /* assert() */
58
 
#include <errno.h>              /* perror(), errno */
59
 
#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 */
60
44
#include <net/if.h>             /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
61
 
                                   SIOCSIFFLAGS, if_indextoname(),
62
 
                                   if_nametoindex(), IF_NAMESIZE */
63
 
#include <unistd.h>             /* close(), SEEK_SET, off_t, write(),
64
 
                                   getuid(), getgid(), setuid(),
65
 
                                   setgid() */
66
 
#include <netinet/in.h>
67
 
#include <arpa/inet.h>          /* inet_pton(), htons */
68
 
#include <iso646.h>             /* not, and */
69
 
#include <argp.h>               /* struct argp_option, error_t, struct
70
 
                                   argp_state, struct argp,
71
 
                                   argp_parse(), ARGP_KEY_ARG,
72
 
                                   ARGP_KEY_END, ARGP_ERR_UNKNOWN */
 
45
                                   SIOCSIFFLAGS */
73
46
 
74
 
/* Avahi */
75
 
/* All Avahi types, constants and functions
76
 
 Avahi*, avahi_*,
77
 
 AVAHI_* */
78
47
#include <avahi-core/core.h>
79
48
#include <avahi-core/lookup.h>
80
49
#include <avahi-core/log.h>
82
51
#include <avahi-common/malloc.h>
83
52
#include <avahi-common/error.h>
84
53
 
85
 
/* GnuTLS */
86
 
#include <gnutls/gnutls.h>      /* All GnuTLS types, constants and functions
87
 
                                   gnutls_*
88
 
                                   init_gnutls_session(),
89
 
                                   GNUTLS_* */
90
 
#include <gnutls/openpgp.h>     /* gnutls_certificate_set_openpgp_key_file(),
91
 
                                   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 */
92
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() */
93
71
/* GPGME */
94
 
#include <gpgme.h>              /* All GPGME types, constants and functions
95
 
                                   gpgme_*
96
 
                                   GPGME_PROTOCOL_OpenPGP,
97
 
                                   GPG_ERR_NO_* */
 
72
#include <errno.h>              /* perror() */
 
73
#include <gpgme.h>
98
74
 
99
75
#define BUFFER_SIZE 256
100
76
 
101
77
bool debug = false;
102
78
static const char *keydir = "/conf/conf.d/mandos";
103
79
static const char mandos_protocol_version[] = "1";
104
 
const char *argp_program_version = "password-request 1.0";
 
80
const char *argp_program_version = "mandosclient 0.9";
105
81
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
106
82
 
107
83
/* Used for passing in values through the Avahi callback functions */
229
205
    } else {
230
206
      fprintf(stderr, "Unsupported algorithm: %s\n",
231
207
              result->unsupported_algorithm);
232
 
      fprintf(stderr, "Wrong key usage: %u\n",
 
208
      fprintf(stderr, "Wrong key usage: %d\n",
233
209
              result->wrong_key_usage);
234
210
      if(result->file_name != NULL){
235
211
        fprintf(stderr, "File name: %s\n", result->file_name);
322
298
  if(debug){
323
299
    fprintf(stderr, "Initializing GnuTLS\n");
324
300
  }
325
 
  
326
 
  ret = gnutls_global_init();
327
 
  if (ret != GNUTLS_E_SUCCESS) {
 
301
 
 
302
  if ((ret = gnutls_global_init ())
 
303
      != GNUTLS_E_SUCCESS) {
328
304
    fprintf (stderr, "GnuTLS global_init: %s\n",
329
305
             safer_gnutls_strerror(ret));
330
306
    return -1;
339
315
  }
340
316
  
341
317
  /* OpenPGP credentials */
342
 
  gnutls_certificate_allocate_credentials(&mc->cred);
343
 
  if (ret != GNUTLS_E_SUCCESS){
 
318
  if ((ret = gnutls_certificate_allocate_credentials (&mc->cred))
 
319
      != GNUTLS_E_SUCCESS) {
344
320
    fprintf (stderr, "GnuTLS memory error: %s\n",
345
321
             safer_gnutls_strerror(ret));
346
322
    gnutls_global_deinit ();
384
360
 
385
361
 globalfail:
386
362
 
387
 
  gnutls_certificate_free_credentials(mc->cred);
388
 
  gnutls_global_deinit();
 
363
  gnutls_certificate_free_credentials (mc->cred);
 
364
  gnutls_global_deinit ();
389
365
  return -1;
390
366
 
391
367
}
456
432
  }
457
433
  
458
434
  if(debug){
459
 
    fprintf(stderr, "Setting up a tcp connection to %s, port %" PRIu16
460
 
            "\n", ip, port);
 
435
    fprintf(stderr, "Setting up a tcp connection to %s, port %d\n",
 
436
            ip, port);
461
437
  }
462
438
  
463
439
  tcp_sd = socket(PF_INET6, SOCK_STREAM, 0);
492
468
  to.in6.sin6_scope_id = (uint32_t)if_index;
493
469
  
494
470
  if(debug){
495
 
    fprintf(stderr, "Connection to: %s, port %" PRIu16 "\n", ip,
496
 
            port);
 
471
    fprintf(stderr, "Connection to: %s, port %d\n", ip, port);
497
472
    char addrstr[INET6_ADDRSTRLEN] = "";
498
473
    if(inet_ntop(to.in6.sin6_family, &(to.in6.sin6_addr), addrstr,
499
474
                 sizeof(addrstr)) == NULL){
540
515
  }
541
516
  
542
517
  gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) tcp_sd);
543
 
 
544
 
  do{
545
 
    ret = gnutls_handshake (session);
546
 
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
 
518
  
 
519
  ret = gnutls_handshake (session);
547
520
  
548
521
  if (ret != GNUTLS_E_SUCCESS){
549
522
    if(debug){
581
554
      case GNUTLS_E_AGAIN:
582
555
        break;
583
556
      case GNUTLS_E_REHANDSHAKE:
584
 
        do{
585
 
          ret = gnutls_handshake (session);
586
 
        } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
 
557
        ret = gnutls_handshake (session);
587
558
        if (ret < 0){
588
559
          fprintf(stderr, "*** GnuTLS Re-handshake failed ***\n");
589
560
          gnutls_perror (ret);
678
649
      char ip[AVAHI_ADDRESS_STR_MAX];
679
650
      avahi_address_snprint(ip, sizeof(ip), address);
680
651
      if(debug){
681
 
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
682
 
                PRIu16 ") on port %d\n", name, host_name, ip,
683
 
                interface, port);
 
652
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %d) on"
 
653
                " port %d\n", name, host_name, ip, interface, port);
684
654
      }
685
655
      int ret = start_mandos_communication(ip, port, interface, mc);
686
656
      if (ret == 0){
865
835
                           .args_doc = "",
866
836
                           .doc = "Mandos client -- Get and decrypt"
867
837
                           " passwords from mandos server" };
868
 
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
869
 
      if (ret == ARGP_ERR_UNKNOWN){
870
 
        fprintf(stderr, "Unkown error while parsing arguments\n");
871
 
        exitcode = EXIT_FAILURE;
872
 
        goto end;
873
 
      }
 
838
      argp_parse (&argp, argc, argv, 0, 0, NULL);
874
839
    }
875
840
      
876
841
    pubkeyfile = combinepath(keydir, pubkeyfile);
1048
1013
    free(seckeyfile);
1049
1014
 
1050
1015
    if (gnutls_initalized){
1051
 
      gnutls_certificate_free_credentials(mc.cred);
 
1016
      gnutls_certificate_free_credentials (mc.cred);
1052
1017
      gnutls_global_deinit ();
1053
1018
    }
1054
1019