Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:jberkman
evolution-data-server-2.6
keyring-integration.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File keyring-integration.patch of Package evolution-data-server-2.6
Index: configure.in =================================================================== RCS file: /cvs/gnome/evolution-data-server/configure.in,v retrieving revision 1.157 diff -u -p -r1.157 configure.in --- configure.in 13 Feb 2006 15:50:15 -0000 1.157 +++ configure.in 15 Feb 2006 08:51:38 -0000 @@ -326,6 +326,9 @@ AC_ARG_ENABLE(nss, [ --enable-nss=[yes, AC_ARG_ENABLE(smime, [ --enable-smime=[yes,no] Attempt to use Mozilla libnss for SMIME support (this requires --enable-nss)], enable_smime="$enableval", enable_smime="yes") +AC_ARG_ENABLE(gnome-keyring, [ --enable-gnome-keyring=[yes,no] Attempt to use Gnome Keyring for storing passwords (this requires --enable-gnome-keyring)], + enable_gnome_keyring="$enableval", enable_gnome_keyring="no") + AC_ARG_WITH(nspr-includes, [ --with-nspr-includes=PREFIX Location of Mozilla nspr4 includes.], with_nspr_includes="$withval") @@ -338,6 +341,16 @@ AC_ARG_WITH(nss-includes, [ --with-nss- AC_ARG_WITH(nss-libs, [ --with-nss-libs=PREFIX Location of Mozilla nss3 libs.], with_nss_libs="$withval") +if test "x${enable_gnome_keyring}" = "xyes"; then + PKG_CHECK_MODULES(GNOME_KEYRING, gnome-keyring-1, with_gnome_keyring="yes", with_gnome_keyring="no"); + if test "x$with_gnome_keyring" = "xyes"; then + AC_DEFINE(WITH_GNOME_KEYRING, 1, [Gnome Keyring available]) + GNOME_KEYRING_REQUIREMENT="gnome-keyring-1" + else + GNOME_KEYRING_REQUIREMENT="" + fi +fi + if test "x${enable_nss}" = "xyes" || test "x${enable_nss}" = "xstatic"; then if test -n "${with_nspr_includes}" || test -n "${with_nspr_libs}" || test -n "${with_nss_includes}" || test -n "${with_nss_libs}" || test "x${enable_nss}" = "xstatic"; then dnl If the user specifies --with-foo or --enable-nss=static, then we have to do this manually @@ -1137,7 +1150,7 @@ EVO_SET_COMPILE_FLAGS(E_DATA_SERVER, $E_ AC_SUBST(E_DATA_SERVER_CFLAGS) AC_SUBST(E_DATA_SERVER_LIBS) -E_DATA_SERVER_UI_DEPS="gtk+-2.0 libglade-2.0 gconf-2.0 libgnome-2.0" +E_DATA_SERVER_UI_DEPS="gtk+-2.0 libglade-2.0 gconf-2.0 libgnome-2.0 $GNOME_KEYRING_REQUIREMENT" EVO_SET_COMPILE_FLAGS(E_DATA_SERVER_UI, $E_DATA_SERVER_UI_DEPS, $THREADS_CFLAGS, $THREADS_LIBS) AC_SUBST(E_DATA_SERVER_UI_CFLAGS) @@ -1371,6 +1384,7 @@ echo "\ fi echo "\ Kerberos 4/5: $msg_krb4/$msg_krb5 + Gnome Keyring: $enable_gnome_keyring/$with_gnome_keyring SSL support: $msg_ssl SMIME support: $msg_smime IPv6 support: $msg_ipv6 --- trunk/libedataserverui/e-passwords.c 2006/02/24 21:00:47 6809 +++ libedataserverui/e-passwords.c 2006/08/03 06:23:01 7293 @@ -52,6 +52,11 @@ #include "e-passwords.h" #include "libedataserver/e-msgport.h" +#include "libedataserver/e-url.h" + +#if WITH_GNOME_KEYRING +#include <gnome-keyring.h> +#endif #ifndef ENABLE_THREADS #define ENABLE_THREADS (1) @@ -69,6 +74,8 @@ #define UNLOCK() #endif +#define d(x) x + struct _EPassMsg { EMsg msg; @@ -185,6 +192,57 @@ } /* the functions that actually do the work */ +#if WITH_GNOME_KEYRING +static void +ep_clear_passwords(EPassMsg *msg) +{ + GnomeKeyringAttributeList *attributes; + GnomeKeyringAttribute attribute; + GnomeKeyringResult result; + GList *matches = NULL, *tmp; + char *path; + char *default_keyring = NULL; + + result = gnome_keyring_get_default_keyring_sync (&default_keyring); + if (!default_keyring) { + if (gnome_keyring_create_sync ("default", NULL) != GNOME_KEYRING_RESULT_OK) { + if (!msg->noreply) + e_msgport_reply(&msg->msg); + return; + } + default_keyring = g_strdup ("default"); + } + + d(g_print("Get Default %d\n", result)); + + /* Not called at all */ + path = g_strdup ("Evolution"); + attributes = gnome_keyring_attribute_list_new (); + + attribute.name = g_strdup ("application"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = path; + g_array_append_val (attributes, attribute); + + result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_NETWORK_PASSWORD, attributes, &matches); + d(g_print ("Find Items %d\n", result)); + + gnome_keyring_attribute_list_free (attributes); + + if (result) { + g_print ("Couldn't clear password"); + } else { + for (tmp = matches; tmp; tmp = tmp->next) { + result = gnome_keyring_item_delete_sync (default_keyring, ((GnomeKeyringFound *) tmp->data)->item_id); + d(g_printf("Delete Items %d\n", result)); + } + } + + g_free (default_keyring); + if (!msg->noreply) + e_msgport_reply(&msg->msg); +} +#else static void ep_clear_passwords(EPassMsg *msg) { @@ -200,6 +258,7 @@ if (!msg->noreply) e_msgport_reply(&msg->msg); } +#endif static gboolean free_entry (gpointer key, gpointer value, gpointer user_data) @@ -210,6 +269,59 @@ return TRUE; } +#if WITH_GNOME_KEYRING +ep_forget_passwords(EPassMsg *msg) +{ + GnomeKeyringAttributeList *attributes; + GnomeKeyringAttribute attribute; + GnomeKeyringResult result; + GList *matches = NULL, *tmp; + char *path; + char *default_keyring = NULL; + + result = gnome_keyring_get_default_keyring_sync (&default_keyring); + if (!default_keyring) { + if (gnome_keyring_create_sync ("default", NULL) != GNOME_KEYRING_RESULT_OK) { + if (!msg->noreply) + e_msgport_reply(&msg->msg); + return; + } + default_keyring = g_strdup ("default"); + } + d(g_print("Get Default %d\n", result)); + + path = g_strdup ("Evolution"); + attributes = gnome_keyring_attribute_list_new (); + + attribute.name = g_strdup ("application"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = path; + g_array_append_val (attributes, attribute); + + + result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_NETWORK_PASSWORD, attributes, &matches); + d(g_print ("Find Items %d\n", result)); + + gnome_keyring_attribute_list_free (attributes); + + if (result) { + g_print ("Couldn't clear password"); + } else { + for (tmp = matches; tmp; tmp = tmp->next) { + result = gnome_keyring_item_delete_sync (default_keyring, ((GnomeKeyringFound *) tmp->data)->item_id); + d(g_printf("Delete Items %d\n", result)); + } + } + + g_free (default_keyring); + + /* free up the session passwords */ + g_hash_table_foreach_remove (passwords, free_entry, NULL); + + if (!msg->noreply) + e_msgport_reply(&msg->msg); +} +#else static void ep_forget_passwords(EPassMsg *msg) { @@ -235,6 +347,7 @@ if (!msg->noreply) e_msgport_reply(&msg->msg); } +#endif static char * password_path (const char *component_name, const char *key) @@ -254,6 +367,71 @@ return path; } +#if WITH_GNOME_KEYRING +static void +ep_remember_password(EPassMsg *msg) +{ + gpointer okey, value; + int len, state, save; + + if (g_hash_table_lookup_extended (passwords, msg->key, &okey, &value)) { + /* add it to the on-disk cache of passwords */ + GnomeKeyringAttributeList *attributes; + GnomeKeyringAttribute attribute; + GnomeKeyringResult result; + GList *pass = NULL, *tmp; + EUri *uri = e_uri_new (okey); + int item_id; + + if (!strcmp (uri->protocol, "ldap") && !uri->user) { + /* LDAP doesnt use username in url. Let the url be the user key. So safe it */ + char *keycopy = g_strdup (msg->key); + int i; + + for (i = 0; i < strlen (keycopy); i ++) + if (keycopy[i] == '/' || keycopy[i] =='=') + keycopy[i] = '_'; + uri->user = keycopy; + } + + attributes = gnome_keyring_attribute_list_new (); + + attribute.name = g_strdup ("user"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup (uri->user); + g_array_append_val (attributes, attribute); + + attribute.name = g_strdup ("server"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup (uri->host); + g_array_append_val (attributes, attribute); + + attribute.name = g_strdup ("application"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup ("Evolution"); + g_array_append_val (attributes, attribute); + + result = gnome_keyring_item_create_sync (NULL, /* Use default keyring */ + GNOME_KEYRING_ITEM_NETWORK_PASSWORD, /* type */ + msg->key, /* name */ + attributes, /* attribute list */ + value, /* password */ + TRUE, /* Update if already exists */ + &item_id); + + d(g_print("Remember %s: %d/%d\n", msg->key, result, item_id)); + /* now remove it from our session hash */ + g_hash_table_remove (passwords, msg->key); + g_free (okey); + g_free (value); + + e_uri_free (uri); + } + + if (!msg->noreply) + e_msgport_reply(&msg->msg); +} +#else static void ep_remember_password(EPassMsg *msg) { @@ -285,7 +463,118 @@ if (!msg->noreply) e_msgport_reply(&msg->msg); } +#endif +#if WITH_GNOME_KEYRING +static void +ep_forget_password (EPassMsg *msg) +{ + GnomeKeyringAttributeList *attributes; + GnomeKeyringAttribute attribute; + GnomeKeyringResult result; + GList *matches = NULL, *tmp; + char *path; + char *default_keyring = NULL; + gpointer okey, value; + EUri *uri = e_uri_new (msg->key); + + if (!strcmp (uri->protocol, "ldap") && !uri->user) { + /* LDAP doesnt use username in url. Let the url be the user key. So safe it */ + char *keycopy = g_strdup (msg->key); + int i; + + for (i = 0; i < strlen (keycopy); i ++) + if (keycopy[i] == '/' || keycopy[i] =='=') + keycopy[i] = '_'; + uri->user = keycopy; + } + + if (g_hash_table_lookup_extended (passwords, msg->key, &okey, &value)) { + g_hash_table_remove (passwords, msg->key); + memset (value, 0, strlen (value)); + g_free (okey); + g_free (value); + } + + if (!uri->host && !uri->user) { + /* No need to remove from keyring for pass phrases */ + if (!msg->noreply) + e_msgport_reply(&msg->msg); + return; + } + + result = gnome_keyring_get_default_keyring_sync (&default_keyring); + if (!default_keyring) { + if (gnome_keyring_create_sync ("default", NULL) != GNOME_KEYRING_RESULT_OK) { + if (!msg->noreply) + e_msgport_reply(&msg->msg); + return; + } + default_keyring = g_strdup ("default"); + } + + d(g_print("Get Default %d\n", result)); + + attributes = gnome_keyring_attribute_list_new (); + attribute.name = g_strdup ("user"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup(uri->user);; + g_array_append_val (attributes, attribute); + + attributes = gnome_keyring_attribute_list_new (); + attribute.name = g_strdup ("server"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup(uri->host);; + g_array_append_val (attributes, attribute); + + attributes = gnome_keyring_attribute_list_new (); + attribute.name = g_strdup ("application"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup("Evolution");; + g_array_append_val (attributes, attribute); + + result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_NETWORK_PASSWORD, attributes, &matches); + d(g_print ("Find Items %d\n", result)); + + gnome_keyring_attribute_list_free (attributes); + + if (result) { + g_print ("Couldn't clear password"); + } else { + for (tmp = matches; tmp; tmp = tmp->next) { + GArray *pattr = ((GnomeKeyringFound *) tmp->data)->attributes; + int i; + GnomeKeyringAttribute *attr; + gboolean accept = TRUE; + guint present = 0; + + for (i =0; (i < pattr->len) && accept; i++) + { + attr = &g_array_index (pattr, GnomeKeyringAttribute, i); + if (!strcmp(attr->name, "user")) { + present++; + if (strcmp (attr->value.string, uri->user)) + accept = FALSE; + } else if (!strcmp(attr->name, "server")) { + present++; + if (strcmp (attr->value.string, uri->host)) + accept = FALSE; + } + } + if (present == 2 && accept) { + result = gnome_keyring_item_delete_sync (default_keyring, ((GnomeKeyringFound *) tmp->data)->item_id); + d(g_printf("Delete Items %s %s %d\n", uri->host, uri->user, result)); + } + } + + } + + g_free (default_keyring); + + if (!msg->noreply) + e_msgport_reply(&msg->msg); +} +#else static void ep_forget_password (EPassMsg *msg) { @@ -308,7 +597,99 @@ if (!msg->noreply) e_msgport_reply(&msg->msg); } +#endif +#if WITH_GNOME_KEYRING +ep_get_password (EPassMsg *msg) +{ + char *path, *passwd; + char *encoded = NULL; + GnomeKeyringAttributeList *attributes; + GnomeKeyringAttribute attribute; + GnomeKeyringResult result; + GList *matches = NULL, *tmp; + + passwd = g_hash_table_lookup (passwords, msg->key); + if (passwd) { + msg->password = g_strdup(passwd); + } else { + EUri *uri = e_uri_new (msg->key); + + if (!strcmp (uri->protocol, "ldap") && !uri->user) { + /* LDAP doesnt use username in url. Let the url be the user key. So safe it */ + char *keycopy = g_strdup (msg->key); + int i; + + for (i = 0; i < strlen (keycopy); i ++) + if (keycopy[i] == '/' || keycopy[i] =='=') + keycopy[i] = '_'; + uri->user = keycopy; + } + + if (uri->host && uri->user) { + /* We dont store passphrases.*/ + + attributes = gnome_keyring_attribute_list_new (); + attribute.name = g_strdup ("user"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup(uri->user);; + g_array_append_val (attributes, attribute); + printf("get %s %s\n", attribute.value.string, msg->key); + + attributes = gnome_keyring_attribute_list_new (); + attribute.name = g_strdup ("server"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup(uri->host);; + g_array_append_val (attributes, attribute); + + attributes = gnome_keyring_attribute_list_new (); + attribute.name = g_strdup ("application"); + attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; + attribute.value.string = g_strdup("Evolution"); + g_array_append_val (attributes, attribute); + + result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_NETWORK_PASSWORD, attributes, &matches); + d(g_print ("Find Items %d\n", result)); + + gnome_keyring_attribute_list_free (attributes); + + if (result) { + g_print ("Couldn't Get password %d\n", result); + } else { + /* FIXME: What to do if this returns more than one? */ + for (tmp = matches; tmp; tmp = tmp->next) { + GArray *pattr = ((GnomeKeyringFound *) tmp->data)->attributes; + int i; + GnomeKeyringAttribute *attr; + gboolean accept = TRUE; + guint present = 0; + + for (i =0; (i < pattr->len) && accept; i++) + { + attr = &g_array_index (pattr, GnomeKeyringAttribute, i); + + if (!strcmp(attr->name, "user")) { + present++; + if (strcmp (attr->value.string, uri->user)) + accept = FALSE; + } else if (!strcmp(attr->name, "server")) { + present++; + if (strcmp (attr->value.string, uri->host)) + accept = FALSE; + } + } + if (present == 2 && accept) + msg->password = g_strdup (((GnomeKeyringFound *) tmp->data)->secret); + } + } + } + + } + + if (!msg->noreply) + e_msgport_reply(&msg->msg); +} +#else static void ep_get_password (EPassMsg *msg) { @@ -332,6 +713,7 @@ if (!msg->noreply) e_msgport_reply(&msg->msg); } +#endif static void ep_add_password (EPassMsg *msg) @@ -535,8 +924,9 @@ e_passwords_shutdown (void) { /* shouldn't need this really - everything is synchronous */ +#if !WITH_GNOME_KEYRING gnome_config_private_sync_file ("/Evolution"); - +#endif e_passwords_cancel(); if (passwords) {
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor