close-cd#I6YKN6 【文件管理器】无法访问共享文件夹

This commit is contained in:
wen-jiexiang 2023-05-31 17:50:02 +08:00
parent cd251c38d4
commit 15409cd5a3
1 changed files with 31 additions and 36 deletions

View File

@ -49,7 +49,6 @@
#include "gvfsjobqueryfsinfo.h" #include "gvfsjobqueryfsinfo.h"
#include "gvfsjobqueryattributes.h" #include "gvfsjobqueryattributes.h"
#include "gvfsjobenumerate.h" #include "gvfsjobenumerate.h"
#include "gvfsjobmove.h"
#include "gvfsdaemonprotocol.h" #include "gvfsdaemonprotocol.h"
#include "gvfsdaemonutils.h" #include "gvfsdaemonutils.h"
#include "gvfsutils.h" #include "gvfsutils.h"
@ -78,7 +77,9 @@ struct _GVfsBackendSmb
GMountSource *mount_source; /* Only used/set during mount */ GMountSource *mount_source; /* Only used/set during mount */
int mount_try; int mount_try;
gboolean mount_try_again;
gboolean mount_cancelled; gboolean mount_cancelled;
gboolean use_anonymous;
gboolean password_in_keyring; gboolean password_in_keyring;
GPasswordSave password_save; GPasswordSave password_save;
@ -201,14 +202,25 @@ auth_callback (SMBCCTX *context,
backend->user == NULL && backend->user == NULL &&
backend->domain == NULL) backend->domain == NULL)
{ {
/* Try again if kerberos login fails */
backend->mount_try_again = TRUE;
g_debug ("auth_callback - kerberos pass\n"); g_debug ("auth_callback - kerberos pass\n");
} }
else if (backend->mount_try == 1 && else if (backend->mount_try == 1 &&
backend->user == NULL && backend->user == NULL &&
backend->domain == NULL) backend->domain == NULL)
{ {
/* Try again if ccache login fails */
backend->mount_try_again = TRUE;
g_debug ("auth_callback - ccache pass\n"); g_debug ("auth_callback - ccache pass\n");
} }
else if (backend->use_anonymous)
{
/* Try again if anonymous login fails */
backend->use_anonymous = FALSE;
backend->mount_try_again = TRUE;
g_debug ("auth_callback - anonymous login pass\n");
}
else else
{ {
gboolean in_keyring = FALSE; gboolean in_keyring = FALSE;
@ -251,19 +263,9 @@ auth_callback (SMBCCTX *context,
g_debug ("auth_callback - asking for password...\n"); g_debug ("auth_callback - asking for password...\n");
if (backend->user) /* translators: First %s is a share name, second is a server name */
{ message = g_strdup_printf (_("Password required for share %s on %s"),
/* Translators: First %s is a share name, second is a server name */ share_name, server_name);
message = g_strdup_printf (_("Authentication Required\nEnter password for share “%s” on “%s”:"),
share_name, server_name);
}
else
{
/* Translators: First %s is a share name, second is a server name */
message = g_strdup_printf (_("Authentication Required\nEnter user and password for share “%s” on “%s”:"),
share_name, server_name);
}
handled = g_mount_source_ask_password (backend->mount_source, handled = g_mount_source_ask_password (backend->mount_source,
message, message,
username_out, username_out,
@ -288,13 +290,13 @@ auth_callback (SMBCCTX *context,
} }
} }
smbc_setOptionNoAutoAnonymousLogin (backend->smb_context, /* Try again if this fails */
!anonymous); backend->mount_try_again = TRUE;
if (anonymous) if (anonymous)
{ {
backend->use_anonymous = TRUE;
backend->password_save = FALSE; backend->password_save = FALSE;
g_debug ("auth_callback - anonymous enabled\n");
} }
else else
{ {
@ -484,6 +486,7 @@ do_mount (GVfsBackend *backend,
*/ */
do do
{ {
op_backend->mount_try_again = FALSE;
op_backend->mount_cancelled = FALSE; op_backend->mount_cancelled = FALSE;
g_debug ("do_mount - try #%d \n", op_backend->mount_try); g_debug ("do_mount - try #%d \n", op_backend->mount_try);
@ -499,13 +502,7 @@ do_mount (GVfsBackend *backend,
if (res == 0) if (res == 0)
break; break;
if (errsv == EINVAL && op_backend->mount_try <= 1 && op_backend->user == NULL) if (op_backend->mount_cancelled || (errsv != EACCES && errsv != EPERM))
{
/* EINVAL is "expected" when kerberos/ccache is misconfigured, see:
* https://gitlab.gnome.org/GNOME/gvfs/-/issues/611
*/
}
else if (op_backend->mount_cancelled || (errsv != EACCES && errsv != EPERM))
{ {
g_debug ("do_mount - (errno != EPERM && errno != EACCES), cancelled = %d, breaking\n", op_backend->mount_cancelled); g_debug ("do_mount - (errno != EPERM && errno != EACCES), cancelled = %d, breaking\n", op_backend->mount_cancelled);
break; break;
@ -521,9 +518,15 @@ do_mount (GVfsBackend *backend,
smbc_setOptionFallbackAfterKerberos (op_backend->smb_context, 1); smbc_setOptionFallbackAfterKerberos (op_backend->smb_context, 1);
} }
/* If the AskPassword reply requested anonymous login, enable the
* anonymous fallback and try again.
*/
smbc_setOptionNoAutoAnonymousLogin (op_backend->smb_context,
!op_backend->use_anonymous);
op_backend->mount_try ++; op_backend->mount_try ++;
} }
while (TRUE); while (op_backend->mount_try_again);
g_free (uri); g_free (uri);
@ -1431,8 +1434,6 @@ set_info_from_stat (GVfsBackendSmb *backend,
if (g_file_attribute_matcher_matches (matcher, if (g_file_attribute_matcher_matches (matcher,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) || G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) ||
g_file_attribute_matcher_matches (matcher,
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE) ||
g_file_attribute_matcher_matches (matcher, g_file_attribute_matcher_matches (matcher,
G_FILE_ATTRIBUTE_STANDARD_ICON) || G_FILE_ATTRIBUTE_STANDARD_ICON) ||
g_file_attribute_matcher_matches (matcher, g_file_attribute_matcher_matches (matcher,
@ -1586,7 +1587,6 @@ do_query_fs_info (GVfsBackend *backend,
g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, "cifs"); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, "cifs");
g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE, TRUE);
g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW, G_FILESYSTEM_PREVIEW_TYPE_IF_ALWAYS);
if (g_file_attribute_matcher_matches (attribute_matcher, if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_FILESYSTEM_SIZE) || G_FILE_ATTRIBUTE_FILESYSTEM_SIZE) ||
@ -2041,7 +2041,6 @@ do_move (GVfsBackend *backend,
smbc_stat_fn smbc_stat; smbc_stat_fn smbc_stat;
smbc_rename_fn smbc_rename; smbc_rename_fn smbc_rename;
smbc_unlink_fn smbc_unlink; smbc_unlink_fn smbc_unlink;
goffset size;
source_uri = create_smb_uri (op_backend->server, op_backend->port, op_backend->share, source); source_uri = create_smb_uri (op_backend->server, op_backend->port, op_backend->share, source);
@ -2063,9 +2062,8 @@ do_move (GVfsBackend *backend,
g_free (source_uri); g_free (source_uri);
return; return;
} }
else
source_is_dir = S_ISDIR (statbuf.st_mode); source_is_dir = S_ISDIR (statbuf.st_mode);
size = statbuf.st_size;
dest_uri = create_smb_uri (op_backend->server, op_backend->port, op_backend->share, destination); dest_uri = create_smb_uri (op_backend->server, op_backend->port, op_backend->share, destination);
@ -2160,10 +2158,7 @@ do_move (GVfsBackend *backend,
g_vfs_job_failed_from_errno (G_VFS_JOB (job), errsv); g_vfs_job_failed_from_errno (G_VFS_JOB (job), errsv);
} }
else else
{ g_vfs_job_succeeded (G_VFS_JOB (job));
g_vfs_job_progress_callback (size, size, job);
g_vfs_job_succeeded (G_VFS_JOB (job));
}
} }
static void static void