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.
20 // DatabaseSession.h - Framework for DL plugin modules
22 #ifndef _H_DATABASESESSION
23 #define _H_DATABASESESSION
25 #include <security_cdsa_plugin/DLabstractsession.h>
27 #include <security_utilities/alloc.h>
28 #include <security_utilities/threading.h>
29 #include <Security/cssmtype.h>
34 class DatabaseManager
;
37 // A class providing some of the base Database (DL and MDS) functionality.
38 class DatabaseSession
: public DLAbstractPluginSession
, public Allocator
41 DatabaseSession(DatabaseManager
&inDatabaseManager
);
42 virtual ~DatabaseSession();
44 virtual void GetDbNames(CSSM_NAME_LIST_PTR
&NameList
);
45 virtual void FreeNameList(CSSM_NAME_LIST
&NameList
);
46 void DbDelete(const char *DbName
,
47 const CSSM_NET_ADDRESS
*DbLocation
,
48 const AccessCredentials
*AccessCred
);
49 void DbCreate(const char *DbName
,
50 const CSSM_NET_ADDRESS
*DbLocation
,
51 const CSSM_DBINFO
&DBInfo
,
52 CSSM_DB_ACCESS_TYPE AccessRequest
,
53 const CSSM_RESOURCE_CONTROL_CONTEXT
*CredAndAclEntry
,
54 const void *OpenParameters
,
55 CSSM_DB_HANDLE
&DbHandle
);
56 virtual void DbOpen(const char *DbName
,
57 const CSSM_NET_ADDRESS
*DbLocation
,
58 CSSM_DB_ACCESS_TYPE AccessRequest
,
59 const AccessCredentials
*AccessCred
,
60 const void *OpenParameters
,
61 CSSM_DB_HANDLE
&DbHandle
);
62 void DbClose(CSSM_DB_HANDLE DBHandle
);
63 void CreateRelation(CSSM_DB_HANDLE DBHandle
,
64 CSSM_DB_RECORDTYPE RelationID
,
65 const char *RelationName
,
66 uint32 NumberOfAttributes
,
67 const CSSM_DB_SCHEMA_ATTRIBUTE_INFO
*pAttributeInfo
,
68 uint32 NumberOfIndexes
,
69 const CSSM_DB_SCHEMA_INDEX_INFO
&pIndexInfo
);
70 void DestroyRelation(CSSM_DB_HANDLE DBHandle
,
71 CSSM_DB_RECORDTYPE RelationID
);
73 void Authenticate(CSSM_DB_HANDLE DBHandle
,
74 CSSM_DB_ACCESS_TYPE AccessRequest
,
75 const AccessCredentials
&AccessCred
);
76 void GetDbAcl(CSSM_DB_HANDLE DBHandle
,
77 const CSSM_STRING
*SelectionTag
,
78 uint32
&NumberOfAclInfos
,
79 CSSM_ACL_ENTRY_INFO_PTR
&AclInfos
);
80 void ChangeDbAcl(CSSM_DB_HANDLE DBHandle
,
81 const AccessCredentials
&AccessCred
,
82 const CSSM_ACL_EDIT
&AclEdit
);
83 void GetDbOwner(CSSM_DB_HANDLE DBHandle
,
84 CSSM_ACL_OWNER_PROTOTYPE
&Owner
);
85 void ChangeDbOwner(CSSM_DB_HANDLE DBHandle
,
86 const AccessCredentials
&AccessCred
,
87 const CSSM_ACL_OWNER_PROTOTYPE
&NewOwner
);
88 void GetDbNameFromHandle(CSSM_DB_HANDLE DBHandle
,
90 void DataInsert(CSSM_DB_HANDLE DBHandle
,
91 CSSM_DB_RECORDTYPE RecordType
,
92 const CSSM_DB_RECORD_ATTRIBUTE_DATA
*Attributes
,
94 CSSM_DB_UNIQUE_RECORD_PTR
&UniqueId
);
95 void DataDelete(CSSM_DB_HANDLE DBHandle
,
96 const CSSM_DB_UNIQUE_RECORD
&UniqueRecordIdentifier
);
97 void DataModify(CSSM_DB_HANDLE DBHandle
,
98 CSSM_DB_RECORDTYPE RecordType
,
99 CSSM_DB_UNIQUE_RECORD
&UniqueRecordIdentifier
,
100 const CSSM_DB_RECORD_ATTRIBUTE_DATA
*AttributesToBeModified
,
101 const CssmData
*DataToBeModified
,
102 CSSM_DB_MODIFY_MODE ModifyMode
);
103 CSSM_HANDLE
DataGetFirst(CSSM_DB_HANDLE DBHandle
,
104 const CssmQuery
*Query
,
105 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
107 CSSM_DB_UNIQUE_RECORD_PTR
&UniqueId
);
108 bool DataGetNext(CSSM_DB_HANDLE DBHandle
,
109 CSSM_HANDLE ResultsHandle
,
110 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
112 CSSM_DB_UNIQUE_RECORD_PTR
&UniqueId
);
113 void DataAbortQuery(CSSM_DB_HANDLE DBHandle
,
114 CSSM_HANDLE ResultsHandle
);
115 void DataGetFromUniqueRecordId(CSSM_DB_HANDLE DBHandle
,
116 const CSSM_DB_UNIQUE_RECORD
&UniqueRecord
,
117 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
119 void FreeUniqueRecord(CSSM_DB_HANDLE DBHandle
,
120 CSSM_DB_UNIQUE_RECORD
&UniqueRecord
);
121 void PassThrough(CSSM_DB_HANDLE DBHandle
,
122 uint32 PassThroughId
,
123 const void *InputParams
,
124 void **OutputParams
);
126 DatabaseManager
&mDatabaseManager
;
130 CSSM_DB_HANDLE
insertDbContext(DbContext
&dbContext
);
131 DbContext
&findDbContext(CSSM_DB_HANDLE inDbHandle
);
133 typedef std::map
<CSSM_DB_HANDLE
, DbContext
*> DbContextMap
;
134 DbContextMap mDbContextMap
;
135 Mutex mDbContextMapLock
;
138 } // end namespace Security
140 #endif //_H_DATABASESESSION