1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2007 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
31 #include "back-monitor.h"
35 #undef INTEGRATE_CORE_SCHEMA
38 * used by many functions to add description to entries
40 * WARNING: be_monitor may change as new databases are added,
41 * so it should not be used outside monitor_back_db_init()
42 * until monitor_back_db_open is called.
44 BackendDB *be_monitor;
46 static struct monitor_subsys_t **monitor_subsys;
47 static int monitor_subsys_opened;
48 static monitor_info_t monitor_info;
49 static const monitor_extra_t monitor_extra = {
50 monitor_back_is_configured,
51 monitor_back_get_subsys,
52 monitor_back_get_subsys_by_dn,
54 monitor_back_register_subsys,
55 monitor_back_register_entry,
56 monitor_back_register_entry_parent,
57 monitor_back_register_entry_attrs,
58 monitor_back_register_entry_callback,
60 monitor_back_unregister_entry,
61 monitor_back_unregister_entry_parent,
62 monitor_back_unregister_entry_attrs,
63 monitor_back_unregister_entry_callback
70 * the known subsystems are added to the subsystems
71 * array at backend initialization; other subsystems
72 * may be added by calling monitor_back_register_subsys()
73 * before the database is opened (e.g. by other backends
74 * or by overlays or modules).
76 static struct monitor_subsys_t known_monitor_subsys[] = {
78 SLAPD_MONITOR_BACKEND_NAME,
79 BER_BVNULL, BER_BVNULL, BER_BVNULL,
80 { BER_BVC( "This subsystem contains information about available backends." ),
82 MONITOR_F_PERSISTENT_CH,
83 monitor_subsys_backend_init,
89 SLAPD_MONITOR_CONN_NAME,
90 BER_BVNULL, BER_BVNULL, BER_BVNULL,
91 { BER_BVC( "This subsystem contains information about connections." ),
93 MONITOR_F_VOLATILE_CH,
94 monitor_subsys_conn_init,
100 SLAPD_MONITOR_DATABASE_NAME,
101 BER_BVNULL, BER_BVNULL, BER_BVNULL,
102 { BER_BVC( "This subsystem contains information about configured databases." ),
104 MONITOR_F_PERSISTENT_CH,
105 monitor_subsys_database_init,
111 SLAPD_MONITOR_LISTENER_NAME,
112 BER_BVNULL, BER_BVNULL, BER_BVNULL,
113 { BER_BVC( "This subsystem contains information about active listeners." ),
115 MONITOR_F_PERSISTENT_CH,
116 monitor_subsys_listener_init,
122 SLAPD_MONITOR_LOG_NAME,
123 BER_BVNULL, BER_BVNULL, BER_BVNULL,
124 { BER_BVC( "This subsystem contains information about logging." ),
125 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
128 monitor_subsys_log_init,
134 SLAPD_MONITOR_OPS_NAME,
135 BER_BVNULL, BER_BVNULL, BER_BVNULL,
136 { BER_BVC( "This subsystem contains information about performed operations." ),
138 MONITOR_F_PERSISTENT_CH,
139 monitor_subsys_ops_init,
145 SLAPD_MONITOR_OVERLAY_NAME,
146 BER_BVNULL, BER_BVNULL, BER_BVNULL,
147 { BER_BVC( "This subsystem contains information about available overlays." ),
149 MONITOR_F_PERSISTENT_CH,
150 monitor_subsys_overlay_init,
156 SLAPD_MONITOR_SASL_NAME,
157 BER_BVNULL, BER_BVNULL, BER_BVNULL,
158 { BER_BVC( "This subsystem contains information about SASL." ),
167 SLAPD_MONITOR_SENT_NAME,
168 BER_BVNULL, BER_BVNULL, BER_BVNULL,
169 { BER_BVC( "This subsystem contains statistics." ),
171 MONITOR_F_PERSISTENT_CH,
172 monitor_subsys_sent_init,
178 SLAPD_MONITOR_THREAD_NAME,
179 BER_BVNULL, BER_BVNULL, BER_BVNULL,
180 { BER_BVC( "This subsystem contains information about threads." ),
182 MONITOR_F_PERSISTENT_CH,
183 monitor_subsys_thread_init,
189 SLAPD_MONITOR_TIME_NAME,
190 BER_BVNULL, BER_BVNULL, BER_BVNULL,
191 { BER_BVC( "This subsystem contains information about time." ),
193 MONITOR_F_PERSISTENT_CH,
194 monitor_subsys_time_init,
200 SLAPD_MONITOR_TLS_NAME,
201 BER_BVNULL, BER_BVNULL, BER_BVNULL,
202 { BER_BVC( "This subsystem contains information about TLS." ),
211 SLAPD_MONITOR_RWW_NAME,
212 BER_BVNULL, BER_BVNULL, BER_BVNULL,
213 { BER_BVC( "This subsystem contains information about read/write waiters." ),
215 MONITOR_F_PERSISTENT_CH,
216 monitor_subsys_rww_init,
225 monitor_back_register_subsys(
226 monitor_subsys_t *ms )
230 if ( monitor_subsys ) {
231 for ( ; monitor_subsys[ i ] != NULL; i++ )
232 /* just count'em */ ;
235 monitor_subsys = ch_realloc( monitor_subsys,
236 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
238 if ( monitor_subsys == NULL ) {
242 monitor_subsys[ i ] = ms;
243 monitor_subsys[ i + 1 ] = NULL;
245 /* if a subsystem is registered __AFTER__ subsystem
246 * initialization (depending on the sequence the databases
247 * are listed in slapd.conf), init it */
248 if ( monitor_subsys_opened ) {
250 /* FIXME: this should only be possible
251 * if be_monitor is already initialized */
252 assert( be_monitor != NULL );
254 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
258 ms->mss_flags |= MONITOR_F_OPENED;
271 typedef struct entry_limbo_t {
275 struct berval el_ndn;
276 struct berval el_nbase;
278 struct berval el_filter;
279 monitor_callback_t *el_cb;
280 monitor_subsys_t *el_mss;
281 unsigned long el_flags;
282 struct entry_limbo_t *el_next;
286 monitor_back_is_configured( void )
288 return be_monitor != NULL;
292 monitor_back_register_entry(
294 monitor_callback_t *cb,
295 monitor_subsys_t *mss,
296 unsigned long flags )
300 if ( be_monitor == NULL ) {
301 Debug( LDAP_DEBUG_ANY,
302 "monitor_back_register_entry(\"%s\"): "
303 "monitor database not configured.\n",
304 e->e_name.bv_val, 0, 0 );
308 mi = ( monitor_info_t * )be_monitor->be_private;
310 assert( mi != NULL );
312 assert( e->e_private == NULL );
314 if ( monitor_subsys_opened ) {
315 Entry *e_parent = NULL,
318 struct berval pdn = BER_BVNULL;
319 monitor_entry_t *mp = NULL,
323 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
325 Debug( LDAP_DEBUG_ANY,
326 "monitor_back_register_entry(\"%s\"): "
328 e->e_name.bv_val, 0, 0 );
329 monitor_cache_release( mi, e_parent );
333 dnParent( &e->e_nname, &pdn );
334 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
335 /* parent does not exist */
336 Debug( LDAP_DEBUG_ANY,
337 "monitor_back_register_entry(\"%s\"): "
338 "parent \"%s\" not found\n",
339 e->e_name.bv_val, pdn.bv_val, 0 );
343 assert( e_parent->e_private != NULL );
344 mp_parent = ( monitor_entry_t * )e_parent->e_private;
346 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
347 /* entry is volatile; cannot append children */
348 Debug( LDAP_DEBUG_ANY,
349 "monitor_back_register_entry(\"%s\"): "
350 "parent \"%s\" is volatile\n",
351 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
356 mp = monitor_entrypriv_create();
358 Debug( LDAP_DEBUG_ANY,
359 "monitor_back_register_entry(\"%s\"): "
360 "monitor_entrypriv_create() failed\n",
361 e->e_name.bv_val, 0, 0 );
366 e_new = entry_dup( e );
367 if ( e_new == NULL ) {
368 Debug( LDAP_DEBUG_ANY,
369 "monitor_back_register_entry(\"%s\"): "
370 "entry_dup() failed\n",
371 e->e_name.bv_val, 0, 0 );
376 e_new->e_private = ( void * )mp;
379 mp->mp_flags = flags;
382 mp->mp_info = mp_parent->mp_info;
383 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
387 ep = &mp_parent->mp_children;
389 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
390 ep = &mp_parent->mp_next;
394 if ( monitor_cache_add( mi, e_new ) ) {
395 Debug( LDAP_DEBUG_ANY,
396 "monitor_back_register_entry(\"%s\"): "
397 "unable to add entry\n",
398 e->e_name.bv_val, 0, 0 );
409 e_new->e_private = NULL;
415 monitor_cache_release( mi, e_parent );
419 entry_limbo_t **elpp, el = { 0 };
421 el.el_type = LIMBO_ENTRY;
423 el.el_e = entry_dup( e );
424 if ( el.el_e == NULL ) {
425 Debug( LDAP_DEBUG_ANY,
426 "monitor_back_register_entry(\"%s\"): "
427 "entry_dup() failed\n",
428 e->e_name.bv_val, 0, 0 );
436 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
438 elpp = &(*elpp)->el_next )
441 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
442 if ( *elpp == NULL ) {
443 el.el_e->e_private = NULL;
444 entry_free( el.el_e );
456 monitor_back_register_entry_parent(
458 monitor_callback_t *cb,
459 monitor_subsys_t *mss,
461 struct berval *nbase,
463 struct berval *filter )
466 struct berval ndn = BER_BVNULL;
468 if ( be_monitor == NULL ) {
469 Debug( LDAP_DEBUG_ANY,
470 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
471 "monitor database not configured.\n",
472 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
473 ldap_pvt_scope2str( scope ),
474 BER_BVISNULL( filter ) ? "" : filter->bv_val );
478 mi = ( monitor_info_t * )be_monitor->be_private;
480 assert( mi != NULL );
482 assert( e->e_private == NULL );
484 if ( BER_BVISNULL( filter ) ) {
486 Debug( LDAP_DEBUG_ANY,
487 "monitor_back_register_entry_parent(\"\"): "
488 "need a valid filter\n",
493 if ( monitor_subsys_opened ) {
494 Entry *e_parent = NULL,
497 struct berval e_name = BER_BVNULL,
498 e_nname = BER_BVNULL;
499 monitor_entry_t *mp = NULL,
503 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
504 /* entry does not exist */
505 Debug( LDAP_DEBUG_ANY,
506 "monitor_back_register_entry_parent(\"\"): "
507 "base=\"%s\" scope=%s filter=\"%s\": "
508 "unable to find entry\n",
509 nbase->bv_val ? nbase->bv_val : "\"\"",
510 ldap_pvt_scope2str( scope ),
515 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
516 /* entry does not exist */
517 Debug( LDAP_DEBUG_ANY,
518 "monitor_back_register_entry_parent(\"%s\"): "
519 "parent entry does not exist\n",
525 assert( e_parent->e_private != NULL );
526 mp_parent = ( monitor_entry_t * )e_parent->e_private;
528 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
529 /* entry is volatile; cannot append callback */
530 Debug( LDAP_DEBUG_ANY,
531 "monitor_back_register_entry_parent(\"%s\"): "
532 "entry is volatile\n",
533 e_parent->e_name.bv_val, 0, 0 );
538 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
539 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
541 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
542 /* entry already exists */
543 Debug( LDAP_DEBUG_ANY,
544 "monitor_back_register_entry_parent(\"%s\"): "
545 "entry already exists\n",
546 e_name.bv_val, 0, 0 );
547 monitor_cache_release( mi, e_new );
553 mp = monitor_entrypriv_create();
555 Debug( LDAP_DEBUG_ANY,
556 "monitor_back_register_entry_parent(\"%s\"): "
557 "monitor_entrypriv_create() failed\n",
558 e->e_name.bv_val, 0, 0 );
563 e_new = entry_dup( e );
564 if ( e_new == NULL ) {
565 Debug( LDAP_DEBUG_ANY,
566 "monitor_back_register_entry(\"%s\"): "
567 "entry_dup() failed\n",
568 e->e_name.bv_val, 0, 0 );
572 ch_free( e_new->e_name.bv_val );
573 ch_free( e_new->e_nname.bv_val );
574 e_new->e_name = e_name;
575 e_new->e_nname = e_nname;
577 e_new->e_private = ( void * )mp;
580 mp->mp_flags = flags;
583 mp->mp_info = mp_parent->mp_info;
584 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
588 ep = &mp_parent->mp_children;
590 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
591 ep = &mp_parent->mp_next;
595 if ( monitor_cache_add( mi, e_new ) ) {
596 Debug( LDAP_DEBUG_ANY,
597 "monitor_back_register_entry(\"%s\"): "
598 "unable to add entry\n",
599 e->e_name.bv_val, 0, 0 );
605 if ( !BER_BVISNULL( &ndn ) ) {
606 ch_free( ndn.bv_val );
614 e_new->e_private = NULL;
620 monitor_cache_release( mi, e_parent );
624 entry_limbo_t **elpp = NULL, el = { 0 };
626 el.el_type = LIMBO_ENTRY_PARENT;
628 el.el_e = entry_dup( e );
629 if ( el.el_e == NULL ) {
630 Debug( LDAP_DEBUG_ANY,
631 "monitor_back_register_entry(\"%s\"): "
632 "entry_dup() failed\n",
633 e->e_name.bv_val, 0, 0 );
637 if ( !BER_BVISNULL( nbase ) ) {
638 ber_dupbv( &el.el_nbase, nbase );
642 if ( !BER_BVISNULL( filter ) ) {
643 ber_dupbv( &el.el_filter, filter );
650 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
652 elpp = &(*elpp)->el_next )
655 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
656 if ( *elpp == NULL ) {
661 if ( *elpp != NULL ) {
666 if ( !BER_BVISNULL( &el.el_filter ) ) {
667 ch_free( el.el_filter.bv_val );
669 if ( !BER_BVISNULL( &el.el_nbase ) ) {
670 ch_free( el.el_nbase.bv_val );
672 entry_free( el.el_e );
681 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
683 if ( rs->sr_type == REP_SEARCH ) {
684 struct berval *ndn = op->o_callback->sc_private;
686 if ( !BER_BVISNULL( ndn ) ) {
687 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
688 ch_free( ndn->bv_val );
693 ber_dupbv( ndn, &rs->sr_entry->e_nname );
701 struct berval *nbase,
703 struct berval *filter,
706 Connection conn = { 0 };
707 OperationBuffer opbuf;
709 SlapReply rs = { 0 };
710 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
715 if ( be_monitor == NULL ) {
719 op = (Operation *) &opbuf;
720 connection_fake_init( &conn, op, &conn );
722 op->o_tag = LDAP_REQ_SEARCH;
724 /* use global malloc for now */
725 if ( op->o_tmpmemctx ) {
726 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
727 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
728 op->o_tmpmemctx = NULL;
730 op->o_tmpmfuncs = &ch_mfuncs;
732 op->o_bd = be_monitor;
733 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
734 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
736 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
740 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
741 op->o_tmpmemctx ) ) {
746 op->o_callback = &cb;
747 cb.sc_private = (void *)ndn;
749 op->ors_scope = scope;
750 op->ors_filter = str2filter_x( op, filter->bv_val );
751 if ( op->ors_filter == NULL ) {
755 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
756 op->ors_attrs = slap_anlist_no_attrs;
757 op->ors_attrsonly = 0;
758 op->ors_tlimit = SLAP_NO_LIMIT;
760 op->ors_limit = NULL;
761 op->ors_deref = LDAP_DEREF_NEVER;
764 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
766 op->o_dn = be_monitor->be_rootdn;
767 op->o_ndn = be_monitor->be_rootndn;
769 rc = op->o_bd->be_search( op, &rs );
772 if ( op->ors_filter != NULL ) {
773 filter_free_x( op, op->ors_filter );
775 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
776 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
778 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
779 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
781 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
782 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
789 switch ( rs.sr_err ) {
791 if ( BER_BVISNULL( ndn ) ) {
796 case LDAP_SIZELIMIT_EXCEEDED:
798 if ( !BER_BVISNULL( ndn ) ) {
799 ber_memfree( ndn->bv_val );
810 monitor_back_register_entry_attrs(
811 struct berval *ndn_in,
813 monitor_callback_t *cb,
814 struct berval *nbase,
816 struct berval *filter )
819 struct berval ndn = BER_BVNULL;
820 char *fname = ( a == NULL ? "callback" : "attrs" );
822 if ( be_monitor == NULL ) {
823 char buf[ SLAP_TEXT_BUFLEN ];
825 snprintf( buf, sizeof( buf ),
826 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
827 "monitor database not configured.\n",
829 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
830 ldap_pvt_scope2str( scope ),
831 BER_BVISNULL( filter ) ? "" : filter->bv_val );
832 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
837 mi = ( monitor_info_t * )be_monitor->be_private;
839 assert( mi != NULL );
841 if ( ndn_in != NULL ) {
845 if ( a == NULL && cb == NULL ) {
850 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
851 && BER_BVISNULL( filter ) )
854 Debug( LDAP_DEBUG_ANY,
855 "monitor_back_register_entry_%s(\"\"): "
856 "need a valid filter\n",
861 if ( monitor_subsys_opened ) {
863 Attribute **atp = NULL;
864 monitor_entry_t *mp = NULL;
865 monitor_callback_t **mcp = NULL;
869 if ( BER_BVISNULL( &ndn ) ) {
870 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
871 char buf[ SLAP_TEXT_BUFLEN ];
873 snprintf( buf, sizeof( buf ),
874 "monitor_back_register_entry_%s(\"\"): "
875 "base=\"%s\" scope=%s filter=\"%s\": "
876 "unable to find entry\n",
878 nbase->bv_val ? nbase->bv_val : "\"\"",
879 ldap_pvt_scope2str( scope ),
882 /* entry does not exist */
883 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
890 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
891 /* entry does not exist */
892 Debug( LDAP_DEBUG_ANY,
893 "monitor_back_register_entry_%s(\"%s\"): "
894 "entry does not exist\n",
895 fname, ndn.bv_val, 0 );
900 assert( e->e_private != NULL );
901 mp = ( monitor_entry_t * )e->e_private;
903 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
904 /* entry is volatile; cannot append callback */
905 Debug( LDAP_DEBUG_ANY,
906 "monitor_back_register_entry_%s(\"%s\"): "
907 "entry is volatile\n",
908 fname, e->e_name.bv_val, 0 );
914 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
915 /* just get to last */ ;
917 for ( ; a != NULL; a = a->a_next ) {
918 assert( a->a_desc != NULL );
919 assert( a->a_vals != NULL );
921 if ( attr_find( e->e_attrs, a->a_desc ) ) {
922 attr_merge( e, a->a_desc, a->a_vals,
923 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
926 *atp = attr_dup( a );
927 if ( *atp == NULL ) {
928 Debug( LDAP_DEBUG_ANY,
929 "monitor_back_register_entry_%s(\"%s\"): "
930 "attr_dup() failed\n",
931 fname, e->e_name.bv_val, 0 );
935 atp = &(*atp)->a_next;
941 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
944 /* NOTE: we do not clear cb->mc_next, so this function
945 * can be used to append a list of callbacks */
958 ber_memfree( ndn.bv_val );
962 monitor_cache_release( mi, e );
966 entry_limbo_t **elpp, el = { 0 };
968 el.el_type = LIMBO_ATTRS;
969 if ( !BER_BVISNULL( &ndn ) ) {
970 ber_dupbv( &el.el_ndn, &ndn );
972 if ( !BER_BVISNULL( nbase ) ) {
973 ber_dupbv( &el.el_nbase, nbase);
976 if ( !BER_BVISNULL( filter ) ) {
977 ber_dupbv( &el.el_filter, filter );
980 el.el_a = attrs_dup( a );
983 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
985 elpp = &(*elpp)->el_next )
988 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
989 if ( *elpp == NULL ) {
990 el.el_e->e_private = NULL;
991 entry_free( el.el_e );
995 if ( *elpp != NULL ) {
1000 if ( !BER_BVISNULL( &el.el_filter ) ) {
1001 ch_free( el.el_filter.bv_val );
1003 if ( el.el_a != NULL ) {
1004 attrs_free( el.el_a );
1006 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1007 ch_free( &el.el_nbase.bv_val );
1009 if ( !BER_BVISNULL( &el.el_ndn ) ) {
1010 ch_free( el.el_ndn.bv_val );
1020 monitor_back_register_entry_callback(
1022 monitor_callback_t *cb,
1023 struct berval *nbase,
1025 struct berval *filter )
1027 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1028 nbase, scope, filter );
1032 * TODO: add corresponding calls to remove installed callbacks, entries
1033 * and so, in case the entity that installed them is removed (e.g. a
1034 * database, via back-config)
1037 monitor_back_unregister_entry(
1038 struct berval *ndn )
1042 if ( be_monitor == NULL ) {
1043 Debug( LDAP_DEBUG_ANY,
1044 "monitor_back_unregister_entry(\"%s\"): "
1045 "monitor database not configured.\n",
1046 ndn->bv_val, 0, 0 );
1051 /* entry will be regularly freed, and resources released
1052 * according to callbacks */
1053 if ( slapd_shutdown ) {
1057 mi = ( monitor_info_t * )be_monitor->be_private;
1059 assert( mi != NULL );
1061 if ( monitor_subsys_opened ) {
1063 monitor_entry_t *mp = NULL;
1064 monitor_callback_t *cb = NULL;
1066 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1067 /* entry does not exist */
1068 Debug( LDAP_DEBUG_ANY,
1069 "monitor_back_unregister_entry(\"%s\"): "
1070 "entry removal failed.\n",
1071 ndn->bv_val, 0, 0 );
1075 mp = (monitor_entry_t *)e->e_private;
1076 assert( mp != NULL );
1078 for ( cb = mp->mp_cb; cb != NULL; ) {
1079 monitor_callback_t *next = cb->mc_next;
1081 if ( cb->mc_free ) {
1082 (void)cb->mc_free( e, &cb->mc_private );
1090 e->e_private = NULL;
1094 entry_limbo_t **elpp;
1096 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1098 elpp = &(*elpp)->el_next )
1100 entry_limbo_t *elp = *elpp;
1102 if ( elp->el_type == LIMBO_ENTRY
1103 && dn_match( ndn, &elp->el_e->e_nname ) )
1105 monitor_callback_t *cb, *next;
1107 for ( cb = elp->el_cb; cb; cb = next ) {
1108 /* FIXME: call callbacks? */
1112 assert( elp->el_e != NULL );
1113 elp->el_e->e_private = NULL;
1114 entry_free( elp->el_e );
1115 *elpp = elp->el_next;
1122 if ( elpp != NULL ) {
1123 /* not found! where did it go? */
1132 monitor_back_unregister_entry_parent(
1133 struct berval *nrdn,
1134 monitor_callback_t *target_cb,
1135 struct berval *nbase,
1137 struct berval *filter )
1140 struct berval ndn = BER_BVNULL;
1142 if ( be_monitor == NULL ) {
1143 Debug( LDAP_DEBUG_ANY,
1144 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1145 "monitor database not configured.\n",
1146 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1147 ldap_pvt_scope2str( scope ),
1148 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1153 /* entry will be regularly freed, and resources released
1154 * according to callbacks */
1155 if ( slapd_shutdown ) {
1159 mi = ( monitor_info_t * )be_monitor->be_private;
1161 assert( mi != NULL );
1163 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1164 && BER_BVISNULL( filter ) )
1167 Debug( LDAP_DEBUG_ANY,
1168 "monitor_back_unregister_entry_parent(\"\"): "
1169 "need a valid filter\n",
1174 if ( monitor_subsys_opened ) {
1176 monitor_entry_t *mp = NULL;
1178 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1179 /* entry does not exist */
1180 Debug( LDAP_DEBUG_ANY,
1181 "monitor_back_unregister_entry_parent(\"\"): "
1182 "base=\"%s\" scope=%s filter=\"%s\": "
1183 "unable to find entry\n",
1184 nbase->bv_val ? nbase->bv_val : "\"\"",
1185 ldap_pvt_scope2str( scope ),
1190 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1191 /* entry does not exist */
1192 Debug( LDAP_DEBUG_ANY,
1193 "monitor_back_unregister_entry(\"%s\"): "
1194 "entry removal failed.\n",
1196 ber_memfree( ndn.bv_val );
1199 ber_memfree( ndn.bv_val );
1201 mp = (monitor_entry_t *)e->e_private;
1202 assert( mp != NULL );
1204 if ( target_cb != NULL ) {
1205 monitor_callback_t **cbp;
1207 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1208 if ( *cbp == target_cb ) {
1209 if ( (*cbp)->mc_free ) {
1210 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1212 *cbp = (*cbp)->mc_next;
1213 ch_free( target_cb );
1221 e->e_private = NULL;
1225 entry_limbo_t **elpp;
1227 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1229 elpp = &(*elpp)->el_next )
1231 entry_limbo_t *elp = *elpp;
1233 if ( elp->el_type == LIMBO_ENTRY_PARENT
1234 && dn_match( nrdn, &elp->el_e->e_nname )
1235 && dn_match( nbase, &elp->el_nbase )
1236 && scope == elp->el_scope
1237 && bvmatch( filter, &elp->el_filter ) )
1239 monitor_callback_t *cb, *next;
1241 for ( cb = elp->el_cb; cb; cb = next ) {
1242 /* FIXME: call callbacks? */
1246 assert( elp->el_e != NULL );
1247 elp->el_e->e_private = NULL;
1248 entry_free( elp->el_e );
1249 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1250 ch_free( elp->el_nbase.bv_val );
1252 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1253 ch_free( elp->el_filter.bv_val );
1255 *elpp = elp->el_next;
1262 if ( elpp != NULL ) {
1263 /* not found! where did it go? */
1272 monitor_back_unregister_entry_attrs(
1273 struct berval *ndn_in,
1274 Attribute *target_a,
1275 monitor_callback_t *target_cb,
1276 struct berval *nbase,
1278 struct berval *filter )
1281 struct berval ndn = BER_BVNULL;
1282 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1284 if ( be_monitor == NULL ) {
1285 char buf[ SLAP_TEXT_BUFLEN ];
1287 snprintf( buf, sizeof( buf ),
1288 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1289 "monitor database not configured.\n",
1291 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1292 ldap_pvt_scope2str( scope ),
1293 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1294 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1299 /* entry will be regularly freed, and resources released
1300 * according to callbacks */
1301 if ( slapd_shutdown ) {
1305 mi = ( monitor_info_t * )be_monitor->be_private;
1307 assert( mi != NULL );
1309 if ( ndn_in != NULL ) {
1313 if ( target_a == NULL && target_cb == NULL ) {
1318 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1319 && BER_BVISNULL( filter ) )
1322 Debug( LDAP_DEBUG_ANY,
1323 "monitor_back_unregister_entry_%s(\"\"): "
1324 "need a valid filter\n",
1329 if ( monitor_subsys_opened ) {
1331 monitor_entry_t *mp = NULL;
1334 if ( BER_BVISNULL( &ndn ) ) {
1335 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1336 char buf[ SLAP_TEXT_BUFLEN ];
1338 snprintf( buf, sizeof( buf ),
1339 "monitor_back_unregister_entry_%s(\"\"): "
1340 "base=\"%s\" scope=%d filter=\"%s\": "
1341 "unable to find entry\n",
1343 nbase->bv_val ? nbase->bv_val : "\"\"",
1344 scope, filter->bv_val );
1346 /* entry does not exist */
1347 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1354 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1355 /* entry does not exist */
1356 Debug( LDAP_DEBUG_ANY,
1357 "monitor_back_unregister_entry(\"%s\"): "
1358 "entry removal failed.\n",
1363 mp = (monitor_entry_t *)e->e_private;
1364 assert( mp != NULL );
1366 if ( target_cb != NULL ) {
1367 monitor_callback_t **cbp;
1369 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1370 if ( *cbp == target_cb ) {
1371 if ( (*cbp)->mc_free ) {
1372 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1374 *cbp = (*cbp)->mc_next;
1375 ch_free( target_cb );
1381 if ( target_a != NULL ) {
1384 for ( a = target_a; a != NULL; a = a->a_next ) {
1385 Modification mod = { 0 };
1387 char textbuf[ SLAP_TEXT_BUFLEN ];
1389 mod.sm_op = LDAP_MOD_DELETE;
1390 mod.sm_desc = a->a_desc;
1391 mod.sm_values = a->a_vals;
1392 mod.sm_nvalues = a->a_nvals;
1394 (void)modify_delete_values( e, &mod, 1,
1395 &text, textbuf, sizeof( textbuf ) );
1400 ber_memfree( ndn.bv_val );
1404 monitor_cache_release( mi, e );
1408 entry_limbo_t **elpp;
1410 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1412 elpp = &(*elpp)->el_next )
1414 entry_limbo_t *elp = *elpp;
1416 if ( elp->el_type == LIMBO_ATTRS
1417 && dn_match( nbase, &elp->el_nbase )
1418 && scope == elp->el_scope
1419 && bvmatch( filter, &elp->el_filter ) )
1421 monitor_callback_t *cb, *next;
1423 for ( cb = elp->el_cb; cb; cb = next ) {
1424 /* FIXME: call callbacks? */
1428 assert( elp->el_e == NULL );
1429 if ( elp->el_a != NULL ) {
1430 attrs_free( elp->el_a );
1432 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1433 ch_free( elp->el_nbase.bv_val );
1435 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1436 ch_free( elp->el_filter.bv_val );
1438 *elpp = elp->el_next;
1445 if ( elpp != NULL ) {
1446 /* not found! where did it go? */
1455 monitor_back_unregister_entry_callback(
1457 monitor_callback_t *cb,
1458 struct berval *nbase,
1460 struct berval *filter )
1462 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1463 * unregister the callback; if a is not null, unregister the
1464 * given attrs. In any case, call cb->cb_free */
1465 return monitor_back_unregister_entry_attrs( ndn,
1466 NULL, cb, nbase, scope, filter );
1470 monitor_back_get_subsys( const char *name )
1472 if ( monitor_subsys != NULL ) {
1475 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1476 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1477 return monitor_subsys[ i ];
1486 monitor_back_get_subsys_by_dn(
1490 if ( monitor_subsys != NULL ) {
1494 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1495 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1496 return monitor_subsys[ i ];
1501 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1502 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1503 return monitor_subsys[ i ];
1513 monitor_back_initialize(
1516 static char *controls[] = {
1517 LDAP_CONTROL_MANAGEDSAIT,
1521 static ConfigTable monitorcfg[] = {
1522 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1523 NULL, NULL, NULL, NULL }
1526 static ConfigOCs monitorocs[] = {
1527 { "( OLcfgDbOc:4.1 "
1528 "NAME 'olcMonitorConfig' "
1529 "DESC 'Monitor backend configuration' "
1530 "SUP olcDatabaseConfig "
1532 Cft_Database, monitorcfg },
1541 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1543 "DESC 'OpenLDAP system monitoring' "
1544 "SUP top STRUCTURAL "
1553 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1554 offsetof(monitor_info_t, mi_oc_monitor) },
1555 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1556 "NAME 'monitorServer' "
1557 "DESC 'Server monitoring root entry' "
1558 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1559 offsetof(monitor_info_t, mi_oc_monitorServer) },
1560 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1561 "NAME 'monitorContainer' "
1562 "DESC 'monitor container class' "
1563 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1564 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1565 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1566 "NAME 'monitorCounterObject' "
1567 "DESC 'monitor counter class' "
1568 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1569 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1570 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1571 "NAME 'monitorOperation' "
1572 "DESC 'monitor operation class' "
1573 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1574 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1575 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1576 "NAME 'monitorConnection' "
1577 "DESC 'monitor connection class' "
1578 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1579 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1580 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1581 "NAME 'managedObject' "
1582 "DESC 'monitor managed entity class' "
1583 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1584 offsetof(monitor_info_t, mi_oc_managedObject) },
1585 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1586 "NAME 'monitoredObject' "
1587 "DESC 'monitor monitored entity class' "
1588 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1589 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1592 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1593 "NAME 'monitoredInfo' "
1594 "DESC 'monitored info' "
1596 "EQUALITY caseIgnoreMatch "
1597 "SUBSTR caseIgnoreSubstringsMatch "
1598 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1599 "NO-USER-MODIFICATION "
1600 "USAGE dSAOperation )", SLAP_AT_HIDE,
1601 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1602 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1603 "NAME 'managedInfo' "
1604 "DESC 'monitor managed info' "
1605 "SUP name )", SLAP_AT_HIDE,
1606 offsetof(monitor_info_t, mi_ad_managedInfo) },
1607 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1608 "NAME 'monitorCounter' "
1609 "DESC 'monitor counter' "
1610 "EQUALITY integerMatch "
1611 "ORDERING integerOrderingMatch "
1612 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1613 "NO-USER-MODIFICATION "
1614 "USAGE dSAOperation )", SLAP_AT_HIDE,
1615 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1616 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1617 "NAME 'monitorOpCompleted' "
1618 "DESC 'monitor completed operations' "
1619 "SUP monitorCounter "
1620 "NO-USER-MODIFICATION "
1621 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1622 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1623 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1624 "NAME 'monitorOpInitiated' "
1625 "DESC 'monitor initiated operations' "
1626 "SUP monitorCounter "
1627 "NO-USER-MODIFICATION "
1628 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1629 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1630 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1631 "NAME 'monitorConnectionNumber' "
1632 "DESC 'monitor connection number' "
1633 "SUP monitorCounter "
1634 "NO-USER-MODIFICATION "
1635 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1636 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1637 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1638 "NAME 'monitorConnectionAuthzDN' "
1639 "DESC 'monitor connection authorization DN' "
1640 /* "SUP distinguishedName " */
1641 "EQUALITY distinguishedNameMatch "
1642 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1643 "NO-USER-MODIFICATION "
1644 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1645 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1646 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1647 "NAME 'monitorConnectionLocalAddress' "
1648 "DESC 'monitor connection local address' "
1649 "SUP monitoredInfo "
1650 "NO-USER-MODIFICATION "
1651 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1652 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1653 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1654 "NAME 'monitorConnectionPeerAddress' "
1655 "DESC 'monitor connection peer address' "
1656 "SUP monitoredInfo "
1657 "NO-USER-MODIFICATION "
1658 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1659 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1660 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1661 "NAME 'monitorTimestamp' "
1662 "DESC 'monitor timestamp' "
1663 "EQUALITY generalizedTimeMatch "
1664 "ORDERING generalizedTimeOrderingMatch "
1665 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1667 "NO-USER-MODIFICATION "
1668 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1669 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1670 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1671 "NAME 'monitorOverlay' "
1672 "DESC 'name of overlays defined for a given database' "
1673 "SUP monitoredInfo "
1674 "NO-USER-MODIFICATION "
1675 "USAGE dSAOperation )", SLAP_AT_HIDE,
1676 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1677 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1679 "DESC 'read/write status of a given database' "
1680 "EQUALITY booleanMatch "
1681 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1683 "USAGE dSAOperation )", SLAP_AT_HIDE,
1684 offsetof(monitor_info_t, mi_ad_readOnly) },
1685 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1686 "NAME 'restrictedOperation' "
1687 "DESC 'name of restricted operation for a given database' "
1688 "SUP managedInfo )", SLAP_AT_HIDE,
1689 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1690 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1691 "NAME 'monitorConnectionProtocol' "
1692 "DESC 'monitor connection protocol' "
1693 "SUP monitoredInfo "
1694 "NO-USER-MODIFICATION "
1695 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1696 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1697 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1698 "NAME 'monitorConnectionOpsReceived' "
1699 "DESC 'monitor number of operations received by the connection' "
1700 "SUP monitorCounter "
1701 "NO-USER-MODIFICATION "
1702 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1703 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1704 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1705 "NAME 'monitorConnectionOpsExecuting' "
1706 "DESC 'monitor number of operations in execution within the connection' "
1707 "SUP monitorCounter "
1708 "NO-USER-MODIFICATION "
1709 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1710 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1711 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1712 "NAME 'monitorConnectionOpsPending' "
1713 "DESC 'monitor number of pending operations within the connection' "
1714 "SUP monitorCounter "
1715 "NO-USER-MODIFICATION "
1716 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1717 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1718 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1719 "NAME 'monitorConnectionOpsCompleted' "
1720 "DESC 'monitor number of operations completed within the connection' "
1721 "SUP monitorCounter "
1722 "NO-USER-MODIFICATION "
1723 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1724 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1725 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1726 "NAME 'monitorConnectionGet' "
1727 "DESC 'number of times connection_get() was called so far' "
1728 "SUP monitorCounter "
1729 "NO-USER-MODIFICATION "
1730 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1731 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1732 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1733 "NAME 'monitorConnectionRead' "
1734 "DESC 'number of times connection_read() was called so far' "
1735 "SUP monitorCounter "
1736 "NO-USER-MODIFICATION "
1737 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1738 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1739 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1740 "NAME 'monitorConnectionWrite' "
1741 "DESC 'number of times connection_write() was called so far' "
1742 "SUP monitorCounter "
1743 "NO-USER-MODIFICATION "
1744 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1745 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1746 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1747 "NAME 'monitorConnectionMask' "
1748 "DESC 'monitor connection mask' "
1749 "SUP monitoredInfo "
1750 "NO-USER-MODIFICATION "
1751 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1752 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1753 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1754 "NAME 'monitorConnectionListener' "
1755 "DESC 'monitor connection listener' "
1756 "SUP monitoredInfo "
1757 "NO-USER-MODIFICATION "
1758 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1759 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1760 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1761 "NAME 'monitorConnectionPeerDomain' "
1762 "DESC 'monitor connection peer domain' "
1763 "SUP monitoredInfo "
1764 "NO-USER-MODIFICATION "
1765 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1766 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1767 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1768 "NAME 'monitorConnectionStartTime' "
1769 "DESC 'monitor connection start time' "
1770 "SUP monitorTimestamp "
1772 "NO-USER-MODIFICATION "
1773 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1774 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1775 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1776 "NAME 'monitorConnectionActivityTime' "
1777 "DESC 'monitor connection activity time' "
1778 "SUP monitorTimestamp "
1780 "NO-USER-MODIFICATION "
1781 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1782 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1783 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1784 "NAME 'monitorIsShadow' "
1785 "DESC 'TRUE if the database is shadow' "
1786 "EQUALITY booleanMatch "
1787 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1789 "USAGE dSAOperation )", SLAP_AT_HIDE,
1790 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1791 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1792 "NAME 'monitorUpdateRef' "
1793 "DESC 'update referral for shadow databases' "
1794 "SUP monitoredInfo "
1796 "USAGE dSAOperation )", SLAP_AT_HIDE,
1797 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1798 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1799 "NAME 'monitorRuntimeConfig' "
1800 "DESC 'TRUE if component allows runtime configuration' "
1801 "EQUALITY booleanMatch "
1802 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1804 "USAGE dSAOperation )", SLAP_AT_HIDE,
1805 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1813 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1814 { "olmSubSystemAttributes", "olmAttributes:0" },
1815 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1816 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1818 /* for example, back-bdb specific attrs
1819 * are in "olmDatabaseAttributes:1"
1821 * NOTE: developers, please record here OID assignments
1822 * for other modules */
1824 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1825 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1826 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1827 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1829 /* for example, back-bdb specific objectClasses
1830 * are in "olmDatabaseObjectClasses:1"
1832 * NOTE: developers, please record here OID assignments
1833 * for other modules */
1839 monitor_info_t *mi = &monitor_info;
1843 argv[ 0 ] = "monitor";
1848 for ( i = 0; s_oid[ i ].name; i++ ) {
1849 argv[ 1 ] = s_oid[ i ].name;
1850 argv[ 2 ] = s_oid[ i ].oid;
1852 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1853 Debug( LDAP_DEBUG_ANY,
1854 "monitor_back_initialize: unable to add "
1855 "objectIdentifier \"%s=%s\"\n",
1856 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1861 /* schema integration */
1862 for ( i = 0; mat[ i ].schema; i++ ) {
1864 AttributeDescription **ad =
1865 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1868 code = register_at( mat[ i ].schema, ad, 0 );
1871 Debug( LDAP_DEBUG_ANY,
1872 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1875 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1878 for ( i = 0; moc[ i ].schema; i++ ) {
1881 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1883 code = register_oc( moc[ i ].schema, Oc, 0 );
1885 Debug( LDAP_DEBUG_ANY,
1886 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1889 (*Oc)->soc_flags |= moc[ i ].flags;
1892 bi->bi_controls = controls;
1896 bi->bi_config = monitor_back_config;
1900 bi->bi_db_init = monitor_back_db_init;
1902 bi->bi_db_config = monitor_back_db_config;
1904 bi->bi_db_open = monitor_back_db_open;
1905 bi->bi_db_close = 0;
1906 bi->bi_db_destroy = monitor_back_db_destroy;
1908 bi->bi_op_bind = monitor_back_bind;
1909 bi->bi_op_unbind = 0;
1910 bi->bi_op_search = monitor_back_search;
1911 bi->bi_op_compare = monitor_back_compare;
1912 bi->bi_op_modify = monitor_back_modify;
1913 bi->bi_op_modrdn = 0;
1915 bi->bi_op_delete = 0;
1916 bi->bi_op_abandon = 0;
1918 bi->bi_extended = 0;
1920 bi->bi_entry_release_rw = 0;
1921 bi->bi_chk_referrals = 0;
1922 bi->bi_operational = monitor_back_operational;
1925 * hooks for slap tools
1927 bi->bi_tool_entry_open = 0;
1928 bi->bi_tool_entry_close = 0;
1929 bi->bi_tool_entry_first = 0;
1930 bi->bi_tool_entry_next = 0;
1931 bi->bi_tool_entry_get = 0;
1932 bi->bi_tool_entry_put = 0;
1933 bi->bi_tool_entry_reindex = 0;
1934 bi->bi_tool_sync = 0;
1935 bi->bi_tool_dn2id_get = 0;
1936 bi->bi_tool_id2entry_get = 0;
1937 bi->bi_tool_entry_modify = 0;
1939 bi->bi_connection_init = 0;
1940 bi->bi_connection_destroy = 0;
1942 bi->bi_extra = (void *)&monitor_extra;
1945 * configuration objectClasses (fake)
1947 bi->bi_cf_ocs = monitorocs;
1949 rc = config_register_schema( monitorcfg, monitorocs );
1958 monitor_back_db_init(
1962 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1967 monitor_subsys_t *ms;
1972 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1973 if ( monitor_back_register_subsys( ms ) ) {
1979 * database monitor can be defined once only
1981 if ( be_monitor != NULL ) {
1982 Debug( LDAP_DEBUG_ANY,
1983 "only one monitor database is allowed\n", 0, 0, 0 );
1988 /* indicate system schema supported */
1989 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1991 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1992 if( rc != LDAP_SUCCESS ) {
1993 Debug( LDAP_DEBUG_ANY,
1994 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
1999 ber_bvarray_add( &be->be_suffix, &pdn );
2000 ber_bvarray_add( &be->be_nsuffix, &ndn );
2002 /* NOTE: only one monitor database is allowed,
2003 * so we use static storage */
2004 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2006 be->be_private = &monitor_info;
2008 be2 = select_backend( &ndn, 0, 0 );
2010 char *type = be2->bd_info->bi_type;
2012 if ( overlay_is_over( be2 ) ) {
2013 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2014 type = oi->oi_orig->bi_type;
2017 Debug( LDAP_DEBUG_ANY,
2018 "\"monitor\" database serving namingContext \"%s\" "
2019 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2020 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2028 monitor_back_db_open(
2031 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2032 struct monitor_subsys_t **ms;
2033 Entry *e, **ep, *root;
2034 monitor_entry_t *mp;
2036 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2038 #ifdef HAVE_GMTIME_R
2041 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2042 struct berval desc[] = {
2043 BER_BVC("This subtree contains monitoring/managing objects."),
2044 BER_BVC("This object contains information about this server."),
2045 BER_BVC("Most of the information is held in operational"
2046 " attributes, which must be explicitly requested."),
2049 assert( be_monitor != NULL );
2050 if ( be != be_monitor ) {
2057 #ifndef HAVE_GMTIME_R
2058 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2060 #ifdef HACK_LOCAL_TIME
2061 # ifdef HAVE_LOCALTIME_R
2062 tms = localtime_r( &starttime, &tm_buf );
2064 tms = localtime( &starttime );
2065 # endif /* HAVE_LOCALTIME_R */
2066 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2067 #else /* !HACK_LOCAL_TIME */
2068 # ifdef HAVE_GMTIME_R
2069 tms = gmtime_r( &starttime, &tm_buf );
2071 tms = gmtime( &starttime );
2072 # endif /* HAVE_GMTIME_R */
2073 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2074 #endif /* !HACK_LOCAL_TIME */
2075 #ifndef HAVE_GMTIME_R
2076 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2079 mi->mi_startTime.bv_val = tmbuf;
2080 mi->mi_startTime.bv_len = strlen( tmbuf );
2082 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2083 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2084 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2086 mi->mi_creatorsName = be->be_rootdn;
2087 mi->mi_ncreatorsName = be->be_rootndn;
2091 * creates the "cn=Monitor" entry
2093 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2097 Debug( LDAP_DEBUG_ANY,
2098 "unable to create \"%s\" entry\n",
2099 SLAPD_MONITOR_DN, 0, 0 );
2103 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2105 bv.bv_val = strchr( (char *) Versionstr, '$' );
2106 if ( bv.bv_val != NULL ) {
2110 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2113 end = strchr( bv.bv_val, '$' );
2114 if ( end != NULL ) {
2117 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2122 bv.bv_len = end - bv.bv_val;
2125 bv.bv_len = strlen( bv.bv_val );
2128 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2130 Debug( LDAP_DEBUG_ANY,
2131 "unable to add monitoredInfo to \"%s\" entry\n",
2132 SLAPD_MONITOR_DN, 0, 0 );
2137 mp = monitor_entrypriv_create();
2141 e->e_private = ( void * )mp;
2142 ep = &mp->mp_children;
2144 if ( monitor_cache_add( mi, e ) ) {
2145 Debug( LDAP_DEBUG_ANY,
2146 "unable to add entry \"%s\" to cache\n",
2147 SLAPD_MONITOR_DN, 0, 0 );
2153 * Create all the subsystem specific entries
2155 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2156 int len = strlen( monitor_subsys[ i ]->mss_name );
2160 dn.bv_len = len + sizeof( "cn=" ) - 1;
2161 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2162 strcpy( dn.bv_val, "cn=" );
2163 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2164 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2166 if ( rc != LDAP_SUCCESS ) {
2167 Debug( LDAP_DEBUG_ANY,
2168 "monitor RDN \"%s\" is invalid\n",
2173 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2174 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2178 Debug( LDAP_DEBUG_ANY,
2179 "unable to create \"%s\" entry\n",
2180 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2183 monitor_subsys[i]->mss_dn = e->e_name;
2184 monitor_subsys[i]->mss_ndn = e->e_nname;
2186 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2187 attr_merge_normalize( e, slap_schema.si_ad_description,
2188 monitor_subsys[ i ]->mss_desc, NULL );
2191 mp = monitor_entrypriv_create();
2195 e->e_private = ( void * )mp;
2196 mp->mp_info = monitor_subsys[ i ];
2197 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2199 if ( monitor_cache_add( mi, e ) ) {
2200 Debug( LDAP_DEBUG_ANY,
2201 "unable to add entry \"%s\" to cache\n",
2202 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2210 assert( be != NULL );
2212 be->be_private = mi;
2215 * opens the monitor backend subsystems
2217 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2218 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2222 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2225 monitor_subsys_opened = 1;
2227 if ( mi->mi_entry_limbo ) {
2228 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
2234 switch ( el->el_type ) {
2236 rc = monitor_back_register_entry(
2243 case LIMBO_ENTRY_PARENT:
2244 rc = monitor_back_register_entry_parent(
2256 rc = monitor_back_register_entry_attrs(
2266 rc = monitor_back_register_entry_callback(
2279 entry_free( el->el_e );
2282 attrs_free( el->el_a );
2284 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2285 ber_memfree( el->el_ndn.bv_val );
2287 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2288 ber_memfree( el->el_nbase.bv_val );
2290 if ( !BER_BVISNULL( &el->el_filter ) ) {
2291 ber_memfree( el->el_filter.bv_val );
2293 if ( el->el_cb && rc != 0 ) {
2294 if ( el->el_cb->mc_dispose ) {
2295 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2297 ch_free( el->el_cb );
2305 mi->mi_entry_limbo = NULL;
2312 monitor_back_config(
2320 * eventually, will hold backend specific configuration parameters
2322 return SLAP_CONF_UNKNOWN;
2327 monitor_back_db_config(
2334 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2337 * eventually, will hold database specific configuration parameters
2339 return SLAP_CONF_UNKNOWN;
2344 monitor_back_db_destroy(
2347 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2354 * FIXME: destroys all the data
2356 /* NOTE: mi points to static storage; don't free it */
2358 (void)monitor_cache_destroy( mi );
2360 if ( monitor_subsys ) {
2363 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2364 if ( monitor_subsys[ i ]->mss_destroy ) {
2365 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2368 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2369 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2373 ch_free( monitor_subsys );
2376 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2378 be->be_private = NULL;
2383 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2385 /* conditionally define the init_module() function */
2386 SLAP_BACKEND_INIT_MODULE( monitor )
2388 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */