deskbar-applet r2354 - in trunk: . deskbar/core



Author: kamstrup
Date: Mon Aug 25 19:50:22 2008
New Revision: 2354
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2354&view=rev

Log:
2008-08-25  Mikkel Kamstrup Erlandsen  <kamstrup cvs gnome org>

    * deskbar/core/Web.py
    Fix a bug in the way the new core.Web module handled updating of account
    info. Before this fix we leaked accounts each time editing of credentials
    took place, and we failed to look up the right one if there where multiple.
    
    Now we purge the keyring for any credentials for the given protocol
    and domain before we add new ones.


Modified:
   trunk/ChangeLog
   trunk/deskbar/core/Web.py

Modified: trunk/deskbar/core/Web.py
==============================================================================
--- trunk/deskbar/core/Web.py	(original)
+++ trunk/deskbar/core/Web.py	Mon Aug 25 19:50:22 2008
@@ -61,29 +61,48 @@
         """
         attrs = {"server": self._host, "protocol": self._protocol}
         items = gnomekeyring.find_items_sync(gnomekeyring.ITEM_NETWORK_PASSWORD, attrs)
+        
+        if (len(items) > 1):
+            LOGGER.warn ("More than one account found for %s" % self._host)
+        
         return (items[0].attributes["user"], items[0].secret)
 
     def set_credentials(self, user, pw):
         """
         Store or update username and password for account
         """
+        # Note: attrs is used to look up the account for old user credentials
         attrs = {
-                "user": user,
                 "server": self._host,
                 "protocol": self._protocol,
             }
         
-        keyring = gnomekeyring.get_default_keyring_sync()        
-        result = gnomekeyring.item_create_sync(keyring,
-                                               gnomekeyring.ITEM_NETWORK_PASSWORD,
-                                               self._realm, attrs, pw, True)
-        
-        if result == 0:
-            LOGGER.debug ("Credential update success (keyring=%s)" % keyring)
-        elif result == 7:
-            LOGGER.debug ("Credential update cancelled (keyring=%s)" % keyring)
-        else:
-            LOGGER.debug ("Credential update failed. Keyring: %s. Result: %s" % (keyring,result))
+        LOGGER.debug ("Updating credentials for %s" % self._host)
+        
+        keyring = gnomekeyring.get_default_keyring_sync()
+        
+        # Look up all accounts registered for this service and realm and delete
+        # them. We get weird errors if more than one account is present
+        try:
+            items = gnomekeyring.find_items_sync (gnomekeyring.ITEM_NETWORK_PASSWORD,
+                                              attrs)
+        except gnomekeyring.NoMatchError:
+            LOGGER.debug ("No existing accounts for %s" % self._host)
+            items = []
+            
+        for item in items:
+            LOGGER.debug ("Purging account %s %s" % 
+                          (item.attributes["user"], item.attributes["server"]))
+            gnomekeyring.item_delete_sync (keyring, item.item_id)
+        
+        # Add the 'user' attribute to attrs and commit it to the keyring
+        LOGGER.debug ("Creating new account %s %s" % (user, self._host))
+        attrs["user"] = user
+        gnomekeyring.item_create_sync(keyring,
+                                      gnomekeyring.ITEM_NETWORK_PASSWORD,
+                                      self._realm, attrs, pw, True)
+        
+        LOGGER.debug ("Credential update success")
 
 class AccountDialog (gtk.MessageDialog):
     """



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]