diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 3215372ff1..5c890d3873 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -2548,7 +2548,7 @@ sortval_reject: #ifdef LDAP_SLAPI case CFG_PLUGIN: - if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx) != LDAP_SUCCESS) + if(slapi_int_read_config(c) != LDAP_SUCCESS) return(1); slapi_plugins_used++; break; diff --git a/servers/slapd/slapi/plugin.c b/servers/slapd/slapi/plugin.c index de8c60d94b..ca5dbead59 100644 --- a/servers/slapd/slapi/plugin.c +++ b/servers/slapd/slapi/plugin.c @@ -36,7 +36,7 @@ #include static int slapi_int_load_plugin( Slapi_PBlock *, const char *, const char *, int, - SLAPI_FUNC *, lt_dlhandle * ); + SLAPI_FUNC *, lt_dlhandle *, ConfigArgs *c ); /* pointer to link list of extended objects */ static ExtendedOp *pGExtendedOps = NULL; @@ -68,15 +68,15 @@ static Slapi_PBlock * plugin_pblock_new( int type, int argc, - char *argv[] ) + ConfigArgs *c ) { Slapi_PBlock *pPlugin = NULL; Slapi_PluginDesc *pPluginDesc = NULL; lt_dlhandle hdLoadHandle; int rc; char **av2 = NULL, **ppPluginArgv; - char *path = argv[2]; - char *initfunc = argv[3]; + char *path = c->argv[2]; + char *initfunc = c->argv[3]; pPlugin = slapi_pblock_new(); if ( pPlugin == NULL ) { @@ -87,7 +87,7 @@ plugin_pblock_new( slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type ); slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGC, (void *)&argc ); - av2 = ldap_charray_dup( argv ); + av2 = ldap_charray_dup( c->argv ); if ( av2 == NULL ) { rc = LDAP_NO_MEMORY; goto done; @@ -102,7 +102,7 @@ plugin_pblock_new( slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGV, (void *)ppPluginArgv ); slapi_pblock_set( pPlugin, SLAPI_X_CONFIG_ARGV, (void *)av2 ); - rc = slapi_int_load_plugin( pPlugin, path, initfunc, 1, NULL, &hdLoadHandle ); + rc = slapi_int_load_plugin( pPlugin, path, initfunc, 1, NULL, &hdLoadHandle, c ); if ( rc != 0 ) { goto done; } @@ -556,7 +556,8 @@ slapi_int_load_plugin( const char *initfunc, int doInit, SLAPI_FUNC *pInitFunc, - lt_dlhandle *pLdHandle ) + lt_dlhandle *pLdHandle, + ConfigArgs *c ) { int rc = LDAP_SUCCESS; SLAPI_FUNC fpInitFunc = NULL; @@ -570,15 +571,17 @@ slapi_int_load_plugin( /* load in the module */ *pLdHandle = lt_dlopen( path ); if ( *pLdHandle == NULL ) { - fprintf( stderr, "failed to load plugin %s: %s\n", + snprintf( c->cr_msg, sizeof( c->cr_msg ), "failed to load plugin %s: %s", path, lt_dlerror() ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return LDAP_LOCAL_ERROR; } fpInitFunc = (SLAPI_FUNC)lt_dlsym( *pLdHandle, initfunc ); if ( fpInitFunc == NULL ) { - fprintf( stderr, "failed to find symbol %s in plugin %s: %s\n", + snprintf( c->cr_msg, sizeof( c->cr_msg ), "failed to find symbol %s in plugin %s: %s", initfunc, path, lt_dlerror() ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); lt_dlclose( *pLdHandle ); return LDAP_LOCAL_ERROR; } @@ -643,50 +646,46 @@ slapi_int_call_plugins( int slapi_int_read_config( - Backend *be, - const char *fname, - int lineno, - int argc, - char **argv, - int index ) + struct config_args_s *c ) { int iType = -1; int numPluginArgc = 0; - if ( argc < 4 ) { - fprintf( stderr, - "%s: line %d: missing arguments " + if ( c->argc < 4 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "missing arguments " "in \"plugin " - " []\" line\n", - fname, lineno ); + " []\" line" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return 1; } /* automatically instantiate overlay if necessary */ - if ( !slapi_over_is_inst( be ) ) { - ConfigReply cr = { 0 }; - if ( slapi_over_config( be, &cr ) != 0 ) { - fprintf( stderr, "Failed to instantiate SLAPI overlay: " - "err=%d msg=\"%s\"\n", cr.err, cr.msg ); + if ( !slapi_over_is_inst( c->be ) ) { + if ( slapi_over_config( c->be, &c->reply ) != 0 ) { + Debug( LDAP_DEBUG_ANY, "%s: " + "Failed to instantiate SLAPI overlay: " + "err=%d msg=\"%s\"\n", c->log, c->reply.err, c->reply.msg ); return -1; } } - if ( strcasecmp( argv[1], "preoperation" ) == 0 ) { + if ( strcasecmp( c->argv[1], "preoperation" ) == 0 ) { iType = SLAPI_PLUGIN_PREOPERATION; - } else if ( strcasecmp( argv[1], "postoperation" ) == 0 ) { + } else if ( strcasecmp( c->argv[1], "postoperation" ) == 0 ) { iType = SLAPI_PLUGIN_POSTOPERATION; - } else if ( strcasecmp( argv[1], "extendedop" ) == 0 ) { + } else if ( strcasecmp( c->argv[1], "extendedop" ) == 0 ) { iType = SLAPI_PLUGIN_EXTENDEDOP; - } else if ( strcasecmp( argv[1], "object" ) == 0 ) { + } else if ( strcasecmp( c->argv[1], "object" ) == 0 ) { iType = SLAPI_PLUGIN_OBJECT; } else { - fprintf( stderr, "%s: line %d: invalid plugin type \"%s\".\n", - fname, lineno, argv[1] ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "invalid plugin type \"%s\"", c->argv[1] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return 1; } - numPluginArgc = argc - 4; + numPluginArgc = c->argc - 4; if ( iType == SLAPI_PLUGIN_PREOPERATION || iType == SLAPI_PLUGIN_EXTENDEDOP || @@ -695,23 +694,23 @@ slapi_int_read_config( int rc; Slapi_PBlock *pPlugin; - pPlugin = plugin_pblock_new( iType, numPluginArgc, argv ); + pPlugin = plugin_pblock_new( iType, numPluginArgc, c->argv ); if (pPlugin == NULL) { return 1; } if (iType == SLAPI_PLUGIN_EXTENDEDOP) { - rc = slapi_int_register_extop(be, &pGExtendedOps, pPlugin); + rc = slapi_int_register_extop(c->be, &pGExtendedOps, pPlugin); if ( rc != LDAP_SUCCESS ) { slapi_pblock_destroy( pPlugin ); return 1; } } - rc = slapi_int_register_plugin_index( be, pPlugin, index ); + rc = slapi_int_register_plugin_index( c->be, pPlugin, c->valx ); if ( rc != LDAP_SUCCESS ) { if ( iType == SLAPI_PLUGIN_EXTENDEDOP ) { - slapi_int_unregister_extop( be, &pGExtendedOps, pPlugin ); + slapi_int_unregister_extop( c->be, &pGExtendedOps, pPlugin ); } slapi_pblock_destroy( pPlugin ); return 1; diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index 9d5251045d..e9eb76ba17 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -72,8 +72,7 @@ LDAP_SLAPI_F (int) slapi_int_register_extop LDAP_P((Backend *pBE, ExtendedOp **o 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 index )); +LDAP_SLAPI_F (int) slapi_int_read_config LDAP_P(( struct config_args_s *c )); LDAP_SLAPI_F (void) slapi_int_plugin_unparse LDAP_P((Backend *be, BerVarray *out )); LDAP_SLAPI_F (int) slapi_int_initialize LDAP_P((void));