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(
343 entry_limbo_t **elpp, el = { 0 };
346 if ( be_monitor == NULL ) {
347 Debug( LDAP_DEBUG_ANY,
348 "monitor_back_register_database_limbo: "
349 "monitor database not configured.\n",
354 mi = ( monitor_info_t * )be_monitor->be_private;
357 el.el_type = LIMBO_DATABASE;
362 for ( elpp = &mi->mi_entry_limbo;
364 elpp = &(*elpp)->el_next )
367 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
376 monitor_back_register_overlay_info_limbo(
383 monitor_back_register_overlay_limbo(
390 monitor_back_register_entry(
392 monitor_callback_t *cb,
393 monitor_subsys_t *mss,
394 unsigned long flags )
398 if ( be_monitor == NULL ) {
399 Debug( LDAP_DEBUG_ANY,
400 "monitor_back_register_entry(\"%s\"): "
401 "monitor database not configured.\n",
402 e->e_name.bv_val, 0, 0 );
406 mi = ( monitor_info_t * )be_monitor->be_private;
408 assert( mi != NULL );
410 assert( e->e_private == NULL );
412 if ( monitor_subsys_is_opened() ) {
413 Entry *e_parent = NULL,
416 struct berval pdn = BER_BVNULL;
417 monitor_entry_t *mp = NULL,
421 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
423 Debug( LDAP_DEBUG_ANY,
424 "monitor_back_register_entry(\"%s\"): "
426 e->e_name.bv_val, 0, 0 );
427 monitor_cache_release( mi, e_parent );
431 dnParent( &e->e_nname, &pdn );
432 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
433 /* parent does not exist */
434 Debug( LDAP_DEBUG_ANY,
435 "monitor_back_register_entry(\"%s\"): "
436 "parent \"%s\" not found\n",
437 e->e_name.bv_val, pdn.bv_val, 0 );
441 assert( e_parent->e_private != NULL );
442 mp_parent = ( monitor_entry_t * )e_parent->e_private;
444 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
445 /* entry is volatile; cannot append children */
446 Debug( LDAP_DEBUG_ANY,
447 "monitor_back_register_entry(\"%s\"): "
448 "parent \"%s\" is volatile\n",
449 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
454 mp = monitor_entrypriv_create();
456 Debug( LDAP_DEBUG_ANY,
457 "monitor_back_register_entry(\"%s\"): "
458 "monitor_entrypriv_create() failed\n",
459 e->e_name.bv_val, 0, 0 );
464 e_new = entry_dup( e );
465 if ( e_new == NULL ) {
466 Debug( LDAP_DEBUG_ANY,
467 "monitor_back_register_entry(\"%s\"): "
468 "entry_dup() failed\n",
469 e->e_name.bv_val, 0, 0 );
474 e_new->e_private = ( void * )mp;
477 mp->mp_flags = flags;
480 mp->mp_info = mp_parent->mp_info;
481 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
485 ep = &mp_parent->mp_children;
487 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
488 ep = &mp_parent->mp_next;
492 if ( monitor_cache_add( mi, e_new ) ) {
493 Debug( LDAP_DEBUG_ANY,
494 "monitor_back_register_entry(\"%s\"): "
495 "unable to add entry\n",
496 e->e_name.bv_val, 0, 0 );
507 e_new->e_private = NULL;
513 monitor_cache_release( mi, e_parent );
517 entry_limbo_t **elpp, el = { 0 };
519 el.el_type = LIMBO_ENTRY;
521 el.el_e = entry_dup( e );
522 if ( el.el_e == NULL ) {
523 Debug( LDAP_DEBUG_ANY,
524 "monitor_back_register_entry(\"%s\"): "
525 "entry_dup() failed\n",
526 e->e_name.bv_val, 0, 0 );
534 for ( elpp = &mi->mi_entry_limbo;
536 elpp = &(*elpp)->el_next )
539 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
540 if ( *elpp == NULL ) {
541 el.el_e->e_private = NULL;
542 entry_free( el.el_e );
554 monitor_back_register_entry_parent(
556 monitor_callback_t *cb,
557 monitor_subsys_t *mss,
559 struct berval *nbase,
561 struct berval *filter )
564 struct berval ndn = BER_BVNULL;
566 if ( be_monitor == NULL ) {
567 Debug( LDAP_DEBUG_ANY,
568 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
569 "monitor database not configured.\n",
570 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
571 ldap_pvt_scope2str( scope ),
572 BER_BVISNULL( filter ) ? "" : filter->bv_val );
576 mi = ( monitor_info_t * )be_monitor->be_private;
578 assert( mi != NULL );
580 assert( e->e_private == NULL );
582 if ( BER_BVISNULL( filter ) ) {
584 Debug( LDAP_DEBUG_ANY,
585 "monitor_back_register_entry_parent(\"\"): "
586 "need a valid filter\n",
591 if ( monitor_subsys_is_opened() ) {
592 Entry *e_parent = NULL,
595 struct berval e_name = BER_BVNULL,
596 e_nname = BER_BVNULL;
597 monitor_entry_t *mp = NULL,
601 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
602 /* entry does not exist */
603 Debug( LDAP_DEBUG_ANY,
604 "monitor_back_register_entry_parent(\"\"): "
605 "base=\"%s\" scope=%s filter=\"%s\": "
606 "unable to find entry\n",
607 nbase->bv_val ? nbase->bv_val : "\"\"",
608 ldap_pvt_scope2str( scope ),
613 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
614 /* entry does not exist */
615 Debug( LDAP_DEBUG_ANY,
616 "monitor_back_register_entry_parent(\"%s\"): "
617 "parent entry does not exist\n",
623 assert( e_parent->e_private != NULL );
624 mp_parent = ( monitor_entry_t * )e_parent->e_private;
626 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
627 /* entry is volatile; cannot append callback */
628 Debug( LDAP_DEBUG_ANY,
629 "monitor_back_register_entry_parent(\"%s\"): "
630 "entry is volatile\n",
631 e_parent->e_name.bv_val, 0, 0 );
636 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
637 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
639 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
640 /* entry already exists */
641 Debug( LDAP_DEBUG_ANY,
642 "monitor_back_register_entry_parent(\"%s\"): "
643 "entry already exists\n",
644 e_name.bv_val, 0, 0 );
645 monitor_cache_release( mi, e_new );
651 mp = monitor_entrypriv_create();
653 Debug( LDAP_DEBUG_ANY,
654 "monitor_back_register_entry_parent(\"%s\"): "
655 "monitor_entrypriv_create() failed\n",
656 e->e_name.bv_val, 0, 0 );
661 e_new = entry_dup( e );
662 if ( e_new == NULL ) {
663 Debug( LDAP_DEBUG_ANY,
664 "monitor_back_register_entry(\"%s\"): "
665 "entry_dup() failed\n",
666 e->e_name.bv_val, 0, 0 );
670 ch_free( e_new->e_name.bv_val );
671 ch_free( e_new->e_nname.bv_val );
672 e_new->e_name = e_name;
673 e_new->e_nname = e_nname;
675 e_new->e_private = ( void * )mp;
678 mp->mp_flags = flags;
681 mp->mp_info = mp_parent->mp_info;
682 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
686 ep = &mp_parent->mp_children;
688 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
689 ep = &mp_parent->mp_next;
693 if ( monitor_cache_add( mi, e_new ) ) {
694 Debug( LDAP_DEBUG_ANY,
695 "monitor_back_register_entry(\"%s\"): "
696 "unable to add entry\n",
697 e->e_name.bv_val, 0, 0 );
703 if ( !BER_BVISNULL( &ndn ) ) {
704 ch_free( ndn.bv_val );
712 e_new->e_private = NULL;
718 monitor_cache_release( mi, e_parent );
722 entry_limbo_t **elpp = NULL, el = { 0 };
724 el.el_type = LIMBO_ENTRY_PARENT;
726 el.el_e = entry_dup( e );
727 if ( el.el_e == NULL ) {
728 Debug( LDAP_DEBUG_ANY,
729 "monitor_back_register_entry(\"%s\"): "
730 "entry_dup() failed\n",
731 e->e_name.bv_val, 0, 0 );
735 if ( !BER_BVISNULL( nbase ) ) {
736 ber_dupbv( &el.el_nbase, nbase );
740 if ( !BER_BVISNULL( filter ) ) {
741 ber_dupbv( &el.el_filter, filter );
748 for ( elpp = &mi->mi_entry_limbo;
750 elpp = &(*elpp)->el_next )
753 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
754 if ( *elpp == NULL ) {
759 if ( *elpp != NULL ) {
764 if ( !BER_BVISNULL( &el.el_filter ) ) {
765 ch_free( el.el_filter.bv_val );
767 if ( !BER_BVISNULL( &el.el_nbase ) ) {
768 ch_free( el.el_nbase.bv_val );
770 entry_free( el.el_e );
779 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
781 if ( rs->sr_type == REP_SEARCH ) {
782 struct berval *ndn = op->o_callback->sc_private;
784 if ( !BER_BVISNULL( ndn ) ) {
785 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
786 ch_free( ndn->bv_val );
791 ber_dupbv( ndn, &rs->sr_entry->e_nname );
799 struct berval *nbase,
801 struct berval *filter,
804 Connection conn = { 0 };
805 OperationBuffer opbuf;
808 SlapReply rs = { 0 };
809 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
814 if ( be_monitor == NULL ) {
818 thrctx = ldap_pvt_thread_pool_context();
819 connection_fake_init( &conn, &opbuf, thrctx );
822 op->o_tag = LDAP_REQ_SEARCH;
824 /* use global malloc for now */
825 if ( op->o_tmpmemctx ) {
826 op->o_tmpmemctx = NULL;
828 op->o_tmpmfuncs = &ch_mfuncs;
830 op->o_bd = be_monitor;
831 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
832 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
834 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
838 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
839 op->o_tmpmemctx ) ) {
844 op->o_callback = &cb;
845 cb.sc_private = (void *)ndn;
847 op->ors_scope = scope;
848 op->ors_filter = str2filter_x( op, filter->bv_val );
849 if ( op->ors_filter == NULL ) {
853 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
854 op->ors_attrs = slap_anlist_no_attrs;
855 op->ors_attrsonly = 0;
856 op->ors_tlimit = SLAP_NO_LIMIT;
858 op->ors_limit = NULL;
859 op->ors_deref = LDAP_DEREF_NEVER;
862 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
864 op->o_dn = be_monitor->be_rootdn;
865 op->o_ndn = be_monitor->be_rootndn;
867 rc = op->o_bd->be_search( op, &rs );
870 if ( op->ors_filter != NULL ) {
871 filter_free_x( op, op->ors_filter );
873 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
874 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
876 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
877 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
879 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
880 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
887 switch ( rs.sr_err ) {
889 if ( BER_BVISNULL( ndn ) ) {
894 case LDAP_SIZELIMIT_EXCEEDED:
896 if ( !BER_BVISNULL( ndn ) ) {
897 ber_memfree( ndn->bv_val );
908 monitor_back_register_entry_attrs(
909 struct berval *ndn_in,
911 monitor_callback_t *cb,
912 struct berval *nbase,
914 struct berval *filter )
917 struct berval ndn = BER_BVNULL;
918 char *fname = ( a == NULL ? "callback" : "attrs" );
920 if ( be_monitor == NULL ) {
921 char buf[ SLAP_TEXT_BUFLEN ];
923 snprintf( buf, sizeof( buf ),
924 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
925 "monitor database not configured.\n",
927 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
928 ldap_pvt_scope2str( scope ),
929 BER_BVISNULL( filter ) ? "" : filter->bv_val );
930 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
935 mi = ( monitor_info_t * )be_monitor->be_private;
937 assert( mi != NULL );
939 if ( ndn_in != NULL ) {
943 if ( a == NULL && cb == NULL ) {
948 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
949 && BER_BVISNULL( filter ) )
952 Debug( LDAP_DEBUG_ANY,
953 "monitor_back_register_entry_%s(\"\"): "
954 "need a valid filter\n",
959 if ( monitor_subsys_is_opened() ) {
961 Attribute **atp = NULL;
962 monitor_entry_t *mp = NULL;
963 monitor_callback_t **mcp = NULL;
967 if ( BER_BVISNULL( &ndn ) ) {
968 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
969 char buf[ SLAP_TEXT_BUFLEN ];
971 snprintf( buf, sizeof( buf ),
972 "monitor_back_register_entry_%s(\"\"): "
973 "base=\"%s\" scope=%s filter=\"%s\": "
974 "unable to find entry\n",
976 nbase->bv_val ? nbase->bv_val : "\"\"",
977 ldap_pvt_scope2str( scope ),
980 /* entry does not exist */
981 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
988 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
989 /* entry does not exist */
990 Debug( LDAP_DEBUG_ANY,
991 "monitor_back_register_entry_%s(\"%s\"): "
992 "entry does not exist\n",
993 fname, ndn.bv_val, 0 );
998 assert( e->e_private != NULL );
999 mp = ( monitor_entry_t * )e->e_private;
1001 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
1002 /* entry is volatile; cannot append callback */
1003 Debug( LDAP_DEBUG_ANY,
1004 "monitor_back_register_entry_%s(\"%s\"): "
1005 "entry is volatile\n",
1006 fname, e->e_name.bv_val, 0 );
1012 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
1013 /* just get to last */ ;
1015 for ( ; a != NULL; a = a->a_next ) {
1016 assert( a->a_desc != NULL );
1017 assert( a->a_vals != NULL );
1019 if ( attr_find( e->e_attrs, a->a_desc ) ) {
1020 attr_merge( e, a->a_desc, a->a_vals,
1021 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
1024 *atp = attr_dup( a );
1025 if ( *atp == NULL ) {
1026 Debug( LDAP_DEBUG_ANY,
1027 "monitor_back_register_entry_%s(\"%s\"): "
1028 "attr_dup() failed\n",
1029 fname, e->e_name.bv_val, 0 );
1033 atp = &(*atp)->a_next;
1039 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
1042 /* NOTE: we do not clear cb->mc_next, so this function
1043 * can be used to append a list of callbacks */
1049 if ( atp && *atp ) {
1056 ber_memfree( ndn.bv_val );
1060 monitor_cache_release( mi, e );
1064 entry_limbo_t **elpp, el = { 0 };
1066 el.el_type = LIMBO_ATTRS;
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 );
1113 monitor_back_register_entry_callback(
1115 monitor_callback_t *cb,
1116 struct berval *nbase,
1118 struct berval *filter )
1120 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1121 nbase, scope, filter );
1125 * TODO: add corresponding calls to remove installed callbacks, entries
1126 * and so, in case the entity that installed them is removed (e.g. a
1127 * database, via back-config)
1130 monitor_back_unregister_entry(
1131 struct berval *ndn )
1135 if ( be_monitor == NULL ) {
1136 Debug( LDAP_DEBUG_ANY,
1137 "monitor_back_unregister_entry(\"%s\"): "
1138 "monitor database not configured.\n",
1139 ndn->bv_val, 0, 0 );
1144 /* entry will be regularly freed, and resources released
1145 * according to callbacks */
1146 if ( slapd_shutdown ) {
1150 mi = ( monitor_info_t * )be_monitor->be_private;
1152 assert( mi != NULL );
1154 if ( monitor_subsys_is_opened() ) {
1156 monitor_entry_t *mp = NULL;
1157 monitor_callback_t *cb = NULL;
1159 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1160 /* entry does not exist */
1161 Debug( LDAP_DEBUG_ANY,
1162 "monitor_back_unregister_entry(\"%s\"): "
1163 "entry removal failed.\n",
1164 ndn->bv_val, 0, 0 );
1168 mp = (monitor_entry_t *)e->e_private;
1169 assert( mp != NULL );
1171 for ( cb = mp->mp_cb; cb != NULL; ) {
1172 monitor_callback_t *next = cb->mc_next;
1174 if ( cb->mc_free ) {
1175 (void)cb->mc_free( e, &cb->mc_private );
1183 e->e_private = NULL;
1187 entry_limbo_t **elpp;
1189 for ( elpp = &mi->mi_entry_limbo;
1191 elpp = &(*elpp)->el_next )
1193 entry_limbo_t *elp = *elpp;
1195 if ( elp->el_type == LIMBO_ENTRY
1196 && dn_match( ndn, &elp->el_e->e_nname ) )
1198 monitor_callback_t *cb, *next;
1200 for ( cb = elp->el_cb; cb; cb = next ) {
1201 /* FIXME: call callbacks? */
1203 if ( cb->mc_dispose ) {
1204 cb->mc_dispose( &cb->mc_private );
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 = &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? */
1340 if ( cb->mc_dispose ) {
1341 cb->mc_dispose( &cb->mc_private );
1345 assert( elp->el_e != NULL );
1346 elp->el_e->e_private = NULL;
1347 entry_free( elp->el_e );
1348 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1349 ch_free( elp->el_nbase.bv_val );
1351 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1352 ch_free( elp->el_filter.bv_val );
1354 *elpp = elp->el_next;
1361 if ( elpp != NULL ) {
1362 /* not found! where did it go? */
1371 monitor_back_unregister_entry_attrs(
1372 struct berval *ndn_in,
1373 Attribute *target_a,
1374 monitor_callback_t *target_cb,
1375 struct berval *nbase,
1377 struct berval *filter )
1380 struct berval ndn = BER_BVNULL;
1381 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1383 if ( be_monitor == NULL ) {
1384 char buf[ SLAP_TEXT_BUFLEN ];
1386 snprintf( buf, sizeof( buf ),
1387 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1388 "monitor database not configured.\n",
1390 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1391 ldap_pvt_scope2str( scope ),
1392 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1393 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1398 /* entry will be regularly freed, and resources released
1399 * according to callbacks */
1400 if ( slapd_shutdown ) {
1404 mi = ( monitor_info_t * )be_monitor->be_private;
1406 assert( mi != NULL );
1408 if ( ndn_in != NULL ) {
1412 if ( target_a == NULL && target_cb == NULL ) {
1417 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1418 && BER_BVISNULL( filter ) )
1421 Debug( LDAP_DEBUG_ANY,
1422 "monitor_back_unregister_entry_%s(\"\"): "
1423 "need a valid filter\n",
1428 if ( monitor_subsys_is_opened() ) {
1430 monitor_entry_t *mp = NULL;
1433 if ( BER_BVISNULL( &ndn ) ) {
1434 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1435 char buf[ SLAP_TEXT_BUFLEN ];
1437 snprintf( buf, sizeof( buf ),
1438 "monitor_back_unregister_entry_%s(\"\"): "
1439 "base=\"%s\" scope=%d filter=\"%s\": "
1440 "unable to find entry\n",
1442 nbase->bv_val ? nbase->bv_val : "\"\"",
1443 scope, filter->bv_val );
1445 /* entry does not exist */
1446 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1453 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1454 /* entry does not exist */
1455 Debug( LDAP_DEBUG_ANY,
1456 "monitor_back_unregister_entry(\"%s\"): "
1457 "entry removal failed.\n",
1462 mp = (monitor_entry_t *)e->e_private;
1463 assert( mp != NULL );
1465 if ( target_cb != NULL ) {
1466 monitor_callback_t **cbp;
1468 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1469 if ( *cbp == target_cb ) {
1470 if ( (*cbp)->mc_free ) {
1471 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1473 *cbp = (*cbp)->mc_next;
1474 ch_free( target_cb );
1480 if ( target_a != NULL ) {
1483 for ( a = target_a; a != NULL; a = a->a_next ) {
1484 Modification mod = { 0 };
1486 char textbuf[ SLAP_TEXT_BUFLEN ];
1488 mod.sm_op = LDAP_MOD_DELETE;
1489 mod.sm_desc = a->a_desc;
1490 mod.sm_values = a->a_vals;
1491 mod.sm_nvalues = a->a_nvals;
1493 (void)modify_delete_values( e, &mod, 1,
1494 &text, textbuf, sizeof( textbuf ) );
1499 ber_memfree( ndn.bv_val );
1502 monitor_cache_release( mi, e );
1505 entry_limbo_t **elpp;
1507 for ( elpp = &mi->mi_entry_limbo;
1509 elpp = &(*elpp)->el_next )
1511 entry_limbo_t *elp = *elpp;
1513 if ( elp->el_type == LIMBO_ATTRS
1514 && dn_match( nbase, &elp->el_nbase )
1515 && scope == elp->el_scope
1516 && bvmatch( filter, &elp->el_filter ) )
1518 monitor_callback_t *cb, *next;
1520 for ( cb = elp->el_cb; cb; cb = next ) {
1521 /* FIXME: call callbacks? */
1523 if ( cb->mc_dispose ) {
1524 cb->mc_dispose( &cb->mc_private );
1528 assert( elp->el_e == NULL );
1529 if ( elp->el_a != NULL ) {
1530 attrs_free( elp->el_a );
1532 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1533 ch_free( elp->el_nbase.bv_val );
1535 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1536 ch_free( elp->el_filter.bv_val );
1538 *elpp = elp->el_next;
1545 if ( elpp != NULL ) {
1546 /* not found! where did it go? */
1555 monitor_back_unregister_entry_callback(
1557 monitor_callback_t *cb,
1558 struct berval *nbase,
1560 struct berval *filter )
1562 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1563 * unregister the callback; if a is not null, unregister the
1564 * given attrs. In any case, call cb->cb_free */
1565 return monitor_back_unregister_entry_attrs( ndn,
1566 NULL, cb, nbase, scope, filter );
1570 monitor_back_get_subsys( const char *name )
1572 if ( monitor_subsys != NULL ) {
1575 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1576 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1577 return monitor_subsys[ i ];
1586 monitor_back_get_subsys_by_dn(
1590 if ( monitor_subsys != NULL ) {
1594 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1595 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1596 return monitor_subsys[ i ];
1601 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1602 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1603 return monitor_subsys[ i ];
1613 monitor_back_initialize(
1616 static char *controls[] = {
1617 LDAP_CONTROL_MANAGEDSAIT,
1621 static ConfigTable monitorcfg[] = {
1622 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1623 NULL, NULL, NULL, NULL }
1626 static ConfigOCs monitorocs[] = {
1627 { "( OLcfgDbOc:4.1 "
1628 "NAME 'olcMonitorConfig' "
1629 "DESC 'Monitor backend configuration' "
1630 "SUP olcDatabaseConfig "
1632 Cft_Database, monitorcfg },
1641 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1643 "DESC 'OpenLDAP system monitoring' "
1644 "SUP top STRUCTURAL "
1653 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1654 offsetof(monitor_info_t, mi_oc_monitor) },
1655 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1656 "NAME 'monitorServer' "
1657 "DESC 'Server monitoring root entry' "
1658 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1659 offsetof(monitor_info_t, mi_oc_monitorServer) },
1660 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1661 "NAME 'monitorContainer' "
1662 "DESC 'monitor container class' "
1663 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1664 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1665 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1666 "NAME 'monitorCounterObject' "
1667 "DESC 'monitor counter class' "
1668 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1669 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1670 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1671 "NAME 'monitorOperation' "
1672 "DESC 'monitor operation class' "
1673 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1674 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1675 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1676 "NAME 'monitorConnection' "
1677 "DESC 'monitor connection class' "
1678 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1679 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1680 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1681 "NAME 'managedObject' "
1682 "DESC 'monitor managed entity class' "
1683 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1684 offsetof(monitor_info_t, mi_oc_managedObject) },
1685 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1686 "NAME 'monitoredObject' "
1687 "DESC 'monitor monitored entity class' "
1688 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1689 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1692 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1693 "NAME 'monitoredInfo' "
1694 "DESC 'monitored info' "
1696 "EQUALITY caseIgnoreMatch "
1697 "SUBSTR caseIgnoreSubstringsMatch "
1698 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1699 "NO-USER-MODIFICATION "
1700 "USAGE dSAOperation )", SLAP_AT_HIDE,
1701 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1702 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1703 "NAME 'managedInfo' "
1704 "DESC 'monitor managed info' "
1705 "SUP name )", SLAP_AT_HIDE,
1706 offsetof(monitor_info_t, mi_ad_managedInfo) },
1707 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1708 "NAME 'monitorCounter' "
1709 "DESC 'monitor counter' "
1710 "EQUALITY integerMatch "
1711 "ORDERING integerOrderingMatch "
1712 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1713 "NO-USER-MODIFICATION "
1714 "USAGE dSAOperation )", SLAP_AT_HIDE,
1715 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1716 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1717 "NAME 'monitorOpCompleted' "
1718 "DESC 'monitor completed operations' "
1719 "SUP monitorCounter "
1720 "NO-USER-MODIFICATION "
1721 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1722 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1723 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1724 "NAME 'monitorOpInitiated' "
1725 "DESC 'monitor initiated operations' "
1726 "SUP monitorCounter "
1727 "NO-USER-MODIFICATION "
1728 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1729 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1730 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1731 "NAME 'monitorConnectionNumber' "
1732 "DESC 'monitor connection number' "
1733 "SUP monitorCounter "
1734 "NO-USER-MODIFICATION "
1735 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1736 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1737 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1738 "NAME 'monitorConnectionAuthzDN' "
1739 "DESC 'monitor connection authorization DN' "
1740 /* "SUP distinguishedName " */
1741 "EQUALITY distinguishedNameMatch "
1742 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1743 "NO-USER-MODIFICATION "
1744 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1745 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1746 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1747 "NAME 'monitorConnectionLocalAddress' "
1748 "DESC 'monitor connection local address' "
1749 "SUP monitoredInfo "
1750 "NO-USER-MODIFICATION "
1751 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1752 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1753 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1754 "NAME 'monitorConnectionPeerAddress' "
1755 "DESC 'monitor connection peer address' "
1756 "SUP monitoredInfo "
1757 "NO-USER-MODIFICATION "
1758 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1759 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1760 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1761 "NAME 'monitorTimestamp' "
1762 "DESC 'monitor timestamp' "
1763 "EQUALITY generalizedTimeMatch "
1764 "ORDERING generalizedTimeOrderingMatch "
1765 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1767 "NO-USER-MODIFICATION "
1768 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1769 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1770 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1771 "NAME 'monitorOverlay' "
1772 "DESC 'name of overlays defined for a given database' "
1773 "SUP monitoredInfo "
1774 "NO-USER-MODIFICATION "
1775 "USAGE dSAOperation )", SLAP_AT_HIDE,
1776 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1777 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1779 "DESC 'read/write status of a given database' "
1780 "EQUALITY booleanMatch "
1781 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1783 "USAGE dSAOperation )", SLAP_AT_HIDE,
1784 offsetof(monitor_info_t, mi_ad_readOnly) },
1785 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1786 "NAME 'restrictedOperation' "
1787 "DESC 'name of restricted operation for a given database' "
1788 "SUP managedInfo )", SLAP_AT_HIDE,
1789 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1790 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1791 "NAME 'monitorConnectionProtocol' "
1792 "DESC 'monitor connection protocol' "
1793 "SUP monitoredInfo "
1794 "NO-USER-MODIFICATION "
1795 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1796 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1797 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1798 "NAME 'monitorConnectionOpsReceived' "
1799 "DESC 'monitor number of operations received by the connection' "
1800 "SUP monitorCounter "
1801 "NO-USER-MODIFICATION "
1802 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1803 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1804 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1805 "NAME 'monitorConnectionOpsExecuting' "
1806 "DESC 'monitor number of operations in execution within the connection' "
1807 "SUP monitorCounter "
1808 "NO-USER-MODIFICATION "
1809 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1810 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1811 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1812 "NAME 'monitorConnectionOpsPending' "
1813 "DESC 'monitor number of pending operations within the connection' "
1814 "SUP monitorCounter "
1815 "NO-USER-MODIFICATION "
1816 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1817 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1818 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1819 "NAME 'monitorConnectionOpsCompleted' "
1820 "DESC 'monitor number of operations completed within the connection' "
1821 "SUP monitorCounter "
1822 "NO-USER-MODIFICATION "
1823 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1824 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1825 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1826 "NAME 'monitorConnectionGet' "
1827 "DESC 'number of times connection_get() was called so far' "
1828 "SUP monitorCounter "
1829 "NO-USER-MODIFICATION "
1830 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1831 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1832 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1833 "NAME 'monitorConnectionRead' "
1834 "DESC 'number of times connection_read() was called so far' "
1835 "SUP monitorCounter "
1836 "NO-USER-MODIFICATION "
1837 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1838 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1839 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1840 "NAME 'monitorConnectionWrite' "
1841 "DESC 'number of times connection_write() was called so far' "
1842 "SUP monitorCounter "
1843 "NO-USER-MODIFICATION "
1844 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1845 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1846 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1847 "NAME 'monitorConnectionMask' "
1848 "DESC 'monitor connection mask' "
1849 "SUP monitoredInfo "
1850 "NO-USER-MODIFICATION "
1851 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1852 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1853 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1854 "NAME 'monitorConnectionListener' "
1855 "DESC 'monitor connection listener' "
1856 "SUP monitoredInfo "
1857 "NO-USER-MODIFICATION "
1858 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1859 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1860 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1861 "NAME 'monitorConnectionPeerDomain' "
1862 "DESC 'monitor connection peer domain' "
1863 "SUP monitoredInfo "
1864 "NO-USER-MODIFICATION "
1865 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1866 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1867 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1868 "NAME 'monitorConnectionStartTime' "
1869 "DESC 'monitor connection start time' "
1870 "SUP monitorTimestamp "
1872 "NO-USER-MODIFICATION "
1873 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1874 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1875 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1876 "NAME 'monitorConnectionActivityTime' "
1877 "DESC 'monitor connection activity time' "
1878 "SUP monitorTimestamp "
1880 "NO-USER-MODIFICATION "
1881 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1882 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1883 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1884 "NAME 'monitorIsShadow' "
1885 "DESC 'TRUE if the database is shadow' "
1886 "EQUALITY booleanMatch "
1887 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1889 "USAGE dSAOperation )", SLAP_AT_HIDE,
1890 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1891 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1892 "NAME 'monitorUpdateRef' "
1893 "DESC 'update referral for shadow databases' "
1894 "SUP monitoredInfo "
1896 "USAGE dSAOperation )", SLAP_AT_HIDE,
1897 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1898 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1899 "NAME 'monitorRuntimeConfig' "
1900 "DESC 'TRUE if component allows runtime configuration' "
1901 "EQUALITY booleanMatch "
1902 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1904 "USAGE dSAOperation )", SLAP_AT_HIDE,
1905 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1913 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1914 { "olmSubSystemAttributes", "olmAttributes:0" },
1915 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1916 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1918 /* for example, back-bdb specific attrs
1919 * are in "olmDatabaseAttributes:1"
1921 * NOTE: developers, please record here OID assignments
1922 * for other modules */
1924 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1925 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1926 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1927 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1929 /* for example, back-bdb specific objectClasses
1930 * are in "olmDatabaseObjectClasses:1"
1932 * NOTE: developers, please record here OID assignments
1933 * for other modules */
1939 monitor_info_t *mi = &monitor_info;
1943 argv[ 0 ] = "monitor";
1948 for ( i = 0; s_oid[ i ].name; i++ ) {
1949 argv[ 1 ] = s_oid[ i ].name;
1950 argv[ 2 ] = s_oid[ i ].oid;
1952 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1953 Debug( LDAP_DEBUG_ANY,
1954 "monitor_back_initialize: unable to add "
1955 "objectIdentifier \"%s=%s\"\n",
1956 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1961 /* schema integration */
1962 for ( i = 0; mat[ i ].schema; i++ ) {
1964 AttributeDescription **ad =
1965 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1968 code = register_at( mat[ i ].schema, ad, 0 );
1971 Debug( LDAP_DEBUG_ANY,
1972 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1975 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1978 for ( i = 0; moc[ i ].schema; i++ ) {
1981 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1983 code = register_oc( moc[ i ].schema, Oc, 0 );
1985 Debug( LDAP_DEBUG_ANY,
1986 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1989 (*Oc)->soc_flags |= moc[ i ].flags;
1992 bi->bi_controls = controls;
1996 bi->bi_config = monitor_back_config;
2000 bi->bi_db_init = monitor_back_db_init;
2002 bi->bi_db_config = monitor_back_db_config;
2004 bi->bi_db_open = monitor_back_db_open;
2005 bi->bi_db_close = 0;
2006 bi->bi_db_destroy = monitor_back_db_destroy;
2008 bi->bi_op_bind = monitor_back_bind;
2009 bi->bi_op_unbind = 0;
2010 bi->bi_op_search = monitor_back_search;
2011 bi->bi_op_compare = monitor_back_compare;
2012 bi->bi_op_modify = monitor_back_modify;
2013 bi->bi_op_modrdn = 0;
2015 bi->bi_op_delete = 0;
2016 bi->bi_op_abandon = 0;
2018 bi->bi_extended = 0;
2020 bi->bi_entry_release_rw = 0;
2021 bi->bi_chk_referrals = 0;
2022 bi->bi_operational = monitor_back_operational;
2025 * hooks for slap tools
2027 bi->bi_tool_entry_open = 0;
2028 bi->bi_tool_entry_close = 0;
2029 bi->bi_tool_entry_first = 0;
2030 bi->bi_tool_entry_next = 0;
2031 bi->bi_tool_entry_get = 0;
2032 bi->bi_tool_entry_put = 0;
2033 bi->bi_tool_entry_reindex = 0;
2034 bi->bi_tool_sync = 0;
2035 bi->bi_tool_dn2id_get = 0;
2036 bi->bi_tool_entry_modify = 0;
2038 bi->bi_connection_init = 0;
2039 bi->bi_connection_destroy = 0;
2041 bi->bi_extra = (void *)&monitor_extra;
2044 * configuration objectClasses (fake)
2046 bi->bi_cf_ocs = monitorocs;
2048 rc = config_register_schema( monitorcfg, monitorocs );
2057 monitor_back_db_init(
2062 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
2067 monitor_subsys_t *ms;
2070 * database monitor can be defined once only
2072 if ( be_monitor != NULL ) {
2074 snprintf(c->msg, sizeof(c->msg),"only one monitor database allowed");
2083 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2084 if ( monitor_back_register_subsys( ms ) ) {
2089 /* indicate system schema supported */
2090 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2092 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2093 if( rc != LDAP_SUCCESS ) {
2094 Debug( LDAP_DEBUG_ANY,
2095 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2100 ber_bvarray_add( &be->be_suffix, &pdn );
2101 ber_bvarray_add( &be->be_nsuffix, &ndn );
2103 /* NOTE: only one monitor database is allowed,
2104 * so we use static storage */
2105 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2107 be->be_private = &monitor_info;
2109 be2 = select_backend( &ndn, 0 );
2111 char *type = be2->bd_info->bi_type;
2113 if ( overlay_is_over( be2 ) ) {
2114 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2115 type = oi->oi_orig->bi_type;
2119 snprintf(c->msg, sizeof(c->msg),
2120 "\"monitor\" database serving namingContext \"%s\" "
2121 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2122 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2131 monitor_back_destroy_limbo_entry(
2136 entry_free( el->el_e );
2139 attrs_free( el->el_a );
2141 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2142 ber_memfree( el->el_nbase.bv_val );
2144 if ( !BER_BVISNULL( &el->el_filter ) ) {
2145 ber_memfree( el->el_filter.bv_val );
2148 /* NOTE: callbacks are not copied; so only free them
2149 * if disposing of */
2150 if ( el->el_cb && dispose != 0 ) {
2151 monitor_callback_t *next;
2153 for ( ; el->el_cb; el->el_cb = next ) {
2154 next = el->el_cb->mc_next;
2155 if ( el->el_cb->mc_dispose ) {
2156 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2158 ch_free( el->el_cb );
2166 monitor_back_db_open(
2170 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2171 struct monitor_subsys_t **ms;
2172 Entry *e, **ep, *root;
2173 monitor_entry_t *mp;
2175 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2177 #ifdef HAVE_GMTIME_R
2180 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2181 struct berval desc[] = {
2182 BER_BVC("This subtree contains monitoring/managing objects."),
2183 BER_BVC("This object contains information about this server."),
2184 BER_BVC("Most of the information is held in operational"
2185 " attributes, which must be explicitly requested."),
2190 assert( be_monitor != NULL );
2191 if ( be != be_monitor ) {
2198 #ifndef HAVE_GMTIME_R
2199 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2201 #ifdef HACK_LOCAL_TIME
2202 # ifdef HAVE_LOCALTIME_R
2203 tms = localtime_r( &starttime, &tm_buf );
2205 tms = localtime( &starttime );
2206 # endif /* HAVE_LOCALTIME_R */
2207 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2208 #else /* !HACK_LOCAL_TIME */
2209 # ifdef HAVE_GMTIME_R
2210 tms = gmtime_r( &starttime, &tm_buf );
2212 tms = gmtime( &starttime );
2213 # endif /* HAVE_GMTIME_R */
2214 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2215 #endif /* !HACK_LOCAL_TIME */
2216 #ifndef HAVE_GMTIME_R
2217 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2220 mi->mi_startTime.bv_val = tmbuf;
2221 mi->mi_startTime.bv_len = strlen( tmbuf );
2223 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2224 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2225 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2227 mi->mi_creatorsName = be->be_rootdn;
2228 mi->mi_ncreatorsName = be->be_rootndn;
2232 * creates the "cn=Monitor" entry
2234 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2238 Debug( LDAP_DEBUG_ANY,
2239 "unable to create \"%s\" entry\n",
2240 SLAPD_MONITOR_DN, 0, 0 );
2244 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2246 bv.bv_val = strchr( (char *) Versionstr, '$' );
2247 if ( bv.bv_val != NULL ) {
2251 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2254 end = strchr( bv.bv_val, '$' );
2255 if ( end != NULL ) {
2258 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2263 bv.bv_len = end - bv.bv_val;
2266 bv.bv_len = strlen( bv.bv_val );
2269 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2271 Debug( LDAP_DEBUG_ANY,
2272 "unable to add monitoredInfo to \"%s\" entry\n",
2273 SLAPD_MONITOR_DN, 0, 0 );
2278 mp = monitor_entrypriv_create();
2282 e->e_private = ( void * )mp;
2283 ep = &mp->mp_children;
2285 if ( monitor_cache_add( mi, e ) ) {
2286 Debug( LDAP_DEBUG_ANY,
2287 "unable to add entry \"%s\" to cache\n",
2288 SLAPD_MONITOR_DN, 0, 0 );
2294 * Create all the subsystem specific entries
2296 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2297 int len = strlen( monitor_subsys[ i ]->mss_name );
2301 dn.bv_len = len + sizeof( "cn=" ) - 1;
2302 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2303 strcpy( dn.bv_val, "cn=" );
2304 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2305 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2307 if ( rc != LDAP_SUCCESS ) {
2308 Debug( LDAP_DEBUG_ANY,
2309 "monitor RDN \"%s\" is invalid\n",
2314 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2315 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2319 Debug( LDAP_DEBUG_ANY,
2320 "unable to create \"%s\" entry\n",
2321 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2324 monitor_subsys[i]->mss_dn = e->e_name;
2325 monitor_subsys[i]->mss_ndn = e->e_nname;
2327 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2328 attr_merge_normalize( e, slap_schema.si_ad_description,
2329 monitor_subsys[ i ]->mss_desc, NULL );
2332 mp = monitor_entrypriv_create();
2336 e->e_private = ( void * )mp;
2337 mp->mp_info = monitor_subsys[ i ];
2338 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2340 if ( monitor_cache_add( mi, e ) ) {
2341 Debug( LDAP_DEBUG_ANY,
2342 "unable to add entry \"%s\" to cache\n",
2343 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2351 assert( be != NULL );
2353 be->be_private = mi;
2356 * opens the monitor backend subsystems
2358 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2359 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2363 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2366 monitor_subsys_opened = 1;
2368 if ( mi->mi_entry_limbo ) {
2369 entry_limbo_t *el = mi->mi_entry_limbo;
2375 switch ( el->el_type ) {
2377 rc = monitor_back_register_entry(
2384 case LIMBO_ENTRY_PARENT:
2385 rc = monitor_back_register_entry_parent(
2397 rc = monitor_back_register_entry_attrs(
2407 rc = monitor_back_register_entry_callback(
2416 rc = monitor_back_register_backend( el->el_bi );
2419 case LIMBO_DATABASE:
2420 rc = monitor_back_register_database( el->el_be, el->el_ndn );
2423 case LIMBO_OVERLAY_INFO:
2424 rc = monitor_back_register_overlay_info( el->el_on );
2428 rc = monitor_back_register_overlay( el->el_be );
2437 monitor_back_destroy_limbo_entry( tmp, rc );
2440 /* try all, but report error at end */
2445 mi->mi_entry_limbo = NULL;
2452 monitor_back_config(
2460 * eventually, will hold backend specific configuration parameters
2462 return SLAP_CONF_UNKNOWN;
2467 monitor_back_db_config(
2474 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2477 * eventually, will hold database specific configuration parameters
2479 return SLAP_CONF_UNKNOWN;
2484 monitor_back_db_destroy(
2488 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2495 * FIXME: destroys all the data
2497 /* NOTE: mi points to static storage; don't free it */
2499 (void)monitor_cache_destroy( mi );
2501 if ( monitor_subsys ) {
2504 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2505 if ( monitor_subsys[ i ]->mss_destroy ) {
2506 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2509 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2510 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2514 ch_free( monitor_subsys );
2517 if ( mi->mi_entry_limbo ) {
2518 entry_limbo_t *el = mi->mi_entry_limbo;
2521 entry_limbo_t *tmp = el;
2523 monitor_back_destroy_limbo_entry( tmp, 1 );
2527 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2529 be->be_private = NULL;
2534 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2536 /* conditionally define the init_module() function */
2537 SLAP_BACKEND_INIT_MODULE( monitor )
2539 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */