2 * Copyright (c) 2000-2001,2003-2004,2006,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 // cssmcred - enhanced PodWrappers and construction aids for ACL credentials
28 #include <security_cdsa_utilities/cssmcred.h>
34 // Scan a SampleGroup for samples with a given CSSM_SAMPLE_TYPE.
35 // Collect all matching samples into a list (which is cleared to begin with).
36 // Return true if any were found, false if none.
37 // Throw if any of the samples are obviously malformed.
39 bool SampleGroup::collect(CSSM_SAMPLE_TYPE sampleType
, list
<CssmSample
> &matches
) const
41 for (uint32 n
= 0; n
< length(); n
++) {
42 TypedList sample
= (*this)[n
];
44 if (sample
.type() == sampleType
) {
45 sample
.snip(); // skip sample type
46 matches
.push_back(sample
);
49 return !matches
.empty();
56 const AccessCredentials
& AccessCredentials::null_credential()
58 static const CSSM_ACCESS_CREDENTIALS null_credentials
= { "" }; // and more nulls
59 return AccessCredentials::overlay(null_credentials
);
62 void AccessCredentials::tag(const char *tagString
)
64 if (tagString
== NULL
)
66 else if (strlen(tagString
) > CSSM_MODULE_STRING_SIZE
)
67 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_ENTRY_TAG
);
69 strcpy(EntryTag
, tagString
);
72 bool AccessCredentials::authorizesUI() const {
73 list
<CssmSample
> uisamples
;
75 if(samples().collect(CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT
, uisamples
)) {
76 // The existence of a lone keychain prompt gives UI access
80 samples().collect(CSSM_SAMPLE_TYPE_KEYCHAIN_LOCK
, uisamples
);
81 samples().collect(CSSM_SAMPLE_TYPE_THRESHOLD
, uisamples
);
83 for (list
<CssmSample
>::iterator it
= uisamples
.begin(); it
!= uisamples
.end(); it
++) {
84 TypedList
&sample
= *it
;
86 if(!sample
.isProper()) {
87 secnotice("integrity", "found a non-proper sample, skipping...");
91 switch (sample
.type()) {
92 case CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT
:
93 // these credentials allow UI
98 // no interesting credential found; no UI for you
103 // AutoCredentials self-constructing credentials structure
105 AutoCredentials::AutoCredentials(Allocator
&alloc
) : allocator(alloc
)
110 AutoCredentials::AutoCredentials(Allocator
&alloc
, uint32 nSamples
) : allocator(alloc
)
113 getSample(nSamples
- 1); // extend array to nSamples elements
116 void AutoCredentials::init()
123 CssmSample
&AutoCredentials::getSample(uint32 n
)
126 sampleArray
= allocator
.alloc
<CssmSample
>(sampleArray
, nSamples
= n
+ 1);
127 Samples
.Samples
= sampleArray
;
128 Samples
.NumberOfSamples
= nSamples
;
130 return sampleArray
[n
];
133 } // end namespace Security