]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/acl_comment.cpp
Security-54.1.3.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / acl_comment.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 // acl_comment - "ignore" ACL subject type
21 //
22 #include <Security/acl_comment.h>
23 #include <Security/cssmwalkers.h>
24 #include <Security/cssmlist.h>
25 #include <algorithm>
26
27 using namespace DataWalkers;
28
29
30 //
31 // The COMMENT subject matches nothing, no matter how pretty.
32 //
33 bool CommentAclSubject::validate(const AclValidationContext &) const
34 {
35 return false;
36 }
37
38
39 //
40 // The toList function simply returns a copy of the preserved list.
41 // The interface convention requires that we chunkCopy here.
42 //
43 CssmList CommentAclSubject::toList(CssmAllocator &alloc) const
44 {
45 CssmList result = CssmList::overlay(*mComment);
46 ChunkCopyWalker w(alloc);
47 walk(w, result);
48 return result;
49 }
50
51
52 //
53 // Construct-from-list makes a unified copy of the list.
54 //
55 CommentAclSubject *CommentAclSubject::Maker::make(const TypedList &list) const
56 {
57 const CSSM_LIST *baseList = &list;
58 size_t commentSize = size(baseList);
59 CSSM_LIST *comment = copy(baseList, CssmAllocator::standard(), commentSize);
60 return new CommentAclSubject(comment, commentSize);
61 }
62
63 CommentAclSubject *CommentAclSubject::Maker::make(Version, Reader &pub, Reader &) const
64 {
65 CSSM_LIST *base; pub(base); // get original pointer base
66 const void *data; uint32 length; pub.countedData(data, length); // data blob
67
68 // copy the input blob into writable memory
69 CSSM_LIST *list = CssmAllocator::standard().malloc<CSSM_LIST>(length);
70 memcpy(list, data, length);
71
72 // relocate it based on the base pointer we stored
73 relocate(list, base);
74
75 // good
76 return new CommentAclSubject(list, length);
77 }
78
79
80 //
81 // Export to blob form.
82 // Since we store the list in unified form, this isn't very hard. Do try to figure
83 // out how walkers work before messing with this code.
84 //
85 void CommentAclSubject::exportBlob(Writer::Counter &pub, Writer::Counter &)
86 {
87 pub(mComment); // yes, the pointer itself
88 pub.countedData(mComment, mSize);
89 }
90
91 void CommentAclSubject::exportBlob(Writer &pub, Writer &)
92 {
93 pub(mComment);
94 pub.countedData(mComment, mSize);
95 }
96