1/* 2 * Copyright (c) 2004 Apple Computer, 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 * attachCommon.cpp - attach/detach to/from arbitrary module 26 */ 27 28#include "attachCommon.h" 29#include <Security/Security.h> 30 31/* SPI; the framework actually contains a static lib we link against */ 32#include <security_cdsa_utils/cuCdsaUtils.h> 33 34static CSSM_VERSION vers = {2, 0}; 35static const CSSM_GUID dummyGuid = { 0xFADE, 0, 0, { 1,2,3,4,5,6,7,0 }}; 36 37static CSSM_API_MEMORY_FUNCS memFuncs = { 38 cuAppMalloc, 39 cuAppFree, 40 cuAppRealloc, 41 cuAppCalloc, 42 NULL 43}; 44 45/* load & attach; returns 0 on error */ 46CSSM_HANDLE attachCommon( 47 const CSSM_GUID *guid, 48 uint32 subserviceFlags) // CSSM_SERVICE_TP, etc. 49{ 50 CSSM_HANDLE hand; 51 CSSM_RETURN crtn; 52 53 if(cuCssmStartup() == CSSM_FALSE) { 54 return 0; 55 } 56 crtn = CSSM_ModuleLoad(guid, 57 CSSM_KEY_HIERARCHY_NONE, 58 NULL, // eventHandler 59 NULL); // AppNotifyCallbackCtx 60 if(crtn) { 61 cssmPerror("CSSM_ModuleLoad()", crtn); 62 return 0; 63 } 64 crtn = CSSM_ModuleAttach (guid, 65 &vers, 66 &memFuncs, // memFuncs 67 0, // SubserviceID 68 subserviceFlags, // SubserviceFlags 69 0, // AttachFlags 70 CSSM_KEY_HIERARCHY_NONE, 71 NULL, // FunctionTable 72 0, // NumFuncTable 73 NULL, // reserved 74 &hand); 75 if(crtn) { 76 cssmPerror("CSSM_ModuleAttach()", crtn); 77 return 0; 78 } 79 else { 80 return hand; 81 } 82} 83 84/* detach & unload */ 85void detachCommon( 86 const CSSM_GUID *guid, 87 CSSM_HANDLE hand) 88{ 89 CSSM_RETURN crtn = CSSM_ModuleDetach(hand); 90 if(crtn) { 91 return; 92 } 93 CSSM_ModuleUnload(guid, NULL, NULL); 94} 95 96 97