-
-OSStatus SecKeychainListRemoveKeychain(SecKeychainRef *keychainRef)
-{
- BEGIN_SECAPI
- list<SecKeychainRef> SecKeychainRefToRemove;
- SecKeychainRefToRemove.push_back(RequiredParam(keychainRef));
- StorageManager &smgr = globals().storageManager;
- smgr.remove(SecKeychainRefToRemove);
- return noErr;
- END_SECAPI
-}
-
-
-pascal OSStatus SecKeychainAddCallback(SecKeychainCallbackProcPtr callbackFunction, SecKeychainEventMask eventMask, void* userContext)
-{
- BEGIN_SECAPI
- RequiredParam(callbackFunction);
- CCallbackMgr::AddCallback(callbackFunction,eventMask,userContext);
- END_SECAPI
-}
-
-OSStatus SecKeychainRemoveCallback(SecKeychainCallbackProcPtr callbackFunction)
-{
- BEGIN_SECAPI
- RequiredParam(callbackFunction);
- CCallbackMgr::RemoveCallback(callbackFunction);
- END_SECAPI
-}
-
-
-// --- Private API
-
-OSStatus SecKeychainChangePassword(SecKeychainRef keychainRef, UInt32 oldPasswordLength, const void *oldPassword, UInt32 newPasswordLength, const void *newPassword)
-{
- BEGIN_SECAPI
- globals().storageManager.changeLoginPassword(oldPasswordLength, oldPassword, newPasswordLength, newPassword);
- END_SECAPI
-}
-
-OSStatus SecKeychainCopyLogin(SecKeychainRef *keychainRef)
-{
- BEGIN_SECAPI
- // NOTE: operates on default Keychain! It shouldn't... we want to
- // have code that operates of a login keychain.
- RequiredParam(keychainRef)=KeychainRef::handle(globals().defaultKeychain.keychain());
- END_SECAPI
-}
-
-
-OSStatus SecKeychainAddInternetPassword(SecKeychainRef keychainRef, UInt32 serverNameLength, char *serverName,
- UInt32 securityDomainLength, char *securityDomain, UInt32 accountNameLength, char *accountName,
- UInt32 pathLength, char *path, UInt16 port, OSType protocol, OSType authType,
- UInt32 passwordLength, const void *passwordData, SecKeychainItemRef *itemRef)
-{
- BEGIN_SECAPI
- KCThrowParamErrIf_(passwordLength!=0 && passwordData==NULL);
- // @@@ Get real itemClass
- Item item(kSecInternetPasswordItemClass, 'aapl', passwordLength, passwordData);
-
- if (serverName && serverNameLength)
- item->setAttribute(Schema::attributeInfo(kSecServerItemAttr),
- CssmData(serverName, serverNameLength));
-
- if (accountName && accountNameLength)
- {
- CssmData account(accountName, accountNameLength);
- item->setAttribute(Schema::attributeInfo(kSecAccountItemAttr), account);
- // @@@ We should probably leave setting of label up to lower level code.
- item->setAttribute(Schema::attributeInfo(kSecLabelItemAttr), account);
- }
-
- if (securityDomain && securityDomainLength)
- item->setAttribute(Schema::attributeInfo(kSecSecurityDomainItemAttr),
- CssmData(securityDomain, securityDomainLength));
-
- item->setAttribute(Schema::attributeInfo(kSecPortItemAttr), UInt32(port));
- item->setAttribute(Schema::attributeInfo(kSecProtocolItemAttr), protocol);
- item->setAttribute(Schema::attributeInfo(kSecAuthTypeItemAttr), authType);
-
- if (path && pathLength)
- item->setAttribute(Schema::attributeInfo(kSecPathItemAttr),
- CssmData(path, pathLength));
-
- Keychain::optional(keychainRef)->add(item);
- if (itemRef)
- *itemRef = ItemRef::handle(item);
-
- END_SECAPI
-}
-
-OSStatus SecKeychainFindInternetPassword(SecKeychainRef keychainRef, UInt32 serverNameLength, char *serverName,
- UInt32 securityDomainLength, char *securityDomain, UInt32 accountNameLength, char *accountName,
- UInt32 pathLength, char *path, UInt16 port, OSType protocol, OSType authType,
- UInt32 *passwordLength, void **passwordData, SecKeychainItemRef *itemRef)
-
-{
- BEGIN_SECAPI
-
-
- UInt32 attrCount = 0;
-
- // The number of attributes to search on depends on what was passed in
- if ( serverName && serverNameLength)
- attrCount++;
-
- if ( securityDomain && securityDomainLength )
- attrCount++;
-
- if ( accountName && accountNameLength)
- attrCount++;
-
- if ( port )
- attrCount++;
-
- if ( protocol )
- attrCount++;
-
- if ( authType )
- attrCount++;
-
- if ( path && pathLength )
- attrCount++;
-
- auto_array<SecKeychainAttribute> attrs(attrCount);
- attrCount = 0;
-
- if ( serverName && serverNameLength )
- {
- attrs[attrCount].tag = kSecServerItemAttr;
- attrs[attrCount].length = serverNameLength;
- attrs[attrCount].data = serverName;
- attrCount++;
- }
- if ( securityDomain && securityDomainLength )
- {
- attrs[attrCount].tag = kSecSecurityDomainItemAttr;
- attrs[attrCount].length = securityDomainLength;
- attrs[attrCount].data = securityDomain;
- attrCount++;
- }
- if ( accountName && accountNameLength )
- {
- attrs[attrCount].tag = kSecAccountItemAttr;
- attrs[attrCount].length = accountNameLength;
- attrs[attrCount].data = accountName;
- attrCount++;
- }
-
- if ( port )
- {
- attrs[attrCount].tag = kSecPortItemAttr;
- attrs[attrCount].length = sizeof( port );
- attrs[attrCount].data = &port;
- attrCount++;
- }
- if ( protocol )
- {
- attrs[attrCount].tag = kSecProtocolItemAttr;
- attrs[attrCount].length = sizeof( protocol );
- attrs[attrCount].data = &protocol;
- attrCount++;
- }
- if ( authType )
- {
- attrs[attrCount].tag = kSecAuthTypeItemAttr;
- attrs[attrCount].length = sizeof( authType );
- attrs[attrCount].data = &authType;
- attrCount++;
- }
-
- if ( path && pathLength )
- {
- attrs[attrCount].tag = kSecPathItemAttr;
- attrs[attrCount].length = pathLength;
- attrs[attrCount].data = path;
- attrCount++;
- }
-
- SecKeychainAttributeList attrList;
- attrList.count = attrCount;
- attrList.attr = attrs.get();
-
- Item item;
-
- KCCursor cursor;
- if (keychainRef)
- cursor = Keychain::optional(keychainRef)->createCursor(kSecInternetPasswordItemClass, &attrList);
- else
- cursor = globals().storageManager.createCursor(kSecInternetPasswordItemClass, &attrList);
-
- if (!cursor->next(item))
- return errSecItemNotFound;
-
-
- // Get its data (only if necessary)
- if ( passwordData || passwordLength )
- {
- CssmDataContainer outData;
- item->getData(outData);
- *passwordLength=outData.length();
- outData.Length=NULL;
- *passwordData=outData.data();
- outData.Data=NULL;
- }
-
- if (itemRef)
- *itemRef=ItemRef::handle(item);
-
-
- END_SECAPI
-
-
-
-}
-
-OSStatus SecKeychainAddGenericPassword(SecKeychainRef keychainRef, UInt32 serviceNameLength, char *serviceName,
- UInt32 accountNameLength, char *accountName,
- UInt32 passwordLength, const void *passwordData, SecKeychainItemRef *itemRef)
-
-{
- BEGIN_SECAPI
-
- KCThrowParamErrIf_(passwordLength!=0 && passwordData==NULL);
- // @@@ Get real itemClass
- Item item(kSecGenericPasswordItemClass, 'aapl', passwordLength, passwordData);
-
- if (serviceName && serviceNameLength)
- item->setAttribute(Schema::attributeInfo(kSecServiceItemAttr), CssmData(serviceName, serviceNameLength));
-
- if (accountName && accountNameLength)
- {
- CssmData account(accountName, accountNameLength);
- item->setAttribute(Schema::attributeInfo(kSecAccountItemAttr), account);
- // @@@ We should probably leave setting of label up to lower level code.
- item->setAttribute(Schema::attributeInfo(kSecLabelItemAttr), account);
- }
-
- Keychain::optional(keychainRef)->add(item);
- if (itemRef)
- *itemRef = ItemRef::handle(item);
-
- END_SECAPI
-}
-
-OSStatus SecKeychainFindGenericPassword(SecKeychainRef keychainRef, UInt32 serviceNameLength, char *serviceName,
- UInt32 accountNameLength, char *accountName,
- UInt32 *passwordLength, void **passwordData, SecKeychainItemRef *itemRef)
-
-{
- BEGIN_SECAPI
- UInt32 attrCount = 0;
-
- // The number of attributes to search on depends on what was passed in
- if (serviceName && serviceNameLength)
- attrCount++;
-
- if (accountName && accountNameLength)
- attrCount++;
-
- auto_array<SecKeychainAttribute> attrs(attrCount);
- attrCount = 0;
-
- if (serviceName && serviceNameLength)
- {
- attrs[attrCount].tag = kSecServiceItemAttr;
- attrs[attrCount].length = serviceNameLength;
- attrs[attrCount].data = serviceName;
- attrCount++;
- }
- if (accountName && accountNameLength)
- {
- attrs[attrCount].tag = kSecAccountItemAttr;
- attrs[attrCount].length = accountNameLength;
- attrs[attrCount].data = accountName;
- attrCount++;
- }
-
- SecKeychainAttributeList attrList;
- attrList.count = attrCount;
- attrList.attr = attrs.get();
-
- Item item;
-
- KCCursor cursor;
- if (keychainRef)
- cursor = Keychain::optional(keychainRef)->createCursor(kSecGenericPasswordItemClass, &attrList);
- else
- cursor = globals().storageManager.createCursor(kSecGenericPasswordItemClass, &attrList);
-
- if (!cursor->next(item))
- return errSecItemNotFound;
-
-
- // Get its data (only if necessary)
- if ( passwordData || passwordLength )
- {
- CssmDataContainer outData;
- item->getData(outData);
- *passwordLength=outData.length();
- outData.Length=NULL;
- *passwordData=outData.data();
- outData.Data=NULL;
- }
-
- if (itemRef)
- *itemRef=ItemRef::handle(item);
-
-
- END_SECAPI
-}
-
-OSStatus SecKeychainLogin(UInt32 nameLength, void* name, UInt32 passwordLength, void* password)
-{
- BEGIN_SECAPI
- globals().storageManager.login(nameLength, name, passwordLength, password);
- END_SECAPI
-}
-
-OSStatus SecKeychainLogout()
-{
- BEGIN_SECAPI
- globals().storageManager.logout();
- END_SECAPI