]> git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cdsa_plugin/lib/DatabaseSession.h
Security-57031.40.6.tar.gz
[apple/security.git] / Security / libsecurity_cdsa_plugin / lib / DatabaseSession.h
1 /*
2 * Copyright (c) 2000-2001,2011,2014 Apple 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 //
20 // DatabaseSession.h - Framework for DL plugin modules
21 //
22 #ifndef _H_DATABASESESSION
23 #define _H_DATABASESESSION
24
25 #include <security_cdsa_plugin/DLabstractsession.h>
26
27 #include <security_utilities/alloc.h>
28 #include <security_utilities/threading.h>
29 #include <Security/cssmtype.h>
30 #include <map>
31
32 namespace Security {
33
34 class DatabaseManager;
35 class DbContext;
36
37 // A class providing some of the base Database (DL and MDS) functionality.
38 class DatabaseSession: public DLAbstractPluginSession, public Allocator
39 {
40 public:
41 DatabaseSession(DatabaseManager &inDatabaseManager);
42 virtual ~DatabaseSession();
43
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);
72
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,
89 char **DbName);
90 void DataInsert(CSSM_DB_HANDLE DBHandle,
91 CSSM_DB_RECORDTYPE RecordType,
92 const CSSM_DB_RECORD_ATTRIBUTE_DATA *Attributes,
93 const CssmData *Data,
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,
106 CssmData *Data,
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,
111 CssmData *Data,
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,
118 CssmData *Data);
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);
125
126 DatabaseManager &mDatabaseManager;
127 protected:
128 void closeAll();
129 private:
130 CSSM_DB_HANDLE insertDbContext(DbContext &dbContext);
131 DbContext &findDbContext(CSSM_DB_HANDLE inDbHandle);
132
133 typedef std::map<CSSM_DB_HANDLE, DbContext *> DbContextMap;
134 DbContextMap mDbContextMap;
135 Mutex mDbContextMapLock;
136 };
137
138 } // end namespace Security
139
140 #endif //_H_DATABASESESSION