]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/plugin.c
Add ability to cache negative results and specify negative TTL on templates
[openldap] / servers / slapd / slapi / plugin.c
index abdd63d6cdc2f27a2430ed2b329fb55f77795574..22e482328a414782d9a6e21e35c9adc5ed2c99bf 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2002-2005 The OpenLDAP Foundation.
+ * Copyright 2002-2006 The OpenLDAP Foundation.
  * Portions Copyright 1997,2002-2003 IBM Corporation.
  * All rights reserved.
  *
@@ -70,9 +70,9 @@ plugin_pblock_new(
        Slapi_PluginDesc *pPluginDesc = NULL;
        lt_dlhandle     hdLoadHandle;
        int             rc;
-       char **av2 = NULL, **ppPluginArgv;
-       char *path = argv[2];
-       char *initfunc = argv[3];
+       char            **av2 = NULL, **ppPluginArgv;
+       char            *path = argv[2];
+       char            *initfunc = argv[3];
 
        pPlugin = slapi_pblock_new();
        if ( pPlugin == NULL ) {
@@ -80,15 +80,8 @@ plugin_pblock_new(
                goto done;
        }
 
-       rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)type );
-       if ( rc != 0 ) {
-               goto done;
-       }
-
-       rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGC, (void *)argc );
-       if ( rc != 0 ) {
-               goto done;
-       }
+       slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
+       slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGC, (void *)&argc );
 
        av2 = ldap_charray_dup( argv );
        if ( av2 == NULL ) {
@@ -101,15 +94,9 @@ plugin_pblock_new(
        } else {
                ppPluginArgv = NULL;
        }
-       rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGV, (void *)ppPluginArgv );
-       if ( rc != 0 ) { 
-               goto done;
-       }
 
-       rc = slapi_pblock_set( pPlugin, SLAPI_X_CONFIG_ARGV, (void *)av2 );
-       if ( rc != 0 ) { 
-               goto done;
-       }
+       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 );
        if ( rc != 0 ) {
@@ -159,9 +146,9 @@ slapi_int_register_plugin(
        Backend *be, 
        Slapi_PBlock *pPB )
 { 
-       Slapi_PBlock *pTmpPB;
-       Slapi_PBlock *pSavePB;
-       int    rc = LDAP_SUCCESS;
+       Slapi_PBlock    *pTmpPB;
+       Slapi_PBlock    *pSavePB;
+       int              rc = LDAP_SUCCESS;
 
        assert( be != NULL );
 
@@ -286,14 +273,12 @@ createExtendedOp()
 {
        ExtendedOp *ret;
 
-       ret = (ExtendedOp *)ch_malloc(sizeof(ExtendedOp));
-       if ( ret != NULL ) {
-               ret->ext_oid.bv_val = NULL;
-               ret->ext_oid.bv_len = 0;
-               ret->ext_func = NULL;
-               ret->ext_be = NULL;
-               ret->ext_next = NULL;
-       }
+       ret = (ExtendedOp *)slapi_ch_malloc(sizeof(ExtendedOp));
+       ret->ext_oid.bv_val = NULL;
+       ret->ext_oid.bv_len = 0;
+       ret->ext_func = NULL;
+       ret->ext_be = NULL;
+       ret->ext_next = NULL;
 
        return ret;
 }
@@ -567,11 +552,15 @@ slapi_int_load_plugin(
        /* load in the module */
        *pLdHandle = lt_dlopen( path );
        if ( *pLdHandle == NULL ) {
+               fprintf( stderr, "failed to load plugin %s: %s\n",
+                        path, lt_dlerror() );
                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",
+                        initfunc, path, lt_dlerror() );
                lt_dlclose( *pLdHandle );
                return LDAP_LOCAL_ERROR;
        }
@@ -613,12 +602,6 @@ slapi_int_call_plugins(
        }
 
        for ( pGetPlugin = tmpPlugin ; *pGetPlugin != NULL; pGetPlugin++ ) {
-               /*
-                * FIXME: we should provide here a sort of sandbox,
-                * to protect from plugin faults; e.g. trap signals
-                * and longjump here, marking the plugin as unsafe for
-                * later executions ...
-                */
                rc = (*pGetPlugin)(pPB);
 
                /*
@@ -661,8 +644,8 @@ slapi_int_read_config(
        }
 
        /* automatically instantiate overlay if necessary */
-       if ( !overlay_is_inst( be, SLAPI_OVERLAY_NAME ) ) {
-               if ( overlay_config( be, SLAPI_OVERLAY_NAME ) != 0 ) {
+       if ( !slapi_over_is_inst( be ) ) {
+               if ( slapi_over_config( be ) != 0 ) {
                        fprintf( stderr, "Failed to instantiate SLAPI overlay\n");
                        return -1;
                }
@@ -755,29 +738,3 @@ slapi_int_plugin_unparse(
        }
 }
 
-int
-slapi_int_initialize(void)
-{
-       if ( ldap_pvt_thread_mutex_init( &slapi_hn_mutex ) ) {
-               return -1;
-       }
-       
-       if ( ldap_pvt_thread_mutex_init( &slapi_time_mutex ) ) {
-               return -1;
-       }
-
-       if ( ldap_pvt_thread_mutex_init( &slapi_printmessage_mutex ) ) {
-               return -1;
-       }
-
-       slapi_log_file = ch_strdup( LDAP_RUNDIR LDAP_DIRSEP "errors" );
-       if ( slapi_log_file == NULL ) {
-               return -1;
-       }
-
-       if ( slapi_int_init_object_extensions() != 0 ) {
-               return -1;
-       }
-
-       return slapi_int_overlay_init();
-}