patches/pidgin-01-gnome-keyring.diff
author rohinis
Tue, 29 Nov 2011 17:32:55 +0000
branchs11express-2010-11
changeset 22234 c23e64da3e06
parent 21653 2c34bc4351b1
permissions -rw-r--r--
2011-11-29 Rohini S <[email protected]> * patches/Python26-22-audio.diff: Fixes CVE-2010-1634 * specs/SUNWPython26.spec: Fixes CR 7085446

--- pidgin-2.7.11.orig/pidgin/gtkmain.c	2011-03-23 11:11:47.246480000 +0530
+++ pidgin-2.7.11/pidgin/gtkmain.c	2011-03-23 11:18:00.940953000 +0530
@@ -70,6 +70,10 @@
 #include "pidginstock.h"
 #include "gtkwhiteboard.h"
 
+#ifdef GAIM_ENABLE_KEYRING
+#include <gnome-keyring.h>
+#endif
+
 #ifdef HAVE_SIGNAL_H
 # include <signal.h>
 #endif
@@ -742,6 +746,12 @@ int main(int argc, char *argv[])
 	gtk_rc_add_default_file(search_path);
 	g_free(search_path);
 
+#ifdef  GAIM_ENABLE_KEYRING
+        GnomeKeyringResult rtn = gnome_keyring_unlock_sync(NULL, NULL);
+        // if (rtn == GNOME_KEYRING_RESULT_DENIED)
+        //   return 0;
+#endif
+
 	gui_check = gtk_init_check(&argc, &argv);
 	if (!gui_check) {
 		char *display = gdk_get_display();
--- pidgin-2.7.11.orig/pidgin/Makefile.am	2011-03-23 11:10:59.469348000 +0530
+++ pidgin-2.7.11/pidgin/Makefile.am	2011-03-23 11:20:38.308884000 +0530
@@ -177,6 +177,7 @@ AM_CPPFLAGS = \
 	$(GSTREAMER_CFLAGS) \
 	$(DEBUG_CFLAGS) \
 	$(GTK_CFLAGS) \
+        $(GAIM_KEYRING_CFLAGS) \
 	$(DBUS_CFLAGS) \
 	$(GTKSPELL_CFLAGS) \
 	$(LIBXML_CFLAGS) \
--- pidgin-2.7.11.orig/libpurple/Makefile.am	2011-03-23 11:11:53.706152000 +0530
+++ pidgin-2.7.11/libpurple/Makefile.am	2011-03-23 11:23:21.015126000 +0530
@@ -305,6 +305,7 @@ libpurple_la_LIBADD = \
 	$(DBUS_LIBS) \
 	$(GLIB_LIBS) \
 	$(LIBXML_LIBS) \
+        $(GAIM_KEYRING_LIBS) \
 	$(NETWORKMANAGER_LIBS) \
 	$(INTLLIBS) \
 	$(FARSIGHT_LIBS) \
@@ -322,6 +323,7 @@ AM_CPPFLAGS = \
 	$(GLIB_CFLAGS) \
 	$(DEBUG_CFLAGS) \
 	$(DBUS_CFLAGS) \
+        $(GAIM_KEYRING_CFLAGS) \
 	$(LIBXML_CFLAGS) \
 	$(FARSIGHT_CFLAGS) \
 	$(GSTREAMER_CFLAGS) \
--- pidgin-2.7.11.orig/libpurple/account.c	2011-03-23 11:12:35.470803000 +0530
+++ pidgin-2.7.11/libpurple/account.c	2011-03-23 11:33:50.370804000 +0530
@@ -49,6 +49,14 @@ typedef struct
 #define PURPLE_ACCOUNT_GET_PRIVATE(account) \
 	((PurpleAccountPrivate *) (account->priv))
 
+#ifdef GAIM_ENABLE_KEYRING
+#include <gnome-keyring.h>
+
+static char * gaim_account_get_password_from_keyring (const char *_prpl, const char *_user);
+static gboolean gaim_account_set_password_in_keyring (const char *_prpl, const char *_user, const char *password);
+#endif
+
+
 /* TODO: Should use PurpleValue instead of this?  What about "ui"? */
 typedef struct
 {
@@ -378,8 +386,13 @@ account_to_xmlnode(PurpleAccount *accoun
 	if (purple_account_get_remember_password(account) &&
 		((tmp = purple_account_get_password(account)) != NULL))
 	{
+#ifdef GAIM_ENABLE_KEYRING
+                gaim_account_set_password_in_keyring( purple_account_get_protocol_id(account),
+                                          purple_account_get_username(account), tmp);
+#else
 		child = xmlnode_new_child(node, "password");
 		xmlnode_insert_data(child, tmp, -1);
+#endif
 	}
 
 	if ((tmp = purple_account_get_alias(account)) != NULL)
@@ -875,18 +888,30 @@ parse_account(xmlnode *node)
 	}
 
 	ret = purple_account_new(name, _purple_oscar_convert(name, protocol_id)); /* XXX: */
-	g_free(name);
-	g_free(protocol_id);
-
-	/* Read the password */
-	child = xmlnode_get_child(node, "password");
-	if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
-	{
-		purple_account_set_remember_password(ret, TRUE);
-		purple_account_set_password(ret, data);
-		g_free(data);
-	}
-
+        gboolean got_pwd = FALSE;
+#ifdef GAIM_ENABLE_KEYRING
+        data = gaim_account_get_password_from_keyring(protocol_id, name);
+        if (data)
+        {
+               got_pwd = TRUE;
+                purple_account_set_remember_password(ret, TRUE);
+                purple_account_set_password(ret, data);
+                g_free(data);
+        }
+#endif
+        if (!got_pwd)
+        {
+                /* Read the password */
+               child = xmlnode_get_child(node, "password");
+               if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
+              {
+                       purple_account_set_remember_password(ret, TRUE);
+                       purple_account_set_password(ret, data);
+                       g_free(data);
+               }
+        }
+        g_free(name);
+        g_free(protocol_id);
 	/* Read the alias */
 	child = xmlnode_get_child(node, "alias");
 	if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
@@ -3114,3 +3139,67 @@ purple_accounts_uninit(void)
 	purple_signals_disconnect_by_handle(handle);
 	purple_signals_unregister_by_instance(handle);
 }
+
+#ifdef GAIM_ENABLE_KEYRING
+static char *
+gaim_account_get_password_from_keyring(const char *_prpl, const char *_user)
+{
+  GnomeKeyringNetworkPasswordData *found_item;
+  GnomeKeyringResult               result;
+  GList                           *matches;
+  char                            *password;
+
+  matches = NULL;
+
+  result = gnome_keyring_find_network_password_sync (
+               _user,          /* user     */
+               NULL,           /* domain   */
+               "gaim.local",   /* server   */
+               NULL,           /* object   */
+              _prpl,          /* protocol */
+               NULL,           /* authtype */
+               1863,           /* port     */
+               &matches);
+
+ if (result != GNOME_KEYRING_RESULT_OK)
+    return NULL;
+
+  if (matches == NULL || matches->data == NULL)
+    return NULL;
+
+  found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
+
+  password = g_strdup (found_item->password);
+
+  gnome_keyring_network_password_list_free (matches);
+
+  return password;
+}
+
+void my_GnomeKeyringOperationGetIntCallback(GnomeKeyringResult result, guint32 val, gpointer data)
+{
+  return;
+}
+
+static gboolean
+gaim_account_set_password_in_keyring (const char *_prpl, const char *_user, const char *_password)
+{
+  GnomeKeyringResult result;
+  guint32            item_id;
+
+  gpointer req = gnome_keyring_set_network_password (
+                NULL,           /* default keyring */
+                _user,          /* user            */
+                NULL,           /* domain          */
+                "gaim.local",   /* server          */
+                NULL,           /* object          */
+                _prpl,          /* protocol        */
+                NULL,           /* authtype        */
+                1863,           /* port            */
+                _password,       /* password        */
+                my_GnomeKeyringOperationGetIntCallback, NULL, NULL);
+  return TRUE;
+}
+#endif
+
+
--- pidgin-2.7.11.orig/configure.ac	2011-03-23 11:10:35.728695000 +0530
+++ pidgin-2.7.11/configure.ac	2011-03-23 11:41:22.384130000 +0530
@@ -2383,6 +2383,19 @@ if test "$zephyr" != "no" ; then
 	LIBS="$orig_LIBS"
 	LDFLAGS="$orig_LDFLAGS"
 fi
+dnl #######################################################################
+dnl # Check for gnome-keyring
+dnl #--enable-gnome-keyring=(yes|no)
+dnl #######################################################################
+AC_ARG_ENABLE(gnome-keyring,
+              AC_HELP_STRING([--enable-gnome-keyring],
+                             [use gnome keyring for storing password [default=no]]),,
+              enable_gnome_keyring=no)
+if test "x$enable_gnome_keyring" = "xyes"; then
+    PKG_CHECK_MODULES(GAIM_KEYRING,
+                      gnome-keyring-1,
+                      AC_DEFINE(GAIM_ENABLE_KEYRING, [], [Set if we should use gnome-keyring]))
+fi
 
 AC_MSG_CHECKING(for me pot o' gold)
 AC_MSG_RESULT(no)