]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/aclclient.cpp
Security-54.tar.gz
[apple/security.git] / cdsa / cdsa_client / aclclient.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 // keyclient
21 //
22 #include <Security/aclclient.h>
23 #include <Security/keychainacl.h>
24 #include <Security/walkers.h>
25
26
27 namespace Security {
28 namespace CssmClient {
29
30
31 //
32 // AclBearer methods (trivial)
33 //
34 AclBearer::~AclBearer()
35 { }
36
37
38 //
39 // Delete an ACL by handle
40 //
41 void AclBearer::addAcl(const AclEntryInput &input, const CSSM_ACCESS_CREDENTIALS *cred)
42 {
43 changeAcl(AclEdit(input), cred);
44 }
45
46 void AclBearer::changeAcl(CSSM_ACL_HANDLE handle, const AclEntryInput &input,
47 const CSSM_ACCESS_CREDENTIALS *cred)
48 {
49 changeAcl(AclEdit(handle, input), cred);
50 }
51
52 void AclBearer::deleteAcl(CSSM_ACL_HANDLE handle, const CSSM_ACCESS_CREDENTIALS *cred)
53 {
54 changeAcl(AclEdit(handle), cred);
55 }
56
57 void AclBearer::deleteAcl(const char *tag, const CSSM_ACCESS_CREDENTIALS *cred)
58 {
59 AutoAclEntryInfoList entries;
60 getAcl(entries, tag);
61 for (uint32 n = 0; n < entries.count(); n++)
62 deleteAcl(entries[n].handle(), cred);
63 }
64
65
66 //
67 // A single global structure containing pseudo-static data
68 //
69 struct Statics {
70 Statics();
71 CssmAllocator &alloc;
72
73 AutoCredentials nullCred;
74 AutoCredentials promptCred;
75 AutoCredentials unlockCred;
76 };
77
78 namespace {
79 ModuleNexus<Statics> statics;
80 }
81
82
83 //
84 // Make pseudo-statics.
85 // Note: This is an eternal object. It is not currently destroyed
86 // if the containing code is unloaded. But then, the containing
87 // code is Security.framework, which never unloads anyway.
88 //
89 Statics::Statics()
90 : alloc(CssmAllocator::standard()),
91 nullCred(alloc, 1),
92 promptCred(alloc, 2),
93 unlockCred(alloc, 1)
94 {
95 // nullCred: nothing at all
96 // contains:
97 // an empty THRESHOLD sample to match threshold subjects with "free" subjects
98 nullCred.sample(0) = TypedList(alloc, CSSM_SAMPLE_TYPE_THRESHOLD);
99
100 // promptCred: a credential permitting user prompt confirmations
101 // contains:
102 // a KEYCHAIN_PROMPT sample, both by itself and in a THRESHOLD
103 promptCred.sample(0) = TypedList(alloc, CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT);
104 promptCred.sample(1) = TypedList(alloc, CSSM_SAMPLE_TYPE_THRESHOLD,
105 new(alloc) ListElement(TypedList(alloc, CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT)));
106
107 // unlockCred: ???
108 unlockCred.sample(0) = TypedList(alloc, CSSM_SAMPLE_TYPE_KEYCHAIN_LOCK,
109 new(alloc) ListElement(CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT));
110 }
111
112
113 //
114 // Make and break AclFactories
115 //
116 AclFactory::AclFactory()
117 { }
118
119 AclFactory::~AclFactory()
120 { }
121
122
123 //
124 // Return basic pseudo-static values
125 //
126 const AccessCredentials *AclFactory::nullCred() const
127 { return &statics().nullCred; }
128
129 const AccessCredentials *AclFactory::promptCred() const
130 { return &statics().promptCred; }
131
132 const AccessCredentials *AclFactory::unlockCred() const
133 { return &statics().unlockCred; }
134
135
136
137 AclFactory::PasswordChangeCredentials::PasswordChangeCredentials (const CssmData& password, CssmAllocator& allocator) :
138 mAllocator (allocator)
139 {
140 mCredentials = new (allocator) AutoCredentials (allocator);;
141 mCredentials->sample(0) = TypedList(allocator, CSSM_SAMPLE_TYPE_KEYCHAIN_CHANGE_LOCK, new (allocator) ListElement (CSSM_SAMPLE_TYPE_PASSWORD),
142 new (allocator) ListElement (password));
143 }
144
145
146
147 AclFactory::PasswordChangeCredentials::~PasswordChangeCredentials ()
148 {
149 DataWalkers::chunkFree (mCredentials, mAllocator);
150 }
151
152
153
154 } // end namespace CssmClient
155 } // end namespace Security