From: Luke Howard Date: Tue, 21 Jan 2003 15:09:58 +0000 (+0000) Subject: Allow plugins not associated with a specific backend X-Git-Tag: NO_SLAP_OP_BLOCKS~558 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1e32bdbd694794d78824262b42aeeabecf26da0d;p=openldap Allow plugins not associated with a specific backend --- diff --git a/servers/slapd/slapi/plugin.c b/servers/slapd/slapi/plugin.c index f1995f5c04..fd603bb821 100644 --- a/servers/slapd/slapi/plugin.c +++ b/servers/slapd/slapi/plugin.c @@ -26,6 +26,8 @@ static int loadPlugin( Slapi_PBlock *, const char *, const char *, int, /* pointer to link list of extended objects */ static ExtendedOp *pGExtendedOps = NULL; +/* global plugins not associated with a specific backend */ +static Slapi_PBlock *pGPlugins = NULL; /********************************************************************* * Function Name: newPlugin @@ -119,10 +121,13 @@ insertPlugin( Slapi_PBlock *pSavePB; int rc = LDAP_SUCCESS; - pTmpPB = (Slapi_PBlock *)(be->be_pb); - + pTmpPB = ( be == NULL ) ? pGPlugins : (Slapi_PBlock *)(be->be_pb); + if ( pTmpPB == NULL ) { - be->be_pb = (void *)pPB; + if ( be != NULL ) + be->be_pb = (void *)pPB; + else + pGPlugins = pPB; } else { while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) { pSavePB = pTmpPB; @@ -173,17 +178,9 @@ getAllPluginFuncs( int numPB = 0; int rc = LDAP_SUCCESS; - if ( be == NULL ) { - /* - * No plugins supported if no backend (yet) - */ - rc = LDAP_OTHER; - goto done; - } - assert( ppFuncPtrs ); - pCurrentPB = (Slapi_PBlock *)(be->be_pb); + pCurrentPB = ( be == NULL ) ? pGPlugins : (Slapi_PBlock *)(be->be_pb); if ( pCurrentPB == NULL ) { /* @@ -221,7 +218,7 @@ getAllPluginFuncs( goto done; } - pCurrentPB = (Slapi_PBlock *)(be->be_pb); + pCurrentPB = ( be == NULL ) ? pGPlugins : (Slapi_PBlock *)(be->be_pb); while ( pCurrentPB != NULL && rc == LDAP_SUCCESS ) { rc = slapi_pblock_get( pCurrentPB, functype, &FuncPtr ); if ( rc == LDAP_SUCCESS ) { @@ -568,7 +565,7 @@ doPluginFNs( Slapi_PBlock *pPB ) { - int rc = LDAP_SUCCESS; + int rc = 0; SLAPI_FUNC *pGetPlugin = NULL, *tmpPlugin = NULL; rc = getAllPluginFuncs(be, funcType, &tmpPlugin ); @@ -595,7 +592,33 @@ doPluginFNs( } } - ch_free( tmpPlugin ); + slapi_ch_free( (void **)&tmpPlugin ); + + /* + * If we failed, and this wasn't a postoperation plugin, we + * should return the failure to the frontend. + */ + if ( !SLAPI_PLUGIN_IS_POST_FN( funcType ) && rc != 0 ) { + return rc; + } + + /* + * Try any global plugins (not associated with a specific + * backend); same logic as above. + */ + if ( be != NULL ) { + rc = getAllPluginFuncs( be, funcType, &tmpPlugin ); + if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) + return 0; + for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) { + rc = (*pGetPlugin)(pPB); + if ( !SLAPI_PLUGIN_IS_POST_FN( funcType ) && rc != 0 ) { + break; + } + } + } + + slapi_ch_free( (void **)&tmpPlugin ); return rc; } diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 1803dabe40..a69df2109e 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -1153,14 +1153,16 @@ int slapi_x_backend_set_pb( Slapi_PBlock *pb, Backend *be ) { #if defined(LDAP_SLAPI) int rc; - + rc = slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be ); if ( rc != LDAP_SUCCESS ) return rc; - - rc = slapi_pblock_set( pb, SLAPI_BE_TYPE, (void *)be->bd_info->bi_type ); - if ( rc != LDAP_SUCCESS ) - return rc; + + if ( be != NULL ) { + rc = slapi_pblock_set( pb, SLAPI_BE_TYPE, (void *)be->bd_info->bi_type ); + if ( rc != LDAP_SUCCESS ) + return rc; + } return LDAP_SUCCESS; #else