2 * Copyright (c) 2000-2001 Apple Computer, 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/DLabstractsession.h>
27 #include <Security/cssmalloc.h>
28 #include <Security/threading.h>
29 #include <Security/cssmtype.h>
32 #if defined(_CPP_DATABASESESSION)
39 class DatabaseManager
;
42 // A class providing some of the base Database (DL and MDS) functionality.
43 class DatabaseSession
: public DLAbstractPluginSession
, public CssmAllocator
46 DatabaseSession(DatabaseManager
&inDatabaseManager
);
47 virtual ~DatabaseSession();
49 void GetDbNames(CSSM_NAME_LIST_PTR
&NameList
);
50 void FreeNameList(CSSM_NAME_LIST
&NameList
);
51 void DbDelete(const char *DbName
,
52 const CSSM_NET_ADDRESS
*DbLocation
,
53 const AccessCredentials
*AccessCred
);
54 void DbCreate(const char *DbName
,
55 const CSSM_NET_ADDRESS
*DbLocation
,
56 const CSSM_DBINFO
&DBInfo
,
57 CSSM_DB_ACCESS_TYPE AccessRequest
,
58 const CSSM_RESOURCE_CONTROL_CONTEXT
*CredAndAclEntry
,
59 const void *OpenParameters
,
60 CSSM_DB_HANDLE
&DbHandle
);
61 void DbOpen(const char *DbName
,
62 const CSSM_NET_ADDRESS
*DbLocation
,
63 CSSM_DB_ACCESS_TYPE AccessRequest
,
64 const AccessCredentials
*AccessCred
,
65 const void *OpenParameters
,
66 CSSM_DB_HANDLE
&DbHandle
);
67 void DbClose(CSSM_DB_HANDLE DBHandle
);
68 void CreateRelation(CSSM_DB_HANDLE DBHandle
,
69 CSSM_DB_RECORDTYPE RelationID
,
70 const char *RelationName
,
71 uint32 NumberOfAttributes
,
72 const CSSM_DB_SCHEMA_ATTRIBUTE_INFO
&pAttributeInfo
,
73 uint32 NumberOfIndexes
,
74 const CSSM_DB_SCHEMA_INDEX_INFO
&pIndexInfo
);
75 void DestroyRelation(CSSM_DB_HANDLE DBHandle
,
76 CSSM_DB_RECORDTYPE RelationID
);
78 void Authenticate(CSSM_DB_HANDLE DBHandle
,
79 CSSM_DB_ACCESS_TYPE AccessRequest
,
80 const AccessCredentials
&AccessCred
);
81 void GetDbAcl(CSSM_DB_HANDLE DBHandle
,
82 const CSSM_STRING
*SelectionTag
,
83 uint32
&NumberOfAclInfos
,
84 CSSM_ACL_ENTRY_INFO_PTR
&AclInfos
);
85 void ChangeDbAcl(CSSM_DB_HANDLE DBHandle
,
86 const AccessCredentials
&AccessCred
,
87 const CSSM_ACL_EDIT
&AclEdit
);
88 void GetDbOwner(CSSM_DB_HANDLE DBHandle
,
89 CSSM_ACL_OWNER_PROTOTYPE
&Owner
);
90 void ChangeDbOwner(CSSM_DB_HANDLE DBHandle
,
91 const AccessCredentials
&AccessCred
,
92 const CSSM_ACL_OWNER_PROTOTYPE
&NewOwner
);
93 void GetDbNameFromHandle(CSSM_DB_HANDLE DBHandle
,
95 void DataInsert(CSSM_DB_HANDLE DBHandle
,
96 CSSM_DB_RECORDTYPE RecordType
,
97 const CSSM_DB_RECORD_ATTRIBUTE_DATA
*Attributes
,
99 CSSM_DB_UNIQUE_RECORD_PTR
&UniqueId
);
100 void DataDelete(CSSM_DB_HANDLE DBHandle
,
101 const CSSM_DB_UNIQUE_RECORD
&UniqueRecordIdentifier
);
102 void DataModify(CSSM_DB_HANDLE DBHandle
,
103 CSSM_DB_RECORDTYPE RecordType
,
104 CSSM_DB_UNIQUE_RECORD
&UniqueRecordIdentifier
,
105 const CSSM_DB_RECORD_ATTRIBUTE_DATA
*AttributesToBeModified
,
106 const CssmData
*DataToBeModified
,
107 CSSM_DB_MODIFY_MODE ModifyMode
);
108 CSSM_HANDLE
DataGetFirst(CSSM_DB_HANDLE DBHandle
,
109 const DLQuery
*Query
,
110 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
112 CSSM_DB_UNIQUE_RECORD_PTR
&UniqueId
);
113 bool DataGetNext(CSSM_DB_HANDLE DBHandle
,
114 CSSM_HANDLE ResultsHandle
,
115 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
117 CSSM_DB_UNIQUE_RECORD_PTR
&UniqueId
);
118 void DataAbortQuery(CSSM_DB_HANDLE DBHandle
,
119 CSSM_HANDLE ResultsHandle
);
120 void DataGetFromUniqueRecordId(CSSM_DB_HANDLE DBHandle
,
121 const CSSM_DB_UNIQUE_RECORD
&UniqueRecord
,
122 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
124 void FreeUniqueRecord(CSSM_DB_HANDLE DBHandle
,
125 CSSM_DB_UNIQUE_RECORD
&UniqueRecord
);
126 void PassThrough(CSSM_DB_HANDLE DBHandle
,
127 uint32 PassThroughId
,
128 const void *InputParams
,
129 void **OutputParams
);
131 DatabaseManager
&mDatabaseManager
;
135 CSSM_DB_HANDLE
insertDbContext(DbContext
&dbContext
);
136 DbContext
&findDbContext(CSSM_DB_HANDLE inDbHandle
);
138 typedef std::map
<CSSM_DB_HANDLE
, DbContext
*> DbContextMap
;
139 DbContextMap mDbContextMap
;
140 Mutex mDbContextMapLock
;
143 } // end namespace Security
145 #if defined(_CPP_DATABASESESSION)
149 #endif //_H_DATABASESESSION