1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2013 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,
69 monitor_back_entry_stub,
70 monitor_back_entrypriv_create,
71 monitor_back_register_subsys_late
78 * the known subsystems are added to the subsystems
79 * array at backend initialization; other subsystems
80 * may be added by calling monitor_back_register_subsys()
81 * before the database is opened (e.g. by other backends
82 * or by overlays or modules).
84 static struct monitor_subsys_t known_monitor_subsys[] = {
86 SLAPD_MONITOR_BACKEND_NAME,
87 BER_BVNULL, BER_BVNULL, BER_BVNULL,
88 { BER_BVC( "This subsystem contains information about available backends." ),
90 MONITOR_F_PERSISTENT_CH,
91 monitor_subsys_backend_init,
97 SLAPD_MONITOR_CONN_NAME,
98 BER_BVNULL, BER_BVNULL, BER_BVNULL,
99 { BER_BVC( "This subsystem contains information about connections." ),
101 MONITOR_F_VOLATILE_CH,
102 monitor_subsys_conn_init,
108 SLAPD_MONITOR_DATABASE_NAME,
109 BER_BVNULL, BER_BVNULL, BER_BVNULL,
110 { BER_BVC( "This subsystem contains information about configured databases." ),
112 MONITOR_F_PERSISTENT_CH,
113 monitor_subsys_database_init,
119 SLAPD_MONITOR_LISTENER_NAME,
120 BER_BVNULL, BER_BVNULL, BER_BVNULL,
121 { BER_BVC( "This subsystem contains information about active listeners." ),
123 MONITOR_F_PERSISTENT_CH,
124 monitor_subsys_listener_init,
130 SLAPD_MONITOR_LOG_NAME,
131 BER_BVNULL, BER_BVNULL, BER_BVNULL,
132 { BER_BVC( "This subsystem contains information about logging." ),
133 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
136 monitor_subsys_log_init,
142 SLAPD_MONITOR_OPS_NAME,
143 BER_BVNULL, BER_BVNULL, BER_BVNULL,
144 { BER_BVC( "This subsystem contains information about performed operations." ),
146 MONITOR_F_PERSISTENT_CH,
147 monitor_subsys_ops_init,
153 SLAPD_MONITOR_OVERLAY_NAME,
154 BER_BVNULL, BER_BVNULL, BER_BVNULL,
155 { BER_BVC( "This subsystem contains information about available overlays." ),
157 MONITOR_F_PERSISTENT_CH,
158 monitor_subsys_overlay_init,
164 SLAPD_MONITOR_SASL_NAME,
165 BER_BVNULL, BER_BVNULL, BER_BVNULL,
166 { BER_BVC( "This subsystem contains information about SASL." ),
175 SLAPD_MONITOR_SENT_NAME,
176 BER_BVNULL, BER_BVNULL, BER_BVNULL,
177 { BER_BVC( "This subsystem contains statistics." ),
179 MONITOR_F_PERSISTENT_CH,
180 monitor_subsys_sent_init,
186 SLAPD_MONITOR_THREAD_NAME,
187 BER_BVNULL, BER_BVNULL, BER_BVNULL,
188 { BER_BVC( "This subsystem contains information about threads." ),
190 MONITOR_F_PERSISTENT_CH,
191 monitor_subsys_thread_init,
197 SLAPD_MONITOR_TIME_NAME,
198 BER_BVNULL, BER_BVNULL, BER_BVNULL,
199 { BER_BVC( "This subsystem contains information about time." ),
201 MONITOR_F_PERSISTENT_CH,
202 monitor_subsys_time_init,
208 SLAPD_MONITOR_TLS_NAME,
209 BER_BVNULL, BER_BVNULL, BER_BVNULL,
210 { BER_BVC( "This subsystem contains information about TLS." ),
219 SLAPD_MONITOR_RWW_NAME,
220 BER_BVNULL, BER_BVNULL, BER_BVNULL,
221 { BER_BVC( "This subsystem contains information about read/write waiters." ),
223 MONITOR_F_PERSISTENT_CH,
224 monitor_subsys_rww_init,
233 monitor_subsys_is_opened( void )
235 return monitor_subsys_opened;
239 monitor_back_register_subsys(
240 monitor_subsys_t *ms )
244 if ( monitor_subsys ) {
245 for ( ; monitor_subsys[ i ] != NULL; i++ )
246 /* just count'em */ ;
249 monitor_subsys = ch_realloc( monitor_subsys,
250 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
252 if ( monitor_subsys == NULL ) {
256 monitor_subsys[ i ] = ms;
257 monitor_subsys[ i + 1 ] = NULL;
259 /* if a subsystem is registered __AFTER__ subsystem
260 * initialization (depending on the sequence the databases
261 * are listed in slapd.conf), init it */
262 if ( monitor_subsys_is_opened() ) {
264 /* FIXME: this should only be possible
265 * if be_monitor is already initialized */
266 assert( be_monitor != NULL );
268 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
272 ms->mss_flags |= MONITOR_F_OPENED;
292 typedef struct entry_limbo_t {
296 slap_overinst *el_on;
299 struct berval *el_ndn;
300 struct berval el_nbase;
302 struct berval el_filter;
303 monitor_callback_t *el_cb;
304 monitor_subsys_t *el_mss;
305 unsigned long el_flags;
306 struct entry_limbo_t *el_next;
310 monitor_back_is_configured( void )
312 return be_monitor != NULL;
316 monitor_back_register_subsys_late(
317 monitor_subsys_t *ms )
319 entry_limbo_t **elpp, el = { 0 };
322 if ( be_monitor == NULL ) {
323 Debug( LDAP_DEBUG_ANY,
324 "monitor_back_register_subsys_late: "
325 "monitor database not configured.\n",
330 /* everyting is ready, can register already */
331 if ( monitor_subsys_is_opened() ) {
332 return monitor_back_register_subsys( ms );
335 mi = ( monitor_info_t * )be_monitor->be_private;
338 el.el_type = LIMBO_SUBSYS;
342 for ( elpp = &mi->mi_entry_limbo;
344 elpp = &(*elpp)->el_next )
347 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
356 monitor_back_register_backend(
363 monitor_back_register_overlay_info(
370 monitor_back_register_backend_limbo(
377 monitor_back_register_database_limbo(
379 struct berval *ndn_out )
381 entry_limbo_t **elpp, el = { 0 };
384 if ( be_monitor == NULL ) {
385 Debug( LDAP_DEBUG_ANY,
386 "monitor_back_register_database_limbo: "
387 "monitor database not configured.\n",
392 mi = ( monitor_info_t * )be_monitor->be_private;
395 el.el_type = LIMBO_DATABASE;
397 el.el_be = be->bd_self;
400 for ( elpp = &mi->mi_entry_limbo;
402 elpp = &(*elpp)->el_next )
405 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
414 monitor_back_register_overlay_info_limbo(
421 monitor_back_register_overlay_limbo(
423 struct slap_overinst *on,
424 struct berval *ndn_out )
426 entry_limbo_t **elpp, el = { 0 };
429 if ( be_monitor == NULL ) {
430 Debug( LDAP_DEBUG_ANY,
431 "monitor_back_register_overlay_limbo: "
432 "monitor database not configured.\n",
437 mi = ( monitor_info_t * )be_monitor->be_private;
440 el.el_type = LIMBO_OVERLAY;
442 el.el_be = be->bd_self;
446 for ( elpp = &mi->mi_entry_limbo;
448 elpp = &(*elpp)->el_next )
451 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
460 monitor_back_register_entry(
462 monitor_callback_t *cb,
463 monitor_subsys_t *mss,
464 unsigned long flags )
468 if ( be_monitor == NULL ) {
469 Debug( LDAP_DEBUG_ANY,
470 "monitor_back_register_entry(\"%s\"): "
471 "monitor database not configured.\n",
472 e->e_name.bv_val, 0, 0 );
476 mi = ( monitor_info_t * )be_monitor->be_private;
478 assert( mi != NULL );
480 assert( e->e_private == NULL );
482 if ( monitor_subsys_is_opened() ) {
483 Entry *e_parent = NULL,
486 struct berval pdn = BER_BVNULL;
487 monitor_entry_t *mp = NULL,
491 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
493 Debug( LDAP_DEBUG_ANY,
494 "monitor_back_register_entry(\"%s\"): "
496 e->e_name.bv_val, 0, 0 );
497 monitor_cache_release( mi, e_parent );
501 dnParent( &e->e_nname, &pdn );
502 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
503 /* parent does not exist */
504 Debug( LDAP_DEBUG_ANY,
505 "monitor_back_register_entry(\"%s\"): "
506 "parent \"%s\" not found\n",
507 e->e_name.bv_val, pdn.bv_val, 0 );
511 assert( e_parent->e_private != NULL );
512 mp_parent = ( monitor_entry_t * )e_parent->e_private;
514 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
515 /* entry is volatile; cannot append children */
516 Debug( LDAP_DEBUG_ANY,
517 "monitor_back_register_entry(\"%s\"): "
518 "parent \"%s\" is volatile\n",
519 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
524 mp = monitor_entrypriv_create();
526 Debug( LDAP_DEBUG_ANY,
527 "monitor_back_register_entry(\"%s\"): "
528 "monitor_entrypriv_create() failed\n",
529 e->e_name.bv_val, 0, 0 );
534 e_new = entry_dup( e );
535 if ( e_new == NULL ) {
536 Debug( LDAP_DEBUG_ANY,
537 "monitor_back_register_entry(\"%s\"): "
538 "entry_dup() failed\n",
539 e->e_name.bv_val, 0, 0 );
544 e_new->e_private = ( void * )mp;
547 mp->mp_flags = flags;
550 mp->mp_info = mp_parent->mp_info;
551 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
555 ep = &mp_parent->mp_children;
557 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
558 ep = &mp_parent->mp_next;
562 if ( monitor_cache_add( mi, e_new ) ) {
563 Debug( LDAP_DEBUG_ANY,
564 "monitor_back_register_entry(\"%s\"): "
565 "unable to add entry\n",
566 e->e_name.bv_val, 0, 0 );
577 e_new->e_private = NULL;
583 monitor_cache_release( mi, e_parent );
587 entry_limbo_t **elpp, el = { 0 };
589 el.el_type = LIMBO_ENTRY;
591 el.el_e = entry_dup( e );
592 if ( el.el_e == NULL ) {
593 Debug( LDAP_DEBUG_ANY,
594 "monitor_back_register_entry(\"%s\"): "
595 "entry_dup() failed\n",
596 e->e_name.bv_val, 0, 0 );
604 for ( elpp = &mi->mi_entry_limbo;
606 elpp = &(*elpp)->el_next )
609 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
610 if ( *elpp == NULL ) {
611 el.el_e->e_private = NULL;
612 entry_free( el.el_e );
624 monitor_back_register_entry_parent(
626 monitor_callback_t *cb,
627 monitor_subsys_t *mss,
629 struct berval *nbase,
631 struct berval *filter )
634 struct berval ndn = BER_BVNULL;
636 if ( be_monitor == NULL ) {
637 Debug( LDAP_DEBUG_ANY,
638 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
639 "monitor database not configured.\n",
640 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
641 ldap_pvt_scope2str( scope ),
642 BER_BVISNULL( filter ) ? "" : filter->bv_val );
646 mi = ( monitor_info_t * )be_monitor->be_private;
648 assert( mi != NULL );
650 assert( e->e_private == NULL );
652 if ( BER_BVISNULL( filter ) ) {
654 Debug( LDAP_DEBUG_ANY,
655 "monitor_back_register_entry_parent(\"\"): "
656 "need a valid filter\n",
661 if ( monitor_subsys_is_opened() ) {
662 Entry *e_parent = NULL,
665 struct berval e_name = BER_BVNULL,
666 e_nname = BER_BVNULL;
667 monitor_entry_t *mp = NULL,
671 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
672 /* entry does not exist */
673 Debug( LDAP_DEBUG_ANY,
674 "monitor_back_register_entry_parent(\"\"): "
675 "base=\"%s\" scope=%s filter=\"%s\": "
676 "unable to find entry\n",
677 nbase->bv_val ? nbase->bv_val : "\"\"",
678 ldap_pvt_scope2str( scope ),
683 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
684 /* entry does not exist */
685 Debug( LDAP_DEBUG_ANY,
686 "monitor_back_register_entry_parent(\"%s\"): "
687 "parent entry does not exist\n",
693 assert( e_parent->e_private != NULL );
694 mp_parent = ( monitor_entry_t * )e_parent->e_private;
696 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
697 /* entry is volatile; cannot append callback */
698 Debug( LDAP_DEBUG_ANY,
699 "monitor_back_register_entry_parent(\"%s\"): "
700 "entry is volatile\n",
701 e_parent->e_name.bv_val, 0, 0 );
706 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
707 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
709 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
710 /* entry already exists */
711 Debug( LDAP_DEBUG_ANY,
712 "monitor_back_register_entry_parent(\"%s\"): "
713 "entry already exists\n",
714 e_name.bv_val, 0, 0 );
715 monitor_cache_release( mi, e_new );
721 mp = monitor_entrypriv_create();
723 Debug( LDAP_DEBUG_ANY,
724 "monitor_back_register_entry_parent(\"%s\"): "
725 "monitor_entrypriv_create() failed\n",
726 e->e_name.bv_val, 0, 0 );
731 e_new = entry_dup( e );
732 if ( e_new == NULL ) {
733 Debug( LDAP_DEBUG_ANY,
734 "monitor_back_register_entry(\"%s\"): "
735 "entry_dup() failed\n",
736 e->e_name.bv_val, 0, 0 );
740 ch_free( e_new->e_name.bv_val );
741 ch_free( e_new->e_nname.bv_val );
742 e_new->e_name = e_name;
743 e_new->e_nname = e_nname;
745 e_new->e_private = ( void * )mp;
748 mp->mp_flags = flags;
751 mp->mp_info = mp_parent->mp_info;
752 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
756 ep = &mp_parent->mp_children;
758 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
759 ep = &mp_parent->mp_next;
763 if ( monitor_cache_add( mi, e_new ) ) {
764 Debug( LDAP_DEBUG_ANY,
765 "monitor_back_register_entry(\"%s\"): "
766 "unable to add entry\n",
767 e->e_name.bv_val, 0, 0 );
773 if ( !BER_BVISNULL( &ndn ) ) {
774 ch_free( ndn.bv_val );
782 e_new->e_private = NULL;
788 monitor_cache_release( mi, e_parent );
792 entry_limbo_t **elpp = NULL, el = { 0 };
794 el.el_type = LIMBO_ENTRY_PARENT;
796 el.el_e = entry_dup( e );
797 if ( el.el_e == NULL ) {
798 Debug( LDAP_DEBUG_ANY,
799 "monitor_back_register_entry(\"%s\"): "
800 "entry_dup() failed\n",
801 e->e_name.bv_val, 0, 0 );
805 if ( !BER_BVISNULL( nbase ) ) {
806 ber_dupbv( &el.el_nbase, nbase );
810 if ( !BER_BVISNULL( filter ) ) {
811 ber_dupbv( &el.el_filter, filter );
818 for ( elpp = &mi->mi_entry_limbo;
820 elpp = &(*elpp)->el_next )
823 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
824 if ( *elpp == NULL ) {
829 if ( *elpp != NULL ) {
834 if ( !BER_BVISNULL( &el.el_filter ) ) {
835 ch_free( el.el_filter.bv_val );
837 if ( !BER_BVISNULL( &el.el_nbase ) ) {
838 ch_free( el.el_nbase.bv_val );
840 entry_free( el.el_e );
849 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
851 if ( rs->sr_type == REP_SEARCH ) {
852 struct berval *ndn = op->o_callback->sc_private;
854 if ( !BER_BVISNULL( ndn ) ) {
855 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
856 ch_free( ndn->bv_val );
861 ber_dupbv( ndn, &rs->sr_entry->e_nname );
869 struct berval *nbase,
871 struct berval *filter,
874 Connection conn = { 0 };
875 OperationBuffer opbuf;
878 SlapReply rs = { REP_RESULT };
879 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
884 if ( be_monitor == NULL ) {
888 thrctx = ldap_pvt_thread_pool_context();
889 connection_fake_init2( &conn, &opbuf, thrctx, 0 );
892 op->o_tag = LDAP_REQ_SEARCH;
894 /* use global malloc for now */
895 if ( op->o_tmpmemctx ) {
896 op->o_tmpmemctx = NULL;
898 op->o_tmpmfuncs = &ch_mfuncs;
900 op->o_bd = be_monitor;
901 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
902 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
904 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
908 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
909 op->o_tmpmemctx ) ) {
914 op->o_callback = &cb;
915 cb.sc_private = (void *)ndn;
917 op->ors_scope = scope;
918 op->ors_filter = str2filter_x( op, filter->bv_val );
919 if ( op->ors_filter == NULL ) {
923 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
924 op->ors_attrs = slap_anlist_no_attrs;
925 op->ors_attrsonly = 0;
926 op->ors_tlimit = SLAP_NO_LIMIT;
928 op->ors_limit = NULL;
929 op->ors_deref = LDAP_DEREF_NEVER;
932 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
934 op->o_dn = be_monitor->be_rootdn;
935 op->o_ndn = be_monitor->be_rootndn;
937 rc = op->o_bd->be_search( op, &rs );
940 if ( op->ors_filter != NULL ) {
941 filter_free_x( op, op->ors_filter, 1 );
943 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
944 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
946 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
947 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
949 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
950 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
957 switch ( rs.sr_err ) {
959 if ( BER_BVISNULL( ndn ) ) {
964 case LDAP_SIZELIMIT_EXCEEDED:
966 if ( !BER_BVISNULL( ndn ) ) {
967 ber_memfree( ndn->bv_val );
978 monitor_back_register_entry_attrs(
979 struct berval *ndn_in,
981 monitor_callback_t *cb,
982 struct berval *nbase,
984 struct berval *filter )
987 struct berval ndn = BER_BVNULL;
988 char *fname = ( a == NULL ? "callback" : "attrs" );
989 struct berval empty_bv = BER_BVC("");
991 if ( nbase == NULL ) nbase = &empty_bv;
992 if ( filter == NULL ) filter = &empty_bv;
994 if ( be_monitor == NULL ) {
995 char buf[ SLAP_TEXT_BUFLEN ];
997 snprintf( buf, sizeof( buf ),
998 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
999 "monitor database not configured.\n",
1001 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1002 ldap_pvt_scope2str( scope ),
1003 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1004 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1009 mi = ( monitor_info_t * )be_monitor->be_private;
1011 assert( mi != NULL );
1013 if ( ndn_in != NULL ) {
1017 if ( a == NULL && cb == NULL ) {
1022 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1023 && BER_BVISNULL( filter ) )
1026 Debug( LDAP_DEBUG_ANY,
1027 "monitor_back_register_entry_%s(\"\"): "
1028 "need a valid filter\n",
1033 if ( monitor_subsys_is_opened() ) {
1035 Attribute **atp = NULL;
1036 monitor_entry_t *mp = NULL;
1037 monitor_callback_t **mcp = NULL;
1041 if ( BER_BVISNULL( &ndn ) ) {
1042 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1043 char buf[ SLAP_TEXT_BUFLEN ];
1045 snprintf( buf, sizeof( buf ),
1046 "monitor_back_register_entry_%s(\"\"): "
1047 "base=\"%s\" scope=%s filter=\"%s\": "
1048 "unable to find entry\n",
1050 nbase->bv_val ? nbase->bv_val : "\"\"",
1051 ldap_pvt_scope2str( scope ),
1054 /* entry does not exist */
1055 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1062 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1063 /* entry does not exist */
1064 Debug( LDAP_DEBUG_ANY,
1065 "monitor_back_register_entry_%s(\"%s\"): "
1066 "entry does not exist\n",
1067 fname, ndn.bv_val, 0 );
1072 assert( e->e_private != NULL );
1073 mp = ( monitor_entry_t * )e->e_private;
1075 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
1076 /* entry is volatile; cannot append callback */
1077 Debug( LDAP_DEBUG_ANY,
1078 "monitor_back_register_entry_%s(\"%s\"): "
1079 "entry is volatile\n",
1080 fname, e->e_name.bv_val, 0 );
1086 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
1087 /* just get to last */ ;
1089 for ( ; a != NULL; a = a->a_next ) {
1090 assert( a->a_desc != NULL );
1091 assert( a->a_vals != NULL );
1093 if ( attr_find( e->e_attrs, a->a_desc ) ) {
1094 attr_merge( e, a->a_desc, a->a_vals,
1095 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
1098 *atp = attr_dup( a );
1099 if ( *atp == NULL ) {
1100 Debug( LDAP_DEBUG_ANY,
1101 "monitor_back_register_entry_%s(\"%s\"): "
1102 "attr_dup() failed\n",
1103 fname, e->e_name.bv_val, 0 );
1107 atp = &(*atp)->a_next;
1113 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
1116 /* NOTE: we do not clear cb->mc_next, so this function
1117 * can be used to append a list of callbacks */
1123 if ( atp && *atp ) {
1130 ber_memfree( ndn.bv_val );
1134 monitor_cache_release( mi, e );
1138 entry_limbo_t **elpp, el = { 0 };
1140 el.el_type = LIMBO_ATTRS;
1142 if ( !BER_BVISNULL( nbase ) ) {
1143 ber_dupbv( &el.el_nbase, nbase);
1145 el.el_scope = scope;
1146 if ( !BER_BVISNULL( filter ) ) {
1147 ber_dupbv( &el.el_filter, filter );
1150 el.el_a = attrs_dup( a );
1153 for ( elpp = &mi->mi_entry_limbo;
1155 elpp = &(*elpp)->el_next )
1158 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
1159 if ( *elpp == NULL ) {
1160 if ( !BER_BVISNULL( &el.el_filter ) ) {
1161 ch_free( el.el_filter.bv_val );
1163 if ( el.el_a != NULL ) {
1164 attrs_free( el.el_a );
1166 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1167 ch_free( &el.el_nbase.bv_val );
1180 monitor_back_register_entry_callback(
1182 monitor_callback_t *cb,
1183 struct berval *nbase,
1185 struct berval *filter )
1187 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1188 nbase, scope, filter );
1192 * TODO: add corresponding calls to remove installed callbacks, entries
1193 * and so, in case the entity that installed them is removed (e.g. a
1194 * database, via back-config)
1197 monitor_back_unregister_entry(
1198 struct berval *ndn )
1202 if ( be_monitor == NULL ) {
1203 Debug( LDAP_DEBUG_ANY,
1204 "monitor_back_unregister_entry(\"%s\"): "
1205 "monitor database not configured.\n",
1206 ndn->bv_val, 0, 0 );
1211 /* entry will be regularly freed, and resources released
1212 * according to callbacks */
1213 if ( slapd_shutdown ) {
1217 mi = ( monitor_info_t * )be_monitor->be_private;
1219 assert( mi != NULL );
1221 if ( monitor_subsys_is_opened() ) {
1223 monitor_entry_t *mp = NULL;
1224 monitor_callback_t *cb = NULL;
1226 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1227 /* entry does not exist */
1228 Debug( LDAP_DEBUG_ANY,
1229 "monitor_back_unregister_entry(\"%s\"): "
1230 "entry removal failed.\n",
1231 ndn->bv_val, 0, 0 );
1235 mp = (monitor_entry_t *)e->e_private;
1236 assert( mp != NULL );
1238 for ( cb = mp->mp_cb; cb != NULL; ) {
1239 monitor_callback_t *next = cb->mc_next;
1241 if ( cb->mc_free ) {
1242 (void)cb->mc_free( e, &cb->mc_private );
1250 e->e_private = NULL;
1254 entry_limbo_t **elpp;
1256 for ( elpp = &mi->mi_entry_limbo;
1258 elpp = &(*elpp)->el_next )
1260 entry_limbo_t *elp = *elpp;
1262 if ( elp->el_type == LIMBO_ENTRY
1263 && dn_match( ndn, &elp->el_e->e_nname ) )
1265 monitor_callback_t *cb, *next;
1267 for ( cb = elp->el_cb; cb; cb = next ) {
1268 /* FIXME: call callbacks? */
1270 if ( cb->mc_dispose ) {
1271 cb->mc_dispose( &cb->mc_private );
1275 assert( elp->el_e != NULL );
1276 elp->el_e->e_private = NULL;
1277 entry_free( elp->el_e );
1278 *elpp = elp->el_next;
1285 if ( elpp != NULL ) {
1286 /* not found! where did it go? */
1295 monitor_back_unregister_entry_parent(
1296 struct berval *nrdn,
1297 monitor_callback_t *target_cb,
1298 struct berval *nbase,
1300 struct berval *filter )
1303 struct berval ndn = BER_BVNULL;
1305 if ( be_monitor == NULL ) {
1306 Debug( LDAP_DEBUG_ANY,
1307 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1308 "monitor database not configured.\n",
1309 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1310 ldap_pvt_scope2str( scope ),
1311 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1316 /* entry will be regularly freed, and resources released
1317 * according to callbacks */
1318 if ( slapd_shutdown ) {
1322 mi = ( monitor_info_t * )be_monitor->be_private;
1324 assert( mi != NULL );
1326 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1327 && BER_BVISNULL( filter ) )
1330 Debug( LDAP_DEBUG_ANY,
1331 "monitor_back_unregister_entry_parent(\"\"): "
1332 "need a valid filter\n",
1337 if ( monitor_subsys_is_opened() ) {
1339 monitor_entry_t *mp = NULL;
1341 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1342 /* entry does not exist */
1343 Debug( LDAP_DEBUG_ANY,
1344 "monitor_back_unregister_entry_parent(\"\"): "
1345 "base=\"%s\" scope=%s filter=\"%s\": "
1346 "unable to find entry\n",
1347 nbase->bv_val ? nbase->bv_val : "\"\"",
1348 ldap_pvt_scope2str( scope ),
1353 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1354 /* entry does not exist */
1355 Debug( LDAP_DEBUG_ANY,
1356 "monitor_back_unregister_entry(\"%s\"): "
1357 "entry removal failed.\n",
1359 ber_memfree( ndn.bv_val );
1362 ber_memfree( ndn.bv_val );
1364 mp = (monitor_entry_t *)e->e_private;
1365 assert( mp != NULL );
1367 if ( target_cb != NULL ) {
1368 monitor_callback_t **cbp;
1370 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1371 if ( *cbp == target_cb ) {
1372 if ( (*cbp)->mc_free ) {
1373 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1375 *cbp = (*cbp)->mc_next;
1376 ch_free( target_cb );
1384 e->e_private = NULL;
1388 entry_limbo_t **elpp;
1390 for ( elpp = &mi->mi_entry_limbo;
1392 elpp = &(*elpp)->el_next )
1394 entry_limbo_t *elp = *elpp;
1396 if ( elp->el_type == LIMBO_ENTRY_PARENT
1397 && dn_match( nrdn, &elp->el_e->e_nname )
1398 && dn_match( nbase, &elp->el_nbase )
1399 && scope == elp->el_scope
1400 && bvmatch( filter, &elp->el_filter ) )
1402 monitor_callback_t *cb, *next;
1404 for ( cb = elp->el_cb; cb; cb = next ) {
1405 /* FIXME: call callbacks? */
1407 if ( cb->mc_dispose ) {
1408 cb->mc_dispose( &cb->mc_private );
1412 assert( elp->el_e != NULL );
1413 elp->el_e->e_private = NULL;
1414 entry_free( elp->el_e );
1415 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1416 ch_free( elp->el_nbase.bv_val );
1418 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1419 ch_free( elp->el_filter.bv_val );
1421 *elpp = elp->el_next;
1428 if ( elpp != NULL ) {
1429 /* not found! where did it go? */
1438 monitor_back_unregister_entry_attrs(
1439 struct berval *ndn_in,
1440 Attribute *target_a,
1441 monitor_callback_t *target_cb,
1442 struct berval *nbase,
1444 struct berval *filter )
1447 struct berval ndn = BER_BVNULL;
1448 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1450 if ( be_monitor == NULL ) {
1451 char buf[ SLAP_TEXT_BUFLEN ];
1453 snprintf( buf, sizeof( buf ),
1454 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1455 "monitor database not configured.\n",
1457 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1458 ldap_pvt_scope2str( scope ),
1459 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1460 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1465 /* entry will be regularly freed, and resources released
1466 * according to callbacks */
1467 if ( slapd_shutdown ) {
1471 mi = ( monitor_info_t * )be_monitor->be_private;
1473 assert( mi != NULL );
1475 if ( ndn_in != NULL ) {
1479 if ( target_a == NULL && target_cb == NULL ) {
1484 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1485 && BER_BVISNULL( filter ) )
1488 Debug( LDAP_DEBUG_ANY,
1489 "monitor_back_unregister_entry_%s(\"\"): "
1490 "need a valid filter\n",
1495 if ( monitor_subsys_is_opened() ) {
1497 monitor_entry_t *mp = NULL;
1500 if ( BER_BVISNULL( &ndn ) ) {
1501 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1502 char buf[ SLAP_TEXT_BUFLEN ];
1504 snprintf( buf, sizeof( buf ),
1505 "monitor_back_unregister_entry_%s(\"\"): "
1506 "base=\"%s\" scope=%d filter=\"%s\": "
1507 "unable to find entry\n",
1509 nbase->bv_val ? nbase->bv_val : "\"\"",
1510 scope, filter->bv_val );
1512 /* entry does not exist */
1513 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1520 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1521 /* entry does not exist */
1522 Debug( LDAP_DEBUG_ANY,
1523 "monitor_back_unregister_entry(\"%s\"): "
1524 "entry removal failed.\n",
1529 mp = (monitor_entry_t *)e->e_private;
1530 assert( mp != NULL );
1532 if ( target_cb != NULL ) {
1533 monitor_callback_t **cbp;
1535 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1536 if ( *cbp == target_cb ) {
1537 if ( (*cbp)->mc_free ) {
1538 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1540 *cbp = (*cbp)->mc_next;
1541 ch_free( target_cb );
1547 if ( target_a != NULL ) {
1550 for ( a = target_a; a != NULL; a = a->a_next ) {
1551 Modification mod = { 0 };
1553 char textbuf[ SLAP_TEXT_BUFLEN ];
1555 mod.sm_op = LDAP_MOD_DELETE;
1556 mod.sm_desc = a->a_desc;
1557 mod.sm_values = a->a_vals;
1558 mod.sm_nvalues = a->a_nvals;
1560 (void)modify_delete_values( e, &mod, 1,
1561 &text, textbuf, sizeof( textbuf ) );
1566 ber_memfree( ndn.bv_val );
1569 monitor_cache_release( mi, e );
1572 entry_limbo_t **elpp;
1574 for ( elpp = &mi->mi_entry_limbo;
1576 elpp = &(*elpp)->el_next )
1578 entry_limbo_t *elp = *elpp;
1580 if ( elp->el_type == LIMBO_ATTRS
1581 && dn_match( nbase, &elp->el_nbase )
1582 && scope == elp->el_scope
1583 && bvmatch( filter, &elp->el_filter ) )
1585 monitor_callback_t *cb, *next;
1587 for ( cb = elp->el_cb; cb; cb = next ) {
1588 /* FIXME: call callbacks? */
1590 if ( cb->mc_dispose ) {
1591 cb->mc_dispose( &cb->mc_private );
1595 assert( elp->el_e == NULL );
1596 if ( elp->el_a != NULL ) {
1597 attrs_free( elp->el_a );
1599 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1600 ch_free( elp->el_nbase.bv_val );
1602 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1603 ch_free( elp->el_filter.bv_val );
1605 *elpp = elp->el_next;
1612 if ( elpp != NULL ) {
1613 /* not found! where did it go? */
1622 monitor_back_unregister_entry_callback(
1624 monitor_callback_t *cb,
1625 struct berval *nbase,
1627 struct berval *filter )
1629 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1630 * unregister the callback; if a is not null, unregister the
1631 * given attrs. In any case, call cb->cb_free */
1632 return monitor_back_unregister_entry_attrs( ndn,
1633 NULL, cb, nbase, scope, filter );
1637 monitor_back_get_subsys( const char *name )
1639 if ( monitor_subsys != NULL ) {
1642 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1643 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1644 return monitor_subsys[ i ];
1653 monitor_back_get_subsys_by_dn(
1657 if ( monitor_subsys != NULL ) {
1661 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1662 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1663 return monitor_subsys[ i ];
1668 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1669 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1670 return monitor_subsys[ i ];
1680 monitor_back_initialize(
1683 static char *controls[] = {
1684 LDAP_CONTROL_MANAGEDSAIT,
1688 static ConfigTable monitorcfg[] = {
1689 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1690 NULL, NULL, NULL, NULL }
1693 static ConfigOCs monitorocs[] = {
1694 { "( OLcfgDbOc:4.1 "
1695 "NAME 'olcMonitorConfig' "
1696 "DESC 'Monitor backend configuration' "
1697 "SUP olcDatabaseConfig "
1699 Cft_Database, monitorcfg },
1708 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1710 "DESC 'OpenLDAP system monitoring' "
1711 "SUP top STRUCTURAL "
1720 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1721 offsetof(monitor_info_t, mi_oc_monitor) },
1722 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1723 "NAME 'monitorServer' "
1724 "DESC 'Server monitoring root entry' "
1725 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1726 offsetof(monitor_info_t, mi_oc_monitorServer) },
1727 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1728 "NAME 'monitorContainer' "
1729 "DESC 'monitor container class' "
1730 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1731 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1732 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1733 "NAME 'monitorCounterObject' "
1734 "DESC 'monitor counter class' "
1735 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1736 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1737 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1738 "NAME 'monitorOperation' "
1739 "DESC 'monitor operation class' "
1740 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1741 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1742 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1743 "NAME 'monitorConnection' "
1744 "DESC 'monitor connection class' "
1745 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1746 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1747 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1748 "NAME 'managedObject' "
1749 "DESC 'monitor managed entity class' "
1750 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1751 offsetof(monitor_info_t, mi_oc_managedObject) },
1752 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1753 "NAME 'monitoredObject' "
1754 "DESC 'monitor monitored entity class' "
1755 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1756 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1759 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1760 "NAME 'monitoredInfo' "
1761 "DESC 'monitored info' "
1763 "EQUALITY caseIgnoreMatch "
1764 "SUBSTR caseIgnoreSubstringsMatch "
1765 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1766 "NO-USER-MODIFICATION "
1767 "USAGE dSAOperation )", SLAP_AT_HIDE,
1768 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1769 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1770 "NAME 'managedInfo' "
1771 "DESC 'monitor managed info' "
1772 "SUP name )", SLAP_AT_HIDE,
1773 offsetof(monitor_info_t, mi_ad_managedInfo) },
1774 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1775 "NAME 'monitorCounter' "
1776 "DESC 'monitor counter' "
1777 "EQUALITY integerMatch "
1778 "ORDERING integerOrderingMatch "
1779 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1780 "NO-USER-MODIFICATION "
1781 "USAGE dSAOperation )", SLAP_AT_HIDE,
1782 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1783 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1784 "NAME 'monitorOpCompleted' "
1785 "DESC 'monitor completed operations' "
1786 "SUP monitorCounter "
1787 "NO-USER-MODIFICATION "
1788 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1789 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1790 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1791 "NAME 'monitorOpInitiated' "
1792 "DESC 'monitor initiated operations' "
1793 "SUP monitorCounter "
1794 "NO-USER-MODIFICATION "
1795 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1796 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1797 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1798 "NAME 'monitorConnectionNumber' "
1799 "DESC 'monitor connection number' "
1800 "SUP monitorCounter "
1801 "NO-USER-MODIFICATION "
1802 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1803 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1804 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1805 "NAME 'monitorConnectionAuthzDN' "
1806 "DESC 'monitor connection authorization DN' "
1807 /* "SUP distinguishedName " */
1808 "EQUALITY distinguishedNameMatch "
1809 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1810 "NO-USER-MODIFICATION "
1811 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1812 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1813 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1814 "NAME 'monitorConnectionLocalAddress' "
1815 "DESC 'monitor connection local address' "
1816 "SUP monitoredInfo "
1817 "NO-USER-MODIFICATION "
1818 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1819 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1820 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1821 "NAME 'monitorConnectionPeerAddress' "
1822 "DESC 'monitor connection peer address' "
1823 "SUP monitoredInfo "
1824 "NO-USER-MODIFICATION "
1825 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1826 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1827 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1828 "NAME 'monitorTimestamp' "
1829 "DESC 'monitor timestamp' "
1830 "EQUALITY generalizedTimeMatch "
1831 "ORDERING generalizedTimeOrderingMatch "
1832 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1834 "NO-USER-MODIFICATION "
1835 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1836 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1837 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1838 "NAME 'monitorOverlay' "
1839 "DESC 'name of overlays defined for a given database' "
1840 "SUP monitoredInfo "
1841 "NO-USER-MODIFICATION "
1842 "USAGE dSAOperation )", SLAP_AT_HIDE,
1843 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1844 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1846 "DESC 'read/write status of a given database' "
1847 "EQUALITY booleanMatch "
1848 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1850 "USAGE dSAOperation )", SLAP_AT_HIDE,
1851 offsetof(monitor_info_t, mi_ad_readOnly) },
1852 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1853 "NAME 'restrictedOperation' "
1854 "DESC 'name of restricted operation for a given database' "
1855 "SUP managedInfo )", SLAP_AT_HIDE,
1856 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1857 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1858 "NAME 'monitorConnectionProtocol' "
1859 "DESC 'monitor connection protocol' "
1860 "SUP monitoredInfo "
1861 "NO-USER-MODIFICATION "
1862 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1863 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1864 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1865 "NAME 'monitorConnectionOpsReceived' "
1866 "DESC 'monitor number of operations received by the connection' "
1867 "SUP monitorCounter "
1868 "NO-USER-MODIFICATION "
1869 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1870 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1871 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1872 "NAME 'monitorConnectionOpsExecuting' "
1873 "DESC 'monitor number of operations in execution within the connection' "
1874 "SUP monitorCounter "
1875 "NO-USER-MODIFICATION "
1876 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1877 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1878 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1879 "NAME 'monitorConnectionOpsPending' "
1880 "DESC 'monitor number of pending operations within the connection' "
1881 "SUP monitorCounter "
1882 "NO-USER-MODIFICATION "
1883 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1884 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1885 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1886 "NAME 'monitorConnectionOpsCompleted' "
1887 "DESC 'monitor number of operations completed within the connection' "
1888 "SUP monitorCounter "
1889 "NO-USER-MODIFICATION "
1890 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1891 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1892 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1893 "NAME 'monitorConnectionGet' "
1894 "DESC 'number of times connection_get() was called so far' "
1895 "SUP monitorCounter "
1896 "NO-USER-MODIFICATION "
1897 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1898 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1899 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1900 "NAME 'monitorConnectionRead' "
1901 "DESC 'number of times connection_read() was called so far' "
1902 "SUP monitorCounter "
1903 "NO-USER-MODIFICATION "
1904 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1905 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1906 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1907 "NAME 'monitorConnectionWrite' "
1908 "DESC 'number of times connection_write() was called so far' "
1909 "SUP monitorCounter "
1910 "NO-USER-MODIFICATION "
1911 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1912 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1913 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1914 "NAME 'monitorConnectionMask' "
1915 "DESC 'monitor connection mask' "
1916 "SUP monitoredInfo "
1917 "NO-USER-MODIFICATION "
1918 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1919 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1920 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1921 "NAME 'monitorConnectionListener' "
1922 "DESC 'monitor connection listener' "
1923 "SUP monitoredInfo "
1924 "NO-USER-MODIFICATION "
1925 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1926 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1927 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1928 "NAME 'monitorConnectionPeerDomain' "
1929 "DESC 'monitor connection peer domain' "
1930 "SUP monitoredInfo "
1931 "NO-USER-MODIFICATION "
1932 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1933 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1934 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1935 "NAME 'monitorConnectionStartTime' "
1936 "DESC 'monitor connection start time' "
1937 "SUP monitorTimestamp "
1939 "NO-USER-MODIFICATION "
1940 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1941 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1942 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1943 "NAME 'monitorConnectionActivityTime' "
1944 "DESC 'monitor connection activity time' "
1945 "SUP monitorTimestamp "
1947 "NO-USER-MODIFICATION "
1948 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1949 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1950 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1951 "NAME 'monitorIsShadow' "
1952 "DESC 'TRUE if the database is shadow' "
1953 "EQUALITY booleanMatch "
1954 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1956 "USAGE dSAOperation )", SLAP_AT_HIDE,
1957 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1958 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1959 "NAME 'monitorUpdateRef' "
1960 "DESC 'update referral for shadow databases' "
1961 "SUP monitoredInfo "
1963 "USAGE dSAOperation )", SLAP_AT_HIDE,
1964 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1965 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1966 "NAME 'monitorRuntimeConfig' "
1967 "DESC 'TRUE if component allows runtime configuration' "
1968 "EQUALITY booleanMatch "
1969 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1971 "USAGE dSAOperation )", SLAP_AT_HIDE,
1972 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1973 { "( 1.3.6.1.4.1.4203.666.1.55.30 "
1974 "NAME 'monitorSuperiorDN' "
1975 "DESC 'monitor superior DN' "
1976 /* "SUP distinguishedName " */
1977 "EQUALITY distinguishedNameMatch "
1978 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1979 "NO-USER-MODIFICATION "
1980 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1981 offsetof(monitor_info_t, mi_ad_monitorSuperiorDN) },
1989 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1990 { "olmSubSystemAttributes", "olmAttributes:0" },
1991 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1992 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1994 /* for example, back-bdb specific attrs
1995 * are in "olmDatabaseAttributes:1"
1997 * NOTE: developers, please record here OID assignments
1998 * for other modules */
2000 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
2001 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
2002 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
2003 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
2005 /* for example, back-bdb specific objectClasses
2006 * are in "olmDatabaseObjectClasses:1"
2008 * NOTE: developers, please record here OID assignments
2009 * for other modules */
2015 monitor_info_t *mi = &monitor_info;
2019 argv[ 0 ] = "monitor";
2024 for ( i = 0; s_oid[ i ].name; i++ ) {
2025 argv[ 1 ] = s_oid[ i ].name;
2026 argv[ 2 ] = s_oid[ i ].oid;
2028 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
2029 Debug( LDAP_DEBUG_ANY,
2030 "monitor_back_initialize: unable to add "
2031 "objectIdentifier \"%s=%s\"\n",
2032 s_oid[ i ].name, s_oid[ i ].oid, 0 );
2037 /* schema integration */
2038 for ( i = 0; mat[ i ].schema; i++ ) {
2040 AttributeDescription **ad =
2041 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
2044 code = register_at( mat[ i ].schema, ad, 0 );
2047 Debug( LDAP_DEBUG_ANY,
2048 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
2051 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
2054 for ( i = 0; moc[ i ].schema; i++ ) {
2057 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
2059 code = register_oc( moc[ i ].schema, Oc, 0 );
2061 Debug( LDAP_DEBUG_ANY,
2062 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
2065 (*Oc)->soc_flags |= moc[ i ].flags;
2068 bi->bi_controls = controls;
2072 bi->bi_config = monitor_back_config;
2076 bi->bi_db_init = monitor_back_db_init;
2078 bi->bi_db_config = monitor_back_db_config;
2080 bi->bi_db_open = monitor_back_db_open;
2081 bi->bi_db_close = 0;
2082 bi->bi_db_destroy = monitor_back_db_destroy;
2084 bi->bi_op_bind = monitor_back_bind;
2085 bi->bi_op_unbind = 0;
2086 bi->bi_op_search = monitor_back_search;
2087 bi->bi_op_compare = monitor_back_compare;
2088 bi->bi_op_modify = monitor_back_modify;
2089 bi->bi_op_modrdn = 0;
2091 bi->bi_op_delete = 0;
2092 bi->bi_op_abandon = 0;
2094 bi->bi_extended = 0;
2096 bi->bi_entry_release_rw = monitor_back_release;
2097 bi->bi_chk_referrals = 0;
2098 bi->bi_operational = monitor_back_operational;
2101 * hooks for slap tools
2103 bi->bi_tool_entry_open = 0;
2104 bi->bi_tool_entry_close = 0;
2105 bi->bi_tool_entry_first = 0;
2106 bi->bi_tool_entry_first_x = 0;
2107 bi->bi_tool_entry_next = 0;
2108 bi->bi_tool_entry_get = 0;
2109 bi->bi_tool_entry_put = 0;
2110 bi->bi_tool_entry_reindex = 0;
2111 bi->bi_tool_sync = 0;
2112 bi->bi_tool_dn2id_get = 0;
2113 bi->bi_tool_entry_modify = 0;
2115 bi->bi_connection_init = 0;
2116 bi->bi_connection_destroy = 0;
2118 bi->bi_extra = (void *)&monitor_extra;
2121 * configuration objectClasses (fake)
2123 bi->bi_cf_ocs = monitorocs;
2125 rc = config_register_schema( monitorcfg, monitorocs );
2134 monitor_back_db_init(
2139 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
2144 monitor_subsys_t *ms;
2147 * database monitor can be defined once only
2149 if ( be_monitor != NULL ) {
2151 snprintf(c->msg, sizeof(c->msg),"only one monitor database allowed");
2160 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2161 if ( monitor_back_register_subsys( ms ) ) {
2166 /* indicate system schema supported */
2167 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2169 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2170 if( rc != LDAP_SUCCESS ) {
2171 Debug( LDAP_DEBUG_ANY,
2172 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2177 ber_bvarray_add( &be->be_suffix, &pdn );
2178 ber_bvarray_add( &be->be_nsuffix, &ndn );
2180 /* NOTE: only one monitor database is allowed,
2181 * so we use static storage */
2182 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2184 be->be_private = &monitor_info;
2186 be2 = select_backend( &ndn, 0 );
2188 char *type = be2->bd_info->bi_type;
2190 if ( overlay_is_over( be2 ) ) {
2191 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2192 type = oi->oi_orig->bi_type;
2196 snprintf(c->msg, sizeof(c->msg),
2197 "\"monitor\" database serving namingContext \"%s\" "
2198 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2199 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2208 monitor_back_destroy_limbo_entry(
2213 entry_free( el->el_e );
2216 attrs_free( el->el_a );
2218 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2219 ber_memfree( el->el_nbase.bv_val );
2221 if ( !BER_BVISNULL( &el->el_filter ) ) {
2222 ber_memfree( el->el_filter.bv_val );
2225 /* NOTE: callbacks are not copied; so only free them
2226 * if disposing of */
2227 if ( el->el_cb && dispose != 0 ) {
2228 monitor_callback_t *next;
2230 for ( ; el->el_cb; el->el_cb = next ) {
2231 next = el->el_cb->mc_next;
2232 if ( el->el_cb->mc_dispose ) {
2233 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2235 ch_free( el->el_cb );
2243 monitor_back_db_open(
2247 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2248 struct monitor_subsys_t **ms;
2249 Entry *e, **ep, *root;
2250 monitor_entry_t *mp;
2252 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2254 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2255 struct berval desc[] = {
2256 BER_BVC("This subtree contains monitoring/managing objects."),
2257 BER_BVC("This object contains information about this server."),
2258 BER_BVC("Most of the information is held in operational"
2259 " attributes, which must be explicitly requested."),
2264 assert( be_monitor != NULL );
2265 if ( be != be_monitor ) {
2272 ldap_pvt_gmtime( &starttime, &tms );
2273 lutil_gentime( tmbuf, sizeof(tmbuf), &tms );
2275 mi->mi_startTime.bv_val = tmbuf;
2276 mi->mi_startTime.bv_len = strlen( tmbuf );
2278 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2279 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2280 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2282 mi->mi_creatorsName = be->be_rootdn;
2283 mi->mi_ncreatorsName = be->be_rootndn;
2287 * creates the "cn=Monitor" entry
2289 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer,
2293 Debug( LDAP_DEBUG_ANY,
2294 "unable to create \"%s\" entry\n",
2295 SLAPD_MONITOR_DN, 0, 0 );
2299 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2301 bv.bv_val = strchr( (char *) Versionstr, '$' );
2302 if ( bv.bv_val != NULL ) {
2306 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2309 end = strchr( bv.bv_val, '$' );
2310 if ( end != NULL ) {
2313 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2318 bv.bv_len = end - bv.bv_val;
2321 bv.bv_len = strlen( bv.bv_val );
2324 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2326 Debug( LDAP_DEBUG_ANY,
2327 "unable to add monitoredInfo to \"%s\" entry\n",
2328 SLAPD_MONITOR_DN, 0, 0 );
2333 mp = monitor_entrypriv_create();
2337 e->e_private = ( void * )mp;
2338 ep = &mp->mp_children;
2340 if ( monitor_cache_add( mi, e ) ) {
2341 Debug( LDAP_DEBUG_ANY,
2342 "unable to add entry \"%s\" to cache\n",
2343 SLAPD_MONITOR_DN, 0, 0 );
2349 * Create all the subsystem specific entries
2351 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2352 int len = strlen( monitor_subsys[ i ]->mss_name );
2356 dn.bv_len = len + sizeof( "cn=" ) - 1;
2357 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2358 strcpy( dn.bv_val, "cn=" );
2359 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2360 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2362 if ( rc != LDAP_SUCCESS ) {
2363 Debug( LDAP_DEBUG_ANY,
2364 "monitor RDN \"%s\" is invalid\n",
2369 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2370 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer,
2374 Debug( LDAP_DEBUG_ANY,
2375 "unable to create \"%s\" entry\n",
2376 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2379 monitor_subsys[i]->mss_dn = e->e_name;
2380 monitor_subsys[i]->mss_ndn = e->e_nname;
2382 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2383 attr_merge_normalize( e, slap_schema.si_ad_description,
2384 monitor_subsys[ i ]->mss_desc, NULL );
2387 mp = monitor_entrypriv_create();
2391 e->e_private = ( void * )mp;
2392 mp->mp_info = monitor_subsys[ i ];
2393 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2395 if ( monitor_cache_add( mi, e ) ) {
2396 Debug( LDAP_DEBUG_ANY,
2397 "unable to add entry \"%s\" to cache\n",
2398 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2406 assert( be != NULL );
2408 be->be_private = mi;
2411 * opens the monitor backend subsystems
2413 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2414 if ( ms[ 0 ]->mss_open && ms[ 0 ]->mss_open( be, ms[ 0 ] ) ) {
2417 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2420 monitor_subsys_opened = 1;
2422 if ( mi->mi_entry_limbo ) {
2423 entry_limbo_t *el = mi->mi_entry_limbo;
2429 switch ( el->el_type ) {
2431 rc = monitor_back_register_entry(
2438 case LIMBO_ENTRY_PARENT:
2439 rc = monitor_back_register_entry_parent(
2451 rc = monitor_back_register_entry_attrs(
2461 rc = monitor_back_register_entry_callback(
2470 rc = monitor_back_register_backend( el->el_bi );
2473 case LIMBO_DATABASE:
2474 rc = monitor_back_register_database( el->el_be, el->el_ndn );
2477 case LIMBO_OVERLAY_INFO:
2478 rc = monitor_back_register_overlay_info( el->el_on );
2482 rc = monitor_back_register_overlay( el->el_be, el->el_on, el->el_ndn );
2486 rc = monitor_back_register_subsys( el->el_mss );
2495 monitor_back_destroy_limbo_entry( tmp, rc );
2498 /* try all, but report error at end */
2503 mi->mi_entry_limbo = NULL;
2510 monitor_back_config(
2518 * eventually, will hold backend specific configuration parameters
2520 return SLAP_CONF_UNKNOWN;
2525 monitor_back_db_config(
2532 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2535 * eventually, will hold database specific configuration parameters
2537 return SLAP_CONF_UNKNOWN;
2542 monitor_back_db_destroy(
2546 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2553 * FIXME: destroys all the data
2555 /* NOTE: mi points to static storage; don't free it */
2557 (void)monitor_cache_destroy( mi );
2559 if ( monitor_subsys ) {
2562 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2563 if ( monitor_subsys[ i ]->mss_destroy ) {
2564 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2567 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2568 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2572 ch_free( monitor_subsys );
2575 if ( mi->mi_entry_limbo ) {
2576 entry_limbo_t *el = mi->mi_entry_limbo;
2579 entry_limbo_t *tmp = el;
2581 monitor_back_destroy_limbo_entry( tmp, 1 );
2585 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2587 be->be_private = NULL;
2592 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2594 /* conditionally define the init_module() function */
2595 SLAP_BACKEND_INIT_MODULE( monitor )
2597 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */