#include <Security/debugging.h>
#include <algorithm>
#include <cstdarg>
+#include <endian.h>
using namespace DataWalkers;
};
void ObjectAcl::validate(AclAuthorization auth, const AccessCredentials *cred,
- AclValidationEnvironment *env) const
+ AclValidationEnvironment *env)
{
+ // make sure we are ready to go
+ instantiateAcl();
+
//@@@ should pre-screen based on requested auth, maybe?
BaseValidationContext ctx(cred, auth, env);
// try owner (owner can do anything)
if (owner.validate(ctx))
return;
-#endif ACL_OMNIPOTENT_OWNER
+#endif //ACL_OMNIPOTENT_OWNER
// try applicable ACLs
pair<ConstIterator, ConstIterator> range;
}
void ObjectAcl::validateOwner(AclAuthorization authorizationHint,
- const AccessCredentials *cred, AclValidationEnvironment *env) const
+ const AccessCredentials *cred, AclValidationEnvironment *env)
{
+ instantiateAcl();
BaseValidationContext ctx(cred, authorizationHint, env);
if (owner.validate(ctx))
return;
void ObjectAcl::exportBlob(CssmData &publicBlob, CssmData &privateBlob)
{
Writer::Counter pubSize, privSize;
- uint32 entryCount = entries.size();
+ Endian<uint32> entryCount = entries.size();
owner.exportBlob(pubSize, privSize);
pubSize(entryCount);
for (Iterator it = begin(); it != end(); it++)
{
Reader pubReader(publicBlob), privReader(privateBlob);
owner.importBlob(pubReader, privReader);
- uint32 entryCount; pubReader(entryCount);
+ Endian<uint32> entryCountIn; pubReader(entryCountIn);
+ uint32 entryCount = entryCountIn;
+
entries.erase(begin(), end());
for (uint32 n = 0; n < entryCount; n++) {
AclEntry newEntry;
//
AclSubject *ObjectAcl::importSubject(Reader &pub, Reader &priv)
{
- uint32 typeAndVersion; pub(typeAndVersion);
+ Endian<uint32> typeAndVersion; pub(typeAndVersion);
return make(typeAndVersion, pub, priv);
}
+//
+// Setup/update hooks
+//
+void ObjectAcl::instantiateAcl()
+{
+ // nothing by default
+}
+
+void ObjectAcl::changedAcl()
+{
+ // nothing by default
+}
+
+
//
// ACL utility methods
//
//
void ObjectAcl::cssmGetAcl(const char *tag, uint32 &count, AclEntryInfo * &acls)
{
+ instantiateAcl();
pair<ConstIterator, ConstIterator> range;
count = getRange(tag, range);
acls = allocator.alloc<AclEntryInfo>(count);
{
IFDUMPING("acl", debugDump("acl-change-from"));
+ // make sure we're ready to go
+ instantiateAcl();
+
// validate access credentials
validateOwner(CSSM_ACL_AUTHORIZATION_CHANGE_ACL, cred, env);
default:
CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_EDIT_MODE);
}
+
+ // notify change
+ changedAcl();
IFDUMPING("acl", debugDump("acl-change-to"));
}
void ObjectAcl::cssmGetOwner(AclOwnerPrototype &outOwner)
{
+ instantiateAcl();
outOwner.TypedSubject = owner.subject->toList(allocator);
outOwner.Delegate = owner.delegate;
}
{
IFDUMPING("acl", debugDump("owner-change-from"));
+ instantiateAcl();
+
// only the owner entry can match
validateOwner(CSSM_ACL_AUTHORIZATION_CHANGE_OWNER, cred, env);
// okay, replace it
owner = newOwner;
+
+ changedAcl();
IFDUMPING("acl", debugDump("owner-change-to"));
}
void ObjectAcl::Entry::importBlob(Reader &pub, Reader &priv)
{
- uint32 del; pub(del); delegate = del; // 4 bytes delegate flag
+ Endian<uint32> del;
+ pub(del); // read del from the public blob
+
+ delegate = del; // 4 bytes delegate flag
subject = importSubject(pub, priv);
}
const char *s; pub(s); tag = s;
// authorizesAnything is on disk as a 4-byte flag
- uint32 tmpAuthorizesAnything;
+ Endian<uint32> tmpAuthorizesAnything;
pub(tmpAuthorizesAnything);
authorizesAnything = tmpAuthorizesAnything;
authorizations.erase(authorizations.begin(), authorizations.end());
if (!authorizesAnything) {
- uint32 count; pub(count);
+ Endian<uint32> countIn; pub(countIn);
+ uint32 count = countIn;
+
for (uint32 n = 0; n < count; n++) {
- AclAuthorization auth; pub(auth);
+ Endian<AclAuthorization> auth; pub(auth);
authorizations.insert(auth);
}
}
AclSubject *ObjectAcl::make(uint32 typeAndVersion, Reader &pub, Reader &priv)
{
- // this type is encode as (version << 24) | type
+ // this type is encoded as (version << 24) | type
return makerFor(typeAndVersion & ~AclSubject::versionMask).make(typeAndVersion >> AclSubject::versionShift, pub, priv);
}
}
CSSM_WORDID_TYPE AclSubject::Maker::getWord(const ListElement &elem,
- int min = 0, int max = INT_MAX)
+ int min /*= 0*/, int max /*= INT_MAX*/)
{
if (elem.type() != CSSM_LIST_ELEMENT_WORDID)
CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);