]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/cssmaclpod.cpp
Security-54.1.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / cssmaclpod.cpp
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // cssmaclpod - enhanced PodWrappers for ACL-related CSSM data structures
21 //
22 #ifdef __MWERKS__
23 #define _CPP_CSSMACLPOD
24 #endif
25
26 #include <Security/cssmaclpod.h>
27 #include <Security/cssmwalkers.h>
28
29
30 AuthorizationGroup::AuthorizationGroup(const AclAuthorizationSet &auths,
31 CssmAllocator &alloc)
32 {
33 NumberOfAuthTags = auths.size();
34 AuthTags = alloc.alloc<CSSM_ACL_AUTHORIZATION_TAG>(NumberOfAuthTags);
35 copy(auths.begin(), auths.end(), AuthTags); // happens to be sorted
36 }
37
38 void AuthorizationGroup::destroy(CssmAllocator &alloc)
39 {
40 alloc.free(AuthTags);
41 }
42
43 bool AuthorizationGroup::contains(CSSM_ACL_AUTHORIZATION_TAG tag) const
44 {
45 return find(AuthTags, &AuthTags[NumberOfAuthTags], tag) != &AuthTags[NumberOfAuthTags];
46 }
47
48
49 AuthorizationGroup::operator AclAuthorizationSet() const
50 {
51 return AclAuthorizationSet(AuthTags, &AuthTags[NumberOfAuthTags]);
52 }
53
54 AclEntryPrototype::AclEntryPrototype(const AclOwnerPrototype &proto)
55 {
56 memset(this, 0, sizeof(*this));
57 TypedSubject = proto.subject(); Delegate = proto.delegate();
58 //@@@ set authorization to "is owner" pseudo-auth? See cssmacl.h
59 }
60
61 void AclEntryPrototype::tag(const char *tagString)
62 {
63 if (tagString == NULL)
64 EntryTag[0] = '\0';
65 else if (strlen(tagString) > CSSM_MODULE_STRING_SIZE)
66 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_ENTRY_TAG);
67 strcpy(EntryTag, tagString);
68 }
69
70
71 AclOwnerPrototype *AutoAclOwnerPrototype::make()
72 {
73 if (!mAclOwnerPrototype) {
74 mAclOwnerPrototype = new AclOwnerPrototype;
75 mAclOwnerPrototype->clearPod();
76 }
77 return mAclOwnerPrototype;
78 }
79
80 AutoAclOwnerPrototype::~AutoAclOwnerPrototype()
81 {
82 if (mAllocator)
83 DataWalkers::chunkFree(mAclOwnerPrototype, *mAllocator);
84 }
85
86 void
87 AutoAclOwnerPrototype::allocator(CssmAllocator &allocator)
88 {
89 mAllocator = &allocator;
90 }
91
92
93 AutoAclEntryInfoList::~AutoAclEntryInfoList()
94 {
95 if (mAllocator)
96 {
97 DataWalkers::ChunkFreeWalker w(*mAllocator);
98 for (uint32 ix = 0; ix < mNumberOfAclEntries; ix++)
99 walk(w, mAclEntryInfo[ix]);
100 //DataWalkers::chunkFree(mAclEntryInfo[ix], *mAllocator);
101 mAllocator->free(mAclEntryInfo);
102 }
103 }
104
105 void
106 AutoAclEntryInfoList::allocator(CssmAllocator &allocator)
107 {
108 mAllocator = &allocator;
109 }