]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cdsa_utilities/lib/objectacl.cpp
Security-57740.20.22.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_utilities / lib / objectacl.cpp
1 /*
2 * Copyright (c) 2000-2004,2006,2011-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // objectacl - core implementation of an ACL-bearing object
27 //
28 #include <security_cdsa_utilities/objectacl.h>
29 #include <security_cdsa_utilities/cssmbridge.h>
30 #include <security_utilities/endian.h>
31 #include <security_utilities/debugging.h>
32 #include <algorithm>
33 #include <cstdarg>
34
35 #include <security_cdsa_utilities/acl_preauth.h> //@@@ impure - will be removed
36
37 using namespace DataWalkers;
38
39
40 //
41 // The static map of available ACL subject makers.
42 // These are the kinds of ACL subjects we can deal with.
43 //
44 ModuleNexus<ObjectAcl::MakerMap> ObjectAcl::makers;
45
46
47 //
48 // Create an ObjectAcl
49 //
50 ObjectAcl::ObjectAcl(Allocator &alloc) : allocator(alloc), mNextHandle(1)
51 {
52 }
53
54 ObjectAcl::ObjectAcl(const AclEntryPrototype &proto, Allocator &alloc)
55 : allocator(alloc), mNextHandle(1)
56 {
57 cssmSetInitial(proto);
58 }
59
60 ObjectAcl::~ObjectAcl()
61 { }
62
63
64 //
65 // Set an "initial ACL" from a CSSM-style initial ACL argument.
66 // This will replace the owner, as well as replace the entire ACL
67 // with a single-item slot, as per CSSM specification.
68 //
69 void ObjectAcl::cssmSetInitial(const AclEntryPrototype &proto)
70 {
71 mOwner = OwnerEntry(proto);
72 add(proto.s_tag(), proto);
73 IFDUMPING("acl", debugDump("create/proto"));
74 }
75
76 void ObjectAcl::cssmSetInitial(const AclSubjectPointer &subject)
77 {
78 mOwner = OwnerEntry(subject);
79 add("", subject);
80 IFDUMPING("acl", debugDump("create/subject"));
81 }
82
83 ObjectAcl::Entry::~Entry()
84 {
85 }
86
87
88 //
89 // ObjectAcl::validate validates an access authorization claim.
90 // Returns normally if 'auth' is granted to the bearer of 'cred'.
91 // Otherwise, throws a suitable (ACL-related) CssmError exception.
92 //
93 bool ObjectAcl::validates(AclAuthorization auth, const AccessCredentials *cred,
94 AclValidationEnvironment *env)
95 {
96 BaseValidationContext ctx(cred, auth, env);
97 return validates(ctx);
98 }
99
100 bool ObjectAcl::validates(AclValidationContext &ctx)
101 {
102 // make sure we are ready to go
103 instantiateAcl();
104
105 IFDUMPING("acleval", Debug::dump("<<WANT(%d)<", ctx.authorization()));
106
107 //@@@ should pre-screen based on requested auth, maybe?
108
109 #if defined(ACL_OMNIPOTENT_OWNER)
110 // try owner (owner can do anything)
111 if (mOwner.validates(ctx))
112 return;
113 #endif //ACL_OMNIPOTENT_OWNER
114
115 // try applicable ACLs
116 pair<EntryMap::const_iterator, EntryMap::const_iterator> range;
117 if (getRange(ctx.s_credTag(), range) == 0) {
118 // no such tag
119 secinfo("SecAccess", "no tag for cred tag: \"%s\"", ctx.s_credTag().c_str());
120 CssmError::throwMe(CSSM_ERRCODE_ACL_ENTRY_TAG_NOT_FOUND);
121 }
122 // try each entry in turn
123 for (EntryMap::const_iterator it = range.first; it != range.second; it++) {
124 const AclEntry &slot = it->second;
125 IFDUMPING("acleval", (Debug::dump(" EVAL["), slot.debugDump(), Debug::dump("]")));
126 if (slot.authorizes(ctx.authorization())) {
127 ctx.init(this, slot.subject);
128 ctx.entryTag(slot.tag);
129 if (slot.validates(ctx)) {
130 IFDUMPING("acleval", Debug::dump(">PASS>>\n"));
131 return true; // passed
132 }
133 IFDUMPING("acleval", Debug::dump(" NO"));
134 }
135 }
136 IFDUMPING("acleval", Debug::dump(">FAIL>>\n"));
137 return false; // no joy
138 }
139
140 void ObjectAcl::validate(AclAuthorization auth, const AccessCredentials *cred,
141 AclValidationEnvironment *env)
142 {
143 if (!validates(auth, cred, env))
144 CssmError::throwMe(CSSM_ERRCODE_OPERATION_AUTH_DENIED);
145 }
146
147 void ObjectAcl::validate(AclValidationContext &ctx)
148 {
149 if (!validates(ctx))
150 CssmError::throwMe(CSSM_ERRCODE_OPERATION_AUTH_DENIED);
151 }
152
153
154 void ObjectAcl::validateOwner(AclAuthorization authorizationHint,
155 const AccessCredentials *cred, AclValidationEnvironment *env)
156 {
157 BaseValidationContext ctx(cred, authorizationHint, env);
158 validateOwner(ctx);
159 }
160
161 void ObjectAcl::validateOwner(AclValidationContext &ctx)
162 {
163 instantiateAcl();
164
165 ctx.init(this, mOwner.subject);
166 if (mOwner.validates(ctx))
167 return;
168 CssmError::throwMe(CSSM_ERRCODE_OPERATION_AUTH_DENIED);
169 }
170
171
172 //
173 // Export an ObjectAcl to two memory blobs: public and private data separated.
174 // This is a standard two-pass size+copy operation.
175 //
176 void ObjectAcl::exportBlob(CssmData &publicBlob, CssmData &privateBlob)
177 {
178 instantiateAcl();
179 Writer::Counter pubSize, privSize;
180 Endian<uint32> entryCount = (uint32)mEntries.size();
181 mOwner.exportBlob(pubSize, privSize);
182 pubSize(entryCount);
183 for (EntryMap::iterator it = begin(); it != end(); it++)
184 it->second.exportBlob(pubSize, privSize);
185 publicBlob = CssmData(allocator.malloc(pubSize), pubSize);
186 privateBlob = CssmData(allocator.malloc(privSize), privSize);
187 Writer pubWriter(publicBlob), privWriter(privateBlob);
188 mOwner.exportBlob(pubWriter, privWriter);
189 pubWriter(entryCount);
190 for (EntryMap::iterator it = begin(); it != end(); it++)
191 it->second.exportBlob(pubWriter, privWriter);
192 IFDUMPING("acl", debugDump("exported"));
193 }
194
195
196 //
197 // Import an ObjectAcl's contents from two memory blobs representing public and
198 // private contents, respectively. These blobs must have been generated by the
199 // export method.
200 // Prior contents (if any) are deleted and replaced.
201 //
202 void ObjectAcl::importBlob(const void *publicBlob, const void *privateBlob)
203 {
204 Reader pubReader(publicBlob), privReader(privateBlob);
205 mOwner.importBlob(pubReader, privReader);
206 Endian<uint32> entryCountIn; pubReader(entryCountIn);
207 uint32 entryCount = entryCountIn;
208
209 mEntries.erase(begin(), end());
210 for (uint32 n = 0; n < entryCount; n++) {
211 AclEntry newEntry;
212 newEntry.importBlob(pubReader, privReader);
213 add(newEntry.tag, newEntry);
214 }
215 IFDUMPING("acl", debugDump("imported"));
216 }
217
218
219 //
220 // Import/export helpers for subjects.
221 // This is exported to (subject implementation) callers to maintain consistency
222 // in binary format handling.
223 //
224 AclSubject *ObjectAcl::importSubject(Reader &pub, Reader &priv)
225 {
226 Endian<uint32> typeAndVersion; pub(typeAndVersion);
227 return make(typeAndVersion, pub, priv);
228 }
229
230
231 //
232 // Setup/update hooks
233 //
234 void ObjectAcl::instantiateAcl()
235 {
236 // nothing by default
237 }
238
239 void ObjectAcl::changedAcl()
240 {
241 // nothing by default
242 }
243
244
245 //
246 // ACL utility methods
247 //
248 unsigned int ObjectAcl::getRange(const std::string &tag,
249 pair<EntryMap::const_iterator, EntryMap::const_iterator> &range, bool tolerant /* = false */) const
250 {
251 if (!tag.empty()) { // tag restriction in effect
252 secinfo("SecAccess", "looking for ACL entries matching tag: \"%s\"", tag.c_str());
253 range = mEntries.equal_range(tag);
254 unsigned int count = (unsigned int)mEntries.count(tag);
255 if (count == 0 && !tolerant)
256 CssmError::throwMe(CSSM_ERRCODE_ACL_ENTRY_TAG_NOT_FOUND);
257 return count;
258 } else { // try all tags
259 secinfo("SecAccess", "no tag given; looking for all ACL entries");
260 range.first = mEntries.begin();
261 range.second = mEntries.end();
262 return (unsigned int)mEntries.size();
263 }
264 }
265
266 ObjectAcl::EntryMap::iterator ObjectAcl::findEntryHandle(CSSM_ACL_HANDLE handle)
267 {
268 for (EntryMap::iterator it = mEntries.begin(); it != mEntries.end(); it++)
269 if (it->second.handle == handle)
270 return it;
271 CssmError::throwMe(CSSMERR_CSSM_INVALID_HANDLE_USAGE); //%%% imprecise error code
272 }
273
274
275 //
276 // CSSM style ACL access and modification functions.
277 //
278 void ObjectAcl::cssmGetAcl(const char *tag, uint32 &count, AclEntryInfo * &acls)
279 {
280 instantiateAcl();
281 pair<EntryMap::const_iterator, EntryMap::const_iterator> range;
282 count = getRange(tag ? tag : "", range);
283 acls = allocator.alloc<AclEntryInfo>(count);
284 uint32 n = 0;
285
286 secinfo("SecAccess", "getting the ACL for %p (%d entries) tag: %s", this, count, tag ? tag : "<none>");
287
288 for (EntryMap::const_iterator it = range.first; it != range.second; it++, n++) {
289 acls[n].EntryHandle = it->second.handle;
290 it->second.toEntryInfo(acls[n].EntryPublicInfo, allocator);
291 secinfo("SecAccess", "found an entry of type %d", acls[n].EntryPublicInfo.TypedSubject.Head->WordID);
292 }
293 count = n;
294 }
295
296 void ObjectAcl::cssmChangeAcl(const AclEdit &edit,
297 const AccessCredentials *cred, AclValidationEnvironment *env, const char *preserveTag)
298 {
299 IFDUMPING("acl", debugDump("acl-change-from"));
300
301 // make sure we're ready to go
302 instantiateAcl();
303
304 // validate access credentials
305 validateOwner(CSSM_ACL_AUTHORIZATION_CHANGE_ACL, cred, env);
306
307 // what is Thy wish, effendi?
308 switch (edit.EditMode) {
309 case CSSM_ACL_EDIT_MODE_ADD: {
310 secinfo("SecAccess", "adding ACL for %p (%ld) while preserving: %s", this, edit.handle(), preserveTag);
311 const AclEntryInput &input = Required(edit.newEntry());
312 if (preserveTag && input.proto().s_tag() == preserveTag)
313 MacOSError::throwMe(CSSM_ERRCODE_OPERATION_AUTH_DENIED);
314 add(input.proto().s_tag(), input.proto());
315 secinfo("SecAccess", "subject type is %d", input.proto().TypedSubject.Head->WordID);
316 }
317 break;
318 case CSSM_ACL_EDIT_MODE_REPLACE: {
319 secinfo("SecAccess", "replacing ACL for %p (%ld to %p) while preserving: %s", this, edit.handle(), edit.newEntry(), preserveTag);
320 // keep the handle, and try for some modicum of atomicity
321 EntryMap::iterator it = findEntryHandle(edit.handle());
322 if (preserveTag && it->second.tag == preserveTag)
323 MacOSError::throwMe(CSSM_ERRCODE_OPERATION_AUTH_DENIED);
324 AclEntryPrototype proto2;
325 it->second.toEntryInfo(proto2, allocator);
326 secinfo("SecAccess", "subject type was %d", proto2.TypedSubject.Head->WordID);
327 DataWalkers::chunkFree(proto2, allocator);
328
329 AclEntryPrototype proto = Required(edit.newEntry()).proto(); // (bypassing callbacks)
330 add(proto.s_tag(), proto, edit.handle());
331 secinfo("SecAccess", "new subject type is %d", proto.TypedSubject.Head->WordID);
332 mEntries.erase(it);
333 }
334 break;
335 case CSSM_ACL_EDIT_MODE_DELETE: {
336 secinfo("SecAccess", "deleting ACL for %p (%ld) while preserving: %s", this, edit.handle(), preserveTag);
337 EntryMap::iterator it = findEntryHandle(edit.handle());
338 if (preserveTag && it->second.tag == preserveTag)
339 MacOSError::throwMe(CSSM_ERRCODE_OPERATION_AUTH_DENIED);
340
341 AclEntryPrototype proto;
342 it->second.toEntryInfo(proto, allocator);
343 secinfo("SecAccess", "subject type was %d", proto.TypedSubject.Head->WordID);
344 DataWalkers::chunkFree(proto, allocator);
345
346 mEntries.erase(it);
347 break;
348 }
349 default:
350 secinfo("SecAccess", "no idea what this CSSM_ACL_EDIT type is: %d", edit.EditMode);
351 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_EDIT_MODE);
352 }
353
354 // notify change
355 changedAcl();
356
357 IFDUMPING("acl", debugDump("acl-change-to"));
358 }
359
360 void ObjectAcl::cssmGetOwner(AclOwnerPrototype &outOwner)
361 {
362 instantiateAcl();
363 outOwner.TypedSubject = mOwner.subject->toList(allocator);
364 outOwner.Delegate = mOwner.delegate;
365
366 secinfo("SecAccess", "%p: getting the owner ACL: type %d", this, outOwner.TypedSubject.Head->WordID);
367 }
368
369 void ObjectAcl::cssmChangeOwner(const AclOwnerPrototype &newOwner,
370 const AccessCredentials *cred, AclValidationEnvironment *env)
371 {
372 IFDUMPING("acl", debugDump("owner-change-from"));
373
374 instantiateAcl();
375
376 // only the owner entry can match
377 validateOwner(CSSM_ACL_AUTHORIZATION_CHANGE_OWNER, cred, env);
378
379 // okay, replace it
380 mOwner = newOwner;
381
382 secinfo("SecAccess", "%p: new owner's type is %d", this, newOwner.subject().Head->WordID);
383
384 changedAcl();
385
386 IFDUMPING("acl", debugDump("owner-change-to"));
387 }
388
389
390 //
391 // Load a set of ACL entries from an AclEntryInfo array.
392 // This completely replaces the ACL's entries.
393 // Note that we will adopt the handles in the infos, so they better be proper
394 // (unique, nonzero).
395 //
396 template <class Input>
397 void ObjectAcl::owner(const Input &input)
398 {
399 IFDUMPING("acl", debugDump("owner-load-old"));
400 mOwner = OwnerEntry(input);
401 IFDUMPING("acl", debugDump("owner-load-new"));
402 }
403
404 template void ObjectAcl::owner(const AclOwnerPrototype &);
405 template void ObjectAcl::owner(const AclSubjectPointer &);
406
407
408 void ObjectAcl::entries(uint32 count, const AclEntryInfo *info)
409 {
410 IFDUMPING("acl", debugDump("entries-load-old"));
411 mEntries.erase(mEntries.begin(), mEntries.end());
412 for (uint32 n = 0; n < count; n++, info++)
413 add(info->proto().s_tag(), info->proto());
414 IFDUMPING("acl", debugDump("entries-load-new"));
415 }
416
417
418 //
419 // Clear out the ACL and return it to un-initialized state
420 //
421 void ObjectAcl::clear()
422 {
423 mOwner = OwnerEntry();
424 mEntries.erase(mEntries.begin(), mEntries.end());
425 secinfo("acl", "%p cleared", this);
426 }
427
428
429 //
430 // Common gate to add an ACL entry
431 //
432 void ObjectAcl::add(const std::string &tag, const AclEntry &newEntry)
433 {
434 add(tag, newEntry, mNextHandle++);
435 }
436
437 void ObjectAcl::add(const std::string &tag, AclEntry newEntry, CSSM_ACL_HANDLE handle)
438 {
439 newEntry.tag = tag;
440 //@@@ This should use a hook-registry mechanism. But for now, we are explicit:
441 if (!newEntry.authorizesAnything) {
442 for (AclAuthorizationSet::const_iterator it = newEntry.authorizations.begin();
443 it != newEntry.authorizations.end(); it++)
444 if (*it >= CSSM_ACL_AUTHORIZATION_PREAUTH_BASE &&
445 *it < CSSM_ACL_AUTHORIZATION_PREAUTH_END) {
446 // preauthorization right - special handling
447 if (newEntry.subject->type() != CSSM_ACL_SUBJECT_TYPE_PREAUTH_SOURCE)
448 newEntry.subject =
449 new PreAuthorizationAcls::SourceAclSubject(newEntry.subject);
450 }
451 }
452
453 mEntries.insert(make_pair(tag, newEntry))->second.handle = handle;
454 if (handle >= mNextHandle)
455 mNextHandle = handle + 1; // don't reuse this handle (in this ACL)
456 }
457
458
459 //
460 // Common features of ACL entries/owners
461 //
462 void ObjectAcl::Entry::init(const AclSubjectPointer &subject, bool delegate)
463 {
464 this->subject = subject;
465 this->delegate = delegate;
466 }
467
468 void ObjectAcl::Entry::importBlob(Reader &pub, Reader &priv)
469 {
470 // the delegation flag is 4 bytes for historic reasons
471 Endian<uint32> del;
472 pub(del);
473 delegate = del;
474
475 subject = importSubject(pub, priv);
476 }
477
478
479 //
480 // An OwnerEntry is a restricted EntryPrototype for use as the ACL owner.
481 //
482 bool ObjectAcl::OwnerEntry::authorizes(AclAuthorization) const
483 {
484 return true; // owner can do anything
485 }
486
487 bool ObjectAcl::OwnerEntry::validates(const AclValidationContext &ctx) const
488 {
489 if (AclValidationEnvironment* env = ctx.environment())
490 if (env->forceSuccess)
491 return true;
492 return subject->validates(ctx); // simple subject match - no strings attached
493 }
494
495
496 //
497 // An AclEntry has some extra goodies
498 //
499 ObjectAcl::AclEntry::AclEntry(const AclEntryPrototype &proto) : Entry(proto)
500 {
501 tag = proto.s_tag();
502 if (proto.authorization().contains(CSSM_ACL_AUTHORIZATION_ANY))
503 authorizesAnything = true; // anything else wouldn't add anything
504 else if (proto.authorization().empty())
505 authorizesAnything = true; // not in standard, but common sense
506 else {
507 authorizesAnything = false;
508 authorizations = proto.authorization();
509 }
510 //@@@ not setting time range
511 // handle = not set here. Set by caller when the AclEntry is created.
512 }
513
514 ObjectAcl::AclEntry::AclEntry(const AclSubjectPointer &subject) : Entry(subject)
515 {
516 authorizesAnything = true; // by default, everything
517 //@@@ not setting time range
518 }
519
520 void ObjectAcl::AclEntry::toEntryInfo(CSSM_ACL_ENTRY_PROTOTYPE &info, Allocator &alloc) const
521 {
522 info.TypedSubject = subject->toList(alloc);
523 info.Delegate = delegate;
524 info.Authorization = authorizesAnything ?
525 AuthorizationGroup(CSSM_ACL_AUTHORIZATION_ANY, alloc) :
526 AuthorizationGroup(authorizations, alloc);
527 //@@@ info.TimeRange =
528 assert(tag.length() <= CSSM_MODULE_STRING_SIZE);
529 memcpy(info.EntryTag, tag.c_str(), tag.length() + 1);
530 }
531
532 bool ObjectAcl::AclEntry::authorizes(AclAuthorization auth) const
533 {
534 return authorizesAnything || authorizations.find(auth) != authorizations.end();
535 }
536
537 bool ObjectAcl::AclEntry::validates(const AclValidationContext &ctx) const
538 {
539 //@@@ not checking time ranges
540 return subject->validates(ctx);
541 }
542
543 void ObjectAcl::AclEntry::addAuthorization(AclAuthorization auth)
544 {
545 authorizations.insert(auth);
546 authorizesAnything = false;
547 }
548
549
550 void ObjectAcl::AclEntry::importBlob(Reader &pub, Reader &priv)
551 {
552 Entry::importBlob(pub, priv);
553 const char *s; pub(s); tag = s;
554
555 // authorizesAnything is on disk as a 4-byte flag
556 Endian<uint32> tmpAuthorizesAnything;
557 pub(tmpAuthorizesAnything);
558 authorizesAnything = tmpAuthorizesAnything;
559
560 authorizations.erase(authorizations.begin(), authorizations.end());
561 if (!authorizesAnything) {
562 Endian<uint32> countIn; pub(countIn);
563 uint32 count = countIn;
564
565 for (uint32 n = 0; n < count; n++) {
566 Endian<AclAuthorization> auth; pub(auth);
567 authorizations.insert(auth);
568 }
569 }
570 //@@@ import time range
571 }
572
573
574 //
575 // Subject factory and makers
576 //
577 AclSubject::Maker::Maker(CSSM_ACL_SUBJECT_TYPE type)
578 : mType(type)
579 {
580 ObjectAcl::makers()[type] = this;
581 }
582
583 AclSubject *ObjectAcl::make(const TypedList &list)
584 {
585 if (!list.isProper())
586 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);
587 return makerFor(list.type()).make(list);
588 }
589
590 AclSubject *ObjectAcl::make(uint32 typeAndVersion, Reader &pub, Reader &priv)
591 {
592 // this type is encoded as (version << 24) | type
593 return makerFor(typeAndVersion & ~AclSubject::versionMask).make(typeAndVersion >> AclSubject::versionShift, pub, priv);
594 }
595
596 AclSubject::Maker &ObjectAcl::makerFor(CSSM_ACL_SUBJECT_TYPE type)
597 {
598 AclSubject::Maker *maker = makers()[type];
599 if (maker == NULL)
600 CssmError::throwMe(CSSM_ERRCODE_ACL_SUBJECT_TYPE_NOT_SUPPORTED);
601 return *maker;
602 }
603
604
605 //
606 // Parsing helper for subject makers.
607 // Note that count/array exclude the first element of list, which is the subject type wordid.
608 //
609 void AclSubject::Maker::crack(const CssmList &list, uint32 count, ListElement **array, ...)
610 {
611 if (count != list.length() - 1)
612 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);
613 if (count > 0) {
614 va_list args;
615 va_start(args, array);
616 ListElement *elem = list.first()->next();
617 for (uint32 n = 0; n < count; n++, elem = elem->next()) {
618 CSSM_LIST_ELEMENT_TYPE expectedType = va_arg(args, CSSM_LIST_ELEMENT_TYPE);
619 if (elem->type() != expectedType)
620 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);
621 array[n] = elem;
622 }
623 va_end(args);
624 }
625 }
626
627 CSSM_WORDID_TYPE AclSubject::Maker::getWord(const ListElement &elem,
628 int min /*= 0*/, int max /*= INT_MAX*/)
629 {
630 if (elem.type() != CSSM_LIST_ELEMENT_WORDID)
631 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);
632 CSSM_WORDID_TYPE value = elem;
633 if (value < min || value > max)
634 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);
635 return value;
636 }
637
638
639 //
640 // Debug dumping support.
641 // Leave the ObjectAcl::debugDump method in (stubbed out)
642 // to keep the virtual table layout stable, and to allow
643 // proper linking in weird mix-and-match scenarios.
644 //
645 void ObjectAcl::debugDump(const char *what) const
646 {
647 #if defined(DEBUGDUMP)
648 if (!what)
649 what = "Dump";
650 Debug::dump("%p ACL %s: %d entries\n", this, what, int(mEntries.size()));
651 Debug::dump(" OWNER ["); mOwner.debugDump(); Debug::dump("]\n");
652 for (EntryMap::const_iterator it = begin(); it != end(); it++) {
653 const AclEntry &ent = it->second;
654 Debug::dump(" (%ld:%s) [", ent.handle, ent.tag.c_str());
655 ent.debugDump();
656 Debug::dump("]\n");
657 }
658 Debug::dump("%p ACL END\n", this);
659 #endif //DEBUGDUMP
660 }
661
662 #if defined(DEBUGDUMP)
663
664 void ObjectAcl::Entry::debugDump() const
665 {
666 if (subject) {
667 if (AclSubject::Version v = subject->version())
668 Debug::dump("V=%d ", v);
669 subject->debugDump();
670 } else {
671 Debug::dump("NULL subject");
672 }
673 if (delegate)
674 Debug::dump(" DELEGATE");
675 }
676
677 void ObjectAcl::AclEntry::debugDump() const
678 {
679 Entry::debugDump();
680 if (authorizesAnything) {
681 Debug::dump(" auth(ALL)");
682 } else {
683 Debug::dump(" auth(");
684 for (AclAuthorizationSet::iterator it = authorizations.begin();
685 it != authorizations.end(); it++) {
686 if (*it >= CSSM_ACL_AUTHORIZATION_PREAUTH_BASE
687 && *it < CSSM_ACL_AUTHORIZATION_PREAUTH_END)
688 Debug::dump(" PRE(%d)", *it - CSSM_ACL_AUTHORIZATION_PREAUTH_BASE);
689 else
690 Debug::dump(" %d", *it);
691 }
692 Debug::dump(")");
693 }
694 }
695
696 #endif //DEBUGDUMP