- Update the smb-browse auth patch

This commit is contained in:
Tomas Bzatek 2008-12-17 10:12:27 +00:00
parent 5ded5a2660
commit 027e464334
2 changed files with 90 additions and 26 deletions

View File

@ -1,6 +1,6 @@
Index: daemon/gvfsbackendnetwork.c Index: daemon/gvfsbackendnetwork.c
=================================================================== ===================================================================
--- daemon/gvfsbackendnetwork.c (revision 2118) --- daemon/gvfsbackendnetwork.c (revision 2135)
+++ daemon/gvfsbackendnetwork.c (working copy) +++ daemon/gvfsbackendnetwork.c (working copy)
@@ -76,6 +76,8 @@ @@ -76,6 +76,8 @@
gboolean have_smb; gboolean have_smb;
@ -213,7 +213,7 @@ Index: daemon/gvfsbackendnetwork.c
g_object_unref (backend->workgroup_icon); g_object_unref (backend->workgroup_icon);
Index: daemon/smb-browse.mount.in Index: daemon/smb-browse.mount.in
=================================================================== ===================================================================
--- daemon/smb-browse.mount.in (revision 2118) --- daemon/smb-browse.mount.in (revision 2135)
+++ daemon/smb-browse.mount.in (working copy) +++ daemon/smb-browse.mount.in (working copy)
@@ -2,5 +2,5 @@ @@ -2,5 +2,5 @@
Type=smb-network;smb-server Type=smb-network;smb-server
@ -224,7 +224,7 @@ Index: daemon/smb-browse.mount.in
Scheme=smb Scheme=smb
Index: daemon/gvfsbackendsmbbrowse.c Index: daemon/gvfsbackendsmbbrowse.c
=================================================================== ===================================================================
--- daemon/gvfsbackendsmbbrowse.c (revision 2118) --- daemon/gvfsbackendsmbbrowse.c (revision 2135)
+++ daemon/gvfsbackendsmbbrowse.c (working copy) +++ daemon/gvfsbackendsmbbrowse.c (working copy)
@@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#include <unistd.h> #include <unistd.h>
@ -242,18 +242,26 @@ Index: daemon/gvfsbackendsmbbrowse.c
#include "gmounttracker.h" #include "gmounttracker.h"
#include <libsmbclient.h> #include <libsmbclient.h>
@@ -56,6 +58,10 @@ @@ -56,6 +58,18 @@
/* The magic "default workgroup" hostname */ /* The magic "default workgroup" hostname */
#define DEFAULT_WORKGROUP_NAME "X-GNOME-DEFAULT-WORKGROUP" #define DEFAULT_WORKGROUP_NAME "X-GNOME-DEFAULT-WORKGROUP"
+/* Time in seconds before we mark dirents cache outdated */ +/* Time in seconds before we mark dirents cache outdated */
+#define DEFAULT_CACHE_EXPIRATION_TIME 10 +#define DEFAULT_CACHE_EXPIRATION_TIME 10
+ +
+
+#define PRINT_DEBUG
+
+#ifdef PRINT_DEBUG
+#define DEBUG(msg...) g_print("### SMB-BROWSE: " msg)
+#else
+#define DEBUG(...)
+#endif
+ +
typedef struct { typedef struct {
unsigned int smbc_type; unsigned int smbc_type;
char *name; char *name;
@@ -74,7 +80,20 @@ @@ -74,7 +88,20 @@
char *mounted_server; /* server or DEFAULT_WORKGROUP_NAME */ char *mounted_server; /* server or DEFAULT_WORKGROUP_NAME */
SMBCCTX *smb_context; SMBCCTX *smb_context;
@ -274,7 +282,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
time_t last_entry_update; time_t last_entry_update;
GList *entries; GList *entries;
int entry_errno; int entry_errno;
@@ -206,6 +225,7 @@ @@ -206,6 +233,7 @@
g_free (backend->server); g_free (backend->server);
g_mutex_free (backend->entries_lock); g_mutex_free (backend->entries_lock);
@ -282,7 +290,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
smbc_free_context (backend->smb_context, TRUE); smbc_free_context (backend->smb_context, TRUE);
@@ -220,6 +240,7 @@ @@ -220,6 +248,7 @@
g_vfs_backend_smb_browse_init (GVfsBackendSmbBrowse *backend) g_vfs_backend_smb_browse_init (GVfsBackendSmbBrowse *backend)
{ {
backend->entries_lock = g_mutex_new (); backend->entries_lock = g_mutex_new ();
@ -290,7 +298,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
if (mount_tracker == NULL) if (mount_tracker == NULL)
mount_tracker = g_mount_tracker_new (NULL); mount_tracker = g_mount_tracker_new (NULL);
@@ -256,14 +277,121 @@ @@ -256,14 +285,129 @@
char *password_out, int pwmaxlen) char *password_out, int pwmaxlen)
{ {
GVfsBackendSmbBrowse *backend; GVfsBackendSmbBrowse *backend;
@ -312,6 +320,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ /* Don't prompt for credentials, let smbclient finish the mount loop */ + /* Don't prompt for credentials, let smbclient finish the mount loop */
+ strncpy (username_out, "ABORT", unmaxlen); + strncpy (username_out, "ABORT", unmaxlen);
+ strncpy (password_out, "", pwmaxlen); + strncpy (password_out, "", pwmaxlen);
+ DEBUG ("auth_callback - mount_cancelled\n");
+ return; + return;
+ } + }
+ +
@ -333,11 +342,14 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ { + {
+ /* Try again if kerberos login + anonymous fallback fails */ + /* Try again if kerberos login + anonymous fallback fails */
+ backend->mount_try_again = TRUE; + backend->mount_try_again = TRUE;
+ DEBUG ("auth_callback - anonymous pass\n");
+ } + }
+ else + else
+ { + {
+ gboolean in_keyring = FALSE; + gboolean in_keyring = FALSE;
+ +
+ DEBUG ("auth_callback - normal pass\n");
+
+ if (!backend->password_in_keyring) + if (!backend->password_in_keyring)
+ { + {
+ in_keyring = g_vfs_keyring_lookup_password (backend->user, + in_keyring = g_vfs_keyring_lookup_password (backend->user,
@ -365,6 +377,8 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ if (backend->user == NULL) + if (backend->user == NULL)
+ flags |= G_ASK_PASSWORD_NEED_USERNAME; + flags |= G_ASK_PASSWORD_NEED_USERNAME;
+ +
+ DEBUG ("auth_callback - asking for password...\n");
+
+ /* translators: %s is a server name */ + /* translators: %s is a server name */
+ message = g_strdup_printf (_("Password required for %s"), + message = g_strdup_printf (_("Password required for %s"),
+ server_name); + server_name);
@ -410,10 +424,12 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ backend->last_user = g_strdup (username_out); + backend->last_user = g_strdup (username_out);
+ backend->last_domain = g_strdup (domain_out); + backend->last_domain = g_strdup (domain_out);
+ backend->last_password = g_strdup (password_out); + backend->last_password = g_strdup (password_out);
+ DEBUG ("auth_callback - out: last_user = '%s', last_domain = '%s'\n",
+ backend->last_user, backend->last_domain);
} }
/* Add a server to the cache system /* Add a server to the cache system
@@ -419,8 +547,8 @@ @@ -419,8 +563,8 @@
} }
} }
@ -424,7 +440,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
{ {
GString *uri; GString *uri;
char dirents[1024*4]; char dirents[1024*4];
@@ -436,6 +564,9 @@ @@ -436,7 +580,12 @@
entries = NULL; entries = NULL;
entry_errno = 0; entry_errno = 0;
@ -432,9 +448,12 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ +
+ g_mutex_lock (backend->update_cache_lock); + g_mutex_lock (backend->update_cache_lock);
+ DEBUG ("update_cache - updating...\n");
+
/* Update Cache */ /* Update Cache */
uri = g_string_new ("smb://"); uri = g_string_new ("smb://");
@@ -450,7 +581,7 @@
@@ -450,7 +599,7 @@
smbc_getdents = smbc_getFunctionGetdents (backend->smb_context); smbc_getdents = smbc_getFunctionGetdents (backend->smb_context);
smbc_closedir = smbc_getFunctionClosedir (backend->smb_context); smbc_closedir = smbc_getFunctionClosedir (backend->smb_context);
@ -443,7 +462,21 @@ Index: daemon/gvfsbackendsmbbrowse.c
g_string_free (uri, TRUE); g_string_free (uri, TRUE);
if (dir == NULL) if (dir == NULL)
{ {
@@ -494,10 +625,11 @@ @@ -462,7 +611,12 @@
{
res = smbc_getdents (backend->smb_context, dir, (struct smbc_dirent *)dirents, sizeof (dirents));
if (res <= 0)
- break;
+ {
+ if (res < 0)
+ DEBUG ("update_cache - smbc_getdents returned %d, errno = [%d] %s\n",
+ res, errno, strerror (errno));
+ break;
+ }
dirp = (struct smbc_dirent *)dirents;
while (res > 0)
@@ -494,10 +648,11 @@
entries = g_list_reverse (entries); entries = g_list_reverse (entries);
} }
@ -457,9 +490,12 @@ Index: daemon/gvfsbackendsmbbrowse.c
out: out:
g_mutex_lock (backend->entries_lock); g_mutex_lock (backend->entries_lock);
@@ -510,7 +642,9 @@ @@ -509,8 +664,12 @@
backend->entry_errno = entry_errno;
backend->last_entry_update = time (NULL); backend->last_entry_update = time (NULL);
+ DEBUG ("update_cache - done.\n");
+
g_mutex_unlock (backend->entries_lock); g_mutex_unlock (backend->entries_lock);
- -
+ g_mutex_unlock (backend->update_cache_lock); + g_mutex_unlock (backend->update_cache_lock);
@ -468,7 +504,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
} }
static BrowseEntry * static BrowseEntry *
@@ -620,10 +754,17 @@ @@ -620,10 +779,17 @@
static gboolean static gboolean
cache_needs_updating (GVfsBackendSmbBrowse *backend) cache_needs_updating (GVfsBackendSmbBrowse *backend)
{ {
@ -489,7 +525,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
} }
static void static void
@@ -635,10 +776,17 @@ @@ -635,10 +801,17 @@
{ {
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend); GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
SMBCCTX *smb_context; SMBCCTX *smb_context;
@ -508,7 +544,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
smb_context = smbc_new_context (); smb_context = smbc_new_context ();
if (smb_context == NULL) if (smb_context == NULL)
{ {
@@ -650,7 +798,13 @@ @@ -650,7 +823,17 @@
smbc_setOptionUserData (smb_context, backend); smbc_setOptionUserData (smb_context, backend);
@ -517,13 +553,17 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ if (debug) + if (debug)
+ debug_val = atoi (debug); + debug_val = atoi (debug);
+ else + else
+#ifdef PRINT_DEBUG
+ debug_val = 4;
+#else
+ debug_val = 0; + debug_val = 0;
+#endif
+ +
+ smbc_setDebug (smb_context, debug_val); + smbc_setDebug (smb_context, debug_val);
smbc_setFunctionAuthDataWithContext (smb_context, auth_callback); smbc_setFunctionAuthDataWithContext (smb_context, auth_callback);
smbc_setFunctionAddCachedServer (smb_context, add_cached_server); smbc_setFunctionAddCachedServer (smb_context, add_cached_server);
@@ -666,10 +820,13 @@ @@ -666,10 +849,13 @@
smb_context->flags = 0; smb_context->flags = 0;
#endif #endif
@ -540,7 +580,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
#if 0 #if 0
smbc_setOptionDebugToStderr (smb_context, 1); smbc_setOptionDebugToStderr (smb_context, 1);
@@ -723,6 +880,88 @@ @@ -723,6 +909,101 @@
g_vfs_backend_set_mount_spec (backend, browse_mount_spec); g_vfs_backend_set_mount_spec (backend, browse_mount_spec);
g_mount_spec_unref (browse_mount_spec); g_mount_spec_unref (browse_mount_spec);
@ -559,22 +599,34 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ g_string_append_c (uri, '/'); + g_string_append_c (uri, '/');
+ } + }
+ +
+ DEBUG ("do_mount - URI = %s\n", uri->str);
+
+ do + do
+ { + {
+ op_backend->mount_try_again = FALSE; + op_backend->mount_try_again = FALSE;
+ op_backend->mount_cancelled = FALSE; + op_backend->mount_cancelled = FALSE;
+ +
+ DEBUG ("do_mount - try #%d \n", op_backend->mount_try);
+
+ dir = smbc_opendir (smb_context, uri->str); + dir = smbc_opendir (smb_context, uri->str);
+ +
+ DEBUG ("do_mount - [%s; %d] dir = %p, cancelled = %d, errno = [%d] '%s' \n",
+ uri->str, op_backend->mount_try, dir, op_backend->mount_cancelled,
+ errno, strerror (errno));
+
+ if (dir == NULL && + if (dir == NULL &&
+ (op_backend->mount_cancelled || (errno != EPERM && errno != EACCES))) + (op_backend->mount_cancelled || (errno != EPERM && errno != EACCES)))
+ break; + {
+ DEBUG ("do_mount - (errno != EPERM && errno != EACCES), breaking\n");
+ break;
+ }
+ +
+ if (dir != NULL) + if (dir != NULL)
+ { + {
+ /* Let update_cache() do enumeration, check for the smbc_getdents() result */ + /* Let update_cache() do enumeration, check for the smbc_getdents() result */
+ res = update_cache (op_backend, dir); + res = update_cache (op_backend, dir);
+ smbc_closedir (smb_context, dir); + smbc_closedir (smb_context, dir);
+ DEBUG ("do_mount - login successful, res = %d\n", res);
+ if (res) + if (res)
+ break; + break;
+ } + }
@ -589,6 +641,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ */ + */
+ if (op_backend->mount_try == 0) + if (op_backend->mount_try == 0)
+ { + {
+ DEBUG ("do_mount - after anon, enabling NTLMSSP fallback\n");
+ smbc_setOptionFallbackAfterKerberos (op_backend->smb_context, 1); + smbc_setOptionFallbackAfterKerberos (op_backend->smb_context, 1);
+ smbc_setOptionNoAutoAnonymousLogin (op_backend->smb_context, 1); + smbc_setOptionNoAutoAnonymousLogin (op_backend->smb_context, 1);
+ } + }
@ -629,7 +682,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
g_vfs_job_succeeded (G_VFS_JOB (job)); g_vfs_job_succeeded (G_VFS_JOB (job));
} }
@@ -822,7 +1061,7 @@ @@ -822,7 +1103,7 @@
{ {
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend); GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
@ -638,7 +691,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
run_mount_mountable (op_backend, run_mount_mountable (op_backend,
job, job,
@@ -878,7 +1117,7 @@ @@ -878,7 +1159,7 @@
{ {
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend); GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
@ -647,7 +700,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
run_open_for_read (op_backend, job, filename); run_open_for_read (op_backend, job, filename);
} }
@@ -1052,7 +1291,7 @@ @@ -1052,7 +1333,7 @@
{ {
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend); GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
@ -656,7 +709,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
run_query_info (op_backend, job, filename, info, matcher); run_query_info (op_backend, job, filename, info, matcher);
} }
@@ -1145,9 +1384,9 @@ @@ -1145,9 +1426,9 @@
GFileQueryInfoFlags flags) GFileQueryInfoFlags flags)
{ {
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend); GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
@ -668,3 +721,11 @@ Index: daemon/gvfsbackendsmbbrowse.c
run_enumerate (op_backend, job, filename, matcher); run_enumerate (op_backend, job, filename, matcher);
} }
@@ -1211,6 +1492,7 @@
}
#endif
+ DEBUG ("g_vfs_backend_smb_browse_class_init - default workgroup = '%s'\n", default_workgroup);
}
void

View File

@ -1,7 +1,7 @@
Summary: Backends for the gio framework in GLib Summary: Backends for the gio framework in GLib
Name: gvfs Name: gvfs
Version: 1.1.2 Version: 1.1.2
Release: 1%{?dist} Release: 2%{?dist}
License: LGPLv2+ License: LGPLv2+
Group: System Environment/Libraries Group: System Environment/Libraries
URL: http://www.gtk.org URL: http://www.gtk.org
@ -13,7 +13,7 @@ BuildRequires: dbus-glib-devel
BuildRequires: /usr/bin/ssh BuildRequires: /usr/bin/ssh
BuildRequires: libcdio-devel >= 0.78.2 BuildRequires: libcdio-devel >= 0.78.2
BuildRequires: hal-devel >= 0.5.10 BuildRequires: hal-devel >= 0.5.10
BuildRequires: libsoup-devel >= 2.23.91 BuildRequires: libsoup-devel >= 2.25.2
BuildRequires: avahi-glib-devel >= 0.6 BuildRequires: avahi-glib-devel >= 0.6
BuildRequires: gnome-keyring-devel BuildRequires: gnome-keyring-devel
BuildRequires: intltool BuildRequires: intltool
@ -258,6 +258,9 @@ update-desktop-database &> /dev/null ||:
%changelog %changelog
* Wed Dec 17 2008 Tomas Bzatek <tbzatek@redhat.com> - 1.1.2-2
- Update the smb-browse auth patch
* Tue Dec 16 2008 Matthias Clasen <mclasen@redhat.com> - 1.1.2-1 * Tue Dec 16 2008 Matthias Clasen <mclasen@redhat.com> - 1.1.2-1
- Update to 1.1.2 - Update to 1.1.2