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 = (entry_limbo_t **)&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 = (entry_limbo_t **)&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 = (entry_limbo_t **)&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 op = (Operation *) &opbuf;
817 thrctx = ldap_pvt_thread_pool_context();
818 connection_fake_init( &conn, op, 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 = (entry_limbo_t **)&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 = (entry_limbo_t **)&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? */
1208 assert( elp->el_e != NULL );
1209 elp->el_e->e_private = NULL;
1210 entry_free( elp->el_e );
1211 *elpp = elp->el_next;
1218 if ( elpp != NULL ) {
1219 /* not found! where did it go? */
1228 monitor_back_unregister_entry_parent(
1229 struct berval *nrdn,
1230 monitor_callback_t *target_cb,
1231 struct berval *nbase,
1233 struct berval *filter )
1236 struct berval ndn = BER_BVNULL;
1238 if ( be_monitor == NULL ) {
1239 Debug( LDAP_DEBUG_ANY,
1240 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1241 "monitor database not configured.\n",
1242 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1243 ldap_pvt_scope2str( scope ),
1244 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1249 /* entry will be regularly freed, and resources released
1250 * according to callbacks */
1251 if ( slapd_shutdown ) {
1255 mi = ( monitor_info_t * )be_monitor->be_private;
1257 assert( mi != NULL );
1259 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1260 && BER_BVISNULL( filter ) )
1263 Debug( LDAP_DEBUG_ANY,
1264 "monitor_back_unregister_entry_parent(\"\"): "
1265 "need a valid filter\n",
1270 if ( monitor_subsys_is_opened() ) {
1272 monitor_entry_t *mp = NULL;
1274 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1275 /* entry does not exist */
1276 Debug( LDAP_DEBUG_ANY,
1277 "monitor_back_unregister_entry_parent(\"\"): "
1278 "base=\"%s\" scope=%s filter=\"%s\": "
1279 "unable to find entry\n",
1280 nbase->bv_val ? nbase->bv_val : "\"\"",
1281 ldap_pvt_scope2str( scope ),
1286 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1287 /* entry does not exist */
1288 Debug( LDAP_DEBUG_ANY,
1289 "monitor_back_unregister_entry(\"%s\"): "
1290 "entry removal failed.\n",
1292 ber_memfree( ndn.bv_val );
1295 ber_memfree( ndn.bv_val );
1297 mp = (monitor_entry_t *)e->e_private;
1298 assert( mp != NULL );
1300 if ( target_cb != NULL ) {
1301 monitor_callback_t **cbp;
1303 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1304 if ( *cbp == target_cb ) {
1305 if ( (*cbp)->mc_free ) {
1306 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1308 *cbp = (*cbp)->mc_next;
1309 ch_free( target_cb );
1317 e->e_private = NULL;
1321 entry_limbo_t **elpp;
1323 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1325 elpp = &(*elpp)->el_next )
1327 entry_limbo_t *elp = *elpp;
1329 if ( elp->el_type == LIMBO_ENTRY_PARENT
1330 && dn_match( nrdn, &elp->el_e->e_nname )
1331 && dn_match( nbase, &elp->el_nbase )
1332 && scope == elp->el_scope
1333 && bvmatch( filter, &elp->el_filter ) )
1335 monitor_callback_t *cb, *next;
1337 for ( cb = elp->el_cb; cb; cb = next ) {
1338 /* FIXME: call callbacks? */
1342 assert( elp->el_e != NULL );
1343 elp->el_e->e_private = NULL;
1344 entry_free( elp->el_e );
1345 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1346 ch_free( elp->el_nbase.bv_val );
1348 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1349 ch_free( elp->el_filter.bv_val );
1351 *elpp = elp->el_next;
1358 if ( elpp != NULL ) {
1359 /* not found! where did it go? */
1368 monitor_back_unregister_entry_attrs(
1369 struct berval *ndn_in,
1370 Attribute *target_a,
1371 monitor_callback_t *target_cb,
1372 struct berval *nbase,
1374 struct berval *filter )
1377 struct berval ndn = BER_BVNULL;
1378 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1380 if ( be_monitor == NULL ) {
1381 char buf[ SLAP_TEXT_BUFLEN ];
1383 snprintf( buf, sizeof( buf ),
1384 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1385 "monitor database not configured.\n",
1387 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1388 ldap_pvt_scope2str( scope ),
1389 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1390 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1395 /* entry will be regularly freed, and resources released
1396 * according to callbacks */
1397 if ( slapd_shutdown ) {
1401 mi = ( monitor_info_t * )be_monitor->be_private;
1403 assert( mi != NULL );
1405 if ( ndn_in != NULL ) {
1409 if ( target_a == NULL && target_cb == NULL ) {
1414 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1415 && BER_BVISNULL( filter ) )
1418 Debug( LDAP_DEBUG_ANY,
1419 "monitor_back_unregister_entry_%s(\"\"): "
1420 "need a valid filter\n",
1425 if ( monitor_subsys_is_opened() ) {
1427 monitor_entry_t *mp = NULL;
1430 if ( BER_BVISNULL( &ndn ) ) {
1431 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1432 char buf[ SLAP_TEXT_BUFLEN ];
1434 snprintf( buf, sizeof( buf ),
1435 "monitor_back_unregister_entry_%s(\"\"): "
1436 "base=\"%s\" scope=%d filter=\"%s\": "
1437 "unable to find entry\n",
1439 nbase->bv_val ? nbase->bv_val : "\"\"",
1440 scope, filter->bv_val );
1442 /* entry does not exist */
1443 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1450 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1451 /* entry does not exist */
1452 Debug( LDAP_DEBUG_ANY,
1453 "monitor_back_unregister_entry(\"%s\"): "
1454 "entry removal failed.\n",
1459 mp = (monitor_entry_t *)e->e_private;
1460 assert( mp != NULL );
1462 if ( target_cb != NULL ) {
1463 monitor_callback_t **cbp;
1465 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1466 if ( *cbp == target_cb ) {
1467 if ( (*cbp)->mc_free ) {
1468 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1470 *cbp = (*cbp)->mc_next;
1471 ch_free( target_cb );
1477 if ( target_a != NULL ) {
1480 for ( a = target_a; a != NULL; a = a->a_next ) {
1481 Modification mod = { 0 };
1483 char textbuf[ SLAP_TEXT_BUFLEN ];
1485 mod.sm_op = LDAP_MOD_DELETE;
1486 mod.sm_desc = a->a_desc;
1487 mod.sm_values = a->a_vals;
1488 mod.sm_nvalues = a->a_nvals;
1490 (void)modify_delete_values( e, &mod, 1,
1491 &text, textbuf, sizeof( textbuf ) );
1496 ber_memfree( ndn.bv_val );
1500 monitor_cache_release( mi, e );
1504 entry_limbo_t **elpp;
1506 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1508 elpp = &(*elpp)->el_next )
1510 entry_limbo_t *elp = *elpp;
1512 if ( elp->el_type == LIMBO_ATTRS
1513 && dn_match( nbase, &elp->el_nbase )
1514 && scope == elp->el_scope
1515 && bvmatch( filter, &elp->el_filter ) )
1517 monitor_callback_t *cb, *next;
1519 for ( cb = elp->el_cb; cb; cb = next ) {
1520 /* FIXME: call callbacks? */
1524 assert( elp->el_e == NULL );
1525 if ( elp->el_a != NULL ) {
1526 attrs_free( elp->el_a );
1528 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1529 ch_free( elp->el_nbase.bv_val );
1531 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1532 ch_free( elp->el_filter.bv_val );
1534 *elpp = elp->el_next;
1541 if ( elpp != NULL ) {
1542 /* not found! where did it go? */
1551 monitor_back_unregister_entry_callback(
1553 monitor_callback_t *cb,
1554 struct berval *nbase,
1556 struct berval *filter )
1558 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1559 * unregister the callback; if a is not null, unregister the
1560 * given attrs. In any case, call cb->cb_free */
1561 return monitor_back_unregister_entry_attrs( ndn,
1562 NULL, cb, nbase, scope, filter );
1566 monitor_back_get_subsys( const char *name )
1568 if ( monitor_subsys != NULL ) {
1571 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1572 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1573 return monitor_subsys[ i ];
1582 monitor_back_get_subsys_by_dn(
1586 if ( monitor_subsys != NULL ) {
1590 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1591 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1592 return monitor_subsys[ i ];
1597 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1598 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1599 return monitor_subsys[ i ];
1609 monitor_back_initialize(
1612 static char *controls[] = {
1613 LDAP_CONTROL_MANAGEDSAIT,
1617 static ConfigTable monitorcfg[] = {
1618 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1619 NULL, NULL, NULL, NULL }
1622 static ConfigOCs monitorocs[] = {
1623 { "( OLcfgDbOc:4.1 "
1624 "NAME 'olcMonitorConfig' "
1625 "DESC 'Monitor backend configuration' "
1626 "SUP olcDatabaseConfig "
1628 Cft_Database, monitorcfg },
1637 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1639 "DESC 'OpenLDAP system monitoring' "
1640 "SUP top STRUCTURAL "
1649 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1650 offsetof(monitor_info_t, mi_oc_monitor) },
1651 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1652 "NAME 'monitorServer' "
1653 "DESC 'Server monitoring root entry' "
1654 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1655 offsetof(monitor_info_t, mi_oc_monitorServer) },
1656 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1657 "NAME 'monitorContainer' "
1658 "DESC 'monitor container class' "
1659 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1660 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1661 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1662 "NAME 'monitorCounterObject' "
1663 "DESC 'monitor counter class' "
1664 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1665 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1666 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1667 "NAME 'monitorOperation' "
1668 "DESC 'monitor operation class' "
1669 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1670 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1671 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1672 "NAME 'monitorConnection' "
1673 "DESC 'monitor connection class' "
1674 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1675 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1676 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1677 "NAME 'managedObject' "
1678 "DESC 'monitor managed entity class' "
1679 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1680 offsetof(monitor_info_t, mi_oc_managedObject) },
1681 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1682 "NAME 'monitoredObject' "
1683 "DESC 'monitor monitored entity class' "
1684 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1685 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1688 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1689 "NAME 'monitoredInfo' "
1690 "DESC 'monitored info' "
1692 "EQUALITY caseIgnoreMatch "
1693 "SUBSTR caseIgnoreSubstringsMatch "
1694 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1695 "NO-USER-MODIFICATION "
1696 "USAGE dSAOperation )", SLAP_AT_HIDE,
1697 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1698 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1699 "NAME 'managedInfo' "
1700 "DESC 'monitor managed info' "
1701 "SUP name )", SLAP_AT_HIDE,
1702 offsetof(monitor_info_t, mi_ad_managedInfo) },
1703 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1704 "NAME 'monitorCounter' "
1705 "DESC 'monitor counter' "
1706 "EQUALITY integerMatch "
1707 "ORDERING integerOrderingMatch "
1708 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1709 "NO-USER-MODIFICATION "
1710 "USAGE dSAOperation )", SLAP_AT_HIDE,
1711 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1712 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1713 "NAME 'monitorOpCompleted' "
1714 "DESC 'monitor completed operations' "
1715 "SUP monitorCounter "
1716 "NO-USER-MODIFICATION "
1717 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1718 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1719 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1720 "NAME 'monitorOpInitiated' "
1721 "DESC 'monitor initiated operations' "
1722 "SUP monitorCounter "
1723 "NO-USER-MODIFICATION "
1724 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1725 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1726 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1727 "NAME 'monitorConnectionNumber' "
1728 "DESC 'monitor connection number' "
1729 "SUP monitorCounter "
1730 "NO-USER-MODIFICATION "
1731 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1732 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1733 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1734 "NAME 'monitorConnectionAuthzDN' "
1735 "DESC 'monitor connection authorization DN' "
1736 /* "SUP distinguishedName " */
1737 "EQUALITY distinguishedNameMatch "
1738 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1739 "NO-USER-MODIFICATION "
1740 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1741 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1742 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1743 "NAME 'monitorConnectionLocalAddress' "
1744 "DESC 'monitor connection local address' "
1745 "SUP monitoredInfo "
1746 "NO-USER-MODIFICATION "
1747 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1748 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1749 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1750 "NAME 'monitorConnectionPeerAddress' "
1751 "DESC 'monitor connection peer address' "
1752 "SUP monitoredInfo "
1753 "NO-USER-MODIFICATION "
1754 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1755 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1756 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1757 "NAME 'monitorTimestamp' "
1758 "DESC 'monitor timestamp' "
1759 "EQUALITY generalizedTimeMatch "
1760 "ORDERING generalizedTimeOrderingMatch "
1761 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1763 "NO-USER-MODIFICATION "
1764 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1765 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1766 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1767 "NAME 'monitorOverlay' "
1768 "DESC 'name of overlays defined for a given database' "
1769 "SUP monitoredInfo "
1770 "NO-USER-MODIFICATION "
1771 "USAGE dSAOperation )", SLAP_AT_HIDE,
1772 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1773 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1775 "DESC 'read/write status of a given database' "
1776 "EQUALITY booleanMatch "
1777 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1779 "USAGE dSAOperation )", SLAP_AT_HIDE,
1780 offsetof(monitor_info_t, mi_ad_readOnly) },
1781 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1782 "NAME 'restrictedOperation' "
1783 "DESC 'name of restricted operation for a given database' "
1784 "SUP managedInfo )", SLAP_AT_HIDE,
1785 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1786 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1787 "NAME 'monitorConnectionProtocol' "
1788 "DESC 'monitor connection protocol' "
1789 "SUP monitoredInfo "
1790 "NO-USER-MODIFICATION "
1791 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1792 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1793 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1794 "NAME 'monitorConnectionOpsReceived' "
1795 "DESC 'monitor number of operations received by the connection' "
1796 "SUP monitorCounter "
1797 "NO-USER-MODIFICATION "
1798 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1799 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1800 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1801 "NAME 'monitorConnectionOpsExecuting' "
1802 "DESC 'monitor number of operations in execution within 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_monitorConnectionOpsExecuting) },
1807 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1808 "NAME 'monitorConnectionOpsPending' "
1809 "DESC 'monitor number of pending operations 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_monitorConnectionOpsPending) },
1814 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1815 "NAME 'monitorConnectionOpsCompleted' "
1816 "DESC 'monitor number of operations completed 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_monitorConnectionOpsCompleted) },
1821 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1822 "NAME 'monitorConnectionGet' "
1823 "DESC 'number of times connection_get() was called so far' "
1824 "SUP monitorCounter "
1825 "NO-USER-MODIFICATION "
1826 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1827 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1828 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1829 "NAME 'monitorConnectionRead' "
1830 "DESC 'number of times connection_read() 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_monitorConnectionRead) },
1835 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1836 "NAME 'monitorConnectionWrite' "
1837 "DESC 'number of times connection_write() 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_monitorConnectionWrite) },
1842 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1843 "NAME 'monitorConnectionMask' "
1844 "DESC 'monitor connection mask' "
1845 "SUP monitoredInfo "
1846 "NO-USER-MODIFICATION "
1847 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1848 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1849 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1850 "NAME 'monitorConnectionListener' "
1851 "DESC 'monitor connection listener' "
1852 "SUP monitoredInfo "
1853 "NO-USER-MODIFICATION "
1854 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1855 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1856 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1857 "NAME 'monitorConnectionPeerDomain' "
1858 "DESC 'monitor connection peer domain' "
1859 "SUP monitoredInfo "
1860 "NO-USER-MODIFICATION "
1861 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1862 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1863 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1864 "NAME 'monitorConnectionStartTime' "
1865 "DESC 'monitor connection start time' "
1866 "SUP monitorTimestamp "
1868 "NO-USER-MODIFICATION "
1869 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1870 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1871 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1872 "NAME 'monitorConnectionActivityTime' "
1873 "DESC 'monitor connection activity time' "
1874 "SUP monitorTimestamp "
1876 "NO-USER-MODIFICATION "
1877 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1878 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1879 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1880 "NAME 'monitorIsShadow' "
1881 "DESC 'TRUE if the database is shadow' "
1882 "EQUALITY booleanMatch "
1883 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1885 "USAGE dSAOperation )", SLAP_AT_HIDE,
1886 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1887 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1888 "NAME 'monitorUpdateRef' "
1889 "DESC 'update referral for shadow databases' "
1890 "SUP monitoredInfo "
1892 "USAGE dSAOperation )", SLAP_AT_HIDE,
1893 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1894 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1895 "NAME 'monitorRuntimeConfig' "
1896 "DESC 'TRUE if component allows runtime configuration' "
1897 "EQUALITY booleanMatch "
1898 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1900 "USAGE dSAOperation )", SLAP_AT_HIDE,
1901 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1909 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1910 { "olmSubSystemAttributes", "olmAttributes:0" },
1911 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1912 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1914 /* for example, back-bdb specific attrs
1915 * are in "olmDatabaseAttributes:1"
1917 * NOTE: developers, please record here OID assignments
1918 * for other modules */
1920 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1921 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1922 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1923 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1925 /* for example, back-bdb specific objectClasses
1926 * are in "olmDatabaseObjectClasses:1"
1928 * NOTE: developers, please record here OID assignments
1929 * for other modules */
1935 monitor_info_t *mi = &monitor_info;
1939 argv[ 0 ] = "monitor";
1944 for ( i = 0; s_oid[ i ].name; i++ ) {
1945 argv[ 1 ] = s_oid[ i ].name;
1946 argv[ 2 ] = s_oid[ i ].oid;
1948 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1949 Debug( LDAP_DEBUG_ANY,
1950 "monitor_back_initialize: unable to add "
1951 "objectIdentifier \"%s=%s\"\n",
1952 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1957 /* schema integration */
1958 for ( i = 0; mat[ i ].schema; i++ ) {
1960 AttributeDescription **ad =
1961 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1964 code = register_at( mat[ i ].schema, ad, 0 );
1967 Debug( LDAP_DEBUG_ANY,
1968 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1971 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1974 for ( i = 0; moc[ i ].schema; i++ ) {
1977 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1979 code = register_oc( moc[ i ].schema, Oc, 0 );
1981 Debug( LDAP_DEBUG_ANY,
1982 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1985 (*Oc)->soc_flags |= moc[ i ].flags;
1988 bi->bi_controls = controls;
1992 bi->bi_config = monitor_back_config;
1996 bi->bi_db_init = monitor_back_db_init;
1998 bi->bi_db_config = monitor_back_db_config;
2000 bi->bi_db_open = monitor_back_db_open;
2001 bi->bi_db_close = 0;
2002 bi->bi_db_destroy = monitor_back_db_destroy;
2004 bi->bi_op_bind = monitor_back_bind;
2005 bi->bi_op_unbind = 0;
2006 bi->bi_op_search = monitor_back_search;
2007 bi->bi_op_compare = monitor_back_compare;
2008 bi->bi_op_modify = monitor_back_modify;
2009 bi->bi_op_modrdn = 0;
2011 bi->bi_op_delete = 0;
2012 bi->bi_op_abandon = 0;
2014 bi->bi_extended = 0;
2016 bi->bi_entry_release_rw = 0;
2017 bi->bi_chk_referrals = 0;
2018 bi->bi_operational = monitor_back_operational;
2021 * hooks for slap tools
2023 bi->bi_tool_entry_open = 0;
2024 bi->bi_tool_entry_close = 0;
2025 bi->bi_tool_entry_first = 0;
2026 bi->bi_tool_entry_next = 0;
2027 bi->bi_tool_entry_get = 0;
2028 bi->bi_tool_entry_put = 0;
2029 bi->bi_tool_entry_reindex = 0;
2030 bi->bi_tool_sync = 0;
2031 bi->bi_tool_dn2id_get = 0;
2032 bi->bi_tool_id2entry_get = 0;
2033 bi->bi_tool_entry_modify = 0;
2035 bi->bi_connection_init = 0;
2036 bi->bi_connection_destroy = 0;
2038 bi->bi_extra = (void *)&monitor_extra;
2041 * configuration objectClasses (fake)
2043 bi->bi_cf_ocs = monitorocs;
2045 rc = config_register_schema( monitorcfg, monitorocs );
2054 monitor_back_db_init(
2058 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
2063 monitor_subsys_t *ms;
2066 * database monitor can be defined once only
2068 if ( be_monitor != NULL ) {
2069 Debug( LDAP_DEBUG_ANY,
2070 "only one monitor database is allowed\n", 0, 0, 0 );
2078 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2079 if ( monitor_back_register_subsys( ms ) ) {
2084 /* indicate system schema supported */
2085 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2087 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2088 if( rc != LDAP_SUCCESS ) {
2089 Debug( LDAP_DEBUG_ANY,
2090 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2095 ber_bvarray_add( &be->be_suffix, &pdn );
2096 ber_bvarray_add( &be->be_nsuffix, &ndn );
2098 /* NOTE: only one monitor database is allowed,
2099 * so we use static storage */
2100 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2102 be->be_private = &monitor_info;
2104 be2 = select_backend( &ndn, 0, 0 );
2106 char *type = be2->bd_info->bi_type;
2108 if ( overlay_is_over( be2 ) ) {
2109 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2110 type = oi->oi_orig->bi_type;
2113 Debug( LDAP_DEBUG_ANY,
2114 "\"monitor\" database serving namingContext \"%s\" "
2115 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2116 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2124 monitor_back_db_open(
2127 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2128 struct monitor_subsys_t **ms;
2129 Entry *e, **ep, *root;
2130 monitor_entry_t *mp;
2132 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2134 #ifdef HAVE_GMTIME_R
2137 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2138 struct berval desc[] = {
2139 BER_BVC("This subtree contains monitoring/managing objects."),
2140 BER_BVC("This object contains information about this server."),
2141 BER_BVC("Most of the information is held in operational"
2142 " attributes, which must be explicitly requested."),
2145 assert( be_monitor != NULL );
2146 if ( be != be_monitor ) {
2153 #ifndef HAVE_GMTIME_R
2154 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2156 #ifdef HACK_LOCAL_TIME
2157 # ifdef HAVE_LOCALTIME_R
2158 tms = localtime_r( &starttime, &tm_buf );
2160 tms = localtime( &starttime );
2161 # endif /* HAVE_LOCALTIME_R */
2162 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2163 #else /* !HACK_LOCAL_TIME */
2164 # ifdef HAVE_GMTIME_R
2165 tms = gmtime_r( &starttime, &tm_buf );
2167 tms = gmtime( &starttime );
2168 # endif /* HAVE_GMTIME_R */
2169 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2170 #endif /* !HACK_LOCAL_TIME */
2171 #ifndef HAVE_GMTIME_R
2172 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2175 mi->mi_startTime.bv_val = tmbuf;
2176 mi->mi_startTime.bv_len = strlen( tmbuf );
2178 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2179 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2180 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2182 mi->mi_creatorsName = be->be_rootdn;
2183 mi->mi_ncreatorsName = be->be_rootndn;
2187 * creates the "cn=Monitor" entry
2189 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2193 Debug( LDAP_DEBUG_ANY,
2194 "unable to create \"%s\" entry\n",
2195 SLAPD_MONITOR_DN, 0, 0 );
2199 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2201 bv.bv_val = strchr( (char *) Versionstr, '$' );
2202 if ( bv.bv_val != NULL ) {
2206 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2209 end = strchr( bv.bv_val, '$' );
2210 if ( end != NULL ) {
2213 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2218 bv.bv_len = end - bv.bv_val;
2221 bv.bv_len = strlen( bv.bv_val );
2224 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2226 Debug( LDAP_DEBUG_ANY,
2227 "unable to add monitoredInfo to \"%s\" entry\n",
2228 SLAPD_MONITOR_DN, 0, 0 );
2233 mp = monitor_entrypriv_create();
2237 e->e_private = ( void * )mp;
2238 ep = &mp->mp_children;
2240 if ( monitor_cache_add( mi, e ) ) {
2241 Debug( LDAP_DEBUG_ANY,
2242 "unable to add entry \"%s\" to cache\n",
2243 SLAPD_MONITOR_DN, 0, 0 );
2249 * Create all the subsystem specific entries
2251 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2252 int len = strlen( monitor_subsys[ i ]->mss_name );
2256 dn.bv_len = len + sizeof( "cn=" ) - 1;
2257 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2258 strcpy( dn.bv_val, "cn=" );
2259 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2260 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2262 if ( rc != LDAP_SUCCESS ) {
2263 Debug( LDAP_DEBUG_ANY,
2264 "monitor RDN \"%s\" is invalid\n",
2269 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2270 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2274 Debug( LDAP_DEBUG_ANY,
2275 "unable to create \"%s\" entry\n",
2276 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2279 monitor_subsys[i]->mss_dn = e->e_name;
2280 monitor_subsys[i]->mss_ndn = e->e_nname;
2282 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2283 attr_merge_normalize( e, slap_schema.si_ad_description,
2284 monitor_subsys[ i ]->mss_desc, NULL );
2287 mp = monitor_entrypriv_create();
2291 e->e_private = ( void * )mp;
2292 mp->mp_info = monitor_subsys[ i ];
2293 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2295 if ( monitor_cache_add( mi, e ) ) {
2296 Debug( LDAP_DEBUG_ANY,
2297 "unable to add entry \"%s\" to cache\n",
2298 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2306 assert( be != NULL );
2308 be->be_private = mi;
2311 * opens the monitor backend subsystems
2313 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2314 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2318 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2321 monitor_subsys_opened = 1;
2323 if ( mi->mi_entry_limbo ) {
2324 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
2330 switch ( el->el_type ) {
2332 rc = monitor_back_register_entry(
2339 case LIMBO_ENTRY_PARENT:
2340 rc = monitor_back_register_entry_parent(
2352 rc = monitor_back_register_entry_attrs(
2362 rc = monitor_back_register_entry_callback(
2371 rc = monitor_back_register_backend( el->el_bi );
2374 case LIMBO_DATABASE:
2375 rc = monitor_back_register_database( el->el_be );
2378 case LIMBO_OVERLAY_INFO:
2379 rc = monitor_back_register_overlay_info( el->el_on );
2383 rc = monitor_back_register_overlay( el->el_be );
2391 entry_free( el->el_e );
2394 attrs_free( el->el_a );
2396 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2397 ber_memfree( el->el_ndn.bv_val );
2399 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2400 ber_memfree( el->el_nbase.bv_val );
2402 if ( !BER_BVISNULL( &el->el_filter ) ) {
2403 ber_memfree( el->el_filter.bv_val );
2405 if ( el->el_cb && rc != 0 ) {
2406 if ( el->el_cb->mc_dispose ) {
2407 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2409 ch_free( el->el_cb );
2417 mi->mi_entry_limbo = NULL;
2424 monitor_back_config(
2432 * eventually, will hold backend specific configuration parameters
2434 return SLAP_CONF_UNKNOWN;
2439 monitor_back_db_config(
2446 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2449 * eventually, will hold database specific configuration parameters
2451 return SLAP_CONF_UNKNOWN;
2456 monitor_back_db_destroy(
2459 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2466 * FIXME: destroys all the data
2468 /* NOTE: mi points to static storage; don't free it */
2470 (void)monitor_cache_destroy( mi );
2472 if ( monitor_subsys ) {
2475 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2476 if ( monitor_subsys[ i ]->mss_destroy ) {
2477 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2480 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2481 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2485 ch_free( monitor_subsys );
2488 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2490 be->be_private = NULL;
2495 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2497 /* conditionally define the init_module() function */
2498 SLAP_BACKEND_INIT_MODULE( monitor )
2500 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */