1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2012 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_backend_limbo(
332 monitor_back_register_database_limbo(
334 struct berval *ndn_out )
336 entry_limbo_t **elpp, el = { 0 };
339 if ( be_monitor == NULL ) {
340 Debug( LDAP_DEBUG_ANY,
341 "monitor_back_register_database_limbo: "
342 "monitor database not configured.\n",
347 mi = ( monitor_info_t * )be_monitor->be_private;
350 el.el_type = LIMBO_DATABASE;
352 el.el_be = be->bd_self;
355 for ( elpp = &mi->mi_entry_limbo;
357 elpp = &(*elpp)->el_next )
360 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
369 monitor_back_register_overlay_info_limbo(
376 monitor_back_register_overlay_limbo(
378 struct slap_overinst *on,
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_overlay_limbo: "
387 "monitor database not configured.\n",
392 mi = ( monitor_info_t * )be_monitor->be_private;
395 el.el_type = LIMBO_OVERLAY;
397 el.el_be = be->bd_self;
401 for ( elpp = &mi->mi_entry_limbo;
403 elpp = &(*elpp)->el_next )
406 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
415 monitor_back_register_entry(
417 monitor_callback_t *cb,
418 monitor_subsys_t *mss,
419 unsigned long flags )
423 if ( be_monitor == NULL ) {
424 Debug( LDAP_DEBUG_ANY,
425 "monitor_back_register_entry(\"%s\"): "
426 "monitor database not configured.\n",
427 e->e_name.bv_val, 0, 0 );
431 mi = ( monitor_info_t * )be_monitor->be_private;
433 assert( mi != NULL );
435 assert( e->e_private == NULL );
437 if ( monitor_subsys_is_opened() ) {
438 Entry *e_parent = NULL,
441 struct berval pdn = BER_BVNULL;
442 monitor_entry_t *mp = NULL,
446 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
448 Debug( LDAP_DEBUG_ANY,
449 "monitor_back_register_entry(\"%s\"): "
451 e->e_name.bv_val, 0, 0 );
452 monitor_cache_release( mi, e_parent );
456 dnParent( &e->e_nname, &pdn );
457 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
458 /* parent does not exist */
459 Debug( LDAP_DEBUG_ANY,
460 "monitor_back_register_entry(\"%s\"): "
461 "parent \"%s\" not found\n",
462 e->e_name.bv_val, pdn.bv_val, 0 );
466 assert( e_parent->e_private != NULL );
467 mp_parent = ( monitor_entry_t * )e_parent->e_private;
469 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
470 /* entry is volatile; cannot append children */
471 Debug( LDAP_DEBUG_ANY,
472 "monitor_back_register_entry(\"%s\"): "
473 "parent \"%s\" is volatile\n",
474 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
479 mp = monitor_entrypriv_create();
481 Debug( LDAP_DEBUG_ANY,
482 "monitor_back_register_entry(\"%s\"): "
483 "monitor_entrypriv_create() failed\n",
484 e->e_name.bv_val, 0, 0 );
489 e_new = entry_dup( e );
490 if ( e_new == NULL ) {
491 Debug( LDAP_DEBUG_ANY,
492 "monitor_back_register_entry(\"%s\"): "
493 "entry_dup() failed\n",
494 e->e_name.bv_val, 0, 0 );
499 e_new->e_private = ( void * )mp;
502 mp->mp_flags = flags;
505 mp->mp_info = mp_parent->mp_info;
506 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
510 ep = &mp_parent->mp_children;
512 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
513 ep = &mp_parent->mp_next;
517 if ( monitor_cache_add( mi, e_new ) ) {
518 Debug( LDAP_DEBUG_ANY,
519 "monitor_back_register_entry(\"%s\"): "
520 "unable to add entry\n",
521 e->e_name.bv_val, 0, 0 );
532 e_new->e_private = NULL;
538 monitor_cache_release( mi, e_parent );
542 entry_limbo_t **elpp, el = { 0 };
544 el.el_type = LIMBO_ENTRY;
546 el.el_e = entry_dup( e );
547 if ( el.el_e == NULL ) {
548 Debug( LDAP_DEBUG_ANY,
549 "monitor_back_register_entry(\"%s\"): "
550 "entry_dup() failed\n",
551 e->e_name.bv_val, 0, 0 );
559 for ( elpp = &mi->mi_entry_limbo;
561 elpp = &(*elpp)->el_next )
564 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
565 if ( *elpp == NULL ) {
566 el.el_e->e_private = NULL;
567 entry_free( el.el_e );
579 monitor_back_register_entry_parent(
581 monitor_callback_t *cb,
582 monitor_subsys_t *mss,
584 struct berval *nbase,
586 struct berval *filter )
589 struct berval ndn = BER_BVNULL;
591 if ( be_monitor == NULL ) {
592 Debug( LDAP_DEBUG_ANY,
593 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
594 "monitor database not configured.\n",
595 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
596 ldap_pvt_scope2str( scope ),
597 BER_BVISNULL( filter ) ? "" : filter->bv_val );
601 mi = ( monitor_info_t * )be_monitor->be_private;
603 assert( mi != NULL );
605 assert( e->e_private == NULL );
607 if ( BER_BVISNULL( filter ) ) {
609 Debug( LDAP_DEBUG_ANY,
610 "monitor_back_register_entry_parent(\"\"): "
611 "need a valid filter\n",
616 if ( monitor_subsys_is_opened() ) {
617 Entry *e_parent = NULL,
620 struct berval e_name = BER_BVNULL,
621 e_nname = BER_BVNULL;
622 monitor_entry_t *mp = NULL,
626 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
627 /* entry does not exist */
628 Debug( LDAP_DEBUG_ANY,
629 "monitor_back_register_entry_parent(\"\"): "
630 "base=\"%s\" scope=%s filter=\"%s\": "
631 "unable to find entry\n",
632 nbase->bv_val ? nbase->bv_val : "\"\"",
633 ldap_pvt_scope2str( scope ),
638 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
639 /* entry does not exist */
640 Debug( LDAP_DEBUG_ANY,
641 "monitor_back_register_entry_parent(\"%s\"): "
642 "parent entry does not exist\n",
648 assert( e_parent->e_private != NULL );
649 mp_parent = ( monitor_entry_t * )e_parent->e_private;
651 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
652 /* entry is volatile; cannot append callback */
653 Debug( LDAP_DEBUG_ANY,
654 "monitor_back_register_entry_parent(\"%s\"): "
655 "entry is volatile\n",
656 e_parent->e_name.bv_val, 0, 0 );
661 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
662 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
664 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
665 /* entry already exists */
666 Debug( LDAP_DEBUG_ANY,
667 "monitor_back_register_entry_parent(\"%s\"): "
668 "entry already exists\n",
669 e_name.bv_val, 0, 0 );
670 monitor_cache_release( mi, e_new );
676 mp = monitor_entrypriv_create();
678 Debug( LDAP_DEBUG_ANY,
679 "monitor_back_register_entry_parent(\"%s\"): "
680 "monitor_entrypriv_create() failed\n",
681 e->e_name.bv_val, 0, 0 );
686 e_new = entry_dup( e );
687 if ( e_new == NULL ) {
688 Debug( LDAP_DEBUG_ANY,
689 "monitor_back_register_entry(\"%s\"): "
690 "entry_dup() failed\n",
691 e->e_name.bv_val, 0, 0 );
695 ch_free( e_new->e_name.bv_val );
696 ch_free( e_new->e_nname.bv_val );
697 e_new->e_name = e_name;
698 e_new->e_nname = e_nname;
700 e_new->e_private = ( void * )mp;
703 mp->mp_flags = flags;
706 mp->mp_info = mp_parent->mp_info;
707 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
711 ep = &mp_parent->mp_children;
713 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
714 ep = &mp_parent->mp_next;
718 if ( monitor_cache_add( mi, e_new ) ) {
719 Debug( LDAP_DEBUG_ANY,
720 "monitor_back_register_entry(\"%s\"): "
721 "unable to add entry\n",
722 e->e_name.bv_val, 0, 0 );
728 if ( !BER_BVISNULL( &ndn ) ) {
729 ch_free( ndn.bv_val );
737 e_new->e_private = NULL;
743 monitor_cache_release( mi, e_parent );
747 entry_limbo_t **elpp = NULL, el = { 0 };
749 el.el_type = LIMBO_ENTRY_PARENT;
751 el.el_e = entry_dup( e );
752 if ( el.el_e == NULL ) {
753 Debug( LDAP_DEBUG_ANY,
754 "monitor_back_register_entry(\"%s\"): "
755 "entry_dup() failed\n",
756 e->e_name.bv_val, 0, 0 );
760 if ( !BER_BVISNULL( nbase ) ) {
761 ber_dupbv( &el.el_nbase, nbase );
765 if ( !BER_BVISNULL( filter ) ) {
766 ber_dupbv( &el.el_filter, filter );
773 for ( elpp = &mi->mi_entry_limbo;
775 elpp = &(*elpp)->el_next )
778 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
779 if ( *elpp == NULL ) {
784 if ( *elpp != NULL ) {
789 if ( !BER_BVISNULL( &el.el_filter ) ) {
790 ch_free( el.el_filter.bv_val );
792 if ( !BER_BVISNULL( &el.el_nbase ) ) {
793 ch_free( el.el_nbase.bv_val );
795 entry_free( el.el_e );
804 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
806 if ( rs->sr_type == REP_SEARCH ) {
807 struct berval *ndn = op->o_callback->sc_private;
809 if ( !BER_BVISNULL( ndn ) ) {
810 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
811 ch_free( ndn->bv_val );
816 ber_dupbv( ndn, &rs->sr_entry->e_nname );
824 struct berval *nbase,
826 struct berval *filter,
829 Connection conn = { 0 };
830 OperationBuffer opbuf;
833 SlapReply rs = { REP_RESULT };
834 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
839 if ( be_monitor == NULL ) {
843 thrctx = ldap_pvt_thread_pool_context();
844 connection_fake_init2( &conn, &opbuf, thrctx, 0 );
847 op->o_tag = LDAP_REQ_SEARCH;
849 /* use global malloc for now */
850 if ( op->o_tmpmemctx ) {
851 op->o_tmpmemctx = NULL;
853 op->o_tmpmfuncs = &ch_mfuncs;
855 op->o_bd = be_monitor;
856 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
857 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
859 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
863 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
864 op->o_tmpmemctx ) ) {
869 op->o_callback = &cb;
870 cb.sc_private = (void *)ndn;
872 op->ors_scope = scope;
873 op->ors_filter = str2filter_x( op, filter->bv_val );
874 if ( op->ors_filter == NULL ) {
878 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
879 op->ors_attrs = slap_anlist_no_attrs;
880 op->ors_attrsonly = 0;
881 op->ors_tlimit = SLAP_NO_LIMIT;
883 op->ors_limit = NULL;
884 op->ors_deref = LDAP_DEREF_NEVER;
887 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
889 op->o_dn = be_monitor->be_rootdn;
890 op->o_ndn = be_monitor->be_rootndn;
892 rc = op->o_bd->be_search( op, &rs );
895 if ( op->ors_filter != NULL ) {
896 filter_free_x( op, op->ors_filter, 1 );
898 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
899 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
901 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
902 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
904 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
905 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
912 switch ( rs.sr_err ) {
914 if ( BER_BVISNULL( ndn ) ) {
919 case LDAP_SIZELIMIT_EXCEEDED:
921 if ( !BER_BVISNULL( ndn ) ) {
922 ber_memfree( ndn->bv_val );
933 monitor_back_register_entry_attrs(
934 struct berval *ndn_in,
936 monitor_callback_t *cb,
937 struct berval *nbase,
939 struct berval *filter )
942 struct berval ndn = BER_BVNULL;
943 char *fname = ( a == NULL ? "callback" : "attrs" );
944 struct berval empty_bv = BER_BVC("");
946 if ( nbase == NULL ) nbase = &empty_bv;
947 if ( filter == NULL ) filter = &empty_bv;
949 if ( be_monitor == NULL ) {
950 char buf[ SLAP_TEXT_BUFLEN ];
952 snprintf( buf, sizeof( buf ),
953 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
954 "monitor database not configured.\n",
956 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
957 ldap_pvt_scope2str( scope ),
958 BER_BVISNULL( filter ) ? "" : filter->bv_val );
959 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
964 mi = ( monitor_info_t * )be_monitor->be_private;
966 assert( mi != NULL );
968 if ( ndn_in != NULL ) {
972 if ( a == NULL && cb == NULL ) {
977 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
978 && BER_BVISNULL( filter ) )
981 Debug( LDAP_DEBUG_ANY,
982 "monitor_back_register_entry_%s(\"\"): "
983 "need a valid filter\n",
988 if ( monitor_subsys_is_opened() ) {
990 Attribute **atp = NULL;
991 monitor_entry_t *mp = NULL;
992 monitor_callback_t **mcp = NULL;
996 if ( BER_BVISNULL( &ndn ) ) {
997 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
998 char buf[ SLAP_TEXT_BUFLEN ];
1000 snprintf( buf, sizeof( buf ),
1001 "monitor_back_register_entry_%s(\"\"): "
1002 "base=\"%s\" scope=%s filter=\"%s\": "
1003 "unable to find entry\n",
1005 nbase->bv_val ? nbase->bv_val : "\"\"",
1006 ldap_pvt_scope2str( scope ),
1009 /* entry does not exist */
1010 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1017 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1018 /* entry does not exist */
1019 Debug( LDAP_DEBUG_ANY,
1020 "monitor_back_register_entry_%s(\"%s\"): "
1021 "entry does not exist\n",
1022 fname, ndn.bv_val, 0 );
1027 assert( e->e_private != NULL );
1028 mp = ( monitor_entry_t * )e->e_private;
1030 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
1031 /* entry is volatile; cannot append callback */
1032 Debug( LDAP_DEBUG_ANY,
1033 "monitor_back_register_entry_%s(\"%s\"): "
1034 "entry is volatile\n",
1035 fname, e->e_name.bv_val, 0 );
1041 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
1042 /* just get to last */ ;
1044 for ( ; a != NULL; a = a->a_next ) {
1045 assert( a->a_desc != NULL );
1046 assert( a->a_vals != NULL );
1048 if ( attr_find( e->e_attrs, a->a_desc ) ) {
1049 attr_merge( e, a->a_desc, a->a_vals,
1050 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
1053 *atp = attr_dup( a );
1054 if ( *atp == NULL ) {
1055 Debug( LDAP_DEBUG_ANY,
1056 "monitor_back_register_entry_%s(\"%s\"): "
1057 "attr_dup() failed\n",
1058 fname, e->e_name.bv_val, 0 );
1062 atp = &(*atp)->a_next;
1068 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
1071 /* NOTE: we do not clear cb->mc_next, so this function
1072 * can be used to append a list of callbacks */
1078 if ( atp && *atp ) {
1085 ber_memfree( ndn.bv_val );
1089 monitor_cache_release( mi, e );
1093 entry_limbo_t **elpp, el = { 0 };
1095 el.el_type = LIMBO_ATTRS;
1097 if ( !BER_BVISNULL( nbase ) ) {
1098 ber_dupbv( &el.el_nbase, nbase);
1100 el.el_scope = scope;
1101 if ( !BER_BVISNULL( filter ) ) {
1102 ber_dupbv( &el.el_filter, filter );
1105 el.el_a = attrs_dup( a );
1108 for ( elpp = &mi->mi_entry_limbo;
1110 elpp = &(*elpp)->el_next )
1113 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
1114 if ( *elpp == NULL ) {
1115 if ( !BER_BVISNULL( &el.el_filter ) ) {
1116 ch_free( el.el_filter.bv_val );
1118 if ( el.el_a != NULL ) {
1119 attrs_free( el.el_a );
1121 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1122 ch_free( &el.el_nbase.bv_val );
1135 monitor_back_register_entry_callback(
1137 monitor_callback_t *cb,
1138 struct berval *nbase,
1140 struct berval *filter )
1142 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1143 nbase, scope, filter );
1147 * TODO: add corresponding calls to remove installed callbacks, entries
1148 * and so, in case the entity that installed them is removed (e.g. a
1149 * database, via back-config)
1152 monitor_back_unregister_entry(
1153 struct berval *ndn )
1157 if ( be_monitor == NULL ) {
1158 Debug( LDAP_DEBUG_ANY,
1159 "monitor_back_unregister_entry(\"%s\"): "
1160 "monitor database not configured.\n",
1161 ndn->bv_val, 0, 0 );
1166 /* entry will be regularly freed, and resources released
1167 * according to callbacks */
1168 if ( slapd_shutdown ) {
1172 mi = ( monitor_info_t * )be_monitor->be_private;
1174 assert( mi != NULL );
1176 if ( monitor_subsys_is_opened() ) {
1178 monitor_entry_t *mp = NULL;
1179 monitor_callback_t *cb = NULL;
1181 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1182 /* entry does not exist */
1183 Debug( LDAP_DEBUG_ANY,
1184 "monitor_back_unregister_entry(\"%s\"): "
1185 "entry removal failed.\n",
1186 ndn->bv_val, 0, 0 );
1190 mp = (monitor_entry_t *)e->e_private;
1191 assert( mp != NULL );
1193 for ( cb = mp->mp_cb; cb != NULL; ) {
1194 monitor_callback_t *next = cb->mc_next;
1196 if ( cb->mc_free ) {
1197 (void)cb->mc_free( e, &cb->mc_private );
1205 e->e_private = NULL;
1209 entry_limbo_t **elpp;
1211 for ( elpp = &mi->mi_entry_limbo;
1213 elpp = &(*elpp)->el_next )
1215 entry_limbo_t *elp = *elpp;
1217 if ( elp->el_type == LIMBO_ENTRY
1218 && dn_match( ndn, &elp->el_e->e_nname ) )
1220 monitor_callback_t *cb, *next;
1222 for ( cb = elp->el_cb; cb; cb = next ) {
1223 /* FIXME: call callbacks? */
1225 if ( cb->mc_dispose ) {
1226 cb->mc_dispose( &cb->mc_private );
1230 assert( elp->el_e != NULL );
1231 elp->el_e->e_private = NULL;
1232 entry_free( elp->el_e );
1233 *elpp = elp->el_next;
1240 if ( elpp != NULL ) {
1241 /* not found! where did it go? */
1250 monitor_back_unregister_entry_parent(
1251 struct berval *nrdn,
1252 monitor_callback_t *target_cb,
1253 struct berval *nbase,
1255 struct berval *filter )
1258 struct berval ndn = BER_BVNULL;
1260 if ( be_monitor == NULL ) {
1261 Debug( LDAP_DEBUG_ANY,
1262 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1263 "monitor database not configured.\n",
1264 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1265 ldap_pvt_scope2str( scope ),
1266 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1271 /* entry will be regularly freed, and resources released
1272 * according to callbacks */
1273 if ( slapd_shutdown ) {
1277 mi = ( monitor_info_t * )be_monitor->be_private;
1279 assert( mi != NULL );
1281 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1282 && BER_BVISNULL( filter ) )
1285 Debug( LDAP_DEBUG_ANY,
1286 "monitor_back_unregister_entry_parent(\"\"): "
1287 "need a valid filter\n",
1292 if ( monitor_subsys_is_opened() ) {
1294 monitor_entry_t *mp = NULL;
1296 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1297 /* entry does not exist */
1298 Debug( LDAP_DEBUG_ANY,
1299 "monitor_back_unregister_entry_parent(\"\"): "
1300 "base=\"%s\" scope=%s filter=\"%s\": "
1301 "unable to find entry\n",
1302 nbase->bv_val ? nbase->bv_val : "\"\"",
1303 ldap_pvt_scope2str( scope ),
1308 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1309 /* entry does not exist */
1310 Debug( LDAP_DEBUG_ANY,
1311 "monitor_back_unregister_entry(\"%s\"): "
1312 "entry removal failed.\n",
1314 ber_memfree( ndn.bv_val );
1317 ber_memfree( ndn.bv_val );
1319 mp = (monitor_entry_t *)e->e_private;
1320 assert( mp != NULL );
1322 if ( target_cb != NULL ) {
1323 monitor_callback_t **cbp;
1325 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1326 if ( *cbp == target_cb ) {
1327 if ( (*cbp)->mc_free ) {
1328 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1330 *cbp = (*cbp)->mc_next;
1331 ch_free( target_cb );
1339 e->e_private = NULL;
1343 entry_limbo_t **elpp;
1345 for ( elpp = &mi->mi_entry_limbo;
1347 elpp = &(*elpp)->el_next )
1349 entry_limbo_t *elp = *elpp;
1351 if ( elp->el_type == LIMBO_ENTRY_PARENT
1352 && dn_match( nrdn, &elp->el_e->e_nname )
1353 && dn_match( nbase, &elp->el_nbase )
1354 && scope == elp->el_scope
1355 && bvmatch( filter, &elp->el_filter ) )
1357 monitor_callback_t *cb, *next;
1359 for ( cb = elp->el_cb; cb; cb = next ) {
1360 /* FIXME: call callbacks? */
1362 if ( cb->mc_dispose ) {
1363 cb->mc_dispose( &cb->mc_private );
1367 assert( elp->el_e != NULL );
1368 elp->el_e->e_private = NULL;
1369 entry_free( elp->el_e );
1370 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1371 ch_free( elp->el_nbase.bv_val );
1373 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1374 ch_free( elp->el_filter.bv_val );
1376 *elpp = elp->el_next;
1383 if ( elpp != NULL ) {
1384 /* not found! where did it go? */
1393 monitor_back_unregister_entry_attrs(
1394 struct berval *ndn_in,
1395 Attribute *target_a,
1396 monitor_callback_t *target_cb,
1397 struct berval *nbase,
1399 struct berval *filter )
1402 struct berval ndn = BER_BVNULL;
1403 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1405 if ( be_monitor == NULL ) {
1406 char buf[ SLAP_TEXT_BUFLEN ];
1408 snprintf( buf, sizeof( buf ),
1409 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1410 "monitor database not configured.\n",
1412 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1413 ldap_pvt_scope2str( scope ),
1414 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1415 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1420 /* entry will be regularly freed, and resources released
1421 * according to callbacks */
1422 if ( slapd_shutdown ) {
1426 mi = ( monitor_info_t * )be_monitor->be_private;
1428 assert( mi != NULL );
1430 if ( ndn_in != NULL ) {
1434 if ( target_a == NULL && target_cb == NULL ) {
1439 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1440 && BER_BVISNULL( filter ) )
1443 Debug( LDAP_DEBUG_ANY,
1444 "monitor_back_unregister_entry_%s(\"\"): "
1445 "need a valid filter\n",
1450 if ( monitor_subsys_is_opened() ) {
1452 monitor_entry_t *mp = NULL;
1455 if ( BER_BVISNULL( &ndn ) ) {
1456 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1457 char buf[ SLAP_TEXT_BUFLEN ];
1459 snprintf( buf, sizeof( buf ),
1460 "monitor_back_unregister_entry_%s(\"\"): "
1461 "base=\"%s\" scope=%d filter=\"%s\": "
1462 "unable to find entry\n",
1464 nbase->bv_val ? nbase->bv_val : "\"\"",
1465 scope, filter->bv_val );
1467 /* entry does not exist */
1468 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1475 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1476 /* entry does not exist */
1477 Debug( LDAP_DEBUG_ANY,
1478 "monitor_back_unregister_entry(\"%s\"): "
1479 "entry removal failed.\n",
1484 mp = (monitor_entry_t *)e->e_private;
1485 assert( mp != NULL );
1487 if ( target_cb != NULL ) {
1488 monitor_callback_t **cbp;
1490 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1491 if ( *cbp == target_cb ) {
1492 if ( (*cbp)->mc_free ) {
1493 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1495 *cbp = (*cbp)->mc_next;
1496 ch_free( target_cb );
1502 if ( target_a != NULL ) {
1505 for ( a = target_a; a != NULL; a = a->a_next ) {
1506 Modification mod = { 0 };
1508 char textbuf[ SLAP_TEXT_BUFLEN ];
1510 mod.sm_op = LDAP_MOD_DELETE;
1511 mod.sm_desc = a->a_desc;
1512 mod.sm_values = a->a_vals;
1513 mod.sm_nvalues = a->a_nvals;
1515 (void)modify_delete_values( e, &mod, 1,
1516 &text, textbuf, sizeof( textbuf ) );
1521 ber_memfree( ndn.bv_val );
1524 monitor_cache_release( mi, e );
1527 entry_limbo_t **elpp;
1529 for ( elpp = &mi->mi_entry_limbo;
1531 elpp = &(*elpp)->el_next )
1533 entry_limbo_t *elp = *elpp;
1535 if ( elp->el_type == LIMBO_ATTRS
1536 && dn_match( nbase, &elp->el_nbase )
1537 && scope == elp->el_scope
1538 && bvmatch( filter, &elp->el_filter ) )
1540 monitor_callback_t *cb, *next;
1542 for ( cb = elp->el_cb; cb; cb = next ) {
1543 /* FIXME: call callbacks? */
1545 if ( cb->mc_dispose ) {
1546 cb->mc_dispose( &cb->mc_private );
1550 assert( elp->el_e == NULL );
1551 if ( elp->el_a != NULL ) {
1552 attrs_free( elp->el_a );
1554 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1555 ch_free( elp->el_nbase.bv_val );
1557 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1558 ch_free( elp->el_filter.bv_val );
1560 *elpp = elp->el_next;
1567 if ( elpp != NULL ) {
1568 /* not found! where did it go? */
1577 monitor_back_unregister_entry_callback(
1579 monitor_callback_t *cb,
1580 struct berval *nbase,
1582 struct berval *filter )
1584 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1585 * unregister the callback; if a is not null, unregister the
1586 * given attrs. In any case, call cb->cb_free */
1587 return monitor_back_unregister_entry_attrs( ndn,
1588 NULL, cb, nbase, scope, filter );
1592 monitor_back_get_subsys( const char *name )
1594 if ( monitor_subsys != NULL ) {
1597 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1598 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1599 return monitor_subsys[ i ];
1608 monitor_back_get_subsys_by_dn(
1612 if ( monitor_subsys != NULL ) {
1616 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1617 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1618 return monitor_subsys[ i ];
1623 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1624 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1625 return monitor_subsys[ i ];
1635 monitor_back_initialize(
1638 static char *controls[] = {
1639 LDAP_CONTROL_MANAGEDSAIT,
1643 static ConfigTable monitorcfg[] = {
1644 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1645 NULL, NULL, NULL, NULL }
1648 static ConfigOCs monitorocs[] = {
1649 { "( OLcfgDbOc:4.1 "
1650 "NAME 'olcMonitorConfig' "
1651 "DESC 'Monitor backend configuration' "
1652 "SUP olcDatabaseConfig "
1654 Cft_Database, monitorcfg },
1663 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1665 "DESC 'OpenLDAP system monitoring' "
1666 "SUP top STRUCTURAL "
1675 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1676 offsetof(monitor_info_t, mi_oc_monitor) },
1677 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1678 "NAME 'monitorServer' "
1679 "DESC 'Server monitoring root entry' "
1680 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1681 offsetof(monitor_info_t, mi_oc_monitorServer) },
1682 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1683 "NAME 'monitorContainer' "
1684 "DESC 'monitor container class' "
1685 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1686 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1687 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1688 "NAME 'monitorCounterObject' "
1689 "DESC 'monitor counter class' "
1690 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1691 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1692 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1693 "NAME 'monitorOperation' "
1694 "DESC 'monitor operation class' "
1695 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1696 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1697 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1698 "NAME 'monitorConnection' "
1699 "DESC 'monitor connection class' "
1700 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1701 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1702 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1703 "NAME 'managedObject' "
1704 "DESC 'monitor managed entity class' "
1705 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1706 offsetof(monitor_info_t, mi_oc_managedObject) },
1707 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1708 "NAME 'monitoredObject' "
1709 "DESC 'monitor monitored entity class' "
1710 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1711 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1714 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1715 "NAME 'monitoredInfo' "
1716 "DESC 'monitored info' "
1718 "EQUALITY caseIgnoreMatch "
1719 "SUBSTR caseIgnoreSubstringsMatch "
1720 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1721 "NO-USER-MODIFICATION "
1722 "USAGE dSAOperation )", SLAP_AT_HIDE,
1723 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1724 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1725 "NAME 'managedInfo' "
1726 "DESC 'monitor managed info' "
1727 "SUP name )", SLAP_AT_HIDE,
1728 offsetof(monitor_info_t, mi_ad_managedInfo) },
1729 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1730 "NAME 'monitorCounter' "
1731 "DESC 'monitor counter' "
1732 "EQUALITY integerMatch "
1733 "ORDERING integerOrderingMatch "
1734 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1735 "NO-USER-MODIFICATION "
1736 "USAGE dSAOperation )", SLAP_AT_HIDE,
1737 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1738 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1739 "NAME 'monitorOpCompleted' "
1740 "DESC 'monitor completed operations' "
1741 "SUP monitorCounter "
1742 "NO-USER-MODIFICATION "
1743 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1744 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1745 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1746 "NAME 'monitorOpInitiated' "
1747 "DESC 'monitor initiated operations' "
1748 "SUP monitorCounter "
1749 "NO-USER-MODIFICATION "
1750 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1751 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1752 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1753 "NAME 'monitorConnectionNumber' "
1754 "DESC 'monitor connection number' "
1755 "SUP monitorCounter "
1756 "NO-USER-MODIFICATION "
1757 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1758 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1759 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1760 "NAME 'monitorConnectionAuthzDN' "
1761 "DESC 'monitor connection authorization DN' "
1762 /* "SUP distinguishedName " */
1763 "EQUALITY distinguishedNameMatch "
1764 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1765 "NO-USER-MODIFICATION "
1766 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1767 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1768 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1769 "NAME 'monitorConnectionLocalAddress' "
1770 "DESC 'monitor connection local address' "
1771 "SUP monitoredInfo "
1772 "NO-USER-MODIFICATION "
1773 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1774 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1775 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1776 "NAME 'monitorConnectionPeerAddress' "
1777 "DESC 'monitor connection peer address' "
1778 "SUP monitoredInfo "
1779 "NO-USER-MODIFICATION "
1780 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1781 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1782 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1783 "NAME 'monitorTimestamp' "
1784 "DESC 'monitor timestamp' "
1785 "EQUALITY generalizedTimeMatch "
1786 "ORDERING generalizedTimeOrderingMatch "
1787 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1789 "NO-USER-MODIFICATION "
1790 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1791 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1792 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1793 "NAME 'monitorOverlay' "
1794 "DESC 'name of overlays defined for a given database' "
1795 "SUP monitoredInfo "
1796 "NO-USER-MODIFICATION "
1797 "USAGE dSAOperation )", SLAP_AT_HIDE,
1798 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1799 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1801 "DESC 'read/write status of a given database' "
1802 "EQUALITY booleanMatch "
1803 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1805 "USAGE dSAOperation )", SLAP_AT_HIDE,
1806 offsetof(monitor_info_t, mi_ad_readOnly) },
1807 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1808 "NAME 'restrictedOperation' "
1809 "DESC 'name of restricted operation for a given database' "
1810 "SUP managedInfo )", SLAP_AT_HIDE,
1811 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1812 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1813 "NAME 'monitorConnectionProtocol' "
1814 "DESC 'monitor connection protocol' "
1815 "SUP monitoredInfo "
1816 "NO-USER-MODIFICATION "
1817 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1818 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1819 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1820 "NAME 'monitorConnectionOpsReceived' "
1821 "DESC 'monitor number of operations received by the connection' "
1822 "SUP monitorCounter "
1823 "NO-USER-MODIFICATION "
1824 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1825 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1826 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1827 "NAME 'monitorConnectionOpsExecuting' "
1828 "DESC 'monitor number of operations in execution within the connection' "
1829 "SUP monitorCounter "
1830 "NO-USER-MODIFICATION "
1831 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1832 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1833 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1834 "NAME 'monitorConnectionOpsPending' "
1835 "DESC 'monitor number of pending operations within the connection' "
1836 "SUP monitorCounter "
1837 "NO-USER-MODIFICATION "
1838 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1839 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1840 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1841 "NAME 'monitorConnectionOpsCompleted' "
1842 "DESC 'monitor number of operations completed within the connection' "
1843 "SUP monitorCounter "
1844 "NO-USER-MODIFICATION "
1845 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1846 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1847 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1848 "NAME 'monitorConnectionGet' "
1849 "DESC 'number of times connection_get() was called so far' "
1850 "SUP monitorCounter "
1851 "NO-USER-MODIFICATION "
1852 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1853 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1854 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1855 "NAME 'monitorConnectionRead' "
1856 "DESC 'number of times connection_read() was called so far' "
1857 "SUP monitorCounter "
1858 "NO-USER-MODIFICATION "
1859 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1860 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1861 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1862 "NAME 'monitorConnectionWrite' "
1863 "DESC 'number of times connection_write() was called so far' "
1864 "SUP monitorCounter "
1865 "NO-USER-MODIFICATION "
1866 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1867 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1868 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1869 "NAME 'monitorConnectionMask' "
1870 "DESC 'monitor connection mask' "
1871 "SUP monitoredInfo "
1872 "NO-USER-MODIFICATION "
1873 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1874 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1875 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1876 "NAME 'monitorConnectionListener' "
1877 "DESC 'monitor connection listener' "
1878 "SUP monitoredInfo "
1879 "NO-USER-MODIFICATION "
1880 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1881 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1882 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1883 "NAME 'monitorConnectionPeerDomain' "
1884 "DESC 'monitor connection peer domain' "
1885 "SUP monitoredInfo "
1886 "NO-USER-MODIFICATION "
1887 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1888 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1889 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1890 "NAME 'monitorConnectionStartTime' "
1891 "DESC 'monitor connection start time' "
1892 "SUP monitorTimestamp "
1894 "NO-USER-MODIFICATION "
1895 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1896 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1897 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1898 "NAME 'monitorConnectionActivityTime' "
1899 "DESC 'monitor connection activity time' "
1900 "SUP monitorTimestamp "
1902 "NO-USER-MODIFICATION "
1903 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1904 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1905 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1906 "NAME 'monitorIsShadow' "
1907 "DESC 'TRUE if the database is shadow' "
1908 "EQUALITY booleanMatch "
1909 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1911 "USAGE dSAOperation )", SLAP_AT_HIDE,
1912 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1913 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1914 "NAME 'monitorUpdateRef' "
1915 "DESC 'update referral for shadow databases' "
1916 "SUP monitoredInfo "
1918 "USAGE dSAOperation )", SLAP_AT_HIDE,
1919 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1920 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1921 "NAME 'monitorRuntimeConfig' "
1922 "DESC 'TRUE if component allows runtime configuration' "
1923 "EQUALITY booleanMatch "
1924 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1926 "USAGE dSAOperation )", SLAP_AT_HIDE,
1927 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1928 { "( 1.3.6.1.4.1.4203.666.1.55.30 "
1929 "NAME 'monitorSuperiorDN' "
1930 "DESC 'monitor superior DN' "
1931 /* "SUP distinguishedName " */
1932 "EQUALITY distinguishedNameMatch "
1933 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1934 "NO-USER-MODIFICATION "
1935 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1936 offsetof(monitor_info_t, mi_ad_monitorSuperiorDN) },
1944 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1945 { "olmSubSystemAttributes", "olmAttributes:0" },
1946 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1947 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1949 /* for example, back-bdb specific attrs
1950 * are in "olmDatabaseAttributes:1"
1952 * NOTE: developers, please record here OID assignments
1953 * for other modules */
1955 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1956 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1957 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1958 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1960 /* for example, back-bdb specific objectClasses
1961 * are in "olmDatabaseObjectClasses:1"
1963 * NOTE: developers, please record here OID assignments
1964 * for other modules */
1970 monitor_info_t *mi = &monitor_info;
1974 argv[ 0 ] = "monitor";
1979 for ( i = 0; s_oid[ i ].name; i++ ) {
1980 argv[ 1 ] = s_oid[ i ].name;
1981 argv[ 2 ] = s_oid[ i ].oid;
1983 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1984 Debug( LDAP_DEBUG_ANY,
1985 "monitor_back_initialize: unable to add "
1986 "objectIdentifier \"%s=%s\"\n",
1987 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1992 /* schema integration */
1993 for ( i = 0; mat[ i ].schema; i++ ) {
1995 AttributeDescription **ad =
1996 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1999 code = register_at( mat[ i ].schema, ad, 0 );
2002 Debug( LDAP_DEBUG_ANY,
2003 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
2006 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
2009 for ( i = 0; moc[ i ].schema; i++ ) {
2012 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
2014 code = register_oc( moc[ i ].schema, Oc, 0 );
2016 Debug( LDAP_DEBUG_ANY,
2017 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
2020 (*Oc)->soc_flags |= moc[ i ].flags;
2023 bi->bi_controls = controls;
2027 bi->bi_config = monitor_back_config;
2031 bi->bi_db_init = monitor_back_db_init;
2033 bi->bi_db_config = monitor_back_db_config;
2035 bi->bi_db_open = monitor_back_db_open;
2036 bi->bi_db_close = 0;
2037 bi->bi_db_destroy = monitor_back_db_destroy;
2039 bi->bi_op_bind = monitor_back_bind;
2040 bi->bi_op_unbind = 0;
2041 bi->bi_op_search = monitor_back_search;
2042 bi->bi_op_compare = monitor_back_compare;
2043 bi->bi_op_modify = monitor_back_modify;
2044 bi->bi_op_modrdn = 0;
2046 bi->bi_op_delete = 0;
2047 bi->bi_op_abandon = 0;
2049 bi->bi_extended = 0;
2051 bi->bi_entry_release_rw = monitor_back_release;
2052 bi->bi_chk_referrals = 0;
2053 bi->bi_operational = monitor_back_operational;
2056 * hooks for slap tools
2058 bi->bi_tool_entry_open = 0;
2059 bi->bi_tool_entry_close = 0;
2060 bi->bi_tool_entry_first = 0;
2061 bi->bi_tool_entry_first_x = 0;
2062 bi->bi_tool_entry_next = 0;
2063 bi->bi_tool_entry_get = 0;
2064 bi->bi_tool_entry_put = 0;
2065 bi->bi_tool_entry_reindex = 0;
2066 bi->bi_tool_sync = 0;
2067 bi->bi_tool_dn2id_get = 0;
2068 bi->bi_tool_entry_modify = 0;
2070 bi->bi_connection_init = 0;
2071 bi->bi_connection_destroy = 0;
2073 bi->bi_extra = (void *)&monitor_extra;
2076 * configuration objectClasses (fake)
2078 bi->bi_cf_ocs = monitorocs;
2080 rc = config_register_schema( monitorcfg, monitorocs );
2089 monitor_back_db_init(
2094 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
2099 monitor_subsys_t *ms;
2102 * database monitor can be defined once only
2104 if ( be_monitor != NULL ) {
2106 snprintf(c->msg, sizeof(c->msg),"only one monitor database allowed");
2115 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2116 if ( monitor_back_register_subsys( ms ) ) {
2121 /* indicate system schema supported */
2122 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2124 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2125 if( rc != LDAP_SUCCESS ) {
2126 Debug( LDAP_DEBUG_ANY,
2127 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2132 ber_bvarray_add( &be->be_suffix, &pdn );
2133 ber_bvarray_add( &be->be_nsuffix, &ndn );
2135 /* NOTE: only one monitor database is allowed,
2136 * so we use static storage */
2137 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2139 be->be_private = &monitor_info;
2141 be2 = select_backend( &ndn, 0 );
2143 char *type = be2->bd_info->bi_type;
2145 if ( overlay_is_over( be2 ) ) {
2146 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2147 type = oi->oi_orig->bi_type;
2151 snprintf(c->msg, sizeof(c->msg),
2152 "\"monitor\" database serving namingContext \"%s\" "
2153 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2154 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2163 monitor_back_destroy_limbo_entry(
2168 entry_free( el->el_e );
2171 attrs_free( el->el_a );
2173 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2174 ber_memfree( el->el_nbase.bv_val );
2176 if ( !BER_BVISNULL( &el->el_filter ) ) {
2177 ber_memfree( el->el_filter.bv_val );
2180 /* NOTE: callbacks are not copied; so only free them
2181 * if disposing of */
2182 if ( el->el_cb && dispose != 0 ) {
2183 monitor_callback_t *next;
2185 for ( ; el->el_cb; el->el_cb = next ) {
2186 next = el->el_cb->mc_next;
2187 if ( el->el_cb->mc_dispose ) {
2188 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2190 ch_free( el->el_cb );
2198 monitor_back_db_open(
2202 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2203 struct monitor_subsys_t **ms;
2204 Entry *e, **ep, *root;
2205 monitor_entry_t *mp;
2207 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2209 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2210 struct berval desc[] = {
2211 BER_BVC("This subtree contains monitoring/managing objects."),
2212 BER_BVC("This object contains information about this server."),
2213 BER_BVC("Most of the information is held in operational"
2214 " attributes, which must be explicitly requested."),
2219 assert( be_monitor != NULL );
2220 if ( be != be_monitor ) {
2227 ldap_pvt_gmtime( &starttime, &tms );
2228 lutil_gentime( tmbuf, sizeof(tmbuf), &tms );
2230 mi->mi_startTime.bv_val = tmbuf;
2231 mi->mi_startTime.bv_len = strlen( tmbuf );
2233 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2234 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2235 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2237 mi->mi_creatorsName = be->be_rootdn;
2238 mi->mi_ncreatorsName = be->be_rootndn;
2242 * creates the "cn=Monitor" entry
2244 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2248 Debug( LDAP_DEBUG_ANY,
2249 "unable to create \"%s\" entry\n",
2250 SLAPD_MONITOR_DN, 0, 0 );
2254 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2256 bv.bv_val = strchr( (char *) Versionstr, '$' );
2257 if ( bv.bv_val != NULL ) {
2261 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2264 end = strchr( bv.bv_val, '$' );
2265 if ( end != NULL ) {
2268 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2273 bv.bv_len = end - bv.bv_val;
2276 bv.bv_len = strlen( bv.bv_val );
2279 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2281 Debug( LDAP_DEBUG_ANY,
2282 "unable to add monitoredInfo to \"%s\" entry\n",
2283 SLAPD_MONITOR_DN, 0, 0 );
2288 mp = monitor_entrypriv_create();
2292 e->e_private = ( void * )mp;
2293 ep = &mp->mp_children;
2295 if ( monitor_cache_add( mi, e ) ) {
2296 Debug( LDAP_DEBUG_ANY,
2297 "unable to add entry \"%s\" to cache\n",
2298 SLAPD_MONITOR_DN, 0, 0 );
2304 * Create all the subsystem specific entries
2306 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2307 int len = strlen( monitor_subsys[ i ]->mss_name );
2311 dn.bv_len = len + sizeof( "cn=" ) - 1;
2312 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2313 strcpy( dn.bv_val, "cn=" );
2314 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2315 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2317 if ( rc != LDAP_SUCCESS ) {
2318 Debug( LDAP_DEBUG_ANY,
2319 "monitor RDN \"%s\" is invalid\n",
2324 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2325 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2329 Debug( LDAP_DEBUG_ANY,
2330 "unable to create \"%s\" entry\n",
2331 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2334 monitor_subsys[i]->mss_dn = e->e_name;
2335 monitor_subsys[i]->mss_ndn = e->e_nname;
2337 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2338 attr_merge_normalize( e, slap_schema.si_ad_description,
2339 monitor_subsys[ i ]->mss_desc, NULL );
2342 mp = monitor_entrypriv_create();
2346 e->e_private = ( void * )mp;
2347 mp->mp_info = monitor_subsys[ i ];
2348 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2350 if ( monitor_cache_add( mi, e ) ) {
2351 Debug( LDAP_DEBUG_ANY,
2352 "unable to add entry \"%s\" to cache\n",
2353 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2361 assert( be != NULL );
2363 be->be_private = mi;
2366 * opens the monitor backend subsystems
2368 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2369 if ( ms[ 0 ]->mss_open && ms[ 0 ]->mss_open( be, ms[ 0 ] ) ) {
2372 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2375 monitor_subsys_opened = 1;
2377 if ( mi->mi_entry_limbo ) {
2378 entry_limbo_t *el = mi->mi_entry_limbo;
2384 switch ( el->el_type ) {
2386 rc = monitor_back_register_entry(
2393 case LIMBO_ENTRY_PARENT:
2394 rc = monitor_back_register_entry_parent(
2406 rc = monitor_back_register_entry_attrs(
2416 rc = monitor_back_register_entry_callback(
2425 rc = monitor_back_register_backend( el->el_bi );
2428 case LIMBO_DATABASE:
2429 rc = monitor_back_register_database( el->el_be, el->el_ndn );
2432 case LIMBO_OVERLAY_INFO:
2433 rc = monitor_back_register_overlay_info( el->el_on );
2437 rc = monitor_back_register_overlay( el->el_be, el->el_on, el->el_ndn );
2446 monitor_back_destroy_limbo_entry( tmp, rc );
2449 /* try all, but report error at end */
2454 mi->mi_entry_limbo = NULL;
2461 monitor_back_config(
2469 * eventually, will hold backend specific configuration parameters
2471 return SLAP_CONF_UNKNOWN;
2476 monitor_back_db_config(
2483 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2486 * eventually, will hold database specific configuration parameters
2488 return SLAP_CONF_UNKNOWN;
2493 monitor_back_db_destroy(
2497 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2504 * FIXME: destroys all the data
2506 /* NOTE: mi points to static storage; don't free it */
2508 (void)monitor_cache_destroy( mi );
2510 if ( monitor_subsys ) {
2513 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2514 if ( monitor_subsys[ i ]->mss_destroy ) {
2515 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2518 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2519 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2523 ch_free( monitor_subsys );
2526 if ( mi->mi_entry_limbo ) {
2527 entry_limbo_t *el = mi->mi_entry_limbo;
2530 entry_limbo_t *tmp = el;
2532 monitor_back_destroy_limbo_entry( tmp, 1 );
2536 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2538 be->be_private = NULL;
2543 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2545 /* conditionally define the init_module() function */
2546 SLAP_BACKEND_INIT_MODULE( monitor )
2548 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */