/*----------------------------------------------------------------------- * File: MODINSTALL.C * * Copyright (c) 1995-2000 Intel Corporation. All rights reserved. *----------------------------------------------------------------------- */ #include #include #include "cssm.h" #include "cssmerr.h" #include "cssmport.h" #include "cssmlock.h" #include "dmyemmtype.h" #include "maf_collectn.h" #include "maf_util.h" #include "guids.h" #include "mds.h" #include "mds_schema.h" #include "mds_util.h" #ifdef VMS #include "installdefs.h" #else #include "intel/installdefs.h" #endif /* Number of MDS update operations that will be remembered by mds_util for * error clean-up during installation. */ #define EMM_MDS_COMMIT_SIZE 150 const CSSM_GUID EMM_GUID = intel_dummy_emm_guid_init; extern const CSSM_API_MEMORY_FUNCS MemoryFuncs; static CSSM_RETURN __CleanMDS( MDSU_CONTEXT *pContext ) { CSSM_RETURN rv = CSSM_OK; MDSU_CDSA_EMM_SCHEMA EmmTemplate; MDSU_CDSA_EMM_SCHEMA EmmData; /* Execute a search on the EMM record type to get a handle of all * records and then delete them. */ /* EMM Schema */ EmmTemplate.ModuleID = EMM_GUID; rv = MDSU_FindFirst( pContext, &IfiMdsuCdsadirEMMSchema, &EmmTemplate, MDSU_EMM_MODULE_ID, &EmmData, NULL ); while ( rv == CSSM_OK ) { if ( EmmData.Manifest.Data ) { MDSU_free( pContext, EmmData.Manifest.Data ); } rv = MDSU_FindNext( pContext, &EmmData, NULL ); } if ( rv == CSSMERR_DL_ENDOFDATA ) { /* Flush everything from the MDS */ rv = MDSU_Revert( pContext ); } /* Make sure nothing gets removed if there is an error */ if ( ( rv != CSSMERR_DL_ENDOFDATA ) && ( rv != CSSM_OK ) ) { MDSU_Commit( pContext ); } return rv; } CSSM_RETURN CSSMAPI INSTALL_ENTRY_NAME( const char *szModuleName, const char *szSearchPath, CSSM_DATA *pCredential, INSTALL_ACTION Action, INSTALL_ERROR *pError ) { CSSM_RETURN rv = CSSM_OK; MDSU_CONTEXT MDSUContext; MDSU_CDSA_EMM_SCHEMA Emm; /* Initialize the MDS update */ if ( ( rv = MDSU_Init( &MDSUContext, &MemoryFuncs, &EMM_GUID, MDS_CDSA_DIRECTORY, ( CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE ), EMM_MDS_COMMIT_SIZE ) ) != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (Init): %X\n", rv ); pError->ErrorCode = rv; return rv; } if ( ( rv = __CleanMDS( &MDSUContext ) ) != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (Clean): %X\n", rv ); pError->ErrorCode = rv; MDSU_Term( &MDSUContext ); return rv; } if ( Action == INSTALL_ACTION_UNINSTALL ) { MDSU_Term( &MDSUContext ); return rv; } /* Fill in the emm schema structure */ memcpy( &Emm.ModuleID, &EMM_GUID, sizeof(CSSM_GUID) ); Emm.Manifest = *pCredential; strcpy( Emm.ModuleName, szModuleName ); strcpy( Emm.Path, szSearchPath ); Emm.CDSAVersion.Major = CSSM_MAJOR; Emm.CDSAVersion.Minor = CSSM_MINOR; Emm.EmmSpecVersion.Major = 2; Emm.EmmSpecVersion.Minor = 0; strcpy( Emm.Desc, "Intel Dummy EMM Module" ); Emm.PolicyStmt.Length = 0; Emm.PolicyStmt.Data = NULL; Emm.EmmVersion.Major = INTEL_DUMMY_EMM_MAJOR_VER; Emm.EmmVersion.Minor = INTEL_DUMMY_EMM_MINOR_VER; strcpy( Emm.EmmVendor, "Intel Corporation" ); Emm.EmmType = CSSM_SERVICE_EMM_DUMMY; /* Insert the EMM schema record into the MDS */ rv = MDSU_UpdateSchema( &MDSUContext, &IfiMdsuCdsadirEMMSchema, &Emm, NULL ); if ( rv != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (EMM): %X\n", rv ); pError->ErrorCode = rv; MDSU_Term( &MDSUContext ); return rv; } /* Commit the records */ MDSU_Commit( &MDSUContext ); /* Shut down the MDS connection */ MDSU_Term( &MDSUContext ); return CSSM_OK; }