Created
September 25, 2009 08:54
-
-
Save floehopper/193415 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void addInternetPassword(NSString *password, NSString *account, | |
NSString *server, NSString *itemLabel, NSString *path, | |
SecProtocolType protocol, int port) | |
{ | |
OSStatus err; | |
SecKeychainItemRef item = nil; | |
const char *pathUTF8 = [path UTF8String]; | |
const char *serverUTF8 = [server UTF8String]; | |
const char *accountUTF8 = [account UTF8String]; | |
const char *passwordUTF8 = [password UTF8String]; | |
const char *itemLabelUTF8 = [itemLabel UTF8String]; | |
//Create initial access control settings for the item: | |
SecAccessRef access = createAccess(itemLabel); | |
//Following is the lower-level equivalent to the | |
// SecKeychainAddInternetPassword function: | |
//Set up the attribute vector (each attribute consists | |
// of {tag, length, pointer}): | |
SecKeychainAttribute attrs[] = { | |
{ kSecLabelItemAttr, strlen(itemLabelUTF8), (char *)itemLabelUTF8 }, | |
{ kSecAccountItemAttr, strlen(accountUTF8), (char *)accountUTF8 }, | |
{ kSecServerItemAttr, strlen(serverUTF8), (char *)serverUTF8 }, | |
{ kSecPortItemAttr, sizeof(int), (int *)&port }, | |
{ kSecProtocolItemAttr, sizeof(SecProtocolType), | |
(SecProtocolType *)&protocol }, | |
{ kSecPathItemAttr, strlen(pathUTF8), (char *)pathUTF8 } | |
}; | |
SecKeychainAttributeList attributes = { sizeof(attrs) / sizeof(attrs[0]), | |
attrs }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment