components/desktop/pidgin/patches/pidgin-01-gnome-keyring.patch
changeset 5091 81e5d6b75c3c
child 7368 13871af9f746
equal deleted inserted replaced
5090:5f131162e136 5091:81e5d6b75c3c
       
     1 # date:2006-11-16 owner:elaine type:branding bugster:6439103
       
     2 # Bug 15335933 SUNBT6439103 gaim must use gnome-keyring
       
     3 #
       
     4 # Changes should be submitted upstream.
       
     5 
       
     6 --- pidgin-2.7.11/libpurple/Makefile.am.orig	2011-03-11 10:20:27.000000000 +0800
       
     7 +++ pidgin-2.7.11/libpurple/Makefile.am	2011-03-14 09:45:48.768422314 +0800
       
     8 @@ -305,6 +305,7 @@
       
     9  	$(DBUS_LIBS) \
       
    10  	$(GLIB_LIBS) \
       
    11  	$(LIBXML_LIBS) \
       
    12 +        $(GAIM_KEYRING_LIBS) \
       
    13  	$(NETWORKMANAGER_LIBS) \
       
    14  	$(INTLLIBS) \
       
    15  	$(FARSTREAM_LIBS) \
       
    16 @@ -322,6 +323,7 @@
       
    17  	$(GLIB_CFLAGS) \
       
    18  	$(DEBUG_CFLAGS) \
       
    19  	$(DBUS_CFLAGS) \
       
    20 +        $(GAIM_KEYRING_CFLAGS) \
       
    21  	$(LIBXML_CFLAGS) \
       
    22  	$(FARSTREAM_CFLAGS) \
       
    23  	$(GSTREAMER_CFLAGS) \
       
    24 --- pidgin-2.7.11/pidgin/gtkmain.c.orig	2011-03-11 10:20:28.000000000 +0800
       
    25 +++ pidgin-2.7.11/pidgin/gtkmain.c	2011-03-14 09:45:48.767697192 +0800
       
    26 @@ -70,6 +70,10 @@
       
    27  #include "pidginstock.h"
       
    28  #include "gtkwhiteboard.h"
       
    29  
       
    30 +#ifdef GAIM_ENABLE_KEYRING
       
    31 +#include <gnome-keyring.h>
       
    32 +#endif
       
    33 +
       
    34  #ifdef HAVE_SIGNAL_H
       
    35  # include <signal.h>
       
    36  #endif
       
    37 @@ -742,6 +746,12 @@
       
    38  	gtk_rc_add_default_file(search_path);
       
    39  	g_free(search_path);
       
    40  
       
    41 +#ifdef  GAIM_ENABLE_KEYRING
       
    42 +        GnomeKeyringResult rtn = gnome_keyring_unlock_sync(NULL, NULL);
       
    43 +        // if (rtn == GNOME_KEYRING_RESULT_DENIED)
       
    44 +        //   return 0;
       
    45 +#endif
       
    46 +
       
    47  	gui_check = gtk_init_check(&argc, &argv);
       
    48  	if (!gui_check) {
       
    49  		char *display = gdk_get_display();
       
    50 --- pidgin-2.7.11/pidgin/Makefile.am.orig	2011-03-11 10:20:28.000000000 +0800
       
    51 +++ pidgin-2.7.11/pidgin/Makefile.am	2011-03-14 09:45:48.768028256 +0800
       
    52 @@ -177,6 +177,7 @@
       
    53  	$(GSTREAMER_CFLAGS) \
       
    54  	$(DEBUG_CFLAGS) \
       
    55  	$(GTK_CFLAGS) \
       
    56 +        $(GAIM_KEYRING_CFLAGS) \
       
    57  	$(DBUS_CFLAGS) \
       
    58  	$(GTKSPELL_CFLAGS) \
       
    59  	$(LIBXML_CFLAGS) \
       
    60 --- pidgin-2.7.11/configure.ac.orig	2011-03-11 10:20:27.000000000 +0800
       
    61 +++ pidgin-2.7.11/configure.ac	2011-03-14 09:45:48.770550233 +0800
       
    62 @@ -2382,6 +2382,20 @@
       
    63  	LDFLAGS="$orig_LDFLAGS"
       
    64  fi
       
    65  
       
    66 +dnl #######################################################################
       
    67 +dnl # Check for gnome-keyring
       
    68 +dnl #--enable-gnome-keyring=(yes|no)
       
    69 +dnl #######################################################################
       
    70 +AC_ARG_ENABLE(gnome-keyring,
       
    71 +              AC_HELP_STRING([--enable-gnome-keyring],
       
    72 +                             [use gnome keyring for storing password [default=no]]),,
       
    73 +              enable_gnome_keyring=no)
       
    74 +if test "x$enable_gnome_keyring" = "xyes"; then
       
    75 +    PKG_CHECK_MODULES(GAIM_KEYRING,
       
    76 +                      gnome-keyring-1,
       
    77 +                      AC_DEFINE(GAIM_ENABLE_KEYRING, [], [Set if we should use gnome-keyring]))
       
    78 +fi
       
    79 +
       
    80  AC_MSG_CHECKING(for me pot o' gold)
       
    81  AC_MSG_RESULT(no)
       
    82  AC_CHECK_FUNCS(gethostid lrand48 timegm)
       
    83 --- pidgin-2.10.11/libpurple/account.c.orig	Tue Feb 17 15:27:17 2015
       
    84 +++ pidgin-2.10.11/libpurple/account.c	Tue Feb 17 15:27:17 2015
       
    85 @@ -54,6 +54,14 @@
       
    86  #define PURPLE_ACCOUNT_GET_PRIVATE(account) \
       
    87  	((PurpleAccountPrivate *) (account->priv))
       
    88  
       
    89 +#ifdef GAIM_ENABLE_KEYRING
       
    90 +#include <gnome-keyring.h>
       
    91 +
       
    92 +static char * gaim_account_get_password_from_keyring (const char *_prpl, const char *_user);
       
    93 +static gboolean gaim_account_set_password_in_keyring (const char *_prpl, const char *_user, const char *password);
       
    94 +#endif
       
    95 +
       
    96 +
       
    97  /* TODO: Should use PurpleValue instead of this?  What about "ui"? */
       
    98  typedef struct
       
    99  {
       
   100 @@ -393,8 +401,13 @@
       
   101  	if (purple_account_get_remember_password(account) &&
       
   102  		((tmp = purple_account_get_password(account)) != NULL))
       
   103  	{
       
   104 +#ifdef GAIM_ENABLE_KEYRING
       
   105 +	        gaim_account_set_password_in_keyring( purple_account_get_protocol_id(account),
       
   106 +                                          purple_account_get_username(account), tmp);
       
   107 +#else
       
   108  		child = xmlnode_new_child(node, "password");
       
   109  		xmlnode_insert_data(child, tmp, -1);
       
   110 +#endif
       
   111  	} else if (_purple_account_is_password_encrypted(account)) {
       
   112  		const char *keyring = NULL;
       
   113  		const char *mode = NULL;
       
   114 @@ -909,27 +925,37 @@
       
   115  	}
       
   116  
       
   117  	ret = purple_account_new(name, _purple_oscar_convert(name, protocol_id)); /* XXX: */
       
   118 -	g_free(name);
       
   119 -	g_free(protocol_id);
       
   120 +        gboolean got_pwd = FALSE;
       
   121 +#ifdef GAIM_ENABLE_KEYRING
       
   122 +        data = gaim_account_get_password_from_keyring(protocol_id, name);
       
   123 +        if (data)
       
   124 +        {
       
   125 +                got_pwd = TRUE;
       
   126 +                purple_account_set_remember_password(ret, TRUE);
       
   127 +                purple_account_set_password(ret, data);
       
   128 +                g_free(data);
       
   129 +        }
       
   130 +#endif
       
   131 +	if (!got_pwd)
       
   132 +	{
       
   133 +	        /* Read the password */
       
   134 +               child = xmlnode_get_child(node, "password");
       
   135 +	       if (child != NULL) {
       
   136 + 		      const char *keyring_id = xmlnode_get_attrib(child, "keyring_id");
       
   137 +		      const char *mode = xmlnode_get_attrib(child, "mode");
       
   138 +		      gboolean is_plaintext;
       
   139  
       
   140 -	/* Read the password */
       
   141 -	child = xmlnode_get_child(node, "password");
       
   142 -	if (child != NULL) {
       
   143 -		const char *keyring_id = xmlnode_get_attrib(child, "keyring_id");
       
   144 -		const char *mode = xmlnode_get_attrib(child, "mode");
       
   145 -		gboolean is_plaintext;
       
   146 +		      data = xmlnode_get_data(child);
       
   147  
       
   148 -		data = xmlnode_get_data(child);
       
   149 +		      if (keyring_id == NULL || keyring_id[0] == '\0')
       
   150 +		      	      is_plaintext = TRUE;
       
   151 +		      else if (g_strcmp0(keyring_id, "keyring-internal") != 0)
       
   152 +			      is_plaintext = FALSE;
       
   153 +		      else if (mode == NULL || mode[0] == '\0' || g_strcmp0(mode, "cleartext") == 0)
       
   154 +			      is_plaintext = TRUE;
       
   155 +		      else
       
   156 +			      is_plaintext = FALSE;
       
   157  
       
   158 -		if (keyring_id == NULL || keyring_id[0] == '\0')
       
   159 -			is_plaintext = TRUE;
       
   160 -		else if (g_strcmp0(keyring_id, "keyring-internal") != 0)
       
   161 -			is_plaintext = FALSE;
       
   162 -		else if (mode == NULL || mode[0] == '\0' || g_strcmp0(mode, "cleartext") == 0)
       
   163 -			is_plaintext = TRUE;
       
   164 -		else
       
   165 -			is_plaintext = FALSE;
       
   166 -
       
   167  		if (is_plaintext) {
       
   168  			purple_account_set_remember_password(ret, TRUE);
       
   169  			purple_account_set_password(ret, data);
       
   170 @@ -940,6 +966,9 @@
       
   171  		}
       
   172  		g_free(data);
       
   173  	}
       
   174 +	}
       
   175 +	g_free(name);
       
   176 +	g_free(protocol_id);
       
   177  
       
   178  	/* Read the alias */
       
   179  	child = xmlnode_get_child(node, "alias");
       
   180 @@ -3350,3 +3378,66 @@
       
   181  
       
   182  	return (priv->password_keyring != NULL);
       
   183  }
       
   184 +
       
   185 +#ifdef GAIM_ENABLE_KEYRING
       
   186 +static char *
       
   187 +gaim_account_get_password_from_keyring(const char *_prpl, const char *_user)
       
   188 +{
       
   189 +  GnomeKeyringNetworkPasswordData *found_item;
       
   190 +  GnomeKeyringResult               result;
       
   191 +  GList                           *matches;
       
   192 +  char                            *password;
       
   193 +
       
   194 +  matches = NULL;
       
   195 +
       
   196 +  result = gnome_keyring_find_network_password_sync (
       
   197 +               _user,          /* user     */
       
   198 +               NULL,           /* domain   */
       
   199 +               "gaim.local",   /* server   */
       
   200 +               NULL,           /* object   */
       
   201 +               _prpl,          /* protocol */
       
   202 +               NULL,           /* authtype */
       
   203 +               1863,           /* port     */
       
   204 +               &matches);
       
   205 +
       
   206 +  if (result != GNOME_KEYRING_RESULT_OK)
       
   207 +    return NULL;
       
   208 +
       
   209 +  if (matches == NULL || matches->data == NULL)
       
   210 +    return NULL;
       
   211 +
       
   212 +  found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
       
   213 +
       
   214 +  password = g_strdup (found_item->password);
       
   215 +
       
   216 +  gnome_keyring_network_password_list_free (matches);
       
   217 +
       
   218 +  return password;
       
   219 +}
       
   220 +
       
   221 +void my_GnomeKeyringOperationGetIntCallback(GnomeKeyringResult result, guint32 val, gpointer data)
       
   222 +{
       
   223 +  return;
       
   224 +}
       
   225 +
       
   226 +static gboolean
       
   227 +gaim_account_set_password_in_keyring (const char *_prpl, const char *_user, const char *_password)
       
   228 +{
       
   229 +  GnomeKeyringResult result;
       
   230 +  guint32            item_id;
       
   231 +
       
   232 +  gpointer req = gnome_keyring_set_network_password (
       
   233 +                NULL,           /* default keyring */
       
   234 +                _user,          /* user            */
       
   235 +                NULL,           /* domain          */
       
   236 +                "gaim.local",   /* server          */
       
   237 +                NULL,           /* object          */
       
   238 +                _prpl,          /* protocol        */
       
   239 +                NULL,           /* authtype        */
       
   240 +                1863,           /* port            */
       
   241 +                _password,       /* password        */
       
   242 +                my_GnomeKeyringOperationGetIntCallback, NULL, NULL);
       
   243 +  return TRUE;
       
   244 +}
       
   245 +#endif
       
   246 +