[vlc-commits] keychain: make sure to also return the username in addition to memorized passwords if needed (closes #20112)

2018-04-12 Thread Felix Paul Kühne
vlc/vlc-3.0 | branch: master | Felix Paul Kühne  | Sun Apr  8 
23:08:55 2018 +0200| [54055e4f933d37dc76013a0feb0c5b498c9e396f] | committer: 
David Fuhrmann

keychain: make sure to also return the username in addition to memorized 
passwords if needed (closes #20112)

(cherry picked from commit d1032043446104ba85739466f157633d12be2a32)
Signed-off-by: David Fuhrmann 

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=54055e4f933d37dc76013a0feb0c5b498c9e396f
---

 modules/keystore/keychain.m | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/modules/keystore/keychain.m b/modules/keystore/keychain.m
index 98a888d51b..e4b22b10b8 100644
--- a/modules/keystore/keychain.m
+++ b/modules/keystore/keychain.m
@@ -371,19 +371,17 @@ static unsigned int Find(vlc_keystore *p_keystore,
 SecKeychainAttributeInfo attrInfo;
 attrInfo.count = 0;
 
-#ifndef NDEBUG
 attrInfo.count = 1;
 UInt32 tags[1] = {kSecAccountItemAttr}; //, kSecAccountItemAttr, 
kSecServerItemAttr, kSecPortItemAttr, kSecProtocolItemAttr, kSecPathItemAttr};
 attrInfo.tag = tags;
 attrInfo.format = NULL;
-#endif
 
 SecKeychainAttributeList *attrList = NULL;
 
-UInt32 dataLength;
-void * data;
+UInt32 secretDataLength;
+void * secretData;
 
-status = SecKeychainItemCopyAttributesAndData(itemRef, , 
NULL, , , );
+status = SecKeychainItemCopyAttributesAndData(itemRef, , 
NULL, , , );
 
 if (status != noErr) {
 msg_Err(p_keystore, "Lookup error: %i (%s)", status, 
[ErrorForStatus(status) UTF8String]);
@@ -391,30 +389,29 @@ static unsigned int Find(vlc_keystore *p_keystore,
 return 0;
 }
 
-#ifndef NDEBUG
 for (unsigned x = 0; x < attrList->count; x++) {
 SecKeychainAttribute *attr = >attr[i];
 switch (attr->tag) {
-case kSecLabelItemAttr:
-NSLog(@"label %@", [[NSString alloc] 
initWithBytes:attr->data length:attr->length encoding:NSUTF8StringEncoding]);
-break;
 case kSecAccountItemAttr:
-NSLog(@"account %@", [[NSString alloc] 
initWithBytes:attr->data length:attr->length encoding:NSUTF8StringEncoding]);
+if (!p_entry->ppsz_values[KEY_USER]) {
+uint8_t *paddedAccountAttribute = calloc(1, attr->length + 
1);
+memcpy(paddedAccountAttribute, attr->data, attr->length);
+p_entry->ppsz_values[KEY_USER] = strdup((const char 
*)attr->data);
+free(paddedAccountAttribute);
+}
 break;
 default:
 break;
 }
 }
-#endif
 
 /* we need to do some padding here, as string is expected to be 0 
terminated */
-uint8_t *retData = calloc(1, dataLength + 1);
-memcpy(retData, data, dataLength);
-
-vlc_keystore_entry_set_secret(p_entry, retData, dataLength + 1);
+uint8_t *paddedSecretData = calloc(1, secretDataLength + 1);
+memcpy(paddedSecretData, secretData, secretDataLength);
+vlc_keystore_entry_set_secret(p_entry, paddedSecretData, 
secretDataLength + 1);
+free(paddedSecretData);
 
-free(retData);
-SecKeychainItemFreeAttributesAndData(attrList, data);
+SecKeychainItemFreeAttributesAndData(attrList, secretData);
 }
 
 *pp_entries = p_entries;

___
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits


[vlc-commits] keychain: make sure to also return the username in addition to memorized passwords if needed (closes #20112)

2018-04-08 Thread Felix Paul Kühne
vlc | branch: master | Felix Paul Kühne  | Sun Apr  8 23:08:55 
2018 +0200| [d1032043446104ba85739466f157633d12be2a32] | committer: Felix Paul 
Kühne

keychain: make sure to also return the username in addition to memorized 
passwords if needed (closes #20112)

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

 modules/keystore/keychain.m | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/modules/keystore/keychain.m b/modules/keystore/keychain.m
index 98a888d51b..e4b22b10b8 100644
--- a/modules/keystore/keychain.m
+++ b/modules/keystore/keychain.m
@@ -371,19 +371,17 @@ static unsigned int Find(vlc_keystore *p_keystore,
 SecKeychainAttributeInfo attrInfo;
 attrInfo.count = 0;
 
-#ifndef NDEBUG
 attrInfo.count = 1;
 UInt32 tags[1] = {kSecAccountItemAttr}; //, kSecAccountItemAttr, 
kSecServerItemAttr, kSecPortItemAttr, kSecProtocolItemAttr, kSecPathItemAttr};
 attrInfo.tag = tags;
 attrInfo.format = NULL;
-#endif
 
 SecKeychainAttributeList *attrList = NULL;
 
-UInt32 dataLength;
-void * data;
+UInt32 secretDataLength;
+void * secretData;
 
-status = SecKeychainItemCopyAttributesAndData(itemRef, , 
NULL, , , );
+status = SecKeychainItemCopyAttributesAndData(itemRef, , 
NULL, , , );
 
 if (status != noErr) {
 msg_Err(p_keystore, "Lookup error: %i (%s)", status, 
[ErrorForStatus(status) UTF8String]);
@@ -391,30 +389,29 @@ static unsigned int Find(vlc_keystore *p_keystore,
 return 0;
 }
 
-#ifndef NDEBUG
 for (unsigned x = 0; x < attrList->count; x++) {
 SecKeychainAttribute *attr = >attr[i];
 switch (attr->tag) {
-case kSecLabelItemAttr:
-NSLog(@"label %@", [[NSString alloc] 
initWithBytes:attr->data length:attr->length encoding:NSUTF8StringEncoding]);
-break;
 case kSecAccountItemAttr:
-NSLog(@"account %@", [[NSString alloc] 
initWithBytes:attr->data length:attr->length encoding:NSUTF8StringEncoding]);
+if (!p_entry->ppsz_values[KEY_USER]) {
+uint8_t *paddedAccountAttribute = calloc(1, attr->length + 
1);
+memcpy(paddedAccountAttribute, attr->data, attr->length);
+p_entry->ppsz_values[KEY_USER] = strdup((const char 
*)attr->data);
+free(paddedAccountAttribute);
+}
 break;
 default:
 break;
 }
 }
-#endif
 
 /* we need to do some padding here, as string is expected to be 0 
terminated */
-uint8_t *retData = calloc(1, dataLength + 1);
-memcpy(retData, data, dataLength);
-
-vlc_keystore_entry_set_secret(p_entry, retData, dataLength + 1);
+uint8_t *paddedSecretData = calloc(1, secretDataLength + 1);
+memcpy(paddedSecretData, secretData, secretDataLength);
+vlc_keystore_entry_set_secret(p_entry, paddedSecretData, 
secretDataLength + 1);
+free(paddedSecretData);
 
-free(retData);
-SecKeychainItemFreeAttributesAndData(attrList, data);
+SecKeychainItemFreeAttributesAndData(attrList, secretData);
 }
 
 *pp_entries = p_entries;

___
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits