1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 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"
33 #undef INTEGRATE_CORE_SCHEMA
36 * used by many functions to add description to entries
38 * WARNING: be_monitor may change as new databases are added,
39 * so it should not be used outside monitor_back_db_init()
40 * until monitor_back_db_open is called.
42 BackendDB *be_monitor;
44 static struct monitor_subsys_t **monitor_subsys;
45 static int monitor_subsys_opened;
46 static monitor_info_t monitor_info;
51 * the known subsystems are added to the subsystems
52 * array at backend initialization; other subsystems
53 * may be added by calling monitor_back_register_subsys()
54 * before the database is opened (e.g. by other backends
55 * or by overlays or modules).
57 static struct monitor_subsys_t known_monitor_subsys[] = {
59 SLAPD_MONITOR_BACKEND_NAME,
60 BER_BVNULL, BER_BVNULL, BER_BVNULL,
61 { BER_BVC( "This subsystem contains information about available backends." ),
63 MONITOR_F_PERSISTENT_CH,
64 monitor_subsys_backend_init,
70 SLAPD_MONITOR_CONN_NAME,
71 BER_BVNULL, BER_BVNULL, BER_BVNULL,
72 { BER_BVC( "This subsystem contains information about connections." ),
74 MONITOR_F_VOLATILE_CH,
75 monitor_subsys_conn_init,
81 SLAPD_MONITOR_DATABASE_NAME,
82 BER_BVNULL, BER_BVNULL, BER_BVNULL,
83 { BER_BVC( "This subsystem contains information about configured databases." ),
85 MONITOR_F_PERSISTENT_CH,
86 monitor_subsys_database_init,
92 SLAPD_MONITOR_LISTENER_NAME,
93 BER_BVNULL, BER_BVNULL, BER_BVNULL,
94 { BER_BVC( "This subsystem contains information about active listeners." ),
96 MONITOR_F_PERSISTENT_CH,
97 monitor_subsys_listener_init,
103 SLAPD_MONITOR_LOG_NAME,
104 BER_BVNULL, BER_BVNULL, BER_BVNULL,
105 { BER_BVC( "This subsystem contains information about logging." ),
106 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
109 monitor_subsys_log_init,
115 SLAPD_MONITOR_OPS_NAME,
116 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 { BER_BVC( "This subsystem contains information about performed operations." ),
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_ops_init,
126 SLAPD_MONITOR_OVERLAY_NAME,
127 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128 { BER_BVC( "This subsystem contains information about available overlays." ),
130 MONITOR_F_PERSISTENT_CH,
131 monitor_subsys_overlay_init,
137 SLAPD_MONITOR_SASL_NAME,
138 BER_BVNULL, BER_BVNULL, BER_BVNULL,
139 { BER_BVC( "This subsystem contains information about SASL." ),
148 SLAPD_MONITOR_SENT_NAME,
149 BER_BVNULL, BER_BVNULL, BER_BVNULL,
150 { BER_BVC( "This subsystem contains statistics." ),
152 MONITOR_F_PERSISTENT_CH,
153 monitor_subsys_sent_init,
159 SLAPD_MONITOR_THREAD_NAME,
160 BER_BVNULL, BER_BVNULL, BER_BVNULL,
161 { BER_BVC( "This subsystem contains information about threads." ),
163 MONITOR_F_PERSISTENT_CH,
164 monitor_subsys_thread_init,
170 SLAPD_MONITOR_TIME_NAME,
171 BER_BVNULL, BER_BVNULL, BER_BVNULL,
172 { BER_BVC( "This subsystem contains information about time." ),
174 MONITOR_F_PERSISTENT_CH,
175 monitor_subsys_time_init,
181 SLAPD_MONITOR_TLS_NAME,
182 BER_BVNULL, BER_BVNULL, BER_BVNULL,
183 { BER_BVC( "This subsystem contains information about TLS." ),
192 SLAPD_MONITOR_RWW_NAME,
193 BER_BVNULL, BER_BVNULL, BER_BVNULL,
194 { BER_BVC( "This subsystem contains information about read/write waiters." ),
196 MONITOR_F_PERSISTENT_CH,
197 monitor_subsys_rww_init,
206 monitor_back_register_subsys(
207 monitor_subsys_t *ms )
211 if ( monitor_subsys ) {
212 for ( ; monitor_subsys[ i ] != NULL; i++ )
213 /* just count'em */ ;
216 monitor_subsys = ch_realloc( monitor_subsys,
217 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
219 if ( monitor_subsys == NULL ) {
223 monitor_subsys[ i ] = ms;
224 monitor_subsys[ i + 1 ] = NULL;
226 /* if a subsystem is registered __AFTER__ subsystem
227 * initialization (depending on the sequence the databases
228 * are listed in slapd.conf), init it */
229 if ( monitor_subsys_opened ) {
231 /* FIXME: this should only be possible
232 * if be_monitor is already initialized */
233 assert( be_monitor != NULL );
235 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
239 ms->mss_flags |= MONITOR_F_OPENED;
252 typedef struct entry_limbo_t {
256 struct berval el_ndn;
257 struct berval el_nbase;
259 struct berval el_filter;
260 monitor_callback_t *el_cb;
261 monitor_subsys_t *el_mss;
262 unsigned long el_flags;
263 struct entry_limbo_t *el_next;
267 monitor_back_is_configured( void )
269 return be_monitor != NULL;
273 monitor_back_register_entry(
275 monitor_callback_t *cb,
276 monitor_subsys_t *mss,
277 unsigned long flags )
281 if ( be_monitor == NULL ) {
282 Debug( LDAP_DEBUG_ANY,
283 "monitor_back_register_entry(\"%s\"): "
284 "monitor database not configured.\n",
285 e->e_name.bv_val, 0, 0 );
289 mi = ( monitor_info_t * )be_monitor->be_private;
291 assert( mi != NULL );
293 assert( e->e_private == NULL );
295 if ( monitor_subsys_opened ) {
296 Entry *e_parent = NULL,
299 struct berval pdn = BER_BVNULL;
300 monitor_entry_t *mp = NULL,
304 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
306 Debug( LDAP_DEBUG_ANY,
307 "monitor_back_register_entry(\"%s\"): "
309 e->e_name.bv_val, 0, 0 );
310 monitor_cache_release( mi, e_parent );
314 dnParent( &e->e_nname, &pdn );
315 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
316 /* parent does not exist */
317 Debug( LDAP_DEBUG_ANY,
318 "monitor_back_register_entry(\"%s\"): "
319 "parent \"%s\" not found\n",
320 e->e_name.bv_val, pdn.bv_val, 0 );
324 assert( e_parent->e_private != NULL );
325 mp_parent = ( monitor_entry_t * )e_parent->e_private;
327 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
328 /* entry is volatile; cannot append children */
329 Debug( LDAP_DEBUG_ANY,
330 "monitor_back_register_entry(\"%s\"): "
331 "parent \"%s\" is volatile\n",
332 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
337 mp = monitor_entrypriv_create();
339 Debug( LDAP_DEBUG_ANY,
340 "monitor_back_register_entry(\"%s\"): "
341 "monitor_entrypriv_create() failed\n",
342 e->e_name.bv_val, 0, 0 );
347 e_new = entry_dup( e );
348 if ( e_new == NULL ) {
349 Debug( LDAP_DEBUG_ANY,
350 "monitor_back_register_entry(\"%s\"): "
351 "entry_dup() failed\n",
352 e->e_name.bv_val, 0, 0 );
357 e_new->e_private = ( void * )mp;
360 mp->mp_flags = flags;
363 mp->mp_info = mp_parent->mp_info;
364 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
368 ep = &mp_parent->mp_children;
370 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
371 ep = &mp_parent->mp_next;
375 if ( monitor_cache_add( mi, e_new ) ) {
376 Debug( LDAP_DEBUG_ANY,
377 "monitor_back_register_entry(\"%s\"): "
378 "unable to add entry\n",
379 e->e_name.bv_val, 0, 0 );
390 e_new->e_private = NULL;
396 monitor_cache_release( mi, e_parent );
400 entry_limbo_t **elpp, el = { 0 };
402 el.el_type = LIMBO_ENTRY;
404 el.el_e = entry_dup( e );
405 if ( el.el_e == NULL ) {
406 Debug( LDAP_DEBUG_ANY,
407 "monitor_back_register_entry(\"%s\"): "
408 "entry_dup() failed\n",
409 e->e_name.bv_val, 0, 0 );
417 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
419 elpp = &(*elpp)->el_next )
422 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
423 if ( *elpp == NULL ) {
424 el.el_e->e_private = NULL;
425 entry_free( el.el_e );
437 monitor_back_register_entry_parent(
439 monitor_callback_t *cb,
440 monitor_subsys_t *mss,
442 struct berval *nbase,
444 struct berval *filter )
447 struct berval ndn = BER_BVNULL;
449 if ( be_monitor == NULL ) {
450 Debug( LDAP_DEBUG_ANY,
451 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
452 "monitor database not configured.\n",
453 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
454 ldap_pvt_scope2str( scope ),
455 BER_BVISNULL( filter ) ? "" : filter->bv_val );
459 mi = ( monitor_info_t * )be_monitor->be_private;
461 assert( mi != NULL );
463 assert( e->e_private == NULL );
465 if ( BER_BVISNULL( filter ) ) {
467 Debug( LDAP_DEBUG_ANY,
468 "monitor_back_register_entry_parent(\"\"): "
469 "need a valid filter\n",
474 if ( monitor_subsys_opened ) {
475 Entry *e_parent = NULL,
478 struct berval e_name = BER_BVNULL,
479 e_nname = BER_BVNULL;
480 monitor_entry_t *mp = NULL,
484 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
485 /* entry does not exist */
486 Debug( LDAP_DEBUG_ANY,
487 "monitor_back_register_entry_parent(\"\"): "
488 "base=\"%s\" scope=%d filter=\"%s\": "
489 "unable to find entry\n",
490 nbase->bv_val ? nbase->bv_val : "\"\"",
491 scope, filter->bv_val );
495 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
496 /* entry does not exist */
497 Debug( LDAP_DEBUG_ANY,
498 "monitor_back_register_entry_parent(\"%s\"): "
499 "parent entry does not exist\n",
505 assert( e_parent->e_private != NULL );
506 mp_parent = ( monitor_entry_t * )e_parent->e_private;
508 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
509 /* entry is volatile; cannot append callback */
510 Debug( LDAP_DEBUG_ANY,
511 "monitor_back_register_entry_parent(\"%s\"): "
512 "entry is volatile\n",
513 e_parent->e_name.bv_val, 0, 0 );
518 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
519 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
521 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
522 /* entry already exists */
523 Debug( LDAP_DEBUG_ANY,
524 "monitor_back_register_entry_parent(\"%s\"): "
525 "entry already exists\n",
526 e_name.bv_val, 0, 0 );
527 monitor_cache_release( mi, e_new );
533 mp = monitor_entrypriv_create();
535 Debug( LDAP_DEBUG_ANY,
536 "monitor_back_register_entry_parent(\"%s\"): "
537 "monitor_entrypriv_create() failed\n",
538 e->e_name.bv_val, 0, 0 );
543 e_new = entry_dup( e );
544 if ( e_new == NULL ) {
545 Debug( LDAP_DEBUG_ANY,
546 "monitor_back_register_entry(\"%s\"): "
547 "entry_dup() failed\n",
548 e->e_name.bv_val, 0, 0 );
552 ch_free( e_new->e_name.bv_val );
553 ch_free( e_new->e_nname.bv_val );
554 e_new->e_name = e_name;
555 e_new->e_nname = e_nname;
557 e_new->e_private = ( void * )mp;
560 mp->mp_flags = flags;
563 mp->mp_info = mp_parent->mp_info;
564 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
568 ep = &mp_parent->mp_children;
570 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
571 ep = &mp_parent->mp_next;
575 if ( monitor_cache_add( mi, e_new ) ) {
576 Debug( LDAP_DEBUG_ANY,
577 "monitor_back_register_entry(\"%s\"): "
578 "unable to add entry\n",
579 e->e_name.bv_val, 0, 0 );
585 if ( !BER_BVISNULL( &ndn ) ) {
586 ch_free( ndn.bv_val );
594 e_new->e_private = NULL;
600 monitor_cache_release( mi, e_parent );
604 entry_limbo_t **elpp = NULL, el = { 0 };
606 el.el_type = LIMBO_ENTRY_PARENT;
608 el.el_e = entry_dup( e );
609 if ( el.el_e == NULL ) {
610 Debug( LDAP_DEBUG_ANY,
611 "monitor_back_register_entry(\"%s\"): "
612 "entry_dup() failed\n",
613 e->e_name.bv_val, 0, 0 );
617 if ( !BER_BVISNULL( nbase ) ) {
618 ber_dupbv( &el.el_nbase, nbase );
622 if ( !BER_BVISNULL( filter ) ) {
623 ber_dupbv( &el.el_filter, filter );
630 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
632 elpp = &(*elpp)->el_next )
635 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
636 if ( *elpp == NULL ) {
641 if ( *elpp != NULL ) {
646 if ( !BER_BVISNULL( &el.el_filter ) ) {
647 ch_free( el.el_filter.bv_val );
649 if ( !BER_BVISNULL( &el.el_nbase ) ) {
650 ch_free( el.el_nbase.bv_val );
652 entry_free( el.el_e );
661 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
663 if ( rs->sr_type == REP_SEARCH ) {
664 struct berval *ndn = op->o_callback->sc_private;
666 if ( !BER_BVISNULL( ndn ) ) {
667 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
668 ch_free( ndn->bv_val );
673 ber_dupbv( ndn, &rs->sr_entry->e_nname );
681 struct berval *nbase,
683 struct berval *filter,
686 Connection conn = { 0 };
687 OperationBuffer opbuf;
689 SlapReply rs = { 0 };
690 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
695 if ( be_monitor == NULL ) {
699 op = (Operation *) &opbuf;
700 connection_fake_init( &conn, op, &conn );
702 op->o_tag = LDAP_REQ_SEARCH;
704 /* use global malloc for now */
705 if ( op->o_tmpmemctx ) {
706 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
707 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
708 op->o_tmpmemctx = NULL;
710 op->o_tmpmfuncs = &ch_mfuncs;
712 op->o_bd = be_monitor;
713 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
714 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
716 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
720 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
721 op->o_tmpmemctx ) ) {
726 op->o_callback = &cb;
727 cb.sc_private = (void *)ndn;
729 op->ors_scope = scope;
730 op->ors_filter = str2filter_x( op, filter->bv_val );
731 if ( op->ors_filter == NULL ) {
735 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
736 op->ors_attrs = slap_anlist_no_attrs;
737 op->ors_attrsonly = 0;
738 op->ors_tlimit = SLAP_NO_LIMIT;
740 op->ors_limit = NULL;
741 op->ors_deref = LDAP_DEREF_NEVER;
744 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
746 op->o_dn = be_monitor->be_rootdn;
747 op->o_ndn = be_monitor->be_rootndn;
749 rc = op->o_bd->be_search( op, &rs );
752 if ( op->ors_filter != NULL ) {
753 filter_free_x( op, op->ors_filter );
755 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
756 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
758 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
759 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
761 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
762 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
769 switch ( rs.sr_err ) {
771 if ( BER_BVISNULL( ndn ) ) {
776 case LDAP_SIZELIMIT_EXCEEDED:
778 if ( !BER_BVISNULL( ndn ) ) {
779 ber_memfree( ndn->bv_val );
790 monitor_back_register_entry_attrs(
791 struct berval *ndn_in,
793 monitor_callback_t *cb,
794 struct berval *nbase,
796 struct berval *filter )
799 struct berval ndn = BER_BVNULL;
800 char *fname = ( a == NULL ? "callback" : "attrs" );
802 if ( be_monitor == NULL ) {
803 char buf[ SLAP_TEXT_BUFLEN ];
805 snprintf( buf, sizeof( buf ),
806 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
807 "monitor database not configured.\n",
809 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
810 ldap_pvt_scope2str( scope ),
811 BER_BVISNULL( filter ) ? "" : filter->bv_val );
812 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
817 mi = ( monitor_info_t * )be_monitor->be_private;
819 assert( mi != NULL );
821 if ( ndn_in != NULL ) {
825 if ( a == NULL && cb == NULL ) {
830 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
831 && BER_BVISNULL( filter ) )
834 Debug( LDAP_DEBUG_ANY,
835 "monitor_back_register_entry_%s(\"\"): "
836 "need a valid filter\n",
841 if ( monitor_subsys_opened ) {
843 Attribute **atp = NULL;
844 monitor_entry_t *mp = NULL;
845 monitor_callback_t **mcp = NULL;
849 if ( BER_BVISNULL( &ndn ) ) {
850 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
851 char buf[ SLAP_TEXT_BUFLEN ];
853 snprintf( buf, sizeof( buf ),
854 "monitor_back_register_entry_%s(\"\"): "
855 "base=\"%s\" scope=%d filter=\"%s\": "
856 "unable to find entry\n",
858 nbase->bv_val ? nbase->bv_val : "\"\"",
859 scope, filter->bv_val );
861 /* entry does not exist */
862 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
869 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
870 /* entry does not exist */
871 Debug( LDAP_DEBUG_ANY,
872 "monitor_back_register_entry_%s(\"%s\"): "
873 "entry does not exist\n",
874 fname, ndn.bv_val, 0 );
879 assert( e->e_private != NULL );
880 mp = ( monitor_entry_t * )e->e_private;
882 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
883 /* entry is volatile; cannot append callback */
884 Debug( LDAP_DEBUG_ANY,
885 "monitor_back_register_entry_%s(\"%s\"): "
886 "entry is volatile\n",
887 fname, e->e_name.bv_val, 0 );
893 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
894 /* just get to last */ ;
896 for ( ; a != NULL; a = a->a_next ) {
897 assert( a->a_desc != NULL );
898 assert( a->a_vals != NULL );
900 if ( attr_find( e->e_attrs, a->a_desc ) ) {
901 attr_merge( e, a->a_desc, a->a_vals,
902 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
905 *atp = attr_dup( a );
906 if ( *atp == NULL ) {
907 Debug( LDAP_DEBUG_ANY,
908 "monitor_back_register_entry_%s(\"%s\"): "
909 "attr_dup() failed\n",
910 fname, e->e_name.bv_val, 0 );
914 atp = &(*atp)->a_next;
920 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
923 /* NOTE: we do not clear cb->mc_next, so this function
924 * can be used to append a list of callbacks */
937 ber_memfree( ndn.bv_val );
941 monitor_cache_release( mi, e );
945 entry_limbo_t **elpp, el = { 0 };
947 el.el_type = LIMBO_ATTRS;
948 if ( !BER_BVISNULL( &ndn ) ) {
949 ber_dupbv( &el.el_ndn, &ndn );
951 if ( !BER_BVISNULL( nbase ) ) {
952 ber_dupbv( &el.el_nbase, nbase);
955 if ( !BER_BVISNULL( filter ) ) {
956 ber_dupbv( &el.el_filter, filter );
959 el.el_a = attrs_dup( a );
962 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
964 elpp = &(*elpp)->el_next )
967 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
968 if ( *elpp == NULL ) {
969 el.el_e->e_private = NULL;
970 entry_free( el.el_e );
975 if ( *elpp != NULL ) {
980 if ( !BER_BVISNULL( &el.el_filter ) ) {
981 ch_free( el.el_filter.bv_val );
983 if ( el.el_a != NULL ) {
984 attrs_free( el.el_a );
986 if ( !BER_BVISNULL( &el.el_nbase ) ) {
987 ch_free( &el.el_nbase.bv_val );
989 if ( !BER_BVISNULL( &el.el_ndn ) ) {
990 ch_free( el.el_ndn.bv_val );
1000 monitor_back_register_entry_callback(
1002 monitor_callback_t *cb,
1003 struct berval *nbase,
1005 struct berval *filter )
1007 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1008 nbase, scope, filter );
1012 * TODO: add corresponding calls to remove installed callbacks, entries
1013 * and so, in case the entity that installed them is removed (e.g. a
1014 * database, via back-config)
1017 monitor_back_unregister_entry(
1018 struct berval *ndn )
1022 if ( be_monitor == NULL ) {
1023 Debug( LDAP_DEBUG_ANY,
1024 "monitor_back_unregister_entry(\"%s\"): "
1025 "monitor database not configured.\n",
1026 ndn->bv_val, 0, 0 );
1031 /* entry will be regularly freed, and resources released
1032 * according to callbacks */
1033 if ( slapd_shutdown ) {
1037 mi = ( monitor_info_t * )be_monitor->be_private;
1039 assert( mi != NULL );
1041 if ( monitor_subsys_opened ) {
1043 monitor_entry_t *mp = NULL;
1044 monitor_callback_t *cb = NULL;
1046 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1047 /* entry does not exist */
1048 Debug( LDAP_DEBUG_ANY,
1049 "monitor_back_unregister_entry(\"%s\"): "
1050 "entry removal failed.\n",
1051 ndn->bv_val, 0, 0 );
1055 mp = (monitor_entry_t *)e->e_private;
1056 assert( mp != NULL );
1058 for ( cb = mp->mp_cb; cb != NULL; ) {
1059 monitor_callback_t *next = cb->mc_next;
1061 if ( cb->mc_free ) {
1062 (void)cb->mc_free( e, cb->mc_private );
1070 e->e_private = NULL;
1074 entry_limbo_t **elpp;
1076 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1078 elpp = &(*elpp)->el_next )
1080 entry_limbo_t *elp = *elpp;
1082 if ( elp->el_type == LIMBO_ENTRY
1083 && dn_match( ndn, &elp->el_e->e_nname ) )
1085 monitor_callback_t *cb, *next;
1087 for ( cb = elp->el_cb; cb; cb = next ) {
1088 /* FIXME: call callbacks? */
1092 assert( elp->el_e != NULL );
1093 elp->el_e->e_private = NULL;
1094 entry_free( elp->el_e );
1095 *elpp = elp->el_next;
1102 if ( elpp != NULL ) {
1103 /* not found! where did it go? */
1112 monitor_back_unregister_entry_parent(
1113 struct berval *nrdn,
1114 monitor_callback_t *target_cb,
1115 struct berval *nbase,
1117 struct berval *filter )
1120 struct berval ndn = BER_BVNULL;
1122 if ( be_monitor == NULL ) {
1123 Debug( LDAP_DEBUG_ANY,
1124 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1125 "monitor database not configured.\n",
1126 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1127 ldap_pvt_scope2str( scope ),
1128 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1133 /* entry will be regularly freed, and resources released
1134 * according to callbacks */
1135 if ( slapd_shutdown ) {
1139 mi = ( monitor_info_t * )be_monitor->be_private;
1141 assert( mi != NULL );
1143 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1144 && BER_BVISNULL( filter ) )
1147 Debug( LDAP_DEBUG_ANY,
1148 "monitor_back_unregister_entry_parent(\"\"): "
1149 "need a valid filter\n",
1154 if ( monitor_subsys_opened ) {
1156 monitor_entry_t *mp = NULL;
1158 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1159 /* entry does not exist */
1160 Debug( LDAP_DEBUG_ANY,
1161 "monitor_back_unregister_entry_parent(\"\"): "
1162 "base=\"%s\" scope=%s filter=\"%s\": "
1163 "unable to find entry\n",
1164 nbase->bv_val ? nbase->bv_val : "\"\"",
1165 ldap_pvt_scope2str( scope ),
1170 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1171 /* entry does not exist */
1172 Debug( LDAP_DEBUG_ANY,
1173 "monitor_back_unregister_entry(\"%s\"): "
1174 "entry removal failed.\n",
1176 ber_memfree( ndn.bv_val );
1179 ber_memfree( ndn.bv_val );
1181 mp = (monitor_entry_t *)e->e_private;
1182 assert( mp != NULL );
1184 if ( target_cb != NULL ) {
1185 monitor_callback_t **cbp;
1187 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1188 if ( *cbp == target_cb ) {
1189 if ( (*cbp)->mc_free ) {
1190 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1192 *cbp = (*cbp)->mc_next;
1193 ch_free( target_cb );
1201 e->e_private = NULL;
1205 entry_limbo_t **elpp;
1207 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1209 elpp = &(*elpp)->el_next )
1211 entry_limbo_t *elp = *elpp;
1213 if ( elp->el_type == LIMBO_ENTRY_PARENT
1214 && dn_match( nrdn, &elp->el_e->e_nname )
1215 && dn_match( nbase, &elp->el_nbase )
1216 && scope == elp->el_scope
1217 && bvmatch( filter, &elp->el_filter ) )
1219 monitor_callback_t *cb, *next;
1221 for ( cb = elp->el_cb; cb; cb = next ) {
1222 /* FIXME: call callbacks? */
1226 assert( elp->el_e != NULL );
1227 elp->el_e->e_private = NULL;
1228 entry_free( elp->el_e );
1229 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1230 ch_free( elp->el_nbase.bv_val );
1232 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1233 ch_free( elp->el_filter.bv_val );
1235 *elpp = elp->el_next;
1242 if ( elpp != NULL ) {
1243 /* not found! where did it go? */
1252 monitor_back_unregister_entry_attrs(
1253 struct berval *ndn_in,
1254 Attribute *target_a,
1255 monitor_callback_t *target_cb,
1256 struct berval *nbase,
1258 struct berval *filter )
1261 struct berval ndn = BER_BVNULL;
1262 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1264 if ( be_monitor == NULL ) {
1265 char buf[ SLAP_TEXT_BUFLEN ];
1267 snprintf( buf, sizeof( buf ),
1268 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1269 "monitor database not configured.\n",
1271 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1272 ldap_pvt_scope2str( scope ),
1273 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1274 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1279 /* entry will be regularly freed, and resources released
1280 * according to callbacks */
1281 if ( slapd_shutdown ) {
1285 mi = ( monitor_info_t * )be_monitor->be_private;
1287 assert( mi != NULL );
1289 if ( ndn_in != NULL ) {
1293 if ( target_a == NULL && target_cb == NULL ) {
1298 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1299 && BER_BVISNULL( filter ) )
1302 Debug( LDAP_DEBUG_ANY,
1303 "monitor_back_unregister_entry_%s(\"\"): "
1304 "need a valid filter\n",
1309 if ( monitor_subsys_opened ) {
1311 monitor_entry_t *mp = NULL;
1314 if ( BER_BVISNULL( &ndn ) ) {
1315 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1316 char buf[ SLAP_TEXT_BUFLEN ];
1318 snprintf( buf, sizeof( buf ),
1319 "monitor_back_unregister_entry_%s(\"\"): "
1320 "base=\"%s\" scope=%d filter=\"%s\": "
1321 "unable to find entry\n",
1323 nbase->bv_val ? nbase->bv_val : "\"\"",
1324 scope, filter->bv_val );
1326 /* entry does not exist */
1327 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1334 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1335 /* entry does not exist */
1336 Debug( LDAP_DEBUG_ANY,
1337 "monitor_back_unregister_entry(\"%s\"): "
1338 "entry removal failed.\n",
1343 mp = (monitor_entry_t *)e->e_private;
1344 assert( mp != NULL );
1346 if ( target_cb != NULL ) {
1347 monitor_callback_t **cbp;
1349 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1350 if ( *cbp == target_cb ) {
1351 if ( (*cbp)->mc_free ) {
1352 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1354 *cbp = (*cbp)->mc_next;
1355 ch_free( target_cb );
1361 if ( target_a != NULL ) {
1364 for ( a = target_a; a != NULL; a = a->a_next ) {
1365 Modification mod = { 0 };
1367 char textbuf[ SLAP_TEXT_BUFLEN ];
1369 mod.sm_op = LDAP_MOD_DELETE;
1370 mod.sm_desc = a->a_desc;
1371 mod.sm_values = a->a_vals;
1372 mod.sm_nvalues = a->a_nvals;
1374 (void)modify_delete_values( e, &mod, 1,
1375 &text, textbuf, sizeof( textbuf ) );
1380 ber_memfree( ndn.bv_val );
1384 monitor_cache_release( mi, e );
1388 entry_limbo_t **elpp;
1390 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1392 elpp = &(*elpp)->el_next )
1394 entry_limbo_t *elp = *elpp;
1396 if ( elp->el_type == LIMBO_ATTRS
1397 && dn_match( nbase, &elp->el_nbase )
1398 && scope == elp->el_scope
1399 && bvmatch( filter, &elp->el_filter ) )
1401 monitor_callback_t *cb, *next;
1403 for ( cb = elp->el_cb; cb; cb = next ) {
1404 /* FIXME: call callbacks? */
1408 assert( elp->el_e == NULL );
1409 if ( elp->el_a != NULL ) {
1410 attrs_free( elp->el_a );
1412 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1413 ch_free( elp->el_nbase.bv_val );
1415 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1416 ch_free( elp->el_filter.bv_val );
1418 *elpp = elp->el_next;
1425 if ( elpp != NULL ) {
1426 /* not found! where did it go? */
1435 monitor_back_unregister_entry_callback(
1437 monitor_callback_t *cb,
1438 struct berval *nbase,
1440 struct berval *filter )
1442 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1443 * unregister the callback; if a is not null, unregister the
1444 * given attrs. In any case, call cb->cb_free */
1445 return monitor_back_unregister_entry_attrs( ndn,
1446 NULL, cb, nbase, scope, filter );
1450 monitor_back_get_subsys( const char *name )
1452 if ( monitor_subsys != NULL ) {
1455 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1456 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1457 return monitor_subsys[ i ];
1466 monitor_back_get_subsys_by_dn(
1470 if ( monitor_subsys != NULL ) {
1474 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1475 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1476 return monitor_subsys[ i ];
1481 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1482 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1483 return monitor_subsys[ i ];
1493 monitor_back_initialize(
1496 static char *controls[] = {
1497 LDAP_CONTROL_MANAGEDSAIT,
1501 static ConfigTable monitorcfg[] = {
1502 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1503 NULL, NULL, NULL, NULL }
1506 static ConfigOCs monitorocs[] = {
1507 { "( OLcfgDbOc:4.1 "
1508 "NAME 'olcMonitorConfig' "
1509 "DESC 'Monitor backend configuration' "
1510 "SUP olcDatabaseConfig "
1512 Cft_Database, monitorcfg },
1522 { "monitor", "( 1.3.6.1.4.1.4203.666.3.16.1 "
1524 "DESC 'OpenLDAP system monitoring' "
1525 "SUP top STRUCTURAL "
1534 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1535 offsetof(monitor_info_t, mi_oc_monitor) },
1536 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.16.2 "
1537 "NAME 'monitorServer' "
1538 "DESC 'Server monitoring root entry' "
1539 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1540 offsetof(monitor_info_t, mi_oc_monitorServer) },
1541 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.16.3 "
1542 "NAME 'monitorContainer' "
1543 "DESC 'monitor container class' "
1544 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1545 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1546 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.16.4 "
1547 "NAME 'monitorCounterObject' "
1548 "DESC 'monitor counter class' "
1549 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1550 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1551 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.16.5 "
1552 "NAME 'monitorOperation' "
1553 "DESC 'monitor operation class' "
1554 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1555 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1556 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.16.6 "
1557 "NAME 'monitorConnection' "
1558 "DESC 'monitor connection class' "
1559 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1560 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1561 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.16.7 "
1562 "NAME 'managedObject' "
1563 "DESC 'monitor managed entity class' "
1564 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1565 offsetof(monitor_info_t, mi_oc_managedObject) },
1566 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.16.8 "
1567 "NAME 'monitoredObject' "
1568 "DESC 'monitor monitored entity class' "
1569 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1570 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1571 { NULL, NULL, 0, -1 }
1573 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.55.1 "
1574 "NAME 'monitoredInfo' "
1575 "DESC 'monitored info' "
1577 "EQUALITY caseIgnoreMatch "
1578 "SUBSTR caseIgnoreSubstringsMatch "
1579 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1580 "NO-USER-MODIFICATION "
1581 "USAGE directoryOperation )", SLAP_AT_HIDE,
1582 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1583 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.55.2 "
1584 "NAME 'managedInfo' "
1585 "DESC 'monitor managed info' "
1586 "SUP name )", SLAP_AT_HIDE,
1587 offsetof(monitor_info_t, mi_ad_managedInfo) },
1588 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.55.3 "
1589 "NAME 'monitorCounter' "
1590 "DESC 'monitor counter' "
1591 "EQUALITY integerMatch "
1592 "ORDERING integerOrderingMatch "
1593 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1594 "NO-USER-MODIFICATION "
1595 "USAGE directoryOperation )", SLAP_AT_HIDE,
1596 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1597 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.55.4 "
1598 "NAME 'monitorOpCompleted' "
1599 "DESC 'monitor completed operations' "
1600 "SUP monitorCounter "
1601 "NO-USER-MODIFICATION "
1602 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1603 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1604 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.55.5 "
1605 "NAME 'monitorOpInitiated' "
1606 "DESC 'monitor initiated operations' "
1607 "SUP monitorCounter "
1608 "NO-USER-MODIFICATION "
1609 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1610 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1611 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.55.6 "
1612 "NAME 'monitorConnectionNumber' "
1613 "DESC 'monitor connection number' "
1614 "SUP monitorCounter "
1615 "NO-USER-MODIFICATION "
1616 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1617 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1618 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.55.7 "
1619 "NAME 'monitorConnectionAuthzDN' "
1620 "DESC 'monitor connection authorization DN' "
1621 /* "SUP distinguishedName " */
1622 "EQUALITY distinguishedNameMatch "
1623 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1624 "NO-USER-MODIFICATION "
1625 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1626 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1627 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.55.8 "
1628 "NAME 'monitorConnectionLocalAddress' "
1629 "DESC 'monitor connection local address' "
1630 "SUP monitoredInfo "
1631 "NO-USER-MODIFICATION "
1632 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1633 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1634 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.55.9 "
1635 "NAME 'monitorConnectionPeerAddress' "
1636 "DESC 'monitor connection peer address' "
1637 "SUP monitoredInfo "
1638 "NO-USER-MODIFICATION "
1639 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1640 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1641 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.55.10 "
1642 "NAME 'monitorTimestamp' "
1643 "DESC 'monitor timestamp' "
1644 "EQUALITY generalizedTimeMatch "
1645 "ORDERING generalizedTimeOrderingMatch "
1646 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1648 "NO-USER-MODIFICATION "
1649 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1650 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1651 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.55.11 "
1652 "NAME 'monitorOverlay' "
1653 "DESC 'name of overlays defined for a given database' "
1654 "SUP monitoredInfo "
1655 "NO-USER-MODIFICATION "
1656 "USAGE directoryOperation )", SLAP_AT_HIDE,
1657 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1658 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.55.12 "
1660 "DESC 'read/write status of a given database' "
1661 "EQUALITY booleanMatch "
1662 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1664 "USAGE directoryOperation )", SLAP_AT_HIDE,
1665 offsetof(monitor_info_t, mi_ad_readOnly) },
1666 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.55.13 "
1667 "NAME 'restrictedOperation' "
1668 "DESC 'name of restricted operation for a given database' "
1669 "SUP managedInfo )", SLAP_AT_HIDE,
1670 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1671 { "monitorConnectionProtocol", "( 1.3.6.1.4.1.4203.666.1.55.14 "
1672 "NAME 'monitorConnectionProtocol' "
1673 "DESC 'monitor connection protocol' "
1674 "SUP monitoredInfo "
1675 "NO-USER-MODIFICATION "
1676 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1677 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1678 { "monitorConnectionOpsReceived", "( 1.3.6.1.4.1.4203.666.1.55.15 "
1679 "NAME 'monitorConnectionOpsReceived' "
1680 "DESC 'monitor number of operations received by the connection' "
1681 "SUP monitorCounter "
1682 "NO-USER-MODIFICATION "
1683 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1684 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1685 { "monitorConnectionOpsExecuting", "( 1.3.6.1.4.1.4203.666.1.55.16 "
1686 "NAME 'monitorConnectionOpsExecuting' "
1687 "DESC 'monitor number of operations in execution within the connection' "
1688 "SUP monitorCounter "
1689 "NO-USER-MODIFICATION "
1690 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1691 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1692 { "monitorConnectionOpsPending", "( 1.3.6.1.4.1.4203.666.1.55.17 "
1693 "NAME 'monitorConnectionOpsPending' "
1694 "DESC 'monitor number of pending operations within the connection' "
1695 "SUP monitorCounter "
1696 "NO-USER-MODIFICATION "
1697 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1698 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1699 { "monitorConnectionOpsCompleted", "( 1.3.6.1.4.1.4203.666.1.55.18 "
1700 "NAME 'monitorConnectionOpsCompleted' "
1701 "DESC 'monitor number of operations completed within the connection' "
1702 "SUP monitorCounter "
1703 "NO-USER-MODIFICATION "
1704 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1705 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1706 { "monitorConnectionGet", "( 1.3.6.1.4.1.4203.666.1.55.19 "
1707 "NAME 'monitorConnectionGet' "
1708 "DESC 'number of times connection_get() was called so far' "
1709 "SUP monitorCounter "
1710 "NO-USER-MODIFICATION "
1711 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1712 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1713 { "monitorConnectionRead", "( 1.3.6.1.4.1.4203.666.1.55.20 "
1714 "NAME 'monitorConnectionRead' "
1715 "DESC 'number of times connection_read() was called so far' "
1716 "SUP monitorCounter "
1717 "NO-USER-MODIFICATION "
1718 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1719 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1720 { "monitorConnectionWrite", "( 1.3.6.1.4.1.4203.666.1.55.21 "
1721 "NAME 'monitorConnectionWrite' "
1722 "DESC 'number of times connection_write() was called so far' "
1723 "SUP monitorCounter "
1724 "NO-USER-MODIFICATION "
1725 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1726 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1727 { "monitorConnectionMask", "( 1.3.6.1.4.1.4203.666.1.55.22 "
1728 "NAME 'monitorConnectionMask' "
1729 "DESC 'monitor connection mask' "
1730 "SUP monitoredInfo "
1731 "NO-USER-MODIFICATION "
1732 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1733 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1734 { "monitorConnectionListener", "( 1.3.6.1.4.1.4203.666.1.55.23 "
1735 "NAME 'monitorConnectionListener' "
1736 "DESC 'monitor connection listener' "
1737 "SUP monitoredInfo "
1738 "NO-USER-MODIFICATION "
1739 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1740 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1741 { "monitorConnectionPeerDomain", "( 1.3.6.1.4.1.4203.666.1.55.24 "
1742 "NAME 'monitorConnectionPeerDomain' "
1743 "DESC 'monitor connection peer domain' "
1744 "SUP monitoredInfo "
1745 "NO-USER-MODIFICATION "
1746 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1747 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1748 { "monitorConnectionStartTime", "( 1.3.6.1.4.1.4203.666.1.55.25 "
1749 "NAME 'monitorConnectionStartTime' "
1750 "DESC 'monitor connection start time' "
1751 "SUP monitorTimestamp "
1753 "NO-USER-MODIFICATION "
1754 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1755 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1756 { "monitorConnectionActivityTime", "( 1.3.6.1.4.1.4203.666.1.55.26 "
1757 "NAME 'monitorConnectionActivityTime' "
1758 "DESC 'monitor connection activity time' "
1759 "SUP monitorTimestamp "
1761 "NO-USER-MODIFICATION "
1762 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1763 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1764 { "monitorIsShadow", "( 1.3.6.1.4.1.4203.666.1.55.27 "
1765 "NAME 'monitorIsShadow' "
1766 "DESC 'TRUE if the database is shadow' "
1767 "EQUALITY booleanMatch "
1768 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1770 "USAGE directoryOperation )", SLAP_AT_HIDE,
1771 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1772 { "monitorUpdateRef", "( 1.3.6.1.4.1.4203.666.1.55.28 "
1773 "NAME 'monitorUpdateRef' "
1774 "DESC 'update referral for shadow databases' "
1775 "SUP monitoredInfo "
1777 "USAGE directoryOperation )", SLAP_AT_HIDE,
1778 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1779 { "monitorRuntimeConfig", "( 1.3.6.1.4.1.4203.666.1.55.29 "
1780 "NAME 'monitorRuntimeConfig' "
1781 "DESC 'TRUE if component allows runtime configuration' "
1782 "EQUALITY booleanMatch "
1783 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1785 "USAGE directoryOperation )", SLAP_AT_HIDE,
1786 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1787 { NULL, NULL, 0, -1 }
1794 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1795 { "olmSubSystemAttributes", "olmAttributes:0" },
1796 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1797 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1799 /* for example, back-bdb specific attrs
1800 * are in "olmDatabaseAttributes:1"
1802 * NOTE: developers, please record here OID assignments
1803 * for other modules */
1805 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1806 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1807 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1808 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1810 /* for example, back-bdb specific objectClasses
1811 * are in "olmDatabaseObjectClasses:1"
1813 * NOTE: developers, please record here OID assignments
1814 * for other modules */
1821 monitor_info_t *mi = &monitor_info;
1823 for ( i = 0; s_oid[ i ].name; i++ ) {
1826 argv[ 0 ] = "monitor";
1827 argv[ 1 ] = s_oid[ i ].name;
1828 argv[ 2 ] = s_oid[ i ].oid;
1830 if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) {
1831 Debug( LDAP_DEBUG_ANY,
1832 "monitor_back_initialize: unable to add "
1833 "objectIdentifier \"%s=%s\"\n",
1834 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1839 /* schema integration */
1840 for ( i = 0; mat[ i ].name; i++ ) {
1841 LDAPAttributeType *at;
1844 AttributeDescription **ad;
1846 at = ldap_str2attributetype( mat[ i ].schema, &code,
1847 &err, LDAP_SCHEMA_ALLOW_ALL );
1849 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1850 "in AttributeType \"%s\" %s before %s\n",
1851 mat[ i ].name, ldap_scherr2str(code), err );
1855 if ( at->at_oid == NULL ) {
1856 ldap_attributetype_free(at);
1857 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1858 "null OID for attributeType \"%s\"\n",
1859 mat[ i ].name, 0, 0 );
1863 code = at_add(at, 0, NULL, &err);
1865 ldap_attributetype_free(at);
1866 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1867 "%s in attributeType \"%s\"\n",
1868 scherr2str(code), mat[ i ].name, 0 );
1873 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1875 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1876 Debug( LDAP_DEBUG_ANY,
1877 "monitor_back_db_init: %s\n", text, 0, 0 );
1881 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1884 for ( i = 0; moc[ i ].name; i++ ) {
1885 LDAPObjectClass *oc;
1890 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1891 LDAP_SCHEMA_ALLOW_ALL );
1893 Debug( LDAP_DEBUG_ANY,
1894 "unable to parse monitor objectclass \"%s\": "
1895 "%s before %s\n" , moc[ i ].name,
1896 ldap_scherr2str(code), err );
1900 if ( oc->oc_oid == NULL ) {
1901 ldap_objectclass_free(oc);
1902 Debug( LDAP_DEBUG_ANY,
1903 "objectclass \"%s\" has no OID\n" ,
1904 moc[ i ].name, 0, 0 );
1908 code = oc_add(oc, 0, NULL, &err);
1910 ldap_objectclass_free(oc);
1911 Debug( LDAP_DEBUG_ANY,
1912 "objectclass \"%s\": %s \"%s\"\n" ,
1913 moc[ i ].name, scherr2str(code), err );
1918 Oc = oc_find( moc[ i ].name );
1920 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1921 "unable to find objectClass %s "
1922 "(just added)\n", moc[ i ].name, 0, 0 );
1926 Oc->soc_flags |= moc[ i ].flags;
1928 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1931 bi->bi_controls = controls;
1935 bi->bi_config = monitor_back_config;
1939 bi->bi_db_init = monitor_back_db_init;
1941 bi->bi_db_config = monitor_back_db_config;
1943 bi->bi_db_open = monitor_back_db_open;
1944 bi->bi_db_close = 0;
1945 bi->bi_db_destroy = monitor_back_db_destroy;
1947 bi->bi_op_bind = monitor_back_bind;
1948 bi->bi_op_unbind = 0;
1949 bi->bi_op_search = monitor_back_search;
1950 bi->bi_op_compare = monitor_back_compare;
1951 bi->bi_op_modify = monitor_back_modify;
1952 bi->bi_op_modrdn = 0;
1954 bi->bi_op_delete = 0;
1955 bi->bi_op_abandon = 0;
1957 bi->bi_extended = 0;
1959 bi->bi_entry_release_rw = 0;
1960 bi->bi_chk_referrals = 0;
1961 bi->bi_operational = monitor_back_operational;
1964 * hooks for slap tools
1966 bi->bi_tool_entry_open = 0;
1967 bi->bi_tool_entry_close = 0;
1968 bi->bi_tool_entry_first = 0;
1969 bi->bi_tool_entry_next = 0;
1970 bi->bi_tool_entry_get = 0;
1971 bi->bi_tool_entry_put = 0;
1972 bi->bi_tool_entry_reindex = 0;
1973 bi->bi_tool_sync = 0;
1974 bi->bi_tool_dn2id_get = 0;
1975 bi->bi_tool_id2entry_get = 0;
1976 bi->bi_tool_entry_modify = 0;
1978 bi->bi_connection_init = 0;
1979 bi->bi_connection_destroy = 0;
1982 * configuration objectClasses (fake)
1984 bi->bi_cf_ocs = monitorocs;
1986 rc = config_register_schema( monitorcfg, monitorocs );
1995 monitor_back_db_init(
1999 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
2004 monitor_subsys_t *ms;
2009 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2010 if ( monitor_back_register_subsys( ms ) ) {
2016 * database monitor can be defined once only
2018 if ( be_monitor != NULL ) {
2019 Debug( LDAP_DEBUG_ANY,
2020 "only one monitor database is allowed\n", 0, 0, 0 );
2025 /* indicate system schema supported */
2026 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2028 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2029 if( rc != LDAP_SUCCESS ) {
2030 Debug( LDAP_DEBUG_ANY,
2031 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2036 ber_bvarray_add( &be->be_suffix, &pdn );
2037 ber_bvarray_add( &be->be_nsuffix, &ndn );
2039 /* NOTE: only one monitor database is allowed,
2040 * so we use static storage */
2041 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2043 be->be_private = &monitor_info;
2045 be2 = select_backend( &ndn, 0, 0 );
2047 char *type = be2->bd_info->bi_type;
2049 if ( overlay_is_over( be2 ) ) {
2050 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2051 type = oi->oi_orig->bi_type;
2054 Debug( LDAP_DEBUG_ANY,
2055 "\"monitor\" database serving namingContext \"%s\" "
2056 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2057 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2065 monitor_back_db_open(
2068 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2069 struct monitor_subsys_t **ms;
2070 Entry *e, **ep, *root;
2071 monitor_entry_t *mp;
2073 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2075 #ifdef HAVE_GMTIME_R
2078 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2079 struct berval desc[] = {
2080 BER_BVC("This subtree contains monitoring/managing objects."),
2081 BER_BVC("This object contains information about this server."),
2082 BER_BVC("Most of the information is held in operational"
2083 " attributes, which must be explicitly requested."),
2086 assert( be_monitor != NULL );
2087 if ( be != be_monitor ) {
2094 #ifndef HAVE_GMTIME_R
2095 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2097 #ifdef HACK_LOCAL_TIME
2098 # ifdef HAVE_LOCALTIME_R
2099 tms = localtime_r( &starttime, &tm_buf );
2101 tms = localtime( &starttime );
2102 # endif /* HAVE_LOCALTIME_R */
2103 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2104 #else /* !HACK_LOCAL_TIME */
2105 # ifdef HAVE_GMTIME_R
2106 tms = gmtime_r( &starttime, &tm_buf );
2108 tms = gmtime( &starttime );
2109 # endif /* HAVE_GMTIME_R */
2110 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2111 #endif /* !HACK_LOCAL_TIME */
2112 #ifndef HAVE_GMTIME_R
2113 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2116 mi->mi_startTime.bv_val = tmbuf;
2117 mi->mi_startTime.bv_len = strlen( tmbuf );
2119 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2120 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2121 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2123 mi->mi_creatorsName = be->be_rootdn;
2124 mi->mi_ncreatorsName = be->be_rootndn;
2128 * creates the "cn=Monitor" entry
2130 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2134 Debug( LDAP_DEBUG_ANY,
2135 "unable to create \"%s\" entry\n",
2136 SLAPD_MONITOR_DN, 0, 0 );
2140 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2142 bv.bv_val = strchr( (char *) Versionstr, '$' );
2143 if ( bv.bv_val != NULL ) {
2147 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2150 end = strchr( bv.bv_val, '$' );
2151 if ( end != NULL ) {
2154 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2159 bv.bv_len = end - bv.bv_val;
2162 bv.bv_len = strlen( bv.bv_val );
2165 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2167 Debug( LDAP_DEBUG_ANY,
2168 "unable to add monitoredInfo to \"%s\" entry\n",
2169 SLAPD_MONITOR_DN, 0, 0 );
2174 mp = monitor_entrypriv_create();
2178 e->e_private = ( void * )mp;
2179 ep = &mp->mp_children;
2181 if ( monitor_cache_add( mi, e ) ) {
2182 Debug( LDAP_DEBUG_ANY,
2183 "unable to add entry \"%s\" to cache\n",
2184 SLAPD_MONITOR_DN, 0, 0 );
2190 * Create all the subsystem specific entries
2192 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2193 int len = strlen( monitor_subsys[ i ]->mss_name );
2197 dn.bv_len = len + sizeof( "cn=" ) - 1;
2198 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2199 strcpy( dn.bv_val, "cn=" );
2200 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2201 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2203 if ( rc != LDAP_SUCCESS ) {
2204 Debug( LDAP_DEBUG_ANY,
2205 "monitor RDN \"%s\" is invalid\n",
2210 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2211 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2215 Debug( LDAP_DEBUG_ANY,
2216 "unable to create \"%s\" entry\n",
2217 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2220 monitor_subsys[i]->mss_dn = e->e_name;
2221 monitor_subsys[i]->mss_ndn = e->e_nname;
2223 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2224 attr_merge_normalize( e, slap_schema.si_ad_description,
2225 monitor_subsys[ i ]->mss_desc, NULL );
2228 mp = monitor_entrypriv_create();
2232 e->e_private = ( void * )mp;
2233 mp->mp_info = monitor_subsys[ i ];
2234 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2236 if ( monitor_cache_add( mi, e ) ) {
2237 Debug( LDAP_DEBUG_ANY,
2238 "unable to add entry \"%s\" to cache\n",
2239 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2247 assert( be != NULL );
2249 be->be_private = mi;
2252 * opens the monitor backend subsystems
2254 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2255 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2259 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2262 monitor_subsys_opened = 1;
2264 if ( mi->mi_entry_limbo ) {
2265 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
2270 switch ( el->el_type ) {
2272 monitor_back_register_entry(
2279 case LIMBO_ENTRY_PARENT:
2280 monitor_back_register_entry_parent(
2292 monitor_back_register_entry_attrs(
2302 monitor_back_register_entry_callback(
2315 entry_free( el->el_e );
2318 attrs_free( el->el_a );
2320 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2321 ber_memfree( el->el_ndn.bv_val );
2323 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2324 ber_memfree( el->el_nbase.bv_val );
2326 if ( !BER_BVISNULL( &el->el_filter ) ) {
2327 ber_memfree( el->el_filter.bv_val );
2335 mi->mi_entry_limbo = NULL;
2342 monitor_back_config(
2350 * eventually, will hold backend specific configuration parameters
2352 return SLAP_CONF_UNKNOWN;
2357 monitor_back_db_config(
2364 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2367 * eventually, will hold database specific configuration parameters
2369 return SLAP_CONF_UNKNOWN;
2374 monitor_back_db_destroy(
2377 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2384 * FIXME: destroys all the data
2386 /* NOTE: mi points to static storage; don't free it */
2388 (void)monitor_cache_destroy( mi );
2390 if ( monitor_subsys ) {
2393 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2394 if ( monitor_subsys[ i ]->mss_destroy ) {
2395 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2398 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2399 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2403 ch_free( monitor_subsys );
2406 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2408 be->be_private = NULL;
2413 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2415 /* conditionally define the init_module() function */
2416 SLAP_BACKEND_INIT_MODULE( monitor )
2418 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */