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

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