openldap/servers/slapd/back-meta/init.c

230 lines
4.8 KiB
C
Raw Normal View History

2003-11-27 14:35:14 +08:00
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
2005-01-02 04:49:32 +08:00
* Copyright 1999-2005 The OpenLDAP Foundation.
2003-12-09 01:41:40 +08:00
* Portions Copyright 2001-2003 Pierangelo Masarati.
* Portions Copyright 1999-2003 Howard Chu.
2003-11-27 14:35:14 +08:00
* All rights reserved.
*
2003-11-27 14:35:14 +08:00
* 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>.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "slap.h"
#include "../back-ldap/back-ldap.h"
#include "back-meta.h"
2004-11-10 17:45:02 +08:00
int
meta_back_open(
BackendInfo *bi
)
{
bi->bi_controls = slap_known_controls;
return 0;
}
int
meta_back_initialize(
BackendInfo *bi
)
{
bi->bi_open = meta_back_open;
bi->bi_config = 0;
bi->bi_close = 0;
bi->bi_destroy = 0;
bi->bi_db_init = meta_back_db_init;
bi->bi_db_config = meta_back_db_config;
bi->bi_db_open = 0;
bi->bi_db_close = 0;
bi->bi_db_destroy = meta_back_db_destroy;
bi->bi_op_bind = meta_back_bind;
bi->bi_op_unbind = 0;
bi->bi_op_search = meta_back_search;
bi->bi_op_compare = meta_back_compare;
bi->bi_op_modify = meta_back_modify;
bi->bi_op_modrdn = meta_back_modrdn;
bi->bi_op_add = meta_back_add;
bi->bi_op_delete = meta_back_delete;
bi->bi_op_abandon = 0;
bi->bi_extended = 0;
bi->bi_chk_referrals = 0;
bi->bi_connection_init = 0;
bi->bi_connection_destroy = meta_back_conn_destroy;
return 0;
}
int
meta_back_db_init(
Backend *be
)
{
struct metainfo *li;
li = ch_calloc( 1, sizeof( struct metainfo ) );
if ( li == NULL ) {
return -1;
}
2003-12-06 19:12:53 +08:00
/*
* At present the default is no default target;
* this may change
*/
li->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
ldap_pvt_thread_mutex_init( &li->mi_conn_mutex );
ldap_pvt_thread_mutex_init( &li->mi_cache.mutex );
be->be_private = li;
return 0;
}
static void
conn_free(
2002-12-15 06:25:52 +08:00
void *v_lc
)
{
2005-01-08 17:20:54 +08:00
struct metaconn *lc = v_lc;
struct metasingleconn *lsc;
assert( lc->mc_conns != NULL );
for ( lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); lsc++ ) {
2005-01-08 17:20:54 +08:00
if ( lsc->msc_ld != NULL ) {
ldap_unbind_ext_s( lsc->msc_ld, NULL, NULL );
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lsc->msc_bound_ndn ) ) {
ber_memfree( lsc->msc_bound_ndn.bv_val );
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lsc->msc_cred ) ) {
/* destroy sensitive data */
memset( lsc->msc_cred.bv_val, 0, lsc->msc_cred.bv_len );
ber_memfree( lsc->msc_cred.bv_val );
2003-04-18 18:02:00 +08:00
}
}
free( lc );
}
static void
mapping_free( void *v_mapping )
{
struct ldapmapping *mapping = v_mapping;
ch_free( mapping->src.bv_val );
ch_free( mapping->dst.bv_val );
ch_free( mapping );
}
static void
target_free(
struct metatarget *lt
)
{
2005-01-08 17:20:54 +08:00
if ( lt->mt_uri ) {
free( lt->mt_uri );
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lt->mt_psuffix ) ) {
free( lt->mt_psuffix.bv_val );
2001-12-27 20:17:54 +08:00
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lt->mt_nsuffix ) ) {
free( lt->mt_nsuffix.bv_val );
2001-12-27 20:17:54 +08:00
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lt->mt_binddn ) ) {
free( lt->mt_binddn.bv_val );
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lt->mt_bindpw ) ) {
free( lt->mt_bindpw.bv_val );
2001-12-27 20:17:54 +08:00
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lt->mt_pseudorootdn ) ) {
free( lt->mt_pseudorootdn.bv_val );
2001-12-27 20:17:54 +08:00
}
2005-01-08 17:20:54 +08:00
if ( !BER_BVISNULL( &lt->mt_pseudorootpw ) ) {
free( lt->mt_pseudorootpw.bv_val );
}
2005-01-08 17:20:54 +08:00
if ( lt->mt_rwmap.rwm_rw ) {
rewrite_info_delete( &lt->mt_rwmap.rwm_rw );
}
2005-01-08 17:20:54 +08:00
avl_free( lt->mt_rwmap.rwm_oc.remap, NULL );
avl_free( lt->mt_rwmap.rwm_oc.map, mapping_free );
avl_free( lt->mt_rwmap.rwm_at.remap, NULL );
avl_free( lt->mt_rwmap.rwm_at.map, mapping_free );
}
int
meta_back_db_destroy(
Backend *be
)
{
struct metainfo *li;
if ( be->be_private ) {
int i;
li = ( struct metainfo * )be->be_private;
/*
* Destroy the connection tree
*/
ldap_pvt_thread_mutex_lock( &li->mi_conn_mutex );
if ( li->mi_conntree ) {
avl_free( li->mi_conntree, conn_free );
}
/*
* Destroy the per-target stuff (assuming there's at
* least one ...)
*/
for ( i = 0; i < li->mi_ntargets; i++ ) {
target_free( li->mi_targets[ i ] );
free( li->mi_targets[ i ] );
}
free( li->mi_targets );
ldap_pvt_thread_mutex_lock( &li->mi_cache.mutex );
if ( li->mi_cache.tree ) {
avl_free( li->mi_cache.tree, meta_dncache_free );
}
ldap_pvt_thread_mutex_unlock( &li->mi_cache.mutex );
ldap_pvt_thread_mutex_destroy( &li->mi_cache.mutex );
ldap_pvt_thread_mutex_unlock( &li->mi_conn_mutex );
ldap_pvt_thread_mutex_destroy( &li->mi_conn_mutex );
if ( li->mi_candidates != NULL ) {
ber_memfree_x( li->mi_candidates, NULL );
}
}
free( be->be_private );
return 0;
}
#if SLAPD_META == SLAPD_MOD_DYNAMIC
2004-11-16 03:45:49 +08:00
/* conditionally define the init_module() function */
SLAP_BACKEND_INIT_MODULE( meta )
2004-11-16 03:45:49 +08:00
#endif /* SLAPD_META == SLAPD_MOD_DYNAMIC */