summaryrefslogtreecommitdiff
path: root/daemon/gvfsbackendsmb.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2008-02-25 14:15:40 +0000
committerAlexander Larsson <alexl@src.gnome.org>2008-02-25 14:15:40 +0000
commit33d8e217717b42a2df50c8533f61a28a4901f18c (patch)
tree4bbdc62fccb33c746d3bc9a0337d94cc539789f2 /daemon/gvfsbackendsmb.c
parentae31680137abeecf238ad811a5dace6090b2360d (diff)
downloadgvfs-33d8e217717b42a2df50c8533f61a28a4901f18c.tar.gz
Support gnome-keyring (#511517) Patch from Carlos Garcia Campos
2008-02-25 Alexander Larsson <alexl@redhat.com> * daemon/gvfsbackendsmb.c: Support gnome-keyring (#511517) Patch from Carlos Garcia Campos svn path=/trunk/; revision=1365
Diffstat (limited to 'daemon/gvfsbackendsmb.c')
-rw-r--r--daemon/gvfsbackendsmb.c87
1 files changed, 59 insertions, 28 deletions
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
index ffb4a65a..f6e24a5d 100644
--- a/daemon/gvfsbackendsmb.c
+++ b/daemon/gvfsbackendsmb.c
@@ -47,6 +47,7 @@
#include "gvfsjobqueryattributes.h"
#include "gvfsjobenumerate.h"
#include "gvfsdaemonprotocol.h"
+#include "gvfskeyring.h"
#ifdef HAVE_GCONF
#include <gconf/gconf-client.h>
@@ -75,6 +76,9 @@ struct _GVfsBackendSmb
GMountSource *mount_source; /* Only used/set during mount */
int mount_try;
gboolean mount_try_again;
+
+ gboolean password_in_keyring;
+ GPasswordSave password_save;
/* Cache */
char *cached_server_name;
@@ -177,36 +181,55 @@ auth_callback (SMBCCTX *context,
}
else
{
- GAskPasswordFlags flags = G_ASK_PASSWORD_NEED_PASSWORD;
- char *message;
+ gboolean in_keyring = FALSE;
+
+ if (!backend->password_in_keyring)
+ {
+ in_keyring = g_vfs_keyring_lookup_password (backend->user,
+ backend->server,
+ backend->domain,
+ "smb",
+ &ask_user,
+ &ask_domain,
+ &ask_password);
+ backend->password_in_keyring = in_keyring;
+ }
- if (backend->domain == NULL)
- flags |= G_ASK_PASSWORD_NEED_DOMAIN;
- if (backend->user == NULL)
- flags |= G_ASK_PASSWORD_NEED_USERNAME;
-
- /* translators: First %s is a share name, second is a server name */
- message = g_strdup_printf (_("Password required for share %s on %s"),
- share_name, server_name);
- handled = g_mount_source_ask_password (backend->mount_source,
- message,
- username_out,
- domain_out,
- flags,
- &abort,
- &ask_password,
- &ask_user,
- &ask_domain,
- NULL);
- g_free (message);
- if (!handled)
- goto out;
+ if (!in_keyring)
+ {
+ GAskPasswordFlags flags = G_ASK_PASSWORD_NEED_PASSWORD;
+ char *message;
- if (abort)
- {
- strncpy (username_out, "ABORT", unmaxlen);
- strncpy (password_out, "", pwmaxlen);
- goto out;
+ if (g_vfs_keyring_is_available ())
+ flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
+ if (backend->domain == NULL)
+ flags |= G_ASK_PASSWORD_NEED_DOMAIN;
+ if (backend->user == NULL)
+ flags |= G_ASK_PASSWORD_NEED_USERNAME;
+
+ /* translators: First %s is a share name, second is a server name */
+ message = g_strdup_printf (_("Password required for share %s on %s"),
+ share_name, server_name);
+ handled = g_mount_source_ask_password (backend->mount_source,
+ message,
+ username_out,
+ domain_out,
+ flags,
+ &abort,
+ &ask_password,
+ &ask_user,
+ &ask_domain,
+ &(backend->password_save));
+ g_free (message);
+ if (!handled)
+ goto out;
+
+ if (abort)
+ {
+ strncpy (username_out, "ABORT", unmaxlen);
+ strncpy (password_out, "", pwmaxlen);
+ goto out;
+ }
}
/* Try again if this fails */
@@ -504,6 +527,7 @@ do_mount (GVfsBackend *backend,
op_backend->mount_source = mount_source;
op_backend->mount_try = 0;
+ op_backend->password_save = G_PASSWORD_SAVE_NEVER;
do
{
@@ -533,6 +557,13 @@ do_mount (GVfsBackend *backend,
_("Failed to mount Windows share"));
return;
}
+
+ g_vfs_keyring_save_password (op_backend->last_user,
+ op_backend->server,
+ op_backend->last_domain,
+ "smb",
+ op_backend->last_password,
+ op_backend->password_save);
g_vfs_job_succeeded (G_VFS_JOB (job));
}