[gvfs/wip/oholy/davs-sd-ipv6: 2/2] dav: Add support for services with IPv6 link-local addresses



commit 7893ad8d714c5325ead895a59adad251edfb88bd
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Oct 10 17:33:04 2019 +0200

    dav: Add support for services with IPv6 link-local addresses
    
    The mount operation currently fails with "Invalid argument" error if
    GVfsDnsSdResolver returns link-local IPv6 address. This can quite easily
    happen also when using File Share functionality provided by GNOME. It
    fails because the link-local addresses requires interface to be specified.
    Let's append the interface in them to fix this issue.
    
    Fixes: https://gitlab.gnome.org/GNOME/gvfs/issues/423

 daemon/gvfsbackenddav.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/daemon/gvfsbackenddav.c b/daemon/gvfsbackenddav.c
index 05297548..0db8d555 100644
--- a/daemon/gvfsbackenddav.c
+++ b/daemon/gvfsbackenddav.c
@@ -1763,11 +1763,13 @@ dav_uri_from_dns_sd_resolver (GVfsBackendDav *dav_backend)
   char       *user;
   char       *path;
   char       *address;
+  gchar      *interface;
   const char *service_type;
   guint       port;
 
   service_type = g_vfs_dns_sd_resolver_get_service_type (dav_backend->resolver);
   address = g_vfs_dns_sd_resolver_get_address (dav_backend->resolver);
+  interface = g_vfs_dns_sd_resolver_get_interface (dav_backend->resolver);
   port = g_vfs_dns_sd_resolver_get_port (dav_backend->resolver);
   user = g_vfs_dns_sd_resolver_lookup_txt_record (dav_backend->resolver, "u"); /* mandatory */
   path = g_vfs_dns_sd_resolver_lookup_txt_record (dav_backend->resolver, "path"); /* optional */
@@ -1789,7 +1791,16 @@ dav_uri_from_dns_sd_resolver (GVfsBackendDav *dav_backend)
 
   /* IPv6 host does not include brackets in SoupURI, but GVfsDnsSdResolver host does */
   if (gvfs_is_ipv6 (address))
-    uri->host = g_strndup (address + 1, strlen (address) - 2);
+    {
+      /* Link-local addresses require interface to be specified. */
+      if (g_str_has_prefix (address, "[fe80:") && interface != NULL)
+        {
+          uri->host = g_strconcat (address + 1, interface, NULL);
+          uri->host[strlen (address) - 2] = '%';
+        }
+      else
+        uri->host = g_strndup (address + 1, strlen (address) - 2);
+    }
   else
     soup_uri_set_host (uri, address);
 
@@ -1800,6 +1811,7 @@ dav_uri_from_dns_sd_resolver (GVfsBackendDav *dav_backend)
 
 
   g_free (address);
+  g_free (interface);
   g_free (user);
   g_free (path);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]