[vlc-devel] [PATCH 4/6] keychain: always use values from the keychain

Thomas Guillem thomas at gllm.fr
Thu Oct 31 15:38:10 CET 2019


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

Needed for the test_modules_keystore success.
---
 modules/keystore/keychain.m | 59 ++++++++++++++++++++++++++++++++-----
 1 file changed, 51 insertions(+), 8 deletions(-)

diff --git a/modules/keystore/keychain.m b/modules/keystore/keychain.m
index c79b8bf5eb6..779196090b7 100644
--- a/modules/keystore/keychain.m
+++ b/modules/keystore/keychain.m
@@ -267,6 +267,53 @@ 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])
+{
+#define SET_STR(key, str) do { \
+    ppsz_values[key] = strdup(str); \
+    if (!ppsz_values[key]) \
+        return VLC_ENOMEM; \
+} while(0)
+#define SET_NSSTR(key, nsstr) SET_STR(key, [nsstr UTF8String])
+#define SET_NSNBR(key, nsnbr) SET_NSSTR(key, [nsnbr stringValue])
+
+    id protocol = [item objectForKey:(__bridge id)kSecAttrProtocol];
+    if (protocol == (__bridge id)kSecAttrProtocolFTP)
+        SET_STR(KEY_PROTOCOL, "ftp");
+    else if (protocol == (__bridge id)kSecAttrProtocolFTPS)
+        SET_STR(KEY_PROTOCOL, "ftps");
+    else if (protocol == (__bridge id)kSecAttrProtocolHTTP)
+        SET_STR(KEY_PROTOCOL, "http");
+    else if (protocol == (__bridge id)kSecAttrProtocolHTTPS)
+        SET_STR(KEY_PROTOCOL, "https");
+    else if (protocol == (__bridge id)kSecAttrProtocolRTSP)
+        SET_STR(KEY_PROTOCOL, "rtsp");
+    else if (protocol == (__bridge id)kSecAttrProtocolSSH)
+        SET_STR(KEY_PROTOCOL, "sftp");
+    else if (protocol == (__bridge id)kSecAttrProtocolSMB)
+        SET_STR(KEY_PROTOCOL, "smb");
+    else
+        return VLC_EGENERIC;
+
+    NSString *user = [item objectForKey:(__bridge id)kSecAttrAccount];
+    if (user)
+        SET_NSSTR(KEY_USER, user);
+
+    NSString *server = [item objectForKey:(__bridge id)kSecAttrServer];
+    if (server)
+        SET_NSSTR(KEY_SERVER, server);
+
+    NSString *path = [item objectForKey:(__bridge id)kSecAttrPath];
+    if (path)
+        SET_NSSTR(KEY_PATH, path);
+
+    NSNumber *port = [item objectForKey:(__bridge id)kSecAttrPort];
+    if (port)
+        SET_NSNBR(KEY_PORT, port);
+
+    return VLC_SUCCESS;
+}
+
 static int Store(vlc_keystore *p_keystore,
                  const char *const ppsz_values[KEY_MAX],
                  const uint8_t *p_secret,
@@ -369,13 +416,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];
@@ -391,11 +439,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)]) {
-- 
2.20.1



More information about the vlc-devel mailing list