diff options
author | Stuart Connolly <stuart02@gmail.com> | 2014-01-17 01:35:24 +0000 |
---|---|---|
committer | Stuart Connolly <stuart02@gmail.com> | 2014-01-17 01:35:24 +0000 |
commit | 834724b5b23c774b1750b2ba53e6be9d02128edb (patch) | |
tree | 938183e18fef685aab89bcfa1292b40e0a44a00b /Source/SPKeychain.m | |
parent | fda4c9c9a138b5b640275c16f01bd0557ccc402e (diff) | |
download | sequelpro-834724b5b23c774b1750b2ba53e6be9d02128edb.tar.gz sequelpro-834724b5b23c774b1750b2ba53e6be9d02128edb.tar.bz2 sequelpro-834724b5b23c774b1750b2ba53e6be9d02128edb.zip |
Restore old keychain code when building against 10.7
Diffstat (limited to 'Source/SPKeychain.m')
-rw-r--r-- | Source/SPKeychain.m | 35 |
1 files changed, 35 insertions, 0 deletions
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 } /** |