1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 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_nbase;
259 struct berval el_filter;
260 monitor_callback_t *el_cb;
261 monitor_subsys_t *el_mss;
262 unsigned long el_flags;
263 struct entry_limbo_t *el_next;
267 monitor_back_is_configured( void )
269 return be_monitor != NULL;
273 monitor_back_register_entry(
275 monitor_callback_t *cb,
276 monitor_subsys_t *mss,
277 unsigned long flags )
281 if ( be_monitor == NULL ) {
282 Debug( LDAP_DEBUG_ANY,
283 "monitor_back_register_entry(\"%s\"): "
284 "monitor database not configured.\n",
285 e->e_name.bv_val, 0, 0 );
289 mi = ( monitor_info_t * )be_monitor->be_private;
291 assert( mi != NULL );
293 assert( e->e_private == NULL );
295 if ( monitor_subsys_opened ) {
296 Entry *e_parent = NULL,
299 struct berval pdn = BER_BVNULL;
300 monitor_entry_t *mp = NULL,
304 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
306 Debug( LDAP_DEBUG_ANY,
307 "monitor_back_register_entry(\"%s\"): "
309 e->e_name.bv_val, 0, 0 );
310 monitor_cache_release( mi, e_parent );
314 dnParent( &e->e_nname, &pdn );
315 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
316 /* parent does not exist */
317 Debug( LDAP_DEBUG_ANY,
318 "monitor_back_register_entry(\"%s\"): "
319 "parent \"%s\" not found\n",
320 e->e_name.bv_val, pdn.bv_val, 0 );
324 assert( e_parent->e_private != NULL );
325 mp_parent = ( monitor_entry_t * )e_parent->e_private;
327 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
328 /* entry is volatile; cannot append children */
329 Debug( LDAP_DEBUG_ANY,
330 "monitor_back_register_entry(\"%s\"): "
331 "parent \"%s\" is volatile\n",
332 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
337 mp = monitor_entrypriv_create();
339 Debug( LDAP_DEBUG_ANY,
340 "monitor_back_register_entry(\"%s\"): "
341 "monitor_entrypriv_create() failed\n",
342 e->e_name.bv_val, 0, 0 );
347 e_new = entry_dup( e );
348 if ( e_new == NULL ) {
349 Debug( LDAP_DEBUG_ANY,
350 "monitor_back_register_entry(\"%s\"): "
351 "entry_dup() failed\n",
352 e->e_name.bv_val, 0, 0 );
357 e_new->e_private = ( void * )mp;
360 mp->mp_flags = flags;
363 mp->mp_info = mp_parent->mp_info;
364 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
368 ep = &mp_parent->mp_children;
370 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
371 ep = &mp_parent->mp_next;
375 if ( monitor_cache_add( mi, e_new ) ) {
376 Debug( LDAP_DEBUG_ANY,
377 "monitor_back_register_entry(\"%s\"): "
378 "unable to add entry\n",
379 e->e_name.bv_val, 0, 0 );
390 e_new->e_private = NULL;
396 monitor_cache_release( mi, e_parent );
400 entry_limbo_t **elpp, el = { 0 };
402 el.el_type = LIMBO_ENTRY;
404 el.el_e = entry_dup( e );
405 if ( el.el_e == NULL ) {
406 Debug( LDAP_DEBUG_ANY,
407 "monitor_back_register_entry(\"%s\"): "
408 "entry_dup() failed\n",
409 e->e_name.bv_val, 0, 0 );
417 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
419 elpp = &(*elpp)->el_next )
422 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
423 if ( *elpp == NULL ) {
424 el.el_e->e_private = NULL;
425 entry_free( el.el_e );
437 monitor_back_register_entry_parent(
439 monitor_callback_t *cb,
440 monitor_subsys_t *mss,
442 struct berval *nbase,
444 struct berval *filter )
447 struct berval ndn = BER_BVNULL;
449 if ( be_monitor == NULL ) {
450 Debug( LDAP_DEBUG_ANY,
451 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
452 "monitor database not configured.\n",
453 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
454 ldap_pvt_scope2str( scope ),
455 BER_BVISNULL( filter ) ? "" : filter->bv_val );
459 mi = ( monitor_info_t * )be_monitor->be_private;
461 assert( mi != NULL );
463 assert( e->e_private == NULL );
465 if ( BER_BVISNULL( filter ) ) {
467 Debug( LDAP_DEBUG_ANY,
468 "monitor_back_register_entry_parent(\"\"): "
469 "need a valid filter\n",
474 if ( monitor_subsys_opened ) {
475 Entry *e_parent = NULL,
478 struct berval e_name = BER_BVNULL,
479 e_nname = BER_BVNULL;
480 monitor_entry_t *mp = NULL,
484 if ( monitor_filter2ndn( nbase, scope, filter, &ndn ) ) {
485 /* entry does not exist */
486 Debug( LDAP_DEBUG_ANY,
487 "monitor_back_register_entry_parent(\"\"): "
488 "base=\"%s\" scope=%d filter=\"%s\": "
489 "unable to find entry\n",
490 nbase->bv_val ? nbase->bv_val : "\"\"",
491 scope, filter->bv_val );
495 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
496 /* entry does not exist */
497 Debug( LDAP_DEBUG_ANY,
498 "monitor_back_register_entry_parent(\"%s\"): "
499 "parent entry does not exist\n",
505 assert( e_parent->e_private != NULL );
506 mp_parent = ( monitor_entry_t * )e_parent->e_private;
508 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
509 /* entry is volatile; cannot append callback */
510 Debug( LDAP_DEBUG_ANY,
511 "monitor_back_register_entry_parent(\"%s\"): "
512 "entry is volatile\n",
513 e_parent->e_name.bv_val, 0, 0 );
518 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
519 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
521 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
522 /* entry already exists */
523 Debug( LDAP_DEBUG_ANY,
524 "monitor_back_register_entry_parent(\"%s\"): "
525 "entry already exists\n",
526 e_name.bv_val, 0, 0 );
527 monitor_cache_release( mi, e_new );
532 mp = monitor_entrypriv_create();
534 Debug( LDAP_DEBUG_ANY,
535 "monitor_back_register_entry_parent(\"%s\"): "
536 "monitor_entrypriv_create() failed\n",
537 e->e_name.bv_val, 0, 0 );
542 e_new = entry_dup( e );
543 if ( e_new == NULL ) {
544 Debug( LDAP_DEBUG_ANY,
545 "monitor_back_register_entry(\"%s\"): "
546 "entry_dup() failed\n",
547 e->e_name.bv_val, 0, 0 );
551 ch_free( e_new->e_name.bv_val );
552 ch_free( e_new->e_nname.bv_val );
553 e_new->e_name = e_name;
554 e_new->e_nname = e_nname;
556 e_new->e_private = ( void * )mp;
559 mp->mp_flags = flags;
562 mp->mp_info = mp_parent->mp_info;
563 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
567 ep = &mp_parent->mp_children;
569 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
570 ep = &mp_parent->mp_next;
574 if ( monitor_cache_add( mi, e_new ) ) {
575 Debug( LDAP_DEBUG_ANY,
576 "monitor_back_register_entry(\"%s\"): "
577 "unable to add entry\n",
578 e->e_name.bv_val, 0, 0 );
584 if ( !BER_BVISNULL( &ndn ) ) {
585 ch_free( ndn.bv_val );
593 e_new->e_private = NULL;
599 monitor_cache_release( mi, e_parent );
603 entry_limbo_t **elpp = NULL, el = { 0 };
605 el.el_type = LIMBO_ENTRY_PARENT;
607 el.el_e = entry_dup( e );
608 if ( el.el_e == NULL ) {
609 Debug( LDAP_DEBUG_ANY,
610 "monitor_back_register_entry(\"%s\"): "
611 "entry_dup() failed\n",
612 e->e_name.bv_val, 0, 0 );
616 if ( !BER_BVISNULL( nbase ) ) {
617 ber_dupbv( &el.el_nbase, nbase );
621 if ( !BER_BVISNULL( filter ) ) {
622 Filter *f = str2filter( filter->bv_val );
626 filter2bv( f, &el.el_filter );
634 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
636 elpp = &(*elpp)->el_next )
639 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
640 if ( *elpp == NULL ) {
645 if ( *elpp != NULL ) {
650 if ( !BER_BVISNULL( &el.el_filter ) ) {
651 ch_free( el.el_filter.bv_val );
653 if ( !BER_BVISNULL( &el.el_nbase ) ) {
654 ch_free( el.el_nbase.bv_val );
656 entry_free( el.el_e );
665 monitor_filter2ndn_cb( Operation *op, SlapReply *rs )
667 if ( rs->sr_type == REP_SEARCH ) {
668 struct berval *ndn = op->o_callback->sc_private;
670 ber_dupbv( ndn, &rs->sr_entry->e_nname );
678 struct berval *nbase,
680 struct berval *filter,
683 Connection conn = { 0 };
684 OperationBuffer opbuf;
686 SlapReply rs = { 0 };
687 slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
692 if ( be_monitor == NULL ) {
696 op = (Operation *) &opbuf;
697 connection_fake_init( &conn, op, &conn );
699 op->o_tag = LDAP_REQ_SEARCH;
701 /* use global malloc for now */
702 if ( op->o_tmpmemctx ) {
703 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
704 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
705 op->o_tmpmemctx = NULL;
707 op->o_tmpmfuncs = &ch_mfuncs;
709 op->o_bd = be_monitor;
710 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
711 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
713 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
717 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
718 op->o_tmpmemctx ) ) {
723 op->o_callback = &cb;
724 cb.sc_private = (void *)ndn;
726 op->ors_scope = scope;
727 op->ors_filter = str2filter_x( op, filter->bv_val );
728 if ( op->ors_filter == NULL ) {
732 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
733 op->ors_attrs = slap_anlist_no_attrs;
734 op->ors_attrsonly = 0;
735 op->ors_tlimit = SLAP_NO_LIMIT;
737 op->ors_limit = NULL;
738 op->ors_deref = LDAP_DEREF_NEVER;
741 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
743 op->o_dn = be_monitor->be_rootdn;
744 op->o_ndn = be_monitor->be_rootndn;
746 rc = op->o_bd->be_search( op, &rs );
749 if ( op->ors_filter != NULL ) {
750 filter_free_x( op, op->ors_filter );
752 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
753 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
755 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
756 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
758 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
759 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
766 switch ( rs.sr_err ) {
768 if ( BER_BVISNULL( ndn ) ) {
773 case LDAP_SIZELIMIT_EXCEEDED:
775 if ( !BER_BVISNULL( ndn ) ) {
776 ber_memfree( ndn->bv_val );
787 monitor_back_register_entry_attrs(
788 struct berval *ndn_in,
790 monitor_callback_t *cb,
791 struct berval *nbase,
793 struct berval *filter )
796 struct berval ndn = BER_BVNULL;
797 char *fname = ( a == NULL ? "callback" : "attrs" );
799 if ( be_monitor == NULL ) {
800 char buf[ SLAP_TEXT_BUFLEN ];
802 snprintf( buf, sizeof( buf ),
803 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
804 "monitor database not configured.\n",
806 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
807 ldap_pvt_scope2str( scope ),
808 BER_BVISNULL( filter ) ? "" : filter->bv_val );
809 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
814 mi = ( monitor_info_t * )be_monitor->be_private;
816 assert( mi != NULL );
818 if ( ndn_in != NULL ) {
822 if ( a == NULL && cb == NULL ) {
827 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
828 && BER_BVISNULL( filter ) )
831 Debug( LDAP_DEBUG_ANY,
832 "monitor_back_register_entry_%s(\"\"): "
833 "need a valid filter\n",
838 if ( monitor_subsys_opened ) {
840 Attribute **atp = NULL;
841 monitor_entry_t *mp = NULL;
842 monitor_callback_t **mcp = NULL;
846 if ( BER_BVISNULL( &ndn ) ) {
847 if ( monitor_filter2ndn( nbase, scope, filter, &ndn ) ) {
848 char buf[ SLAP_TEXT_BUFLEN ];
850 snprintf( buf, sizeof( buf ),
851 "monitor_back_register_entry_%s(\"\"): "
852 "base=\"%s\" scope=%d filter=\"%s\": "
853 "unable to find entry\n",
855 nbase->bv_val ? nbase->bv_val : "\"\"",
856 scope, filter->bv_val );
858 /* entry does not exist */
859 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
866 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
867 /* entry does not exist */
868 Debug( LDAP_DEBUG_ANY,
869 "monitor_back_register_entry_%s(\"%s\"): "
870 "entry does not exist\n",
871 fname, ndn.bv_val, 0 );
876 assert( e->e_private != NULL );
877 mp = ( monitor_entry_t * )e->e_private;
879 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
880 /* entry is volatile; cannot append callback */
881 Debug( LDAP_DEBUG_ANY,
882 "monitor_back_register_entry_%s(\"%s\"): "
883 "entry is volatile\n",
884 fname, e->e_name.bv_val, 0 );
890 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
891 /* just get to last */ ;
893 for ( ; a != NULL; a = a->a_next ) {
894 assert( a->a_desc != NULL );
895 assert( a->a_vals != NULL );
897 if ( attr_find( e->e_attrs, a->a_desc ) ) {
898 attr_merge( e, a->a_desc, a->a_vals,
899 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
902 *atp = attr_dup( a );
903 if ( *atp == NULL ) {
904 Debug( LDAP_DEBUG_ANY,
905 "monitor_back_register_entry_%s(\"%s\"): "
906 "attr_dup() failed\n",
907 fname, e->e_name.bv_val, 0 );
911 atp = &(*atp)->a_next;
917 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
920 /* NOTE: we do not clear cb->mc_next, so this function
921 * can be used to append a list of callbacks */
934 ber_memfree( ndn.bv_val );
938 monitor_cache_release( mi, e );
942 entry_limbo_t **elpp, el = { 0 };
944 el.el_type = LIMBO_ATTRS;
945 if ( !BER_BVISNULL( &ndn ) ) {
946 ber_dupbv( &el.el_ndn, &ndn );
948 if ( !BER_BVISNULL( nbase ) ) {
949 ber_dupbv( &el.el_nbase, nbase);
952 if ( !BER_BVISNULL( filter ) ) {
953 Filter *f = str2filter( filter->bv_val );
957 filter2bv( f, &el.el_filter );
961 el.el_a = attrs_dup( a );
964 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
966 elpp = &(*elpp)->el_next )
969 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
970 if ( *elpp == NULL ) {
971 el.el_e->e_private = NULL;
972 entry_free( el.el_e );
977 if ( *elpp != NULL ) {
982 if ( !BER_BVISNULL( &el.el_filter ) ) {
983 ch_free( el.el_filter.bv_val );
985 if ( el.el_a != NULL ) {
986 attrs_free( el.el_a );
988 if ( !BER_BVISNULL( &el.el_nbase ) ) {
989 ch_free( &el.el_nbase.bv_val );
991 if ( !BER_BVISNULL( &el.el_ndn ) ) {
992 ch_free( el.el_ndn.bv_val );
1002 monitor_back_register_entry_callback(
1004 monitor_callback_t *cb,
1005 struct berval *nbase,
1007 struct berval *filter )
1009 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1010 nbase, scope, filter );
1014 * TODO: add corresponding calls to remove installed callbacks, entries
1015 * and so, in case the entity that installed them is removed (e.g. a
1016 * database, via back-config)
1019 monitor_back_unregister_entry(
1020 struct berval *ndn )
1024 if ( be_monitor == NULL ) {
1025 Debug( LDAP_DEBUG_ANY,
1026 "monitor_back_unregister_entry(\"%s\"): "
1027 "monitor database not configured.\n",
1028 ndn->bv_val, 0, 0 );
1033 mi = ( monitor_info_t * )be_monitor->be_private;
1035 assert( mi != NULL );
1037 if ( monitor_subsys_opened ) {
1039 monitor_entry_t *mp = NULL;
1040 monitor_callback_t *cb = NULL;
1042 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1043 /* entry does not exist */
1044 Debug( LDAP_DEBUG_ANY,
1045 "monitor_back_unregister_entry(\"%s\"): "
1046 "entry removal failed.\n",
1047 ndn->bv_val, 0, 0 );
1051 mp = (monitor_entry_t *)e->e_private;
1052 assert( mp != NULL );
1054 for ( cb = mp->mp_cb; cb != NULL; ) {
1055 monitor_callback_t *next = cb->mc_next;
1057 if ( cb->mc_free ) {
1058 (void)cb->mc_free( e, cb->mc_private );
1066 e->e_private = NULL;
1070 entry_limbo_t **elpp;
1072 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1074 elpp = &(*elpp)->el_next )
1076 entry_limbo_t *elp = *elpp;
1078 if ( elp->el_type == LIMBO_ENTRY
1079 && dn_match( ndn, &elp->el_e->e_nname ) )
1081 monitor_callback_t *cb, *next;
1083 for ( cb = elp->el_cb; cb; cb = next ) {
1084 /* FIXME: call callbacks? */
1088 assert( elp->el_e != NULL );
1089 elp->el_e->e_private = NULL;
1090 entry_free( elp->el_e );
1091 *elpp = elp->el_next;
1098 if ( elpp != NULL ) {
1099 /* not found! where did it go? */
1108 monitor_back_unregister_entry_parent(
1109 struct berval *nrdn,
1110 monitor_callback_t *target_cb,
1111 struct berval *nbase,
1113 struct berval *filter )
1116 struct berval ndn = BER_BVNULL;
1118 if ( be_monitor == NULL ) {
1119 Debug( LDAP_DEBUG_ANY,
1120 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1121 "monitor database not configured.\n",
1122 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1123 ldap_pvt_scope2str( scope ),
1124 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1129 mi = ( monitor_info_t * )be_monitor->be_private;
1131 assert( mi != NULL );
1133 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1134 && BER_BVISNULL( filter ) )
1137 Debug( LDAP_DEBUG_ANY,
1138 "monitor_back_unregister_entry_parent(\"\"): "
1139 "need a valid filter\n",
1144 if ( monitor_subsys_opened ) {
1146 monitor_entry_t *mp = NULL;
1148 if ( monitor_filter2ndn( nbase, scope, filter, &ndn ) ) {
1149 /* entry does not exist */
1150 Debug( LDAP_DEBUG_ANY,
1151 "monitor_back_unregister_entry_parent(\"\"): "
1152 "base=\"%s\" scope=%s filter=\"%s\": "
1153 "unable to find entry\n",
1154 nbase->bv_val ? nbase->bv_val : "\"\"",
1155 ldap_pvt_scope2str( scope ),
1160 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1161 /* entry does not exist */
1162 Debug( LDAP_DEBUG_ANY,
1163 "monitor_back_unregister_entry(\"%s\"): "
1164 "entry removal failed.\n",
1166 ber_memfree( ndn.bv_val );
1169 ber_memfree( ndn.bv_val );
1171 mp = (monitor_entry_t *)e->e_private;
1172 assert( mp != NULL );
1174 if ( target_cb != NULL ) {
1175 monitor_callback_t **cbp;
1177 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1178 if ( *cbp == target_cb ) {
1179 if ( (*cbp)->mc_free ) {
1180 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1182 *cbp = (*cbp)->mc_next;
1183 ch_free( target_cb );
1191 e->e_private = NULL;
1195 entry_limbo_t **elpp;
1197 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1199 elpp = &(*elpp)->el_next )
1201 entry_limbo_t *elp = *elpp;
1203 if ( elp->el_type == LIMBO_ENTRY_PARENT
1204 && dn_match( nrdn, &elp->el_e->e_nname )
1205 && dn_match( nbase, &elp->el_nbase )
1206 && scope == elp->el_scope
1207 && bvmatch( filter, &elp->el_filter ) )
1209 monitor_callback_t *cb, *next;
1211 for ( cb = elp->el_cb; cb; cb = next ) {
1212 /* FIXME: call callbacks? */
1216 assert( elp->el_e != NULL );
1217 elp->el_e->e_private = NULL;
1218 entry_free( elp->el_e );
1219 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1220 ch_free( elp->el_nbase.bv_val );
1222 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1223 ch_free( elp->el_filter.bv_val );
1225 *elpp = elp->el_next;
1232 if ( elpp != NULL ) {
1233 /* not found! where did it go? */
1242 monitor_back_unregister_entry_attrs(
1243 struct berval *ndn_in,
1244 Attribute *target_a,
1245 monitor_callback_t *target_cb,
1246 struct berval *nbase,
1248 struct berval *filter )
1251 struct berval ndn = BER_BVNULL;
1252 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1254 if ( be_monitor == NULL ) {
1255 char buf[ SLAP_TEXT_BUFLEN ];
1257 snprintf( buf, sizeof( buf ),
1258 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1259 "monitor database not configured.\n",
1261 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1262 ldap_pvt_scope2str( scope ),
1263 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1264 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1269 mi = ( monitor_info_t * )be_monitor->be_private;
1271 assert( mi != NULL );
1273 if ( ndn_in != NULL ) {
1277 if ( target_a == NULL && target_cb == NULL ) {
1282 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1283 && BER_BVISNULL( filter ) )
1286 Debug( LDAP_DEBUG_ANY,
1287 "monitor_back_unregister_entry_%s(\"\"): "
1288 "need a valid filter\n",
1293 if ( monitor_subsys_opened ) {
1295 monitor_entry_t *mp = NULL;
1298 if ( BER_BVISNULL( &ndn ) ) {
1299 if ( monitor_filter2ndn( nbase, scope, filter, &ndn ) ) {
1300 char buf[ SLAP_TEXT_BUFLEN ];
1302 snprintf( buf, sizeof( buf ),
1303 "monitor_back_unregister_entry_%s(\"\"): "
1304 "base=\"%s\" scope=%d filter=\"%s\": "
1305 "unable to find entry\n",
1307 nbase->bv_val ? nbase->bv_val : "\"\"",
1308 scope, filter->bv_val );
1310 /* entry does not exist */
1311 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1318 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1319 /* entry does not exist */
1320 Debug( LDAP_DEBUG_ANY,
1321 "monitor_back_unregister_entry(\"%s\"): "
1322 "entry removal failed.\n",
1327 mp = (monitor_entry_t *)e->e_private;
1328 assert( mp != NULL );
1330 if ( target_cb != NULL ) {
1331 monitor_callback_t **cbp;
1333 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1334 if ( *cbp == target_cb ) {
1335 if ( (*cbp)->mc_free ) {
1336 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1338 *cbp = (*cbp)->mc_next;
1339 ch_free( target_cb );
1345 if ( target_a != NULL ) {
1348 for ( a = target_a; a != NULL; a = a->a_next ) {
1349 Modification mod = { 0 };
1351 char textbuf[ SLAP_TEXT_BUFLEN ];
1353 mod.sm_op = LDAP_MOD_DELETE;
1354 mod.sm_desc = a->a_desc;
1355 mod.sm_values = a->a_vals;
1356 mod.sm_nvalues = a->a_nvals;
1358 (void)modify_delete_values( e, &mod, 1,
1359 &text, textbuf, sizeof( textbuf ) );
1364 ber_memfree( ndn.bv_val );
1368 monitor_cache_release( mi, e );
1372 entry_limbo_t **elpp;
1374 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1376 elpp = &(*elpp)->el_next )
1378 entry_limbo_t *elp = *elpp;
1380 if ( elp->el_type == LIMBO_ATTRS
1381 && dn_match( nbase, &elp->el_nbase )
1382 && scope == elp->el_scope
1383 && bvmatch( filter, &elp->el_filter ) )
1385 monitor_callback_t *cb, *next;
1387 for ( cb = elp->el_cb; cb; cb = next ) {
1388 /* FIXME: call callbacks? */
1392 assert( elp->el_e == NULL );
1393 if ( elp->el_a != NULL ) {
1394 attrs_free( elp->el_a );
1396 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1397 ch_free( elp->el_nbase.bv_val );
1399 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1400 ch_free( elp->el_filter.bv_val );
1402 *elpp = elp->el_next;
1409 if ( elpp != NULL ) {
1410 /* not found! where did it go? */
1419 monitor_back_unregister_entry_callback(
1421 monitor_callback_t *cb,
1422 struct berval *nbase,
1424 struct berval *filter )
1426 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1427 * unregister the callback; if a is not null, unregister the
1428 * given attrs. In any case, call cb->cb_free */
1429 return monitor_back_unregister_entry_attrs( ndn,
1430 NULL, cb, nbase, scope, filter );
1434 monitor_back_get_subsys( const char *name )
1436 if ( monitor_subsys != NULL ) {
1439 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1440 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1441 return monitor_subsys[ i ];
1450 monitor_back_get_subsys_by_dn(
1454 if ( monitor_subsys != NULL ) {
1458 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1459 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1460 return monitor_subsys[ i ];
1465 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1466 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1467 return monitor_subsys[ i ];
1477 monitor_back_initialize(
1480 static char *controls[] = {
1481 LDAP_CONTROL_MANAGEDSAIT,
1485 static ConfigTable monitorcfg[] = {
1486 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1487 NULL, NULL, NULL, NULL }
1490 static ConfigOCs monitorocs[] = {
1491 { "( OLcfgDbOc:4.1 "
1492 "NAME 'olcMonitorConfig' "
1493 "DESC 'Monitor backend configuration' "
1494 "SUP olcDatabaseConfig "
1496 Cft_Database, monitorcfg },
1506 { "monitor", "( 1.3.6.1.4.1.4203.666.3.16.1 "
1508 "DESC 'OpenLDAP system monitoring' "
1509 "SUP top STRUCTURAL "
1518 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1519 offsetof(monitor_info_t, mi_oc_monitor) },
1520 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.16.2 "
1521 "NAME 'monitorServer' "
1522 "DESC 'Server monitoring root entry' "
1523 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1524 offsetof(monitor_info_t, mi_oc_monitorServer) },
1525 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.16.3 "
1526 "NAME 'monitorContainer' "
1527 "DESC 'monitor container class' "
1528 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1529 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1530 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.16.4 "
1531 "NAME 'monitorCounterObject' "
1532 "DESC 'monitor counter class' "
1533 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1534 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1535 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.16.5 "
1536 "NAME 'monitorOperation' "
1537 "DESC 'monitor operation class' "
1538 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1539 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1540 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.16.6 "
1541 "NAME 'monitorConnection' "
1542 "DESC 'monitor connection class' "
1543 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1544 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1545 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.16.7 "
1546 "NAME 'managedObject' "
1547 "DESC 'monitor managed entity class' "
1548 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1549 offsetof(monitor_info_t, mi_oc_managedObject) },
1550 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.16.8 "
1551 "NAME 'monitoredObject' "
1552 "DESC 'monitor monitored entity class' "
1553 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1554 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1555 { NULL, NULL, 0, -1 }
1557 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.55.1 "
1558 "NAME 'monitoredInfo' "
1559 "DESC 'monitored info' "
1561 "EQUALITY caseIgnoreMatch "
1562 "SUBSTR caseIgnoreSubstringsMatch "
1563 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1564 "NO-USER-MODIFICATION "
1565 "USAGE directoryOperation )", SLAP_AT_HIDE,
1566 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1567 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.55.2 "
1568 "NAME 'managedInfo' "
1569 "DESC 'monitor managed info' "
1570 "SUP name )", SLAP_AT_HIDE,
1571 offsetof(monitor_info_t, mi_ad_managedInfo) },
1572 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.55.3 "
1573 "NAME 'monitorCounter' "
1574 "DESC 'monitor counter' "
1575 "EQUALITY integerMatch "
1576 "ORDERING integerOrderingMatch "
1577 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1578 "NO-USER-MODIFICATION "
1579 "USAGE directoryOperation )", SLAP_AT_HIDE,
1580 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1581 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.55.4 "
1582 "NAME 'monitorOpCompleted' "
1583 "DESC 'monitor completed operations' "
1584 "SUP monitorCounter "
1585 "NO-USER-MODIFICATION "
1586 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1587 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1588 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.55.5 "
1589 "NAME 'monitorOpInitiated' "
1590 "DESC 'monitor initiated operations' "
1591 "SUP monitorCounter "
1592 "NO-USER-MODIFICATION "
1593 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1594 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1595 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.55.6 "
1596 "NAME 'monitorConnectionNumber' "
1597 "DESC 'monitor connection number' "
1598 "SUP monitorCounter "
1599 "NO-USER-MODIFICATION "
1600 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1601 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1602 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.55.7 "
1603 "NAME 'monitorConnectionAuthzDN' "
1604 "DESC 'monitor connection authorization DN' "
1605 /* "SUP distinguishedName " */
1606 "EQUALITY distinguishedNameMatch "
1607 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1608 "NO-USER-MODIFICATION "
1609 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1610 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1611 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.55.8 "
1612 "NAME 'monitorConnectionLocalAddress' "
1613 "DESC 'monitor connection local address' "
1614 "SUP monitoredInfo "
1615 "NO-USER-MODIFICATION "
1616 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1617 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1618 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.55.9 "
1619 "NAME 'monitorConnectionPeerAddress' "
1620 "DESC 'monitor connection peer address' "
1621 "SUP monitoredInfo "
1622 "NO-USER-MODIFICATION "
1623 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1624 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1625 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.55.10 "
1626 "NAME 'monitorTimestamp' "
1627 "DESC 'monitor timestamp' "
1628 "EQUALITY generalizedTimeMatch "
1629 "ORDERING generalizedTimeOrderingMatch "
1630 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1632 "NO-USER-MODIFICATION "
1633 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1634 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1635 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.55.11 "
1636 "NAME 'monitorOverlay' "
1637 "DESC 'name of overlays defined for a given database' "
1638 "SUP monitoredInfo "
1639 "NO-USER-MODIFICATION "
1640 "USAGE directoryOperation )", SLAP_AT_HIDE,
1641 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1642 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.55.12 "
1644 "DESC 'read/write status of a given database' "
1645 "EQUALITY booleanMatch "
1646 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1648 "USAGE directoryOperation )", SLAP_AT_HIDE,
1649 offsetof(monitor_info_t, mi_ad_readOnly) },
1650 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.55.13 "
1651 "NAME 'restrictedOperation' "
1652 "DESC 'name of restricted operation for a given database' "
1653 "SUP managedInfo )", SLAP_AT_HIDE,
1654 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1655 { "monitorConnectionProtocol", "( 1.3.6.1.4.1.4203.666.1.55.14 "
1656 "NAME 'monitorConnectionProtocol' "
1657 "DESC 'monitor connection protocol' "
1658 "SUP monitoredInfo "
1659 "NO-USER-MODIFICATION "
1660 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1661 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1662 { "monitorConnectionOpsReceived", "( 1.3.6.1.4.1.4203.666.1.55.15 "
1663 "NAME 'monitorConnectionOpsReceived' "
1664 "DESC 'monitor number of operations received by the connection' "
1665 "SUP monitorCounter "
1666 "NO-USER-MODIFICATION "
1667 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1668 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1669 { "monitorConnectionOpsExecuting", "( 1.3.6.1.4.1.4203.666.1.55.16 "
1670 "NAME 'monitorConnectionOpsExecuting' "
1671 "DESC 'monitor number of operations in execution within the connection' "
1672 "SUP monitorCounter "
1673 "NO-USER-MODIFICATION "
1674 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1675 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1676 { "monitorConnectionOpsPending", "( 1.3.6.1.4.1.4203.666.1.55.17 "
1677 "NAME 'monitorConnectionOpsPending' "
1678 "DESC 'monitor number of pending operations within the connection' "
1679 "SUP monitorCounter "
1680 "NO-USER-MODIFICATION "
1681 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1682 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1683 { "monitorConnectionOpsCompleted", "( 1.3.6.1.4.1.4203.666.1.55.18 "
1684 "NAME 'monitorConnectionOpsCompleted' "
1685 "DESC 'monitor number of operations completed within the connection' "
1686 "SUP monitorCounter "
1687 "NO-USER-MODIFICATION "
1688 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1689 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1690 { "monitorConnectionGet", "( 1.3.6.1.4.1.4203.666.1.55.19 "
1691 "NAME 'monitorConnectionGet' "
1692 "DESC 'number of times connection_get() was called so far' "
1693 "SUP monitorCounter "
1694 "NO-USER-MODIFICATION "
1695 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1696 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1697 { "monitorConnectionRead", "( 1.3.6.1.4.1.4203.666.1.55.20 "
1698 "NAME 'monitorConnectionRead' "
1699 "DESC 'number of times connection_read() was called so far' "
1700 "SUP monitorCounter "
1701 "NO-USER-MODIFICATION "
1702 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1703 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1704 { "monitorConnectionWrite", "( 1.3.6.1.4.1.4203.666.1.55.21 "
1705 "NAME 'monitorConnectionWrite' "
1706 "DESC 'number of times connection_write() was called so far' "
1707 "SUP monitorCounter "
1708 "NO-USER-MODIFICATION "
1709 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1710 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1711 { "monitorConnectionMask", "( 1.3.6.1.4.1.4203.666.1.55.22 "
1712 "NAME 'monitorConnectionMask' "
1713 "DESC 'monitor connection mask' "
1714 "SUP monitoredInfo "
1715 "NO-USER-MODIFICATION "
1716 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1717 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1718 { "monitorConnectionListener", "( 1.3.6.1.4.1.4203.666.1.55.23 "
1719 "NAME 'monitorConnectionListener' "
1720 "DESC 'monitor connection listener' "
1721 "SUP monitoredInfo "
1722 "NO-USER-MODIFICATION "
1723 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1724 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1725 { "monitorConnectionPeerDomain", "( 1.3.6.1.4.1.4203.666.1.55.24 "
1726 "NAME 'monitorConnectionPeerDomain' "
1727 "DESC 'monitor connection peer domain' "
1728 "SUP monitoredInfo "
1729 "NO-USER-MODIFICATION "
1730 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1731 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1732 { "monitorConnectionStartTime", "( 1.3.6.1.4.1.4203.666.1.55.25 "
1733 "NAME 'monitorConnectionStartTime' "
1734 "DESC 'monitor connection start time' "
1735 "SUP monitorTimestamp "
1737 "NO-USER-MODIFICATION "
1738 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1739 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1740 { "monitorConnectionActivityTime", "( 1.3.6.1.4.1.4203.666.1.55.26 "
1741 "NAME 'monitorConnectionActivityTime' "
1742 "DESC 'monitor connection activity time' "
1743 "SUP monitorTimestamp "
1745 "NO-USER-MODIFICATION "
1746 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1747 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1748 { "monitorIsShadow", "( 1.3.6.1.4.1.4203.666.1.55.27 "
1749 "NAME 'monitorIsShadow' "
1750 "DESC 'TRUE if the database is shadow' "
1751 "EQUALITY booleanMatch "
1752 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1754 "USAGE directoryOperation )", SLAP_AT_HIDE,
1755 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1756 { "monitorUpdateRef", "( 1.3.6.1.4.1.4203.666.1.55.28 "
1757 "NAME 'monitorUpdateRef' "
1758 "DESC 'update referral for shadow databases' "
1759 "SUP monitoredInfo "
1761 "USAGE directoryOperation )", SLAP_AT_HIDE,
1762 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1763 { "monitorRuntimeConfig", "( 1.3.6.1.4.1.4203.666.1.55.29 "
1764 "NAME 'monitorRuntimeConfig' "
1765 "DESC 'TRUE if component allows runtime configuration' "
1766 "EQUALITY booleanMatch "
1767 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1769 "USAGE directoryOperation )", SLAP_AT_HIDE,
1770 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1771 { NULL, NULL, 0, -1 }
1778 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1779 { "olmSubSystemAttributes", "olmAttributes:0" },
1780 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1781 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1783 /* for example, back-bdb specific attrs
1784 * are in "olmDatabaseAttributes:1"
1786 * NOTE: developers, please record here OID assignments
1787 * for other modules */
1789 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1790 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1791 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1792 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1794 /* for example, back-bdb specific objectClasses
1795 * are in "olmDatabaseObjectClasses:1"
1797 * NOTE: developers, please record here OID assignments
1798 * for other modules */
1805 monitor_info_t *mi = &monitor_info;
1807 for ( i = 0; s_oid[ i ].name; i++ ) {
1810 argv[ 0 ] = "monitor";
1811 argv[ 1 ] = s_oid[ i ].name;
1812 argv[ 2 ] = s_oid[ i ].oid;
1814 if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) {
1815 Debug( LDAP_DEBUG_ANY,
1816 "monitor_back_initialize: unable to add "
1817 "objectIdentifier \"%s=%s\"\n",
1818 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1823 /* schema integration */
1824 for ( i = 0; mat[ i ].name; i++ ) {
1825 LDAPAttributeType *at;
1828 AttributeDescription **ad;
1830 at = ldap_str2attributetype( mat[ i ].schema, &code,
1831 &err, LDAP_SCHEMA_ALLOW_ALL );
1833 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1834 "in AttributeType \"%s\" %s before %s\n",
1835 mat[ i ].name, ldap_scherr2str(code), err );
1839 if ( at->at_oid == NULL ) {
1840 ldap_attributetype_free(at);
1841 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1842 "null OID for attributeType \"%s\"\n",
1843 mat[ i ].name, 0, 0 );
1847 code = at_add(at, 0, NULL, &err);
1849 ldap_attributetype_free(at);
1850 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1851 "%s in attributeType \"%s\"\n",
1852 scherr2str(code), mat[ i ].name, 0 );
1857 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1859 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1860 Debug( LDAP_DEBUG_ANY,
1861 "monitor_back_db_init: %s\n", text, 0, 0 );
1865 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1868 for ( i = 0; moc[ i ].name; i++ ) {
1869 LDAPObjectClass *oc;
1874 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1875 LDAP_SCHEMA_ALLOW_ALL );
1877 Debug( LDAP_DEBUG_ANY,
1878 "unable to parse monitor objectclass \"%s\": "
1879 "%s before %s\n" , moc[ i ].name,
1880 ldap_scherr2str(code), err );
1884 if ( oc->oc_oid == NULL ) {
1885 ldap_objectclass_free(oc);
1886 Debug( LDAP_DEBUG_ANY,
1887 "objectclass \"%s\" has no OID\n" ,
1888 moc[ i ].name, 0, 0 );
1892 code = oc_add(oc, 0, NULL, &err);
1894 ldap_objectclass_free(oc);
1895 Debug( LDAP_DEBUG_ANY,
1896 "objectclass \"%s\": %s \"%s\"\n" ,
1897 moc[ i ].name, scherr2str(code), err );
1902 Oc = oc_find( moc[ i ].name );
1904 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1905 "unable to find objectClass %s "
1906 "(just added)\n", moc[ i ].name, 0, 0 );
1910 Oc->soc_flags |= moc[ i ].flags;
1912 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1915 bi->bi_controls = controls;
1919 bi->bi_config = monitor_back_config;
1923 bi->bi_db_init = monitor_back_db_init;
1925 bi->bi_db_config = monitor_back_db_config;
1927 bi->bi_db_open = monitor_back_db_open;
1928 bi->bi_db_close = 0;
1929 bi->bi_db_destroy = monitor_back_db_destroy;
1931 bi->bi_op_bind = monitor_back_bind;
1932 bi->bi_op_unbind = 0;
1933 bi->bi_op_search = monitor_back_search;
1934 bi->bi_op_compare = monitor_back_compare;
1935 bi->bi_op_modify = monitor_back_modify;
1936 bi->bi_op_modrdn = 0;
1938 bi->bi_op_delete = 0;
1939 bi->bi_op_abandon = 0;
1941 bi->bi_extended = 0;
1943 bi->bi_entry_release_rw = 0;
1944 bi->bi_chk_referrals = 0;
1945 bi->bi_operational = monitor_back_operational;
1948 * hooks for slap tools
1950 bi->bi_tool_entry_open = 0;
1951 bi->bi_tool_entry_close = 0;
1952 bi->bi_tool_entry_first = 0;
1953 bi->bi_tool_entry_next = 0;
1954 bi->bi_tool_entry_get = 0;
1955 bi->bi_tool_entry_put = 0;
1956 bi->bi_tool_entry_reindex = 0;
1957 bi->bi_tool_sync = 0;
1958 bi->bi_tool_dn2id_get = 0;
1959 bi->bi_tool_id2entry_get = 0;
1960 bi->bi_tool_entry_modify = 0;
1962 bi->bi_connection_init = 0;
1963 bi->bi_connection_destroy = 0;
1966 * configuration objectClasses (fake)
1968 bi->bi_cf_ocs = monitorocs;
1970 rc = config_register_schema( monitorcfg, monitorocs );
1979 monitor_back_db_init(
1983 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1988 monitor_subsys_t *ms;
1993 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1994 if ( monitor_back_register_subsys( ms ) ) {
2000 * database monitor can be defined once only
2002 if ( be_monitor != NULL ) {
2003 Debug( LDAP_DEBUG_ANY,
2004 "only one monitor database is allowed\n", 0, 0, 0 );
2009 /* indicate system schema supported */
2010 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2012 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2013 if( rc != LDAP_SUCCESS ) {
2014 Debug( LDAP_DEBUG_ANY,
2015 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2020 ber_bvarray_add( &be->be_suffix, &pdn );
2021 ber_bvarray_add( &be->be_nsuffix, &ndn );
2023 /* NOTE: only one monitor database is allowed,
2024 * so we use static storage */
2025 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2027 be->be_private = &monitor_info;
2029 be2 = select_backend( &ndn, 0, 0 );
2031 char *type = be2->bd_info->bi_type;
2033 if ( overlay_is_over( be2 ) ) {
2034 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2035 type = oi->oi_orig->bi_type;
2038 Debug( LDAP_DEBUG_ANY,
2039 "\"monitor\" database serving namingContext \"%s\" "
2040 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2041 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2049 monitor_back_db_open(
2052 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2053 struct monitor_subsys_t **ms;
2054 Entry *e, **ep, *root;
2055 monitor_entry_t *mp;
2057 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2059 #ifdef HAVE_GMTIME_R
2062 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2063 struct berval desc[] = {
2064 BER_BVC("This subtree contains monitoring/managing objects."),
2065 BER_BVC("This object contains information about this server."),
2066 BER_BVC("Most of the information is held in operational"
2067 " attributes, which must be explicitly requested."),
2070 assert( be_monitor != NULL );
2071 if ( be != be_monitor ) {
2078 #ifndef HAVE_GMTIME_R
2079 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2081 #ifdef HACK_LOCAL_TIME
2082 # ifdef HAVE_LOCALTIME_R
2083 tms = localtime_r( &starttime, &tm_buf );
2085 tms = localtime( &starttime );
2086 # endif /* HAVE_LOCALTIME_R */
2087 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2088 #else /* !HACK_LOCAL_TIME */
2089 # ifdef HAVE_GMTIME_R
2090 tms = gmtime_r( &starttime, &tm_buf );
2092 tms = gmtime( &starttime );
2093 # endif /* HAVE_GMTIME_R */
2094 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2095 #endif /* !HACK_LOCAL_TIME */
2096 #ifndef HAVE_GMTIME_R
2097 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2100 mi->mi_startTime.bv_val = tmbuf;
2101 mi->mi_startTime.bv_len = strlen( tmbuf );
2103 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2104 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2105 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2107 mi->mi_creatorsName = be->be_rootdn;
2108 mi->mi_ncreatorsName = be->be_rootndn;
2112 * creates the "cn=Monitor" entry
2114 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2118 Debug( LDAP_DEBUG_ANY,
2119 "unable to create \"%s\" entry\n",
2120 SLAPD_MONITOR_DN, 0, 0 );
2124 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2126 bv.bv_val = strchr( (char *) Versionstr, '$' );
2127 if ( bv.bv_val != NULL ) {
2131 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2134 end = strchr( bv.bv_val, '$' );
2135 if ( end != NULL ) {
2138 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2143 bv.bv_len = end - bv.bv_val;
2146 bv.bv_len = strlen( bv.bv_val );
2149 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2151 Debug( LDAP_DEBUG_ANY,
2152 "unable to add monitoredInfo to \"%s\" entry\n",
2153 SLAPD_MONITOR_DN, 0, 0 );
2158 mp = monitor_entrypriv_create();
2162 e->e_private = ( void * )mp;
2163 ep = &mp->mp_children;
2165 if ( monitor_cache_add( mi, e ) ) {
2166 Debug( LDAP_DEBUG_ANY,
2167 "unable to add entry \"%s\" to cache\n",
2168 SLAPD_MONITOR_DN, 0, 0 );
2174 * Create all the subsystem specific entries
2176 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2177 int len = strlen( monitor_subsys[ i ]->mss_name );
2181 dn.bv_len = len + sizeof( "cn=" ) - 1;
2182 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2183 strcpy( dn.bv_val, "cn=" );
2184 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2185 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2187 if ( rc != LDAP_SUCCESS ) {
2188 Debug( LDAP_DEBUG_ANY,
2189 "monitor RDN \"%s\" is invalid\n",
2194 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2195 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2199 Debug( LDAP_DEBUG_ANY,
2200 "unable to create \"%s\" entry\n",
2201 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2204 monitor_subsys[i]->mss_dn = e->e_name;
2205 monitor_subsys[i]->mss_ndn = e->e_nname;
2207 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2208 attr_merge_normalize( e, slap_schema.si_ad_description,
2209 monitor_subsys[ i ]->mss_desc, NULL );
2212 mp = monitor_entrypriv_create();
2216 e->e_private = ( void * )mp;
2217 mp->mp_info = monitor_subsys[ i ];
2218 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2220 if ( monitor_cache_add( mi, e ) ) {
2221 Debug( LDAP_DEBUG_ANY,
2222 "unable to add entry \"%s\" to cache\n",
2223 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2231 assert( be != NULL );
2233 be->be_private = mi;
2236 * opens the monitor backend subsystems
2238 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2239 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2243 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2246 monitor_subsys_opened = 1;
2248 if ( mi->mi_entry_limbo ) {
2249 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
2254 switch ( el->el_type ) {
2256 monitor_back_register_entry(
2263 case LIMBO_ENTRY_PARENT:
2264 monitor_back_register_entry_parent(
2276 monitor_back_register_entry_attrs(
2286 monitor_back_register_entry_callback(
2299 entry_free( el->el_e );
2302 attrs_free( el->el_a );
2304 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2305 ber_memfree( el->el_ndn.bv_val );
2307 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2308 ber_memfree( el->el_nbase.bv_val );
2310 if ( !BER_BVISNULL( &el->el_filter ) ) {
2311 ber_memfree( el->el_filter.bv_val );
2319 mi->mi_entry_limbo = NULL;
2326 monitor_back_config(
2334 * eventually, will hold backend specific configuration parameters
2336 return SLAP_CONF_UNKNOWN;
2341 monitor_back_db_config(
2348 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2351 * eventually, will hold database specific configuration parameters
2353 return SLAP_CONF_UNKNOWN;
2358 monitor_back_db_destroy(
2361 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2368 * FIXME: destroys all the data
2370 /* NOTE: mi points to static storage; don't free it */
2372 (void)monitor_cache_destroy( mi );
2374 if ( monitor_subsys ) {
2377 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2378 if ( monitor_subsys[ i ]->mss_destroy ) {
2379 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2382 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2383 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2387 ch_free( monitor_subsys );
2390 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2392 be->be_private = NULL;
2397 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2399 /* conditionally define the init_module() function */
2400 SLAP_BACKEND_INIT_MODULE( monitor )
2402 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */