#ifndef SLAPD_LDAP_H
#define SLAPD_LDAP_H
+#include "../back-monitor/back-monitor.h"
+
LDAP_BEGIN_DECL
struct ldapinfo_t;
+/* stuff required for monitoring */
+typedef struct ldap_monitor_info_t {
+ monitor_subsys_t lmi_mss;
+ struct ldapinfo_t *lmi_li;
+
+ struct berval lmi_rdn;
+ struct berval lmi_nrdn;
+ monitor_callback_t *lmi_cb;
+ struct berval lmi_base;
+ int lmi_scope;
+ struct berval lmi_filter;
+ struct berval lmi_more_filter;
+} ldap_monitor_info_t;
+
typedef struct ldapconn_t {
Connection *lc_conn;
#define LDAP_BACK_PCONN ((void *)0x0)
ldap_avl_info_t li_conninfo;
+ ldap_monitor_info_t li_monitor_info;
+
sig_atomic_t li_isquarantined;
#define LDAP_BACK_FQ_NO (0)
#define LDAP_BACK_FQ_YES (1)
#include <ac/string.h>
#include <ac/socket.h>
+#include "lutil.h"
#include "slap.h"
#include "back-ldap.h"
-
#include "config.h"
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
static int ldap_chain_db_init_common( BackendDB *be );
static int ldap_chain_db_init_one( BackendDB *be );
-#define ldap_chain_db_open_one(be) (lback)->bi_db_open( (be) )
+static int ldap_chain_db_open_one( BackendDB *be );
#define ldap_chain_db_close_one(be) (0)
#define ldap_chain_db_destroy_one(be) (lback)->bi_db_destroy( (be) )
BerVarray ref,
int depth );
+static slap_overinst ldapchain;
+
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
static int
chaining_control_add(
{
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
ldap_chain_t *lc = (ldap_chain_t *)on->on_bi.bi_private;
- void *private = op->o_bd->be_private;
+ BackendDB db, *bd = op->o_bd;
ldap_chain_cb_t lb = { 0 };
slap_callback *sc = op->o_callback,
sc2 = { 0 };
* e) what ssf
*/
+ db = *op->o_bd;
+ SLAP_DBFLAGS( &db ) &= ~SLAP_DBFLAG_MONITORING;
+ op->o_bd = &db;
+
matched = rs->sr_matched;
rs->sr_matched = NULL;
ref = rs->sr_ref;
rs->sr_type = sr_type;
rs->sr_matched = matched;
rs->sr_ref = ref;
- op->o_bd->be_private = private;
+ op->o_bd = bd;
op->o_callback = sc;
op->o_ndn = ndn;
if ( lc->lc_common_li == NULL ) {
lc->lc_common_li = li;
- } else if ( avl_insert( &lc->lc_lai.lai_tree, (caddr_t)li,
- ldap_chain_uri_cmp, ldap_chain_uri_dup ) )
- {
- Debug( LDAP_DEBUG_ANY, "slapd-chain: "
- "database \"%s\" insert failed.\n",
- e->e_name.bv_val, 0, 0 );
- rc = LDAP_CONSTRAINT_VIOLATION;
- goto done;
+ } else {
+ li->li_uri = ch_strdup( at->a_vals[ 0 ].bv_val );
+ value_add_one( &li->li_bvuri, &at->a_vals[ 0 ] );
+ if ( avl_insert( &lc->lc_lai.lai_tree, (caddr_t)li,
+ ldap_chain_uri_cmp, ldap_chain_uri_dup ) )
+ {
+ Debug( LDAP_DEBUG_ANY, "slapd-chain: "
+ "database \"%s\" insert failed.\n",
+ e->e_name.bv_val, 0, 0 );
+ rc = LDAP_CONSTRAINT_VIOLATION;
+ goto done;
+ }
}
done:;
ldap_chain_t *lc = NULL;
if ( lback == NULL ) {
+ static BackendInfo lback2;
+
lback = backend_info( "ldap" );
if ( lback == NULL ) {
return 1;
}
+
+ lback2 = *lback;
+ lback2.bi_type = ldapchain.on_bi.bi_type;
+ lback = &lback2;
}
lc = ch_malloc( sizeof( ldap_chain_t ) );
{
slap_overinst *on = (slap_overinst *) be->bd_info;
ldap_chain_t *lc = (ldap_chain_t *)on->on_bi.bi_private;
+ slap_mask_t monitoring;
+ int rc = 0;
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
- int rc = 0;
-
rc = overlay_register_control( be, LDAP_CONTROL_X_CHAINING_BEHAVIOR );
if ( rc != 0 ) {
return rc;
be->be_private = be_private;
}
- return ldap_chain_db_func( be, db_open );
+ /* filter out and restore monitoring */
+ monitoring = ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_MONITORING );
+ SLAP_DBFLAGS( be ) &= ~SLAP_DBFLAG_MONITORING;
+ rc = ldap_chain_db_func( be, db_open );
+ SLAP_DBFLAGS( be ) |= monitoring;
+
+ return rc;
}
static int
{
BackendInfo *bi = be->bd_info;
ldapinfo_t *li;
- int t;
+ int rc;
be->bd_info = lback;
be->be_private = NULL;
- t = lback->bi_db_init( be );
- if ( t != 0 ) {
- return t;
+ rc = lback->bi_db_init( be );
+ if ( rc != 0 ) {
+ return rc;
}
li = (ldapinfo_t *)be->be_private;
li->li_urllist_f = NULL;
li->li_urllist_p = NULL;
+
be->bd_info = bi;
return 0;
return 0;
}
+static int
+ldap_chain_db_open_one(
+ BackendDB *be )
+{
+#ifdef SLAPD_MONITOR
+ if ( SLAP_DBMONITORING( be ) ) {
+ ldapinfo_t *li = (ldapinfo_t *)be->be_private;
+
+ if ( li->li_uri == NULL ) {
+ ber_str2bv( "cn=Common Connections", 0, 1,
+ &li->li_monitor_info.lmi_rdn );
+
+ } else {
+ char *ptr;
+
+ li->li_monitor_info.lmi_rdn.bv_len
+ = STRLENOF( "cn=" ) + strlen( li->li_uri );
+ ptr = li->li_monitor_info.lmi_rdn.bv_val
+ = ch_malloc( li->li_monitor_info.lmi_rdn.bv_len + 1 );
+ ptr = lutil_strcopy( ptr, "cn=" );
+ ptr = lutil_strcopy( ptr, li->li_uri );
+ ptr[ 0 ] = '\0';
+ }
+ }
+#endif /* SLAPD_MONITOR */
+
+ return lback->bi_db_open( be );
+}
+
typedef struct ldap_chain_conn_apply_t {
BackendDB *be;
Connection *conn;
}
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
-static slap_overinst ldapchain;
-
int
chain_initialize( void )
{
int
ldap_back_initialize( BackendInfo *bi )
{
+ int rc;
+
bi->bi_flags =
#ifdef LDAP_DYNAMIC_OBJECTS
/* this is set because all the support a proxy has to provide
bi->bi_db_init = ldap_back_db_init;
bi->bi_db_config = config_generic_wrapper;
bi->bi_db_open = ldap_back_db_open;
- bi->bi_db_close = 0;
+ bi->bi_db_close = ldap_back_db_close;
bi->bi_db_destroy = ldap_back_db_destroy;
bi->bi_op_bind = ldap_back_bind;
bi->bi_connection_init = 0;
bi->bi_connection_destroy = ldap_back_conn_destroy;
- if ( chain_initialize() ) {
- return -1;
+ rc = chain_initialize();
+ if ( rc ) {
+ return rc;
}
#ifdef SLAP_DISTPROC
- if ( distproc_initialize() ) {
- return -1;
+ rc = distproc_initialize();
+ if ( rc ) {
+ return rc;
}
#endif
ldap_back_db_init( Backend *be )
{
ldapinfo_t *li;
+ int rc;
li = (ldapinfo_t *)ch_calloc( 1, sizeof( ldapinfo_t ) );
if ( li == NULL ) {
be->be_cf_ocs = be->bd_info->bi_cf_ocs;
- return 0;
+ rc = ldap_back_monitor_db_init( be );
+
+ return rc;
}
int
}
}
+ /* monitor setup */
+ rc = ldap_back_monitor_db_open( be );
+ if ( rc != 0 ) {
+ goto fail;
+ }
+
li->li_flags |= LDAP_BACK_F_ISOPEN;
- return 0;
+fail:;
+ return rc;
}
void
}
int
-ldap_back_db_destroy(
- Backend *be
-)
+ldap_back_db_close( Backend *be )
+{
+ int rc = 0;
+
+ if ( be->be_private ) {
+ rc = ldap_back_monitor_db_close( be );
+ }
+
+ return rc;
+}
+
+int
+ldap_back_db_destroy( Backend *be )
{
if ( be->be_private ) {
ldapinfo_t *li = ( ldapinfo_t * )be->be_private;
ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
ldap_pvt_thread_mutex_destroy( &li->li_conninfo.lai_mutex );
ldap_pvt_thread_mutex_destroy( &li->li_uri_mutex );
+
+ (void)ldap_back_monitor_db_destroy( be );
}
ch_free( be->be_private );
LDAP_BEGIN_DECL
extern BI_init ldap_back_initialize;
-
extern BI_open ldap_back_open;
-extern BI_close ldap_back_close;
-extern BI_destroy ldap_back_destroy;
extern BI_db_init ldap_back_db_init;
extern BI_db_open ldap_back_db_open;
+extern BI_db_close ldap_back_db_close;
extern BI_db_destroy ldap_back_db_destroy;
extern BI_op_bind ldap_back_bind;
extern int distproc_initialize( void );
#endif
+extern int ldap_back_monitor_db_init( BackendDB *be );
+extern int ldap_back_monitor_db_open( BackendDB *be );
+extern int ldap_back_monitor_db_close( BackendDB *be );
+extern int ldap_back_monitor_db_destroy( BackendDB *be );
+
extern LDAP_REBIND_PROC ldap_back_default_rebind;
extern LDAP_URLLIST_PROC ldap_back_default_urllist;