/*----------------------------------------------------------------------- * File: MODINSTALL.C * * Copyright (c) 1995-2000 Intel Corporation. All rights reserved. *----------------------------------------------------------------------- */ #include #include #include "maf_include.h" #ifdef VMS #include "installdefs.h" #else #include "intel/installdefs.h" #endif #include "mds.h" #include "mds_schema.h" #include "mds_util.h" #define STUBCSP_MDS_COMMIT_SIZE (250) /* Capability group code markers for run-time processor function __CalcGCodes */ #define NEW_CAP ( 1 ) #define CAP_ATTR ( 0 ) /* Generic attribute declaration macros */ /* Use to indicate the start of a new capability */ #undef DECLARE_CAP #define DECLARE_CAP( _usee_, _cctype_, _algid_, _attr_, _val_, _desc_ ) \ { ADDIN_GUID_INITIALIZER, \ ADDIN_CSP_SUBSERVICE_ID, \ CSSM_USEE_##_usee_, \ CSSM_ALGCLASS_##_cctype_, \ CSSM_ALGID_##_algid_, \ NEW_CAP, \ CSSM_ATTRIBUTE_##_attr_, \ _val_, _desc_ } /* Use to indicate addition of another attribute to the current capability */ #undef DECLARE_ATR #define DECLARE_ATR( _usee_, _cctype_, _algid_, _attr_, _val_, _desc_ ) \ { ADDIN_GUID_INITIALIZER, \ ADDIN_CSP_SUBSERVICE_ID, \ CSSM_USEE_##_usee_, \ CSSM_ALGCLASS_##_cctype_, \ CSSM_ALGID_##_algid_, \ CAP_ATTR, \ CSSM_ATTRIBUTE_##_attr_, \ _val_, _desc_ } /* Macro to create the initializer for a single value attribute */ #define SINGLE_VAL( _val_ ) \ { _val_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 1 /* Macro to create the initializer for an algorithm ID value attribute */ #define ALGID_VAL( _val_ ) \ { CSSM_ALGID_##_val_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 1 /* Macro to create the initilizer for a range value attribute */ #define RANGE_VAL( _min_, _max_ ) \ { _min_, _max_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 2 /* Macro to create the initilizer for an algorithm mode value attribute */ #define MODE_VAL( _mode_ ) \ { CSSM_ALGMODE_##_mode_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 1 /* Macro to create the initilizer for an algorithm mode value attribute */ #define PADDING_VAL( _mode_ ) \ { CSSM_PADDING_##_mode_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 1 /* Static capability table listing the attributes that need to be inserted * into the MDS. */ static MDSU_CDSA_CSP_CAPABILITY_SCHEMA CapabilityTable[] = { /* USEE AlgClass AlgID Attribute Attribute Value Description */ /* Example Capability */ DECLARE_CAP( NONE, RANDOMGEN, NONE, BLOCK_SIZE, SINGLE_VAL( 1 ), "Example capability starter attribue" ), DECLARE_ATR( NONE, RANDOMGEN, NONE, OUTPUT_SIZE, SINGLE_VAL( 1 ), "Example additional capability attribute" ) }; static const uint32 CapabilityTableSize = sizeof(CapabilityTable) / sizeof(MDSU_CDSA_CSP_CAPABILITY_SCHEMA); /* Perform run-time calculation of group codes. */ static void __CalcGCodes() { uint32 uGCode = (uint32)-1; /* Cause first increment to rollover to zero */ uint32 i; /* Iterate through the capability array and set the appropriate group codes. */ for ( i = 0; i < CapabilityTableSize; i++ ) { if ( CapabilityTable[i].GroupId == NEW_CAP ) { uGCode++; } CapabilityTable[i].GroupId = uGCode; } } static CSSM_RETURN __CleanMDS( MDSU_CONTEXT *pContext ) { CSSM_RETURN rv = CSSM_OK; MDSU_CDSA_COMMON_SCHEMA CommonTemplate; MDSU_CDSA_COMMON_SCHEMA CommonData; MDSU_CDSA_CSP_PRIMARY_SCHEMA CSPPrimaryTemplate; MDSU_CDSA_CSP_PRIMARY_SCHEMA CSPPrimaryData; MDSU_CDSA_CSP_ENC_PRODUCT_SCHEMA CSPEncProdTemplate; MDSU_CDSA_CSP_ENC_PRODUCT_SCHEMA CSPEncProdData; MDSU_CDSA_CSP_CAPABILITY_SCHEMA CSPCapabilityTemplate; MDSU_CDSA_CSP_CAPABILITY_SCHEMA CSPCapabilityData; /* Execute a search on every CSP record type to get a handle of all * records and then delete them. */ /* Common Schema */ CommonTemplate.ModuleID = ADDIN_GUID; rv = MDSU_FindFirst( pContext, &IfiMdsuCdsadirCommonSchema, &CommonTemplate, MDSU_COM_MODULE_ID, &CommonData, NULL ); while ( rv == CSSM_OK ) { if ( CommonData.Manifest.Data ) { MDSU_free( pContext, CommonData.Manifest.Data ); } rv = MDSU_FindNext( pContext, &CommonData, NULL ); } if ( rv == CSSMERR_DL_ENDOFDATA ) { /* CSP Primary Schema */ CSPPrimaryTemplate.ModuleID = ADDIN_GUID; rv = MDSU_FindFirst( pContext, &IfiMdsuCdsadirCSPPrimarySchema, &CSPPrimaryTemplate, MDSU_CSPP_MODULE_ID, &CSPPrimaryData, NULL ); while ( rv == CSSM_OK ) { if ( CSPPrimaryData.Manifest.Data ) { MDSU_free( pContext, CSPPrimaryData.Manifest.Data ); } rv = MDSU_FindNext( pContext, &CSPPrimaryData, NULL ); } if ( rv == CSSMERR_DL_ENDOFDATA ) { /* CSP Encapsulated Product Schema */ CSPEncProdTemplate.ModuleID = ADDIN_GUID; rv = MDSU_FindFirst( pContext, &IfiMdsuCdsadirCSPEncProductSchema, &CSPEncProdTemplate, MDSU_CSPEP_MODULE_ID, &CSPEncProdData, NULL ); while ( rv == CSSM_OK ) { rv = MDSU_FindNext( pContext, &CSPEncProdData, NULL ); } if ( rv == CSSMERR_DL_ENDOFDATA ) { /* CSP Capability Schema */ CSPCapabilityTemplate.ModuleID = ADDIN_GUID; rv = MDSU_FindFirst( pContext, &IfiMdsuCdsadirCSPCapabilitySchema, &CSPCapabilityTemplate, MDSU_CSPCAP_MODULE_ID, &CSPCapabilityData, NULL ); while ( rv == CSSM_OK ) { rv = MDSU_FindNext( pContext, &CSPCapabilityData, NULL ); } if ( rv == CSSMERR_DL_ENDOFDATA ) { /* Flush everything from the MDS */ rv = MDSU_Revert( pContext ); } /* CSP Capability removed */ } /* CSP Encapsulated Product removed */ } /* CSP Primary removed */ } /* Common removed */ /* 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_COMMON_SCHEMA Common; MDSU_CDSA_CSP_PRIMARY_SCHEMA CSPPrimary; MDSU_CDSA_CSP_ENC_PRODUCT_SCHEMA CSPEncProduct; uint32 i; /* Calculate the group codes for the capability table */ __CalcGCodes(); /* Initialize the MDS update */ if ( ( rv = MDSU_Init( &MDSUContext, &Addin_APIMemFuncs, &ADDIN_GUID, MDS_CDSA_DIRECTORY, ( CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE ), STUBCSP_MDS_COMMIT_SIZE ) ) != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (Init): %X\n", rv ); pError->ErrorCode = rv; return rv; } /* Place code to remove existing entries here */ 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 "easy" common schema structure */ memcpy( &Common.ModuleID, &ADDIN_GUID, sizeof(ADDIN_GUID) ); Common.Manifest = *pCredential; strcpy( Common.ModuleName, szModuleName ); strcpy( Common.Path, szSearchPath ); Common.CDSAVersion.Major = CSSM_MAJOR; Common.CDSAVersion.Minor = CSSM_MINOR; strcpy( Common.Desc, ADDIN_PRINT_NAME ); Common.DynamicFlag = CSSM_FALSE; Common.MultiThreadFlag = CSSM_FALSE; Common.ServiceMask = CSSM_SERVICE_CSP; /* Insert the common schema record into the MDS */ rv = MDSU_UpdateSchema( &MDSUContext, &IfiMdsuCdsadirCommonSchema, &Common, NULL ); if ( rv != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (common): %X\n", rv ); pError->ErrorCode = rv; MDSU_Term( &MDSUContext ); return rv; } /* Fill in the CSP primary schema data */ memcpy( &CSPPrimary.ModuleID, &ADDIN_GUID, sizeof(ADDIN_GUID) ); CSPPrimary.SSID = ADDIN_CSP_SUBSERVICE_ID; CSPPrimary.Manifest.Data = NULL; CSPPrimary.Manifest.Length = 0; strcpy( CSPPrimary.ModuleName, ADDIN_PRINT_NAME ); CSPPrimary.ProductVersion.Major = ADDIN_PRODUCT_VERSION_MAJOR; CSPPrimary.ProductVersion.Minor = ADDIN_PRODUCT_VERSION_MINOR; strcpy( CSPPrimary.Vendor, ADDIN_VENDOR_NAME ); CSPPrimary.CspType = CSSM_CSP_SOFTWARE; CSPPrimary.CspFlags = 0; CSPPrimary.CspCustomFlags = 0; CSPPrimary.UseeTags[0] = CSSM_USEE_NONE; CSPPrimary.NumUseeTags = 1; CSPPrimary.NumSampleTypes = 0; CSPPrimary.NumAclSubjectTypes = 0; CSPPrimary.NumAclAuthTags = 0; /* Write the data to MDS */ rv = MDSU_UpdateSchema( &MDSUContext, &IfiMdsuCdsadirCSPPrimarySchema, &CSPPrimary, NULL ); if ( rv != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (CSP Primary): %X\n", rv ); pError->ErrorCode = rv; MDSU_Revert( &MDSUContext ); MDSU_Term( &MDSUContext ); return rv; } /* Fill in the CSP encapsulated product schema data */ memcpy( &CSPEncProduct.ModuleID, &ADDIN_GUID, sizeof(ADDIN_GUID) ); CSPEncProduct.SSID = ADDIN_CSP_SUBSERVICE_ID; strcpy( CSPEncProduct.ProductVendor, ADDIN_VENDOR_NAME ); CSPEncProduct.ProductVersion.Major = ADDIN_PRODUCT_VERSION_MAJOR; CSPEncProduct.ProductVersion.Minor = ADDIN_PRODUCT_VERSION_MINOR; strcpy( CSPEncProduct.ProductDesc, ADDIN_PRODUCT_DESCRIPTION ); CSPEncProduct.ProductFlags = 0; CSPEncProduct.CustomFlags = 0; strcpy( CSPEncProduct.StandardDesc, ADDIN_STANDARD_DESCRIPTION ); CSPEncProduct.StandardVersion.Major = ADDIN_STANDARD_VERSION_MAJOR; CSPEncProduct.StandardVersion.Minor = ADDIN_STANDARD_VERSION_MINOR; strcpy( CSPEncProduct.ReaderDesc, "" ); strcpy( CSPEncProduct.ReaderVendor, "" ); CSPEncProduct.ReaderVersion.Major = 0; CSPEncProduct.ReaderVersion.Minor = 0; CSPEncProduct.ReaderFirmwareVersion.Major = 0; CSPEncProduct.ReaderFirmwareVersion.Minor = 0; CSPEncProduct.ReaderFlags = 0; CSPEncProduct.ReaderCustomFlags = 0; strcpy( CSPEncProduct.ReaderSerialNumber, "" ); /* Write the data to MDS */ rv = MDSU_UpdateSchema( &MDSUContext, &IfiMdsuCdsadirCSPEncProductSchema, &CSPEncProduct, NULL ); if ( rv != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (CSP Enc): %X\n", rv ); pError->ErrorCode = rv; MDSU_Revert( &MDSUContext ); MDSU_Term( &MDSUContext ); return rv; } /* Write the CSP capabilities table */ for ( i = 0; i < CapabilityTableSize; i++ ) { rv = MDSU_UpdateSchema( &MDSUContext, &IfiMdsuCdsadirCSPCapabilitySchema, (void*)&CapabilityTable[i], NULL ); if ( rv != CSSM_OK ) { sprintf( pError->ErrorString, "MDS Error (CSP Cap): %X\n", rv ); pError->ErrorCode = rv; MDSU_Revert( &MDSUContext ); MDSU_Term( &MDSUContext ); return rv; } } /* Commit the records */ MDSU_Commit( &MDSUContext ); /* Shut down the MDS connection */ MDSU_Term( &MDSUContext ); return CSSM_OK; }