📄 plugin.c
字号:
/* $OpenLDAP: pkg/ldap/servers/slapd/slapi/plugin.c,v 1.26.2.5 2007/01/02 21:44:10 kurt Exp $ *//* This work is part of OpenLDAP Software <http://www.openldap.org/>. * * Copyright 2002-2007 The OpenLDAP Foundation. * Portions Copyright 1997,2002-2003 IBM Corporation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted only as authorized by the OpenLDAP * Public License. * * A copy of this license is available in the file LICENSE in the * top-level directory of the distribution or, alternatively, at * <http://www.OpenLDAP.org/license.html>. *//* ACKNOWLEDGEMENTS: * This work was initially developed by IBM Corporation for use in * IBM products and subsequently ported to OpenLDAP Software by * Steve Omrani. Additional significant contributors include: * Luke Howard */#include "portable.h"#include <ldap_pvt_thread.h>#include <slap.h>#include <slapi.h>#include <lutil.h>/* * Note: if ltdl.h is not available, slapi should not be compiled */#include <ltdl.h>static int slapi_int_load_plugin( Slapi_PBlock *, const char *, const char *, int, SLAPI_FUNC *, lt_dlhandle * );/* pointer to link list of extended objects */static ExtendedOp *pGExtendedOps = NULL;/********************************************************************* * Function Name: plugin_pblock_new * * Description: This routine creates a new Slapi_PBlock structure, * loads in the plugin module and executes the init * function provided by the module. * * Input: type - type of the plugin, such as SASL, database, etc. * path - the loadpath to load the module in * initfunc - name of the plugin function to execute first * argc - number of arguements * argv[] - an array of char pointers point to * the arguments passed in via * the configuration file. * * Output: * * Return Values: a pointer to a newly created Slapi_PBlock structrue or * NULL - function failed * * Messages: None *********************************************************************/static Slapi_PBlock *plugin_pblock_new( int type, int argc, char *argv[] ) { 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]; pPlugin = slapi_pblock_new(); if ( pPlugin == NULL ) { rc = LDAP_NO_MEMORY; 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 ) { rc = LDAP_NO_MEMORY; goto done; } if ( argc > 0 ) { ppPluginArgv = &av2[4]; } else { ppPluginArgv = NULL; } 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 ) { goto done; } if ( slapi_pblock_get( pPlugin, SLAPI_PLUGIN_DESCRIPTION, (void **)&pPluginDesc ) == 0 && pPluginDesc != NULL ) { slapi_log_error(SLAPI_LOG_TRACE, "plugin_pblock_new", "Registered plugin %s %s [%s] (%s)\n", pPluginDesc->spd_id, pPluginDesc->spd_version, pPluginDesc->spd_vendor, pPluginDesc->spd_description); }done: if ( rc != 0 && pPlugin != NULL ) { slapi_pblock_destroy( pPlugin ); pPlugin = NULL; if ( av2 != NULL ) { ldap_charray_free( av2 ); } } return pPlugin;} /********************************************************************* * Function Name: slapi_int_register_plugin * * Description: insert the slapi_pblock structure to the end of the plugin * list * * Input: a pointer to a plugin slapi_pblock structure to be added to * the list * * Output: none * * Return Values: LDAP_SUCCESS - successfully inserted. * LDAP_LOCAL_ERROR. * * Messages: None *********************************************************************/int slapi_int_register_plugin( Backend *be, Slapi_PBlock *pPB ){ Slapi_PBlock *pTmpPB; Slapi_PBlock *pSavePB; int rc = LDAP_SUCCESS; assert( be != NULL ); pTmpPB = SLAPI_BACKEND_PBLOCK( be ); if ( pTmpPB == NULL ) { SLAPI_BACKEND_PBLOCK( be ) = pPB; } else { while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) { pSavePB = pTmpPB; rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB ); } if ( rc == LDAP_SUCCESS ) { rc = slapi_pblock_set( pSavePB, SLAPI_IBM_PBLOCK, (void *)pPB ); } } return ( rc != LDAP_SUCCESS ) ? LDAP_OTHER : LDAP_SUCCESS;} /********************************************************************* * Function Name: slapi_int_get_plugins * * Description: get the desired type of function pointers defined * in all the plugins * * Input: the type of the functions to get, such as pre-operation,etc. * * Output: none * * Return Values: this routine returns a pointer to an array of function * pointers containing backend-specific plugin functions * followed by global plugin functions * * Messages: None *********************************************************************/int slapi_int_get_plugins( Backend *be, int functype, SLAPI_FUNC **ppFuncPtrs ){ Slapi_PBlock *pCurrentPB; SLAPI_FUNC FuncPtr; SLAPI_FUNC *pTmpFuncPtr; int numPB = 0; int rc = LDAP_SUCCESS; assert( ppFuncPtrs != NULL ); if ( be == NULL ) { goto done; } pCurrentPB = SLAPI_BACKEND_PBLOCK( be ); 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 ( numPB == 0 ) { *ppFuncPtrs = NULL; rc = LDAP_SUCCESS; goto done; } /* * Now, build the function pointer array of backend-specific * plugins followed by global plugins. */ *ppFuncPtrs = pTmpFuncPtr = (SLAPI_FUNC *)ch_malloc( ( numPB + 1 ) * sizeof(SLAPI_FUNC) ); if ( ppFuncPtrs == NULL ) { rc = LDAP_NO_MEMORY; goto done; } pCurrentPB = SLAPI_BACKEND_PBLOCK( be ); 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 ); } } *pTmpFuncPtr = NULL;done: if ( rc != LDAP_SUCCESS && *ppFuncPtrs != NULL ) { ch_free( *ppFuncPtrs ); *ppFuncPtrs = NULL; } return rc;}/********************************************************************* * Function Name: createExtendedOp * * Description: Creates an extended operation structure and * initializes the fields * * Return value: A newly allocated structure or NULL ********************************************************************/ExtendedOp *createExtendedOp(){ ExtendedOp *ret; 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;}/********************************************************************* * Function Name: slapi_int_unregister_extop * * Description: This routine removes the ExtendedOp structures * asscoiated with a particular extended operation * plugin. * * Input: pBE - pointer to a backend structure * opList - pointer to a linked list of extended * operation structures * pPB - pointer to a slapi parameter block * * Output: * * Return Value: none * * Messages: None *********************************************************************/voidslapi_int_unregister_extop( Backend *pBE, ExtendedOp **opList, Slapi_PBlock *pPB ){ ExtendedOp *pTmpExtOp, *backExtOp; char **pTmpOIDs; int i;#if 0 assert( pBE != NULL); /* unused */#endif /* 0 */ assert( opList != NULL ); assert( pPB != NULL ); if ( *opList == NULL ) { return; } slapi_pblock_get( pPB, SLAPI_PLUGIN_EXT_OP_OIDLIST, &pTmpOIDs ); if ( pTmpOIDs == NULL ) { return; } for ( i = 0; pTmpOIDs[i] != NULL; i++ ) { backExtOp = NULL; pTmpExtOp = *opList; for ( ; pTmpExtOp != NULL; pTmpExtOp = pTmpExtOp->ext_next) { int rc; rc = strcasecmp( pTmpExtOp->ext_oid.bv_val, pTmpOIDs[ i ] ); if ( rc == 0 ) { if ( backExtOp == NULL ) { *opList = pTmpExtOp->ext_next; } else { backExtOp->ext_next = pTmpExtOp->ext_next; } ch_free( pTmpExtOp ); break; } backExtOp = pTmpExtOp; } }}/********************************************************************* * Function Name: slapi_int_register_extop * * Description: This routine creates a new ExtendedOp structure, loads * in the extended op module and put the extended op function address * in the structure. The function will not be executed in * this routine. * * Input: pBE - pointer to a backend structure * opList - pointer to a linked list of extended * operation structures * pPB - pointer to a slapi parameter block * * Output: * * Return Value: an LDAP return code * * Messages: None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -