[vlc-devel] [PATCH] keystore: always store to the memory keystore

Thomas Guillem thomas at gllm.fr
Tue Dec 15 13:03:04 CET 2020


The memory keystore was never used if the system keystore was
functional. This caused several issue:
 - No caching of the system keystore (slower)
 - Guest account always tried in the first place on some access modules
   (mainly SMB ones).

Indeed, modules generally do a first query via the credential API
without triggering any user interaction (so no system keystore and no
dialog). The first time an URL is opened, the credential API won't
return a valid result and the module will fallback to the Guest account.
If the Guest account fail, modules query the credential with an user
interaction to find the correct user account.

Always saving to the memory keystore will allow the next open of an URL
to first try the correct account without trying the Guest account..
---
 src/misc/keystore.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/misc/keystore.c b/src/misc/keystore.c
index d58e8dea982..a35b905223b 100644
--- a/src/misc/keystore.c
+++ b/src/misc/keystore.c
@@ -507,23 +507,24 @@ vlc_credential_store(vlc_credential *p_credential, vlc_object_t *p_parent)
 {
     if (!is_credential_valid(p_credential))
         return false;
-    /* Don't need to store again */
-    if (p_credential->b_from_keystore)
-        return p_credential->b_from_keystore;
 
-    vlc_keystore *p_keystore;
-    if (p_credential->b_store)
+    vlc_keystore *keystores[2];
+    size_t keystores_count = 0;
+
+    /* Memory keystore */
+    keystores[keystores_count] = get_memory_keystore(p_parent);
+    if (keystores[keystores_count] != NULL)
+        keystores_count++;
+
+    if (p_credential->b_store
+     && !p_credential->b_from_keystore /* Don't need to store again */ )
     {
         /* Store in permanent keystore */
         assert(p_credential->p_keystore != NULL);
-        p_keystore = p_credential->p_keystore;
-    }
-    else
-    {
-        /* Store in memory keystore */
-        p_keystore = get_memory_keystore(p_parent);
+        keystores[keystores_count++] = p_credential->p_keystore;
     }
-    if (p_keystore == NULL)
+
+    if (keystores_count == 0)
         return false;
 
     const vlc_url_t *p_url = p_credential->p_url;
@@ -573,8 +574,14 @@ vlc_credential_store(vlc_credential *p_credential, vlc_object_t *p_parent)
     const uint8_t *p_password = (const uint8_t *)
         (p_credential->psz_password != NULL ? p_credential->psz_password : "");
 
-    bool b_ret = vlc_keystore_store(p_keystore, ppsz_values, p_password,
-                                    -1, psz_label) == VLC_SUCCESS;
+    bool b_ret = false;
+    for (size_t i = 0; i < keystores_count; ++i)
+    {
+        int err = vlc_keystore_store(keystores[i], ppsz_values, p_password,
+                                     -1, psz_label);
+        if (err == VLC_SUCCESS)
+            b_ret = true;
+    }
     free(psz_label);
     free(psz_path);
     return b_ret;
-- 
2.29.2



More information about the vlc-devel mailing list