/*----------------------------------------------------------------------- * File: DUMMY.C * * Copyright (c) 1995-2000 Intel Corporation. All rights reserved. *----------------------------------------------------------------------- */ /* * OpenVMS History * * 12-Sep-2002 Carol Kelly * o Merge in V3_14 changes * */ #ifdef WIN32 #pragma warning (disable:4201 4514 4214 4115) #include #include #pragma warning (default:4201 4214 4115) #ifdef _DEBUG #include #endif #endif #include "cssm.h" #include "guids.h" /* for guid definitions */ #include "cssmtype.h" #include "emmtype.h" #include "emmspi.h" #include "dummyapi.h" #include "dummyspi.h" #include "cssmerr.h" #include "guids.h" #include "mds_util_api.h" #include "mds_util_helper.h" #include "cssmport.h" #include "dummy_mds.h" #ifdef ISL_INCLUDED #include "callouts.h" #include "eislapi.h" #include "common.h" ISL_VERIFIED_MODULE_PTR* VerifiedCSSMModulePtrArr= NULL; uint32 NumSections = 0; char szFunctionName[128]; ISL_CONST_DATA ConstData; #endif CSSM_GUID dummyemm_guid_30 = intel_dummy_emm_guid_init; /* DUMMY EMM */ CSSM_STATE_FUNCS CssmStateFuncs; #ifndef ISL_INCLUDED CSSM_LIB_HANDLE g_cssmHandle; #endif CSSM_BOOL MDSUTILInitialized = CSSM_FALSE; #ifdef CSSM_MEMTRACK_ON void * CSSMAPI _dummy_malloc (uint32 size, void *AllocRef, const char * szFilename, uint32 u32LineNumber) { return _malloc_dbg(size, _NORMAL_BLOCK, szFilename, u32LineNumber); } void * CSSMAPI _dummy_realloc (void *Ptr, uint32 size, void *AllocRef, const char * szFilename, uint32 u32LineNumber) { return _realloc_dbg(Ptr, size, _NORMAL_BLOCK, szFilename, u32LineNumber); } void CSSMAPI _dummy_free (void *Ptr, void *AllocRef, const char * szFilename, uint32 u32LineNumber) { _free_dbg(Ptr, _NORMAL_BLOCK); } void * CSSMAPI _dummy_calloc (uint32 size, uint32 count, void* AllocRef, const char * szFilename, uint32 u32LineNumber) { return _calloc_dbg(size, count, _NORMAL_BLOCK, szFilename, u32LineNumber); } #else void * CSSMAPI _dummy_malloc (uint32 size, void *AllocRef) { return malloc( size ); } void * CSSMAPI _dummy_realloc (void *Ptr, uint32 size, void *AllocRef) { return realloc(Ptr, size); } void CSSMAPI _dummy_free (void *Ptr, void *AllocRef) { free(Ptr); } void * CSSMAPI _dummy_calloc (uint32 size, uint32 count, void* AllocRefr) { return calloc(size, count ); } #endif CSSM_API_MEMORY_FUNCS MemoryFuncs = { _dummy_malloc, _dummy_free, _dummy_realloc, _dummy_calloc, NULL }; CSSM_RETURN CSSMAPI DummyEmm_Passthru(CSSM_MODULE_HANDLE hAddIn, CSSM_SERVICE_MASK ServiceMask) { EMM_SPI_DUMMY_FUNCS_PTR DummyFuncsPtr; CSSM_RETURN ret; void* Callback = NULL; CSSM_BOOL bIsOk = CSSM_TRUE; //MessageBox( NULL,"DummyEmm:Passthru","DUMMY EMM",MB_OK); #ifndef ISL_INCLUDED CSSM_PROC_ADDR retAddress = NULL; if( g_cssmHandle == NULL ) return CSSMERR_CSSM_INTERNAL_ERROR; #endif #ifdef ISL_INCLUDED /* now we get the return address */ ISL_FUNCTION_PTR retAddress = NULL; EISL_GetReturnAddress(retAddress); /* If some body linked to emm and not called AddinAttcahe, so that ModuleManagerAuthenticate did not happen and CSSM verify did not happen*/ if(VerifiedCSSMModulePtrArr == NULL) { return CSSMERR_CSSM_INTERNAL_ERROR; } #endif /* EMM should call cssm_IsFuncCallValid if we need to do a check of the caller or check the function pointer to be within the verified module*/ ret = CssmStateFuncs.cssm_GetAttachFunctions( hAddIn,ServiceMask,&Callback, NULL); if(ret == CSSM_OK && Callback != NULL) { DummyFuncsPtr = (EMM_SPI_DUMMY_FUNCS_PTR)Callback; if(!IsBadCodePtr((CSSM_PROC_ADDR)DummyFuncsPtr->PassThrough)) { ret = CssmStateFuncs.cssm_IsFuncCallValid(hAddIn, (CSSM_PROC_ADDR)retAddress, #ifdef __arch64__ (CSSM_PROC_ADDR)(*(void **)DummyFuncsPtr->PassThrough), #else (CSSM_PROC_ADDR)DummyFuncsPtr->PassThrough, #endif 0, /* no privilege */ NULL, /* don't need privilege */ 0, /* no hints */ &bIsOk); if( ret == CSSM_OK && bIsOk ) { ret = DummyFuncsPtr->PassThrough(hAddIn,ServiceMask); } } else { ret = DUMMY_EMM_FUNCTION_NOT_IMPLEMENTED; } CssmStateFuncs.cssm_ReleaseAttachFunctions ( hAddIn); } return ret; } CSSM_RETURN CSSMAPI DummyEmm_Passthru1(CSSM_MODULE_HANDLE hAddIn, CSSM_SERVICE_MASK ServiceMask) { EMM_SPI_DUMMY_FUNCS_PTR DummyFuncsPtr; CSSM_RETURN ret; void* Callback = NULL; CSSM_BOOL bIsOk=CSSM_TRUE; //MessageBox( NULL,"DummyEmm:Passthru1","DUMMY EMM",MB_OK); #ifndef ISL_INCLUDED CSSM_PROC_ADDR retAddress = NULL; /* dummy for parameter passing */ if( g_cssmHandle == NULL ) return CSSMERR_CSSM_INTERNAL_ERROR; #endif #ifdef ISL_INCLUDED /* now we get the return address */ ISL_FUNCTION_PTR retAddress = NULL; EISL_GetReturnAddress(retAddress); /* If some body linked to emm and not called AddinAttcahe, so that ModuleManagerAuthenticate did not happen and CSSM verify did not happen*/ if(VerifiedCSSMModulePtrArr == NULL) { return CSSMERR_CSSM_INTERNAL_ERROR; } #endif ret = CssmStateFuncs.cssm_GetAttachFunctions( hAddIn,ServiceMask,&Callback, NULL); if(ret == CSSM_OK && Callback != NULL) { DummyFuncsPtr = (EMM_SPI_DUMMY_FUNCS_PTR)Callback; if(!IsBadCodePtr((CSSM_PROC_ADDR)DummyFuncsPtr->PassThrough1)) { ret = CssmStateFuncs.cssm_IsFuncCallValid(hAddIn, (CSSM_PROC_ADDR)retAddress, #ifdef __arch64__ (CSSM_PROC_ADDR)(*(void **)DummyFuncsPtr->PassThrough1), #else (CSSM_PROC_ADDR)DummyFuncsPtr->PassThrough1, #endif 0, /* no privilege */ NULL, /* don't need privilege */ 0, /* no hints */ &bIsOk); if( ret == CSSM_OK && bIsOk ) { ret = DummyFuncsPtr->PassThrough1(hAddIn,ServiceMask); } } else { ret = DUMMY_EMM_FUNCTION_NOT_IMPLEMENTED; } CssmStateFuncs.cssm_ReleaseAttachFunctions ( hAddIn); } return ret; } /*--------------------------------------------------------------- * *Name: Initialize * *Description: * Require function that CSSM calls during the attach process for * checking the compatibilty of the version of the TP requested. * *Parameters: * VerMajor (input) - Major version of the TP requested * VerMinor (input) - Minor version of the TP requested * *Returns: * CSSM_FAIL - versions are not compatible * CSSM_OK - versions are compatible * *-------------------------------------------------------------*/ CSSM_RETURN CSSMAPI Initialize (uint32 VerMajor, uint32 VerMinor) { #ifdef ISL_INCLUDED /* DLL is attaching to the address space of the current process. */ ISL_VERIFIED_MODULE_PTR VerifiedDummyModulePtr = NULL; VerifiedDummyModulePtr = EISL_SelfCheck(); if(VerifiedDummyModulePtr == NULL) { #ifdef _DEBUG OutputDebugString("EMM::EISL_SelfCheck() Failed\n"); #endif return CSSM_FALSE; } EISL_RecycleVerifiedModuleCredentials(VerifiedDummyModulePtr); #endif return (CSSM_OK); } /*--------------------------------------------------------------- * *Name: Terminate * *Description: * Require function that CSSM calls during the detach process. * *Parameters: * None * *Returns: * CSSM_FAIL - Don't free library * CSSM_OK - OK to free the library * *-------------------------------------------------------------*/ CSSM_RETURN CSSMAPI Terminate (void) { #ifdef ISL_INCLUDED if(VerifiedCSSMModulePtrArr != NULL) { cssm_FreeVerifiedCredentials( VerifiedCSSMModulePtrArr, NumSections); dummy_free(VerifiedCSSMModulePtrArr, 0); } #endif if( MDSUTILInitialized) { MDSUTIL_Term(); MDSUTILInitialized = CSSM_FALSE; } return (CSSM_OK); } /* this function is called from CSSM after ModuleManagerAuthenticate, to pass cssm internal dat structure to emm*/ CSSM_RETURN CSSMAPI RegisterDispatchTable ( CSSM_STATE_FUNCS_PTR CssmStateCallTable) { CssmStateFuncs.cssm_GetAttachFunctions = CssmStateCallTable->cssm_GetAttachFunctions; CssmStateFuncs.cssm_ReleaseAttachFunctions = CssmStateCallTable->cssm_ReleaseAttachFunctions; CssmStateFuncs.cssm_GetAppMemoryFunctions = CssmStateCallTable->cssm_GetAppMemoryFunctions; CssmStateFuncs.cssm_IsFuncCallValid = CssmStateCallTable->cssm_IsFuncCallValid; CssmStateFuncs.cssm_DeregisterManagerServices = CssmStateCallTable->cssm_DeregisterManagerServices; CssmStateFuncs.cssm_DeliverModuleManagerEvent = CssmStateCallTable->cssm_DeliverModuleManagerEvent; return CSSM_OK; } CSSM_RETURN CSSMAPI DeregisterDispatchTable (void) { return CSSM_OK; } CSSM_RETURN CSSMAPI EventNotifyManager (const CSSM_MANAGER_EVENT_NOTIFICATION* EventDescription) { switch (EventDescription->Event) { case CSSM_MANAGER_SERVICE_REQUEST: return CSSM_MANAGER_SERVICE_REQUEST; case CSSM_MANAGER_REPLY: return CSSM_MANAGER_REPLY; default: return 0; } } CSSM_RETURN CSSMAPI RefreshFunctionTable(CSSM_FUNC_NAME_ADDR_PTR FuncNameAddrPtr, uint32 NumOfFuncNameAddr) { uint32 i; if(FuncNameAddrPtr != NULL) { for(i=0;iInitialize = Initialize; FunctionTable->Terminate = Terminate; FunctionTable->RegisterDispatchTable = RegisterDispatchTable; FunctionTable->DeregisterDispatchTable = DeregisterDispatchTable; FunctionTable->EventNotifyManager = EventNotifyManager; FunctionTable->RefreshFunctionTable = RefreshFunctionTable; } szCSSMPath; return CSSM_OK; } #if defined (LINUX) static int _init() __attribute__ ((constructor)); static int _fini() __attribute__ ((destructor)); #endif #if defined (UNIX) int _init() { } int _fini() { } #endif #ifdef WIN32 /*--------------------------------------------------------------- * *Name: DllMain * *Description: * Entry point for the DLL. * *Parameters: * hInstance (input) - Instance handle of calling process * dwReason (input) - Reasons for receiving this call * lpReserved (input) - Reserved field * *Returns: * FALSE - unable to initialize DLL. This will cause the LoadLibrary * call to fail. * TRUE - DLL is initialize and ready to be called * *-------------------------------------------------------------*/ BOOL WINAPI DllMain (HANDLE hInstance, DWORD dwReason, LPVOID lpReserved) { switch (dwReason) { case DLL_PROCESS_ATTACH: { #ifdef _DEBUG OutputDebugString("In Dummy Emm Process Attach"); #endif break; } case DLL_THREAD_ATTACH: /* A new thread is being created in the current process. */ #ifdef _DEBUG OutputDebugString("In Dummy Emm thread attach"); #endif break; case DLL_THREAD_DETACH: #ifdef _DEBUG OutputDebugString("In Dummy Emm thread Detach"); #endif break; case DLL_PROCESS_DETACH: { /* The calling process is detaching the DLL */ #ifdef _DEBUG OutputDebugString("In Dummy Emm Process Detach"); #endif break; } } return TRUE; } #endif /* WIN32 */