]> git.saurik.com Git - apple/security.git/blob - cdsa/mds/MDSModule.cpp
Security-179.tar.gz
[apple/security.git] / cdsa / mds / MDSModule.cpp
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 #include "MDSModule.h"
20 #include "MDSSession.h"
21 #include <Security/mds_schema.h>
22 #include <memory>
23
24 namespace Security
25 {
26
27 ModuleNexus<MDSModule> MDSModule::mModuleNexus;
28
29 // Names and IDs of tables used in the MDS databases
30
31 #define TABLE(t) { t, #t }
32
33 /*
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.
38 */
39 #define USE_FILE_DL_TABLES 1
40
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),
48 #else
49 TABLE(MDS_CDSADIR_MDS_SCHEMA_RELATIONS),
50 TABLE(MDS_CDSADIR_MDS_SCHEMA_ATTRIBUTES),
51 TABLE(MDS_CDSADIR_MDS_SCHEMA_INDEXES),
52 #endif
53 TABLE(CSSM_DL_DB_SCHEMA_PARSING_MODULE),
54
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),
75
76 // marker for the end of the list
77 { ~0UL, NULL }
78 };
79
80 MDSModule &
81 MDSModule::get ()
82 {
83 return mModuleNexus ();
84 }
85
86 MDSModule::MDSModule ()
87 : mDatabaseManager(kTableNames),
88 mLastScanTime((time_t)0)
89 {
90 mDbPath[0] = '\0';
91 }
92
93 /*
94 * Called upon unload or process death by CleanModuleNexus.
95 */
96 MDSModule::~MDSModule ()
97 {
98 /* TBD - close all DBs */
99 }
100
101 void MDSModule::lastScanIsNow()
102 {
103 mLastScanTime = Time::now();
104 }
105
106 double MDSModule::timeSinceLastScan()
107 {
108 Time::Interval delta = Time::now() - mLastScanTime;
109 return delta.seconds();
110 }
111
112 void MDSModule::getDbPath(
113 char *path)
114 {
115 StLock<Mutex> _(mDbPathLock);
116 strcpy(path, mDbPath);
117 }
118
119 void MDSModule::setDbPath(const char *path)
120 {
121 StLock<Mutex> _(mDbPathLock);
122 assert(strlen(path) <= MAXPATHLEN);
123 strcpy(mDbPath, path);
124 }
125
126 } // end namespace Security