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 #include <security_cdsa_utilities/cssmerrors.h> 30 31 32 namespace Security { 33 34 35 // 36 // During construction, a LoadablePlugin loads itself into memory and locates 37 // the canonical (CDSA defined) four entrypoints. If anything fails, we throw. 38 // 39 LoadablePlugin::LoadablePlugin(const char *path) : LoadableBundle(path) 40 { 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); 45 } 46 load(); 47 } 48 49 50 // 51 // Loading and unloading devolves directly onto LoadableBundle 52 // 53 void LoadablePlugin::load() 54 { 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"); 61 } 62 63 void LoadablePlugin::unload() 64 { 65 secinfo("cssm", "LoadablePlugin::unload() path %s", path().c_str()); 66 /* skipping for workaround for radar 3774226 67 LoadableBundle::unload(); */ 68 } 69 70 bool LoadablePlugin::isLoaded() const 71 { 72 return LoadableBundle::isLoaded(); 73 } 74 75 76 // 77 // Pass module entry points to the statically linked functions 78 // 79 CSSM_RETURN LoadablePlugin::load(const CSSM_GUID *CssmGuid, 80 const CSSM_GUID *ModuleGuid, 81 CSSM_SPI_ModuleEventHandler CssmNotifyCallback, 82 void *CssmNotifyCallbackCtx) 83 { 84 secinfo("cssm", "LoadablePlugin::load(guid,...) path %s", path().c_str()); 85 return mFunctions.load(CssmGuid, ModuleGuid, 86 CssmNotifyCallback, CssmNotifyCallbackCtx); 87 } 88 89 CSSM_RETURN LoadablePlugin::unload(const CSSM_GUID *CssmGuid, 90 const CSSM_GUID *ModuleGuid, 91 CSSM_SPI_ModuleEventHandler CssmNotifyCallback, 92 void *CssmNotifyCallbackCtx) 93 { 94 secinfo("cssm", "LoadablePlugin::unload(guid,...) path %s", path().c_str()); 95 return mFunctions.unload(CssmGuid, ModuleGuid, 96 CssmNotifyCallback, CssmNotifyCallbackCtx); 97 } 98 99 CSSM_RETURN LoadablePlugin::attach(const CSSM_GUID *ModuleGuid, 100 const CSSM_VERSION *Version, 101 uint32 SubserviceID, 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) 111 { 112 return mFunctions.attach(ModuleGuid, Version, SubserviceID, SubServiceType, 113 AttachFlags, ModuleHandle, KeyHierarchy, CssmGuid, ModuleManagerGuid, 114 CallerGuid, Upcalls, FuncTbl); 115 } 116 117 CSSM_RETURN LoadablePlugin::detach(CSSM_MODULE_HANDLE ModuleHandle) 118 { 119 return mFunctions.detach(ModuleHandle); 120 } 121 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); 126 } 127 128 } // end namespace Security