Blame SOURCES/smbbrowse-Force-NT1-protocol-version-for-workgroup-s.patch

0b0087
diff --git a/configure.ac b/configure.ac
0b0087
index 3b5836ff..daeee728 100644
0b0087
--- a/configure.ac
0b0087
+++ b/configure.ac
0b0087
@@ -546,6 +546,11 @@ if test "x$enable_samba" != "xno"; then
0b0087
   if test "x$msg_samba" = "xyes"; then
0b0087
     PKG_CHECK_MODULES([SAMBA], [smbclient])
0b0087
     AC_DEFINE([HAVE_SAMBA], 1, [Define to 1 if you have the samba libraries])
0b0087
+
0b0087
+    AC_CHECK_LIB(smbclient, smbc_setOptionProtocols,
0b0087
+        AC_DEFINE(HAVE_SMBC_SETOPTIONPROTOCOLS, 1, [Define to 1 if smbc_setOptionProtocols() is available]),
0b0087
+        []
0b0087
+    )
0b0087
   fi
0b0087
 fi
0b0087
 
0b0087
diff --git a/daemon/gvfsbackendsmbbrowse.c b/daemon/gvfsbackendsmbbrowse.c
0b0087
index f08d2988..3b11883e 100644
0b0087
--- a/daemon/gvfsbackendsmbbrowse.c
0b0087
+++ b/daemon/gvfsbackendsmbbrowse.c
0b0087
@@ -45,6 +45,7 @@
0b0087
 #include "gvfskeyring.h"
0b0087
 #include "gmounttracker.h"
0b0087
 #include "gvfsbackendsmbprivate.h"
0b0087
+#include "gvfsutils.h"
0b0087
 
0b0087
 #include <libsmbclient.h>
0b0087
 
0b0087
@@ -847,6 +848,47 @@ do_mount (GVfsBackend *backend,
0b0087
   else
0b0087
     op_backend->server = g_strdup (op_backend->mounted_server);
0b0087
 
0b0087
+#ifdef HAVE_SMBC_SETOPTIONPROTOCOLS
0b0087
+  /* Force NT1 protocol version if server can't be resolved (i.e. is not
0b0087
+   * hostname, nor IP address). This is needed for workgroup support, because
0b0087
+   * "client max protocol" has been changed from NT1 to SMB3 in recent samba
0b0087
+   * versions.
0b0087
+   */
0b0087
+
0b0087
+  if (op_backend->server != NULL)
0b0087
+    {
0b0087
+      GResolver *resolver;
0b0087
+      GList *addresses;
0b0087
+      GError *error = NULL;
0b0087
+      gchar *server;
0b0087
+
0b0087
+      resolver = g_resolver_get_default ();
0b0087
+
0b0087
+      /* IPv6 server includes brackets in GMountSpec, GResolver doesn't */
0b0087
+      if (gvfs_is_ipv6 (op_backend->server))
0b0087
+        server = g_strndup (op_backend->server + 1, strlen (op_backend->server) - 2);
0b0087
+      else
0b0087
+        server = g_strdup (op_backend->server);
0b0087
+
0b0087
+      addresses = g_resolver_lookup_by_name (resolver, server, NULL, &error);
0b0087
+      if (addresses == NULL)
0b0087
+        {
0b0087
+          if (error != NULL)
0b0087
+            {
0b0087
+              g_debug ("%s\n", error->message);
0b0087
+              g_error_free (error);
0b0087
+            }
0b0087
+
0b0087
+          g_debug ("Forcing NT1 protocol version\n");
0b0087
+          smbc_setOptionProtocols (smb_context, "NT1", "NT1");
0b0087
+        }
0b0087
+
0b0087
+      g_resolver_free_addresses (addresses);
0b0087
+      g_object_unref (resolver);
0b0087
+      g_free (server);
0b0087
+    }
0b0087
+#endif
0b0087
+
0b0087
   icon = NULL;
0b0087
   symbolic_icon = NULL;
0b0087
   if (op_backend->server == NULL)
0b0087
diff --git a/meson.build b/meson.build
0b0087
index 34600188..3a876172 100644
0b0087
--- a/meson.build
0b0087
+++ b/meson.build
0b0087
@@ -416,6 +416,8 @@ config_h.set10('HAVE_LIBUSB', enable_libusb)
0b0087
 enable_samba = get_option('smb')
0b0087
 if enable_samba
0b0087
   smbclient_dep = dependency('smbclient')
0b0087
+
0b0087
+  config_h.set('HAVE_SMBC_SETOPTIONPROTOCOLS', cc.has_function('smbc_setOptionProtocols', dependencies: smbclient_dep))
0b0087
 endif
0b0087
 
0b0087
 # *** Check for libarchive ***