#ifdef __MWERKS__
#define _CPP_CSSMMDS
#endif
#include "cssmmds.h"
ModuleNexus<MdsComponent::MDS> MdsComponent::mds;
MdsComponent::MdsComponent(const Guid &guid) : mMyGuid(guid)
{
mIsValid = false;
}
MdsComponent::~MdsComponent()
{
}
void MdsComponent::getInfo() const
{
rewind(mds().config);
char buffer[1024];
while (fgets(buffer, sizeof(buffer), mds().config)) {
static const char space[] = " \t\f";
char *p = buffer + strspn(buffer, space);
if (*p == '#' || *p == '\0' || *p == '\n')
continue;
const char *guid = p; p += strcspn(p, space);
if (!*p) CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR);
*p++ = '\0';
try {
if (Guid(guid) != mMyGuid)
continue; } catch (CssmCommonError &error) {
if (error.cssmError() == CSSM_ERRCODE_INVALID_GUID)
CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR); throw; }
p += strspn(p, space);
mServices = 0;
mIsThreadSafe = false;
while (*p && !isspace(*p)) {
switch (*p) {
case 'a': mServices |= CSSM_SERVICE_AC; break;
case 'c': mServices |= CSSM_SERVICE_CSP; break;
case 'd': mServices |= CSSM_SERVICE_DL; break;
case 'C': mServices |= CSSM_SERVICE_CL; break;
case 't': mServices |= CSSM_SERVICE_TP; break;
case 'm': mIsThreadSafe = true; break;
default:
CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR);
}
p++;
}
if (!*p) CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR);
p += strspn(p, space); p[strlen(p)-1] = '\0'; mPath = p; mIsValid = true;
return;
}
CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID); }
#if !defined(_MDS_PATH)
# define _MDS_PATH "/System/Library/Frameworks/Security.framework/Resources/MDS"
#endif
MdsComponent::MDS::MDS()
{
const char *path = getenv("MDSPATH");
if (path == NULL)
path = getenv("MDSFILE");
if (path == NULL)
path = _MDS_PATH;
if (!(config = fopen(path, "r")))
CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR);
}
MdsComponent::MDS::~MDS()
{
fclose(config);
}