/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2001-2005 The OpenLDAP Foundation.
+ * Copyright 2001-2006 The OpenLDAP Foundation.
* Portions Copyright 2001-2003 Pierangelo Masarati.
* All rights reserved.
*
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_backend_init,
+ NULL, /* destroy */
NULL, /* update */
NULL, /* create */
NULL /* modify */
BER_BVNULL },
MONITOR_F_VOLATILE_CH,
monitor_subsys_conn_init,
- monitor_subsys_conn_update,
- monitor_subsys_conn_create,
+ NULL, /* destroy */
+ NULL, /* update */
+ NULL, /* create */
NULL /* modify */
}, {
SLAPD_MONITOR_DATABASE_NAME,
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_database_init,
+ NULL, /* destroy */
NULL, /* update */
NULL, /* create */
- monitor_subsys_database_modify
+ NULL /* modify */
}, {
SLAPD_MONITOR_LISTENER_NAME,
BER_BVNULL, BER_BVNULL, BER_BVNULL,
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_listener_init,
+ NULL, /* destroy */
NULL, /* update */
NULL, /* create */
NULL /* modify */
BER_BVNULL },
MONITOR_F_NONE,
monitor_subsys_log_init,
+ NULL, /* destroy */
NULL, /* update */
NULL, /* create */
- monitor_subsys_log_modify
+ NULL, /* modify */
}, {
SLAPD_MONITOR_OPS_NAME,
BER_BVNULL, BER_BVNULL, BER_BVNULL,
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_ops_init,
- monitor_subsys_ops_update,
+ NULL, /* destroy */
+ NULL, /* update */
NULL, /* create */
NULL, /* modify */
}, {
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_overlay_init,
+ NULL, /* destroy */
NULL, /* update */
NULL, /* create */
NULL, /* modify */
BER_BVNULL },
MONITOR_F_NONE,
NULL, /* init */
+ NULL, /* destroy */
NULL, /* update */
NULL, /* create */
NULL /* modify */
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_sent_init,
- monitor_subsys_sent_update,
+ NULL, /* destroy */
+ NULL, /* update */
NULL, /* create */
NULL, /* modify */
}, {
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_thread_init,
- monitor_subsys_thread_update,
+ NULL, /* destroy */
+ NULL, /* update */
NULL, /* create */
NULL /* modify */
}, {
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_time_init,
- monitor_subsys_time_update,
+ NULL, /* destroy */
+ NULL, /* update */
NULL, /* create */
NULL, /* modify */
}, {
BER_BVNULL },
MONITOR_F_NONE,
NULL, /* init */
+ NULL, /* destroy */
NULL, /* update */
NULL, /* create */
NULL /* modify */
BER_BVNULL },
MONITOR_F_PERSISTENT_CH,
monitor_subsys_rww_init,
- monitor_subsys_rww_update,
+ NULL, /* destroy */
+ NULL, /* update */
NULL, /* create */
NULL /* modify */
}, { NULL }
struct entry_limbo_t *el_next;
} entry_limbo_t;
+int
+monitor_back_is_configured( void )
+{
+ return be_monitor != NULL;
+}
+
int
monitor_back_register_entry(
Entry *e,
monitor_callback_t *cb )
{
- monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
+ monitor_info_t *mi;
+
+ if ( be_monitor == NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_register_entry(\"%s\"): "
+ "monitor database not configured.\n",
+ e->e_name.bv_val, 0, 0 );
+ return -1;
+ }
+
+ mi = ( monitor_info_t * )be_monitor->be_private;
assert( mi != NULL );
assert( e != NULL );
int scope,
struct berval *filter )
{
- monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
+ monitor_info_t *mi;
struct berval ndn = BER_BVNULL;
+ if ( be_monitor == NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
+ "monitor database not configured.\n",
+ BER_BVISNULL( base ) ? "" : base->bv_val,
+ ldap_pvt_scope2str( scope ),
+ BER_BVISNULL( filter ) ? "" : filter->bv_val );
+ return -1;
+ }
+
+ mi = ( monitor_info_t * )be_monitor->be_private;
+
assert( mi != NULL );
assert( e != NULL );
assert( e->e_private == NULL );
/* entry does not exist */
Debug( LDAP_DEBUG_ANY,
"monitor_back_register_entry_parent(\"\"): "
- "base=%s scope=%d filter=%s : "
+ "base=\"%s\" scope=%d filter=\"%s\": "
"unable to find entry\n",
base->bv_val ? base->bv_val : "\"\"",
scope, filter->bv_val );
struct berval *ndn )
{
Connection conn = { 0 };
- char opbuf[OPERATION_BUFFER_SIZE];
+ OperationBuffer opbuf;
Operation *op;
SlapReply rs = { 0 };
slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
return -1;
}
- op = (Operation *)opbuf;
+ op = (Operation *) &opbuf;
connection_fake_init( &conn, op, &conn );
op->o_tag = LDAP_REQ_SEARCH;
cb.sc_private = (void *)ndn;
op->ors_scope = scope;
- ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
op->ors_filter = str2filter_x( op, filter->bv_val );
+ if ( op->ors_filter == NULL ) {
+ rc = LDAP_OTHER;
+ goto cleanup;
+ }
+ ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
op->ors_attrs = slap_anlist_no_attrs;
op->ors_attrsonly = 0;
op->ors_tlimit = SLAP_NO_LIMIT;
rc = op->o_bd->be_search( op, &rs );
- filter_free_x( op, op->ors_filter );
- op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
- op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
- op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+cleanup:;
+ if ( op->ors_filter != NULL ) {
+ filter_free_x( op, op->ors_filter );
+ }
+ if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
+ op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
+ }
+ if ( !BER_BVISNULL( &op->o_req_dn ) ) {
+ op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
+ }
+ if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
+ op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+ }
if ( rc != 0 ) {
return rc;
int scope,
struct berval *filter )
{
- monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
+ monitor_info_t *mi;
struct berval ndn = BER_BVNULL;
+ char *fname = ( a == NULL ? "callback" : "attrs" );
+
+ if ( be_monitor == NULL ) {
+ char buf[ SLAP_TEXT_BUFLEN ];
+
+ snprintf( buf, sizeof( buf ),
+ "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
+ "monitor database not configured.\n",
+ fname,
+ BER_BVISNULL( base ) ? "" : base->bv_val,
+ ldap_pvt_scope2str( scope ),
+ BER_BVISNULL( filter ) ? "" : filter->bv_val );
+ Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
+
+ return -1;
+ }
+
+ mi = ( monitor_info_t * )be_monitor->be_private;
assert( mi != NULL );
{
/* need a filter */
Debug( LDAP_DEBUG_ANY,
- "monitor_back_register_entry_*(\"\"): "
+ "monitor_back_register_entry_%s(\"\"): "
"need a valid filter\n",
- 0, 0, 0 );
+ fname, 0, 0 );
return -1;
}
if ( BER_BVISNULL( &ndn ) ) {
if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
- /* entry does not exist */
- Debug( LDAP_DEBUG_ANY,
- "monitor_back_register_entry_*(\"\"): "
- "base=%s scope=%d filter=%s : "
+ char buf[ SLAP_TEXT_BUFLEN ];
+
+ snprintf( buf, sizeof( buf ),
+ "monitor_back_register_entry_%s(\"\"): "
+ "base=\"%s\" scope=%d filter=\"%s\": "
"unable to find entry\n",
+ fname,
base->bv_val ? base->bv_val : "\"\"",
scope, filter->bv_val );
+
+ /* entry does not exist */
+ Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
return -1;
}
if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
/* entry does not exist */
Debug( LDAP_DEBUG_ANY,
- "monitor_back_register_entry_*(\"%s\"): "
+ "monitor_back_register_entry_%s(\"%s\"): "
"entry does not exist\n",
- ndn.bv_val, 0, 0 );
+ fname, ndn.bv_val, 0 );
rc = -1;
goto done;
}
if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
/* entry is volatile; cannot append callback */
Debug( LDAP_DEBUG_ANY,
- "monitor_back_register_entry_*(\"%s\"): "
+ "monitor_back_register_entry_%s(\"%s\"): "
"entry is volatile\n",
- e->e_name.bv_val, 0, 0 );
+ fname, e->e_name.bv_val, 0 );
rc = -1;
goto done;
}
for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
/* just get to last */ ;
- *atp = attrs_dup( a );
- if ( *atp == NULL ) {
- Debug( LDAP_DEBUG_ANY,
- "monitor_back_register_entry_*(\"%s\"): "
- "attrs_dup() failed\n",
- e->e_name.bv_val, 0, 0 );
- rc = -1;
- goto done;
+ for ( ; a != NULL; a = a->a_next ) {
+ assert( a->a_desc != NULL );
+ assert( a->a_vals != NULL );
+
+ if ( attr_find( e->e_attrs, a->a_desc ) ) {
+ attr_merge( e, a->a_desc, a->a_vals,
+ a->a_nvals == a->a_vals ? NULL : a->a_nvals );
+
+ } else {
+ *atp = attr_dup( a );
+ if ( *atp == NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_register_entry_%s(\"%s\"): "
+ "attr_dup() failed\n",
+ fname, e->e_name.bv_val, 0 );
+ rc = -1;
+ goto done;
+ }
+ atp = &(*atp)->a_next;
+ }
}
}
done:;
if ( rc ) {
- if ( *atp ) {
+ if ( atp && *atp ) {
attrs_free( *atp );
*atp = NULL;
}
base, scope, filter );
}
+/*
+ * TODO: add corresponding calls to remove installed callbacks, entries
+ * and so, in case the entity that installed them is removed (e.g. a
+ * database, via back-config)
+ */
+int
+monitor_back_unregister_entry(
+ Entry *target_e )
+{
+ monitor_info_t *mi;
+
+ if ( be_monitor == NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_unregister_entry(\"%s\"): "
+ "monitor database not configured.\n",
+ target_e->e_name.bv_val, 0, 0 );
+
+ return -1;
+ }
+
+ mi = ( monitor_info_t * )be_monitor->be_private;
+
+ assert( mi != NULL );
+
+ if ( monitor_subsys_opened ) {
+ Entry *e = NULL;
+ monitor_entry_t *mp = NULL;
+ monitor_callback_t *cb = NULL;
+
+ if ( monitor_cache_remove( mi, &target_e->e_nname, &e ) != 0 ) {
+ /* entry does not exist */
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_unregister_entry(\"%s\"): "
+ "entry removal failed.\n",
+ target_e->e_name.bv_val, 0, 0 );
+ return -1;
+ }
+
+ mp = (monitor_entry_t *)e->e_private;
+ assert( mp != NULL );
+
+ for ( cb = mp->mp_cb; cb != NULL; ) {
+ monitor_callback_t *next = cb->mc_next;
+
+ if ( cb->mc_free ) {
+ (void)cb->mc_free( e, cb->mc_private );
+ }
+ ch_free( cb );
+
+ cb = next;
+ }
+
+ } else {
+ /* TODO: remove from limbo */
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+monitor_back_unregister_entry_attrs(
+ struct berval *ndn_in,
+ Attribute *target_a,
+ monitor_callback_t *target_cb,
+ struct berval *base,
+ int scope,
+ struct berval *filter )
+{
+ monitor_info_t *mi;
+ struct berval ndn = BER_BVNULL;
+ char *fname = ( target_a == NULL ? "callback" : "attrs" );
+
+ if ( be_monitor == NULL ) {
+ char buf[ SLAP_TEXT_BUFLEN ];
+
+ snprintf( buf, sizeof( buf ),
+ "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
+ "monitor database not configured.\n",
+ fname,
+ BER_BVISNULL( base ) ? "" : base->bv_val,
+ (char *)ldap_pvt_scope2str( scope ),
+ BER_BVISNULL( filter ) ? "" : filter->bv_val );
+ Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
+
+ return -1;
+ }
+
+ mi = ( monitor_info_t * )be_monitor->be_private;
+
+ assert( mi != NULL );
+
+ if ( ndn_in != NULL ) {
+ ndn = *ndn_in;
+ }
+
+ if ( target_a == NULL && target_cb == NULL ) {
+ /* nothing to do */
+ return -1;
+ }
+
+ if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
+ && BER_BVISNULL( filter ) )
+ {
+ /* need a filter */
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_unregister_entry_%s(\"\"): "
+ "need a valid filter\n",
+ fname, 0, 0 );
+ return -1;
+ }
+
+ if ( monitor_subsys_opened ) {
+ Entry *e = NULL;
+ monitor_entry_t *mp = NULL;
+ int freeit = 0;
+
+ if ( BER_BVISNULL( &ndn ) ) {
+ if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
+ char buf[ SLAP_TEXT_BUFLEN ];
+
+ snprintf( buf, sizeof( buf ),
+ "monitor_back_unregister_entry_%s(\"\"): "
+ "base=\"%s\" scope=%d filter=\"%s\": "
+ "unable to find entry\n",
+ fname,
+ base->bv_val ? base->bv_val : "\"\"",
+ scope, filter->bv_val );
+
+ /* entry does not exist */
+ Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
+ return -1;
+ }
+
+ freeit = 1;
+ }
+
+ if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
+ /* entry does not exist */
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_unregister_entry(\"%s\"): "
+ "entry removal failed.\n",
+ ndn.bv_val, 0, 0 );
+ return -1;
+ }
+
+ mp = (monitor_entry_t *)e->e_private;
+ assert( mp != NULL );
+
+ if ( target_cb != NULL ) {
+ monitor_callback_t **cbp;
+
+ for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
+ if ( *cbp == target_cb ) {
+ if ( (*cbp)->mc_free ) {
+ (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
+ }
+ *cbp = (*cbp)->mc_next;
+ ch_free( target_cb );
+ break;
+ }
+ }
+ }
+
+ if ( target_a != NULL ) {
+ Attribute *a;
+
+ for ( a = target_a; a != NULL; a = a->a_next ) {
+ Modification mod = { 0 };
+ const char *text;
+ char textbuf[ SLAP_TEXT_BUFLEN ];
+
+ mod.sm_op = LDAP_MOD_DELETE;
+ mod.sm_desc = a->a_desc;
+ mod.sm_values = a->a_vals;
+ mod.sm_nvalues = a->a_nvals;
+
+ (void)modify_delete_values( e, &mod, 1,
+ &text, textbuf, sizeof( textbuf ) );
+ }
+ }
+
+ if ( freeit ) {
+ ber_memfree( ndn.bv_val );
+ }
+
+ if ( e ) {
+ monitor_cache_release( mi, e );
+ }
+
+ } else {
+ /* TODO: remove from limbo */
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+monitor_back_unregister_entry_callback(
+ struct berval *ndn,
+ monitor_callback_t *cb,
+ struct berval *base,
+ int scope,
+ struct berval *filter )
+{
+ /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
+ * unregister the callback; if a is not null, unregister the
+ * given attrs. In any case, call cb->cb_free */
+ return monitor_back_unregister_entry_attrs( ndn,
+ NULL, cb, base, scope, filter );
+}
+
monitor_subsys_t *
monitor_back_get_subsys( const char *name )
{
monitor_back_initialize(
BackendInfo *bi )
{
- monitor_subsys_t *ms;
static char *controls[] = {
LDAP_CONTROL_MANAGEDSAIT,
NULL
};
- monitor_info_t *mi = &monitor_info;
- int i;
- const char *text;
+
+ static ConfigTable monitorcfg[] = {
+ { NULL, NULL, 0, 0, 0, ARG_IGNORED,
+ NULL, NULL, NULL, NULL }
+ };
+
+ static ConfigOCs monitorocs[] = {
+ { "( OLcfgDbOc:4.1 "
+ "NAME 'olcMonitorConfig' "
+ "DESC 'Monitor backend configuration' "
+ "SUP olcDatabaseConfig "
+ ")",
+ Cft_Database, monitorcfg },
+ { NULL, 0, NULL }
+ };
struct m_s {
char *name;
offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
{ NULL, NULL, 0, -1 }
};
- static ConfigTable monitorcfg[] = {
- { NULL, NULL, 0, 0, 0, ARG_IGNORED,
- NULL, NULL, NULL, NULL }
- };
- static ConfigOCs monitorocs[] = {
- { "( OLcfgDbOc:4.1 "
- "NAME 'olcMonitorConfig' "
- "DESC 'Monitor backend configuration' "
- "SUP olcDatabaseConfig "
- ")",
- Cft_Database, monitorcfg },
- { NULL, 0, NULL }
- };
- int rc;
-
- bi->bi_controls = controls;
-
- bi->bi_init = 0;
- bi->bi_open = 0;
- bi->bi_config = monitor_back_config;
- bi->bi_close = 0;
- bi->bi_destroy = 0;
-
- bi->bi_db_init = monitor_back_db_init;
- bi->bi_db_config = monitor_back_db_config;
- bi->bi_db_open = monitor_back_db_open;
- bi->bi_db_close = 0;
- bi->bi_db_destroy = monitor_back_db_destroy;
-
- bi->bi_op_bind = monitor_back_bind;
- bi->bi_op_unbind = 0;
- bi->bi_op_search = monitor_back_search;
- bi->bi_op_compare = monitor_back_compare;
- bi->bi_op_modify = monitor_back_modify;
- bi->bi_op_modrdn = 0;
- bi->bi_op_add = 0;
- bi->bi_op_delete = 0;
- bi->bi_op_abandon = 0;
- bi->bi_extended = 0;
-
- bi->bi_entry_release_rw = 0;
- bi->bi_chk_referrals = 0;
- bi->bi_operational = monitor_back_operational;
-
- /*
- * hooks for slap tools
- */
- bi->bi_tool_entry_open = 0;
- bi->bi_tool_entry_close = 0;
- bi->bi_tool_entry_first = 0;
- bi->bi_tool_entry_next = 0;
- bi->bi_tool_entry_get = 0;
- bi->bi_tool_entry_put = 0;
- bi->bi_tool_entry_reindex = 0;
- bi->bi_tool_sync = 0;
- bi->bi_tool_dn2id_get = 0;
- bi->bi_tool_id2entry_get = 0;
- bi->bi_tool_entry_modify = 0;
-
- bi->bi_connection_init = 0;
- bi->bi_connection_destroy = 0;
+ static struct {
+ char *name;
+ char *oid;
+ } s_oid[] = {
+ { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
+ { "olmSubSystemAttributes", "olmAttributes:0" },
+ { "olmGenericAttributes", "olmSubSystemAttributes:0" },
+ { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
+
+ /* for example, back-bdb specific attrs
+ * are in "olmDatabaseAttributes:1"
+ *
+ * NOTE: developers, please record here OID assignments
+ * for other modules */
+
+ { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
+ { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
+ { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
+ { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
+
+ /* for example, back-bdb specific objectClasses
+ * are in "olmDatabaseObjectClasses:1"
+ *
+ * NOTE: developers, please record here OID assignments
+ * for other modules */
+
+ { NULL }
+ };
- /*
- * configuration objectClasses (fake)
- */
- bi->bi_cf_ocs = monitorocs;
+ int i, rc;
+ const char *text;
+ monitor_info_t *mi = &monitor_info;
- rc = config_register_schema( monitorcfg, monitorocs );
- if ( rc ) {
- return rc;
- }
+ for ( i = 0; s_oid[ i ].name; i++ ) {
+ char *argv[ 3 ];
+
+ argv[ 0 ] = "monitor";
+ argv[ 1 ] = s_oid[ i ].name;
+ argv[ 2 ] = s_oid[ i ].oid;
- /*
- * register subsys
- */
- for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
- if ( monitor_back_register_subsys( ms ) ) {
- return -1;
+ if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_back_initialize: unable to add "
+ "objectIdentifier \"%s=%s\"\n",
+ s_oid[ i ].name, s_oid[ i ].oid, 0 );
+ return 1;
}
}
}
if ( at->at_oid == NULL ) {
+ ldap_attributetype_free(at);
Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
"null OID for attributeType \"%s\"\n",
mat[ i ].name, 0, 0 );
code = at_add(at, 0, NULL, &err);
if ( code ) {
+ ldap_attributetype_free(at);
Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
"%s in attributeType \"%s\"\n",
scherr2str(code), mat[ i ].name, 0 );
}
if ( oc->oc_oid == NULL ) {
+ ldap_objectclass_free(oc);
Debug( LDAP_DEBUG_ANY,
"objectclass \"%s\" has no OID\n" ,
moc[ i ].name, 0, 0 );
code = oc_add(oc, 0, NULL, &err);
if ( code ) {
+ ldap_objectclass_free(oc);
Debug( LDAP_DEBUG_ANY,
"objectclass \"%s\": %s \"%s\"\n" ,
moc[ i ].name, scherr2str(code), err );
return -1;
}
-
ldap_memfree(oc);
Oc = oc_find( moc[ i ].name );
((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
}
+ bi->bi_controls = controls;
+
+ bi->bi_init = 0;
+ bi->bi_open = 0;
+ bi->bi_config = monitor_back_config;
+ bi->bi_close = 0;
+ bi->bi_destroy = 0;
+
+ bi->bi_db_init = monitor_back_db_init;
+#if 0
+ bi->bi_db_config = monitor_back_db_config;
+#endif
+ bi->bi_db_open = monitor_back_db_open;
+ bi->bi_db_close = 0;
+ bi->bi_db_destroy = monitor_back_db_destroy;
+
+ bi->bi_op_bind = monitor_back_bind;
+ bi->bi_op_unbind = 0;
+ bi->bi_op_search = monitor_back_search;
+ bi->bi_op_compare = monitor_back_compare;
+ bi->bi_op_modify = monitor_back_modify;
+ bi->bi_op_modrdn = 0;
+ bi->bi_op_add = 0;
+ bi->bi_op_delete = 0;
+ bi->bi_op_abandon = 0;
+
+ bi->bi_extended = 0;
+
+ bi->bi_entry_release_rw = 0;
+ bi->bi_chk_referrals = 0;
+ bi->bi_operational = monitor_back_operational;
+
+ /*
+ * hooks for slap tools
+ */
+ bi->bi_tool_entry_open = 0;
+ bi->bi_tool_entry_close = 0;
+ bi->bi_tool_entry_first = 0;
+ bi->bi_tool_entry_next = 0;
+ bi->bi_tool_entry_get = 0;
+ bi->bi_tool_entry_put = 0;
+ bi->bi_tool_entry_reindex = 0;
+ bi->bi_tool_sync = 0;
+ bi->bi_tool_dn2id_get = 0;
+ bi->bi_tool_id2entry_get = 0;
+ bi->bi_tool_entry_modify = 0;
+
+ bi->bi_connection_init = 0;
+ bi->bi_connection_destroy = 0;
+
+ /*
+ * configuration objectClasses (fake)
+ */
+ bi->bi_cf_ocs = monitorocs;
+
+ rc = config_register_schema( monitorcfg, monitorocs );
+ if ( rc ) {
+ return rc;
+ }
+
return 0;
}
monitor_back_db_init(
BackendDB *be )
{
- int rc;
- struct berval dn, ndn;
- struct berval bv;
+ int rc;
+ struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
+ pdn,
+ ndn;
+ BackendDB *be2;
+
+ monitor_subsys_t *ms;
+
+ /*
+ * register subsys
+ */
+ for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
+ if ( monitor_back_register_subsys( ms ) ) {
+ return -1;
+ }
+ }
/*
* database monitor can be defined once only
/* indicate system schema supported */
SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
- dn.bv_val = SLAPD_MONITOR_DN;
- dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
-
- rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
+ rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
- "unable to normalize monitor DN \"%s\" (%d)\n",
+ "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
dn.bv_val, rc, 0 );
return -1;
}
- ber_dupbv( &bv, &dn );
- ber_bvarray_add( &be->be_suffix, &bv );
+ ber_bvarray_add( &be->be_suffix, &pdn );
ber_bvarray_add( &be->be_nsuffix, &ndn );
/* NOTE: only one monitor database is allowed,
be->be_private = &monitor_info;
+ be2 = select_backend( &ndn, 0, 0 );
+ if ( be2 != be ) {
+ char *type = be2->bd_info->bi_type;
+
+ if ( overlay_is_over( be2 ) ) {
+ slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
+ type = oi->oi_orig->bi_type;
+ }
+
+ Debug( LDAP_DEBUG_ANY,
+ "\"monitor\" database serving namingContext \"%s\" "
+ "is hidden by \"%s\" database serving namingContext \"%s\".\n",
+ pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
+ return -1;
+ }
+
return 0;
}
{
monitor_info_t *mi = (monitor_info_t *)be->be_private;
struct monitor_subsys_t **ms;
- Entry *e, **ep;
+ Entry *e, **ep, *root;
monitor_entry_t *mp;
int i;
- char buf[ BACKMONITOR_BUFSIZE ];
- struct berval bv;
+ struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
struct tm *tms;
#ifdef HAVE_GMTIME_R
struct tm tm_buf;
#endif
static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
+ struct berval desc[] = {
+ BER_BVC("This subtree contains monitoring/managing objects."),
+ BER_BVC("This object contains information about this server."),
+ BER_BVC("Most of the information is held in operational"
+ " attributes, which must be explicitly requested."),
+ BER_BVNULL };
assert( be_monitor != NULL );
if ( be != be_monitor ) {
if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
+ BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
} else {
mi->mi_creatorsName = be->be_rootdn;
+ mi->mi_ncreatorsName = be->be_rootndn;
}
/*
* creates the "cn=Monitor" entry
*/
- snprintf( buf, sizeof( buf ),
- "dn: %s\n"
- "objectClass: %s\n"
- "structuralObjectClass: %s\n"
- "cn: Monitor\n"
- "description: This subtree contains monitoring/managing objects.\n"
- "description: This object contains information about this server.\n"
- "description: Most of the information is held in operational"
- " attributeTypes, which must be explicitly requested.\n"
- "creatorsName: %s\n"
- "modifiersName: %s\n"
- "createTimestamp: %s\n"
- "modifyTimestamp: %s\n",
- SLAPD_MONITOR_DN,
- mi->mi_oc_monitorServer->soc_cname.bv_val,
- mi->mi_oc_monitorServer->soc_cname.bv_val,
- mi->mi_creatorsName.bv_val,
- mi->mi_creatorsName.bv_val,
- mi->mi_startTime.bv_val,
- mi->mi_startTime.bv_val );
-
- e = str2entry( buf );
+ e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
+ NULL, NULL );
+
if ( e == NULL) {
Debug( LDAP_DEBUG_ANY,
"unable to create \"%s\" entry\n",
return( -1 );
}
+ attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
+
bv.bv_val = strchr( (char *) Versionstr, '$' );
if ( bv.bv_val != NULL ) {
char *end;
SLAPD_MONITOR_DN, 0, 0 );
return -1;
}
+ root = e;
/*
* Create all the subsystem specific entries
return( -1 );
}
- dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
- dn.bv_val = ch_malloc( dn.bv_len + 1 );
- strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
- strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
- rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
- &monitor_subsys[ i ]->mss_ndn, NULL );
- free( dn.bv_val );
- if ( rc != LDAP_SUCCESS ) {
- Debug( LDAP_DEBUG_ANY,
- "monitor DN \"%s\" is invalid\n",
- dn.bv_val, 0, 0 );
- return( -1 );
- }
+ e = monitor_entry_stub( &root->e_name, &root->e_nname,
+ &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
+ NULL, NULL );
- snprintf( buf, sizeof( buf ),
- "dn: %s\n"
- "objectClass: %s\n"
- "structuralObjectClass: %s\n"
- "cn: %s\n"
- "creatorsName: %s\n"
- "modifiersName: %s\n"
- "createTimestamp: %s\n"
- "modifyTimestamp: %s\n",
- monitor_subsys[ i ]->mss_dn.bv_val,
- mi->mi_oc_monitorContainer->soc_cname.bv_val,
- mi->mi_oc_monitorContainer->soc_cname.bv_val,
- monitor_subsys[ i ]->mss_name,
- mi->mi_creatorsName.bv_val,
- mi->mi_creatorsName.bv_val,
- mi->mi_startTime.bv_val,
- mi->mi_startTime.bv_val );
-
- e = str2entry( buf );
-
if ( e == NULL) {
Debug( LDAP_DEBUG_ANY,
"unable to create \"%s\" entry\n",
monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
return( -1 );
}
+ monitor_subsys[i]->mss_dn = e->e_name;
+ monitor_subsys[i]->mss_ndn = e->e_nname;
if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
attr_merge_normalize( e, slap_schema.si_ad_description,
return SLAP_CONF_UNKNOWN;
}
+#if 0
int
monitor_back_db_config(
Backend *be,
int argc,
char **argv )
{
-#if 0
monitor_info_t *mi = ( monitor_info_t * )be->be_private;
-#endif
/*
* eventually, will hold database specific configuration parameters
*/
return SLAP_CONF_UNKNOWN;
}
+#endif
int
monitor_back_db_destroy(
{
monitor_info_t *mi = ( monitor_info_t * )be->be_private;
+ if ( mi == NULL ) {
+ return -1;
+ }
+
/*
* FIXME: destroys all the data
*/
int i;
for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
+ if ( monitor_subsys[ i ]->mss_destroy ) {
+ monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
+ }
+
if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
}
ch_free( monitor_subsys );
}
+ ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
+
+ be->be_private = NULL;
+
return 0;
}