#include "Record.h"
#include <security_cdsa_client/aclclient.h>
namespace Tokend
{
AutoAclOwnerPrototype Record::gNobodyAclOwner;
AutoAclEntryInfoList Record::gAnyReadAclEntries;
Record::Record()
{
}
Record::~Record()
{
for_each_delete(mAttributes.begin(), mAttributes.end());
}
bool
Record::hasAttributeAtIndex(uint32 attributeIndex) const
{
if (attributeIndex < mAttributes.size())
return mAttributes[attributeIndex] != NULL;
return false;
}
const Attribute &
Record::attributeAtIndex(uint32 attributeIndex) const
{
if (attributeIndex < mAttributes.size())
{
Attribute *attribute = mAttributes[attributeIndex];
if (attribute)
return *attribute;
}
CssmError::throwMe(CSSMERR_DL_INTERNAL_ERROR);
}
void Record::attributeAtIndex(uint32 attributeIndex, Attribute *attribute)
{
auto_ptr<Attribute> _(attribute);
if (attributeIndex >= mAttributes.size())
mAttributes.resize(attributeIndex + 1);
if (mAttributes[attributeIndex] != NULL)
CssmError::throwMe(CSSMERR_DL_INTERNAL_ERROR);
mAttributes[attributeIndex] = _.release();
}
void Record::getOwner(AclOwnerPrototype &owner)
{
if (!gNobodyAclOwner)
{
Allocator &alloc = Allocator::standard();
gNobodyAclOwner.allocator(alloc);
gNobodyAclOwner = CssmClient::AclFactory::NobodySubject(alloc);
}
owner = gNobodyAclOwner;
}
void Record::getAcl(const char *tag, uint32 &count, AclEntryInfo *&acls)
{
if (!gAnyReadAclEntries) {
gAnyReadAclEntries.allocator(Allocator::standard());
gAnyReadAclEntries.add(CssmClient::AclFactory::AnySubject(
gAnyReadAclEntries.allocator()),
AclAuthorizationSet(CSSM_ACL_AUTHORIZATION_DB_READ, 0));
}
count = gAnyReadAclEntries.size();
acls = gAnyReadAclEntries.entries();
}
void Record::changeOwner(const AclOwnerPrototype &owner)
{
CssmError::throwMe(CSSM_ERRCODE_OBJECT_MANIP_AUTH_DENIED);
}
void Record::changeAcl(const AccessCredentials &cred, const AclEdit &edit)
{
CssmError::throwMe(CSSM_ERRCODE_OBJECT_MANIP_AUTH_DENIED);
}
const char *Record::description()
{
CssmError::throwMe(CSSMERR_DL_MISSING_VALUE);
}
Attribute *Record::getDataAttribute(TokenContext *tokenContext)
{
CssmError::throwMe(CSSMERR_DL_MISSING_VALUE);
}
}