[gvfs/wip/oholy/smb-force-nt1: 4/4] smbbrowse: Force NT1 protocol version for workgroup support



commit 6c8bc39f570ea82cf14e83ce7d1dbdbe569d09d1
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Sep 12 15:28:51 2018 +0200

    smbbrowse: Force NT1 protocol version for workgroup support
    
    "Windows Network" doesn't work with recent samba versions, because
    "client max protocol" has been changed from NT1 to SMB3 recently.
    NT1 is mandatory for workgroup support. Let's force NT1 using the
    newly added smbc_setOptionProtocols API if available. But force this
    only when neither hostname, nor IP address is used. This among others
    prevents complete breakage if NT1 is disabled on server. Use GResolver
    to implement this heuristic.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780958

 daemon/gvfsbackendsmbbrowse.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 meson.build                   |  2 ++
 2 files changed, 44 insertions(+)
---
diff --git a/daemon/gvfsbackendsmbbrowse.c b/daemon/gvfsbackendsmbbrowse.c
index f08d2988..3b11883e 100644
--- a/daemon/gvfsbackendsmbbrowse.c
+++ b/daemon/gvfsbackendsmbbrowse.c
@@ -45,6 +45,7 @@
 #include "gvfskeyring.h"
 #include "gmounttracker.h"
 #include "gvfsbackendsmbprivate.h"
+#include "gvfsutils.h"
 
 #include <libsmbclient.h>
 
@@ -847,6 +848,47 @@ do_mount (GVfsBackend *backend,
   else
     op_backend->server = g_strdup (op_backend->mounted_server);
 
+#ifdef HAVE_SMBC_SETOPTIONPROTOCOLS
+  /* Force NT1 protocol version if server can't be resolved (i.e. is not
+   * hostname, nor IP address). This is needed for workgroup support, because
+   * "client max protocol" has been changed from NT1 to SMB3 in recent samba
+   * versions.
+   */
+
+  if (op_backend->server != NULL)
+    {
+      GResolver *resolver;
+      GList *addresses;
+      GError *error = NULL;
+      gchar *server;
+
+      resolver = g_resolver_get_default ();
+
+      /* IPv6 server includes brackets in GMountSpec, GResolver doesn't */
+      if (gvfs_is_ipv6 (op_backend->server))
+        server = g_strndup (op_backend->server + 1, strlen (op_backend->server) - 2);
+      else
+        server = g_strdup (op_backend->server);
+
+      addresses = g_resolver_lookup_by_name (resolver, server, NULL, &error);
+      if (addresses == NULL)
+        {
+          if (error != NULL)
+            {
+              g_debug ("%s\n", error->message);
+              g_error_free (error);
+            }
+
+          g_debug ("Forcing NT1 protocol version\n");
+          smbc_setOptionProtocols (smb_context, "NT1", "NT1");
+        }
+
+      g_resolver_free_addresses (addresses);
+      g_object_unref (resolver);
+      g_free (server);
+    }
+#endif
+
   icon = NULL;
   symbolic_icon = NULL;
   if (op_backend->server == NULL)
diff --git a/meson.build b/meson.build
index 6b760983..59f840a4 100644
--- a/meson.build
+++ b/meson.build
@@ -387,6 +387,8 @@ config_h.set10('HAVE_LIBUSB', enable_libusb)
 enable_samba = get_option('smb')
 if enable_samba
   smbclient_dep = dependency('smbclient')
+
+  config_h.set('HAVE_SMBC_SETOPTIONPROTOCOLS', cc.has_function('smbc_setOptionProtocols', dependencies: 
smbclient_dep))
 endif
 
 # *** Check for libarchive ***


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