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/DatabaseSession.h>
23 #include <Security/handleobject.h>
24 #include <Security/mds.h>
25 #include <Security/MDSModule.h>
26 #include <Security/MDSSchema.h>
29 #include <sys/param.h>
30 #include <sys/types.h>
36 class MDSSession
: public DatabaseSession
, public HandleObject
40 MDSSession (const Guid
*inCallerGuid
,
41 const CSSM_MEMORY_FUNCS
&inMemoryFunctions
);
42 virtual ~MDSSession ();
48 CSSM_DB_HANDLE
MDSSession::dbOpen(
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 void GetDbNames(CSSM_NAME_LIST_PTR
&NameList
);
59 void FreeNameList(CSSM_NAME_LIST
&NameList
);
60 void GetDbNameFromHandle(CSSM_DB_HANDLE DBHandle
,
63 // implement CssmHeap::Allocator
64 void *malloc(size_t size
) throw(std::bad_alloc
)
65 { return mCssmMemoryFunctions
.malloc(size
); }
66 void free(void *addr
) throw()
67 { mCssmMemoryFunctions
.free(addr
); }
68 void *realloc(void *addr
, size_t size
) throw(std::bad_alloc
)
69 { return mCssmMemoryFunctions
.realloc(addr
, size
); }
71 MDSModule
&module() { return mModule
; }
72 void removeRecordsForGuid(
74 CSSM_DB_HANDLE dbHand
);
78 * represents two DB files in any location and state
83 DbFilesInfo(MDSSession
&session
, const char *dbPath
);
85 /* these three may not be needed */
86 CSSM_DB_HANDLE
objDbHand();
87 CSSM_DB_HANDLE
directDbHand();
88 time_t laterTimestamp() { return mLaterTimestamp
; }
90 /* public functions used by MDSSession */
91 void updateSystemDbInfo(
92 const char *systemPath
, // e.g., /System/Library/Frameworks
93 const char *bundlePath
); // e.g., /System/Library/Security
94 void removeOutdatedPlugins();
95 void updateForBundleDir(
96 const char *bundleDirPath
);
98 const char *bundlePath
);
99 void autoCommit(CSSM_BOOL val
); // DB autocommit on/off
104 /* object and list to keep track of "to be deleted" records */
105 #define MAX_GUID_LEN 64 /* normally 37 */
109 TbdRecord(const CSSM_DATA
&guid
);
111 const char *guid() { return mGuid
; }
113 char mGuid
[MAX_GUID_LEN
];
115 typedef vector
<TbdRecord
*> TbdVector
;
117 void checkOutdatedPlugin(
118 const CSSM_DATA
&pathValue
,
119 const CSSM_DATA
&guidValue
,
120 TbdVector
&tbdVector
);
122 MDSSession
&mSession
;
123 char mDbPath
[MAXPATHLEN
];
124 CSSM_DB_HANDLE mObjDbHand
;
125 CSSM_DB_HANDLE mDirectDbHand
;
126 time_t mLaterTimestamp
;
130 const char *lockFile
,
136 /* given DB file name, fill in fully specified path */
139 char fullPath
[MAXPATHLEN
+1]);
141 void updateDataBases();
143 bool systemDatabasesPresent(bool purge
);
144 void createSystemDatabase(
146 const RelationInfo
*relationInfo
,
147 unsigned numRelations
,
148 CSSM_BOOL autoCommit
,
150 CSSM_DB_HANDLE
&dbHand
); // RETURNED
151 bool createSystemDatabases(
152 CSSM_BOOL autoCommit
,
155 const CssmMemoryFunctions mCssmMemoryFunctions
;
157 bool mCallerGuidPresent
;
160 int mLockFd
; // per-user MDS DB lock
163 } // end namespace Security
165 #endif //_MDSSESSION_H_