]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10089 - Use ConfigArgs in slapi config parsing
authorHoward Chu <hyc@openldap.org>
Tue, 22 Mar 2022 16:01:59 +0000 (16:01 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Mon, 23 Oct 2023 19:12:56 +0000 (19:12 +0000)
servers/slapd/bconfig.c
servers/slapd/slapi/plugin.c
servers/slapd/slapi/proto-slapi.h

index 4c4b925a9b270d0c047d3c9db979734eca3b4d8e..cf8d887b581a52655725ba3cbf12f8f39686eea4 100644 (file)
@@ -2533,7 +2533,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;
index de8c60d94b5545a19a107421d17c9e2e61c70a10..ca5dbead595c31f0d9981c349d5a41948ba73264 100644 (file)
@@ -36,7 +36,7 @@
 #include <ltdl.h>
 
 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 <plugin_type> <lib_path> "
-                       "<init_function> [<arguments>]\" line\n",
-                       fname, lineno );
+                       "<init_function> [<arguments>]\" 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;
index 9d5251045d0ad7457a6bfc07483072756006e684..e9eb76ba17f10585cda6117ade946205ece975b0 100644 (file)
@@ -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));