1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
30 #include "back-monitor.h"
32 #undef INTEGRATE_CORE_SCHEMA
35 * used by many functions to add description to entries
37 * WARNING: be_monitor may change as new databases are added,
38 * so it should not be used outside monitor_back_db_init()
39 * until monitor_back_db_open is called.
41 BackendDB *be_monitor = NULL;
43 static struct monitor_subsys_t **monitor_subsys = NULL;
44 static int monitor_subsys_opened = 0;
49 * the known subsystems are added to the subsystems
50 * array at backend initialization; other subsystems
51 * may be added by calling monitor_back_register_subsys()
52 * before the database is opened (e.g. by other backends
53 * or by overlays or modules).
55 static struct monitor_subsys_t known_monitor_subsys[] = {
57 SLAPD_MONITOR_BACKEND_NAME,
58 BER_BVNULL, BER_BVNULL, BER_BVNULL,
59 MONITOR_F_PERSISTENT_CH,
60 monitor_subsys_backend_init,
65 SLAPD_MONITOR_CONN_NAME,
66 BER_BVNULL, BER_BVNULL, BER_BVNULL,
67 MONITOR_F_VOLATILE_CH,
68 monitor_subsys_conn_init,
69 monitor_subsys_conn_update,
70 monitor_subsys_conn_create,
73 SLAPD_MONITOR_DATABASE_NAME,
74 BER_BVNULL, BER_BVNULL, BER_BVNULL,
75 MONITOR_F_PERSISTENT_CH,
76 monitor_subsys_database_init,
79 monitor_subsys_database_modify
81 SLAPD_MONITOR_LISTENER_NAME,
82 BER_BVNULL, BER_BVNULL, BER_BVNULL,
83 MONITOR_F_PERSISTENT_CH,
84 monitor_subsys_listener_init,
89 SLAPD_MONITOR_LOG_NAME,
90 BER_BVNULL, BER_BVNULL, BER_BVNULL,
92 monitor_subsys_log_init,
95 monitor_subsys_log_modify
97 SLAPD_MONITOR_OPS_NAME,
98 BER_BVNULL, BER_BVNULL, BER_BVNULL,
99 MONITOR_F_PERSISTENT_CH,
100 monitor_subsys_ops_init,
101 monitor_subsys_ops_update,
105 SLAPD_MONITOR_OVERLAY_NAME,
106 BER_BVNULL, BER_BVNULL, BER_BVNULL,
107 MONITOR_F_PERSISTENT_CH,
108 monitor_subsys_overlay_init,
113 SLAPD_MONITOR_SASL_NAME,
114 BER_BVNULL, BER_BVNULL, BER_BVNULL,
121 SLAPD_MONITOR_SENT_NAME,
122 BER_BVNULL, BER_BVNULL, BER_BVNULL,
123 MONITOR_F_PERSISTENT_CH,
124 monitor_subsys_sent_init,
125 monitor_subsys_sent_update,
129 SLAPD_MONITOR_THREAD_NAME,
130 BER_BVNULL, BER_BVNULL, BER_BVNULL,
131 MONITOR_F_PERSISTENT_CH,
132 monitor_subsys_thread_init,
133 monitor_subsys_thread_update,
137 SLAPD_MONITOR_TIME_NAME,
138 BER_BVNULL, BER_BVNULL, BER_BVNULL,
139 MONITOR_F_PERSISTENT_CH,
140 monitor_subsys_time_init,
141 monitor_subsys_time_update,
145 SLAPD_MONITOR_TLS_NAME,
146 BER_BVNULL, BER_BVNULL, BER_BVNULL,
153 SLAPD_MONITOR_RWW_NAME,
154 BER_BVNULL, BER_BVNULL, BER_BVNULL,
155 MONITOR_F_PERSISTENT_CH,
156 monitor_subsys_rww_init,
157 monitor_subsys_rww_update,
164 monitor_back_register_subsys( monitor_subsys_t *ms )
168 if ( monitor_subsys ) {
169 for ( ; monitor_subsys[ i ] != NULL; i++ )
170 /* just count'em */ ;
173 monitor_subsys = ch_realloc( monitor_subsys,
174 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
176 if ( monitor_subsys == NULL ) {
180 monitor_subsys[ i ] = ms;
181 monitor_subsys[ i + 1 ] = NULL;
183 /* if a subsystem is registered __AFTER__ subsystem
184 * initialization (depending on the sequence the databases
185 * are listed in slapd.conf), init it */
186 if ( monitor_subsys_opened ) {
188 /* FIXME: this should only be possible
189 * if be_monitor is already initialized */
190 assert( be_monitor );
192 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
196 ms->mss_flags |= MONITOR_F_OPENED;
209 typedef struct entry_limbo_t {
213 struct berval el_ndn;
214 struct berval el_base;
216 struct berval el_filter;
217 monitor_callback_t *el_cb;
218 struct entry_limbo_t *el_next;
222 monitor_back_register_entry(
224 monitor_callback_t *cb )
226 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
228 assert( mi != NULL );
230 assert( e->e_private == NULL );
232 if ( monitor_subsys_opened ) {
233 Entry *e_parent = NULL,
236 struct berval pdn = BER_BVNULL;
237 monitor_entry_t *mp = NULL,
241 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
243 Debug( LDAP_DEBUG_ANY,
244 "monitor_back_register_entry(\"%s\"): "
246 e->e_name.bv_val, 0, 0 );
247 monitor_cache_release( mi, e_parent );
251 dnParent( &e->e_nname, &pdn );
252 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
253 /* parent does not exist */
254 Debug( LDAP_DEBUG_ANY,
255 "monitor_back_register_entry(\"%s\"): "
256 "parent \"%s\" not found\n",
257 e->e_name.bv_val, pdn.bv_val, 0 );
261 assert( e_parent->e_private != NULL );
262 mp_parent = ( monitor_entry_t * )e_parent->e_private;
264 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
265 /* entry is volatile; cannot append children */
266 Debug( LDAP_DEBUG_ANY,
267 "monitor_back_register_entry(\"%s\"): "
268 "parent \"%s\" is volatile\n",
269 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
274 mp = monitor_entrypriv_create();
276 Debug( LDAP_DEBUG_ANY,
277 "monitor_back_register_entry(\"%s\"): "
278 "monitor_entrypriv_create() failed\n",
279 e->e_name.bv_val, 0, 0 );
284 e_new = entry_dup( e );
285 if ( e_new == NULL ) {
286 Debug( LDAP_DEBUG_ANY,
287 "monitor_back_register_entry(\"%s\"): "
288 "entry_dup() failed\n",
289 e->e_name.bv_val, 0, 0 );
294 e_new->e_private = ( void * )mp;
295 mp->mp_info = mp_parent->mp_info;
296 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
299 ep = &mp_parent->mp_children;
301 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
302 ep = &mp_parent->mp_next;
306 if ( monitor_cache_add( mi, e_new ) ) {
307 Debug( LDAP_DEBUG_ANY,
308 "monitor_back_register_entry(\"%s\"): "
309 "unable to add entry\n",
310 e->e_name.bv_val, 0, 0 );
321 e_new->e_private = NULL;
327 monitor_cache_release( mi, e_parent );
331 entry_limbo_t **elpp, el = { 0 };
333 el.el_type = LIMBO_ENTRY;
335 el.el_e = entry_dup( e );
336 if ( el.el_e == NULL ) {
337 Debug( LDAP_DEBUG_ANY,
338 "monitor_back_register_entry(\"%s\"): "
339 "entry_dup() failed\n",
340 e->e_name.bv_val, 0, 0 );
346 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
348 elpp = &(*elpp)->el_next )
351 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
352 if ( *elpp == NULL ) {
353 el.el_e->e_private = NULL;
354 entry_free( el.el_e );
366 monitor_back_register_entry_parent(
368 monitor_callback_t *cb,
371 struct berval *filter )
373 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
374 struct berval ndn = BER_BVNULL;
376 assert( mi != NULL );
378 assert( e->e_private == NULL );
380 if ( BER_BVISNULL( filter ) ) {
382 Debug( LDAP_DEBUG_ANY,
383 "monitor_back_register_entry_parent(\"\"): "
384 "need a valid filter\n",
389 if ( monitor_subsys_opened ) {
390 Entry *e_parent = NULL,
393 struct berval e_name = BER_BVNULL,
394 e_nname = BER_BVNULL;
395 monitor_entry_t *mp = NULL,
399 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
400 /* entry does not exist */
401 Debug( LDAP_DEBUG_ANY,
402 "monitor_back_register_entry_*(\"\"): "
403 "base=%s scope=%d filter=%s : "
404 "unable to find entry\n",
405 base->bv_val ? base->bv_val : "\"\"",
406 scope, filter->bv_val );
410 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
411 /* entry does not exist */
412 Debug( LDAP_DEBUG_ANY,
413 "monitor_back_register_entry_parent(\"%s\"): "
414 "parent entry does not exist\n",
420 assert( e_parent->e_private != NULL );
421 mp_parent = ( monitor_entry_t * )e_parent->e_private;
423 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
424 /* entry is volatile; cannot append callback */
425 Debug( LDAP_DEBUG_ANY,
426 "monitor_back_register_entry_*(\"%s\"): "
427 "entry is volatile\n",
428 e_parent->e_name.bv_val, 0, 0 );
433 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
434 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
436 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
437 /* entry already exists */
438 Debug( LDAP_DEBUG_ANY,
439 "monitor_back_register_entry_parent(\"%s\"): "
440 "entry already exists\n",
441 e_name.bv_val, 0, 0 );
442 monitor_cache_release( mi, e_new );
447 mp = monitor_entrypriv_create();
449 Debug( LDAP_DEBUG_ANY,
450 "monitor_back_register_entry_parent(\"%s\"): "
451 "monitor_entrypriv_create() failed\n",
452 e->e_name.bv_val, 0, 0 );
457 e_new = entry_dup( e );
458 if ( e_new == NULL ) {
459 Debug( LDAP_DEBUG_ANY,
460 "monitor_back_register_entry(\"%s\"): "
461 "entry_dup() failed\n",
462 e->e_name.bv_val, 0, 0 );
466 ch_free( e_new->e_name.bv_val );
467 ch_free( e_new->e_nname.bv_val );
468 e_new->e_name = e_name;
469 e_new->e_nname = e_nname;
471 e_new->e_private = ( void * )mp;
472 mp->mp_info = mp_parent->mp_info;
473 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
476 ep = &mp_parent->mp_children;
478 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
479 ep = &mp_parent->mp_next;
483 if ( monitor_cache_add( mi, e_new ) ) {
484 Debug( LDAP_DEBUG_ANY,
485 "monitor_back_register_entry(\"%s\"): "
486 "unable to add entry\n",
487 e->e_name.bv_val, 0, 0 );
493 if ( !BER_BVISNULL( &ndn ) ) {
494 ch_free( ndn.bv_val );
502 e_new->e_private = NULL;
508 monitor_cache_release( mi, e_parent );
512 entry_limbo_t **elpp, el = { 0 };
514 el.el_type = LIMBO_ENTRY_PARENT;
516 el.el_e = entry_dup( e );
517 if ( el.el_e == NULL ) {
518 Debug( LDAP_DEBUG_ANY,
519 "monitor_back_register_entry(\"%s\"): "
520 "entry_dup() failed\n",
521 e->e_name.bv_val, 0, 0 );
525 if ( !BER_BVISNULL( base ) ) {
526 ber_dupbv( &el.el_base, base );
529 if ( !BER_BVISNULL( filter ) ) {
530 ber_dupbv( &el.el_filter, filter );
535 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
537 elpp = &(*elpp)->el_next )
540 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
541 if ( *elpp == NULL ) {
542 el.el_e->e_private = NULL;
543 entry_free( el.el_e );
555 monitor_filter2ndn_cb( Operation *op, SlapReply *rs )
557 if ( rs->sr_type == REP_SEARCH ) {
558 struct berval *ndn = op->o_callback->sc_private;
560 ber_dupbv( ndn, &rs->sr_entry->e_nname );
567 monitor_filter2ndn( struct berval *base, int scope, struct berval *filter,
570 Connection conn = { 0 };
571 char opbuf[OPERATION_BUFFER_SIZE];
573 SlapReply rs = { 0 };
574 slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
579 if ( be_monitor == NULL ) {
583 op = (Operation *)opbuf;
584 connection_fake_init( &conn, op, &conn );
586 op->o_tag = LDAP_REQ_SEARCH;
588 /* use global malloc for now */
589 op->o_tmpmemctx = NULL;
590 op->o_tmpmfuncs = &ch_mfuncs;
592 op->o_bd = be_monitor;
593 if ( base == NULL || BER_BVISNULL( base ) ) {
594 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
596 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
600 if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn,
601 op->o_tmpmemctx ) ) {
606 op->o_callback = &cb;
607 cb.sc_private = (void *)ndn;
609 op->ors_scope = scope;
610 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
611 op->ors_filter = str2filter_x( op, filter->bv_val );
612 op->ors_attrs = slap_anlist_no_attrs;
613 op->ors_attrsonly = 0;
614 op->ors_tlimit = SLAP_NO_LIMIT;
616 op->ors_limit = NULL;
617 op->ors_deref = LDAP_DEREF_NEVER;
620 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
622 rc = op->o_bd->be_search( op, &rs );
624 filter_free_x( op, op->ors_filter );
625 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
626 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
627 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
633 switch ( rs.sr_err ) {
635 if ( BER_BVISNULL( ndn ) ) {
640 case LDAP_SIZELIMIT_EXCEEDED:
642 if ( !BER_BVISNULL( ndn ) ) {
643 ber_memfree( ndn->bv_val );
654 monitor_back_register_entry_attrs(
655 struct berval *ndn_in,
657 monitor_callback_t *cb,
660 struct berval *filter )
662 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
663 struct berval ndn = BER_BVNULL;
665 assert( mi != NULL );
667 if ( ndn_in != NULL ) {
671 if ( a == NULL && cb == NULL ) {
676 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
677 && BER_BVISNULL( filter ) )
680 Debug( LDAP_DEBUG_ANY,
681 "monitor_back_register_entry_*(\"\"): "
682 "need a valid filter\n",
687 if ( monitor_subsys_opened ) {
689 Attribute **atp = NULL;
690 monitor_entry_t *mp = NULL;
691 monitor_callback_t **mcp = NULL;
695 if ( BER_BVISNULL( &ndn ) ) {
696 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
697 /* entry does not exist */
698 Debug( LDAP_DEBUG_ANY,
699 "monitor_back_register_entry_*(\"\"): "
700 "base=%s scope=%d filter=%s : "
701 "unable to find entry\n",
702 base->bv_val ? base->bv_val : "\"\"",
703 scope, filter->bv_val );
710 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
711 /* entry does not exist */
712 Debug( LDAP_DEBUG_ANY,
713 "monitor_back_register_entry_*(\"%s\"): "
714 "entry does not exist\n",
720 assert( e->e_private != NULL );
721 mp = ( monitor_entry_t * )e->e_private;
723 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
724 /* entry is volatile; cannot append callback */
725 Debug( LDAP_DEBUG_ANY,
726 "monitor_back_register_entry_*(\"%s\"): "
727 "entry is volatile\n",
728 e->e_name.bv_val, 0, 0 );
734 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
735 /* just get to last */ ;
737 *atp = attrs_dup( a );
738 if ( *atp == NULL ) {
739 Debug( LDAP_DEBUG_ANY,
740 "monitor_back_register_entry_*(\"%s\"): "
741 "attrs_dup() failed\n",
742 e->e_name.bv_val, 0, 0 );
749 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
752 /* NOTE: we do not clear cb->mc_next, so this function
753 * can be used to append a list of callbacks */
766 ber_memfree( ndn.bv_val );
770 monitor_cache_release( mi, e );
774 entry_limbo_t **elpp, el = { 0 };
776 el.el_type = LIMBO_ATTRS;
777 if ( !BER_BVISNULL( &ndn ) ) {
778 ber_dupbv( &el.el_ndn, &ndn );
780 if ( !BER_BVISNULL( base ) ) {
781 ber_dupbv( &el.el_base, base);
784 if ( !BER_BVISNULL( filter ) ) {
785 ber_dupbv( &el.el_filter, filter );
788 el.el_a = attrs_dup( a );
791 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
793 elpp = &(*elpp)->el_next )
796 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
797 if ( *elpp == NULL ) {
798 el.el_e->e_private = NULL;
799 entry_free( el.el_e );
811 monitor_back_register_entry_callback(
813 monitor_callback_t *cb,
816 struct berval *filter )
818 return monitor_back_register_entry_attrs( ndn, NULL, cb,
819 base, scope, filter );
823 monitor_back_get_subsys( const char *name )
825 if ( monitor_subsys != NULL ) {
828 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
829 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
830 return monitor_subsys[ i ];
839 monitor_back_get_subsys_by_dn( struct berval *ndn, int sub )
841 if ( monitor_subsys != NULL ) {
845 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
846 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
847 return monitor_subsys[ i ];
852 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
853 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
854 return monitor_subsys[ i ];
864 monitor_back_initialize(
868 monitor_subsys_t *ms;
869 static char *controls[] = {
870 LDAP_CONTROL_MANAGEDSAIT,
874 bi->bi_controls = controls;
878 bi->bi_config = monitor_back_config;
882 bi->bi_db_init = monitor_back_db_init;
883 bi->bi_db_config = monitor_back_db_config;
884 bi->bi_db_open = monitor_back_db_open;
886 bi->bi_db_destroy = monitor_back_db_destroy;
888 bi->bi_op_bind = monitor_back_bind;
889 bi->bi_op_unbind = 0;
890 bi->bi_op_search = monitor_back_search;
891 bi->bi_op_compare = monitor_back_compare;
892 bi->bi_op_modify = monitor_back_modify;
893 bi->bi_op_modrdn = 0;
895 bi->bi_op_delete = 0;
896 bi->bi_op_abandon = 0;
900 bi->bi_entry_release_rw = 0;
901 bi->bi_chk_referrals = 0;
902 bi->bi_operational = monitor_back_operational;
905 * hooks for slap tools
907 bi->bi_tool_entry_open = 0;
908 bi->bi_tool_entry_close = 0;
909 bi->bi_tool_entry_first = 0;
910 bi->bi_tool_entry_next = 0;
911 bi->bi_tool_entry_get = 0;
912 bi->bi_tool_entry_put = 0;
913 bi->bi_tool_entry_reindex = 0;
914 bi->bi_tool_sync = 0;
915 bi->bi_tool_dn2id_get = 0;
916 bi->bi_tool_id2entry_get = 0;
917 bi->bi_tool_entry_modify = 0;
919 bi->bi_connection_init = 0;
920 bi->bi_connection_destroy = 0;
922 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
923 if ( monitor_back_register_subsys( ms ) ) {
932 monitor_back_db_init(
938 struct berval dn, ndn;
948 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
950 "DESC 'OpenLDAP system monitoring' "
951 "SUP top STRUCTURAL "
956 #if 0 /* temporarily disabled */
967 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
968 offsetof(monitor_info_t, mi_oc_monitor) },
969 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
970 "NAME 'monitorServer' "
971 "DESC 'Server monitoring root entry' "
972 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
973 offsetof(monitor_info_t, mi_oc_monitorServer) },
974 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
975 "NAME 'monitorContainer' "
976 "DESC 'monitor container class' "
977 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
978 offsetof(monitor_info_t, mi_oc_monitorContainer) },
979 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
980 "NAME 'monitorCounterObject' "
981 "DESC 'monitor counter class' "
982 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
983 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
984 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
985 "NAME 'monitorOperation' "
986 "DESC 'monitor operation class' "
987 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
988 offsetof(monitor_info_t, mi_oc_monitorOperation) },
989 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
990 "NAME 'monitorConnection' "
991 "DESC 'monitor connection class' "
992 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
993 offsetof(monitor_info_t, mi_oc_monitorConnection) },
994 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
995 "NAME 'managedObject' "
996 "DESC 'monitor managed entity class' "
997 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
998 offsetof(monitor_info_t, mi_oc_managedObject) },
999 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.14 "
1000 "NAME 'monitoredObject' "
1001 "DESC 'monitor monitored entity class' "
1002 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1003 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1004 { NULL, NULL, 0, -1 }
1006 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
1007 "NAME 'monitoredInfo' "
1008 "DESC 'monitored info' "
1010 "EQUALITY caseIgnoreMatch "
1011 "SUBSTR caseIgnoreSubstringsMatch "
1012 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1013 "NO-USER-MODIFICATION "
1014 "USAGE directoryOperation )", SLAP_AT_HIDE,
1015 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1016 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
1017 "NAME 'managedInfo' "
1018 "DESC 'monitor managed info' "
1019 "SUP name )", SLAP_AT_HIDE,
1020 offsetof(monitor_info_t, mi_ad_managedInfo) },
1021 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
1022 "NAME 'monitorCounter' "
1023 "DESC 'monitor counter' "
1024 "EQUALITY integerMatch "
1025 "ORDERING integerOrderingMatch "
1026 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1027 "NO-USER-MODIFICATION "
1028 "USAGE directoryOperation )", SLAP_AT_HIDE,
1029 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1030 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
1031 "NAME 'monitorOpCompleted' "
1032 "DESC 'monitor completed operations' "
1033 "SUP monitorCounter "
1034 "NO-USER-MODIFICATION "
1035 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1036 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1037 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
1038 "NAME 'monitorOpInitiated' "
1039 "DESC 'monitor initiated operations' "
1040 "SUP monitorCounter "
1041 "NO-USER-MODIFICATION "
1042 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1043 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1044 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
1045 "NAME 'monitorConnectionNumber' "
1046 "DESC 'monitor connection number' "
1047 "SUP monitorCounter "
1048 "NO-USER-MODIFICATION "
1049 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1050 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1051 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
1052 "NAME 'monitorConnectionAuthzDN' "
1053 "DESC 'monitor connection authorization DN' "
1054 /* "SUP distinguishedName " */
1055 "EQUALITY distinguishedNameMatch "
1056 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1057 "NO-USER-MODIFICATION "
1058 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1059 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1060 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
1061 "NAME 'monitorConnectionLocalAddress' "
1062 "DESC 'monitor connection local address' "
1063 "SUP monitoredInfo "
1064 "NO-USER-MODIFICATION "
1065 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1066 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1067 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
1068 "NAME 'monitorConnectionPeerAddress' "
1069 "DESC 'monitor connection peer address' "
1070 "SUP monitoredInfo "
1071 "NO-USER-MODIFICATION "
1072 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1073 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1074 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.24 "
1075 "NAME 'monitorTimestamp' "
1076 "DESC 'monitor timestamp' "
1077 "EQUALITY generalizedTimeMatch "
1078 "ORDERING generalizedTimeOrderingMatch "
1079 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1081 "NO-USER-MODIFICATION "
1082 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1083 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1084 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.27 "
1085 "NAME 'monitorOverlay' "
1086 "DESC 'name of overlays defined for a given database' "
1087 "SUP monitoredInfo "
1088 "NO-USER-MODIFICATION "
1089 "USAGE directoryOperation )", SLAP_AT_HIDE,
1090 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1091 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.31 "
1093 "DESC 'read/write status of a given database' "
1094 "EQUALITY booleanMatch "
1095 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1097 "USAGE directoryOperation )", SLAP_AT_HIDE,
1098 offsetof(monitor_info_t, mi_ad_readOnly) },
1099 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.32 "
1100 "NAME 'restrictedOperation' "
1101 "DESC 'name of restricted operation for a given database' "
1102 "SUP managedInfo )", SLAP_AT_HIDE,
1103 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1104 { "monitorConnectionProtocol", "( 1.3.6.1.4.1.4203.666.1.39 "
1105 "NAME 'monitorConnectionProtocol' "
1106 "DESC 'monitor connection protocol' "
1107 "SUP monitoredInfo "
1108 "NO-USER-MODIFICATION "
1109 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1110 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1111 { "monitorConnectionOpsReceived", "( 1.3.6.1.4.1.4203.666.1.40 "
1112 "NAME 'monitorConnectionOpsReceived' "
1113 "DESC 'monitor number of operations received by the connection' "
1114 "SUP monitorCounter "
1115 "NO-USER-MODIFICATION "
1116 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1117 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1118 { "monitorConnectionOpsExecuting", "( 1.3.6.1.4.1.4203.666.1.41 "
1119 "NAME 'monitorConnectionOpsExecuting' "
1120 "DESC 'monitor number of operations in execution within the connection' "
1121 "SUP monitorCounter "
1122 "NO-USER-MODIFICATION "
1123 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1124 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1125 { "monitorConnectionOpsPending", "( 1.3.6.1.4.1.4203.666.1.42 "
1126 "NAME 'monitorConnectionOpsPending' "
1127 "DESC 'monitor number of pending operations within the connection' "
1128 "SUP monitorCounter "
1129 "NO-USER-MODIFICATION "
1130 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1131 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1132 { "monitorConnectionOpsCompleted", "( 1.3.6.1.4.1.4203.666.1.43 "
1133 "NAME 'monitorConnectionOpsCompleted' "
1134 "DESC 'monitor number of operations completed within the connection' "
1135 "SUP monitorCounter "
1136 "NO-USER-MODIFICATION "
1137 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1138 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1139 { "monitorConnectionGet", "( 1.3.6.1.4.1.4203.666.1.44 "
1140 "NAME 'monitorConnectionGet' "
1141 "DESC 'number of times connection_get() was called so far' "
1142 "SUP monitorCounter "
1143 "NO-USER-MODIFICATION "
1144 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1145 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1146 { "monitorConnectionRead", "( 1.3.6.1.4.1.4203.666.1.45 "
1147 "NAME 'monitorConnectionRead' "
1148 "DESC 'number of times connection_read() was called so far' "
1149 "SUP monitorCounter "
1150 "NO-USER-MODIFICATION "
1151 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1152 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1153 { "monitorConnectionWrite", "( 1.3.6.1.4.1.4203.666.1.46 "
1154 "NAME 'monitorConnectionWrite' "
1155 "DESC 'number of times connection_write() was called so far' "
1156 "SUP monitorCounter "
1157 "NO-USER-MODIFICATION "
1158 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1159 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1160 { "monitorConnectionMask", "( 1.3.6.1.4.1.4203.666.1.47 "
1161 "NAME 'monitorConnectionMask' "
1162 "DESC 'monitor connection mask' "
1163 "SUP monitoredInfo "
1164 "NO-USER-MODIFICATION "
1165 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1166 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1167 { "monitorConnectionListener", "( 1.3.6.1.4.1.4203.666.1.48 "
1168 "NAME 'monitorConnectionListener' "
1169 "DESC 'monitor connection listener' "
1170 "SUP monitoredInfo "
1171 "NO-USER-MODIFICATION "
1172 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1173 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1174 { "monitorConnectionPeerDomain", "( 1.3.6.1.4.1.4203.666.1.49 "
1175 "NAME 'monitorConnectionPeerDomain' "
1176 "DESC 'monitor connection peer domain' "
1177 "SUP monitoredInfo "
1178 "NO-USER-MODIFICATION "
1179 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1180 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1181 { "monitorConnectionStartTime", "( 1.3.6.1.4.1.4203.666.1.50 "
1182 "NAME 'monitorConnectionStartTime' "
1183 "DESC 'monitor connection start time' "
1184 "SUP monitorTimestamp "
1186 "NO-USER-MODIFICATION "
1187 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1188 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1189 { "monitorConnectionActivityTime", "( 1.3.6.1.4.1.4203.666.1.51 "
1190 "NAME 'monitorConnectionActivityTime' "
1191 "DESC 'monitor connection activity time' "
1192 "SUP monitorTimestamp "
1194 "NO-USER-MODIFICATION "
1195 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1196 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1197 #ifdef INTEGRATE_CORE_SCHEMA
1198 { NULL, NULL, 0, -1 }, /* description */
1199 { NULL, NULL, 0, -1 }, /* seeAlso */
1200 { NULL, NULL, 0, -1 }, /* l */
1201 { NULL, NULL, 0, -1 }, /* labeledURI */
1202 #endif /* INTEGRATE_CORE_SCHEMA */
1203 { NULL, NULL, 0, -1 }
1205 { "description", "( 2.5.4.13 "
1206 "NAME 'description' "
1207 "DESC 'RFC2256: descriptive information' "
1208 "EQUALITY caseIgnoreMatch "
1209 "SUBSTR caseIgnoreSubstringsMatch "
1210 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )", 0,
1211 offsetof(monitor_info_t, mi_ad_description) },
1212 { "seeAlso", "( 2.5.4.34 "
1214 "DESC 'RFC2256: DN of related object' "
1215 "SUP distinguishedName )", 0,
1216 offsetof(monitor_info_t, mi_ad_seeAlso) },
1218 "NAME ( 'l' 'localityName' ) "
1219 "DESC 'RFC2256: locality which this object resides in' "
1221 offsetof(monitor_info_t, mi_ad_l) },
1222 #ifdef MONITOR_DEFINE_LABELEDURI
1223 { "labeledURI", "( 1.3.6.1.4.1.250.1.57 "
1224 "NAME 'labeledURI' "
1225 "DESC 'RFC2079: Uniform Resource Identifier with optional label' "
1226 "EQUALITY caseExactMatch "
1227 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )", 0,
1228 offsetof(monitor_info_t, mi_ad_labeledURI) },
1229 #endif /* MONITOR_DEFINE_LABELEDURI */
1230 { NULL, NULL, 0, -1 }
1234 * database monitor can be defined once only
1237 Debug( LDAP_DEBUG_ANY,
1238 "only one monitor backend is allowed\n", 0, 0, 0 );
1243 /* indicate system schema supported */
1244 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1246 dn.bv_val = SLAPD_MONITOR_DN;
1247 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
1249 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
1250 if( rc != LDAP_SUCCESS ) {
1251 Debug( LDAP_DEBUG_ANY,
1252 "unable to normalize monitor DN \"%s\"\n",
1253 SLAPD_MONITOR_DN, 0, 0 );
1257 ber_dupbv( &bv, &dn );
1258 ber_bvarray_add( &be->be_suffix, &bv );
1259 ber_bvarray_add( &be->be_nsuffix, &ndn );
1261 mi = ( monitor_info_t * )ch_calloc( sizeof( monitor_info_t ), 1 );
1263 Debug( LDAP_DEBUG_ANY,
1264 "unable to initialize monitor backend\n", 0, 0, 0 );
1268 memset( mi, 0, sizeof( monitor_info_t ) );
1270 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
1272 be->be_private = mi;
1274 #ifdef INTEGRATE_CORE_SCHEMA
1275 /* prepare for schema integration */
1276 for ( k = 0; mat[ k ].name != NULL; k++ );
1277 #endif /* INTEGRATE_CORE_SCHEMA */
1279 for ( i = 0; mat_core[ i ].name != NULL; i++ ) {
1280 AttributeDescription **ad;
1283 ad = ((AttributeDescription **)&(((char *)mi)[ mat_core[ i ].offset ]));
1286 switch (slap_str2ad( mat_core[ i ].name, ad, &text ) ) {
1290 #ifdef INTEGRATE_CORE_SCHEMA
1291 case LDAP_UNDEFINED_TYPE:
1292 mat[ k ] = mat_core[ i ];
1295 #endif /* INTEGRATE_CORE_SCHEMA */
1298 Debug( LDAP_DEBUG_ANY,
1299 "monitor_back_db_init: %s: %s\n",
1300 mat_core[ i ].name, text, 0 );
1305 /* schema integration */
1306 for ( i = 0; mat[ i ].name; i++ ) {
1307 LDAPAttributeType *at;
1310 AttributeDescription **ad;
1312 at = ldap_str2attributetype( mat[ i ].schema, &code,
1313 &err, LDAP_SCHEMA_ALLOW_ALL );
1315 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1316 "in AttributeType \"%s\" %s before %s\n",
1317 mat[ i ].name, ldap_scherr2str(code), err );
1321 if ( at->at_oid == NULL ) {
1322 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1323 "null OID for attributeType \"%s\"\n",
1324 mat[ i ].name, 0, 0 );
1328 code = at_add(at, 0, NULL, &err);
1330 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1331 "%s in attributeType \"%s\"\n",
1332 scherr2str(code), mat[ i ].name, 0 );
1337 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1339 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1340 Debug( LDAP_DEBUG_ANY,
1341 "monitor_back_db_init: %s\n", text, 0, 0 );
1345 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1348 for ( i = 0; moc[ i ].name; i++ ) {
1349 LDAPObjectClass *oc;
1354 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1355 LDAP_SCHEMA_ALLOW_ALL );
1357 Debug( LDAP_DEBUG_ANY,
1358 "unable to parse monitor objectclass \"%s\": "
1359 "%s before %s\n" , moc[ i ].name,
1360 ldap_scherr2str(code), err );
1364 if ( oc->oc_oid == NULL ) {
1365 Debug( LDAP_DEBUG_ANY,
1366 "objectclass \"%s\" has no OID\n" ,
1367 moc[ i ].name, 0, 0 );
1371 code = oc_add(oc, 0, NULL, &err);
1373 Debug( LDAP_DEBUG_ANY,
1374 "objectclass \"%s\": %s \"%s\"\n" ,
1375 moc[ i ].name, scherr2str(code), err );
1381 Oc = oc_find( moc[ i ].name );
1383 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1384 "unable to find objectClass %s "
1385 "(just added)\n", moc[ i ].name, 0, 0 );
1389 Oc->soc_flags |= moc[ i ].flags;
1391 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1398 monitor_back_db_open(
1402 monitor_info_t *mi = (monitor_info_t *)be->be_private;
1403 struct monitor_subsys_t **ms;
1405 monitor_entry_t *mp;
1407 char buf[ BACKMONITOR_BUFSIZE ],
1411 #ifdef HAVE_GMTIME_R
1414 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
1416 assert( be_monitor );
1417 if ( be != be_monitor ) {
1424 #ifndef HAVE_GMTIME_R
1425 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
1427 #ifdef HACK_LOCAL_TIME
1428 # ifdef HAVE_LOCALTIME_R
1429 tms = localtime_r( &starttime, &tm_buf );
1431 tms = localtime( &starttime );
1432 # endif /* HAVE_LOCALTIME_R */
1433 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
1434 #else /* !HACK_LOCAL_TIME */
1435 # ifdef HAVE_GMTIME_R
1436 tms = gmtime_r( &starttime, &tm_buf );
1438 tms = gmtime( &starttime );
1439 # endif /* HAVE_GMTIME_R */
1440 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
1441 #endif /* !HACK_LOCAL_TIME */
1442 #ifndef HAVE_GMTIME_R
1443 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
1446 mi->mi_startTime.bv_val = tmbuf;
1447 mi->mi_startTime.bv_len = strlen( tmbuf );
1449 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
1450 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
1452 mi->mi_creatorsName = be->be_rootdn;
1456 * creates the "cn=Monitor" entry
1458 snprintf( buf, sizeof( buf ),
1461 "structuralObjectClass: %s\n"
1463 "%s: This subtree contains monitoring/managing objects.\n"
1464 "%s: This object contains information about this server.\n"
1466 "%s: createTimestamp reflects the time this server instance was created.\n"
1467 "%s: modifyTimestamp reflects the time this server instance was last accessed.\n"
1469 "creatorsName: %s\n"
1470 "modifiersName: %s\n"
1471 "createTimestamp: %s\n"
1472 "modifyTimestamp: %s\n",
1474 mi->mi_oc_monitorServer->soc_cname.bv_val,
1475 mi->mi_oc_monitorServer->soc_cname.bv_val,
1476 mi->mi_ad_description->ad_cname.bv_val,
1477 mi->mi_ad_description->ad_cname.bv_val,
1479 mi->mi_ad_description->ad_cname.bv_val,
1480 mi->mi_ad_description->ad_cname.bv_val,
1482 mi->mi_creatorsName.bv_val,
1483 mi->mi_creatorsName.bv_val,
1484 mi->mi_startTime.bv_val,
1485 mi->mi_startTime.bv_val );
1487 e = str2entry( buf );
1489 Debug( LDAP_DEBUG_ANY,
1490 "unable to create \"%s\" entry\n",
1491 SLAPD_MONITOR_DN, 0, 0 );
1495 bv.bv_val = (char *) Versionstr;
1496 end_of_line = strchr( Versionstr, '\n' );
1497 if ( end_of_line ) {
1498 bv.bv_len = end_of_line - Versionstr;
1500 bv.bv_len = strlen( Versionstr );
1503 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
1505 Debug( LDAP_DEBUG_ANY,
1506 "unable to add monitoredInfo to \"%s\" entry\n",
1507 SLAPD_MONITOR_DN, 0, 0 );
1511 if ( mi->mi_l.bv_len ) {
1512 if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) {
1513 Debug( LDAP_DEBUG_ANY,
1514 "unable to add locality to \"%s\" entry\n",
1515 SLAPD_MONITOR_DN, 0, 0 );
1520 mp = monitor_entrypriv_create();
1524 e->e_private = ( void * )mp;
1525 ep = &mp->mp_children;
1527 if ( monitor_cache_add( mi, e ) ) {
1528 Debug( LDAP_DEBUG_ANY,
1529 "unable to add entry \"%s\" to cache\n",
1530 SLAPD_MONITOR_DN, 0, 0 );
1535 * Create all the subsystem specific entries
1537 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1538 int len = strlen( monitor_subsys[ i ]->mss_name );
1542 dn.bv_len = len + sizeof( "cn=" ) - 1;
1543 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1544 strcpy( dn.bv_val, "cn=" );
1545 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1546 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1548 if ( rc != LDAP_SUCCESS ) {
1549 Debug( LDAP_DEBUG_ANY,
1550 "monitor RDN \"%s\" is invalid\n",
1555 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
1556 dn.bv_val = ch_malloc( dn.bv_len + 1 );
1557 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
1558 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
1559 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
1560 &monitor_subsys[ i ]->mss_ndn, NULL );
1562 if ( rc != LDAP_SUCCESS ) {
1563 Debug( LDAP_DEBUG_ANY,
1564 "monitor DN \"%s\" is invalid\n",
1569 snprintf( buf, sizeof( buf ),
1572 "structuralObjectClass: %s\n"
1574 "creatorsName: %s\n"
1575 "modifiersName: %s\n"
1576 "createTimestamp: %s\n"
1577 "modifyTimestamp: %s\n",
1578 monitor_subsys[ i ]->mss_dn.bv_val,
1579 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1580 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1581 monitor_subsys[ i ]->mss_name,
1582 mi->mi_creatorsName.bv_val,
1583 mi->mi_creatorsName.bv_val,
1584 mi->mi_startTime.bv_val,
1585 mi->mi_startTime.bv_val );
1587 e = str2entry( buf );
1590 Debug( LDAP_DEBUG_ANY,
1591 "unable to create \"%s\" entry\n",
1592 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1596 mp = monitor_entrypriv_create();
1600 e->e_private = ( void * )mp;
1601 mp->mp_info = monitor_subsys[ i ];
1602 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1604 if ( monitor_cache_add( mi, e ) ) {
1605 Debug( LDAP_DEBUG_ANY,
1606 "unable to add entry \"%s\" to cache\n",
1607 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1617 be->be_private = mi;
1620 * opens the monitor backend subsystems
1622 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1623 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1627 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1630 monitor_subsys_opened = 1;
1632 if ( mi->mi_entry_limbo ) {
1633 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
1638 switch ( el->el_type ) {
1640 monitor_back_register_entry(
1645 case LIMBO_ENTRY_PARENT:
1646 monitor_back_register_entry_parent(
1656 monitor_back_register_entry_attrs(
1666 monitor_back_register_entry_callback(
1679 entry_free( el->el_e );
1682 attrs_free( el->el_a );
1684 if ( !BER_BVISNULL( &el->el_ndn ) ) {
1685 ber_memfree( el->el_ndn.bv_val );
1687 if ( !BER_BVISNULL( &el->el_base ) ) {
1688 ber_memfree( el->el_base.bv_val );
1690 if ( !BER_BVISNULL( &el->el_filter ) ) {
1691 ber_memfree( el->el_filter.bv_val );
1699 mi->mi_entry_limbo = NULL;
1706 monitor_back_config(
1715 * eventually, will hold backend specific configuration parameters
1717 return SLAP_CONF_UNKNOWN;
1721 monitor_back_db_config(
1729 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1732 * eventually, will hold database specific configuration parameters
1734 if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
1739 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_l );
1742 return SLAP_CONF_UNKNOWN;
1749 monitor_back_db_destroy(
1754 * FIXME: destroys all the data
1759 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
1761 /* conditionally define the init_module() function */
1762 SLAP_BACKEND_INIT_MODULE( monitor )
1764 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */