2003-11-27 14:35:14 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1999-2004 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.
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
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>.
|
|
|
|
*/
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2003-04-29 23:05:19 +08:00
|
|
|
#include <ac/string.h>
|
2001-05-12 08:51:28 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "../back-ldap/back-ldap.h"
|
|
|
|
#include "back-meta.h"
|
2004-11-11 08:39:19 +08:00
|
|
|
#include "external.h"
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2004-04-08 13:56:23 +08:00
|
|
|
#if SLAPD_META == SLAPD_MOD_DYNAMIC
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
int
|
2003-06-13 06:25:20 +08:00
|
|
|
init_module( int argc, char *argv[] ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
BackendInfo bi;
|
|
|
|
|
|
|
|
memset( &bi, '\0', sizeof( bi ) );
|
|
|
|
bi.bi_type = "meta";
|
|
|
|
bi.bi_init = meta_back_initialize;
|
|
|
|
|
|
|
|
backend_add( &bi );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-04-08 13:56:23 +08:00
|
|
|
#endif /* SLAPD_META */
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2004-11-10 17:45:02 +08:00
|
|
|
int
|
2004-08-19 20:10:22 +08:00
|
|
|
meta_back_open(
|
|
|
|
BackendInfo *bi
|
|
|
|
)
|
|
|
|
{
|
2004-10-06 13:51:38 +08:00
|
|
|
bi->bi_controls = slap_known_controls;
|
2004-08-19 20:10:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
int
|
|
|
|
meta_back_initialize(
|
|
|
|
BackendInfo *bi
|
|
|
|
)
|
|
|
|
{
|
2004-08-19 20:10:22 +08:00
|
|
|
bi->bi_open = meta_back_open;
|
2001-05-12 08:51:28 +08:00
|
|
|
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;
|
|
|
|
|
2003-03-07 03:44:41 +08:00
|
|
|
struct rewrite_info *rwinfo;
|
|
|
|
|
|
|
|
rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
|
|
|
|
if ( rwinfo == NULL ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
li = ch_calloc( 1, sizeof( struct metainfo ) );
|
|
|
|
if ( li == NULL ) {
|
2003-12-06 19:12:53 +08:00
|
|
|
rewrite_info_delete( &rwinfo );
|
2001-05-12 08:51:28 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2003-12-06 19:12:53 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* At present the default is no default target;
|
|
|
|
* this may change
|
|
|
|
*/
|
|
|
|
li->defaulttarget = META_DEFAULT_TARGET_NONE;
|
2003-03-07 03:44:41 +08:00
|
|
|
li->rwinfo = rwinfo;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
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(
|
2002-12-15 06:25:52 +08:00
|
|
|
void *v_lc
|
2001-05-12 08:51:28 +08:00
|
|
|
)
|
|
|
|
{
|
2002-12-15 06:25:52 +08:00
|
|
|
struct metaconn *lc = v_lc;
|
2002-08-10 01:15:10 +08:00
|
|
|
struct metasingleconn *lsc;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2002-08-10 01:15:10 +08:00
|
|
|
for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) {
|
|
|
|
if ( lsc->ld != NULL ) {
|
|
|
|
ldap_unbind( lsc->ld );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2002-08-10 01:15:10 +08:00
|
|
|
if ( lsc->bound_dn.bv_val ) {
|
|
|
|
ber_memfree( lsc->bound_dn.bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-04-18 18:02:00 +08:00
|
|
|
if ( lsc->cred.bv_val ) {
|
|
|
|
memset( lsc->cred.bv_val, 0, lsc->cred.bv_len );
|
|
|
|
ber_memfree( lsc->cred.bv_val );
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
free( lc->conns );
|
|
|
|
free( lc );
|
|
|
|
}
|
|
|
|
|
2004-11-10 17:56:55 +08:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
static void
|
|
|
|
target_free(
|
|
|
|
struct metatarget *lt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if ( lt->uri ) {
|
|
|
|
free( lt->uri );
|
|
|
|
}
|
2001-12-29 12:48:00 +08:00
|
|
|
if ( lt->psuffix.bv_val ) {
|
|
|
|
free( lt->psuffix.bv_val );
|
2001-12-27 20:17:54 +08:00
|
|
|
}
|
2001-12-29 12:48:00 +08:00
|
|
|
if ( lt->suffix.bv_val ) {
|
|
|
|
free( lt->suffix.bv_val );
|
2001-12-27 20:17:54 +08:00
|
|
|
}
|
2001-12-29 18:30:23 +08:00
|
|
|
if ( lt->binddn.bv_val ) {
|
|
|
|
free( lt->binddn.bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2001-12-29 18:30:23 +08:00
|
|
|
if ( lt->bindpw.bv_val ) {
|
|
|
|
free( lt->bindpw.bv_val );
|
2001-12-27 20:17:54 +08:00
|
|
|
}
|
2001-12-29 18:30:23 +08:00
|
|
|
if ( lt->pseudorootdn.bv_val ) {
|
|
|
|
free( lt->pseudorootdn.bv_val );
|
2001-12-27 20:17:54 +08:00
|
|
|
}
|
2001-12-29 18:30:23 +08:00
|
|
|
if ( lt->pseudorootpw.bv_val ) {
|
|
|
|
free( lt->pseudorootpw.bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-04-08 01:04:14 +08:00
|
|
|
if ( lt->rwmap.rwm_rw ) {
|
2003-11-15 02:39:18 +08:00
|
|
|
rewrite_info_delete( <->rwmap.rwm_rw );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-04-08 01:04:14 +08:00
|
|
|
avl_free( lt->rwmap.rwm_oc.remap, NULL );
|
|
|
|
avl_free( lt->rwmap.rwm_oc.map, mapping_free );
|
|
|
|
avl_free( lt->rwmap.rwm_at.remap, NULL );
|
|
|
|
avl_free( lt->rwmap.rwm_at.map, mapping_free );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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->conn_mutex );
|
|
|
|
|
|
|
|
if ( li->conntree ) {
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_free( li->conntree, conn_free );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy the per-target stuff (assuming there's at
|
|
|
|
* least one ...)
|
|
|
|
*/
|
|
|
|
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 ) {
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_free( li->cache.tree, meta_dncache_free );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &li->cache.mutex );
|
|
|
|
ldap_pvt_thread_mutex_destroy( &li->cache.mutex );
|
|
|
|
|
2002-04-02 19:16:00 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
|
|
|
|
ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
free( be->be_private );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|