2 * Copyright (c) 2000-2001,2011,2013-2014 Apple Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 #include "MDSModule.h"
20 #include "MDSSession.h"
21 #include <Security/mds_schema.h>
27 ModuleNexus
<MDSModule
> MDSModule::mModuleNexus
;
29 // Names and IDs of tables used in the MDS databases
31 #define TABLE(t) { t, #t }
34 * For now, to allow compatibility with AppleFileDL, we use the same record IDs
35 * it uses when constructing an AppleDatabaseManager. See Radar 2817921 for details.
36 * The fix requires that AppleDatabase be able to fetch its meta-table relationIDs
37 * from an existing DB at DbOpen time; I'm not sure that's possible.
39 #define USE_FILE_DL_TABLES 1
41 static const AppleDatabaseTableName kTableNames
[] = {
42 // the meta-tables. the parsing module is not used by MDS, but is required
43 // by the implementation of the database
44 #if USE_FILE_DL_TABLES
45 TABLE(CSSM_DL_DB_SCHEMA_INFO
),
46 TABLE(CSSM_DL_DB_SCHEMA_ATTRIBUTES
),
47 TABLE(CSSM_DL_DB_SCHEMA_INDEXES
),
49 TABLE(MDS_CDSADIR_MDS_SCHEMA_RELATIONS
),
50 TABLE(MDS_CDSADIR_MDS_SCHEMA_ATTRIBUTES
),
51 TABLE(MDS_CDSADIR_MDS_SCHEMA_INDEXES
),
53 TABLE(CSSM_DL_DB_SCHEMA_PARSING_MODULE
),
55 // the MDS-specific tables
56 TABLE(MDS_OBJECT_RECORDTYPE
),
57 TABLE(MDS_CDSADIR_CSSM_RECORDTYPE
),
58 TABLE(MDS_CDSADIR_KRMM_RECORDTYPE
),
59 TABLE(MDS_CDSADIR_EMM_RECORDTYPE
),
60 TABLE(MDS_CDSADIR_COMMON_RECORDTYPE
),
61 TABLE(MDS_CDSADIR_CSP_PRIMARY_RECORDTYPE
),
62 TABLE(MDS_CDSADIR_CSP_CAPABILITY_RECORDTYPE
),
63 TABLE(MDS_CDSADIR_CSP_ENCAPSULATED_PRODUCT_RECORDTYPE
),
64 TABLE(MDS_CDSADIR_CSP_SC_INFO_RECORDTYPE
),
65 TABLE(MDS_CDSADIR_DL_PRIMARY_RECORDTYPE
),
66 TABLE(MDS_CDSADIR_DL_ENCAPSULATED_PRODUCT_RECORDTYPE
),
67 TABLE(MDS_CDSADIR_CL_PRIMARY_RECORDTYPE
),
68 TABLE(MDS_CDSADIR_CL_ENCAPSULATED_PRODUCT_RECORDTYPE
),
69 TABLE(MDS_CDSADIR_TP_PRIMARY_RECORDTYPE
),
70 TABLE(MDS_CDSADIR_TP_OIDS_RECORDTYPE
),
71 TABLE(MDS_CDSADIR_TP_ENCAPSULATED_PRODUCT_RECORDTYPE
),
72 TABLE(MDS_CDSADIR_EMM_PRIMARY_RECORDTYPE
),
73 TABLE(MDS_CDSADIR_AC_PRIMARY_RECORDTYPE
),
74 TABLE(MDS_CDSADIR_KR_PRIMARY_RECORDTYPE
),
76 // marker for the end of the list
83 return mModuleNexus ();
86 MDSModule::MDSModule ()
87 : mDatabaseManager(kTableNames
),
88 mLastScanTime((time_t)0),
95 * Called upon unload or process death by CleanModuleNexus.
97 MDSModule::~MDSModule ()
99 /* TBD - close all DBs */
102 void MDSModule::lastScanIsNow()
104 mLastScanTime
= Time::now();
107 double MDSModule::timeSinceLastScan()
109 Time::Interval delta
= Time::now() - mLastScanTime
;
110 return delta
.seconds();
113 void MDSModule::getDbPath(
116 StLock
<Mutex
> _(mDbPathLock
);
117 strcpy(path
, mDbPath
);
120 void MDSModule::setDbPath(const char *path
)
122 StLock
<Mutex
> _(mDbPathLock
);
123 /* caller assures this, and this is private to this module */
124 assert(strlen(path
) <= MAXPATHLEN
);
125 strcpy(mDbPath
, path
);
128 void MDSModule::setServerMode()
130 secinfo("MDSModule", "setting global server mode");
134 } // end namespace Security