SecPolicySearch.cpp [plain text]
#include <Security/SecPolicySearch.h>
#include <Security/SecPolicyPriv.h>
#include <security_keychain/PolicyCursor.h>
#include <security_keychain/Policies.h>
#include "SecBridge.h"
CFTypeID
SecPolicySearchGetTypeID(void)
{
BEGIN_SECAPI
return gTypes().PolicyCursor.typeID;
END_SECAPI1(_kCFRuntimeNotATypeID)
}
OSStatus
SecPolicySearchCreate(
CSSM_CERT_TYPE certType,
const CSSM_OID* oid,
const CSSM_DATA* value,
SecPolicySearchRef* searchRef)
{
BEGIN_SECAPI
Required(searchRef); PolicyCursor* pc = new PolicyCursor(oid, value);
if (pc == NULL)
{
return errSecPolicyNotFound;
}
SecPointer<PolicyCursor> cursor(pc);
*searchRef = cursor->handle();
END_SECAPI
}
OSStatus
SecPolicySearchCopyNext(
SecPolicySearchRef searchRef,
SecPolicyRef* policyRef)
{
BEGIN_SECAPI
RequiredParam(policyRef);
SecPointer<Policy> policy;
#if !SECTRUST_OSX
if (!PolicyCursor::required(searchRef)->next(policy))
return errSecPolicyNotFound;
*policyRef = policy->handle();
#else
CFStringRef oidStr = NULL;
PolicyCursor *policyCursor = PolicyCursor::required(searchRef);
do {
if (!policyCursor->next(policy))
return errSecPolicyNotFound;
CssmOid oid = policy->oid();
CFStringRef str = SecPolicyGetStringForOID(&oid);
if (str) {
oidStr = str;
if (CFEqual(str, kSecPolicyAppleiChat) ||
CFEqual(str, kSecPolicyApplePKINITClient) ||
CFEqual(str, kSecPolicyApplePKINITServer)) {
oidStr = NULL;
}
else if (policyCursor->oidProvided() == false &&
CFEqual(str, kSecPolicyAppleRevocation)) {
oidStr = NULL;
}
}
}
while (!oidStr);
CFRef<CFDictionaryRef> properties = policy->properties();
if ((*policyRef = SecPolicyCreateWithProperties(oidStr, properties)) != NULL) {
__secapiresult = errSecSuccess;
} else {
__secapiresult = errSecPolicyNotFound;
}
#endif
END_SECAPI
}