#ifndef _SECURITY_STORAGEMANAGER_H_
#define _SECURITY_STORAGEMANAGER_H_
#include <list>
#include <set>
#include <security_keychain/DLDBListCFPref.h>
#include <security_keychain/DynamicDLDBList.h>
#include <security_keychain/Keychains.h>
#include <security_keychain/KeyItem.h>
#include <Security/Authorization.h>
#define kLegacyKeychainRenamedSuffix "_renamed"
#define kKeychainRenamedSuffix "_renamed_"
namespace Security
{
namespace KeychainCore
{
class StorageManager
{
NOCOPY(StorageManager)
public:
typedef vector<Keychain> KeychainList;
typedef vector<DLDbIdentifier> DLDbList;
StorageManager();
~StorageManager() {}
Mutex* getStorageManagerMutex();
Keychain make(const char *fullPathName);
Keychain make(const char *fullPathName, bool add);
Keychain makeLoginAuthUI(const Item *item);
void created(const Keychain &keychain);
void lockAll();
void add(const Keychain& keychainToAdd);
size_t size();
Keychain at(unsigned int ix);
Keychain operator[](unsigned int ix);
KCCursor createCursor(const SecKeychainAttributeList *attrList);
KCCursor createCursor(SecItemClass itemClass, const SecKeychainAttributeList *attrList);
Keychain keychain(const DLDbIdentifier &dLDbIdentifier);
void removeKeychain(const DLDbIdentifier &dLDbIdentifier, KeychainImpl *keychainImpl);
void didRemoveKeychain(const DLDbIdentifier &dLDbIdentifier);
Keychain makeKeychain(const DLDbIdentifier &dLDbIdentifier, bool add = true);
void remove(const KeychainList &kcsToRemove, bool deleteDb = false);
void getSearchList(KeychainList &keychainList);
void setSearchList(const KeychainList &keychainList);
void forceUserSearchListReread ();
void getSearchList(SecPreferencesDomain domain, KeychainList &keychainList);
void setSearchList(SecPreferencesDomain domain, const KeychainList &keychainList);
void rename(Keychain keychain, const char* newName);
void renameUnique(Keychain keychain, CFStringRef newName);
void optionalSearchList(CFTypeRef keychainOrArray, KeychainList &keychainList);
static void convertToKeychainList(CFArrayRef keychainArray, KeychainList &keychainList);
static CFArrayRef convertFromKeychainList(const KeychainList &keychainList);
void login(AuthorizationRef authRef, UInt32 nameLength, const char* name);
void login(ConstStringPtr name, ConstStringPtr password);
void login(UInt32 nameLength, const void *name, UInt32 passwordLength, const void *password);
void stashLogin();
void stashKeychain();
void logout();
void changeLoginPassword(ConstStringPtr oldPassword, ConstStringPtr newPassword);
void changeLoginPassword(UInt32 oldPasswordLength, const void *oldPassword, UInt32 newPasswordLength, const void *newPassword);
void resetKeychain(Boolean resetSearchList);
Keychain defaultKeychain();
Keychain defaultKeychainUI(Item &item);
void defaultKeychain(const Keychain &keychain);
Keychain loginKeychain();
void loginKeychain(Keychain keychain);
Keychain defaultKeychain(SecPreferencesDomain domain);
void defaultKeychain(SecPreferencesDomain domain, const Keychain &keychain);
SecPreferencesDomain domain() { return mDomain; }
void domain(SecPreferencesDomain newDomain);
bool keychainOwnerPermissionsValidForDomain(const char* path, SecPreferencesDomain domain);
void addToDomainList(SecPreferencesDomain domain, const char* dbName, const CSSM_GUID &guid, uint32 subServiceType);
void isInDomainList(SecPreferencesDomain domain, const char* dbName, const CSSM_GUID &guid, uint32 subServiceType);
void removeFromDomainList(SecPreferencesDomain domain, const char* dbName, const CSSM_GUID &guid, uint32 subServiceType);
private:
static void convertList(DLDbList &ids, const KeychainList &kcs);
void convertList(KeychainList &kcs, const DLDbList &ids);
void addAndNotify(const Keychain& keychainToAdd);
void removeKeychainFromSyncList (const DLDbIdentifier &id);
typedef map<DLDbIdentifier, __weak KeychainImpl *> KeychainMap;
KeychainMap mKeychains;
DynamicDLDBList mDynamicList;
DLDbListCFPref mSavedList;
DLDbListCFPref mCommonList;
SecPreferencesDomain mDomain; Mutex mMutex;
RecursiveMutex mKeychainMapMutex;
};
}
}
#endif // !_SECURITY_STORAGEMANAGER_H_