322
323
safer_gnutls_strerror(ret));
325
if ((ret = gnutls_priority_set_direct (es->session, "NORMAL", &err))
326
if ((ret = gnutls_priority_set_direct (es->session, mc->priority, &err))
326
327
!= GNUTLS_E_SUCCESS) {
327
328
fprintf(stderr, "Syntax error at: %s\n", err);
328
329
fprintf(stderr, "GnuTLS error: %s\n",
536
static AvahiSimplePoll *simple_poll = NULL;
537
static AvahiServer *server = NULL;
539
static void resolve_callback(
540
AvahiSServiceResolver *r,
541
AvahiIfIndex interface,
542
AVAHI_GCC_UNUSED AvahiProtocol protocol,
543
AvahiResolverEvent event,
547
const char *host_name,
548
const AvahiAddress *address,
550
AVAHI_GCC_UNUSED AvahiStringList *txt,
551
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
552
AVAHI_GCC_UNUSED void* userdata) {
538
static void resolve_callback( AvahiSServiceResolver *r,
539
AvahiIfIndex interface,
540
AVAHI_GCC_UNUSED AvahiProtocol protocol,
541
AvahiResolverEvent event,
545
const char *host_name,
546
const AvahiAddress *address,
548
AVAHI_GCC_UNUSED AvahiStringList *txt,
549
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
550
AVAHI_GCC_UNUSED void* userdata) {
551
mandos_context *mc = userdata;
554
552
assert(r); /* Spurious warning */
556
554
/* Called whenever a service has been resolved successfully or
561
559
case AVAHI_RESOLVER_FAILURE:
562
560
fprintf(stderr, "(Resolver) Failed to resolve service '%s' of"
563
561
" type '%s' in domain '%s': %s\n", name, type, domain,
564
avahi_strerror(avahi_server_errno(server)));
562
avahi_strerror(avahi_server_errno(mc->server)));
567
565
case AVAHI_RESOLVER_FOUND:
572
570
fprintf(stderr, "Mandos server \"%s\" found on %s (%s) on"
573
571
" port %d\n", name, host_name, ip, port);
575
int ret = start_mandos_communication(ip, port, interface);
573
int ret = start_mandos_communication(ip, port, interface, mc);
577
575
exit(EXIT_SUCCESS);
581
579
avahi_s_service_resolver_free(r);
584
static void browse_callback(
585
AvahiSServiceBrowser *b,
586
AvahiIfIndex interface,
587
AvahiProtocol protocol,
588
AvahiBrowserEvent event,
592
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
595
AvahiServer *s = userdata;
596
assert(b); /* Spurious warning */
598
/* Called whenever a new services becomes available on the LAN or
599
is removed from the LAN */
603
case AVAHI_BROWSER_FAILURE:
605
fprintf(stderr, "(Browser) %s\n",
606
avahi_strerror(avahi_server_errno(server)));
607
avahi_simple_poll_quit(simple_poll);
610
case AVAHI_BROWSER_NEW:
611
/* We ignore the returned resolver object. In the callback
612
function we free it. If the server is terminated before
613
the callback function is called the server will free
614
the resolver for us. */
616
if (!(avahi_s_service_resolver_new(s, interface, protocol, name,
618
AVAHI_PROTO_INET6, 0,
619
resolve_callback, s)))
620
fprintf(stderr, "Failed to resolve service '%s': %s\n", name,
621
avahi_strerror(avahi_server_errno(s)));
624
case AVAHI_BROWSER_REMOVE:
627
case AVAHI_BROWSER_ALL_FOR_NOW:
628
case AVAHI_BROWSER_CACHE_EXHAUSTED:
582
static void browse_callback( AvahiSServiceBrowser *b,
583
AvahiIfIndex interface,
584
AvahiProtocol protocol,
585
AvahiBrowserEvent event,
589
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
591
mandos_context *mc = userdata;
592
assert(b); /* Spurious warning */
594
/* Called whenever a new services becomes available on the LAN or
595
is removed from the LAN */
599
case AVAHI_BROWSER_FAILURE:
601
fprintf(stderr, "(Browser) %s\n",
602
avahi_strerror(avahi_server_errno(mc->server)));
603
avahi_simple_poll_quit(mc->simple_poll);
606
case AVAHI_BROWSER_NEW:
607
/* We ignore the returned resolver object. In the callback
608
function we free it. If the server is terminated before
609
the callback function is called the server will free
610
the resolver for us. */
612
if (!(avahi_s_service_resolver_new(mc->server, interface, protocol, name,
614
AVAHI_PROTO_INET6, 0,
615
resolve_callback, mc)))
616
fprintf(stderr, "Failed to resolve service '%s': %s\n", name,
617
avahi_strerror(avahi_server_errno(s)));
620
case AVAHI_BROWSER_REMOVE:
623
case AVAHI_BROWSER_ALL_FOR_NOW:
624
case AVAHI_BROWSER_CACHE_EXHAUSTED:
633
629
/* Combines file name and path and returns the malloced new
671
669
{"certdir", required_argument, 0, 'd'},
672
670
{"certkey", required_argument, 0, 'c'},
673
671
{"certfile", required_argument, 0, 'k'},
672
{"dh_bits", required_argument, 0, 'D'},
673
{"priority", required_argument, 0, 'p'},
676
676
int option_index = 0;
795
810
config.publish_domain = 0;
797
812
/* Allocate a new server */
798
server = avahi_server_new(avahi_simple_poll_get(simple_poll),
813
mc.server = avahi_server_new(avahi_simple_poll_get(simple_poll),
799
814
&config, NULL, NULL, &error);
801
816
/* Free the configuration data */
802
817
avahi_server_config_free(&config);
804
819
/* Check if creating the server object succeeded */
806
821
fprintf(stderr, "Failed to create server: %s\n",
807
822
avahi_strerror(error));
808
823
returncode = EXIT_FAILURE;
812
827
/* Create the service browser */
813
sb = avahi_s_service_browser_new(server, if_index,
828
sb = avahi_s_service_browser_new(mc.server, if_index,
814
829
AVAHI_PROTO_INET6,
815
830
"_mandos._tcp", NULL, 0,
816
browse_callback, server);
831
browse_callback, &mc);
818
833
fprintf(stderr, "Failed to create service browser: %s\n",
819
avahi_strerror(avahi_server_errno(server)));
834
avahi_strerror(avahi_server_errno(mc.server)));
820
835
returncode = EXIT_FAILURE;