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