#include "portable.h"
#include <stdio.h>
#include <ac/socket.h>
#include "slap.h"
#include "../back-ldap/back-ldap.h"
#include "back-meta.h"
#ifdef SLAPD_META_DYNAMIC
int
back_meta_LTX_init_module( int argc, char *argv[] ) {
BackendInfo bi;
memset( &bi, '\0', sizeof( bi ) );
bi.bi_type = "meta";
bi.bi_init = meta_back_initialize;
backend_add( &bi );
return 0;
}
#endif
int
meta_back_initialize(
BackendInfo *bi
)
{
bi->bi_open = 0;
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_acl_group = meta_back_group;
bi->bi_acl_attribute = meta_back_attribute;
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;
}
li->defaulttarget = META_DEFAULT_TARGET_NONE;
ldap_pvt_thread_mutex_init( &li->conn_mutex );
ldap_pvt_thread_mutex_init( &li->cache.mutex );
be->be_private = li;
return 0;
}
static void
conn_free(
struct metaconn *lc
)
{
struct metasingleconn **lsc;
for ( lsc = lc->conns; lsc[ 0 ] != NULL; lsc++ ) {
if ( lsc[ 0 ]->ld != NULL ) {
ldap_unbind( lsc[ 0 ]->ld );
}
if ( lsc[ 0 ]->bound_dn.bv_val ) {
ber_memfree( lsc[ 0 ]->bound_dn.bv_val );
}
free( lsc[ 0 ] );
}
free( lc->conns );
free( lc );
}
static void
target_free(
struct metatarget *lt
)
{
if ( lt->uri ) {
free( lt->uri );
}
if ( lt->psuffix.bv_val ) {
free( lt->psuffix.bv_val );
}
if ( lt->suffix.bv_val ) {
free( lt->suffix.bv_val );
}
if ( lt->binddn.bv_val ) {
free( lt->binddn.bv_val );
}
if ( lt->bindpw.bv_val ) {
free( lt->bindpw.bv_val );
}
if ( lt->pseudorootdn.bv_val ) {
free( lt->pseudorootdn.bv_val );
}
if ( lt->pseudorootpw.bv_val ) {
free( lt->pseudorootpw.bv_val );
}
if ( lt->rwinfo ) {
rewrite_info_delete( lt->rwinfo );
}
avl_free( lt->oc_map.remap, NULL );
avl_free( lt->oc_map.map, ( AVL_FREE )mapping_free );
avl_free( lt->at_map.remap, NULL );
avl_free( lt->at_map.map, ( AVL_FREE )mapping_free );
}
int
meta_back_db_destroy(
Backend *be
)
{
struct metainfo *li;
if ( be->be_private ) {
int i;
li = ( struct metainfo * )be->be_private;
ldap_pvt_thread_mutex_lock( &li->conn_mutex );
if ( li->conntree ) {
avl_free( li->conntree,
( AVL_FREE )conn_free );
}
ldap_pvt_thread_mutex_unlock( &li->cache.mutex );
ldap_pvt_thread_mutex_destroy( &li->cache.mutex );
for ( i = 0; i < li->ntargets; i++ ) {
target_free( li->targets[ i ] );
free( li->targets[ i ] );
}
free( li->targets );
ldap_pvt_thread_mutex_lock( &li->cache.mutex );
if ( li->cache.tree ) {
avl_free( li->cache.tree,
( AVL_FREE )meta_dncache_free );
}
ldap_pvt_thread_mutex_unlock( &li->cache.mutex );
ldap_pvt_thread_mutex_destroy( &li->cache.mutex );
}
free( be->be_private );
return 0;
}