]> git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cssm/lib/modload_plugin.cpp
Security-57031.40.6.tar.gz
[apple/security.git] / Security / libsecurity_cssm / lib / modload_plugin.cpp
1 /*
2 * Copyright (c) 2000-2001,2003-2004,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // modload_plugin - loader interface for dynamically loaded plugin modules
27 //
28 #include "modload_plugin.h"
29
30
31 namespace Security {
32
33
34 //
35 // During construction, a LoadablePlugin loads itself into memory and locates
36 // the canonical (CDSA defined) four entrypoints. If anything fails, we throw.
37 //
38 LoadablePlugin::LoadablePlugin(const char *path) : LoadableBundle(path)
39 {
40 secdebug("cssm", "LoadablePlugin(%s)", path);
41 load();
42 }
43
44
45 //
46 // Loading and unloading devolves directly onto LoadableBundle
47 //
48 void LoadablePlugin::load()
49 {
50 secdebug("cssm", "LoadablePlugin::load() path %s", path().c_str());
51 LoadableBundle::load();
52 findFunction(mFunctions.load, "CSSM_SPI_ModuleLoad");
53 findFunction(mFunctions.attach, "CSSM_SPI_ModuleAttach");
54 findFunction(mFunctions.detach, "CSSM_SPI_ModuleDetach");
55 findFunction(mFunctions.unload, "CSSM_SPI_ModuleUnload");
56 }
57
58 void LoadablePlugin::unload()
59 {
60 secdebug("cssm", "LoadablePlugin::unload() path %s", path().c_str());
61 /* skipping for workaround for radar 3774226
62 LoadableBundle::unload(); */
63 }
64
65 bool LoadablePlugin::isLoaded() const
66 {
67 return LoadableBundle::isLoaded();
68 }
69
70
71 //
72 // Pass module entry points to the statically linked functions
73 //
74 CSSM_RETURN LoadablePlugin::load(const CSSM_GUID *CssmGuid,
75 const CSSM_GUID *ModuleGuid,
76 CSSM_SPI_ModuleEventHandler CssmNotifyCallback,
77 void *CssmNotifyCallbackCtx)
78 {
79 secdebug("cssm", "LoadablePlugin::load(guid,...) path %s", path().c_str());
80 return mFunctions.load(CssmGuid, ModuleGuid,
81 CssmNotifyCallback, CssmNotifyCallbackCtx);
82 }
83
84 CSSM_RETURN LoadablePlugin::unload(const CSSM_GUID *CssmGuid,
85 const CSSM_GUID *ModuleGuid,
86 CSSM_SPI_ModuleEventHandler CssmNotifyCallback,
87 void *CssmNotifyCallbackCtx)
88 {
89 secdebug("cssm", "LoadablePlugin::unload(guid,...) path %s", path().c_str());
90 return mFunctions.unload(CssmGuid, ModuleGuid,
91 CssmNotifyCallback, CssmNotifyCallbackCtx);
92 }
93
94 CSSM_RETURN LoadablePlugin::attach(const CSSM_GUID *ModuleGuid,
95 const CSSM_VERSION *Version,
96 uint32 SubserviceID,
97 CSSM_SERVICE_TYPE SubServiceType,
98 CSSM_ATTACH_FLAGS AttachFlags,
99 CSSM_MODULE_HANDLE ModuleHandle,
100 CSSM_KEY_HIERARCHY KeyHierarchy,
101 const CSSM_GUID *CssmGuid,
102 const CSSM_GUID *ModuleManagerGuid,
103 const CSSM_GUID *CallerGuid,
104 const CSSM_UPCALLS *Upcalls,
105 CSSM_MODULE_FUNCS_PTR *FuncTbl)
106 {
107 return mFunctions.attach(ModuleGuid, Version, SubserviceID, SubServiceType,
108 AttachFlags, ModuleHandle, KeyHierarchy, CssmGuid, ModuleManagerGuid,
109 CallerGuid, Upcalls, FuncTbl);
110 }
111
112 CSSM_RETURN LoadablePlugin::detach(CSSM_MODULE_HANDLE ModuleHandle)
113 {
114 return mFunctions.detach(ModuleHandle);
115 }
116
117
118 } // end namespace Security