]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/main.c
* make all flags parameters UINT32 when marshalling for DBUS
[catta] / avahi-daemon / main.c
index 566a276d599355d4b23324b142fc6e01ac1c0ce4..de74178d7079b55ad71fe6aa026fa01ccdf52a17 100644 (file)
@@ -50,6 +50,7 @@
 #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"
@@ -104,8 +105,6 @@ static char **resolv_conf = NULL;
 
 static DaemonConfig config;
 
-#define MAX_NAME_SERVERS 10
-
 static int has_prefix(const char *s, const char *prefix) {
     size_t l;
 
@@ -122,17 +121,14 @@ static int load_resolv_conf(const DaemonConfig *c) {
     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;
 
@@ -179,10 +175,10 @@ static AvahiSEntryGroup* add_dns_servers(AvahiServer *s, AvahiSEntryGroup* g, ch
     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;
@@ -203,6 +199,22 @@ static void remove_dns_server_entry_groups(void) {
         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;
     
@@ -220,12 +232,12 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void *userda
 #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])
@@ -381,6 +393,8 @@ static int load_config_file(DaemonConfig *c) {
                     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);
+                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') {
@@ -392,9 +406,10 @@ static int load_config_file(DaemonConfig *c) {
                     } else {
                         c->enable_dbus = 0;
                     }
-                }
-                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;
@@ -425,6 +440,19 @@ static int load_config_file(DaemonConfig *c) {
                 }
             }
 
+        } 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;
 
@@ -550,8 +578,10 @@ static void signal_callback(AvahiWatch *watch, int fd, AvahiWatchEvent event, vo
                 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;
@@ -619,6 +649,7 @@ static int run_server(DaemonConfig *c) {
         goto finish;
     }
 
+    update_wide_area_servers();
 
     if (c->daemonize)
         daemon_retval_send(0);
@@ -842,6 +873,7 @@ int main(int argc, char *argv[]) {
     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;