]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | /* |
2 | * Copyright (c) 2000-2001 Apple Computer, 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 | #ifndef _MDSSESSION_H_ | |
20 | #define _MDSSESSION_H_ 1 | |
21 | ||
22 | #include <Security/DatabaseSession.h> | |
23 | #include <Security/handleobject.h> | |
24 | #include <Security/mds.h> | |
29654253 A |
25 | #include <Security/MDSModule.h> |
26 | #include <Security/MDSSchema.h> | |
bac41a7b A |
27 | #include <map> |
28 | #include <sys/stat.h> | |
29654253 A |
29 | #include <sys/param.h> |
30 | #include <sys/types.h> | |
bac41a7b A |
31 | #include <list> |
32 | ||
29654253 A |
33 | namespace Security |
34 | { | |
bac41a7b A |
35 | |
36 | class MDSSession: public DatabaseSession, public HandleObject | |
37 | { | |
38 | NOCOPY(MDSSession) | |
39 | public: | |
40 | MDSSession (const Guid *inCallerGuid, | |
41 | const CSSM_MEMORY_FUNCS &inMemoryFunctions); | |
42 | virtual ~MDSSession (); | |
43 | ||
44 | void terminate (); | |
45 | void install (); | |
46 | void uninstall (); | |
47 | ||
29654253 A |
48 | CSSM_DB_HANDLE MDSSession::dbOpen( |
49 | const char *dbName); | |
50 | ||
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, | |
61 | char **DbName); | |
bac41a7b A |
62 | |
63 | // implement CssmHeap::Allocator | |
29654253 A |
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); } | |
bac41a7b | 70 | |
29654253 A |
71 | MDSModule &module() { return mModule; } |
72 | void removeRecordsForGuid( | |
73 | const char *guid, | |
74 | CSSM_DB_HANDLE dbHand); | |
75 | ||
76 | ||
77 | /* | |
78 | * represents two DB files in any location and state | |
79 | */ | |
80 | class DbFilesInfo | |
81 | { | |
82 | public: | |
83 | DbFilesInfo(MDSSession &session, const char *dbPath); | |
84 | ~DbFilesInfo(); | |
85 | /* these three may not be needed */ | |
86 | CSSM_DB_HANDLE objDbHand(); | |
87 | CSSM_DB_HANDLE directDbHand(); | |
88 | time_t laterTimestamp() { return mLaterTimestamp; } | |
89 | ||
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); | |
97 | void updateForBundle( | |
98 | const char *bundlePath); | |
99 | void autoCommit(CSSM_BOOL val); // DB autocommit on/off | |
100 | private: | |
101 | bool lookupForPath( | |
102 | const char *path); | |
bac41a7b | 103 | |
29654253 A |
104 | /* object and list to keep track of "to be deleted" records */ |
105 | #define MAX_GUID_LEN 64 /* normally 37 */ | |
106 | class TbdRecord | |
107 | { | |
108 | public: | |
109 | TbdRecord(const CSSM_DATA &guid); | |
110 | ~TbdRecord() { } | |
111 | const char *guid() { return mGuid; } | |
112 | private: | |
113 | char mGuid[MAX_GUID_LEN]; | |
114 | }; | |
115 | typedef vector<TbdRecord *> TbdVector; | |
bac41a7b | 116 | |
29654253 A |
117 | void checkOutdatedPlugin( |
118 | const CSSM_DATA &pathValue, | |
119 | const CSSM_DATA &guidValue, | |
120 | TbdVector &tbdVector); | |
121 | ||
122 | MDSSession &mSession; | |
123 | char mDbPath[MAXPATHLEN]; | |
124 | CSSM_DB_HANDLE mObjDbHand; | |
125 | CSSM_DB_HANDLE mDirectDbHand; | |
126 | time_t mLaterTimestamp; | |
127 | }; /* DbFilesInfo */ | |
128 | private: | |
129 | bool obtainLock( | |
130 | const char *lockFile, | |
131 | int &fd, | |
132 | int timeout = 0); | |
133 | void releaseLock( | |
134 | int &fd); | |
135 | ||
136 | /* given DB file name, fill in fully specified path */ | |
137 | void dbFullPath( | |
138 | const char *dbName, | |
139 | char fullPath[MAXPATHLEN+1]); | |
140 | ||
141 | void updateDataBases(); | |
142 | ||
143 | bool systemDatabasesPresent(bool purge); | |
144 | void createSystemDatabase( | |
145 | const char *dbName, | |
146 | const RelationInfo *relationInfo, | |
147 | unsigned numRelations, | |
df0e469f A |
148 | CSSM_BOOL autoCommit, |
149 | mode_t mode, | |
29654253 | 150 | CSSM_DB_HANDLE &dbHand); // RETURNED |
df0e469f A |
151 | bool createSystemDatabases( |
152 | CSSM_BOOL autoCommit, | |
153 | mode_t mode); | |
bac41a7b A |
154 | |
155 | const CssmMemoryFunctions mCssmMemoryFunctions; | |
29654253 A |
156 | Guid mCallerGuid; |
157 | bool mCallerGuidPresent; | |
bac41a7b | 158 | |
29654253 A |
159 | MDSModule &mModule; |
160 | int mLockFd; // per-user MDS DB lock | |
bac41a7b A |
161 | }; |
162 | ||
29654253 A |
163 | } // end namespace Security |
164 | ||
bac41a7b | 165 | #endif //_MDSSESSION_H_ |