version 1.37, 2004/11/15 18:45:50
|
version 1.37.2.6, 2005/10/05 17:42:20
|
Line 1
|
Line 1
|
/* $OpenLDAP: pkg/ldap/servers/slapd/back-meta/init.c,v 1.36 2004/11/13 17:52:45 ando Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/back-meta/init.c,v 1.49 2005/10/01 16:07:00 ando Exp $ */ |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
* |
* |
* Copyright 1999-2004 The OpenLDAP Foundation. |
* Copyright 1999-2005 The OpenLDAP Foundation. |
* Portions Copyright 2001-2003 Pierangelo Masarati. |
* Portions Copyright 2001-2003 Pierangelo Masarati. |
* Portions Copyright 1999-2003 Howard Chu. |
* Portions Copyright 1999-2003 Howard Chu. |
* All rights reserved. |
* All rights reserved. |
Line 28
|
Line 28
|
|
|
int |
int |
meta_back_open( |
meta_back_open( |
BackendInfo *bi |
BackendInfo *bi ) |
) |
|
{ |
{ |
|
/* FIXME: need to remove the pagedResults, and likely more... */ |
bi->bi_controls = slap_known_controls; |
bi->bi_controls = slap_known_controls; |
|
|
return 0; |
return 0; |
} |
} |
|
|
int |
int |
meta_back_initialize( |
meta_back_initialize( |
BackendInfo *bi |
BackendInfo *bi ) |
) |
|
{ |
{ |
bi->bi_open = meta_back_open; |
bi->bi_open = meta_back_open; |
bi->bi_config = 0; |
bi->bi_config = 0; |
Line 47 meta_back_initialize(
|
Line 47 meta_back_initialize(
|
|
|
bi->bi_db_init = meta_back_db_init; |
bi->bi_db_init = meta_back_db_init; |
bi->bi_db_config = meta_back_db_config; |
bi->bi_db_config = meta_back_db_config; |
bi->bi_db_open = 0; |
bi->bi_db_open = meta_back_db_open; |
bi->bi_db_close = 0; |
bi->bi_db_close = 0; |
bi->bi_db_destroy = meta_back_db_destroy; |
bi->bi_db_destroy = meta_back_db_destroy; |
|
|
Line 73 meta_back_initialize(
|
Line 73 meta_back_initialize(
|
|
|
int |
int |
meta_back_db_init( |
meta_back_db_init( |
Backend *be |
Backend *be ) |
) |
|
{ |
{ |
struct metainfo *li; |
metainfo_t *mi; |
|
|
struct rewrite_info *rwinfo; |
|
|
|
rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT ); |
|
if ( rwinfo == NULL ) { |
|
return -1; |
|
} |
|
|
|
li = ch_calloc( 1, sizeof( struct metainfo ) ); |
mi = ch_malloc( sizeof( metainfo_t ) ); |
if ( li == NULL ) { |
if ( mi == NULL ) { |
rewrite_info_delete( &rwinfo ); |
|
return -1; |
return -1; |
} |
} |
|
memset( mi, 0, sizeof( metainfo_t ) ); |
|
|
/* |
/* |
* At present the default is no default target; |
* At present the default is no default target; |
* this may change |
* this may change |
*/ |
*/ |
li->defaulttarget = META_DEFAULT_TARGET_NONE; |
mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE; |
li->rwinfo = rwinfo; |
|
|
|
ldap_pvt_thread_mutex_init( &li->conn_mutex ); |
ldap_pvt_thread_mutex_init( &mi->mi_conn_mutex ); |
ldap_pvt_thread_mutex_init( &li->cache.mutex ); |
ldap_pvt_thread_mutex_init( &mi->mi_cache.mutex ); |
be->be_private = li; |
|
|
/* safe default */ |
|
mi->mi_nretries = META_RETRY_DEFAULT; |
|
mi->mi_version = LDAP_VERSION3; |
|
|
|
be->be_private = mi; |
|
|
return 0; |
return 0; |
} |
} |
|
|
static void |
int |
conn_free( |
meta_back_db_open( |
void *v_lc |
Backend *be ) |
) |
|
{ |
{ |
struct metaconn *lc = v_lc; |
metainfo_t *mi = (metainfo_t *)be->be_private; |
struct metasingleconn *lsc; |
|
|
|
for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) { |
int i, rc; |
if ( lsc->ld != NULL ) { |
|
ldap_unbind( lsc->ld ); |
for ( i = 0; i < mi->mi_ntargets; i++ ) { |
|
if ( mi->mi_targets[ i ].mt_flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) |
|
{ |
|
mi->mi_targets[ i ].mt_flags &= ~LDAP_BACK_F_SUPPORT_T_F_DISCOVER; |
|
rc = slap_discover_feature( mi->mi_targets[ i ].mt_uri, |
|
mi->mi_targets[ i ].mt_version, |
|
slap_schema.si_ad_supportedFeatures->ad_cname.bv_val, |
|
LDAP_FEATURE_ABSOLUTE_FILTERS ); |
|
if ( rc == LDAP_COMPARE_TRUE ) { |
|
mi->mi_targets[ i ].mt_flags |= LDAP_BACK_F_SUPPORT_T_F; |
|
} |
} |
} |
if ( lsc->bound_dn.bv_val ) { |
} |
ber_memfree( lsc->bound_dn.bv_val ); |
|
|
return 0; |
|
} |
|
|
|
void |
|
meta_back_conn_free( |
|
void *v_mc ) |
|
{ |
|
metaconn_t *mc = v_mc; |
|
int i, ntargets; |
|
|
|
assert( mc != NULL ); |
|
assert( mc->mc_refcnt == 0 ); |
|
|
|
if ( !BER_BVISNULL( &mc->mc_local_ndn ) ) { |
|
free( mc->mc_local_ndn.bv_val ); |
|
} |
|
|
|
assert( mc->mc_conns != NULL ); |
|
|
|
/* at least one must be present... */ |
|
ntargets = mc->mc_conns[ 0 ].msc_info->mi_ntargets; |
|
|
|
for ( i = 0; i < ntargets; i++ ) { |
|
metasingleconn_t *msc = &mc->mc_conns[ i ]; |
|
|
|
if ( msc->msc_ld != NULL ) { |
|
ldap_unbind_ext_s( msc->msc_ld, NULL, NULL ); |
} |
} |
if ( lsc->cred.bv_val ) { |
|
memset( lsc->cred.bv_val, 0, lsc->cred.bv_len ); |
if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) { |
ber_memfree( lsc->cred.bv_val ); |
ber_memfree( msc->msc_bound_ndn.bv_val ); |
|
} |
|
|
|
if ( !BER_BVISNULL( &msc->msc_cred ) ) { |
|
/* destroy sensitive data */ |
|
memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len ); |
|
ber_memfree( msc->msc_cred.bv_val ); |
} |
} |
} |
} |
free( lc->conns ); |
|
free( lc ); |
ldap_pvt_thread_mutex_destroy( &mc->mc_mutex ); |
|
free( mc ); |
} |
} |
|
|
static void |
static void |
mapping_free( void *v_mapping ) |
mapping_free( |
|
void *v_mapping ) |
{ |
{ |
struct ldapmapping *mapping = v_mapping; |
struct ldapmapping *mapping = v_mapping; |
ch_free( mapping->src.bv_val ); |
ch_free( mapping->src.bv_val ); |
Line 140 mapping_free( void *v_mapping )
|
Line 179 mapping_free( void *v_mapping )
|
|
|
static void |
static void |
target_free( |
target_free( |
struct metatarget *lt |
metatarget_t *mt ) |
) |
|
{ |
{ |
if ( lt->uri ) { |
if ( mt->mt_uri ) { |
free( lt->uri ); |
free( mt->mt_uri ); |
} |
} |
if ( lt->psuffix.bv_val ) { |
if ( !BER_BVISNULL( &mt->mt_psuffix ) ) { |
free( lt->psuffix.bv_val ); |
free( mt->mt_psuffix.bv_val ); |
} |
} |
if ( lt->suffix.bv_val ) { |
if ( !BER_BVISNULL( &mt->mt_nsuffix ) ) { |
free( lt->suffix.bv_val ); |
free( mt->mt_nsuffix.bv_val ); |
} |
} |
if ( lt->binddn.bv_val ) { |
if ( !BER_BVISNULL( &mt->mt_binddn ) ) { |
free( lt->binddn.bv_val ); |
free( mt->mt_binddn.bv_val ); |
} |
} |
if ( lt->bindpw.bv_val ) { |
if ( !BER_BVISNULL( &mt->mt_bindpw ) ) { |
free( lt->bindpw.bv_val ); |
free( mt->mt_bindpw.bv_val ); |
} |
} |
if ( lt->pseudorootdn.bv_val ) { |
if ( !BER_BVISNULL( &mt->mt_pseudorootdn ) ) { |
free( lt->pseudorootdn.bv_val ); |
free( mt->mt_pseudorootdn.bv_val ); |
} |
} |
if ( lt->pseudorootpw.bv_val ) { |
if ( !BER_BVISNULL( &mt->mt_pseudorootpw ) ) { |
free( lt->pseudorootpw.bv_val ); |
free( mt->mt_pseudorootpw.bv_val ); |
} |
} |
if ( lt->rwmap.rwm_rw ) { |
if ( mt->mt_rwmap.rwm_rw ) { |
rewrite_info_delete( <->rwmap.rwm_rw ); |
rewrite_info_delete( &mt->mt_rwmap.rwm_rw ); |
} |
} |
avl_free( lt->rwmap.rwm_oc.remap, NULL ); |
avl_free( mt->mt_rwmap.rwm_oc.remap, NULL ); |
avl_free( lt->rwmap.rwm_oc.map, mapping_free ); |
avl_free( mt->mt_rwmap.rwm_oc.map, mapping_free ); |
avl_free( lt->rwmap.rwm_at.remap, NULL ); |
avl_free( mt->mt_rwmap.rwm_at.remap, NULL ); |
avl_free( lt->rwmap.rwm_at.map, mapping_free ); |
avl_free( mt->mt_rwmap.rwm_at.map, mapping_free ); |
} |
} |
|
|
int |
int |
meta_back_db_destroy( |
meta_back_db_destroy( |
Backend *be |
Backend *be ) |
) |
|
{ |
{ |
struct metainfo *li; |
metainfo_t *mi; |
|
|
if ( be->be_private ) { |
if ( be->be_private ) { |
int i; |
int i; |
|
|
li = ( struct metainfo * )be->be_private; |
mi = ( metainfo_t * )be->be_private; |
|
|
/* |
/* |
* Destroy the connection tree |
* Destroy the connection tree |
*/ |
*/ |
ldap_pvt_thread_mutex_lock( &li->conn_mutex ); |
ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); |
|
|
if ( li->conntree ) { |
if ( mi->mi_conntree ) { |
avl_free( li->conntree, conn_free ); |
avl_free( mi->mi_conntree, meta_back_conn_free ); |
} |
} |
|
|
/* |
/* |
* Destroy the per-target stuff (assuming there's at |
* Destroy the per-target stuff (assuming there's at |
* least one ...) |
* least one ...) |
*/ |
*/ |
for ( i = 0; i < li->ntargets; i++ ) { |
for ( i = 0; i < mi->mi_ntargets; i++ ) { |
target_free( li->targets[ i ] ); |
target_free( &mi->mi_targets[ i ] ); |
free( li->targets[ i ] ); |
|
} |
} |
|
|
free( li->targets ); |
free( mi->mi_targets ); |
|
|
ldap_pvt_thread_mutex_lock( &li->cache.mutex ); |
ldap_pvt_thread_mutex_lock( &mi->mi_cache.mutex ); |
if ( li->cache.tree ) { |
if ( mi->mi_cache.tree ) { |
avl_free( li->cache.tree, meta_dncache_free ); |
avl_free( mi->mi_cache.tree, meta_dncache_free ); |
} |
} |
|
|
ldap_pvt_thread_mutex_unlock( &li->cache.mutex ); |
ldap_pvt_thread_mutex_unlock( &mi->mi_cache.mutex ); |
ldap_pvt_thread_mutex_destroy( &li->cache.mutex ); |
ldap_pvt_thread_mutex_destroy( &mi->mi_cache.mutex ); |
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex ); |
|
ldap_pvt_thread_mutex_destroy( &mi->mi_conn_mutex ); |
|
|
ldap_pvt_thread_mutex_unlock( &li->conn_mutex ); |
if ( mi->mi_candidates != NULL ) { |
ldap_pvt_thread_mutex_destroy( &li->conn_mutex ); |
ber_memfree_x( mi->mi_candidates, NULL ); |
|
} |
} |
} |
|
|
free( be->be_private ); |
free( be->be_private ); |