#include <security_cdsa_utilities/cssmcred.h>
namespace Security {
static const CSSM_ACCESS_CREDENTIALS null_credentials = { "" }; #if BUG_GCC
const AccessCredentials &AccessCredentials::null =
*static_cast<const AccessCredentials *>(&null_credentials);
#else
const AccessCredentials &AccessCredentials::null =
static_cast<const AccessCredentials &>(null_credentials);
#endif
bool SampleGroup::collect(CSSM_SAMPLE_TYPE sampleType, list<CssmSample> &matches) const
{
for (uint32 n = 0; n < length(); n++) {
TypedList sample = (*this)[n];
sample.checkProper();
if (sample.type() == sampleType) {
sample.snip(); matches.push_back(sample);
}
}
return !matches.empty();
}
void AccessCredentials::tag(const char *tagString)
{
if (tagString == NULL)
EntryTag[0] = '\0';
else if (strlen(tagString) > CSSM_MODULE_STRING_SIZE)
CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_ENTRY_TAG);
else
strcpy(EntryTag, tagString);
}
bool AccessCredentials::authorizesUI() const {
list<CssmSample> uisamples;
if(samples().collect(CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT, uisamples)) {
return true;
}
samples().collect(CSSM_SAMPLE_TYPE_KEYCHAIN_LOCK, uisamples);
samples().collect(CSSM_SAMPLE_TYPE_THRESHOLD, uisamples);
for (list<CssmSample>::iterator it = uisamples.begin(); it != uisamples.end(); it++) {
TypedList &sample = *it;
if(!sample.isProper()) {
secnotice("integrity", "found a non-proper sample, skipping...");
continue;
}
switch (sample.type()) {
case CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT:
return true;
}
}
return false;
}
AutoCredentials::AutoCredentials(Allocator &alloc) : allocator(alloc)
{
init();
}
AutoCredentials::AutoCredentials(Allocator &alloc, uint32 nSamples) : allocator(alloc)
{
init();
getSample(nSamples - 1); }
void AutoCredentials::init()
{
sampleArray = NULL;
nSamples = 0;
}
CssmSample &AutoCredentials::getSample(uint32 n)
{
if (n >= nSamples) {
sampleArray = allocator.alloc<CssmSample>(sampleArray, nSamples = n + 1);
Samples.Samples = sampleArray;
Samples.NumberOfSamples = nSamples;
}
return sampleArray[n];
}
}