[gvfs/wip/oholy/keyring-order: 4/4] keyring: Prefer the most recent item



commit 2c472cd9e9607138ddaad9fcc3c5a37d5572ba02
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Dec 18 13:26:29 2018 +0100

    keyring: Prefer the most recent item
    
    If keyring contains more entries for one host, the first one is always
    used. However, this is not always the best one. Imagine the situation
    that the username was changed on the server for some reason and the
    previous username is invalid. When user connects using the new username,
    a new entry is added to the keyring. However, next time the old username
    is automatically used when mounting using the hostname only, which leads
    to login failures and the user has to specify its password each time...
    Prefer the most recent item from keyring if they are equal in specificity
    in order to prevent such issues.
    
    It would be best to remove the invalid entry automatically from the
    keyring, but it is not safe to remove it just in case of login failure,
    because it might be just some network outage, or so...
    
    https://gitlab.gnome.org/GNOME/gvfs/issues/352

 daemon/gvfskeyring.c | 4 ++++
 1 file changed, 4 insertions(+)
---
diff --git a/daemon/gvfskeyring.c b/daemon/gvfskeyring.c
index 556672be..8fa56f78 100644
--- a/daemon/gvfskeyring.c
+++ b/daemon/gvfskeyring.c
@@ -153,6 +153,10 @@ compare_specificity (gconstpointer  a,
 
   res = g_hash_table_size (attributes_a) - g_hash_table_size (attributes_b);
 
+  /* Prefer the most recent item if they are equal in specificity. */
+  if (res == 0)
+    res = secret_item_get_modified (item_b) - secret_item_get_modified (item_a);
+
   g_hash_table_unref (attributes_a);
   g_hash_table_unref (attributes_b);
 


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