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>
31 #include "back-monitor.h"
33 #undef INTEGRATE_CORE_SCHEMA
36 * used by many functions to add description to entries
38 * WARNING: be_monitor may change as new databases are added,
39 * so it should not be used outside monitor_back_db_init()
40 * until monitor_back_db_open is called.
42 BackendDB *be_monitor;
44 static struct monitor_subsys_t **monitor_subsys;
45 static int monitor_subsys_opened;
46 static monitor_info_t monitor_info;
51 * the known subsystems are added to the subsystems
52 * array at backend initialization; other subsystems
53 * may be added by calling monitor_back_register_subsys()
54 * before the database is opened (e.g. by other backends
55 * or by overlays or modules).
57 static struct monitor_subsys_t known_monitor_subsys[] = {
59 SLAPD_MONITOR_BACKEND_NAME,
60 BER_BVNULL, BER_BVNULL, BER_BVNULL,
61 { BER_BVC( "This subsystem contains information about available backends." ),
63 MONITOR_F_PERSISTENT_CH,
64 monitor_subsys_backend_init,
70 SLAPD_MONITOR_CONN_NAME,
71 BER_BVNULL, BER_BVNULL, BER_BVNULL,
72 { BER_BVC( "This subsystem contains information about connections." ),
74 MONITOR_F_VOLATILE_CH,
75 monitor_subsys_conn_init,
81 SLAPD_MONITOR_DATABASE_NAME,
82 BER_BVNULL, BER_BVNULL, BER_BVNULL,
83 { BER_BVC( "This subsystem contains information about configured databases." ),
85 MONITOR_F_PERSISTENT_CH,
86 monitor_subsys_database_init,
92 SLAPD_MONITOR_LISTENER_NAME,
93 BER_BVNULL, BER_BVNULL, BER_BVNULL,
94 { BER_BVC( "This subsystem contains information about active listeners." ),
96 MONITOR_F_PERSISTENT_CH,
97 monitor_subsys_listener_init,
103 SLAPD_MONITOR_LOG_NAME,
104 BER_BVNULL, BER_BVNULL, BER_BVNULL,
105 { BER_BVC( "This subsystem contains information about logging." ),
106 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
109 monitor_subsys_log_init,
115 SLAPD_MONITOR_OPS_NAME,
116 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 { BER_BVC( "This subsystem contains information about performed operations." ),
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_ops_init,
126 SLAPD_MONITOR_OVERLAY_NAME,
127 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128 { BER_BVC( "This subsystem contains information about available overlays." ),
130 MONITOR_F_PERSISTENT_CH,
131 monitor_subsys_overlay_init,
137 SLAPD_MONITOR_SASL_NAME,
138 BER_BVNULL, BER_BVNULL, BER_BVNULL,
139 { BER_BVC( "This subsystem contains information about SASL." ),
148 SLAPD_MONITOR_SENT_NAME,
149 BER_BVNULL, BER_BVNULL, BER_BVNULL,
150 { BER_BVC( "This subsystem contains statistics." ),
152 MONITOR_F_PERSISTENT_CH,
153 monitor_subsys_sent_init,
159 SLAPD_MONITOR_THREAD_NAME,
160 BER_BVNULL, BER_BVNULL, BER_BVNULL,
161 { BER_BVC( "This subsystem contains information about threads." ),
163 MONITOR_F_PERSISTENT_CH,
164 monitor_subsys_thread_init,
170 SLAPD_MONITOR_TIME_NAME,
171 BER_BVNULL, BER_BVNULL, BER_BVNULL,
172 { BER_BVC( "This subsystem contains information about time." ),
174 MONITOR_F_PERSISTENT_CH,
175 monitor_subsys_time_init,
181 SLAPD_MONITOR_TLS_NAME,
182 BER_BVNULL, BER_BVNULL, BER_BVNULL,
183 { BER_BVC( "This subsystem contains information about TLS." ),
192 SLAPD_MONITOR_RWW_NAME,
193 BER_BVNULL, BER_BVNULL, BER_BVNULL,
194 { BER_BVC( "This subsystem contains information about read/write waiters." ),
196 MONITOR_F_PERSISTENT_CH,
197 monitor_subsys_rww_init,
206 monitor_back_register_subsys(
207 monitor_subsys_t *ms )
211 if ( monitor_subsys ) {
212 for ( ; monitor_subsys[ i ] != NULL; i++ )
213 /* just count'em */ ;
216 monitor_subsys = ch_realloc( monitor_subsys,
217 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
219 if ( monitor_subsys == NULL ) {
223 monitor_subsys[ i ] = ms;
224 monitor_subsys[ i + 1 ] = NULL;
226 /* if a subsystem is registered __AFTER__ subsystem
227 * initialization (depending on the sequence the databases
228 * are listed in slapd.conf), init it */
229 if ( monitor_subsys_opened ) {
231 /* FIXME: this should only be possible
232 * if be_monitor is already initialized */
233 assert( be_monitor != NULL );
235 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
239 ms->mss_flags |= MONITOR_F_OPENED;
252 typedef struct entry_limbo_t {
256 struct berval el_ndn;
257 struct berval el_base;
259 struct berval el_filter;
260 monitor_callback_t *el_cb;
261 struct entry_limbo_t *el_next;
265 monitor_back_register_entry(
267 monitor_callback_t *cb )
269 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
271 assert( mi != NULL );
273 assert( e->e_private == NULL );
275 if ( monitor_subsys_opened ) {
276 Entry *e_parent = NULL,
279 struct berval pdn = BER_BVNULL;
280 monitor_entry_t *mp = NULL,
284 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
286 Debug( LDAP_DEBUG_ANY,
287 "monitor_back_register_entry(\"%s\"): "
289 e->e_name.bv_val, 0, 0 );
290 monitor_cache_release( mi, e_parent );
294 dnParent( &e->e_nname, &pdn );
295 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
296 /* parent does not exist */
297 Debug( LDAP_DEBUG_ANY,
298 "monitor_back_register_entry(\"%s\"): "
299 "parent \"%s\" not found\n",
300 e->e_name.bv_val, pdn.bv_val, 0 );
304 assert( e_parent->e_private != NULL );
305 mp_parent = ( monitor_entry_t * )e_parent->e_private;
307 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
308 /* entry is volatile; cannot append children */
309 Debug( LDAP_DEBUG_ANY,
310 "monitor_back_register_entry(\"%s\"): "
311 "parent \"%s\" is volatile\n",
312 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
317 mp = monitor_entrypriv_create();
319 Debug( LDAP_DEBUG_ANY,
320 "monitor_back_register_entry(\"%s\"): "
321 "monitor_entrypriv_create() failed\n",
322 e->e_name.bv_val, 0, 0 );
327 e_new = entry_dup( e );
328 if ( e_new == NULL ) {
329 Debug( LDAP_DEBUG_ANY,
330 "monitor_back_register_entry(\"%s\"): "
331 "entry_dup() failed\n",
332 e->e_name.bv_val, 0, 0 );
337 e_new->e_private = ( void * )mp;
338 mp->mp_info = mp_parent->mp_info;
339 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
342 ep = &mp_parent->mp_children;
344 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
345 ep = &mp_parent->mp_next;
349 if ( monitor_cache_add( mi, e_new ) ) {
350 Debug( LDAP_DEBUG_ANY,
351 "monitor_back_register_entry(\"%s\"): "
352 "unable to add entry\n",
353 e->e_name.bv_val, 0, 0 );
364 e_new->e_private = NULL;
370 monitor_cache_release( mi, e_parent );
374 entry_limbo_t **elpp, el = { 0 };
376 el.el_type = LIMBO_ENTRY;
378 el.el_e = entry_dup( e );
379 if ( el.el_e == NULL ) {
380 Debug( LDAP_DEBUG_ANY,
381 "monitor_back_register_entry(\"%s\"): "
382 "entry_dup() failed\n",
383 e->e_name.bv_val, 0, 0 );
389 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
391 elpp = &(*elpp)->el_next )
394 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
395 if ( *elpp == NULL ) {
396 el.el_e->e_private = NULL;
397 entry_free( el.el_e );
409 monitor_back_register_entry_parent(
411 monitor_callback_t *cb,
414 struct berval *filter )
416 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
417 struct berval ndn = BER_BVNULL;
419 assert( mi != NULL );
421 assert( e->e_private == NULL );
423 if ( BER_BVISNULL( filter ) ) {
425 Debug( LDAP_DEBUG_ANY,
426 "monitor_back_register_entry_parent(\"\"): "
427 "need a valid filter\n",
432 if ( monitor_subsys_opened ) {
433 Entry *e_parent = NULL,
436 struct berval e_name = BER_BVNULL,
437 e_nname = BER_BVNULL;
438 monitor_entry_t *mp = NULL,
442 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
443 /* entry does not exist */
444 Debug( LDAP_DEBUG_ANY,
445 "monitor_back_register_entry_parent(\"\"): "
446 "base=%s scope=%d filter=%s : "
447 "unable to find entry\n",
448 base->bv_val ? base->bv_val : "\"\"",
449 scope, filter->bv_val );
453 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
454 /* entry does not exist */
455 Debug( LDAP_DEBUG_ANY,
456 "monitor_back_register_entry_parent(\"%s\"): "
457 "parent entry does not exist\n",
463 assert( e_parent->e_private != NULL );
464 mp_parent = ( monitor_entry_t * )e_parent->e_private;
466 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
467 /* entry is volatile; cannot append callback */
468 Debug( LDAP_DEBUG_ANY,
469 "monitor_back_register_entry_parent(\"%s\"): "
470 "entry is volatile\n",
471 e_parent->e_name.bv_val, 0, 0 );
476 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
477 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
479 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
480 /* entry already exists */
481 Debug( LDAP_DEBUG_ANY,
482 "monitor_back_register_entry_parent(\"%s\"): "
483 "entry already exists\n",
484 e_name.bv_val, 0, 0 );
485 monitor_cache_release( mi, e_new );
490 mp = monitor_entrypriv_create();
492 Debug( LDAP_DEBUG_ANY,
493 "monitor_back_register_entry_parent(\"%s\"): "
494 "monitor_entrypriv_create() failed\n",
495 e->e_name.bv_val, 0, 0 );
500 e_new = entry_dup( e );
501 if ( e_new == NULL ) {
502 Debug( LDAP_DEBUG_ANY,
503 "monitor_back_register_entry(\"%s\"): "
504 "entry_dup() failed\n",
505 e->e_name.bv_val, 0, 0 );
509 ch_free( e_new->e_name.bv_val );
510 ch_free( e_new->e_nname.bv_val );
511 e_new->e_name = e_name;
512 e_new->e_nname = e_nname;
514 e_new->e_private = ( void * )mp;
515 mp->mp_info = mp_parent->mp_info;
516 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
519 ep = &mp_parent->mp_children;
521 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
522 ep = &mp_parent->mp_next;
526 if ( monitor_cache_add( mi, e_new ) ) {
527 Debug( LDAP_DEBUG_ANY,
528 "monitor_back_register_entry(\"%s\"): "
529 "unable to add entry\n",
530 e->e_name.bv_val, 0, 0 );
536 if ( !BER_BVISNULL( &ndn ) ) {
537 ch_free( ndn.bv_val );
545 e_new->e_private = NULL;
551 monitor_cache_release( mi, e_parent );
555 entry_limbo_t **elpp, el = { 0 };
557 el.el_type = LIMBO_ENTRY_PARENT;
559 el.el_e = entry_dup( e );
560 if ( el.el_e == NULL ) {
561 Debug( LDAP_DEBUG_ANY,
562 "monitor_back_register_entry(\"%s\"): "
563 "entry_dup() failed\n",
564 e->e_name.bv_val, 0, 0 );
568 if ( !BER_BVISNULL( base ) ) {
569 ber_dupbv( &el.el_base, base );
572 if ( !BER_BVISNULL( filter ) ) {
573 ber_dupbv( &el.el_filter, filter );
578 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
580 elpp = &(*elpp)->el_next )
583 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
584 if ( *elpp == NULL ) {
585 el.el_e->e_private = NULL;
586 entry_free( el.el_e );
598 monitor_filter2ndn_cb( Operation *op, SlapReply *rs )
600 if ( rs->sr_type == REP_SEARCH ) {
601 struct berval *ndn = op->o_callback->sc_private;
603 ber_dupbv( ndn, &rs->sr_entry->e_nname );
613 struct berval *filter,
616 Connection conn = { 0 };
617 char opbuf[OPERATION_BUFFER_SIZE];
619 SlapReply rs = { 0 };
620 slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
625 if ( be_monitor == NULL ) {
629 op = (Operation *)opbuf;
630 connection_fake_init( &conn, op, &conn );
632 op->o_tag = LDAP_REQ_SEARCH;
634 /* use global malloc for now */
635 if ( op->o_tmpmemctx ) {
636 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
637 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
638 op->o_tmpmemctx = NULL;
640 op->o_tmpmfuncs = &ch_mfuncs;
642 op->o_bd = be_monitor;
643 if ( base == NULL || BER_BVISNULL( base ) ) {
644 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
646 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
650 if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn,
651 op->o_tmpmemctx ) ) {
656 op->o_callback = &cb;
657 cb.sc_private = (void *)ndn;
659 op->ors_scope = scope;
660 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
661 op->ors_filter = str2filter_x( op, filter->bv_val );
662 op->ors_attrs = slap_anlist_no_attrs;
663 op->ors_attrsonly = 0;
664 op->ors_tlimit = SLAP_NO_LIMIT;
666 op->ors_limit = NULL;
667 op->ors_deref = LDAP_DEREF_NEVER;
670 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
672 op->o_dn = be_monitor->be_rootdn;
673 op->o_ndn = be_monitor->be_rootndn;
675 rc = op->o_bd->be_search( op, &rs );
677 filter_free_x( op, op->ors_filter );
678 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
679 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
680 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
686 switch ( rs.sr_err ) {
688 if ( BER_BVISNULL( ndn ) ) {
693 case LDAP_SIZELIMIT_EXCEEDED:
695 if ( !BER_BVISNULL( ndn ) ) {
696 ber_memfree( ndn->bv_val );
707 monitor_back_register_entry_attrs(
708 struct berval *ndn_in,
710 monitor_callback_t *cb,
713 struct berval *filter )
715 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
716 struct berval ndn = BER_BVNULL;
718 assert( mi != NULL );
720 if ( ndn_in != NULL ) {
724 if ( a == NULL && cb == NULL ) {
729 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
730 && BER_BVISNULL( filter ) )
733 Debug( LDAP_DEBUG_ANY,
734 "monitor_back_register_entry_*(\"\"): "
735 "need a valid filter\n",
740 if ( monitor_subsys_opened ) {
742 Attribute **atp = NULL;
743 monitor_entry_t *mp = NULL;
744 monitor_callback_t **mcp = NULL;
748 if ( BER_BVISNULL( &ndn ) ) {
749 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
750 /* entry does not exist */
751 Debug( LDAP_DEBUG_ANY,
752 "monitor_back_register_entry_*(\"\"): "
753 "base=%s scope=%d filter=%s : "
754 "unable to find entry\n",
755 base->bv_val ? base->bv_val : "\"\"",
756 scope, filter->bv_val );
763 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
764 /* entry does not exist */
765 Debug( LDAP_DEBUG_ANY,
766 "monitor_back_register_entry_*(\"%s\"): "
767 "entry does not exist\n",
773 assert( e->e_private != NULL );
774 mp = ( monitor_entry_t * )e->e_private;
776 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
777 /* entry is volatile; cannot append callback */
778 Debug( LDAP_DEBUG_ANY,
779 "monitor_back_register_entry_*(\"%s\"): "
780 "entry is volatile\n",
781 e->e_name.bv_val, 0, 0 );
787 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
788 /* just get to last */ ;
790 *atp = attrs_dup( a );
791 if ( *atp == NULL ) {
792 Debug( LDAP_DEBUG_ANY,
793 "monitor_back_register_entry_*(\"%s\"): "
794 "attrs_dup() failed\n",
795 e->e_name.bv_val, 0, 0 );
802 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
805 /* NOTE: we do not clear cb->mc_next, so this function
806 * can be used to append a list of callbacks */
819 ber_memfree( ndn.bv_val );
823 monitor_cache_release( mi, e );
827 entry_limbo_t **elpp, el = { 0 };
829 el.el_type = LIMBO_ATTRS;
830 if ( !BER_BVISNULL( &ndn ) ) {
831 ber_dupbv( &el.el_ndn, &ndn );
833 if ( !BER_BVISNULL( base ) ) {
834 ber_dupbv( &el.el_base, base);
837 if ( !BER_BVISNULL( filter ) ) {
838 ber_dupbv( &el.el_filter, filter );
841 el.el_a = attrs_dup( a );
844 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
846 elpp = &(*elpp)->el_next )
849 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
850 if ( *elpp == NULL ) {
851 el.el_e->e_private = NULL;
852 entry_free( el.el_e );
864 monitor_back_register_entry_callback(
866 monitor_callback_t *cb,
869 struct berval *filter )
871 return monitor_back_register_entry_attrs( ndn, NULL, cb,
872 base, scope, filter );
876 monitor_back_get_subsys( const char *name )
878 if ( monitor_subsys != NULL ) {
881 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
882 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
883 return monitor_subsys[ i ];
892 monitor_back_get_subsys_by_dn(
896 if ( monitor_subsys != NULL ) {
900 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
901 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
902 return monitor_subsys[ i ];
907 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
908 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
909 return monitor_subsys[ i ];
919 monitor_back_initialize(
922 monitor_subsys_t *ms;
923 static char *controls[] = {
924 LDAP_CONTROL_MANAGEDSAIT,
927 monitor_info_t *mi = &monitor_info;
937 { "monitor", "( 1.3.6.1.4.1.4203.666.3.16.1 "
939 "DESC 'OpenLDAP system monitoring' "
940 "SUP top STRUCTURAL "
949 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
950 offsetof(monitor_info_t, mi_oc_monitor) },
951 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.16.2 "
952 "NAME 'monitorServer' "
953 "DESC 'Server monitoring root entry' "
954 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
955 offsetof(monitor_info_t, mi_oc_monitorServer) },
956 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.16.3 "
957 "NAME 'monitorContainer' "
958 "DESC 'monitor container class' "
959 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
960 offsetof(monitor_info_t, mi_oc_monitorContainer) },
961 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.16.4 "
962 "NAME 'monitorCounterObject' "
963 "DESC 'monitor counter class' "
964 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
965 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
966 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.16.5 "
967 "NAME 'monitorOperation' "
968 "DESC 'monitor operation class' "
969 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
970 offsetof(monitor_info_t, mi_oc_monitorOperation) },
971 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.16.6 "
972 "NAME 'monitorConnection' "
973 "DESC 'monitor connection class' "
974 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
975 offsetof(monitor_info_t, mi_oc_monitorConnection) },
976 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.16.7 "
977 "NAME 'managedObject' "
978 "DESC 'monitor managed entity class' "
979 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
980 offsetof(monitor_info_t, mi_oc_managedObject) },
981 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.16.8 "
982 "NAME 'monitoredObject' "
983 "DESC 'monitor monitored entity class' "
984 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
985 offsetof(monitor_info_t, mi_oc_monitoredObject) },
986 { NULL, NULL, 0, -1 }
988 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.55.1 "
989 "NAME 'monitoredInfo' "
990 "DESC 'monitored info' "
992 "EQUALITY caseIgnoreMatch "
993 "SUBSTR caseIgnoreSubstringsMatch "
994 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
995 "NO-USER-MODIFICATION "
996 "USAGE directoryOperation )", SLAP_AT_HIDE,
997 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
998 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.55.2 "
999 "NAME 'managedInfo' "
1000 "DESC 'monitor managed info' "
1001 "SUP name )", SLAP_AT_HIDE,
1002 offsetof(monitor_info_t, mi_ad_managedInfo) },
1003 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.55.3 "
1004 "NAME 'monitorCounter' "
1005 "DESC 'monitor counter' "
1006 "EQUALITY integerMatch "
1007 "ORDERING integerOrderingMatch "
1008 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1009 "NO-USER-MODIFICATION "
1010 "USAGE directoryOperation )", SLAP_AT_HIDE,
1011 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1012 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.55.4 "
1013 "NAME 'monitorOpCompleted' "
1014 "DESC 'monitor completed operations' "
1015 "SUP monitorCounter "
1016 "NO-USER-MODIFICATION "
1017 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1018 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1019 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.55.5 "
1020 "NAME 'monitorOpInitiated' "
1021 "DESC 'monitor initiated operations' "
1022 "SUP monitorCounter "
1023 "NO-USER-MODIFICATION "
1024 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1025 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1026 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.55.6 "
1027 "NAME 'monitorConnectionNumber' "
1028 "DESC 'monitor connection number' "
1029 "SUP monitorCounter "
1030 "NO-USER-MODIFICATION "
1031 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1032 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1033 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.55.7 "
1034 "NAME 'monitorConnectionAuthzDN' "
1035 "DESC 'monitor connection authorization DN' "
1036 /* "SUP distinguishedName " */
1037 "EQUALITY distinguishedNameMatch "
1038 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1039 "NO-USER-MODIFICATION "
1040 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1041 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1042 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.55.8 "
1043 "NAME 'monitorConnectionLocalAddress' "
1044 "DESC 'monitor connection local address' "
1045 "SUP monitoredInfo "
1046 "NO-USER-MODIFICATION "
1047 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1048 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1049 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.55.9 "
1050 "NAME 'monitorConnectionPeerAddress' "
1051 "DESC 'monitor connection peer address' "
1052 "SUP monitoredInfo "
1053 "NO-USER-MODIFICATION "
1054 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1055 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1056 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.55.10 "
1057 "NAME 'monitorTimestamp' "
1058 "DESC 'monitor timestamp' "
1059 "EQUALITY generalizedTimeMatch "
1060 "ORDERING generalizedTimeOrderingMatch "
1061 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1063 "NO-USER-MODIFICATION "
1064 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1065 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1066 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.55.11 "
1067 "NAME 'monitorOverlay' "
1068 "DESC 'name of overlays defined for a given database' "
1069 "SUP monitoredInfo "
1070 "NO-USER-MODIFICATION "
1071 "USAGE directoryOperation )", SLAP_AT_HIDE,
1072 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1073 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.55.12 "
1075 "DESC 'read/write status of a given database' "
1076 "EQUALITY booleanMatch "
1077 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1079 "USAGE directoryOperation )", SLAP_AT_HIDE,
1080 offsetof(monitor_info_t, mi_ad_readOnly) },
1081 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.55.13 "
1082 "NAME 'restrictedOperation' "
1083 "DESC 'name of restricted operation for a given database' "
1084 "SUP managedInfo )", SLAP_AT_HIDE,
1085 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1086 { "monitorConnectionProtocol", "( 1.3.6.1.4.1.4203.666.1.55.14 "
1087 "NAME 'monitorConnectionProtocol' "
1088 "DESC 'monitor connection protocol' "
1089 "SUP monitoredInfo "
1090 "NO-USER-MODIFICATION "
1091 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1092 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1093 { "monitorConnectionOpsReceived", "( 1.3.6.1.4.1.4203.666.1.55.15 "
1094 "NAME 'monitorConnectionOpsReceived' "
1095 "DESC 'monitor number of operations received by the connection' "
1096 "SUP monitorCounter "
1097 "NO-USER-MODIFICATION "
1098 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1099 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1100 { "monitorConnectionOpsExecuting", "( 1.3.6.1.4.1.4203.666.1.55.16 "
1101 "NAME 'monitorConnectionOpsExecuting' "
1102 "DESC 'monitor number of operations in execution within the connection' "
1103 "SUP monitorCounter "
1104 "NO-USER-MODIFICATION "
1105 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1106 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1107 { "monitorConnectionOpsPending", "( 1.3.6.1.4.1.4203.666.1.55.17 "
1108 "NAME 'monitorConnectionOpsPending' "
1109 "DESC 'monitor number of pending operations within the connection' "
1110 "SUP monitorCounter "
1111 "NO-USER-MODIFICATION "
1112 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1113 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1114 { "monitorConnectionOpsCompleted", "( 1.3.6.1.4.1.4203.666.1.55.18 "
1115 "NAME 'monitorConnectionOpsCompleted' "
1116 "DESC 'monitor number of operations completed within the connection' "
1117 "SUP monitorCounter "
1118 "NO-USER-MODIFICATION "
1119 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1120 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1121 { "monitorConnectionGet", "( 1.3.6.1.4.1.4203.666.1.55.19 "
1122 "NAME 'monitorConnectionGet' "
1123 "DESC 'number of times connection_get() was called so far' "
1124 "SUP monitorCounter "
1125 "NO-USER-MODIFICATION "
1126 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1127 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1128 { "monitorConnectionRead", "( 1.3.6.1.4.1.4203.666.1.55.20 "
1129 "NAME 'monitorConnectionRead' "
1130 "DESC 'number of times connection_read() was called so far' "
1131 "SUP monitorCounter "
1132 "NO-USER-MODIFICATION "
1133 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1134 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1135 { "monitorConnectionWrite", "( 1.3.6.1.4.1.4203.666.1.55.21 "
1136 "NAME 'monitorConnectionWrite' "
1137 "DESC 'number of times connection_write() was called so far' "
1138 "SUP monitorCounter "
1139 "NO-USER-MODIFICATION "
1140 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1141 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1142 { "monitorConnectionMask", "( 1.3.6.1.4.1.4203.666.1.55.22 "
1143 "NAME 'monitorConnectionMask' "
1144 "DESC 'monitor connection mask' "
1145 "SUP monitoredInfo "
1146 "NO-USER-MODIFICATION "
1147 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1148 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1149 { "monitorConnectionListener", "( 1.3.6.1.4.1.4203.666.1.55.23 "
1150 "NAME 'monitorConnectionListener' "
1151 "DESC 'monitor connection listener' "
1152 "SUP monitoredInfo "
1153 "NO-USER-MODIFICATION "
1154 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1155 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1156 { "monitorConnectionPeerDomain", "( 1.3.6.1.4.1.4203.666.1.55.24 "
1157 "NAME 'monitorConnectionPeerDomain' "
1158 "DESC 'monitor connection peer domain' "
1159 "SUP monitoredInfo "
1160 "NO-USER-MODIFICATION "
1161 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1162 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1163 { "monitorConnectionStartTime", "( 1.3.6.1.4.1.4203.666.1.55.25 "
1164 "NAME 'monitorConnectionStartTime' "
1165 "DESC 'monitor connection start time' "
1166 "SUP monitorTimestamp "
1168 "NO-USER-MODIFICATION "
1169 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1170 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1171 { "monitorConnectionActivityTime", "( 1.3.6.1.4.1.4203.666.1.55.26 "
1172 "NAME 'monitorConnectionActivityTime' "
1173 "DESC 'monitor connection activity time' "
1174 "SUP monitorTimestamp "
1176 "NO-USER-MODIFICATION "
1177 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1178 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1179 { "monitorIsShadow", "( 1.3.6.1.4.1.4203.666.1.55.27 "
1180 "NAME 'monitorIsShadow' "
1181 "DESC 'TRUE if the database is shadow' "
1182 "EQUALITY booleanMatch "
1183 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1185 "USAGE directoryOperation )", SLAP_AT_HIDE,
1186 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1187 { "monitorUpdateRef", "( 1.3.6.1.4.1.4203.666.1.55.28 "
1188 "NAME 'monitorUpdateRef' "
1189 "DESC 'update referral for shadow databases' "
1190 "SUP monitoredInfo "
1192 "USAGE directoryOperation )", SLAP_AT_HIDE,
1193 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1194 { "monitorRuntimeConfig", "( 1.3.6.1.4.1.4203.666.1.55.29 "
1195 "NAME 'monitorRuntimeConfig' "
1196 "DESC 'TRUE if component allows runtime configuration' "
1197 "EQUALITY booleanMatch "
1198 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1200 "USAGE directoryOperation )", SLAP_AT_HIDE,
1201 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1202 { NULL, NULL, 0, -1 }
1204 static ConfigTable monitorcfg[] = {
1205 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1206 NULL, NULL, NULL, NULL }
1208 static ConfigOCs monitorocs[] = {
1209 { "( OLcfgDbOc:4.1 "
1210 "NAME 'olcMonitorConfig' "
1211 "DESC 'Monitor backend configuration' "
1212 "SUP olcDatabaseConfig "
1214 Cft_Database, monitorcfg },
1219 bi->bi_controls = controls;
1223 bi->bi_config = monitor_back_config;
1227 bi->bi_db_init = monitor_back_db_init;
1228 bi->bi_db_config = monitor_back_db_config;
1229 bi->bi_db_open = monitor_back_db_open;
1230 bi->bi_db_close = 0;
1231 bi->bi_db_destroy = monitor_back_db_destroy;
1233 bi->bi_op_bind = monitor_back_bind;
1234 bi->bi_op_unbind = 0;
1235 bi->bi_op_search = monitor_back_search;
1236 bi->bi_op_compare = monitor_back_compare;
1237 bi->bi_op_modify = monitor_back_modify;
1238 bi->bi_op_modrdn = 0;
1240 bi->bi_op_delete = 0;
1241 bi->bi_op_abandon = 0;
1243 bi->bi_extended = 0;
1245 bi->bi_entry_release_rw = 0;
1246 bi->bi_chk_referrals = 0;
1247 bi->bi_operational = monitor_back_operational;
1250 * hooks for slap tools
1252 bi->bi_tool_entry_open = 0;
1253 bi->bi_tool_entry_close = 0;
1254 bi->bi_tool_entry_first = 0;
1255 bi->bi_tool_entry_next = 0;
1256 bi->bi_tool_entry_get = 0;
1257 bi->bi_tool_entry_put = 0;
1258 bi->bi_tool_entry_reindex = 0;
1259 bi->bi_tool_sync = 0;
1260 bi->bi_tool_dn2id_get = 0;
1261 bi->bi_tool_id2entry_get = 0;
1262 bi->bi_tool_entry_modify = 0;
1264 bi->bi_connection_init = 0;
1265 bi->bi_connection_destroy = 0;
1268 * configuration objectClasses (fake)
1270 bi->bi_cf_ocs = monitorocs;
1272 rc = config_register_schema( monitorcfg, monitorocs );
1280 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1281 if ( monitor_back_register_subsys( ms ) ) {
1286 /* schema integration */
1287 for ( i = 0; mat[ i ].name; i++ ) {
1288 LDAPAttributeType *at;
1291 AttributeDescription **ad;
1293 at = ldap_str2attributetype( mat[ i ].schema, &code,
1294 &err, LDAP_SCHEMA_ALLOW_ALL );
1296 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1297 "in AttributeType \"%s\" %s before %s\n",
1298 mat[ i ].name, ldap_scherr2str(code), err );
1302 if ( at->at_oid == NULL ) {
1303 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1304 "null OID for attributeType \"%s\"\n",
1305 mat[ i ].name, 0, 0 );
1309 code = at_add(at, 0, NULL, &err);
1311 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1312 "%s in attributeType \"%s\"\n",
1313 scherr2str(code), mat[ i ].name, 0 );
1318 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1320 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1321 Debug( LDAP_DEBUG_ANY,
1322 "monitor_back_db_init: %s\n", text, 0, 0 );
1326 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1329 for ( i = 0; moc[ i ].name; i++ ) {
1330 LDAPObjectClass *oc;
1335 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1336 LDAP_SCHEMA_ALLOW_ALL );
1338 Debug( LDAP_DEBUG_ANY,
1339 "unable to parse monitor objectclass \"%s\": "
1340 "%s before %s\n" , moc[ i ].name,
1341 ldap_scherr2str(code), err );
1345 if ( oc->oc_oid == NULL ) {
1346 Debug( LDAP_DEBUG_ANY,
1347 "objectclass \"%s\" has no OID\n" ,
1348 moc[ i ].name, 0, 0 );
1352 code = oc_add(oc, 0, NULL, &err);
1354 Debug( LDAP_DEBUG_ANY,
1355 "objectclass \"%s\": %s \"%s\"\n" ,
1356 moc[ i ].name, scherr2str(code), err );
1362 Oc = oc_find( moc[ i ].name );
1364 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1365 "unable to find objectClass %s "
1366 "(just added)\n", moc[ i ].name, 0, 0 );
1370 Oc->soc_flags |= moc[ i ].flags;
1372 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1379 monitor_back_db_init(
1383 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1389 * database monitor can be defined once only
1391 if ( be_monitor != NULL ) {
1392 Debug( LDAP_DEBUG_ANY,
1393 "only one monitor database is allowed\n", 0, 0, 0 );
1398 /* indicate system schema supported */
1399 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1401 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1402 if( rc != LDAP_SUCCESS ) {
1403 Debug( LDAP_DEBUG_ANY,
1404 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
1409 ber_bvarray_add( &be->be_suffix, &pdn );
1410 ber_bvarray_add( &be->be_nsuffix, &ndn );
1412 /* NOTE: only one monitor database is allowed,
1413 * so we use static storage */
1414 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
1416 be->be_private = &monitor_info;
1418 be2 = select_backend( &ndn, 0, 0 );
1420 char *type = be2->bd_info->bi_type;
1422 if ( overlay_is_over( be2 ) ) {
1423 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
1424 type = oi->oi_orig->bi_type;
1427 Debug( LDAP_DEBUG_ANY,
1428 "\"monitor\" database serving namingContext \"%s\" "
1429 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
1430 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
1438 monitor_back_db_open(
1441 monitor_info_t *mi = (monitor_info_t *)be->be_private;
1442 struct monitor_subsys_t **ms;
1444 monitor_entry_t *mp;
1446 char buf[ BACKMONITOR_BUFSIZE ];
1449 #ifdef HAVE_GMTIME_R
1452 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
1454 assert( be_monitor != NULL );
1455 if ( be != be_monitor ) {
1462 #ifndef HAVE_GMTIME_R
1463 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
1465 #ifdef HACK_LOCAL_TIME
1466 # ifdef HAVE_LOCALTIME_R
1467 tms = localtime_r( &starttime, &tm_buf );
1469 tms = localtime( &starttime );
1470 # endif /* HAVE_LOCALTIME_R */
1471 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
1472 #else /* !HACK_LOCAL_TIME */
1473 # ifdef HAVE_GMTIME_R
1474 tms = gmtime_r( &starttime, &tm_buf );
1476 tms = gmtime( &starttime );
1477 # endif /* HAVE_GMTIME_R */
1478 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
1479 #endif /* !HACK_LOCAL_TIME */
1480 #ifndef HAVE_GMTIME_R
1481 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
1484 mi->mi_startTime.bv_val = tmbuf;
1485 mi->mi_startTime.bv_len = strlen( tmbuf );
1487 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
1488 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
1490 mi->mi_creatorsName = be->be_rootdn;
1494 * creates the "cn=Monitor" entry
1496 snprintf( buf, sizeof( buf ),
1499 "structuralObjectClass: %s\n"
1501 "description: This subtree contains monitoring/managing objects.\n"
1502 "description: This object contains information about this server.\n"
1503 "description: Most of the information is held in operational"
1504 " attributeTypes, which must be explicitly requested.\n"
1505 "creatorsName: %s\n"
1506 "modifiersName: %s\n"
1507 "createTimestamp: %s\n"
1508 "modifyTimestamp: %s\n",
1510 mi->mi_oc_monitorServer->soc_cname.bv_val,
1511 mi->mi_oc_monitorServer->soc_cname.bv_val,
1512 mi->mi_creatorsName.bv_val,
1513 mi->mi_creatorsName.bv_val,
1514 mi->mi_startTime.bv_val,
1515 mi->mi_startTime.bv_val );
1517 e = str2entry( buf );
1519 Debug( LDAP_DEBUG_ANY,
1520 "unable to create \"%s\" entry\n",
1521 SLAPD_MONITOR_DN, 0, 0 );
1525 bv.bv_val = strchr( (char *) Versionstr, '$' );
1526 if ( bv.bv_val != NULL ) {
1530 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
1533 end = strchr( bv.bv_val, '$' );
1534 if ( end != NULL ) {
1537 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
1542 bv.bv_len = end - bv.bv_val;
1545 bv.bv_len = strlen( bv.bv_val );
1548 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
1550 Debug( LDAP_DEBUG_ANY,
1551 "unable to add monitoredInfo to \"%s\" entry\n",
1552 SLAPD_MONITOR_DN, 0, 0 );
1557 mp = monitor_entrypriv_create();
1561 e->e_private = ( void * )mp;
1562 ep = &mp->mp_children;
1564 if ( monitor_cache_add( mi, e ) ) {
1565 Debug( LDAP_DEBUG_ANY,
1566 "unable to add entry \"%s\" to cache\n",
1567 SLAPD_MONITOR_DN, 0, 0 );
1572 * Create all the subsystem specific entries
1574 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1575 int len = strlen( monitor_subsys[ i ]->mss_name );
1579 dn.bv_len = len + sizeof( "cn=" ) - 1;
1580 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1581 strcpy( dn.bv_val, "cn=" );
1582 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1583 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1585 if ( rc != LDAP_SUCCESS ) {
1586 Debug( LDAP_DEBUG_ANY,
1587 "monitor RDN \"%s\" is invalid\n",
1592 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
1593 dn.bv_val = ch_malloc( dn.bv_len + 1 );
1594 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
1595 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
1596 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
1597 &monitor_subsys[ i ]->mss_ndn, NULL );
1599 if ( rc != LDAP_SUCCESS ) {
1600 Debug( LDAP_DEBUG_ANY,
1601 "monitor DN \"%s\" is invalid\n",
1606 snprintf( buf, sizeof( buf ),
1609 "structuralObjectClass: %s\n"
1611 "creatorsName: %s\n"
1612 "modifiersName: %s\n"
1613 "createTimestamp: %s\n"
1614 "modifyTimestamp: %s\n",
1615 monitor_subsys[ i ]->mss_dn.bv_val,
1616 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1617 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1618 monitor_subsys[ i ]->mss_name,
1619 mi->mi_creatorsName.bv_val,
1620 mi->mi_creatorsName.bv_val,
1621 mi->mi_startTime.bv_val,
1622 mi->mi_startTime.bv_val );
1624 e = str2entry( buf );
1627 Debug( LDAP_DEBUG_ANY,
1628 "unable to create \"%s\" entry\n",
1629 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1633 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
1634 attr_merge_normalize( e, slap_schema.si_ad_description,
1635 monitor_subsys[ i ]->mss_desc, NULL );
1638 mp = monitor_entrypriv_create();
1642 e->e_private = ( void * )mp;
1643 mp->mp_info = monitor_subsys[ i ];
1644 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1646 if ( monitor_cache_add( mi, e ) ) {
1647 Debug( LDAP_DEBUG_ANY,
1648 "unable to add entry \"%s\" to cache\n",
1649 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1657 assert( be != NULL );
1659 be->be_private = mi;
1662 * opens the monitor backend subsystems
1664 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1665 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1669 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1672 monitor_subsys_opened = 1;
1674 if ( mi->mi_entry_limbo ) {
1675 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
1680 switch ( el->el_type ) {
1682 monitor_back_register_entry(
1687 case LIMBO_ENTRY_PARENT:
1688 monitor_back_register_entry_parent(
1698 monitor_back_register_entry_attrs(
1708 monitor_back_register_entry_callback(
1721 entry_free( el->el_e );
1724 attrs_free( el->el_a );
1726 if ( !BER_BVISNULL( &el->el_ndn ) ) {
1727 ber_memfree( el->el_ndn.bv_val );
1729 if ( !BER_BVISNULL( &el->el_base ) ) {
1730 ber_memfree( el->el_base.bv_val );
1732 if ( !BER_BVISNULL( &el->el_filter ) ) {
1733 ber_memfree( el->el_filter.bv_val );
1741 mi->mi_entry_limbo = NULL;
1748 monitor_back_config(
1756 * eventually, will hold backend specific configuration parameters
1758 return SLAP_CONF_UNKNOWN;
1762 monitor_back_db_config(
1770 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1774 * eventually, will hold database specific configuration parameters
1776 return SLAP_CONF_UNKNOWN;
1780 monitor_back_db_destroy(
1783 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1790 * FIXME: destroys all the data
1792 /* NOTE: mi points to static storage; don't free it */
1794 (void)monitor_cache_destroy( mi );
1796 if ( monitor_subsys ) {
1799 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1800 if ( monitor_subsys[ i ]->mss_destroy ) {
1801 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
1804 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
1805 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
1809 ch_free( monitor_subsys );
1812 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
1814 be->be_private = NULL;
1819 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
1821 /* conditionally define the init_module() function */
1822 SLAP_BACKEND_INIT_MODULE( monitor )
1824 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */