2 * Copyright (c) 2000-2004,2006,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // aclsubject - abstract ACL subject implementation
28 #include <security_cdsa_utilities/cssmacl.h>
29 #include <security_cdsa_utilities/cssmbridge.h>
30 #include <security_utilities/endian.h>
31 #include <security_utilities/debugging.h>
37 // Validation contexts
39 AclValidationContext::~AclValidationContext()
43 void AclValidationContext::init(ObjectAcl
*acl
, AclSubject
*subject
)
50 const char *AclValidationContext::credTag() const
52 return mCred
? mCred
->tag() : NULL
;
55 std::string
AclValidationContext::s_credTag() const
57 const char *s
= this->credTag();
61 const char *AclValidationContext::entryTag() const
66 void AclValidationContext::entryTag(const char *tag
)
68 mEntryTag
= (tag
&& tag
[0]) ? tag
: NULL
;
71 void AclValidationContext::entryTag(const std::string
&tag
)
73 mEntryTag
= tag
.empty() ? NULL
: tag
.c_str();
78 // Common (basic) features of AclSubjects
80 AclSubject::AclSubject(uint32 type
, Version v
/* = 0 */)
81 : mType(type
), mVersion(v
)
83 assert(!(type
& versionMask
));
86 AclSubject::~AclSubject()
89 AclValidationEnvironment::~AclValidationEnvironment()
92 Adornable
&AclValidationEnvironment::store(const AclSubject
*subject
)
94 CssmError::throwMe(CSSM_ERRCODE_ACL_SUBJECT_TYPE_NOT_SUPPORTED
);
97 void AclSubject::exportBlob(Writer::Counter
&, Writer::Counter
&)
100 void AclSubject::exportBlob(Writer
&, Writer
&)
103 void AclSubject::importBlob(Reader
&, Reader
&)
106 void AclSubject::reset()
109 AclSubject::Maker::~Maker()
115 // A SimpleAclSubject accepts only a single type of sample, validates
116 // samples independently, and makes no use of certificates.
118 bool SimpleAclSubject::validate(const AclValidationContext
&ctx
) const
120 for (uint32 n
= 0; n
< ctx
.count(); n
++) {
121 const TypedList
&sample
= ctx
[n
];
122 if (!sample
.isProper())
123 CssmError::throwMe(CSSM_ERRCODE_INVALID_SAMPLE_VALUE
);
124 if (sample
.type() == type() && validate(ctx
, sample
)) {
126 return true; // matched this sample; validation successful
134 // AclSubjects always have a (virtual) dump method.
135 // It's empty unless DEBUGDUMP is enabled.
137 void AclSubject::debugDump() const
139 #if defined(DEBUGDUMP)
141 case CSSM_ACL_SUBJECT_TYPE_ANY
:
145 Debug::dump("subject type=%d", type());
151 #if defined(DEBUGDUMP)
153 void AclSubject::dump(const char *title
) const
155 Debug::dump(" ** %s ", title
);