1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2007 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"
35 #undef INTEGRATE_CORE_SCHEMA
38 * used by many functions to add description to entries
40 * WARNING: be_monitor may change as new databases are added,
41 * so it should not be used outside monitor_back_db_init()
42 * until monitor_back_db_open is called.
44 BackendDB *be_monitor;
46 static struct monitor_subsys_t **monitor_subsys;
47 static int monitor_subsys_opened;
48 static monitor_info_t monitor_info;
49 static const monitor_extra_t monitor_extra = {
50 monitor_back_is_configured,
51 monitor_back_get_subsys,
52 monitor_back_get_subsys_by_dn,
54 monitor_back_register_subsys,
55 monitor_back_register_backend,
56 monitor_back_register_database,
57 monitor_back_register_overlay_info,
58 monitor_back_register_overlay,
59 monitor_back_register_entry,
60 monitor_back_register_entry_parent,
61 monitor_back_register_entry_attrs,
62 monitor_back_register_entry_callback,
64 monitor_back_unregister_entry,
65 monitor_back_unregister_entry_parent,
66 monitor_back_unregister_entry_attrs,
67 monitor_back_unregister_entry_callback
74 * the known subsystems are added to the subsystems
75 * array at backend initialization; other subsystems
76 * may be added by calling monitor_back_register_subsys()
77 * before the database is opened (e.g. by other backends
78 * or by overlays or modules).
80 static struct monitor_subsys_t known_monitor_subsys[] = {
82 SLAPD_MONITOR_BACKEND_NAME,
83 BER_BVNULL, BER_BVNULL, BER_BVNULL,
84 { BER_BVC( "This subsystem contains information about available backends." ),
86 MONITOR_F_PERSISTENT_CH,
87 monitor_subsys_backend_init,
93 SLAPD_MONITOR_CONN_NAME,
94 BER_BVNULL, BER_BVNULL, BER_BVNULL,
95 { BER_BVC( "This subsystem contains information about connections." ),
97 MONITOR_F_VOLATILE_CH,
98 monitor_subsys_conn_init,
104 SLAPD_MONITOR_DATABASE_NAME,
105 BER_BVNULL, BER_BVNULL, BER_BVNULL,
106 { BER_BVC( "This subsystem contains information about configured databases." ),
108 MONITOR_F_PERSISTENT_CH,
109 monitor_subsys_database_init,
115 SLAPD_MONITOR_LISTENER_NAME,
116 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 { BER_BVC( "This subsystem contains information about active listeners." ),
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_listener_init,
126 SLAPD_MONITOR_LOG_NAME,
127 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128 { BER_BVC( "This subsystem contains information about logging." ),
129 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
132 monitor_subsys_log_init,
138 SLAPD_MONITOR_OPS_NAME,
139 BER_BVNULL, BER_BVNULL, BER_BVNULL,
140 { BER_BVC( "This subsystem contains information about performed operations." ),
142 MONITOR_F_PERSISTENT_CH,
143 monitor_subsys_ops_init,
149 SLAPD_MONITOR_OVERLAY_NAME,
150 BER_BVNULL, BER_BVNULL, BER_BVNULL,
151 { BER_BVC( "This subsystem contains information about available overlays." ),
153 MONITOR_F_PERSISTENT_CH,
154 monitor_subsys_overlay_init,
160 SLAPD_MONITOR_SASL_NAME,
161 BER_BVNULL, BER_BVNULL, BER_BVNULL,
162 { BER_BVC( "This subsystem contains information about SASL." ),
171 SLAPD_MONITOR_SENT_NAME,
172 BER_BVNULL, BER_BVNULL, BER_BVNULL,
173 { BER_BVC( "This subsystem contains statistics." ),
175 MONITOR_F_PERSISTENT_CH,
176 monitor_subsys_sent_init,
182 SLAPD_MONITOR_THREAD_NAME,
183 BER_BVNULL, BER_BVNULL, BER_BVNULL,
184 { BER_BVC( "This subsystem contains information about threads." ),
186 MONITOR_F_PERSISTENT_CH,
187 monitor_subsys_thread_init,
193 SLAPD_MONITOR_TIME_NAME,
194 BER_BVNULL, BER_BVNULL, BER_BVNULL,
195 { BER_BVC( "This subsystem contains information about time." ),
197 MONITOR_F_PERSISTENT_CH,
198 monitor_subsys_time_init,
204 SLAPD_MONITOR_TLS_NAME,
205 BER_BVNULL, BER_BVNULL, BER_BVNULL,
206 { BER_BVC( "This subsystem contains information about TLS." ),
215 SLAPD_MONITOR_RWW_NAME,
216 BER_BVNULL, BER_BVNULL, BER_BVNULL,
217 { BER_BVC( "This subsystem contains information about read/write waiters." ),
219 MONITOR_F_PERSISTENT_CH,
220 monitor_subsys_rww_init,
229 monitor_subsys_is_opened( void )
231 return monitor_subsys_opened;
235 monitor_back_register_subsys(
236 monitor_subsys_t *ms )
240 if ( monitor_subsys ) {
241 for ( ; monitor_subsys[ i ] != NULL; i++ )
242 /* just count'em */ ;
245 monitor_subsys = ch_realloc( monitor_subsys,
246 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
248 if ( monitor_subsys == NULL ) {
252 monitor_subsys[ i ] = ms;
253 monitor_subsys[ i + 1 ] = NULL;
255 /* if a subsystem is registered __AFTER__ subsystem
256 * initialization (depending on the sequence the databases
257 * are listed in slapd.conf), init it */
258 if ( monitor_subsys_is_opened() ) {
260 /* FIXME: this should only be possible
261 * if be_monitor is already initialized */
262 assert( be_monitor != NULL );
264 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
268 ms->mss_flags |= MONITOR_F_OPENED;
287 typedef struct entry_limbo_t {
291 slap_overinst *el_on;
294 struct berval el_ndn;
295 struct berval el_nbase;
297 struct berval el_filter;
298 monitor_callback_t *el_cb;
299 monitor_subsys_t *el_mss;
300 unsigned long el_flags;
301 struct entry_limbo_t *el_next;
305 monitor_back_is_configured( void )
307 return be_monitor != NULL;
311 monitor_back_register_backend(
318 monitor_back_register_overlay_info(
325 monitor_back_register_overlay(
332 monitor_back_register_backend_limbo(
339 monitor_back_register_database_limbo(
342 entry_limbo_t **elpp, el = { 0 };
345 if ( be_monitor == NULL ) {
346 Debug( LDAP_DEBUG_ANY,
347 "monitor_back_register_database_limbo: "
348 "monitor database not configured.\n",
353 mi = ( monitor_info_t * )be_monitor->be_private;
356 el.el_type = LIMBO_DATABASE;
360 for ( elpp = &mi->mi_entry_limbo;
362 elpp = &(*elpp)->el_next )
365 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
374 monitor_back_register_overlay_info_limbo(
381 monitor_back_register_overlay_limbo(
388 monitor_back_register_entry(
390 monitor_callback_t *cb,
391 monitor_subsys_t *mss,
392 unsigned long flags )
396 if ( be_monitor == NULL ) {
397 Debug( LDAP_DEBUG_ANY,
398 "monitor_back_register_entry(\"%s\"): "
399 "monitor database not configured.\n",
400 e->e_name.bv_val, 0, 0 );
404 mi = ( monitor_info_t * )be_monitor->be_private;
406 assert( mi != NULL );
408 assert( e->e_private == NULL );
410 if ( monitor_subsys_is_opened() ) {
411 Entry *e_parent = NULL,
414 struct berval pdn = BER_BVNULL;
415 monitor_entry_t *mp = NULL,
419 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
421 Debug( LDAP_DEBUG_ANY,
422 "monitor_back_register_entry(\"%s\"): "
424 e->e_name.bv_val, 0, 0 );
425 monitor_cache_release( mi, e_parent );
429 dnParent( &e->e_nname, &pdn );
430 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
431 /* parent does not exist */
432 Debug( LDAP_DEBUG_ANY,
433 "monitor_back_register_entry(\"%s\"): "
434 "parent \"%s\" not found\n",
435 e->e_name.bv_val, pdn.bv_val, 0 );
439 assert( e_parent->e_private != NULL );
440 mp_parent = ( monitor_entry_t * )e_parent->e_private;
442 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
443 /* entry is volatile; cannot append children */
444 Debug( LDAP_DEBUG_ANY,
445 "monitor_back_register_entry(\"%s\"): "
446 "parent \"%s\" is volatile\n",
447 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
452 mp = monitor_entrypriv_create();
454 Debug( LDAP_DEBUG_ANY,
455 "monitor_back_register_entry(\"%s\"): "
456 "monitor_entrypriv_create() failed\n",
457 e->e_name.bv_val, 0, 0 );
462 e_new = entry_dup( e );
463 if ( e_new == NULL ) {
464 Debug( LDAP_DEBUG_ANY,
465 "monitor_back_register_entry(\"%s\"): "
466 "entry_dup() failed\n",
467 e->e_name.bv_val, 0, 0 );
472 e_new->e_private = ( void * )mp;
475 mp->mp_flags = flags;
478 mp->mp_info = mp_parent->mp_info;
479 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
483 ep = &mp_parent->mp_children;
485 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
486 ep = &mp_parent->mp_next;
490 if ( monitor_cache_add( mi, e_new ) ) {
491 Debug( LDAP_DEBUG_ANY,
492 "monitor_back_register_entry(\"%s\"): "
493 "unable to add entry\n",
494 e->e_name.bv_val, 0, 0 );
505 e_new->e_private = NULL;
511 monitor_cache_release( mi, e_parent );
515 entry_limbo_t **elpp, el = { 0 };
517 el.el_type = LIMBO_ENTRY;
519 el.el_e = entry_dup( e );
520 if ( el.el_e == NULL ) {
521 Debug( LDAP_DEBUG_ANY,
522 "monitor_back_register_entry(\"%s\"): "
523 "entry_dup() failed\n",
524 e->e_name.bv_val, 0, 0 );
532 for ( elpp = &mi->mi_entry_limbo;
534 elpp = &(*elpp)->el_next )
537 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
538 if ( *elpp == NULL ) {
539 el.el_e->e_private = NULL;
540 entry_free( el.el_e );
552 monitor_back_register_entry_parent(
554 monitor_callback_t *cb,
555 monitor_subsys_t *mss,
557 struct berval *nbase,
559 struct berval *filter )
562 struct berval ndn = BER_BVNULL;
564 if ( be_monitor == NULL ) {
565 Debug( LDAP_DEBUG_ANY,
566 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
567 "monitor database not configured.\n",
568 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
569 ldap_pvt_scope2str( scope ),
570 BER_BVISNULL( filter ) ? "" : filter->bv_val );
574 mi = ( monitor_info_t * )be_monitor->be_private;
576 assert( mi != NULL );
578 assert( e->e_private == NULL );
580 if ( BER_BVISNULL( filter ) ) {
582 Debug( LDAP_DEBUG_ANY,
583 "monitor_back_register_entry_parent(\"\"): "
584 "need a valid filter\n",
589 if ( monitor_subsys_is_opened() ) {
590 Entry *e_parent = NULL,
593 struct berval e_name = BER_BVNULL,
594 e_nname = BER_BVNULL;
595 monitor_entry_t *mp = NULL,
599 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
600 /* entry does not exist */
601 Debug( LDAP_DEBUG_ANY,
602 "monitor_back_register_entry_parent(\"\"): "
603 "base=\"%s\" scope=%s filter=\"%s\": "
604 "unable to find entry\n",
605 nbase->bv_val ? nbase->bv_val : "\"\"",
606 ldap_pvt_scope2str( scope ),
611 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
612 /* entry does not exist */
613 Debug( LDAP_DEBUG_ANY,
614 "monitor_back_register_entry_parent(\"%s\"): "
615 "parent entry does not exist\n",
621 assert( e_parent->e_private != NULL );
622 mp_parent = ( monitor_entry_t * )e_parent->e_private;
624 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
625 /* entry is volatile; cannot append callback */
626 Debug( LDAP_DEBUG_ANY,
627 "monitor_back_register_entry_parent(\"%s\"): "
628 "entry is volatile\n",
629 e_parent->e_name.bv_val, 0, 0 );
634 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
635 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
637 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
638 /* entry already exists */
639 Debug( LDAP_DEBUG_ANY,
640 "monitor_back_register_entry_parent(\"%s\"): "
641 "entry already exists\n",
642 e_name.bv_val, 0, 0 );
643 monitor_cache_release( mi, e_new );
649 mp = monitor_entrypriv_create();
651 Debug( LDAP_DEBUG_ANY,
652 "monitor_back_register_entry_parent(\"%s\"): "
653 "monitor_entrypriv_create() failed\n",
654 e->e_name.bv_val, 0, 0 );
659 e_new = entry_dup( e );
660 if ( e_new == NULL ) {
661 Debug( LDAP_DEBUG_ANY,
662 "monitor_back_register_entry(\"%s\"): "
663 "entry_dup() failed\n",
664 e->e_name.bv_val, 0, 0 );
668 ch_free( e_new->e_name.bv_val );
669 ch_free( e_new->e_nname.bv_val );
670 e_new->e_name = e_name;
671 e_new->e_nname = e_nname;
673 e_new->e_private = ( void * )mp;
676 mp->mp_flags = flags;
679 mp->mp_info = mp_parent->mp_info;
680 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
684 ep = &mp_parent->mp_children;
686 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
687 ep = &mp_parent->mp_next;
691 if ( monitor_cache_add( mi, e_new ) ) {
692 Debug( LDAP_DEBUG_ANY,
693 "monitor_back_register_entry(\"%s\"): "
694 "unable to add entry\n",
695 e->e_name.bv_val, 0, 0 );
701 if ( !BER_BVISNULL( &ndn ) ) {
702 ch_free( ndn.bv_val );
710 e_new->e_private = NULL;
716 monitor_cache_release( mi, e_parent );
720 entry_limbo_t **elpp = NULL, el = { 0 };
722 el.el_type = LIMBO_ENTRY_PARENT;
724 el.el_e = entry_dup( e );
725 if ( el.el_e == NULL ) {
726 Debug( LDAP_DEBUG_ANY,
727 "monitor_back_register_entry(\"%s\"): "
728 "entry_dup() failed\n",
729 e->e_name.bv_val, 0, 0 );
733 if ( !BER_BVISNULL( nbase ) ) {
734 ber_dupbv( &el.el_nbase, nbase );
738 if ( !BER_BVISNULL( filter ) ) {
739 ber_dupbv( &el.el_filter, filter );
746 for ( elpp = &mi->mi_entry_limbo;
748 elpp = &(*elpp)->el_next )
751 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
752 if ( *elpp == NULL ) {
757 if ( *elpp != NULL ) {
762 if ( !BER_BVISNULL( &el.el_filter ) ) {
763 ch_free( el.el_filter.bv_val );
765 if ( !BER_BVISNULL( &el.el_nbase ) ) {
766 ch_free( el.el_nbase.bv_val );
768 entry_free( el.el_e );
777 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
779 if ( rs->sr_type == REP_SEARCH ) {
780 struct berval *ndn = op->o_callback->sc_private;
782 if ( !BER_BVISNULL( ndn ) ) {
783 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
784 ch_free( ndn->bv_val );
789 ber_dupbv( ndn, &rs->sr_entry->e_nname );
797 struct berval *nbase,
799 struct berval *filter,
802 Connection conn = { 0 };
803 OperationBuffer opbuf;
806 SlapReply rs = { 0 };
807 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
812 if ( be_monitor == NULL ) {
816 thrctx = ldap_pvt_thread_pool_context();
817 connection_fake_init( &conn, &opbuf, thrctx );
820 op->o_tag = LDAP_REQ_SEARCH;
822 /* use global malloc for now */
823 if ( op->o_tmpmemctx ) {
824 op->o_tmpmemctx = NULL;
826 op->o_tmpmfuncs = &ch_mfuncs;
828 op->o_bd = be_monitor;
829 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
830 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
832 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
836 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
837 op->o_tmpmemctx ) ) {
842 op->o_callback = &cb;
843 cb.sc_private = (void *)ndn;
845 op->ors_scope = scope;
846 op->ors_filter = str2filter_x( op, filter->bv_val );
847 if ( op->ors_filter == NULL ) {
851 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
852 op->ors_attrs = slap_anlist_no_attrs;
853 op->ors_attrsonly = 0;
854 op->ors_tlimit = SLAP_NO_LIMIT;
856 op->ors_limit = NULL;
857 op->ors_deref = LDAP_DEREF_NEVER;
860 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
862 op->o_dn = be_monitor->be_rootdn;
863 op->o_ndn = be_monitor->be_rootndn;
865 rc = op->o_bd->be_search( op, &rs );
868 if ( op->ors_filter != NULL ) {
869 filter_free_x( op, op->ors_filter );
871 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
872 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
874 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
875 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
877 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
878 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
885 switch ( rs.sr_err ) {
887 if ( BER_BVISNULL( ndn ) ) {
892 case LDAP_SIZELIMIT_EXCEEDED:
894 if ( !BER_BVISNULL( ndn ) ) {
895 ber_memfree( ndn->bv_val );
906 monitor_back_register_entry_attrs(
907 struct berval *ndn_in,
909 monitor_callback_t *cb,
910 struct berval *nbase,
912 struct berval *filter )
915 struct berval ndn = BER_BVNULL;
916 char *fname = ( a == NULL ? "callback" : "attrs" );
918 if ( be_monitor == NULL ) {
919 char buf[ SLAP_TEXT_BUFLEN ];
921 snprintf( buf, sizeof( buf ),
922 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
923 "monitor database not configured.\n",
925 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
926 ldap_pvt_scope2str( scope ),
927 BER_BVISNULL( filter ) ? "" : filter->bv_val );
928 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
933 mi = ( monitor_info_t * )be_monitor->be_private;
935 assert( mi != NULL );
937 if ( ndn_in != NULL ) {
941 if ( a == NULL && cb == NULL ) {
946 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
947 && BER_BVISNULL( filter ) )
950 Debug( LDAP_DEBUG_ANY,
951 "monitor_back_register_entry_%s(\"\"): "
952 "need a valid filter\n",
957 if ( monitor_subsys_is_opened() ) {
959 Attribute **atp = NULL;
960 monitor_entry_t *mp = NULL;
961 monitor_callback_t **mcp = NULL;
965 if ( BER_BVISNULL( &ndn ) ) {
966 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
967 char buf[ SLAP_TEXT_BUFLEN ];
969 snprintf( buf, sizeof( buf ),
970 "monitor_back_register_entry_%s(\"\"): "
971 "base=\"%s\" scope=%s filter=\"%s\": "
972 "unable to find entry\n",
974 nbase->bv_val ? nbase->bv_val : "\"\"",
975 ldap_pvt_scope2str( scope ),
978 /* entry does not exist */
979 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
986 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
987 /* entry does not exist */
988 Debug( LDAP_DEBUG_ANY,
989 "monitor_back_register_entry_%s(\"%s\"): "
990 "entry does not exist\n",
991 fname, ndn.bv_val, 0 );
996 assert( e->e_private != NULL );
997 mp = ( monitor_entry_t * )e->e_private;
999 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
1000 /* entry is volatile; cannot append callback */
1001 Debug( LDAP_DEBUG_ANY,
1002 "monitor_back_register_entry_%s(\"%s\"): "
1003 "entry is volatile\n",
1004 fname, e->e_name.bv_val, 0 );
1010 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
1011 /* just get to last */ ;
1013 for ( ; a != NULL; a = a->a_next ) {
1014 assert( a->a_desc != NULL );
1015 assert( a->a_vals != NULL );
1017 if ( attr_find( e->e_attrs, a->a_desc ) ) {
1018 attr_merge( e, a->a_desc, a->a_vals,
1019 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
1022 *atp = attr_dup( a );
1023 if ( *atp == NULL ) {
1024 Debug( LDAP_DEBUG_ANY,
1025 "monitor_back_register_entry_%s(\"%s\"): "
1026 "attr_dup() failed\n",
1027 fname, e->e_name.bv_val, 0 );
1031 atp = &(*atp)->a_next;
1037 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
1040 /* NOTE: we do not clear cb->mc_next, so this function
1041 * can be used to append a list of callbacks */
1047 if ( atp && *atp ) {
1054 ber_memfree( ndn.bv_val );
1058 monitor_cache_release( mi, e );
1062 entry_limbo_t **elpp, el = { 0 };
1064 el.el_type = LIMBO_ATTRS;
1065 if ( !BER_BVISNULL( &ndn ) ) {
1066 ber_dupbv( &el.el_ndn, &ndn );
1068 if ( !BER_BVISNULL( nbase ) ) {
1069 ber_dupbv( &el.el_nbase, nbase);
1071 el.el_scope = scope;
1072 if ( !BER_BVISNULL( filter ) ) {
1073 ber_dupbv( &el.el_filter, filter );
1076 el.el_a = attrs_dup( a );
1079 for ( elpp = &mi->mi_entry_limbo;
1081 elpp = &(*elpp)->el_next )
1084 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
1085 if ( *elpp == NULL ) {
1086 el.el_e->e_private = NULL;
1087 entry_free( el.el_e );
1091 if ( *elpp != NULL ) {
1096 if ( !BER_BVISNULL( &el.el_filter ) ) {
1097 ch_free( el.el_filter.bv_val );
1099 if ( el.el_a != NULL ) {
1100 attrs_free( el.el_a );
1102 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1103 ch_free( &el.el_nbase.bv_val );
1105 if ( !BER_BVISNULL( &el.el_ndn ) ) {
1106 ch_free( el.el_ndn.bv_val );
1116 monitor_back_register_entry_callback(
1118 monitor_callback_t *cb,
1119 struct berval *nbase,
1121 struct berval *filter )
1123 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1124 nbase, scope, filter );
1128 * TODO: add corresponding calls to remove installed callbacks, entries
1129 * and so, in case the entity that installed them is removed (e.g. a
1130 * database, via back-config)
1133 monitor_back_unregister_entry(
1134 struct berval *ndn )
1138 if ( be_monitor == NULL ) {
1139 Debug( LDAP_DEBUG_ANY,
1140 "monitor_back_unregister_entry(\"%s\"): "
1141 "monitor database not configured.\n",
1142 ndn->bv_val, 0, 0 );
1147 /* entry will be regularly freed, and resources released
1148 * according to callbacks */
1149 if ( slapd_shutdown ) {
1153 mi = ( monitor_info_t * )be_monitor->be_private;
1155 assert( mi != NULL );
1157 if ( monitor_subsys_is_opened() ) {
1159 monitor_entry_t *mp = NULL;
1160 monitor_callback_t *cb = NULL;
1162 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1163 /* entry does not exist */
1164 Debug( LDAP_DEBUG_ANY,
1165 "monitor_back_unregister_entry(\"%s\"): "
1166 "entry removal failed.\n",
1167 ndn->bv_val, 0, 0 );
1171 mp = (monitor_entry_t *)e->e_private;
1172 assert( mp != NULL );
1174 for ( cb = mp->mp_cb; cb != NULL; ) {
1175 monitor_callback_t *next = cb->mc_next;
1177 if ( cb->mc_free ) {
1178 (void)cb->mc_free( e, &cb->mc_private );
1186 e->e_private = NULL;
1190 entry_limbo_t **elpp;
1192 for ( elpp = &mi->mi_entry_limbo;
1194 elpp = &(*elpp)->el_next )
1196 entry_limbo_t *elp = *elpp;
1198 if ( elp->el_type == LIMBO_ENTRY
1199 && dn_match( ndn, &elp->el_e->e_nname ) )
1201 monitor_callback_t *cb, *next;
1203 for ( cb = elp->el_cb; cb; cb = next ) {
1204 /* FIXME: call callbacks? */
1206 if ( cb->mc_dispose ) {
1207 cb->mc_dispose( &cb->mc_private );
1211 assert( elp->el_e != NULL );
1212 elp->el_e->e_private = NULL;
1213 entry_free( elp->el_e );
1214 *elpp = elp->el_next;
1221 if ( elpp != NULL ) {
1222 /* not found! where did it go? */
1231 monitor_back_unregister_entry_parent(
1232 struct berval *nrdn,
1233 monitor_callback_t *target_cb,
1234 struct berval *nbase,
1236 struct berval *filter )
1239 struct berval ndn = BER_BVNULL;
1241 if ( be_monitor == NULL ) {
1242 Debug( LDAP_DEBUG_ANY,
1243 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1244 "monitor database not configured.\n",
1245 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1246 ldap_pvt_scope2str( scope ),
1247 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1252 /* entry will be regularly freed, and resources released
1253 * according to callbacks */
1254 if ( slapd_shutdown ) {
1258 mi = ( monitor_info_t * )be_monitor->be_private;
1260 assert( mi != NULL );
1262 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1263 && BER_BVISNULL( filter ) )
1266 Debug( LDAP_DEBUG_ANY,
1267 "monitor_back_unregister_entry_parent(\"\"): "
1268 "need a valid filter\n",
1273 if ( monitor_subsys_is_opened() ) {
1275 monitor_entry_t *mp = NULL;
1277 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1278 /* entry does not exist */
1279 Debug( LDAP_DEBUG_ANY,
1280 "monitor_back_unregister_entry_parent(\"\"): "
1281 "base=\"%s\" scope=%s filter=\"%s\": "
1282 "unable to find entry\n",
1283 nbase->bv_val ? nbase->bv_val : "\"\"",
1284 ldap_pvt_scope2str( scope ),
1289 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1290 /* entry does not exist */
1291 Debug( LDAP_DEBUG_ANY,
1292 "monitor_back_unregister_entry(\"%s\"): "
1293 "entry removal failed.\n",
1295 ber_memfree( ndn.bv_val );
1298 ber_memfree( ndn.bv_val );
1300 mp = (monitor_entry_t *)e->e_private;
1301 assert( mp != NULL );
1303 if ( target_cb != NULL ) {
1304 monitor_callback_t **cbp;
1306 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1307 if ( *cbp == target_cb ) {
1308 if ( (*cbp)->mc_free ) {
1309 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1311 *cbp = (*cbp)->mc_next;
1312 ch_free( target_cb );
1320 e->e_private = NULL;
1324 entry_limbo_t **elpp;
1326 for ( elpp = &mi->mi_entry_limbo;
1328 elpp = &(*elpp)->el_next )
1330 entry_limbo_t *elp = *elpp;
1332 if ( elp->el_type == LIMBO_ENTRY_PARENT
1333 && dn_match( nrdn, &elp->el_e->e_nname )
1334 && dn_match( nbase, &elp->el_nbase )
1335 && scope == elp->el_scope
1336 && bvmatch( filter, &elp->el_filter ) )
1338 monitor_callback_t *cb, *next;
1340 for ( cb = elp->el_cb; cb; cb = next ) {
1341 /* FIXME: call callbacks? */
1343 if ( cb->mc_dispose ) {
1344 cb->mc_dispose( &cb->mc_private );
1348 assert( elp->el_e != NULL );
1349 elp->el_e->e_private = NULL;
1350 entry_free( elp->el_e );
1351 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1352 ch_free( elp->el_nbase.bv_val );
1354 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1355 ch_free( elp->el_filter.bv_val );
1357 *elpp = elp->el_next;
1364 if ( elpp != NULL ) {
1365 /* not found! where did it go? */
1374 monitor_back_unregister_entry_attrs(
1375 struct berval *ndn_in,
1376 Attribute *target_a,
1377 monitor_callback_t *target_cb,
1378 struct berval *nbase,
1380 struct berval *filter )
1383 struct berval ndn = BER_BVNULL;
1384 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1386 if ( be_monitor == NULL ) {
1387 char buf[ SLAP_TEXT_BUFLEN ];
1389 snprintf( buf, sizeof( buf ),
1390 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1391 "monitor database not configured.\n",
1393 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1394 ldap_pvt_scope2str( scope ),
1395 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1396 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1401 /* entry will be regularly freed, and resources released
1402 * according to callbacks */
1403 if ( slapd_shutdown ) {
1407 mi = ( monitor_info_t * )be_monitor->be_private;
1409 assert( mi != NULL );
1411 if ( ndn_in != NULL ) {
1415 if ( target_a == NULL && target_cb == NULL ) {
1420 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1421 && BER_BVISNULL( filter ) )
1424 Debug( LDAP_DEBUG_ANY,
1425 "monitor_back_unregister_entry_%s(\"\"): "
1426 "need a valid filter\n",
1431 if ( monitor_subsys_is_opened() ) {
1433 monitor_entry_t *mp = NULL;
1436 if ( BER_BVISNULL( &ndn ) ) {
1437 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1438 char buf[ SLAP_TEXT_BUFLEN ];
1440 snprintf( buf, sizeof( buf ),
1441 "monitor_back_unregister_entry_%s(\"\"): "
1442 "base=\"%s\" scope=%d filter=\"%s\": "
1443 "unable to find entry\n",
1445 nbase->bv_val ? nbase->bv_val : "\"\"",
1446 scope, filter->bv_val );
1448 /* entry does not exist */
1449 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1456 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1457 /* entry does not exist */
1458 Debug( LDAP_DEBUG_ANY,
1459 "monitor_back_unregister_entry(\"%s\"): "
1460 "entry removal failed.\n",
1465 mp = (monitor_entry_t *)e->e_private;
1466 assert( mp != NULL );
1468 if ( target_cb != NULL ) {
1469 monitor_callback_t **cbp;
1471 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1472 if ( *cbp == target_cb ) {
1473 if ( (*cbp)->mc_free ) {
1474 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1476 *cbp = (*cbp)->mc_next;
1477 ch_free( target_cb );
1483 if ( target_a != NULL ) {
1486 for ( a = target_a; a != NULL; a = a->a_next ) {
1487 Modification mod = { 0 };
1489 char textbuf[ SLAP_TEXT_BUFLEN ];
1491 mod.sm_op = LDAP_MOD_DELETE;
1492 mod.sm_desc = a->a_desc;
1493 mod.sm_values = a->a_vals;
1494 mod.sm_nvalues = a->a_nvals;
1496 (void)modify_delete_values( e, &mod, 1,
1497 &text, textbuf, sizeof( textbuf ) );
1502 ber_memfree( ndn.bv_val );
1505 monitor_cache_release( mi, e );
1508 entry_limbo_t **elpp;
1510 for ( elpp = &mi->mi_entry_limbo;
1512 elpp = &(*elpp)->el_next )
1514 entry_limbo_t *elp = *elpp;
1516 if ( elp->el_type == LIMBO_ATTRS
1517 && dn_match( nbase, &elp->el_nbase )
1518 && scope == elp->el_scope
1519 && bvmatch( filter, &elp->el_filter ) )
1521 monitor_callback_t *cb, *next;
1523 for ( cb = elp->el_cb; cb; cb = next ) {
1524 /* FIXME: call callbacks? */
1526 if ( cb->mc_dispose ) {
1527 cb->mc_dispose( &cb->mc_private );
1531 assert( elp->el_e == NULL );
1532 if ( elp->el_a != NULL ) {
1533 attrs_free( elp->el_a );
1535 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1536 ch_free( elp->el_nbase.bv_val );
1538 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1539 ch_free( elp->el_filter.bv_val );
1541 *elpp = elp->el_next;
1548 if ( elpp != NULL ) {
1549 /* not found! where did it go? */
1558 monitor_back_unregister_entry_callback(
1560 monitor_callback_t *cb,
1561 struct berval *nbase,
1563 struct berval *filter )
1565 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1566 * unregister the callback; if a is not null, unregister the
1567 * given attrs. In any case, call cb->cb_free */
1568 return monitor_back_unregister_entry_attrs( ndn,
1569 NULL, cb, nbase, scope, filter );
1573 monitor_back_get_subsys( const char *name )
1575 if ( monitor_subsys != NULL ) {
1578 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1579 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1580 return monitor_subsys[ i ];
1589 monitor_back_get_subsys_by_dn(
1593 if ( monitor_subsys != NULL ) {
1597 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1598 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1599 return monitor_subsys[ i ];
1604 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1605 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1606 return monitor_subsys[ i ];
1616 monitor_back_initialize(
1619 static char *controls[] = {
1620 LDAP_CONTROL_MANAGEDSAIT,
1624 static ConfigTable monitorcfg[] = {
1625 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1626 NULL, NULL, NULL, NULL }
1629 static ConfigOCs monitorocs[] = {
1630 { "( OLcfgDbOc:4.1 "
1631 "NAME 'olcMonitorConfig' "
1632 "DESC 'Monitor backend configuration' "
1633 "SUP olcDatabaseConfig "
1635 Cft_Database, monitorcfg },
1644 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1646 "DESC 'OpenLDAP system monitoring' "
1647 "SUP top STRUCTURAL "
1656 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1657 offsetof(monitor_info_t, mi_oc_monitor) },
1658 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1659 "NAME 'monitorServer' "
1660 "DESC 'Server monitoring root entry' "
1661 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1662 offsetof(monitor_info_t, mi_oc_monitorServer) },
1663 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1664 "NAME 'monitorContainer' "
1665 "DESC 'monitor container class' "
1666 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1667 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1668 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1669 "NAME 'monitorCounterObject' "
1670 "DESC 'monitor counter class' "
1671 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1672 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1673 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1674 "NAME 'monitorOperation' "
1675 "DESC 'monitor operation class' "
1676 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1677 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1678 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1679 "NAME 'monitorConnection' "
1680 "DESC 'monitor connection class' "
1681 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1682 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1683 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1684 "NAME 'managedObject' "
1685 "DESC 'monitor managed entity class' "
1686 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1687 offsetof(monitor_info_t, mi_oc_managedObject) },
1688 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1689 "NAME 'monitoredObject' "
1690 "DESC 'monitor monitored entity class' "
1691 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1692 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1695 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1696 "NAME 'monitoredInfo' "
1697 "DESC 'monitored info' "
1699 "EQUALITY caseIgnoreMatch "
1700 "SUBSTR caseIgnoreSubstringsMatch "
1701 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1702 "NO-USER-MODIFICATION "
1703 "USAGE dSAOperation )", SLAP_AT_HIDE,
1704 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1705 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1706 "NAME 'managedInfo' "
1707 "DESC 'monitor managed info' "
1708 "SUP name )", SLAP_AT_HIDE,
1709 offsetof(monitor_info_t, mi_ad_managedInfo) },
1710 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1711 "NAME 'monitorCounter' "
1712 "DESC 'monitor counter' "
1713 "EQUALITY integerMatch "
1714 "ORDERING integerOrderingMatch "
1715 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1716 "NO-USER-MODIFICATION "
1717 "USAGE dSAOperation )", SLAP_AT_HIDE,
1718 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1719 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1720 "NAME 'monitorOpCompleted' "
1721 "DESC 'monitor completed operations' "
1722 "SUP monitorCounter "
1723 "NO-USER-MODIFICATION "
1724 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1725 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1726 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1727 "NAME 'monitorOpInitiated' "
1728 "DESC 'monitor initiated operations' "
1729 "SUP monitorCounter "
1730 "NO-USER-MODIFICATION "
1731 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1732 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1733 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1734 "NAME 'monitorConnectionNumber' "
1735 "DESC 'monitor connection number' "
1736 "SUP monitorCounter "
1737 "NO-USER-MODIFICATION "
1738 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1739 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1740 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1741 "NAME 'monitorConnectionAuthzDN' "
1742 "DESC 'monitor connection authorization DN' "
1743 /* "SUP distinguishedName " */
1744 "EQUALITY distinguishedNameMatch "
1745 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1746 "NO-USER-MODIFICATION "
1747 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1748 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1749 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1750 "NAME 'monitorConnectionLocalAddress' "
1751 "DESC 'monitor connection local address' "
1752 "SUP monitoredInfo "
1753 "NO-USER-MODIFICATION "
1754 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1755 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1756 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1757 "NAME 'monitorConnectionPeerAddress' "
1758 "DESC 'monitor connection peer address' "
1759 "SUP monitoredInfo "
1760 "NO-USER-MODIFICATION "
1761 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1762 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1763 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1764 "NAME 'monitorTimestamp' "
1765 "DESC 'monitor timestamp' "
1766 "EQUALITY generalizedTimeMatch "
1767 "ORDERING generalizedTimeOrderingMatch "
1768 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1770 "NO-USER-MODIFICATION "
1771 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1772 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1773 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1774 "NAME 'monitorOverlay' "
1775 "DESC 'name of overlays defined for a given database' "
1776 "SUP monitoredInfo "
1777 "NO-USER-MODIFICATION "
1778 "USAGE dSAOperation )", SLAP_AT_HIDE,
1779 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1780 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1782 "DESC 'read/write status of a given database' "
1783 "EQUALITY booleanMatch "
1784 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1786 "USAGE dSAOperation )", SLAP_AT_HIDE,
1787 offsetof(monitor_info_t, mi_ad_readOnly) },
1788 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1789 "NAME 'restrictedOperation' "
1790 "DESC 'name of restricted operation for a given database' "
1791 "SUP managedInfo )", SLAP_AT_HIDE,
1792 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1793 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1794 "NAME 'monitorConnectionProtocol' "
1795 "DESC 'monitor connection protocol' "
1796 "SUP monitoredInfo "
1797 "NO-USER-MODIFICATION "
1798 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1799 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1800 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1801 "NAME 'monitorConnectionOpsReceived' "
1802 "DESC 'monitor number of operations received by the connection' "
1803 "SUP monitorCounter "
1804 "NO-USER-MODIFICATION "
1805 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1806 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1807 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1808 "NAME 'monitorConnectionOpsExecuting' "
1809 "DESC 'monitor number of operations in execution within the connection' "
1810 "SUP monitorCounter "
1811 "NO-USER-MODIFICATION "
1812 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1813 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1814 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1815 "NAME 'monitorConnectionOpsPending' "
1816 "DESC 'monitor number of pending operations within the connection' "
1817 "SUP monitorCounter "
1818 "NO-USER-MODIFICATION "
1819 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1820 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1821 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1822 "NAME 'monitorConnectionOpsCompleted' "
1823 "DESC 'monitor number of operations completed within the connection' "
1824 "SUP monitorCounter "
1825 "NO-USER-MODIFICATION "
1826 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1827 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1828 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1829 "NAME 'monitorConnectionGet' "
1830 "DESC 'number of times connection_get() was called so far' "
1831 "SUP monitorCounter "
1832 "NO-USER-MODIFICATION "
1833 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1834 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1835 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1836 "NAME 'monitorConnectionRead' "
1837 "DESC 'number of times connection_read() was called so far' "
1838 "SUP monitorCounter "
1839 "NO-USER-MODIFICATION "
1840 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1841 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1842 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1843 "NAME 'monitorConnectionWrite' "
1844 "DESC 'number of times connection_write() was called so far' "
1845 "SUP monitorCounter "
1846 "NO-USER-MODIFICATION "
1847 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1848 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1849 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1850 "NAME 'monitorConnectionMask' "
1851 "DESC 'monitor connection mask' "
1852 "SUP monitoredInfo "
1853 "NO-USER-MODIFICATION "
1854 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1855 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1856 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1857 "NAME 'monitorConnectionListener' "
1858 "DESC 'monitor connection listener' "
1859 "SUP monitoredInfo "
1860 "NO-USER-MODIFICATION "
1861 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1862 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1863 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1864 "NAME 'monitorConnectionPeerDomain' "
1865 "DESC 'monitor connection peer domain' "
1866 "SUP monitoredInfo "
1867 "NO-USER-MODIFICATION "
1868 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1869 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1870 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1871 "NAME 'monitorConnectionStartTime' "
1872 "DESC 'monitor connection start time' "
1873 "SUP monitorTimestamp "
1875 "NO-USER-MODIFICATION "
1876 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1877 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1878 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1879 "NAME 'monitorConnectionActivityTime' "
1880 "DESC 'monitor connection activity time' "
1881 "SUP monitorTimestamp "
1883 "NO-USER-MODIFICATION "
1884 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1885 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1886 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1887 "NAME 'monitorIsShadow' "
1888 "DESC 'TRUE if the database is shadow' "
1889 "EQUALITY booleanMatch "
1890 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1892 "USAGE dSAOperation )", SLAP_AT_HIDE,
1893 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1894 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1895 "NAME 'monitorUpdateRef' "
1896 "DESC 'update referral for shadow databases' "
1897 "SUP monitoredInfo "
1899 "USAGE dSAOperation )", SLAP_AT_HIDE,
1900 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1901 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1902 "NAME 'monitorRuntimeConfig' "
1903 "DESC 'TRUE if component allows runtime configuration' "
1904 "EQUALITY booleanMatch "
1905 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1907 "USAGE dSAOperation )", SLAP_AT_HIDE,
1908 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1916 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1917 { "olmSubSystemAttributes", "olmAttributes:0" },
1918 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1919 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1921 /* for example, back-bdb specific attrs
1922 * are in "olmDatabaseAttributes:1"
1924 * NOTE: developers, please record here OID assignments
1925 * for other modules */
1927 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1928 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1929 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1930 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1932 /* for example, back-bdb specific objectClasses
1933 * are in "olmDatabaseObjectClasses:1"
1935 * NOTE: developers, please record here OID assignments
1936 * for other modules */
1942 monitor_info_t *mi = &monitor_info;
1946 argv[ 0 ] = "monitor";
1951 for ( i = 0; s_oid[ i ].name; i++ ) {
1952 argv[ 1 ] = s_oid[ i ].name;
1953 argv[ 2 ] = s_oid[ i ].oid;
1955 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1956 Debug( LDAP_DEBUG_ANY,
1957 "monitor_back_initialize: unable to add "
1958 "objectIdentifier \"%s=%s\"\n",
1959 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1964 /* schema integration */
1965 for ( i = 0; mat[ i ].schema; i++ ) {
1967 AttributeDescription **ad =
1968 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1971 code = register_at( mat[ i ].schema, ad, 0 );
1974 Debug( LDAP_DEBUG_ANY,
1975 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1978 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1981 for ( i = 0; moc[ i ].schema; i++ ) {
1984 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1986 code = register_oc( moc[ i ].schema, Oc, 0 );
1988 Debug( LDAP_DEBUG_ANY,
1989 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1992 (*Oc)->soc_flags |= moc[ i ].flags;
1995 bi->bi_controls = controls;
1999 bi->bi_config = monitor_back_config;
2003 bi->bi_db_init = monitor_back_db_init;
2005 bi->bi_db_config = monitor_back_db_config;
2007 bi->bi_db_open = monitor_back_db_open;
2008 bi->bi_db_close = 0;
2009 bi->bi_db_destroy = monitor_back_db_destroy;
2011 bi->bi_op_bind = monitor_back_bind;
2012 bi->bi_op_unbind = 0;
2013 bi->bi_op_search = monitor_back_search;
2014 bi->bi_op_compare = monitor_back_compare;
2015 bi->bi_op_modify = monitor_back_modify;
2016 bi->bi_op_modrdn = 0;
2018 bi->bi_op_delete = 0;
2019 bi->bi_op_abandon = 0;
2021 bi->bi_extended = 0;
2023 bi->bi_entry_release_rw = 0;
2024 bi->bi_chk_referrals = 0;
2025 bi->bi_operational = monitor_back_operational;
2028 * hooks for slap tools
2030 bi->bi_tool_entry_open = 0;
2031 bi->bi_tool_entry_close = 0;
2032 bi->bi_tool_entry_first = 0;
2033 bi->bi_tool_entry_next = 0;
2034 bi->bi_tool_entry_get = 0;
2035 bi->bi_tool_entry_put = 0;
2036 bi->bi_tool_entry_reindex = 0;
2037 bi->bi_tool_sync = 0;
2038 bi->bi_tool_dn2id_get = 0;
2039 bi->bi_tool_entry_modify = 0;
2041 bi->bi_connection_init = 0;
2042 bi->bi_connection_destroy = 0;
2044 bi->bi_extra = (void *)&monitor_extra;
2047 * configuration objectClasses (fake)
2049 bi->bi_cf_ocs = monitorocs;
2051 rc = config_register_schema( monitorcfg, monitorocs );
2060 monitor_back_db_init(
2065 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
2070 monitor_subsys_t *ms;
2073 * database monitor can be defined once only
2075 if ( be_monitor != NULL ) {
2077 snprintf(c->msg, sizeof(c->msg),"only one monitor database allowed");
2086 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2087 if ( monitor_back_register_subsys( ms ) ) {
2092 /* indicate system schema supported */
2093 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2095 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2096 if( rc != LDAP_SUCCESS ) {
2097 Debug( LDAP_DEBUG_ANY,
2098 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2103 ber_bvarray_add( &be->be_suffix, &pdn );
2104 ber_bvarray_add( &be->be_nsuffix, &ndn );
2106 /* NOTE: only one monitor database is allowed,
2107 * so we use static storage */
2108 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2110 be->be_private = &monitor_info;
2112 be2 = select_backend( &ndn, 0 );
2114 char *type = be2->bd_info->bi_type;
2116 if ( overlay_is_over( be2 ) ) {
2117 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2118 type = oi->oi_orig->bi_type;
2122 snprintf(c->msg, sizeof(c->msg),
2123 "\"monitor\" database serving namingContext \"%s\" "
2124 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2125 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2134 monitor_back_destroy_limbo_entry(
2139 entry_free( el->el_e );
2142 attrs_free( el->el_a );
2144 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2145 ber_memfree( el->el_ndn.bv_val );
2147 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2148 ber_memfree( el->el_nbase.bv_val );
2150 if ( !BER_BVISNULL( &el->el_filter ) ) {
2151 ber_memfree( el->el_filter.bv_val );
2154 /* NOTE: callbacks are not copied; so only free them
2155 * if disposing of */
2156 if ( el->el_cb && dispose != 0 ) {
2157 monitor_callback_t *next;
2159 for ( ; el->el_cb; el->el_cb = next ) {
2160 next = el->el_cb->mc_next;
2161 if ( el->el_cb->mc_dispose ) {
2162 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2164 ch_free( el->el_cb );
2172 monitor_back_db_open(
2176 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2177 struct monitor_subsys_t **ms;
2178 Entry *e, **ep, *root;
2179 monitor_entry_t *mp;
2181 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2183 #ifdef HAVE_GMTIME_R
2186 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2187 struct berval desc[] = {
2188 BER_BVC("This subtree contains monitoring/managing objects."),
2189 BER_BVC("This object contains information about this server."),
2190 BER_BVC("Most of the information is held in operational"
2191 " attributes, which must be explicitly requested."),
2196 assert( be_monitor != NULL );
2197 if ( be != be_monitor ) {
2204 #ifndef HAVE_GMTIME_R
2205 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2207 #ifdef HACK_LOCAL_TIME
2208 # ifdef HAVE_LOCALTIME_R
2209 tms = localtime_r( &starttime, &tm_buf );
2211 tms = localtime( &starttime );
2212 # endif /* HAVE_LOCALTIME_R */
2213 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2214 #else /* !HACK_LOCAL_TIME */
2215 # ifdef HAVE_GMTIME_R
2216 tms = gmtime_r( &starttime, &tm_buf );
2218 tms = gmtime( &starttime );
2219 # endif /* HAVE_GMTIME_R */
2220 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2221 #endif /* !HACK_LOCAL_TIME */
2222 #ifndef HAVE_GMTIME_R
2223 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2226 mi->mi_startTime.bv_val = tmbuf;
2227 mi->mi_startTime.bv_len = strlen( tmbuf );
2229 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2230 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2231 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2233 mi->mi_creatorsName = be->be_rootdn;
2234 mi->mi_ncreatorsName = be->be_rootndn;
2238 * creates the "cn=Monitor" entry
2240 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2244 Debug( LDAP_DEBUG_ANY,
2245 "unable to create \"%s\" entry\n",
2246 SLAPD_MONITOR_DN, 0, 0 );
2250 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2252 bv.bv_val = strchr( (char *) Versionstr, '$' );
2253 if ( bv.bv_val != NULL ) {
2257 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2260 end = strchr( bv.bv_val, '$' );
2261 if ( end != NULL ) {
2264 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2269 bv.bv_len = end - bv.bv_val;
2272 bv.bv_len = strlen( bv.bv_val );
2275 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2277 Debug( LDAP_DEBUG_ANY,
2278 "unable to add monitoredInfo to \"%s\" entry\n",
2279 SLAPD_MONITOR_DN, 0, 0 );
2284 mp = monitor_entrypriv_create();
2288 e->e_private = ( void * )mp;
2289 ep = &mp->mp_children;
2291 if ( monitor_cache_add( mi, e ) ) {
2292 Debug( LDAP_DEBUG_ANY,
2293 "unable to add entry \"%s\" to cache\n",
2294 SLAPD_MONITOR_DN, 0, 0 );
2300 * Create all the subsystem specific entries
2302 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2303 int len = strlen( monitor_subsys[ i ]->mss_name );
2307 dn.bv_len = len + sizeof( "cn=" ) - 1;
2308 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2309 strcpy( dn.bv_val, "cn=" );
2310 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2311 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2313 if ( rc != LDAP_SUCCESS ) {
2314 Debug( LDAP_DEBUG_ANY,
2315 "monitor RDN \"%s\" is invalid\n",
2320 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2321 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2325 Debug( LDAP_DEBUG_ANY,
2326 "unable to create \"%s\" entry\n",
2327 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2330 monitor_subsys[i]->mss_dn = e->e_name;
2331 monitor_subsys[i]->mss_ndn = e->e_nname;
2333 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2334 attr_merge_normalize( e, slap_schema.si_ad_description,
2335 monitor_subsys[ i ]->mss_desc, NULL );
2338 mp = monitor_entrypriv_create();
2342 e->e_private = ( void * )mp;
2343 mp->mp_info = monitor_subsys[ i ];
2344 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2346 if ( monitor_cache_add( mi, e ) ) {
2347 Debug( LDAP_DEBUG_ANY,
2348 "unable to add entry \"%s\" to cache\n",
2349 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2357 assert( be != NULL );
2359 be->be_private = mi;
2362 * opens the monitor backend subsystems
2364 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2365 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2369 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2372 monitor_subsys_opened = 1;
2374 if ( mi->mi_entry_limbo ) {
2375 entry_limbo_t *el = mi->mi_entry_limbo;
2381 switch ( el->el_type ) {
2383 rc = monitor_back_register_entry(
2390 case LIMBO_ENTRY_PARENT:
2391 rc = monitor_back_register_entry_parent(
2403 rc = monitor_back_register_entry_attrs(
2413 rc = monitor_back_register_entry_callback(
2422 rc = monitor_back_register_backend( el->el_bi );
2425 case LIMBO_DATABASE:
2426 rc = monitor_back_register_database( el->el_be );
2429 case LIMBO_OVERLAY_INFO:
2430 rc = monitor_back_register_overlay_info( el->el_on );
2434 rc = monitor_back_register_overlay( el->el_be );
2443 monitor_back_destroy_limbo_entry( tmp, rc );
2446 /* try all, but report error at end */
2451 mi->mi_entry_limbo = NULL;
2458 monitor_back_config(
2466 * eventually, will hold backend specific configuration parameters
2468 return SLAP_CONF_UNKNOWN;
2473 monitor_back_db_config(
2480 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2483 * eventually, will hold database specific configuration parameters
2485 return SLAP_CONF_UNKNOWN;
2490 monitor_back_db_destroy(
2494 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2501 * FIXME: destroys all the data
2503 /* NOTE: mi points to static storage; don't free it */
2505 (void)monitor_cache_destroy( mi );
2507 if ( monitor_subsys ) {
2510 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2511 if ( monitor_subsys[ i ]->mss_destroy ) {
2512 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2515 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2516 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2520 ch_free( monitor_subsys );
2523 if ( mi->mi_entry_limbo ) {
2524 entry_limbo_t *el = mi->mi_entry_limbo;
2527 entry_limbo_t *tmp = el;
2529 monitor_back_destroy_limbo_entry( tmp, 1 );
2533 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2535 be->be_private = NULL;
2540 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2542 /* conditionally define the init_module() function */
2543 SLAP_BACKEND_INIT_MODULE( monitor )
2545 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */