[vlc-commits] keychain: always use values from the keychain

Thomas Guillem git at videolan.org
Thu Nov 14 15:24:04 CET 2019


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Oct 31 15:30:54 2019 +0100| [7902e12f2e4418f22a9f2b06b1d5f86ba3ce09b7] | committer: Thomas Guillem

keychain: always use values from the keychain

Specially since the keychain could store more informations that the search
query.

Needed for the test_modules_keystore success.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7902e12f2e4418f22a9f2b06b1d5f86ba3ce09b7
---

 modules/keystore/keychain.m | 57 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 8 deletions(-)

diff --git a/modules/keystore/keychain.m b/modules/keystore/keychain.m
index d8852e061a..dde0723745 100644
--- a/modules/keystore/keychain.m
+++ b/modules/keystore/keychain.m
@@ -268,6 +268,51 @@ static int SetAttributesForQuery(const char *const ppsz_values[KEY_MAX], NSMutab
     return VLC_SUCCESS;
 }
 
+static int FillEntryValues(const NSDictionary *item, char *ppsz_values[KEY_MAX])
+{
+    NSString *protocol = [item objectForKey:(__bridge id)kSecAttrProtocol];
+    if (protocol)
+    {
+        ppsz_values[KEY_PROTOCOL] = strdup([protocol UTF8String]);
+        if (!ppsz_values[KEY_PROTOCOL])
+            return VLC_ENOMEM;
+    }
+
+    NSString *user = [item objectForKey:(__bridge id)kSecAttrAccount];
+    if (user)
+    {
+        ppsz_values[KEY_USER] = strdup([user UTF8String]);
+        if (!ppsz_values[KEY_USER])
+            return VLC_ENOMEM;
+    }
+
+    NSString *server = [item objectForKey:(__bridge id)kSecAttrServer];
+    if (server)
+    {
+        ppsz_values[KEY_SERVER] = strdup([server UTF8String]);
+        if (!ppsz_values[KEY_SERVER])
+            return VLC_ENOMEM;
+    }
+
+    NSString *path = [item objectForKey:(__bridge id)kSecAttrPath];
+    if (path)
+    {
+        ppsz_values[KEY_PATH] = strdup([path UTF8String]);
+        if (!ppsz_values[KEY_PATH])
+            return VLC_ENOMEM;
+    }
+
+    NSNumber *port = [item objectForKey:(__bridge id)kSecAttrPort];
+    if (port)
+    {
+        ppsz_values[KEY_PORT] = strdup([[port stringValue] UTF8String]);
+        if (!ppsz_values[KEY_PORT])
+            return VLC_ENOMEM;
+    }
+
+    return VLC_SUCCESS;
+}
+
 static int Store(vlc_keystore *p_keystore,
                  const char *const ppsz_values[KEY_MAX],
                  const uint8_t *p_secret,
@@ -370,13 +415,14 @@ static unsigned int Find(vlc_keystore *p_keystore,
 
     for (NSUInteger i = 0; i < count; i++) {
         vlc_keystore_entry *p_entry = &p_entries[i];
-        if (ks_values_copy((const char **)p_entry->ppsz_values, ppsz_values) != VLC_SUCCESS) {
+        NSDictionary *keychainItem = [listOfResults objectAtIndex:i];
+
+        if (FillEntryValues(keychainItem, p_entry->ppsz_values))
+        {
             vlc_keystore_release_entries(p_entries, 1);
             return 0;
         }
 
-        NSDictionary *keychainItem = [listOfResults objectAtIndex:i];
-
         NSString *accountName = [keychainItem objectForKey:(__bridge id)kSecAttrAccount];
         NSMutableDictionary *passwordFetchQuery = [baseLookupQuery mutableCopy];
         [passwordFetchQuery setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
@@ -392,11 +438,6 @@ static unsigned int Find(vlc_keystore *p_keystore,
             return 0;
         }
 
-        if (!p_entry->ppsz_values[KEY_USER] && accountName) {
-            msg_Dbg(p_keystore, "using account name from the keychain for login");
-            p_entry->ppsz_values[KEY_USER] = strdup([accountName UTF8String]);
-        }
-
         NSData *secretData = (__bridge_transfer NSData *)secretResult;
         NSNumber *creator = [keychainItem objectForKey:(__bridge id)kSecAttrCreator];
         if (creator && [creator isEqual:@(kVlc4Creator)]) {



More information about the vlc-commits mailing list