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.
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.
26 #include <Security/globalizer.h>
30 // We currently use exactly one instance of CssmManager.
32 static ModuleNexus
<CssmManager
> gManager
;
36 // Public API: (Re)Intiailize CSSM
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
,
47 gManager().initialize(Required(Version
),
49 Guid::required(CallerGuid
),
57 // Public API: Terminate CSSM.
63 gManager().terminate();
69 // Public API: Load a CSSM module
72 CSSM_ModuleLoad (const CSSM_GUID
*ModuleGuid
,
73 CSSM_KEY_HIERARCHY KeyHierarchy
,
74 CSSM_API_ModuleEventHandler AppNotifyCallback
,
75 void *AppNotifyCallbackCtx
)
78 gManager().loadModule(Guid::required(ModuleGuid
),
80 ModuleCallback(AppNotifyCallback
, AppNotifyCallbackCtx
));
86 // Public API: Unload a module
89 CSSM_ModuleUnload (const CSSM_GUID
*ModuleGuid
,
90 CSSM_API_ModuleEventHandler AppNotifyCallback
,
91 void *AppNotifyCallbackCtx
)
94 gManager().unloadModule(Guid::required(ModuleGuid
),
95 ModuleCallback(AppNotifyCallback
, AppNotifyCallbackCtx
));
101 CSSM_Introduce (const CSSM_GUID
*ModuleID
,
102 CSSM_KEY_HIERARCHY KeyHierarchy
)
105 gManager().introduce(Guid::required(ModuleID
), KeyHierarchy
);
110 CSSM_Unintroduce (const CSSM_GUID
*ModuleID
)
113 gManager().unIntroduce(Guid::required(ModuleID
));
119 CSSM_ModuleAttach (const CSSM_GUID
*ModuleGuid
,
120 const CSSM_VERSION
*Version
,
121 const CSSM_API_MEMORY_FUNCS
*MemoryFuncs
,
123 CSSM_SERVICE_TYPE SubServiceType
,
124 CSSM_ATTACH_FLAGS AttachFlags
,
125 CSSM_KEY_HIERARCHY KeyHierarchy
,
126 CSSM_FUNC_NAME_ADDR
*FunctionTable
,
127 uint32 NumFunctionTable
,
129 CSSM_MODULE_HANDLE_PTR NewModuleHandle
)
132 Required(NewModuleHandle
) = gManager().getModule(Guid::required(ModuleGuid
))->attach(
134 SubserviceID
, SubServiceType
,
135 Required(MemoryFuncs
),
138 FunctionTable
, NumFunctionTable
144 CSSM_ModuleDetach (CSSM_MODULE_HANDLE ModuleHandle
)
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
156 CSSM_SetPrivilege (CSSM_PRIVILEGE Privilege
)
159 gManager().setPrivilege(Privilege
);
164 CSSM_GetPrivilege (CSSM_PRIVILEGE
*Privilege
)
167 Required(Privilege
) = gManager().getPrivilege();
173 CSSM_GetModuleGUIDFromHandle (CSSM_MODULE_HANDLE ModuleHandle
,
174 CSSM_GUID_PTR ModuleGUID
)
177 Attachment
&attachment
= findHandleAndLock
<Attachment
>(ModuleHandle
);
178 StLock
<Mutex
> _(attachment
, true);
179 Required(ModuleGUID
) = attachment
.module.myGuid();
184 CSSM_GetSubserviceUIDFromHandle (CSSM_MODULE_HANDLE ModuleHandle
,
185 CSSM_SUBSERVICE_UID_PTR SubserviceUID
)
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();
200 CSSM_ListAttachedModuleManagers (uint32
*NumberOfModuleManagers
,
204 *NumberOfModuleManagers
= 0; // EMMs not implemented
209 CSSM_GetAPIMemoryFunctions (CSSM_MODULE_HANDLE AddInHandle
,
210 CSSM_API_MEMORY_FUNCS_PTR AppMemoryFuncs
)
213 Attachment
&attachment
= findHandleAndLock
<Attachment
>(AddInHandle
);
214 StLock
<Mutex
> _(attachment
, true);
215 Required(AppMemoryFuncs
) = attachment
;