- 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
===================================================================
--- daemon/gvfsbackendnetwork.c (revision 2118)
--- daemon/gvfsbackendnetwork.c (revision 2135)
+++ daemon/gvfsbackendnetwork.c (working copy)
@@ -76,6 +76,8 @@
gboolean have_smb;
@ -213,7 +213,7 @@ Index: daemon/gvfsbackendnetwork.c
g_object_unref (backend->workgroup_icon);
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)
@@ -2,5 +2,5 @@
Type=smb-network;smb-server
@ -224,7 +224,7 @@ Index: daemon/smb-browse.mount.in
Scheme=smb
Index: daemon/gvfsbackendsmbbrowse.c
===================================================================
--- daemon/gvfsbackendsmbbrowse.c (revision 2118)
--- daemon/gvfsbackendsmbbrowse.c (revision 2135)
+++ daemon/gvfsbackendsmbbrowse.c (working copy)
@@ -28,6 +28,7 @@
#include <unistd.h>
@ -242,18 +242,26 @@ Index: daemon/gvfsbackendsmbbrowse.c
#include "gmounttracker.h"
#include <libsmbclient.h>
@@ -56,6 +58,10 @@
@@ -56,6 +58,18 @@
/* The magic "default workgroup" hostname */
#define DEFAULT_WORKGROUP_NAME "X-GNOME-DEFAULT-WORKGROUP"
+/* Time in seconds before we mark dirents cache outdated */
+#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 {
unsigned int smbc_type;
char *name;
@@ -74,7 +80,20 @@
@@ -74,7 +88,20 @@
char *mounted_server; /* server or DEFAULT_WORKGROUP_NAME */
SMBCCTX *smb_context;
@ -274,7 +282,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
time_t last_entry_update;
GList *entries;
int entry_errno;
@@ -206,6 +225,7 @@
@@ -206,6 +233,7 @@
g_free (backend->server);
g_mutex_free (backend->entries_lock);
@ -282,7 +290,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
smbc_free_context (backend->smb_context, TRUE);
@@ -220,6 +240,7 @@
@@ -220,6 +248,7 @@
g_vfs_backend_smb_browse_init (GVfsBackendSmbBrowse *backend)
{
backend->entries_lock = g_mutex_new ();
@ -290,7 +298,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
if (mount_tracker == NULL)
mount_tracker = g_mount_tracker_new (NULL);
@@ -256,14 +277,121 @@
@@ -256,14 +285,129 @@
char *password_out, int pwmaxlen)
{
GVfsBackendSmbBrowse *backend;
@ -312,6 +320,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ /* Don't prompt for credentials, let smbclient finish the mount loop */
+ strncpy (username_out, "ABORT", unmaxlen);
+ strncpy (password_out, "", pwmaxlen);
+ DEBUG ("auth_callback - mount_cancelled\n");
+ return;
+ }
+
@ -333,11 +342,14 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ {
+ /* Try again if kerberos login + anonymous fallback fails */
+ backend->mount_try_again = TRUE;
+ DEBUG ("auth_callback - anonymous pass\n");
+ }
+ else
+ {
+ gboolean in_keyring = FALSE;
+
+ DEBUG ("auth_callback - normal pass\n");
+
+ if (!backend->password_in_keyring)
+ {
+ in_keyring = g_vfs_keyring_lookup_password (backend->user,
@ -365,6 +377,8 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ if (backend->user == NULL)
+ flags |= G_ASK_PASSWORD_NEED_USERNAME;
+
+ DEBUG ("auth_callback - asking for password...\n");
+
+ /* translators: %s is a server name */
+ message = g_strdup_printf (_("Password required for %s"),
+ server_name);
@ -410,10 +424,12 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ backend->last_user = g_strdup (username_out);
+ backend->last_domain = g_strdup (domain_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
@@ -419,8 +547,8 @@
@@ -419,8 +563,8 @@
}
}
@ -424,7 +440,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
{
GString *uri;
char dirents[1024*4];
@@ -436,6 +564,9 @@
@@ -436,7 +580,12 @@
entries = NULL;
entry_errno = 0;
@ -432,9 +448,12 @@ Index: daemon/gvfsbackendsmbbrowse.c
+
+ g_mutex_lock (backend->update_cache_lock);
+ DEBUG ("update_cache - updating...\n");
+
/* Update Cache */
uri = g_string_new ("smb://");
@@ -450,7 +581,7 @@
@@ -450,7 +599,7 @@
smbc_getdents = smbc_getFunctionGetdents (backend->smb_context);
smbc_closedir = smbc_getFunctionClosedir (backend->smb_context);
@ -443,7 +462,21 @@ Index: daemon/gvfsbackendsmbbrowse.c
g_string_free (uri, TRUE);
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);
}
@ -457,9 +490,12 @@ Index: daemon/gvfsbackendsmbbrowse.c
out:
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);
+ DEBUG ("update_cache - done.\n");
+
g_mutex_unlock (backend->entries_lock);
-
+ g_mutex_unlock (backend->update_cache_lock);
@ -468,7 +504,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
}
static BrowseEntry *
@@ -620,10 +754,17 @@
@@ -620,10 +779,17 @@
static gboolean
cache_needs_updating (GVfsBackendSmbBrowse *backend)
{
@ -489,7 +525,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
}
static void
@@ -635,10 +776,17 @@
@@ -635,10 +801,17 @@
{
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
SMBCCTX *smb_context;
@ -508,7 +544,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
smb_context = smbc_new_context ();
if (smb_context == NULL)
{
@@ -650,7 +798,13 @@
@@ -650,7 +823,17 @@
smbc_setOptionUserData (smb_context, backend);
@ -517,13 +553,17 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ if (debug)
+ debug_val = atoi (debug);
+ else
+#ifdef PRINT_DEBUG
+ debug_val = 4;
+#else
+ debug_val = 0;
+#endif
+
+ smbc_setDebug (smb_context, debug_val);
smbc_setFunctionAuthDataWithContext (smb_context, auth_callback);
smbc_setFunctionAddCachedServer (smb_context, add_cached_server);
@@ -666,10 +820,13 @@
@@ -666,10 +849,13 @@
smb_context->flags = 0;
#endif
@ -540,7 +580,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
#if 0
smbc_setOptionDebugToStderr (smb_context, 1);
@@ -723,6 +880,88 @@
@@ -723,6 +909,101 @@
g_vfs_backend_set_mount_spec (backend, browse_mount_spec);
g_mount_spec_unref (browse_mount_spec);
@ -559,22 +599,34 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ g_string_append_c (uri, '/');
+ }
+
+ DEBUG ("do_mount - URI = %s\n", uri->str);
+
+ do
+ {
+ op_backend->mount_try_again = FALSE;
+ op_backend->mount_cancelled = FALSE;
+
+ DEBUG ("do_mount - try #%d \n", op_backend->mount_try);
+
+ 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 &&
+ (op_backend->mount_cancelled || (errno != EPERM && errno != EACCES)))
+ break;
+ {
+ DEBUG ("do_mount - (errno != EPERM && errno != EACCES), breaking\n");
+ break;
+ }
+
+ if (dir != NULL)
+ {
+ /* 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);
+ DEBUG ("do_mount - login successful, res = %d\n", res);
+ if (res)
+ break;
+ }
@ -589,6 +641,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
+ */
+ if (op_backend->mount_try == 0)
+ {
+ DEBUG ("do_mount - after anon, enabling NTLMSSP fallback\n");
+ smbc_setOptionFallbackAfterKerberos (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));
}
@@ -822,7 +1061,7 @@
@@ -822,7 +1103,7 @@
{
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
@ -638,7 +691,7 @@ Index: daemon/gvfsbackendsmbbrowse.c
run_mount_mountable (op_backend,
job,
@@ -878,7 +1117,7 @@
@@ -878,7 +1159,7 @@
{
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);
}
@@ -1052,7 +1291,7 @@
@@ -1052,7 +1333,7 @@
{
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);
}
@@ -1145,9 +1384,9 @@
@@ -1145,9 +1426,9 @@
GFileQueryInfoFlags flags)
{
GVfsBackendSmbBrowse *op_backend = G_VFS_BACKEND_SMB_BROWSE (backend);
@ -668,3 +721,11 @@ Index: daemon/gvfsbackendsmbbrowse.c
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
Name: gvfs
Version: 1.1.2
Release: 1%{?dist}
Release: 2%{?dist}
License: LGPLv2+
Group: System Environment/Libraries
URL: http://www.gtk.org
@ -13,7 +13,7 @@ BuildRequires: dbus-glib-devel
BuildRequires: /usr/bin/ssh
BuildRequires: libcdio-devel >= 0.78.2
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: gnome-keyring-devel
BuildRequires: intltool
@ -258,6 +258,9 @@ update-desktop-database &> /dev/null ||:
%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
- Update to 1.1.2