#include "MDSModule.h"
#include "MDSSession.h"
#include <Security/mds_schema.h>
#include <memory>
namespace Security
{
ModuleNexus<MDSModule> MDSModule::mModuleNexus;
#define TABLE(t) { t, #t }
#define USE_FILE_DL_TABLES 1
static const AppleDatabaseTableName kTableNames[] = {
#if USE_FILE_DL_TABLES
TABLE(CSSM_DL_DB_SCHEMA_INFO),
TABLE(CSSM_DL_DB_SCHEMA_ATTRIBUTES),
TABLE(CSSM_DL_DB_SCHEMA_INDEXES),
#else
TABLE(MDS_CDSADIR_MDS_SCHEMA_RELATIONS),
TABLE(MDS_CDSADIR_MDS_SCHEMA_ATTRIBUTES),
TABLE(MDS_CDSADIR_MDS_SCHEMA_INDEXES),
#endif
TABLE(CSSM_DL_DB_SCHEMA_PARSING_MODULE),
TABLE(MDS_OBJECT_RECORDTYPE),
TABLE(MDS_CDSADIR_CSSM_RECORDTYPE),
TABLE(MDS_CDSADIR_KRMM_RECORDTYPE),
TABLE(MDS_CDSADIR_EMM_RECORDTYPE),
TABLE(MDS_CDSADIR_COMMON_RECORDTYPE),
TABLE(MDS_CDSADIR_CSP_PRIMARY_RECORDTYPE),
TABLE(MDS_CDSADIR_CSP_CAPABILITY_RECORDTYPE),
TABLE(MDS_CDSADIR_CSP_ENCAPSULATED_PRODUCT_RECORDTYPE),
TABLE(MDS_CDSADIR_CSP_SC_INFO_RECORDTYPE),
TABLE(MDS_CDSADIR_DL_PRIMARY_RECORDTYPE),
TABLE(MDS_CDSADIR_DL_ENCAPSULATED_PRODUCT_RECORDTYPE),
TABLE(MDS_CDSADIR_CL_PRIMARY_RECORDTYPE),
TABLE(MDS_CDSADIR_CL_ENCAPSULATED_PRODUCT_RECORDTYPE),
TABLE(MDS_CDSADIR_TP_PRIMARY_RECORDTYPE),
TABLE(MDS_CDSADIR_TP_OIDS_RECORDTYPE),
TABLE(MDS_CDSADIR_TP_ENCAPSULATED_PRODUCT_RECORDTYPE),
TABLE(MDS_CDSADIR_EMM_PRIMARY_RECORDTYPE),
TABLE(MDS_CDSADIR_AC_PRIMARY_RECORDTYPE),
TABLE(MDS_CDSADIR_KR_PRIMARY_RECORDTYPE),
{ ~0UL, NULL }
};
MDSModule &
MDSModule::get ()
{
return mModuleNexus ();
}
MDSModule::MDSModule ()
: mDatabaseManager(kTableNames),
mLastScanTime((time_t)0),
mServerMode(false)
{
mDbPath[0] = '\0';
}
MDSModule::~MDSModule ()
{
}
void MDSModule::lastScanIsNow()
{
mLastScanTime = Time::now();
}
double MDSModule::timeSinceLastScan()
{
Time::Interval delta = Time::now() - mLastScanTime;
return delta.seconds();
}
void MDSModule::getDbPath(
char *path)
{
StLock<Mutex> _(mDbPathLock);
strcpy(path, mDbPath);
}
void MDSModule::setDbPath(const char *path)
{
StLock<Mutex> _(mDbPathLock);
assert(strlen(path) <= MAXPATHLEN);
strcpy(mDbPath, path);
}
void MDSModule::setServerMode()
{
secdebug("MDSModule", "setting global server mode");
mServerMode = true;
}
}