Re: Fixing SMB browsing
- From: Nate Nielsen <nielsen-list memberwebs com>
- To: Federico Mena Quintero <federico ximian com>
- Cc: "gnome-vfs-list gnome org" <gnome-vfs-list gnome org>
- Subject: Re: Fixing SMB browsing
- Date: Wed, 22 Feb 2006 19:55:22 +0000 (GMT)
Federico Mena Quintero wrote:
> On Tue, 2006-02-21 at 03:27 +0000, Nate Nielsen wrote:
>>Without this flag if a certain set of credentials fail, then
>>libsmbclient tries to do an anonymous logon, which from gnome-vfs's
>>point of view unexpected behavior, user confusion and frustration.
>>There's also no real simple way to tell (from within gnome-vfs) whether
>>this 'helpful' behavior occurred or not, but that's beside the point.
>>
>>smb-method tries to do an anonymous login first before prompting the
>>user for a password. Obviously we're doing it wrong, if the only way
>>anonymous logins work is with SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON
>>turned off.
>
> With the flag turned on, all we got during testing is that *every* share
> asked for a password first, even those that should have let you in
> anonymously and without any kind of prompting. With the flag turned
> off, all kinds of shares appear to work fine --- those that let
> anonymous logins never prompt you, and those that require authentication
> prompt you just fine. Maybe I'm just being dumb and empirical, but hey,
> it works :)
It works on your network, in your use case. However it causes regression
in other use cases. Not really acceptable...
Instead of taking the easy way out, I suspect that something like the
attached patch will do the trick. Even if the attach patch doesn't work
for you right off the bat, let's tweak it and make it work.
Cheers,
Nate
Index: modules/smb-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/smb-method.c,v
retrieving revision 1.35
diff -U3 -r1.35 smb-method.c
--- modules/smb-method.c 20 Oct 2005 16:03:59 -0000 1.35
+++ modules/smb-method.c 22 Feb 2006 19:07:54 -0000
@@ -102,6 +102,9 @@
/* The magic "default workgroup" hostname */
#define DEFAULT_WORKGROUP_NAME "X-GNOME-DEFAULT-WORKGROUP"
+/* Guest logins use: */
+#define GUEST_LOGIN "guest"
+
/* 5 minutes before we re-read the workgroup cache again */
#define WORKGROUP_CACHE_TIMEOUT (5*60)
@@ -111,7 +114,8 @@
/* Authentication ----------------------------------------------------------- */
#define SMB_AUTH_STATE_PREFILLED 0x00000010 /* Have asked gnome-auth for prefilled auth */
-#define SMB_AUTH_STATE_PROMPTED 0x00000020 /* Have asked gnome-auth for to prompt user */
+#define SMB_AUTH_STATE_GUEST 0x00000020 /* Have tried 'guest' authentication */
+#define SMB_AUTH_STATE_PROMPTED 0x00000040 /* Have asked gnome-auth for to prompt user */
typedef struct _SmbAuthContext {
@@ -151,7 +155,7 @@
char *username, int unmaxlen,
char *password, int pwmaxlen);
-#if 0
+#if 1
#define DEBUG_SMB_ENABLE
#define DEBUG_SMB_LOCKS
#endif
@@ -828,9 +832,9 @@
server = g_hash_table_lookup (server_cache, &server_lookup);
if (server == NULL) {
- /* If a blank user, try 'guest' */
+ /* If a blank user, try looking up 'guest' */
if (!actx->use_user) {
- server_lookup.username = "guest";
+ server_lookup.username = GUEST_LOGIN;
server_lookup.domain = NULL;
server = g_hash_table_lookup (server_cache, &server_lookup);
}
@@ -949,7 +953,12 @@
in_args.domain = (char*)actx->use_domain;
in_args.port = actx->uri ? ((GnomeVFSToplevelURI*)actx->uri)->host_port : 0;
- in_args.default_user = actx->use_user ? actx->use_user : (char*)g_get_user_name ();
+ in_args.default_user = actx->use_user;
+ if (string_compare (in_args.default_user, GUEST_LOGIN))
+ in_args.default_user = NULL;
+ if (!in_args.default_user)
+ in_args.default_user = (char*)g_get_user_name ();
+
in_args.default_domain = actx->use_domain ? actx->use_domain : smb_context->workgroup;
memset (&out_args, 0, sizeof (out_args));
@@ -1198,12 +1207,26 @@
cont = FALSE;
UNLOCK_SMB();
-
+
+ /* Do we have gnome-keyring credentials for this? */
if (!(actx->state & SMB_AUTH_STATE_PREFILLED)) {
actx->state |= SMB_AUTH_STATE_PREFILLED;
cont = prefill_authentication (actx);
}
-
+
+ /* Then we try a guest credentials... */
+ if (!cont && !(actx->state & SMB_AUTH_STATE_GUEST)) {
+ g_free (actx->use_user);
+ actx->use_user = strdup(GUEST_LOGIN);
+ g_free (actx->use_domain);
+ actx->use_domain = NULL;
+ g_free (actx->use_password);
+ actx->use_password = strdup("");
+ actx->state |= SMB_AUTH_STATE_GUEST;
+ cont = TRUE;
+ }
+
+ /* And as a last step, prompt */
if (!cont)
cont = prompt_authentication (actx, &auth_cancelled);
@@ -1279,19 +1302,17 @@
strncpy (password_out, actx->use_password ? actx->use_password : "", pwmaxlen);
if (actx->use_domain)
strncpy (domain_out, actx->use_domain, domainmaxlen);
- DEBUG_SMB(("[auth] Using credentials: %s:%s %s\n", username_out, password_out, domain_out));
-
- /* On first login try a guest login */
- } else if (actx->passes == 1) {
- strncpy (username_out, "guest", unmaxlen);
- strncpy (password_out, "", pwmaxlen);
- DEBUG_SMB(("[auth] No credentials, trying 'guest' user login\n"));
-
- /* We have no credentials ... */
+ DEBUG_SMB(("[auth] Using credentials: %s:%s %s\n", username_out, password_out, domain_out));
+
+ /* We have no credentials ... */
} else {
+ if (actx->passes == 1)
+ DEBUG_SMB(("[auth] No credentials, trying anonymous user login\n"));
+ else
+ DEBUG_SMB(("[auth] No credentials, returning null values\n"));
+
strncpy (username_out, "", unmaxlen);
strncpy (password_out, "", pwmaxlen);
- DEBUG_SMB(("[auth] No credentials, returning null values\n"));
}
/* Put in the default workgroup if none specified */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]