/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2002-2005 The OpenLDAP Foundation.
+ * Copyright 2002-2011 The OpenLDAP Foundation.
* Portions Copyright 1997,2002-2003 IBM Corporation.
* All rights reserved.
*
*/
#include "portable.h"
-#include <ldap_pvt_thread.h>
-#include <slap.h>
-#include <slapi.h>
-#include <lutil.h>
+#include "ldap_pvt_thread.h"
+#include "slap.h"
+#include "config.h"
+#include "slapi.h"
+#include "lutil.h"
/*
* Note: if ltdl.h is not available, slapi should not be compiled
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 ) {
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 ) {
} 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, TRUE, NULL, &hdLoadHandle );
+ rc = slapi_int_load_plugin( pPlugin, path, initfunc, 1, NULL, &hdLoadHandle );
if ( rc != 0 ) {
goto done;
}
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 ); /* global plugins are now stored in frontendDB */
+ assert( be != NULL );
- pTmpPB = (Slapi_PBlock *)be->be_pb;
+ pTmpPB = SLAPI_BACKEND_PBLOCK( be );
if ( pTmpPB == NULL ) {
- be->be_pb = (void *)pPB;
+ SLAPI_BACKEND_PBLOCK( be ) = pPB;
} else {
while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) {
pSavePB = pTmpPB;
goto done;
}
- /*
- * First, count the plugins associated with a specific
- * backend.
- */
- if ( be != frontendDB ) {
- pCurrentPB = (Slapi_PBlock *)be->be_pb;
-
- while ( pCurrentPB != NULL && rc == LDAP_SUCCESS ) {
- rc = slapi_pblock_get( pCurrentPB, functype, &FuncPtr );
- if ( rc == LDAP_SUCCESS ) {
- if ( FuncPtr != NULL ) {
- numPB++;
- }
- rc = slapi_pblock_get( pCurrentPB,
- SLAPI_IBM_PBLOCK, &pCurrentPB );
- }
- }
- }
- if ( rc != LDAP_SUCCESS ) {
- goto done;
- }
-
- /*
- * Then, count the global plugins.
- */
- pCurrentPB = (Slapi_PBlock *)frontendDB->be_pb;
+ pCurrentPB = SLAPI_BACKEND_PBLOCK( be );
while ( pCurrentPB != NULL && rc == LDAP_SUCCESS ) {
rc = slapi_pblock_get( pCurrentPB, functype, &FuncPtr );
SLAPI_IBM_PBLOCK, &pCurrentPB );
}
}
- if ( rc != LDAP_SUCCESS ) {
- goto done;
- }
if ( numPB == 0 ) {
*ppFuncPtrs = NULL;
goto done;
}
- if ( be != frontendDB ) {
- pCurrentPB = (Slapi_PBlock *)be->be_pb;
-
- while ( pCurrentPB != NULL && rc == LDAP_SUCCESS ) {
- rc = slapi_pblock_get( pCurrentPB, functype, &FuncPtr );
- if ( rc == LDAP_SUCCESS ) {
- if ( FuncPtr != NULL ) {
- *pTmpFuncPtr = FuncPtr;
- pTmpFuncPtr++;
- }
- rc = slapi_pblock_get( pCurrentPB,
- SLAPI_IBM_PBLOCK, &pCurrentPB );
- }
- }
- }
-
- pCurrentPB = (Slapi_PBlock *)frontendDB->be_pb;
+ pCurrentPB = SLAPI_BACKEND_PBLOCK( be );
while ( pCurrentPB != NULL && rc == LDAP_SUCCESS ) {
rc = slapi_pblock_get( pCurrentPB, functype, &FuncPtr );
SLAPI_IBM_PBLOCK, &pCurrentPB );
}
}
- *pTmpFuncPtr = NULL ;
+
+ *pTmpFuncPtr = NULL;
+
done:
if ( rc != LDAP_SUCCESS && *ppFuncPtrs != NULL ) {
{
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;
}
/* 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;
}
- if ( doInit == TRUE ) {
+ if ( doInit ) {
rc = ( *fpInitFunc )( pPlugin );
if ( rc != LDAP_SUCCESS ) {
lt_dlclose( *pLdHandle );
rc = slapi_int_get_plugins( be, funcType, &tmpPlugin );
if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
/* Nothing to do, front-end should ignore. */
- return 1;
+ return rc;
}
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);
/*
}
/* automatically instantiate overlay if necessary */
- if ( !overlay_is_inst( be, "slapi" ) ) {
- if ( overlay_config( be, "slapi" ) != 0 ) {
- fprintf( stderr, "failed to instantiate SLAPI overlay\n");
+ 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 );
return -1;
}
}
idx.bv_val = ibuf;
i = 0;
- for ( pp = be->be_pb;
+ for ( pp = SLAPI_BACKEND_PBLOCK( be );
pp != NULL;
slapi_pblock_get( pp, SLAPI_IBM_PBLOCK, &pp ) )
{
slapi_pblock_get( pp, SLAPI_X_CONFIG_ARGV, &argv );
if ( argv == NULL ) /* could be dynamic plugin */
continue;
- idx.bv_len = sprintf( idx.bv_val, "{%d}", i );
+ idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), "{%d}", i );
+ if ( idx.bv_len >= sizeof( ibuf ) ) {
+ /* FIXME: just truncating by now */
+ idx.bv_len = sizeof( ibuf ) - 1;
+ }
bv.bv_len = idx.bv_len;
for (j=1; argv[j]; j++) {
bv.bv_len += strlen(argv[j]);
}
}
-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();
-}