2 * Copyright (c) 2000-2001,2003-2004,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // This file contains the core CSSM public functions.
27 // Note that hardly anything happens in here; we just hand off requests
28 // to the various objects representing CSSM state.
32 #include <security_utilities/globalizer.h>
33 #include <security_cdsa_utilities/cssmbridge.h>
34 #include "LegacyAPICounts.h"
37 // We currently use exactly one instance of CssmManager.
39 static ModuleNexus
<CssmManager
> gManager
;
43 // Public API: (Re)Intiailize CSSM
46 CSSM_Init (const CSSM_VERSION
*Version
,
47 CSSM_PRIVILEGE_SCOPE Scope
,
48 const CSSM_GUID
*CallerGuid
,
49 CSSM_KEY_HIERARCHY KeyHierarchy
,
50 CSSM_PVC_MODE
*PvcPolicy
,
54 gManager().initialize(Required(Version
),
56 Guid::required(CallerGuid
),
64 // Public API: Terminate CSSM.
70 gManager().terminate();
76 // Public API: Load a CSSM module
79 CSSM_ModuleLoad (const CSSM_GUID
*ModuleGuid
,
80 CSSM_KEY_HIERARCHY KeyHierarchy
,
81 CSSM_API_ModuleEventHandler AppNotifyCallback
,
82 void *AppNotifyCallbackCtx
)
85 gManager().loadModule(Guid::required(ModuleGuid
),
87 ModuleCallback(AppNotifyCallback
, AppNotifyCallbackCtx
));
93 // Public API: Unload a module
96 CSSM_ModuleUnload (const CSSM_GUID
*ModuleGuid
,
97 CSSM_API_ModuleEventHandler AppNotifyCallback
,
98 void *AppNotifyCallbackCtx
)
101 gManager().unloadModule(Guid::required(ModuleGuid
),
102 ModuleCallback(AppNotifyCallback
, AppNotifyCallbackCtx
));
108 CSSM_Introduce (const CSSM_GUID
*ModuleID
,
109 CSSM_KEY_HIERARCHY KeyHierarchy
)
112 gManager().introduce(Guid::required(ModuleID
), KeyHierarchy
);
117 CSSM_Unintroduce (const CSSM_GUID
*ModuleID
)
120 gManager().unIntroduce(Guid::required(ModuleID
));
126 CSSM_ModuleAttach (const CSSM_GUID
*ModuleGuid
,
127 const CSSM_VERSION
*Version
,
128 const CSSM_API_MEMORY_FUNCS
*MemoryFuncs
,
130 CSSM_SERVICE_TYPE SubServiceType
,
131 CSSM_ATTACH_FLAGS AttachFlags
,
132 CSSM_KEY_HIERARCHY KeyHierarchy
,
133 CSSM_FUNC_NAME_ADDR
*FunctionTable
,
134 uint32 NumFunctionTable
,
136 CSSM_MODULE_HANDLE_PTR NewModuleHandle
)
139 Required(NewModuleHandle
) = gManager().getModule(Guid::required(ModuleGuid
))->attach(
141 SubserviceID
, SubServiceType
,
142 Required(MemoryFuncs
),
145 FunctionTable
, NumFunctionTable
151 CSSM_ModuleDetach (CSSM_MODULE_HANDLE ModuleHandle
)
154 Attachment
*attachment
= &HandleObject::findAndKill
<Attachment
>(ModuleHandle
, CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
155 attachment
->detach(true); // expect locked, will unlock
156 // the attachment is now off the maps, known idle, and unhooked
163 CSSM_SetPrivilege (CSSM_PRIVILEGE Privilege
)
166 gManager().setPrivilege(Privilege
);
171 CSSM_GetPrivilege (CSSM_PRIVILEGE
*Privilege
)
174 Required(Privilege
) = gManager().getPrivilege();
180 CSSM_GetModuleGUIDFromHandle (CSSM_MODULE_HANDLE ModuleHandle
,
181 CSSM_GUID_PTR ModuleGUID
)
184 Attachment
&attachment
= HandleObject::findAndLock
<Attachment
>(ModuleHandle
, CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
185 StLock
<Mutex
> _(attachment
, true);
186 Required(ModuleGUID
) = attachment
.module.myGuid();
191 CSSM_GetSubserviceUIDFromHandle (CSSM_MODULE_HANDLE ModuleHandle
,
192 CSSM_SUBSERVICE_UID_PTR SubserviceUID
)
195 Attachment
&attachment
= HandleObject::findAndLock
<Attachment
>(ModuleHandle
, CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
196 StLock
<Mutex
> _(attachment
, true);
197 CSSM_SUBSERVICE_UID
&result
= Required(SubserviceUID
);
198 result
.Guid
= attachment
.module.myGuid();
199 result
.Version
= attachment
.pluginVersion();
200 result
.SubserviceId
= attachment
.subserviceId();
201 result
.SubserviceType
= attachment
.subserviceType();
207 CSSM_ListAttachedModuleManagers (uint32
*NumberOfModuleManagers
,
211 *NumberOfModuleManagers
= 0; // EMMs not implemented
216 CSSM_GetAPIMemoryFunctions (CSSM_MODULE_HANDLE AddInHandle
,
217 CSSM_API_MEMORY_FUNCS_PTR AppMemoryFuncs
)
220 Attachment
&attachment
= HandleObject::findAndLock
<Attachment
>(AddInHandle
, CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
221 StLock
<Mutex
> _(attachment
, true);
222 Required(AppMemoryFuncs
) = attachment
;