#include <avahi-common/error.h>
#include <avahi-common/alternative.h>
#include <avahi-core/core.h>
+#include <avahi-core/publish.h>
#include <avahi-core/log.h>
#include "main.h"
int daemonize;
int use_syslog;
char *config_file;
-#ifdef HAVE_DBUS
int enable_dbus;
int fail_on_missing_dbus;
-#endif
int drop_root;
int publish_resolv_conf;
char ** publish_dns_servers;
static DaemonConfig config;
-#define MAX_NAME_SERVERS 10
-
static int has_prefix(const char *s, const char *prefix) {
size_t l;
avahi_strfreev(resolv_conf);
resolv_conf = NULL;
- if (!c->publish_resolv_conf)
- return 0;
-
if (!(f = fopen(RESOLV_CONF, "r"))) {
avahi_log_warn("Failed to open "RESOLV_CONF".");
goto finish;
}
- resolv_conf = avahi_new0(char*, MAX_NAME_SERVERS+1);
+ resolv_conf = avahi_new0(char*, AVAHI_MAX_WIDE_AREA_SERVERS+1);
- while (!feof(f) && i < MAX_NAME_SERVERS) {
+ while (!feof(f) && i < AVAHI_MAX_WIDE_AREA_SERVERS) {
char ln[128];
char *p;
for (p = l; *p; p++) {
AvahiAddress a;
- if (!avahi_address_parse(*p, AF_UNSPEC, &a))
+ if (!avahi_address_parse(*p, AVAHI_PROTO_UNSPEC, &a))
avahi_log_warn("Failed to parse address '%s', ignoring.", *p);
else
- if (avahi_server_add_dns_server_address(s, g, -1, AF_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, &a, 53) < 0) {
+ if (avahi_server_add_dns_server_address(s, g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, &a, 53) < 0) {
avahi_s_entry_group_free(g);
avahi_log_error("Failed to add DNS server address: %s", avahi_strerror(avahi_server_errno(s)));
return NULL;
avahi_s_entry_group_reset(dns_servers_entry_group);
}
+static void update_wide_area_servers(void) {
+ AvahiAddress a[AVAHI_MAX_WIDE_AREA_SERVERS];
+ unsigned n = 0;
+ char **p;
+
+ for (p = resolv_conf; *p && n < AVAHI_MAX_WIDE_AREA_SERVERS; p++) {
+ if (!avahi_address_parse(*p, AVAHI_PROTO_UNSPEC, &a[n]))
+ avahi_log_warn("Failed to parse address '%s', ignoring.", *p);
+ else
+ n++;
+ }
+
+ avahi_server_set_wide_area_servers(avahi_server, a, n);
+
+}
+
static void server_callback(AvahiServer *s, AvahiServerState state, void *userdata) {
DaemonConfig *c = userdata;
#endif
if (state == AVAHI_SERVER_RUNNING) {
- avahi_log_info("Server startup complete. Host name is <%s>", avahi_server_get_host_name_fqdn(s));
+ avahi_log_info("Server startup complete. Host name is %s. Local service cookie is %u.", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s));
static_service_add_to_server();
remove_dns_server_entry_groups();
- if (resolv_conf && resolv_conf[0])
+ if (c->publish_resolv_conf && resolv_conf && resolv_conf[0])
resolv_conf_entry_group = add_dns_servers(s, resolv_conf_entry_group, resolv_conf);
if (c->publish_dns_servers && c->publish_dns_servers[0])
c->server_config.check_response_ttl = is_yes(p->value);
else if (strcasecmp(p->key, "use-iff-running") == 0)
c->server_config.use_iff_running = is_yes(p->value);
-#ifdef HAVE_DBUS
+ else if (strcasecmp(p->key, "disallow-other-stacks") == 0)
+ c->server_config.disallow_other_stacks = is_yes(p->value);
else if (strcasecmp(p->key, "enable-dbus") == 0) {
if (*(p->value) == 'w' || *(p->value) == 'W') {
} else if (*(p->value) == 'y' || *(p->value) == 'Y') {
c->fail_on_missing_dbus = 1;
c->enable_dbus = 1;
- } else
+ } else {
c->enable_dbus = 0;
-
- }
-#endif
- else if (strcasecmp(p->key, "drop-root") == 0)
+ }
+ } else if (strcasecmp(p->key, "drop-root") == 0)
c->drop_root = is_yes(p->value);
+ else if (strcasecmp(p->key, "add-service-cookie") == 0)
+ c->server_config.add_service_cookie = is_yes(p->value);
else {
avahi_log_error("Invalid configuration key \"%s\" in group \"%s\"\n", p->key, g->name);
goto finish;
}
}
+ } else if (strcasecmp(g->name, "wide-area") == 0) {
+ AvahiIniFilePair *p;
+
+ for (p = g->pairs; p; p = p->pairs_next) {
+
+ if (strcasecmp(p->key, "enable-wide-area") == 0)
+ c->server_config.enable_wide_area = is_yes(p->value);
+ else {
+ avahi_log_error("Invalid configuration key \"%s\" in group \"%s\"\n", p->key, g->name);
+ goto finish;
+ }
+ }
+
} else if (strcasecmp(g->name, "reflector") == 0) {
AvahiIniFilePair *p;
avahi_s_entry_group_reset(resolv_conf_entry_group);
load_resolv_conf(&config);
+
+ update_wide_area_servers();
- if (resolv_conf && resolv_conf[0])
+ if (config.publish_resolv_conf && resolv_conf && resolv_conf[0])
resolv_conf_entry_group = add_dns_servers(avahi_server, resolv_conf_entry_group, resolv_conf);
break;
if (simple_protocol_setup(poll_api) < 0)
goto finish;
-
+ if (c->enable_dbus) {
#ifdef HAVE_DBUS
- if (c->enable_dbus)
if (dbus_protocol_setup(poll_api) < 0) {
if (c->fail_on_missing_dbus)
avahi_log_warn("WARNING: Failed to contact D-BUS daemon, disabling D-BUS support.");
c->enable_dbus = 0;
}
+#else
+ avahi_log_warn("WARNING: We are configured to enable D-BUS but it was not compiled in.");
+ c->enable_dbus = 0;
#endif
+ }
load_resolv_conf(c);
static_service_load();
goto finish;
}
+ update_wide_area_servers();
if (c->daemonize)
daemon_retval_send(0);
init_rand_seed();
avahi_server_config_init(&config.server_config);
+ config.server_config.disallow_other_stacks = 1;
config.command = DAEMON_RUN;
config.daemonize = 0;
config.config_file = NULL;
#ifdef HAVE_DBUS
config.enable_dbus = 1;
config.fail_on_missing_dbus = 1;
+#else
+ config.enable_dbus = 0;
+ config.fail_on_missing_dbus = 0;
#endif
config.drop_root = 1;
config.publish_dns_servers = NULL;