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