gvfs r1293 - in trunk: . common daemon
- From: alexl svn gnome org
- To: svn-commits-list gnome org
- Subject: gvfs r1293 - in trunk: . common daemon
- Date: Mon, 18 Feb 2008 10:46:03 +0000 (GMT)
Author: alexl
Date: Mon Feb 18 10:46:03 2008
New Revision: 1293
URL: http://svn.gnome.org/viewvc/gvfs?rev=1293&view=rev
Log:
2008-02-18 Alexander Larsson <alexl redhat com>
* configure.ac:
Detect gnome-keyring
* common/gmountsource.[ch]:
Add password out to ask_password
* daemon/Makefile.am:
* daemon/gvfskeyring.[ch]:
Helper code for keyring support
* daemon/gvfsbackendsftp.c:
Add keyring support
* daemon/gvfsbackenddav.c:
* daemon/gvfsbackendsmb.c:
Update to api changes
This is the initial work on keyring support (#511517)
Patch from Carlos Garcia Campos
Added:
trunk/daemon/gvfskeyring.c
trunk/daemon/gvfskeyring.h
Modified:
trunk/ChangeLog
trunk/common/gmountsource.c
trunk/common/gmountsource.h
trunk/configure.ac
trunk/daemon/Makefile.am
trunk/daemon/gvfsbackenddav.c
trunk/daemon/gvfsbackendsftp.c
trunk/daemon/gvfsbackendsmb.c
Modified: trunk/common/gmountsource.c
==============================================================================
--- trunk/common/gmountsource.c (original)
+++ trunk/common/gmountsource.c Mon Feb 18 10:46:03 2008
@@ -124,10 +124,11 @@
struct AskPasswordData {
/* results: */
- gboolean aborted;
- char *password;
- char *username;
- char *domain;
+ gboolean aborted;
+ char *password;
+ char *username;
+ char *domain;
+ GPasswordSave password_save;
};
typedef struct AskPasswordSyncData AskPasswordSyncData;
@@ -195,6 +196,7 @@
data->password = g_strdup (password);
data->username = g_strdup (username);
data->domain = g_strdup (domain);
+ data->password_save = (GPasswordSave)password_save;
/* TODO: handle more args */
}
@@ -268,7 +270,8 @@
gboolean *aborted,
char **password_out,
char **user_out,
- char **domain_out)
+ char **domain_out,
+ GPasswordSave *password_save_out)
{
AskPasswordData *data;
GSimpleAsyncResult *simple;
@@ -301,6 +304,9 @@
data->domain = NULL;
}
+ if (password_save_out)
+ *password_save_out = data->password_save;
+
return TRUE;
}
@@ -334,9 +340,11 @@
gboolean *aborted_out,
char **password_out,
char **user_out,
- char **domain_out)
+ char **domain_out,
+ GPasswordSave *password_save_out)
{
char *password, *username, *domain;
+ GPasswordSave password_save;
gboolean handled, aborted;
AskPasswordSyncData data = {NULL};
@@ -373,7 +381,8 @@
&aborted,
&password,
&username,
- &domain);
+ &domain,
+ &password_save);
g_object_unref (data.result);
if (aborted_out)
@@ -393,6 +402,9 @@
*domain_out = domain;
else
g_free (domain);
+
+ if (password_save_out)
+ *password_save_out = password_save;
return handled;
}
@@ -409,6 +421,7 @@
char *username;
char *password;
char *domain;
+ GPasswordSave password_save;
source = G_MOUNT_SOURCE (source_object);
op = G_MOUNT_OPERATION (user_data);
@@ -421,7 +434,8 @@
&aborted,
&username,
&password,
- &domain);
+ &domain,
+ &password_save);
if (!handled)
result = G_MOUNT_OPERATION_UNHANDLED;
@@ -437,6 +451,7 @@
g_mount_operation_set_username (op, username);
if (domain)
g_mount_operation_set_domain (op, domain);
+ g_mount_operation_set_password_save (op, password_save);
}
g_mount_operation_reply (op, result);
Modified: trunk/common/gmountsource.h
==============================================================================
--- trunk/common/gmountsource.h (original)
+++ trunk/common/gmountsource.h Mon Feb 18 10:46:03 2008
@@ -64,7 +64,8 @@
gboolean *aborted,
char **password_out,
char **user_out,
- char **domain_out);
+ char **domain_out,
+ GPasswordSave *password_save_out);
void g_mount_source_ask_password_async (GMountSource *mount_source,
const char *message,
@@ -79,7 +80,8 @@
gboolean *aborted,
char **password_out,
char **user_out,
- char **domain_out);
+ char **domain_out,
+ GPasswordSave *password_save_out);
const char * g_mount_source_get_dbus_id (GMountSource *mount_source);
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Mon Feb 18 10:46:03 2008
@@ -222,6 +222,28 @@
AM_CONDITIONAL(USE_HAL, [test "$msg_hal" = "yes"])
+dnl *******************************
+dnl *** Check for GNOME Keyring ***
+dnl *******************************
+AC_ARG_ENABLE(KEYRING, [ --disable-keyring build without GNOME Keyring support])
+msg_keyring=no
+KEYRING_LIBS=
+KEYRING_CFLAGS=
+
+if test "x$enable_keyring" != "xno"; then
+ PKG_CHECK_EXISTS(gnome-keyring-1, msg_keyring=yes)
+
+ if test "x$msg_keyring" == "xyes"; then
+ PKG_CHECK_MODULES(KEYRING, gnome-keyring-1)
+ AC_DEFINE(HAVE_KEYRING, 1, [Define to 1 if GNOME Keyring is available])
+ fi
+fi
+
+AC_SUBST(KEYRING_LIBS)
+AC_SUBST(KEYRING_CFLAGS)
+
+AM_CONDITIONAL(USE_KEYRING, [test "$msg_keyring" = "yes"])
+
dnl ==========================================================================
dnl Samba 3.0
@@ -366,4 +388,5 @@
CDDA support: $msg_cdda
GConf support: $msg_gconf
Use HAL for volume monitor: $msg_hal (with fast init path: $have_hal_fast_init)
+ GNOME Keyring support: $msg_keyring
"
Modified: trunk/daemon/Makefile.am
==============================================================================
--- trunk/daemon/Makefile.am (original)
+++ trunk/daemon/Makefile.am Mon Feb 18 10:46:03 2008
@@ -8,6 +8,7 @@
-I$(top_srcdir)/common \
-I$(top_builddir) \
$(GLIB_CFLAGS) $(DBUS_CFLAGS) \
+ $(KEYRING_CFLAGS) \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DLIBEXEC_DIR=\"$(libexecdir)/\" \
-DMOUNTABLE_DIR=\"$(mountdir)/\" \
@@ -19,7 +20,7 @@
libraries = \
libdaemon.la \
$(top_builddir)/common/libgvfscommon.la \
- $(GLIB_LIBS) $(DBUS_LIBS)
+ $(GLIB_LIBS) $(DBUS_LIBS) $(KEYRING_LIBS)
# D-BUS service file
%.service: %.service.in ../config.log
@@ -103,6 +104,7 @@
gvfsjobqueryattributes.c gvfsjobqueryattributes.h \
gvfsjobcreatemonitor.c gvfsjobcreatemonitor.h \
dbus-gmain.h dbus-gmain.c \
+ gvfskeyring.h gvfskeyring.c \
$(NULL)
gvfsd_SOURCES = \
Modified: trunk/daemon/gvfsbackenddav.c
==============================================================================
--- trunk/daemon/gvfsbackenddav.c (original)
+++ trunk/daemon/gvfsbackenddav.c Mon Feb 18 10:46:03 2008
@@ -818,7 +818,8 @@
G_ASK_PASSWORD_NEED_USERNAME,
&aborted,
&new_password,
- &new_username,
+ &new_username,
+ NULL,
NULL);
if (res && !aborted)
soup_auth_authenticate (auth, new_username, new_password);
Modified: trunk/daemon/gvfsbackendsftp.c
==============================================================================
--- trunk/daemon/gvfsbackendsftp.c (original)
+++ trunk/daemon/gvfsbackendsftp.c Mon Feb 18 10:46:03 2008
@@ -52,6 +52,7 @@
#include "gvfsjobqueryattributes.h"
#include "gvfsjobenumerate.h"
#include "gvfsdaemonprotocol.h"
+#include "gvfskeyring.h"
#include "sftp.h"
#include "pty_open.h"
@@ -617,6 +618,7 @@
gboolean aborted = FALSE;
gboolean ret_val;
char *new_password = NULL;
+ GPasswordSave password_save;
gsize bytes_written;
if (op_backend->client_vendor == SFTP_VENDOR_SSH)
@@ -689,27 +691,49 @@
g_str_has_suffix (buffer, "Password:") ||
g_str_has_prefix (buffer, "Enter passphrase for key"))
{
- if (!g_mount_source_ask_password (mount_source,
- g_str_has_prefix (buffer, "Enter passphrase for key") ?
- _("Enter passphrase for key")
- :
- _("Enter password"),
- op_backend->user,
- NULL,
- G_ASK_PASSWORD_NEED_PASSWORD,
- &aborted,
- &new_password,
- NULL,
- NULL) ||
- aborted)
- {
- g_set_error (error,
- G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
- "%s", _("Password dialog cancelled"));
- ret_val = FALSE;
- break;
- }
-
+ if (!g_vfs_keyring_lookup_password (op_backend->user,
+ op_backend->host,
+ NULL,
+ "sftp",
+ NULL,
+ NULL,
+ &new_password))
+ {
+ GAskPasswordFlags flags = G_ASK_PASSWORD_NEED_PASSWORD;
+
+ if (g_vfs_keyring_is_available ())
+ flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
+
+ if (!g_mount_source_ask_password (mount_source,
+ g_str_has_prefix (buffer, "Enter passphrase for key") ?
+ _("Enter passphrase for key")
+ :
+ _("Enter password"),
+ op_backend->user,
+ NULL,
+ flags,
+ &aborted,
+ &new_password,
+ NULL,
+ NULL,
+ &password_save) ||
+ aborted)
+ {
+ g_set_error (error,
+ G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+ "%s", _("Password dialog cancelled"));
+ ret_val = FALSE;
+ break;
+ }
+
+ g_vfs_keyring_save_password (op_backend->user,
+ op_backend->host,
+ NULL,
+ "sftp",
+ new_password,
+ password_save);
+ }
+
if (!g_output_stream_write_all (reply_stream,
new_password, strlen (new_password),
&bytes_written,
Modified: trunk/daemon/gvfsbackendsmb.c
==============================================================================
--- trunk/daemon/gvfsbackendsmb.c (original)
+++ trunk/daemon/gvfsbackendsmb.c Mon Feb 18 10:46:03 2008
@@ -187,7 +187,8 @@
&abort,
&ask_password,
&ask_user,
- &ask_domain);
+ &ask_domain,
+ NULL);
g_free (message);
if (!handled)
goto out;
Added: trunk/daemon/gvfskeyring.c
==============================================================================
--- (empty file)
+++ trunk/daemon/gvfskeyring.c Mon Feb 18 10:46:03 2008
@@ -0,0 +1,128 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2008 Carlos Garcia Campos
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Carlos Garcia Campos <carlosgc gnome org>
+ */
+
+#include <config.h>
+
+#ifdef HAVE_KEYRING
+#include <gnome-keyring.h>
+#endif
+
+#include "gvfskeyring.h"
+
+gboolean
+g_vfs_keyring_is_available (void)
+{
+#ifdef HAVE_KEYRING
+ return gnome_keyring_is_available ();
+#else
+ return FALSE;
+#endif
+}
+
+gboolean
+g_vfs_keyring_lookup_password (const gchar *username,
+ const gchar *host,
+ const gchar *domain,
+ const gchar *protocol,
+ gchar **username_out,
+ gchar **domain_out,
+ gchar **password_out)
+{
+#ifdef HAVE_KEYRING
+ GnomeKeyringNetworkPasswordData *pwd_data;
+ GnomeKeyringResult result;
+ GList *plist;
+
+ if (!gnome_keyring_is_available ())
+ return FALSE;
+
+ result = gnome_keyring_find_network_password_sync (
+ username,
+ domain,
+ host,
+ NULL,
+ protocol,
+ NULL,
+ 0,
+ &plist);
+
+ 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;
+
+ *password_out = g_strdup (pwd_data->password);
+
+ if (username_out)
+ *username_out = g_strdup (pwd_data->user);
+
+ if (domain_out)
+ *domain_out = g_strdup (pwd_data->domain);
+
+ gnome_keyring_network_password_list_free (plist);
+
+ return TRUE;
+#else
+ return FALSE;
+#endif /* HAVE_KEYRING */
+}
+
+gboolean
+g_vfs_keyring_save_password (const gchar *username,
+ const gchar *host,
+ const gchar *domain,
+ const gchar *protocol,
+ const gchar *password,
+ GPasswordSave flags)
+{
+#ifdef HAVE_KEYRING
+ GnomeKeyringResult result;
+ const gchar *keyring;
+ guint32 item_id;
+
+ if (!gnome_keyring_is_available ())
+ return FALSE;
+
+ if (flags == G_PASSWORD_SAVE_NEVER)
+ return FALSE;
+
+ keyring = (flags == G_PASSWORD_SAVE_FOR_SESSION) ? "session" : NULL;
+
+ result = gnome_keyring_set_network_password_sync (
+ keyring,
+ username,
+ domain,
+ host,
+ NULL,
+ protocol,
+ NULL,
+ 0,
+ password,
+ &item_id);
+
+ return (result == GNOME_KEYRING_RESULT_OK);
+#else
+ return FALSE;
+#endif /* HAVE_KEYRING */
+}
Added: trunk/daemon/gvfskeyring.h
==============================================================================
--- (empty file)
+++ trunk/daemon/gvfskeyring.h Mon Feb 18 10:46:03 2008
@@ -0,0 +1,47 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2008 Carlos Garcia Campos
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Carlos Garcia Campos <carlosgc gnome org>
+ */
+
+#ifndef __G_VFS_KEYRING_H__
+#define __G_VFS_KEYRING_H__
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+gboolean g_vfs_keyring_is_available (void);
+gboolean g_vfs_keyring_lookup_password (const gchar *username,
+ const gchar *host,
+ const gchar *domain,
+ const gchar *protocol,
+ gchar **username_out,
+ gchar **domain_out,
+ gchar **password);
+gboolean g_vfs_keyring_save_password (const gchar *username,
+ const gchar *host,
+ const gchar *domain,
+ const gchar *protocol,
+ const gchar *password,
+ GPasswordSave flags);
+
+G_END_DECLS
+
+#endif /* __G_VFS_KEYRING_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]