]> git.saurik.com Git - apple/security.git/blob - cdsa/cssm/cssm.cpp
Security-28.tar.gz
[apple/security.git] / cdsa / cssm / cssm.cpp
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 //
20 // This file contains the core CSSM public functions.
21 // Note that hardly anything happens in here; we just hand off requests
22 // to the various objects representing CSSM state.
23 //
24 #include "manager.h"
25 #include "module.h"
26 #include <Security/globalizer.h>
27
28
29 //
30 // We currently use exactly one instance of CssmManager.
31 //
32 static ModuleNexus<CssmManager> gManager;
33
34
35 //
36 // Public API: (Re)Intiailize CSSM
37 //
38 CSSM_RETURN CSSMAPI
39 CSSM_Init (const CSSM_VERSION *Version,
40 CSSM_PRIVILEGE_SCOPE Scope,
41 const CSSM_GUID *CallerGuid,
42 CSSM_KEY_HIERARCHY KeyHierarchy,
43 CSSM_PVC_MODE *PvcPolicy,
44 const void *)
45 {
46 BEGIN_API
47 gManager().initialize(Required(Version),
48 Scope,
49 Guid::required(CallerGuid),
50 KeyHierarchy,
51 Required(PvcPolicy));
52 END_API(CSSM)
53 }
54
55
56 //
57 // Public API: Terminate CSSM.
58 //
59 CSSM_RETURN CSSMAPI
60 CSSM_Terminate (void)
61 {
62 BEGIN_API
63 gManager().terminate();
64 END_API(CSSM)
65 }
66
67
68 //
69 // Public API: Load a CSSM module
70 //
71 CSSM_RETURN CSSMAPI
72 CSSM_ModuleLoad (const CSSM_GUID *ModuleGuid,
73 CSSM_KEY_HIERARCHY KeyHierarchy,
74 CSSM_API_ModuleEventHandler AppNotifyCallback,
75 void *AppNotifyCallbackCtx)
76 {
77 BEGIN_API
78 gManager().loadModule(Guid::required(ModuleGuid),
79 KeyHierarchy,
80 ModuleCallback(AppNotifyCallback, AppNotifyCallbackCtx));
81 END_API(CSSM)
82 }
83
84
85 //
86 // Public API: Unload a module
87 //
88 CSSM_RETURN CSSMAPI
89 CSSM_ModuleUnload (const CSSM_GUID *ModuleGuid,
90 CSSM_API_ModuleEventHandler AppNotifyCallback,
91 void *AppNotifyCallbackCtx)
92 {
93 BEGIN_API
94 gManager().unloadModule(Guid::required(ModuleGuid),
95 ModuleCallback(AppNotifyCallback, AppNotifyCallbackCtx));
96 END_API(CSSM)
97 }
98
99
100 CSSM_RETURN CSSMAPI
101 CSSM_Introduce (const CSSM_GUID *ModuleID,
102 CSSM_KEY_HIERARCHY KeyHierarchy)
103 {
104 BEGIN_API
105 gManager().introduce(Guid::required(ModuleID), KeyHierarchy);
106 END_API(CSSM)
107 }
108
109 CSSM_RETURN CSSMAPI
110 CSSM_Unintroduce (const CSSM_GUID *ModuleID)
111 {
112 BEGIN_API
113 gManager().unIntroduce(Guid::required(ModuleID));
114 END_API(CSSM)
115 }
116
117
118 CSSM_RETURN CSSMAPI
119 CSSM_ModuleAttach (const CSSM_GUID *ModuleGuid,
120 const CSSM_VERSION *Version,
121 const CSSM_API_MEMORY_FUNCS *MemoryFuncs,
122 uint32 SubserviceID,
123 CSSM_SERVICE_TYPE SubServiceType,
124 CSSM_ATTACH_FLAGS AttachFlags,
125 CSSM_KEY_HIERARCHY KeyHierarchy,
126 CSSM_FUNC_NAME_ADDR *FunctionTable,
127 uint32 NumFunctionTable,
128 const void *,
129 CSSM_MODULE_HANDLE_PTR NewModuleHandle)
130 {
131 BEGIN_API
132 Required(NewModuleHandle) = gManager().getModule(Guid::required(ModuleGuid))->attach(
133 Required(Version),
134 SubserviceID, SubServiceType,
135 Required(MemoryFuncs),
136 AttachFlags,
137 KeyHierarchy,
138 FunctionTable, NumFunctionTable
139 );
140 END_API(CSSM)
141 }
142
143 CSSM_RETURN CSSMAPI
144 CSSM_ModuleDetach (CSSM_MODULE_HANDLE ModuleHandle)
145 {
146 BEGIN_API
147 Attachment *attachment = &killHandle<Attachment>(ModuleHandle);
148 attachment->detach(true); // expect locked, will unlock
149 // the attachment is now off the maps, known idle, and unhooked
150 delete attachment;
151 END_API(CSSM)
152 }
153
154
155 CSSM_RETURN CSSMAPI
156 CSSM_SetPrivilege (CSSM_PRIVILEGE Privilege)
157 {
158 BEGIN_API
159 gManager().setPrivilege(Privilege);
160 END_API(CSSM)
161 }
162
163 CSSM_RETURN CSSMAPI
164 CSSM_GetPrivilege (CSSM_PRIVILEGE *Privilege)
165 {
166 BEGIN_API
167 Required(Privilege) = gManager().getPrivilege();
168 END_API(CSSM)
169 }
170
171
172 CSSM_RETURN CSSMAPI
173 CSSM_GetModuleGUIDFromHandle (CSSM_MODULE_HANDLE ModuleHandle,
174 CSSM_GUID_PTR ModuleGUID)
175 {
176 BEGIN_API
177 Attachment &attachment = findHandleAndLock<Attachment>(ModuleHandle);
178 StLock<Mutex> _(attachment, true);
179 Required(ModuleGUID) = attachment.module.myGuid();
180 END_API(CSSM)
181 }
182
183 CSSM_RETURN CSSMAPI
184 CSSM_GetSubserviceUIDFromHandle (CSSM_MODULE_HANDLE ModuleHandle,
185 CSSM_SUBSERVICE_UID_PTR SubserviceUID)
186 {
187 BEGIN_API
188 Attachment &attachment = findHandleAndLock<Attachment>(ModuleHandle);
189 StLock<Mutex> _(attachment, true);
190 CSSM_SUBSERVICE_UID &result = Required(SubserviceUID);
191 result.Guid = attachment.module.myGuid();
192 result.Version = attachment.pluginVersion();
193 result.SubserviceId = attachment.subserviceId();
194 result.SubserviceType = attachment.subserviceType();
195 END_API(CSSM)
196 }
197
198
199 CSSM_RETURN CSSMAPI
200 CSSM_ListAttachedModuleManagers (uint32 *NumberOfModuleManagers,
201 CSSM_GUID_PTR)
202 {
203 BEGIN_API
204 *NumberOfModuleManagers = 0; // EMMs not implemented
205 END_API(CSSM)
206 }
207
208 CSSM_RETURN CSSMAPI
209 CSSM_GetAPIMemoryFunctions (CSSM_MODULE_HANDLE AddInHandle,
210 CSSM_API_MEMORY_FUNCS_PTR AppMemoryFuncs)
211 {
212 BEGIN_API
213 Attachment &attachment = findHandleAndLock<Attachment>(AddInHandle);
214 StLock<Mutex> _(attachment, true);
215 Required(AppMemoryFuncs) = attachment;
216 END_API(CSSM)
217 }