6b6d0f
From 8c7e79042d819304ea38408d0d90313eef7a3869 Mon Sep 17 00:00:00 2001
6b6d0f
From: Ondrej Holy <oholy@redhat.com>
6b6d0f
Date: Wed, 4 May 2022 13:20:46 +0200
6b6d0f
Subject: [PATCH] smb: Rework anonymous handling to avoid EINVAL
6b6d0f
6b6d0f
After the recent samba change, the "Invalid Argument" error can be still
6b6d0f
returned when anonymous login is requested even after the commit 747c7f6.
6b6d0f
This is because `smbc_setOptionNoAutoAnonymousLogin` is called after returning
6b6d0f
from the `auth_callback` function (i.e. there is one redundant iteration).
6b6d0f
Let's rework the handling a bit and call that immediately, which bypasses
6b6d0f
the issue.
6b6d0f
6b6d0f
Fixes: https://gitlab.gnome.org/GNOME/gvfs/-/issues/619
6b6d0f
---
6b6d0f
 daemon/gvfsbackendsmb.c | 19 ++++---------------
6b6d0f
 1 file changed, 4 insertions(+), 15 deletions(-)
6b6d0f
6b6d0f
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
6b6d0f
index 776b67bc..a1e3eacd 100644
6b6d0f
--- a/daemon/gvfsbackendsmb.c
6b6d0f
+++ b/daemon/gvfsbackendsmb.c
6b6d0f
@@ -80,7 +80,6 @@ struct _GVfsBackendSmb
6b6d0f
   int mount_try;
6b6d0f
   gboolean mount_try_again;
6b6d0f
   gboolean mount_cancelled;
6b6d0f
-  gboolean use_anonymous;
6b6d0f
 	
6b6d0f
   gboolean password_in_keyring;
6b6d0f
   GPasswordSave password_save;
6b6d0f
@@ -215,13 +214,6 @@ auth_callback (SMBCCTX *context,
6b6d0f
       backend->mount_try_again = TRUE;
6b6d0f
       g_debug ("auth_callback - ccache pass\n");
6b6d0f
     }
6b6d0f
-  else if (backend->use_anonymous)
6b6d0f
-    {
6b6d0f
-      /* Try again if anonymous login fails */
6b6d0f
-      backend->use_anonymous = FALSE;
6b6d0f
-      backend->mount_try_again = TRUE;
6b6d0f
-      g_debug ("auth_callback - anonymous login pass\n");
6b6d0f
-    }
6b6d0f
   else
6b6d0f
     {
6b6d0f
       gboolean in_keyring = FALSE;
6b6d0f
@@ -304,10 +296,13 @@ auth_callback (SMBCCTX *context,
6b6d0f
       /* Try again if this fails */
6b6d0f
       backend->mount_try_again = TRUE;
6b6d0f
 
6b6d0f
+      smbc_setOptionNoAutoAnonymousLogin (backend->smb_context,
6b6d0f
+                                          !anonymous);
6b6d0f
+
6b6d0f
       if (anonymous)
6b6d0f
         {
6b6d0f
-          backend->use_anonymous = TRUE;
6b6d0f
           backend->password_save = FALSE;
6b6d0f
+          g_debug ("auth_callback - anonymous enabled\n");
6b6d0f
         }
6b6d0f
       else
6b6d0f
         {
6b6d0f
@@ -535,12 +530,6 @@ do_mount (GVfsBackend *backend,
6b6d0f
           smbc_setOptionFallbackAfterKerberos (op_backend->smb_context, 1);
6b6d0f
         }
6b6d0f
 
6b6d0f
-      /* If the AskPassword reply requested anonymous login, enable the
6b6d0f
-       * anonymous fallback and try again.
6b6d0f
-       */
6b6d0f
-      smbc_setOptionNoAutoAnonymousLogin (op_backend->smb_context,
6b6d0f
-                                          !op_backend->use_anonymous);
6b6d0f
-
6b6d0f
       op_backend->mount_try ++;
6b6d0f
     }
6b6d0f
   while (op_backend->mount_try_again);
6b6d0f
-- 
6b6d0f
2.36.0
6b6d0f