summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2008-02-25 20:08:28 +0000
committerCarlos Garcia Campos <carlosgc@src.gnome.org>2008-02-25 20:08:28 +0000
commite4af3df72bf4aa44e539db78d95ff311990eb512 (patch)
tree85f2f3a76412246d4883a894e2918d47a2342861 /daemon
parentd966b3ade7d0d864f827417b015251454d96e9e2 (diff)
downloadgvfs-e4af3df72bf4aa44e539db78d95ff311990eb512.tar.gz
Update to gvfskeyring api changes
2008-02-25 Carlos Garcia Campos <carlosgc@gnome.org> * daemon/gvfsbackendsftp.c: * daemon/gvfsbackendsmb.c: Update to gvfskeyring api changes * daemon/gvfskeyring.c: * daemon/gvfskeyring.h: Add object, authtype and port parameters for both save and lookup. svn path=/trunk/; revision=1374
Diffstat (limited to 'daemon')
-rw-r--r--daemon/gvfsbackendsftp.c51
-rw-r--r--daemon/gvfsbackendsmb.c6
-rw-r--r--daemon/gvfskeyring.c52
-rw-r--r--daemon/gvfskeyring.h6
4 files changed, 92 insertions, 23 deletions
diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c
index cd39379d..4c33e818 100644
--- a/daemon/gvfsbackendsftp.c
+++ b/daemon/gvfsbackendsftp.c
@@ -24,6 +24,7 @@
#include <config.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
@@ -658,6 +659,38 @@ get_hostname_and_fingerprint_from_line (const gchar *buffer,
return TRUE;
}
+static const gchar *
+get_authtype_from_password_line (const char *password_line)
+{
+ return g_str_has_prefix (password_line, "Enter passphrase for key") ?
+ "publickey" : "password";
+}
+
+static char *
+get_object_from_password_line (const char *password_line)
+{
+ char *chr, *ptr, *object = NULL;
+
+ if (g_str_has_prefix (password_line, "Enter passphrase for key"))
+ {
+ ptr = strchr (password_line, '\'');
+ if (ptr != NULL)
+ {
+ ptr += 1;
+ chr = strchr (ptr, '\'');
+ if (chr != NULL)
+ {
+ object = g_strndup (ptr, chr - ptr);
+ }
+ else
+ {
+ object = g_strdup (ptr);
+ }
+ }
+ }
+ return object;
+}
+
static gboolean
handle_login (GVfsBackend *backend,
GMountSource *mount_source,
@@ -680,6 +713,8 @@ handle_login (GVfsBackend *backend,
GPasswordSave password_save = G_PASSWORD_SAVE_NEVER;
gsize bytes_written;
gboolean password_in_keyring = FALSE;
+ const gchar *authtype = NULL;
+ gchar *object = NULL;
if (op_backend->client_vendor == SFTP_VENDOR_SSH)
prompt_fd = stderr_fd;
@@ -751,12 +786,21 @@ handle_login (GVfsBackend *backend,
g_str_has_suffix (buffer, "Password:") ||
g_str_has_prefix (buffer, "Enter passphrase for key"))
{
+ authtype = get_authtype_from_password_line (buffer);
+ object = get_object_from_password_line (buffer);
+
/* If password is in keyring at this point is because it failed */
if (!op_backend->tmp_password && (password_in_keyring ||
!g_vfs_keyring_lookup_password (op_backend->user,
op_backend->host,
NULL,
"sftp",
+ object,
+ authtype,
+ op_backend->port != -1 ?
+ op_backend->port
+ :
+ 0,
NULL,
NULL,
&new_password)))
@@ -906,10 +950,17 @@ handle_login (GVfsBackend *backend,
op_backend->host,
NULL,
"sftp",
+ object,
+ authtype,
+ op_backend->port != -1 ?
+ op_backend->port
+ :
+ 0,
new_password,
password_save);
}
+ g_free (object);
g_free (new_password);
g_object_unref (prompt_stream);
g_object_unref (reply_stream);
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
index f6e24a5d..4cabf10f 100644
--- a/daemon/gvfsbackendsmb.c
+++ b/daemon/gvfsbackendsmb.c
@@ -188,6 +188,9 @@ auth_callback (SMBCCTX *context,
in_keyring = g_vfs_keyring_lookup_password (backend->user,
backend->server,
backend->domain,
+ NULL,
+ NULL,
+ 0,
"smb",
&ask_user,
&ask_domain,
@@ -562,6 +565,9 @@ do_mount (GVfsBackend *backend,
op_backend->server,
op_backend->last_domain,
"smb",
+ NULL,
+ NULL,
+ 0,
op_backend->last_password,
op_backend->password_save);
diff --git a/daemon/gvfskeyring.c b/daemon/gvfskeyring.c
index 583db085..1863ff18 100644
--- a/daemon/gvfskeyring.c
+++ b/daemon/gvfskeyring.c
@@ -33,7 +33,7 @@ gboolean
g_vfs_keyring_is_available (void)
{
#ifdef HAVE_KEYRING
- return gnome_keyring_is_available ();
+ return gnome_keyring_is_available ();
#else
return FALSE;
#endif
@@ -44,35 +44,38 @@ g_vfs_keyring_lookup_password (const gchar *username,
const gchar *host,
const gchar *domain,
const gchar *protocol,
+ const gchar *object,
+ const gchar *authtype,
+ guint32 port,
gchar **username_out,
gchar **domain_out,
gchar **password_out)
{
#ifdef HAVE_KEYRING
- GnomeKeyringNetworkPasswordData *pwd_data;
- GnomeKeyringResult result;
- GList *plist;
+ GnomeKeyringNetworkPasswordData *pwd_data;
+ GnomeKeyringResult result;
+ GList *plist;
- if (!gnome_keyring_is_available ())
- return FALSE;
+ if (!gnome_keyring_is_available ())
+ return FALSE;
- result = gnome_keyring_find_network_password_sync (
+ result = gnome_keyring_find_network_password_sync (
username,
domain,
host,
- NULL,
+ object,
protocol,
- NULL,
- 0,
+ authtype,
+ port,
&plist);
- if (result != GNOME_KEYRING_RESULT_OK || plist == NULL)
- return FALSE;
+ if (result != GNOME_KEYRING_RESULT_OK || plist == NULL)
+ return FALSE;
- /* We use the first result, which is the least specific match */
- pwd_data = (GnomeKeyringNetworkPasswordData *)plist->data;
+ /* We use the first result, which is the least specific match */
+ pwd_data = (GnomeKeyringNetworkPasswordData *)plist->data;
- *password_out = g_strdup (pwd_data->password);
+ *password_out = g_strdup (pwd_data->password);
if (username_out)
*username_out = g_strdup (pwd_data->user);
@@ -80,9 +83,9 @@ g_vfs_keyring_lookup_password (const gchar *username,
if (domain_out)
*domain_out = g_strdup (pwd_data->domain);
- gnome_keyring_network_password_list_free (plist);
-
- return TRUE;
+ gnome_keyring_network_password_list_free (plist);
+
+ return TRUE;
#else
return FALSE;
#endif /* HAVE_KEYRING */
@@ -93,6 +96,9 @@ g_vfs_keyring_save_password (const gchar *username,
const gchar *host,
const gchar *domain,
const gchar *protocol,
+ const gchar *object,
+ const gchar *authtype,
+ guint32 port,
const gchar *password,
GPasswordSave flags)
{
@@ -101,8 +107,8 @@ g_vfs_keyring_save_password (const gchar *username,
const gchar *keyring;
guint32 item_id;
- if (!gnome_keyring_is_available ())
- return FALSE;
+ if (!gnome_keyring_is_available ())
+ return FALSE;
if (flags == G_PASSWORD_SAVE_NEVER)
return FALSE;
@@ -114,10 +120,10 @@ g_vfs_keyring_save_password (const gchar *username,
username,
domain,
host,
- NULL,
+ object,
protocol,
- NULL,
- 0,
+ authtype,
+ port,
password,
&item_id);
diff --git a/daemon/gvfskeyring.h b/daemon/gvfskeyring.h
index f9f72042..54c04962 100644
--- a/daemon/gvfskeyring.h
+++ b/daemon/gvfskeyring.h
@@ -32,6 +32,9 @@ gboolean g_vfs_keyring_lookup_password (const gchar *username,
const gchar *host,
const gchar *domain,
const gchar *protocol,
+ const gchar *object,
+ const gchar *authtype,
+ guint32 port,
gchar **username_out,
gchar **domain_out,
gchar **password);
@@ -39,6 +42,9 @@ gboolean g_vfs_keyring_save_password (const gchar *username,
const gchar *host,
const gchar *domain,
const gchar *protocol,
+ const gchar *object,
+ const gchar *authtype,
+ guint32 port,
const gchar *password,
GPasswordSave flags);