From 834724b5b23c774b1750b2ba53e6be9d02128edb Mon Sep 17 00:00:00 2001 From: Stuart Connolly Date: Fri, 17 Jan 2014 01:35:24 +0000 Subject: Restore old keychain code when building against 10.7 --- Source/SPKeychain.m | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'Source/SPKeychain.m') diff --git a/Source/SPKeychain.m b/Source/SPKeychain.m index f7580f65..cc98bf6c 100644 --- a/Source/SPKeychain.m +++ b/Source/SPKeychain.m @@ -213,6 +213,7 @@ */ - (BOOL)passwordExistsForName:(NSString *)name account:(NSString *)account { +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 NSMutableDictionary *query = [NSMutableDictionary dictionary]; [query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; @@ -225,6 +226,40 @@ CFDictionaryRef result = NULL; return SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result) == errSecSuccess; +#else + SecKeychainItemRef item; + SecKeychainSearchRef search = NULL; + NSInteger numberOfItemsFound = 0; + SecKeychainAttributeList list; + SecKeychainAttribute attributes[2]; + + // Check supplied variables and replaces nils with empty strings + if (!name) name = @""; + if (!account) account = @""; + + attributes[0].tag = kSecAccountItemAttr; + attributes[0].data = (void *)[account UTF8String]; // Account name + attributes[0].length = (UInt32)strlen([account UTF8String]); // Length of account name (bytes) + + attributes[1].tag = kSecServiceItemAttr; + attributes[1].data = (void *)[name UTF8String]; // Service name + attributes[1].length = (UInt32)strlen([name UTF8String]); // Length of service name (bytes) + + list.count = 2; + list.attr = attributes; + + if (SecKeychainSearchCreateFromAttributes(NULL, kSecGenericPasswordItemClass, &list, &search) == noErr) { + while (SecKeychainSearchCopyNext(search, &item) == noErr) + { + CFRelease(item); + numberOfItemsFound++; + } + } + + if (search) CFRelease(search); + + return (numberOfItemsFound > 0); +#endif } /** -- cgit v1.2.3