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

Thomas Guillem thomas at gllm.fr
Fri Dec 18 10:31:40 UTC 2020


That way, it can be used when switching from interact to nointeract or if
the system keystore become dysfunctional (no valid pin/passphrase).
---
 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 328c8ef3733..8fcc6523671 100644
--- a/src/misc/keystore.c
+++ b/src/misc/keystore.c
@@ -550,23 +550,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;
@@ -616,8 +617,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