2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
22 #include <Security/aclclient.h>
23 #include <Security/keychainacl.h>
24 #include <Security/cssmwalkers.h>
25 #include <Security/cssmdata.h>
29 namespace CssmClient
{
33 // AclBearer methods (trivial)
35 AclBearer::~AclBearer()
40 // Delete an ACL by handle
42 void AclBearer::addAcl(const AclEntryInput
&input
, const CSSM_ACCESS_CREDENTIALS
*cred
)
44 changeAcl(AclEdit(input
), cred
);
47 void AclBearer::changeAcl(CSSM_ACL_HANDLE handle
, const AclEntryInput
&input
,
48 const CSSM_ACCESS_CREDENTIALS
*cred
)
50 changeAcl(AclEdit(handle
, input
), cred
);
53 void AclBearer::deleteAcl(CSSM_ACL_HANDLE handle
, const CSSM_ACCESS_CREDENTIALS
*cred
)
55 changeAcl(AclEdit(handle
), cred
);
58 void AclBearer::deleteAcl(const char *tag
, const CSSM_ACCESS_CREDENTIALS
*cred
)
60 AutoAclEntryInfoList entries
;
62 for (uint32 n
= 0; n
< entries
.count(); n
++)
63 deleteAcl(entries
[n
].handle(), cred
);
68 // A single global structure containing pseudo-static data
74 AutoCredentials nullCred
;
75 AutoCredentials promptCred
;
76 AutoCredentials unlockCred
;
80 ModuleNexus
<Statics
> statics
;
85 // Make pseudo-statics.
86 // Note: This is an eternal object. It is not currently destroyed
87 // if the containing code is unloaded. But then, the containing
88 // code is Security.framework, which never unloads anyway.
91 : alloc(CssmAllocator::standard()),
96 // nullCred: nothing at all
98 // an empty THRESHOLD sample to match threshold subjects with "free" subjects
99 nullCred
.sample(0) = TypedList(alloc
, CSSM_SAMPLE_TYPE_THRESHOLD
);
101 // promptCred: a credential permitting user prompt confirmations
103 // a KEYCHAIN_PROMPT sample, both by itself and in a THRESHOLD
104 promptCred
.sample(0) = TypedList(alloc
, CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT
);
105 promptCred
.sample(1) = TypedList(alloc
, CSSM_SAMPLE_TYPE_THRESHOLD
,
106 new(alloc
) ListElement(TypedList(alloc
, CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT
)));
109 unlockCred
.sample(0) = TypedList(alloc
, CSSM_SAMPLE_TYPE_KEYCHAIN_LOCK
,
110 new(alloc
) ListElement(CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT
));
115 // Make and break AclFactories
117 AclFactory::AclFactory()
120 AclFactory::~AclFactory()
125 // Return basic pseudo-static values
127 const AccessCredentials
*AclFactory::nullCred() const
128 { return &statics().nullCred
; }
130 const AccessCredentials
*AclFactory::promptCred() const
131 { return &statics().promptCred
; }
133 const AccessCredentials
*AclFactory::unlockCred() const
134 { return &statics().unlockCred
; }
138 // Manage the (pseudo) credentials used to explicitly provide a passphrase to a keychain.
139 // Use the eternal unlockCred() for normal (protected prompt) unlocking.
141 AclFactory::KeychainCredentials::~KeychainCredentials ()
143 DataWalkers::chunkFree (mCredentials
, allocator
);
146 AclFactory::PassphraseUnlockCredentials::PassphraseUnlockCredentials (const CssmData
& password
,
147 CssmAllocator
& allocator
) : KeychainCredentials(allocator
)
149 mCredentials
->sample(0) = TypedList(allocator
, CSSM_SAMPLE_TYPE_KEYCHAIN_LOCK
,
150 new (allocator
) ListElement (CSSM_SAMPLE_TYPE_PASSWORD
),
151 new (allocator
) ListElement (CssmAutoData(allocator
, password
).release()));
156 // Manage the (pseudo) credentials used to explicitly change a keychain's passphrase
158 AclFactory::PasswordChangeCredentials::PasswordChangeCredentials (const CssmData
& password
,
159 CssmAllocator
& allocator
) : KeychainCredentials(allocator
)
161 mCredentials
->sample(0) = TypedList(allocator
, CSSM_SAMPLE_TYPE_KEYCHAIN_CHANGE_LOCK
,
162 new (allocator
) ListElement (CSSM_SAMPLE_TYPE_PASSWORD
),
163 new (allocator
) ListElement (CssmAutoData(allocator
, password
).release()));
168 // Create an ANY style AclEntryInput.
169 // This can be used to explicitly request wide-open authorization on a new CSSM object.
171 AclFactory::AnyResourceContext::AnyResourceContext(const CSSM_ACCESS_CREDENTIALS
*cred
)
172 : mAny(CSSM_ACL_SUBJECT_TYPE_ANY
), mTag(CSSM_ACL_AUTHORIZATION_ANY
)
174 // set up an ANY/EVERYTHING AclEntryInput
175 input().proto().subject() += &mAny
;
176 AuthorizationGroup
&authGroup
= input().proto().authorization();
177 authGroup
.NumberOfAuthTags
= 1;
178 authGroup
.AuthTags
= &mTag
;
180 // install the cred (not copied)
185 } // end namespace CssmClient
186 } // end namespace Security