75
75
#define BUFFER_SIZE 256
77
77
bool debug = false;
78
static const char *keydir = "/conf/conf.d/mandos";
79
static const char mandos_protocol_version[] = "1";
78
const char *keydir = "/conf/conf.d/mandos";
80
79
const char *argp_program_version = "mandosclient 0.9";
81
80
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
81
const char mandos_protocol_version[] = "1";
83
/* Used for passing in values through the Avahi callback functions */
83
/* Used for passing in values through all the callback functions */
85
85
AvahiSimplePoll *simple_poll;
86
86
AvahiServer *server;
90
90
const char *priority;
94
* Make room in "buffer" for at least BUFFER_SIZE additional bytes.
95
* "buffer_capacity" is how much is currently allocated,
96
* "buffer_length" is how much is already used.
98
93
size_t adjustbuffer(char **buffer, size_t buffer_length,
99
94
size_t buffer_capacity){
100
95
if (buffer_length + BUFFER_SIZE > buffer_capacity){
236
231
*plaintext = NULL;
238
plaintext_capacity = adjustbuffer(plaintext,
239
(size_t)plaintext_length,
233
plaintext_capacity = adjustbuffer(plaintext, (size_t)plaintext_length,
240
234
plaintext_capacity);
241
235
if (plaintext_capacity == 0){
242
236
perror("adjustbuffer");
361
static int init_gnutls_session(mandos_context *mc,
362
gnutls_session_t *session){
355
static int init_gnutls_session(mandos_context *mc, gnutls_session_t *session){
364
357
/* GnuTLS session creation */
365
358
ret = gnutls_init(session, GNUTLS_SERVER);
416
409
char interface[IF_NAMESIZE];
417
410
gnutls_session_t session;
411
gnutls_dh_params_t dh_params;
419
413
ret = init_gnutls_session (mc, &session);
443
437
memset(&to,0,sizeof(to)); /* Spurious warning */
444
to.in6.sin6_family = AF_INET6;
438
to.sin6_family = AF_INET6;
445
439
/* It would be nice to have a way to detect if we were passed an
446
440
IPv4 address here. Now we assume an IPv6 address. */
447
ret = inet_pton(AF_INET6, ip, &to.in6.sin6_addr);
441
ret = inet_pton(AF_INET6, ip, &to.sin6_addr);
449
443
perror("inet_pton");
453
447
fprintf(stderr, "Bad address: %s\n", ip);
456
to.in6.sin6_port = htons(port); /* Spurious warning */
450
to.sin6_port = htons(port); /* Spurious warning */
458
to.in6.sin6_scope_id = (uint32_t)if_index;
452
to.sin6_scope_id = (uint32_t)if_index;
461
455
fprintf(stderr, "Connection to: %s, port %d\n", ip, port);
462
456
char addrstr[INET6_ADDRSTRLEN] = "";
463
if(inet_ntop(to.in6.sin6_family, &(to.in6.sin6_addr), addrstr,
457
if(inet_ntop(to.sin6_family, &(to.sin6_addr), addrstr,
464
458
sizeof(addrstr)) == NULL){
465
459
perror("inet_ntop");
528
buffer_capacity = adjustbuffer(&buffer, buffer_length,
522
buffer_capacity = adjustbuffer(&buffer, buffer_length, buffer_capacity);
530
523
if (buffer_capacity == 0){
531
524
perror("adjustbuffer");
748
741
.doc = "Debug mode", .group = 3 },
749
742
{ .name = "connect", .key = 'c',
751
.doc = "Connect directly to a sepcified mandos server",
744
.doc = "Connect directly to a sepcified mandos server", .group = 1 },
753
745
{ .name = "interface", .key = 'i',
754
746
.arg = "INTERFACE",
755
.doc = "Interface that Avahi will conntect through",
747
.doc = "Interface that Avahi will conntect through", .group = 1 },
757
748
{ .name = "keydir", .key = 'd',
759
.doc = "Directory where the openpgp keyring is",
750
.doc = "Directory where the openpgp keyring is", .group = 1 },
761
751
{ .name = "seckey", .key = 's',
763
.doc = "Secret openpgp key for gnutls authentication",
753
.doc = "Secret openpgp key for gnutls authentication", .group = 1 },
765
754
{ .name = "pubkey", .key = 'p',
767
.doc = "Public openpgp key for gnutls authentication",
756
.doc = "Public openpgp key for gnutls authentication", .group = 2 },
769
757
{ .name = "dh-bits", .key = 129,
771
.doc = "dh-bits to use in gnutls communication",
759
.doc = "dh-bits to use in gnutls communication", .group = 2 },
773
760
{ .name = "priority", .key = 130,
774
761
.arg = "PRIORITY",
775
762
.doc = "GNUTLS priority", .group = 1 },
780
error_t parse_opt (int key, char *arg,
781
struct argp_state *state) {
782
/* Get the INPUT argument from `argp_parse', which we know is
783
a pointer to our plugin list pointer. */
767
error_t parse_opt (int key, char *arg, struct argp_state *state) {
768
/* Get the INPUT argument from `argp_parse', which we know is a
769
pointer to our plugin list pointer. */
825
811
struct argp argp = { .options = options, .parser = parse_opt,
827
.doc = "Mandos client -- Get and decrypt"
828
" passwords from mandos server" };
813
.doc = "Mandos client -- Get and decrypt passwords from mandos server" };
829
814
argp_parse (&argp, argc, argv, 0, 0, NULL);