diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 101a753296..81566fc7e2 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -1418,8 +1418,13 @@ config_generic(ConfigArgs *c) { case CFG_SYNC_SUBENTRY: break; - /* no-ops, requires slapd restart */ +#ifdef LDAP_SLAPI case CFG_PLUGIN: + slapi_int_unregister_plugins(c->be, c->valx); + break; +#endif + + /* no-op, requires slapd restart */ case CFG_MODLOAD: snprintf(c->log, sizeof( c->log ), "change requires slapd restart"); break; @@ -2409,7 +2414,7 @@ sortval_reject: #ifdef LDAP_SLAPI case CFG_PLUGIN: - if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS) + if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx) != LDAP_SUCCESS) return(1); slapi_plugins_used++; break; diff --git a/servers/slapd/slapi/plugin.c b/servers/slapd/slapi/plugin.c index 0212ad1cd0..92756083b5 100644 --- a/servers/slapd/slapi/plugin.c +++ b/servers/slapd/slapi/plugin.c @@ -129,7 +129,7 @@ done: /********************************************************************* * Function Name: slapi_int_register_plugin * - * Description: insert the slapi_pblock structure to the end of the plugin + * Description: insert the slapi_pblock structure to a given position the end of the plugin * list * * Input: a pointer to a plugin slapi_pblock structure to be added to @@ -143,21 +143,23 @@ done: * Messages: None *********************************************************************/ int -slapi_int_register_plugin( +slapi_int_register_plugin_index( Backend *be, - Slapi_PBlock *pPB ) + Slapi_PBlock *pPB, + int index ) { Slapi_PBlock *pTmpPB; Slapi_PBlock *pSavePB; - int rc = LDAP_SUCCESS; + int pos = 0, rc = LDAP_SUCCESS; assert( be != NULL ); pTmpPB = SLAPI_BACKEND_PBLOCK( be ); - if ( pTmpPB == NULL ) { + if ( pTmpPB == NULL || index == 0 ) { SLAPI_BACKEND_PBLOCK( be ) = pPB; } else { - while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) { + while ( pTmpPB != NULL && rc == LDAP_SUCCESS && + ( index < 0 || pos++ < index ) ) { pSavePB = pTmpPB; rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB ); } @@ -166,10 +168,22 @@ slapi_int_register_plugin( rc = slapi_pblock_set( pSavePB, SLAPI_IBM_PBLOCK, (void *)pPB ); } } + + if ( index >= 0 && rc == LDAP_SUCCESS ) { + rc = slapi_pblock_set( pPB, SLAPI_IBM_PBLOCK, (void *)pTmpPB ); + } return ( rc != LDAP_SUCCESS ) ? LDAP_OTHER : LDAP_SUCCESS; } - + +int +slapi_int_register_plugin( + Backend *be, + Slapi_PBlock *pPB ) +{ + return slapi_int_register_plugin_index( be, pPB, -1 ); +} + /********************************************************************* * Function Name: slapi_int_get_plugins * @@ -630,7 +644,8 @@ slapi_int_read_config( const char *fname, int lineno, int argc, - char **argv ) + char **argv, + int index ) { int iType = -1; int numPluginArgc = 0; @@ -690,7 +705,7 @@ slapi_int_read_config( } } - rc = slapi_int_register_plugin( be, pPlugin ); + rc = slapi_int_register_plugin_index( be, pPlugin, index ); if ( rc != LDAP_SUCCESS ) { if ( iType == SLAPI_PLUGIN_EXTENDEDOP ) { slapi_int_unregister_extop( be, &pGExtendedOps, pPlugin ); @@ -703,6 +718,74 @@ slapi_int_read_config( return 0; } +int +slapi_int_unregister_plugin( + Backend *be, + Slapi_PBlock *pPlugin, + Slapi_PBlock *pPrev +) +{ + int type; + + assert( pPlugin != NULL ); + + slapi_pblock_get( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type ); + if ( type == SLAPI_PLUGIN_EXTENDEDOP ) { + slapi_int_unregister_extop( be, &pGExtendedOps, pPlugin ); + } + + if ( pPrev != NULL ) { + Slapi_PBlock *pNext = NULL; + + slapi_pblock_get( pPlugin, SLAPI_IBM_PBLOCK, &pNext ); + slapi_pblock_set( pPrev, SLAPI_IBM_PBLOCK, &pNext ); + } + slapi_pblock_destroy( pPlugin ); + + return LDAP_SUCCESS; +} + +int +slapi_int_unregister_plugins( + Backend *be, + int index +) +{ + Slapi_PBlock *pTmpPB = NULL; + Slapi_PBlock *pSavePB = NULL; + int rc = LDAP_SUCCESS; + + pTmpPB = SLAPI_BACKEND_PBLOCK( be ); + if ( pTmpPB == NULL ) { + return ( index < 0 ) ? LDAP_SUCCESS : LDAP_OTHER; + } + + if ( index < 0 ) { + /* All plugins must go */ + while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) { + pSavePB = pTmpPB; + rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB ); + if ( pSavePB != NULL ) { + slapi_int_unregister_plugin( be, pSavePB, NULL ); + } + } + } else if ( index == 0 ) { + slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pSavePB ); + SLAPI_BACKEND_PBLOCK( be ) = pSavePB; + slapi_int_unregister_plugin( be, pTmpPB, NULL ); + } else { + int pos = -1; + while ( pTmpPB != NULL && rc == LDAP_SUCCESS && ++pos < index ) { + pSavePB = pTmpPB; + rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB ); + } + if ( pos == index ) { + slapi_int_unregister_plugin( be, pTmpPB, pSavePB ); + } + } + return rc; +} + void slapi_int_plugin_unparse( Backend *be, diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index 6d7203d7ea..9c9bc69b59 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -65,13 +65,15 @@ LDAP_SLAPI_F (int) slapi_int_pblock_get_next LDAP_P(( Slapi_PBlock **pb )); /* plugin.c */ LDAP_SLAPI_F (int) slapi_int_register_plugin LDAP_P((Backend *be, Slapi_PBlock *pPB)); +LDAP_SLAPI_F (int) slapi_int_register_plugin_index LDAP_P((Backend *be, Slapi_PBlock *pPB, int index)); LDAP_SLAPI_F (int) slapi_int_call_plugins LDAP_P((Backend *be, int funcType, Slapi_PBlock * pPB)); LDAP_SLAPI_F (int) slapi_int_get_plugins LDAP_P((Backend *be, int functype, SLAPI_FUNC **ppFuncPtrs)); LDAP_SLAPI_F (int) slapi_int_register_extop LDAP_P((Backend *pBE, ExtendedOp **opList, Slapi_PBlock *pPB)); LDAP_SLAPI_F (int) slapi_int_get_extop_plugin LDAP_P((struct berval *reqoid, SLAPI_FUNC *pFuncAddr )); LDAP_SLAPI_F (struct berval *) slapi_int_get_supported_extop LDAP_P(( int )); +LDAP_SLAPI_F (int) slapi_int_unregister_plugins LDAP_P((Backend *be, int index)); LDAP_SLAPI_F (int) slapi_int_read_config LDAP_P((Backend *be, const char *fname, int lineno, - int argc, char **argv )); + int argc, char **argv, int index )); LDAP_SLAPI_F (void) slapi_int_plugin_unparse LDAP_P((Backend *be, BerVarray *out )); LDAP_SLAPI_F (int) slapi_int_initialize LDAP_P((void));