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.
19 #ifndef _MDSSESSION_H_
20 #define _MDSSESSION_H_ 1
22 #include <security_cdsa_plugin/DatabaseSession.h>
23 #include <security_cdsa_utilities/handleobject.h>
24 #include <security_cdsa_utilities/cssmdb.h>
25 #include <Security/mdspriv.h>
26 #include "MDSModule.h"
27 #include "MDSSchema.h"
30 #include <sys/param.h>
31 #include <sys/types.h>
37 class MDSSession
: public DatabaseSession
, public HandleObject
41 MDSSession (const Guid
*inCallerGuid
,
42 const CSSM_MEMORY_FUNCS
&inMemoryFunctions
);
43 virtual ~MDSSession ();
49 CSSM_DB_HANDLE
dbOpen(const char *dbName
, bool batched
= false);
51 // some DatabaseSession routines we need to override
52 void DbOpen(const char *DbName
,
53 const CSSM_NET_ADDRESS
*DbLocation
,
54 CSSM_DB_ACCESS_TYPE AccessRequest
,
55 const AccessCredentials
*AccessCred
,
56 const void *OpenParameters
,
57 CSSM_DB_HANDLE
&DbHandle
);
58 CSSM_HANDLE
DataGetFirst(CSSM_DB_HANDLE DBHandle
,
59 const CssmQuery
*Query
,
60 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
62 CSSM_DB_UNIQUE_RECORD_PTR
&UniqueId
);
63 void GetDbNames(CSSM_NAME_LIST_PTR
&NameList
);
64 void FreeNameList(CSSM_NAME_LIST
&NameList
);
65 void GetDbNameFromHandle(CSSM_DB_HANDLE DBHandle
,
68 // additional public (or private API) methods
69 void installFile(const MDS_InstallDefaults
*defaults
,
70 const char *inBundlePath
, const char *subdir
, const char *file
);
71 void removeSubservice(const char *guid
, uint32 ssid
);
73 // implement CssmHeap::Allocator
74 void *malloc(size_t size
) throw(std::bad_alloc
)
75 { return mCssmMemoryFunctions
.malloc(size
); }
76 void free(void *addr
) throw()
77 { mCssmMemoryFunctions
.free(addr
); }
78 void *realloc(void *addr
, size_t size
) throw(std::bad_alloc
)
79 { return mCssmMemoryFunctions
.realloc(addr
, size
); }
81 MDSModule
&module() { return mModule
; }
82 void removeRecordsForGuid(
84 CSSM_DB_HANDLE dbHand
);
88 * represents two DB files in any location and state
93 DbFilesInfo(MDSSession
&session
, const char *dbPath
);
95 /* these three may not be needed */
96 CSSM_DB_HANDLE
objDbHand();
97 CSSM_DB_HANDLE
directDbHand();
98 time_t laterTimestamp() { return mLaterTimestamp
; }
100 /* public functions used by MDSSession */
101 void updateSystemDbInfo(
102 const char *systemPath
, // e.g., /System/Library/Frameworks
103 const char *bundlePath
); // e.g., /System/Library/Security
104 void removeOutdatedPlugins();
105 void updateForBundleDir(
106 const char *bundleDirPath
);
107 void updateForBundle(
108 const char *bundlePath
);
113 /* object and list to keep track of "to be deleted" records */
114 #define MAX_GUID_LEN 64 /* normally 37 */
118 TbdRecord(const CSSM_DATA
&guid
);
120 const char *guid() { return mGuid
; }
122 char mGuid
[MAX_GUID_LEN
];
124 typedef vector
<TbdRecord
*> TbdVector
;
126 void checkOutdatedPlugin(
127 const CSSM_DATA
&pathValue
,
128 const CSSM_DATA
&guidValue
,
129 TbdVector
&tbdVector
);
131 MDSSession
&mSession
;
132 char mDbPath
[MAXPATHLEN
];
133 CSSM_DB_HANDLE mObjDbHand
;
134 CSSM_DB_HANDLE mDirectDbHand
;
135 time_t mLaterTimestamp
;
144 LockHelper() : mFD(-1) {}
148 const char *lockFile
,
152 /* given DB file name, fill in fully specified path */
155 char fullPath
[MAXPATHLEN
+1]);
157 void updateDataBases();
159 void clearRecords(CSSM_DB_HANDLE dbHand
, const CssmQuery
&query
);
161 bool systemDatabasesPresent(bool purge
);
162 void createSystemDatabase(
164 const RelationInfo
*relationInfo
,
165 unsigned numRelations
,
166 CSSM_BOOL autoCommit
,
168 CSSM_DB_HANDLE
&dbHand
); // RETURNED
169 bool createSystemDatabases(
170 CSSM_BOOL autoCommit
,
173 RecursionBlock mUpdating
; // updateDatabases() in progress
175 const CssmMemoryFunctions mCssmMemoryFunctions
;
177 bool mCallerGuidPresent
;
182 } // end namespace Security
184 #endif //_MDSSESSION_H_