2 * Copyright (c) 2000-2001,2011,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 #ifndef _MDSDATABASE_H_
20 #define _MDSDATABASE_H_ 1
22 #include <security_filedb/AppleDatabase.h>
23 #include <security_utilities/threading.h>
26 /* This is the concrete DatabaseFactory subclass that creates MDSDatabase instances.
27 Specifically with MDS there are always exactly 2 databases with fixed names. These
28 are both created whenever the first Database is requested from this factory. The
29 contents of these databases is constructed on the fly by scanning the CSSM bundle
30 path for plugins and reading the mds segments from there. Asking
31 for a Database with a name different from the 2 allowed ones will result in an
32 exception being thrown.
35 class MDSDatabaseManager
: public AppleDatabaseManager
38 MDSDatabaseManager(const AppleDatabaseTableName
*tableNames
);
39 Database
*make(const DbName
&inDbName
);
42 /* This is the class which represents each of the two MDS databases. */
44 class MDSDatabase
: public AppleDatabase
47 MDSDatabase(const DbName
&inDbName
, const AppleDatabaseTableName
*tableNames
);
53 makeDbContext(DatabaseSession
&inDatabaseSession
,
54 CSSM_DB_ACCESS_TYPE inAccessRequest
,
55 const CSSM_ACCESS_CREDENTIALS
*inAccessCred
,
56 const void *inOpenParameters
);
59 dbOpen(DbContext
&inDbContext
);
65 dbCreate(DbContext
&inDbContext
, const CSSM_DBINFO
&inDBInfo
,
66 const CSSM_ACL_ENTRY_INPUT
*inInitialAclEntry
);
69 dbDelete(DatabaseSession
&inDatabaseSession
,
70 const CSSM_ACCESS_CREDENTIALS
*inAccessCred
);
73 createRelation (DbContext
&dbContext
,
74 CSSM_DB_RECORDTYPE inRelationID
,
75 const char *inRelationName
,
76 uint32 inNumberOfAttributes
,
77 const CSSM_DB_SCHEMA_ATTRIBUTE_INFO
&inAttributeInfo
,
78 uint32 inNumberOfIndexes
,
79 const CSSM_DB_SCHEMA_INDEX_INFO
&inIndexInfo
);
82 destroyRelation (DbContext
&dbContext
, CSSM_DB_RECORDTYPE inRelationID
);
85 authenticate(DbContext
&dbContext
,
86 CSSM_DB_ACCESS_TYPE inAccessRequest
,
87 const CSSM_ACCESS_CREDENTIALS
&inAccessCred
);
90 getDbAcl(DbContext
&dbContext
,
91 const CSSM_STRING
*inSelectionTag
,
92 uint32
&outNumberOfAclInfos
,
93 CSSM_ACL_ENTRY_INFO_PTR
&outAclInfos
);
96 changeDbAcl(DbContext
&dbContext
,
97 const CSSM_ACCESS_CREDENTIALS
&inAccessCred
,
98 const CSSM_ACL_EDIT
&inAclEdit
);
101 getDbOwner(DbContext
&dbContext
, CSSM_ACL_OWNER_PROTOTYPE
&outOwner
);
104 changeDbOwner(DbContext
&dbContext
,
105 const CSSM_ACCESS_CREDENTIALS
&inAccessCred
,
106 const CSSM_ACL_OWNER_PROTOTYPE
&inNewOwner
);
109 getDbNameFromHandle (const DbContext
&dbContext
) const;
111 virtual CSSM_DB_UNIQUE_RECORD_PTR
112 dataInsert (DbContext
&dbContext
,
113 CSSM_DB_RECORDTYPE RecordType
,
114 const CSSM_DB_RECORD_ATTRIBUTE_DATA
*inAttributes
,
115 const CssmData
*inData
);
118 dataDelete (DbContext
&dbContext
,
119 const CSSM_DB_UNIQUE_RECORD
&inUniqueRecordIdentifier
);
122 dataModify (DbContext
&dbContext
,
123 CSSM_DB_RECORDTYPE RecordType
,
124 CSSM_DB_UNIQUE_RECORD
&inoutUniqueRecordIdentifier
,
125 const CSSM_DB_RECORD_ATTRIBUTE_DATA
*inAttributesToBeModified
,
126 const CssmData
*inDataToBeModified
,
127 CSSM_DB_MODIFY_MODE ModifyMode
);
130 dataGetFirst (DbContext
&dbContext
,
131 const CssmQuery
*inQuery
,
132 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR inoutAttributes
,
134 CSSM_DB_UNIQUE_RECORD_PTR
&outUniqueRecord
);
137 dataGetNext (DbContext
&dbContext
,
138 CSSM_HANDLE inResultsHandle
,
139 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR inoutAttributes
,
141 CSSM_DB_UNIQUE_RECORD_PTR
&outUniqueRecord
);
144 dataAbortQuery (DbContext
&dbContext
,
145 CSSM_HANDLE inResultsHandle
);
148 dataGetFromUniqueRecordId (DbContext
&dbContext
,
149 const CSSM_DB_UNIQUE_RECORD
&inUniqueRecord
,
150 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR inoutAttributes
,
151 CssmData
*inoutData
);
154 freeUniqueRecord (DbContext
&dbContext
,
155 CSSM_DB_UNIQUE_RECORD
&inUniqueRecord
);
158 #endif //_MDSDATABASE_H_