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 // modload_plugin - loader interface for dynamically loaded plugin modules
28 #include "modload_plugin.h"
29 #include <security_cdsa_utilities/cssmerrors.h>
36 // During construction, a LoadablePlugin loads itself into memory and locates
37 // the canonical (CDSA defined) four entrypoints. If anything fails, we throw.
39 LoadablePlugin::LoadablePlugin(const char *path
) : LoadableBundle(path
)
41 secinfo("cssm", "LoadablePlugin(%s)", path
);
42 if (!allowableModulePath(path
)) {
43 secinfo("cssm", "LoadablePlugin(): not loaded; plugin in non-standard location: %s", path
);
44 CssmError::throwMe(CSSMERR_CSSM_ADDIN_AUTHENTICATE_FAILED
);
51 // Loading and unloading devolves directly onto LoadableBundle
53 void LoadablePlugin::load()
55 secinfo("cssm", "LoadablePlugin::load() path %s", path().c_str());
56 LoadableBundle::load();
57 findFunction(mFunctions
.load
, "CSSM_SPI_ModuleLoad");
58 findFunction(mFunctions
.attach
, "CSSM_SPI_ModuleAttach");
59 findFunction(mFunctions
.detach
, "CSSM_SPI_ModuleDetach");
60 findFunction(mFunctions
.unload
, "CSSM_SPI_ModuleUnload");
63 void LoadablePlugin::unload()
65 secinfo("cssm", "LoadablePlugin::unload() path %s", path().c_str());
66 /* skipping for workaround for radar 3774226
67 LoadableBundle::unload(); */
70 bool LoadablePlugin::isLoaded() const
72 return LoadableBundle::isLoaded();
77 // Pass module entry points to the statically linked functions
79 CSSM_RETURN
LoadablePlugin::load(const CSSM_GUID
*CssmGuid
,
80 const CSSM_GUID
*ModuleGuid
,
81 CSSM_SPI_ModuleEventHandler CssmNotifyCallback
,
82 void *CssmNotifyCallbackCtx
)
84 secinfo("cssm", "LoadablePlugin::load(guid,...) path %s", path().c_str());
85 return mFunctions
.load(CssmGuid
, ModuleGuid
,
86 CssmNotifyCallback
, CssmNotifyCallbackCtx
);
89 CSSM_RETURN
LoadablePlugin::unload(const CSSM_GUID
*CssmGuid
,
90 const CSSM_GUID
*ModuleGuid
,
91 CSSM_SPI_ModuleEventHandler CssmNotifyCallback
,
92 void *CssmNotifyCallbackCtx
)
94 secinfo("cssm", "LoadablePlugin::unload(guid,...) path %s", path().c_str());
95 return mFunctions
.unload(CssmGuid
, ModuleGuid
,
96 CssmNotifyCallback
, CssmNotifyCallbackCtx
);
99 CSSM_RETURN
LoadablePlugin::attach(const CSSM_GUID
*ModuleGuid
,
100 const CSSM_VERSION
*Version
,
102 CSSM_SERVICE_TYPE SubServiceType
,
103 CSSM_ATTACH_FLAGS AttachFlags
,
104 CSSM_MODULE_HANDLE ModuleHandle
,
105 CSSM_KEY_HIERARCHY KeyHierarchy
,
106 const CSSM_GUID
*CssmGuid
,
107 const CSSM_GUID
*ModuleManagerGuid
,
108 const CSSM_GUID
*CallerGuid
,
109 const CSSM_UPCALLS
*Upcalls
,
110 CSSM_MODULE_FUNCS_PTR
*FuncTbl
)
112 return mFunctions
.attach(ModuleGuid
, Version
, SubserviceID
, SubServiceType
,
113 AttachFlags
, ModuleHandle
, KeyHierarchy
, CssmGuid
, ModuleManagerGuid
,
114 CallerGuid
, Upcalls
, FuncTbl
);
117 CSSM_RETURN
LoadablePlugin::detach(CSSM_MODULE_HANDLE ModuleHandle
)
119 return mFunctions
.detach(ModuleHandle
);
122 bool LoadablePlugin::allowableModulePath(const char *path
) {
123 // True if module path is in default location
124 const char *loadablePrefix
="/System/Library/Security/";
125 return (strncmp(loadablePrefix
,path
,strlen(loadablePrefix
)) == 0);
128 } // end namespace Security