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;
47 static const monitor_extra_t monitor_extra = {
48 monitor_back_is_configured,
49 monitor_back_get_subsys,
50 monitor_back_get_subsys_by_dn,
52 monitor_back_register_subsys,
53 monitor_back_register_entry,
54 monitor_back_register_entry_parent,
55 monitor_back_register_entry_attrs,
56 monitor_back_register_entry_callback,
58 monitor_back_unregister_entry,
59 monitor_back_unregister_entry_parent,
60 monitor_back_unregister_entry_attrs,
61 monitor_back_unregister_entry_callback
68 * the known subsystems are added to the subsystems
69 * array at backend initialization; other subsystems
70 * may be added by calling monitor_back_register_subsys()
71 * before the database is opened (e.g. by other backends
72 * or by overlays or modules).
74 static struct monitor_subsys_t known_monitor_subsys[] = {
76 SLAPD_MONITOR_BACKEND_NAME,
77 BER_BVNULL, BER_BVNULL, BER_BVNULL,
78 { BER_BVC( "This subsystem contains information about available backends." ),
80 MONITOR_F_PERSISTENT_CH,
81 monitor_subsys_backend_init,
87 SLAPD_MONITOR_CONN_NAME,
88 BER_BVNULL, BER_BVNULL, BER_BVNULL,
89 { BER_BVC( "This subsystem contains information about connections." ),
91 MONITOR_F_VOLATILE_CH,
92 monitor_subsys_conn_init,
98 SLAPD_MONITOR_DATABASE_NAME,
99 BER_BVNULL, BER_BVNULL, BER_BVNULL,
100 { BER_BVC( "This subsystem contains information about configured databases." ),
102 MONITOR_F_PERSISTENT_CH,
103 monitor_subsys_database_init,
109 SLAPD_MONITOR_LISTENER_NAME,
110 BER_BVNULL, BER_BVNULL, BER_BVNULL,
111 { BER_BVC( "This subsystem contains information about active listeners." ),
113 MONITOR_F_PERSISTENT_CH,
114 monitor_subsys_listener_init,
120 SLAPD_MONITOR_LOG_NAME,
121 BER_BVNULL, BER_BVNULL, BER_BVNULL,
122 { BER_BVC( "This subsystem contains information about logging." ),
123 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
126 monitor_subsys_log_init,
132 SLAPD_MONITOR_OPS_NAME,
133 BER_BVNULL, BER_BVNULL, BER_BVNULL,
134 { BER_BVC( "This subsystem contains information about performed operations." ),
136 MONITOR_F_PERSISTENT_CH,
137 monitor_subsys_ops_init,
143 SLAPD_MONITOR_OVERLAY_NAME,
144 BER_BVNULL, BER_BVNULL, BER_BVNULL,
145 { BER_BVC( "This subsystem contains information about available overlays." ),
147 MONITOR_F_PERSISTENT_CH,
148 monitor_subsys_overlay_init,
154 SLAPD_MONITOR_SASL_NAME,
155 BER_BVNULL, BER_BVNULL, BER_BVNULL,
156 { BER_BVC( "This subsystem contains information about SASL." ),
165 SLAPD_MONITOR_SENT_NAME,
166 BER_BVNULL, BER_BVNULL, BER_BVNULL,
167 { BER_BVC( "This subsystem contains statistics." ),
169 MONITOR_F_PERSISTENT_CH,
170 monitor_subsys_sent_init,
176 SLAPD_MONITOR_THREAD_NAME,
177 BER_BVNULL, BER_BVNULL, BER_BVNULL,
178 { BER_BVC( "This subsystem contains information about threads." ),
180 MONITOR_F_PERSISTENT_CH,
181 monitor_subsys_thread_init,
187 SLAPD_MONITOR_TIME_NAME,
188 BER_BVNULL, BER_BVNULL, BER_BVNULL,
189 { BER_BVC( "This subsystem contains information about time." ),
191 MONITOR_F_PERSISTENT_CH,
192 monitor_subsys_time_init,
198 SLAPD_MONITOR_TLS_NAME,
199 BER_BVNULL, BER_BVNULL, BER_BVNULL,
200 { BER_BVC( "This subsystem contains information about TLS." ),
209 SLAPD_MONITOR_RWW_NAME,
210 BER_BVNULL, BER_BVNULL, BER_BVNULL,
211 { BER_BVC( "This subsystem contains information about read/write waiters." ),
213 MONITOR_F_PERSISTENT_CH,
214 monitor_subsys_rww_init,
223 monitor_back_register_subsys(
224 monitor_subsys_t *ms )
228 if ( monitor_subsys ) {
229 for ( ; monitor_subsys[ i ] != NULL; i++ )
230 /* just count'em */ ;
233 monitor_subsys = ch_realloc( monitor_subsys,
234 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
236 if ( monitor_subsys == NULL ) {
240 monitor_subsys[ i ] = ms;
241 monitor_subsys[ i + 1 ] = NULL;
243 /* if a subsystem is registered __AFTER__ subsystem
244 * initialization (depending on the sequence the databases
245 * are listed in slapd.conf), init it */
246 if ( monitor_subsys_opened ) {
248 /* FIXME: this should only be possible
249 * if be_monitor is already initialized */
250 assert( be_monitor != NULL );
252 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
256 ms->mss_flags |= MONITOR_F_OPENED;
269 typedef struct entry_limbo_t {
273 struct berval el_ndn;
274 struct berval el_nbase;
276 struct berval el_filter;
277 monitor_callback_t *el_cb;
278 monitor_subsys_t *el_mss;
279 unsigned long el_flags;
280 struct entry_limbo_t *el_next;
284 monitor_back_is_configured( void )
286 return be_monitor != NULL;
290 monitor_back_register_entry(
292 monitor_callback_t *cb,
293 monitor_subsys_t *mss,
294 unsigned long flags )
298 if ( be_monitor == NULL ) {
299 Debug( LDAP_DEBUG_ANY,
300 "monitor_back_register_entry(\"%s\"): "
301 "monitor database not configured.\n",
302 e->e_name.bv_val, 0, 0 );
306 mi = ( monitor_info_t * )be_monitor->be_private;
308 assert( mi != NULL );
310 assert( e->e_private == NULL );
312 if ( monitor_subsys_opened ) {
313 Entry *e_parent = NULL,
316 struct berval pdn = BER_BVNULL;
317 monitor_entry_t *mp = NULL,
321 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
323 Debug( LDAP_DEBUG_ANY,
324 "monitor_back_register_entry(\"%s\"): "
326 e->e_name.bv_val, 0, 0 );
327 monitor_cache_release( mi, e_parent );
331 dnParent( &e->e_nname, &pdn );
332 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
333 /* parent does not exist */
334 Debug( LDAP_DEBUG_ANY,
335 "monitor_back_register_entry(\"%s\"): "
336 "parent \"%s\" not found\n",
337 e->e_name.bv_val, pdn.bv_val, 0 );
341 assert( e_parent->e_private != NULL );
342 mp_parent = ( monitor_entry_t * )e_parent->e_private;
344 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
345 /* entry is volatile; cannot append children */
346 Debug( LDAP_DEBUG_ANY,
347 "monitor_back_register_entry(\"%s\"): "
348 "parent \"%s\" is volatile\n",
349 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
354 mp = monitor_entrypriv_create();
356 Debug( LDAP_DEBUG_ANY,
357 "monitor_back_register_entry(\"%s\"): "
358 "monitor_entrypriv_create() failed\n",
359 e->e_name.bv_val, 0, 0 );
364 e_new = entry_dup( e );
365 if ( e_new == NULL ) {
366 Debug( LDAP_DEBUG_ANY,
367 "monitor_back_register_entry(\"%s\"): "
368 "entry_dup() failed\n",
369 e->e_name.bv_val, 0, 0 );
374 e_new->e_private = ( void * )mp;
377 mp->mp_flags = flags;
380 mp->mp_info = mp_parent->mp_info;
381 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
385 ep = &mp_parent->mp_children;
387 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
388 ep = &mp_parent->mp_next;
392 if ( monitor_cache_add( mi, e_new ) ) {
393 Debug( LDAP_DEBUG_ANY,
394 "monitor_back_register_entry(\"%s\"): "
395 "unable to add entry\n",
396 e->e_name.bv_val, 0, 0 );
407 e_new->e_private = NULL;
413 monitor_cache_release( mi, e_parent );
417 entry_limbo_t **elpp, el = { 0 };
419 el.el_type = LIMBO_ENTRY;
421 el.el_e = entry_dup( e );
422 if ( el.el_e == NULL ) {
423 Debug( LDAP_DEBUG_ANY,
424 "monitor_back_register_entry(\"%s\"): "
425 "entry_dup() failed\n",
426 e->e_name.bv_val, 0, 0 );
434 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
436 elpp = &(*elpp)->el_next )
439 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
440 if ( *elpp == NULL ) {
441 el.el_e->e_private = NULL;
442 entry_free( el.el_e );
454 monitor_back_register_entry_parent(
456 monitor_callback_t *cb,
457 monitor_subsys_t *mss,
459 struct berval *nbase,
461 struct berval *filter )
464 struct berval ndn = BER_BVNULL;
466 if ( be_monitor == NULL ) {
467 Debug( LDAP_DEBUG_ANY,
468 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
469 "monitor database not configured.\n",
470 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
471 ldap_pvt_scope2str( scope ),
472 BER_BVISNULL( filter ) ? "" : filter->bv_val );
476 mi = ( monitor_info_t * )be_monitor->be_private;
478 assert( mi != NULL );
480 assert( e->e_private == NULL );
482 if ( BER_BVISNULL( filter ) ) {
484 Debug( LDAP_DEBUG_ANY,
485 "monitor_back_register_entry_parent(\"\"): "
486 "need a valid filter\n",
491 if ( monitor_subsys_opened ) {
492 Entry *e_parent = NULL,
495 struct berval e_name = BER_BVNULL,
496 e_nname = BER_BVNULL;
497 monitor_entry_t *mp = NULL,
501 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
502 /* entry does not exist */
503 Debug( LDAP_DEBUG_ANY,
504 "monitor_back_register_entry_parent(\"\"): "
505 "base=\"%s\" scope=%d filter=\"%s\": "
506 "unable to find entry\n",
507 nbase->bv_val ? nbase->bv_val : "\"\"",
508 scope, filter->bv_val );
512 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
513 /* entry does not exist */
514 Debug( LDAP_DEBUG_ANY,
515 "monitor_back_register_entry_parent(\"%s\"): "
516 "parent entry does not exist\n",
522 assert( e_parent->e_private != NULL );
523 mp_parent = ( monitor_entry_t * )e_parent->e_private;
525 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
526 /* entry is volatile; cannot append callback */
527 Debug( LDAP_DEBUG_ANY,
528 "monitor_back_register_entry_parent(\"%s\"): "
529 "entry is volatile\n",
530 e_parent->e_name.bv_val, 0, 0 );
535 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
536 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
538 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
539 /* entry already exists */
540 Debug( LDAP_DEBUG_ANY,
541 "monitor_back_register_entry_parent(\"%s\"): "
542 "entry already exists\n",
543 e_name.bv_val, 0, 0 );
544 monitor_cache_release( mi, e_new );
550 mp = monitor_entrypriv_create();
552 Debug( LDAP_DEBUG_ANY,
553 "monitor_back_register_entry_parent(\"%s\"): "
554 "monitor_entrypriv_create() failed\n",
555 e->e_name.bv_val, 0, 0 );
560 e_new = entry_dup( e );
561 if ( e_new == NULL ) {
562 Debug( LDAP_DEBUG_ANY,
563 "monitor_back_register_entry(\"%s\"): "
564 "entry_dup() failed\n",
565 e->e_name.bv_val, 0, 0 );
569 ch_free( e_new->e_name.bv_val );
570 ch_free( e_new->e_nname.bv_val );
571 e_new->e_name = e_name;
572 e_new->e_nname = e_nname;
574 e_new->e_private = ( void * )mp;
577 mp->mp_flags = flags;
580 mp->mp_info = mp_parent->mp_info;
581 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
585 ep = &mp_parent->mp_children;
587 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
588 ep = &mp_parent->mp_next;
592 if ( monitor_cache_add( mi, e_new ) ) {
593 Debug( LDAP_DEBUG_ANY,
594 "monitor_back_register_entry(\"%s\"): "
595 "unable to add entry\n",
596 e->e_name.bv_val, 0, 0 );
602 if ( !BER_BVISNULL( &ndn ) ) {
603 ch_free( ndn.bv_val );
611 e_new->e_private = NULL;
617 monitor_cache_release( mi, e_parent );
621 entry_limbo_t **elpp = NULL, el = { 0 };
623 el.el_type = LIMBO_ENTRY_PARENT;
625 el.el_e = entry_dup( e );
626 if ( el.el_e == NULL ) {
627 Debug( LDAP_DEBUG_ANY,
628 "monitor_back_register_entry(\"%s\"): "
629 "entry_dup() failed\n",
630 e->e_name.bv_val, 0, 0 );
634 if ( !BER_BVISNULL( nbase ) ) {
635 ber_dupbv( &el.el_nbase, nbase );
639 if ( !BER_BVISNULL( filter ) ) {
640 ber_dupbv( &el.el_filter, filter );
647 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
649 elpp = &(*elpp)->el_next )
652 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
653 if ( *elpp == NULL ) {
658 if ( *elpp != NULL ) {
663 if ( !BER_BVISNULL( &el.el_filter ) ) {
664 ch_free( el.el_filter.bv_val );
666 if ( !BER_BVISNULL( &el.el_nbase ) ) {
667 ch_free( el.el_nbase.bv_val );
669 entry_free( el.el_e );
678 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
680 if ( rs->sr_type == REP_SEARCH ) {
681 struct berval *ndn = op->o_callback->sc_private;
683 if ( !BER_BVISNULL( ndn ) ) {
684 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
685 ch_free( ndn->bv_val );
690 ber_dupbv( ndn, &rs->sr_entry->e_nname );
698 struct berval *nbase,
700 struct berval *filter,
703 Connection conn = { 0 };
704 OperationBuffer opbuf;
706 SlapReply rs = { 0 };
707 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
712 if ( be_monitor == NULL ) {
716 op = (Operation *) &opbuf;
717 connection_fake_init( &conn, op, &conn );
719 op->o_tag = LDAP_REQ_SEARCH;
721 /* use global malloc for now */
722 if ( op->o_tmpmemctx ) {
723 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
724 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
725 op->o_tmpmemctx = NULL;
727 op->o_tmpmfuncs = &ch_mfuncs;
729 op->o_bd = be_monitor;
730 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
731 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
733 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
737 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
738 op->o_tmpmemctx ) ) {
743 op->o_callback = &cb;
744 cb.sc_private = (void *)ndn;
746 op->ors_scope = scope;
747 op->ors_filter = str2filter_x( op, filter->bv_val );
748 if ( op->ors_filter == NULL ) {
752 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
753 op->ors_attrs = slap_anlist_no_attrs;
754 op->ors_attrsonly = 0;
755 op->ors_tlimit = SLAP_NO_LIMIT;
757 op->ors_limit = NULL;
758 op->ors_deref = LDAP_DEREF_NEVER;
761 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
763 op->o_dn = be_monitor->be_rootdn;
764 op->o_ndn = be_monitor->be_rootndn;
766 rc = op->o_bd->be_search( op, &rs );
769 if ( op->ors_filter != NULL ) {
770 filter_free_x( op, op->ors_filter );
772 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
773 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
775 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
776 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
778 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
779 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
786 switch ( rs.sr_err ) {
788 if ( BER_BVISNULL( ndn ) ) {
793 case LDAP_SIZELIMIT_EXCEEDED:
795 if ( !BER_BVISNULL( ndn ) ) {
796 ber_memfree( ndn->bv_val );
807 monitor_back_register_entry_attrs(
808 struct berval *ndn_in,
810 monitor_callback_t *cb,
811 struct berval *nbase,
813 struct berval *filter )
816 struct berval ndn = BER_BVNULL;
817 char *fname = ( a == NULL ? "callback" : "attrs" );
819 if ( be_monitor == NULL ) {
820 char buf[ SLAP_TEXT_BUFLEN ];
822 snprintf( buf, sizeof( buf ),
823 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
824 "monitor database not configured.\n",
826 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
827 ldap_pvt_scope2str( scope ),
828 BER_BVISNULL( filter ) ? "" : filter->bv_val );
829 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
834 mi = ( monitor_info_t * )be_monitor->be_private;
836 assert( mi != NULL );
838 if ( ndn_in != NULL ) {
842 if ( a == NULL && cb == NULL ) {
847 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
848 && BER_BVISNULL( filter ) )
851 Debug( LDAP_DEBUG_ANY,
852 "monitor_back_register_entry_%s(\"\"): "
853 "need a valid filter\n",
858 if ( monitor_subsys_opened ) {
860 Attribute **atp = NULL;
861 monitor_entry_t *mp = NULL;
862 monitor_callback_t **mcp = NULL;
866 if ( BER_BVISNULL( &ndn ) ) {
867 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
868 char buf[ SLAP_TEXT_BUFLEN ];
870 snprintf( buf, sizeof( buf ),
871 "monitor_back_register_entry_%s(\"\"): "
872 "base=\"%s\" scope=%d filter=\"%s\": "
873 "unable to find entry\n",
875 nbase->bv_val ? nbase->bv_val : "\"\"",
876 scope, filter->bv_val );
878 /* entry does not exist */
879 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
886 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
887 /* entry does not exist */
888 Debug( LDAP_DEBUG_ANY,
889 "monitor_back_register_entry_%s(\"%s\"): "
890 "entry does not exist\n",
891 fname, ndn.bv_val, 0 );
896 assert( e->e_private != NULL );
897 mp = ( monitor_entry_t * )e->e_private;
899 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
900 /* entry is volatile; cannot append callback */
901 Debug( LDAP_DEBUG_ANY,
902 "monitor_back_register_entry_%s(\"%s\"): "
903 "entry is volatile\n",
904 fname, e->e_name.bv_val, 0 );
910 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
911 /* just get to last */ ;
913 for ( ; a != NULL; a = a->a_next ) {
914 assert( a->a_desc != NULL );
915 assert( a->a_vals != NULL );
917 if ( attr_find( e->e_attrs, a->a_desc ) ) {
918 attr_merge( e, a->a_desc, a->a_vals,
919 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
922 *atp = attr_dup( a );
923 if ( *atp == NULL ) {
924 Debug( LDAP_DEBUG_ANY,
925 "monitor_back_register_entry_%s(\"%s\"): "
926 "attr_dup() failed\n",
927 fname, e->e_name.bv_val, 0 );
931 atp = &(*atp)->a_next;
937 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
940 /* NOTE: we do not clear cb->mc_next, so this function
941 * can be used to append a list of callbacks */
954 ber_memfree( ndn.bv_val );
958 monitor_cache_release( mi, e );
962 entry_limbo_t **elpp, el = { 0 };
964 el.el_type = LIMBO_ATTRS;
965 if ( !BER_BVISNULL( &ndn ) ) {
966 ber_dupbv( &el.el_ndn, &ndn );
968 if ( !BER_BVISNULL( nbase ) ) {
969 ber_dupbv( &el.el_nbase, nbase);
972 if ( !BER_BVISNULL( filter ) ) {
973 ber_dupbv( &el.el_filter, filter );
976 el.el_a = attrs_dup( a );
979 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
981 elpp = &(*elpp)->el_next )
984 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
985 if ( *elpp == NULL ) {
986 el.el_e->e_private = NULL;
987 entry_free( el.el_e );
992 if ( *elpp != NULL ) {
997 if ( !BER_BVISNULL( &el.el_filter ) ) {
998 ch_free( el.el_filter.bv_val );
1000 if ( el.el_a != NULL ) {
1001 attrs_free( el.el_a );
1003 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1004 ch_free( &el.el_nbase.bv_val );
1006 if ( !BER_BVISNULL( &el.el_ndn ) ) {
1007 ch_free( el.el_ndn.bv_val );
1017 monitor_back_register_entry_callback(
1019 monitor_callback_t *cb,
1020 struct berval *nbase,
1022 struct berval *filter )
1024 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1025 nbase, scope, filter );
1029 * TODO: add corresponding calls to remove installed callbacks, entries
1030 * and so, in case the entity that installed them is removed (e.g. a
1031 * database, via back-config)
1034 monitor_back_unregister_entry(
1035 struct berval *ndn )
1039 if ( be_monitor == NULL ) {
1040 Debug( LDAP_DEBUG_ANY,
1041 "monitor_back_unregister_entry(\"%s\"): "
1042 "monitor database not configured.\n",
1043 ndn->bv_val, 0, 0 );
1048 /* entry will be regularly freed, and resources released
1049 * according to callbacks */
1050 if ( slapd_shutdown ) {
1054 mi = ( monitor_info_t * )be_monitor->be_private;
1056 assert( mi != NULL );
1058 if ( monitor_subsys_opened ) {
1060 monitor_entry_t *mp = NULL;
1061 monitor_callback_t *cb = NULL;
1063 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1064 /* entry does not exist */
1065 Debug( LDAP_DEBUG_ANY,
1066 "monitor_back_unregister_entry(\"%s\"): "
1067 "entry removal failed.\n",
1068 ndn->bv_val, 0, 0 );
1072 mp = (monitor_entry_t *)e->e_private;
1073 assert( mp != NULL );
1075 for ( cb = mp->mp_cb; cb != NULL; ) {
1076 monitor_callback_t *next = cb->mc_next;
1078 if ( cb->mc_free ) {
1079 (void)cb->mc_free( e, cb->mc_private );
1087 e->e_private = NULL;
1091 entry_limbo_t **elpp;
1093 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1095 elpp = &(*elpp)->el_next )
1097 entry_limbo_t *elp = *elpp;
1099 if ( elp->el_type == LIMBO_ENTRY
1100 && dn_match( ndn, &elp->el_e->e_nname ) )
1102 monitor_callback_t *cb, *next;
1104 for ( cb = elp->el_cb; cb; cb = next ) {
1105 /* FIXME: call callbacks? */
1109 assert( elp->el_e != NULL );
1110 elp->el_e->e_private = NULL;
1111 entry_free( elp->el_e );
1112 *elpp = elp->el_next;
1119 if ( elpp != NULL ) {
1120 /* not found! where did it go? */
1129 monitor_back_unregister_entry_parent(
1130 struct berval *nrdn,
1131 monitor_callback_t *target_cb,
1132 struct berval *nbase,
1134 struct berval *filter )
1137 struct berval ndn = BER_BVNULL;
1139 if ( be_monitor == NULL ) {
1140 Debug( LDAP_DEBUG_ANY,
1141 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1142 "monitor database not configured.\n",
1143 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1144 ldap_pvt_scope2str( scope ),
1145 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1150 /* entry will be regularly freed, and resources released
1151 * according to callbacks */
1152 if ( slapd_shutdown ) {
1156 mi = ( monitor_info_t * )be_monitor->be_private;
1158 assert( mi != NULL );
1160 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1161 && BER_BVISNULL( filter ) )
1164 Debug( LDAP_DEBUG_ANY,
1165 "monitor_back_unregister_entry_parent(\"\"): "
1166 "need a valid filter\n",
1171 if ( monitor_subsys_opened ) {
1173 monitor_entry_t *mp = NULL;
1175 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1176 /* entry does not exist */
1177 Debug( LDAP_DEBUG_ANY,
1178 "monitor_back_unregister_entry_parent(\"\"): "
1179 "base=\"%s\" scope=%s filter=\"%s\": "
1180 "unable to find entry\n",
1181 nbase->bv_val ? nbase->bv_val : "\"\"",
1182 ldap_pvt_scope2str( scope ),
1187 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1188 /* entry does not exist */
1189 Debug( LDAP_DEBUG_ANY,
1190 "monitor_back_unregister_entry(\"%s\"): "
1191 "entry removal failed.\n",
1193 ber_memfree( ndn.bv_val );
1196 ber_memfree( ndn.bv_val );
1198 mp = (monitor_entry_t *)e->e_private;
1199 assert( mp != NULL );
1201 if ( target_cb != NULL ) {
1202 monitor_callback_t **cbp;
1204 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1205 if ( *cbp == target_cb ) {
1206 if ( (*cbp)->mc_free ) {
1207 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1209 *cbp = (*cbp)->mc_next;
1210 ch_free( target_cb );
1218 e->e_private = NULL;
1222 entry_limbo_t **elpp;
1224 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1226 elpp = &(*elpp)->el_next )
1228 entry_limbo_t *elp = *elpp;
1230 if ( elp->el_type == LIMBO_ENTRY_PARENT
1231 && dn_match( nrdn, &elp->el_e->e_nname )
1232 && dn_match( nbase, &elp->el_nbase )
1233 && scope == elp->el_scope
1234 && bvmatch( filter, &elp->el_filter ) )
1236 monitor_callback_t *cb, *next;
1238 for ( cb = elp->el_cb; cb; cb = next ) {
1239 /* FIXME: call callbacks? */
1243 assert( elp->el_e != NULL );
1244 elp->el_e->e_private = NULL;
1245 entry_free( elp->el_e );
1246 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1247 ch_free( elp->el_nbase.bv_val );
1249 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1250 ch_free( elp->el_filter.bv_val );
1252 *elpp = elp->el_next;
1259 if ( elpp != NULL ) {
1260 /* not found! where did it go? */
1269 monitor_back_unregister_entry_attrs(
1270 struct berval *ndn_in,
1271 Attribute *target_a,
1272 monitor_callback_t *target_cb,
1273 struct berval *nbase,
1275 struct berval *filter )
1278 struct berval ndn = BER_BVNULL;
1279 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1281 if ( be_monitor == NULL ) {
1282 char buf[ SLAP_TEXT_BUFLEN ];
1284 snprintf( buf, sizeof( buf ),
1285 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1286 "monitor database not configured.\n",
1288 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1289 ldap_pvt_scope2str( scope ),
1290 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1291 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1296 /* entry will be regularly freed, and resources released
1297 * according to callbacks */
1298 if ( slapd_shutdown ) {
1302 mi = ( monitor_info_t * )be_monitor->be_private;
1304 assert( mi != NULL );
1306 if ( ndn_in != NULL ) {
1310 if ( target_a == NULL && target_cb == NULL ) {
1315 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1316 && BER_BVISNULL( filter ) )
1319 Debug( LDAP_DEBUG_ANY,
1320 "monitor_back_unregister_entry_%s(\"\"): "
1321 "need a valid filter\n",
1326 if ( monitor_subsys_opened ) {
1328 monitor_entry_t *mp = NULL;
1331 if ( BER_BVISNULL( &ndn ) ) {
1332 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1333 char buf[ SLAP_TEXT_BUFLEN ];
1335 snprintf( buf, sizeof( buf ),
1336 "monitor_back_unregister_entry_%s(\"\"): "
1337 "base=\"%s\" scope=%d filter=\"%s\": "
1338 "unable to find entry\n",
1340 nbase->bv_val ? nbase->bv_val : "\"\"",
1341 scope, filter->bv_val );
1343 /* entry does not exist */
1344 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1351 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1352 /* entry does not exist */
1353 Debug( LDAP_DEBUG_ANY,
1354 "monitor_back_unregister_entry(\"%s\"): "
1355 "entry removal failed.\n",
1360 mp = (monitor_entry_t *)e->e_private;
1361 assert( mp != NULL );
1363 if ( target_cb != NULL ) {
1364 monitor_callback_t **cbp;
1366 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1367 if ( *cbp == target_cb ) {
1368 if ( (*cbp)->mc_free ) {
1369 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1371 *cbp = (*cbp)->mc_next;
1372 ch_free( target_cb );
1378 if ( target_a != NULL ) {
1381 for ( a = target_a; a != NULL; a = a->a_next ) {
1382 Modification mod = { 0 };
1384 char textbuf[ SLAP_TEXT_BUFLEN ];
1386 mod.sm_op = LDAP_MOD_DELETE;
1387 mod.sm_desc = a->a_desc;
1388 mod.sm_values = a->a_vals;
1389 mod.sm_nvalues = a->a_nvals;
1391 (void)modify_delete_values( e, &mod, 1,
1392 &text, textbuf, sizeof( textbuf ) );
1397 ber_memfree( ndn.bv_val );
1401 monitor_cache_release( mi, e );
1405 entry_limbo_t **elpp;
1407 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1409 elpp = &(*elpp)->el_next )
1411 entry_limbo_t *elp = *elpp;
1413 if ( elp->el_type == LIMBO_ATTRS
1414 && dn_match( nbase, &elp->el_nbase )
1415 && scope == elp->el_scope
1416 && bvmatch( filter, &elp->el_filter ) )
1418 monitor_callback_t *cb, *next;
1420 for ( cb = elp->el_cb; cb; cb = next ) {
1421 /* FIXME: call callbacks? */
1425 assert( elp->el_e == NULL );
1426 if ( elp->el_a != NULL ) {
1427 attrs_free( elp->el_a );
1429 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1430 ch_free( elp->el_nbase.bv_val );
1432 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1433 ch_free( elp->el_filter.bv_val );
1435 *elpp = elp->el_next;
1442 if ( elpp != NULL ) {
1443 /* not found! where did it go? */
1452 monitor_back_unregister_entry_callback(
1454 monitor_callback_t *cb,
1455 struct berval *nbase,
1457 struct berval *filter )
1459 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1460 * unregister the callback; if a is not null, unregister the
1461 * given attrs. In any case, call cb->cb_free */
1462 return monitor_back_unregister_entry_attrs( ndn,
1463 NULL, cb, nbase, scope, filter );
1467 monitor_back_get_subsys( const char *name )
1469 if ( monitor_subsys != NULL ) {
1472 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1473 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1474 return monitor_subsys[ i ];
1483 monitor_back_get_subsys_by_dn(
1487 if ( monitor_subsys != NULL ) {
1491 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1492 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1493 return monitor_subsys[ i ];
1498 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1499 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1500 return monitor_subsys[ i ];
1510 monitor_back_initialize(
1513 static char *controls[] = {
1514 LDAP_CONTROL_MANAGEDSAIT,
1518 static ConfigTable monitorcfg[] = {
1519 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1520 NULL, NULL, NULL, NULL }
1523 static ConfigOCs monitorocs[] = {
1524 { "( OLcfgDbOc:4.1 "
1525 "NAME 'olcMonitorConfig' "
1526 "DESC 'Monitor backend configuration' "
1527 "SUP olcDatabaseConfig "
1529 Cft_Database, monitorcfg },
1538 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1540 "DESC 'OpenLDAP system monitoring' "
1541 "SUP top STRUCTURAL "
1550 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1551 offsetof(monitor_info_t, mi_oc_monitor) },
1552 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1553 "NAME 'monitorServer' "
1554 "DESC 'Server monitoring root entry' "
1555 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1556 offsetof(monitor_info_t, mi_oc_monitorServer) },
1557 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1558 "NAME 'monitorContainer' "
1559 "DESC 'monitor container class' "
1560 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1561 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1562 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1563 "NAME 'monitorCounterObject' "
1564 "DESC 'monitor counter class' "
1565 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1566 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1567 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1568 "NAME 'monitorOperation' "
1569 "DESC 'monitor operation class' "
1570 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1571 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1572 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1573 "NAME 'monitorConnection' "
1574 "DESC 'monitor connection class' "
1575 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1576 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1577 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1578 "NAME 'managedObject' "
1579 "DESC 'monitor managed entity class' "
1580 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1581 offsetof(monitor_info_t, mi_oc_managedObject) },
1582 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1583 "NAME 'monitoredObject' "
1584 "DESC 'monitor monitored entity class' "
1585 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1586 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1589 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1590 "NAME 'monitoredInfo' "
1591 "DESC 'monitored info' "
1593 "EQUALITY caseIgnoreMatch "
1594 "SUBSTR caseIgnoreSubstringsMatch "
1595 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1596 "NO-USER-MODIFICATION "
1597 "USAGE directoryOperation )", SLAP_AT_HIDE,
1598 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1599 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1600 "NAME 'managedInfo' "
1601 "DESC 'monitor managed info' "
1602 "SUP name )", SLAP_AT_HIDE,
1603 offsetof(monitor_info_t, mi_ad_managedInfo) },
1604 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1605 "NAME 'monitorCounter' "
1606 "DESC 'monitor counter' "
1607 "EQUALITY integerMatch "
1608 "ORDERING integerOrderingMatch "
1609 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1610 "NO-USER-MODIFICATION "
1611 "USAGE directoryOperation )", SLAP_AT_HIDE,
1612 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1613 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1614 "NAME 'monitorOpCompleted' "
1615 "DESC 'monitor completed operations' "
1616 "SUP monitorCounter "
1617 "NO-USER-MODIFICATION "
1618 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1619 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1620 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1621 "NAME 'monitorOpInitiated' "
1622 "DESC 'monitor initiated operations' "
1623 "SUP monitorCounter "
1624 "NO-USER-MODIFICATION "
1625 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1626 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1627 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1628 "NAME 'monitorConnectionNumber' "
1629 "DESC 'monitor connection number' "
1630 "SUP monitorCounter "
1631 "NO-USER-MODIFICATION "
1632 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1633 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1634 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1635 "NAME 'monitorConnectionAuthzDN' "
1636 "DESC 'monitor connection authorization DN' "
1637 /* "SUP distinguishedName " */
1638 "EQUALITY distinguishedNameMatch "
1639 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1640 "NO-USER-MODIFICATION "
1641 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1642 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1643 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1644 "NAME 'monitorConnectionLocalAddress' "
1645 "DESC 'monitor connection local address' "
1646 "SUP monitoredInfo "
1647 "NO-USER-MODIFICATION "
1648 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1649 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1650 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1651 "NAME 'monitorConnectionPeerAddress' "
1652 "DESC 'monitor connection peer address' "
1653 "SUP monitoredInfo "
1654 "NO-USER-MODIFICATION "
1655 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1656 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1657 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1658 "NAME 'monitorTimestamp' "
1659 "DESC 'monitor timestamp' "
1660 "EQUALITY generalizedTimeMatch "
1661 "ORDERING generalizedTimeOrderingMatch "
1662 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1664 "NO-USER-MODIFICATION "
1665 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1666 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1667 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1668 "NAME 'monitorOverlay' "
1669 "DESC 'name of overlays defined for a given database' "
1670 "SUP monitoredInfo "
1671 "NO-USER-MODIFICATION "
1672 "USAGE directoryOperation )", SLAP_AT_HIDE,
1673 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1674 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1676 "DESC 'read/write status of a given database' "
1677 "EQUALITY booleanMatch "
1678 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1680 "USAGE directoryOperation )", SLAP_AT_HIDE,
1681 offsetof(monitor_info_t, mi_ad_readOnly) },
1682 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1683 "NAME 'restrictedOperation' "
1684 "DESC 'name of restricted operation for a given database' "
1685 "SUP managedInfo )", SLAP_AT_HIDE,
1686 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1687 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1688 "NAME 'monitorConnectionProtocol' "
1689 "DESC 'monitor connection protocol' "
1690 "SUP monitoredInfo "
1691 "NO-USER-MODIFICATION "
1692 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1693 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1694 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1695 "NAME 'monitorConnectionOpsReceived' "
1696 "DESC 'monitor number of operations received by the connection' "
1697 "SUP monitorCounter "
1698 "NO-USER-MODIFICATION "
1699 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1700 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1701 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1702 "NAME 'monitorConnectionOpsExecuting' "
1703 "DESC 'monitor number of operations in execution within the connection' "
1704 "SUP monitorCounter "
1705 "NO-USER-MODIFICATION "
1706 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1707 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1708 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1709 "NAME 'monitorConnectionOpsPending' "
1710 "DESC 'monitor number of pending operations within the connection' "
1711 "SUP monitorCounter "
1712 "NO-USER-MODIFICATION "
1713 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1714 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1715 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1716 "NAME 'monitorConnectionOpsCompleted' "
1717 "DESC 'monitor number of operations completed within the connection' "
1718 "SUP monitorCounter "
1719 "NO-USER-MODIFICATION "
1720 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1721 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1722 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1723 "NAME 'monitorConnectionGet' "
1724 "DESC 'number of times connection_get() was called so far' "
1725 "SUP monitorCounter "
1726 "NO-USER-MODIFICATION "
1727 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1728 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1729 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1730 "NAME 'monitorConnectionRead' "
1731 "DESC 'number of times connection_read() was called so far' "
1732 "SUP monitorCounter "
1733 "NO-USER-MODIFICATION "
1734 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1735 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1736 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1737 "NAME 'monitorConnectionWrite' "
1738 "DESC 'number of times connection_write() was called so far' "
1739 "SUP monitorCounter "
1740 "NO-USER-MODIFICATION "
1741 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1742 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1743 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1744 "NAME 'monitorConnectionMask' "
1745 "DESC 'monitor connection mask' "
1746 "SUP monitoredInfo "
1747 "NO-USER-MODIFICATION "
1748 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1749 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1750 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1751 "NAME 'monitorConnectionListener' "
1752 "DESC 'monitor connection listener' "
1753 "SUP monitoredInfo "
1754 "NO-USER-MODIFICATION "
1755 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1756 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1757 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1758 "NAME 'monitorConnectionPeerDomain' "
1759 "DESC 'monitor connection peer domain' "
1760 "SUP monitoredInfo "
1761 "NO-USER-MODIFICATION "
1762 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1763 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1764 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1765 "NAME 'monitorConnectionStartTime' "
1766 "DESC 'monitor connection start time' "
1767 "SUP monitorTimestamp "
1769 "NO-USER-MODIFICATION "
1770 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1771 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1772 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1773 "NAME 'monitorConnectionActivityTime' "
1774 "DESC 'monitor connection activity time' "
1775 "SUP monitorTimestamp "
1777 "NO-USER-MODIFICATION "
1778 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1779 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1780 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1781 "NAME 'monitorIsShadow' "
1782 "DESC 'TRUE if the database is shadow' "
1783 "EQUALITY booleanMatch "
1784 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1786 "USAGE directoryOperation )", SLAP_AT_HIDE,
1787 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1788 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1789 "NAME 'monitorUpdateRef' "
1790 "DESC 'update referral for shadow databases' "
1791 "SUP monitoredInfo "
1793 "USAGE directoryOperation )", SLAP_AT_HIDE,
1794 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1795 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1796 "NAME 'monitorRuntimeConfig' "
1797 "DESC 'TRUE if component allows runtime configuration' "
1798 "EQUALITY booleanMatch "
1799 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1801 "USAGE directoryOperation )", SLAP_AT_HIDE,
1802 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1810 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1811 { "olmSubSystemAttributes", "olmAttributes:0" },
1812 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1813 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1815 /* for example, back-bdb specific attrs
1816 * are in "olmDatabaseAttributes:1"
1818 * NOTE: developers, please record here OID assignments
1819 * for other modules */
1821 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1822 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1823 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1824 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1826 /* for example, back-bdb specific objectClasses
1827 * are in "olmDatabaseObjectClasses:1"
1829 * NOTE: developers, please record here OID assignments
1830 * for other modules */
1837 monitor_info_t *mi = &monitor_info;
1839 for ( i = 0; s_oid[ i ].name; i++ ) {
1842 argv[ 0 ] = "monitor";
1843 argv[ 1 ] = s_oid[ i ].name;
1844 argv[ 2 ] = s_oid[ i ].oid;
1846 if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) {
1847 Debug( LDAP_DEBUG_ANY,
1848 "monitor_back_initialize: unable to add "
1849 "objectIdentifier \"%s=%s\"\n",
1850 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1855 /* schema integration */
1856 for ( i = 0; mat[ i ].schema; i++ ) {
1858 AttributeDescription **ad =
1859 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1862 code = register_at( mat[ i ].schema, ad, 0 );
1865 Debug( LDAP_DEBUG_ANY,
1866 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1869 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1872 for ( i = 0; moc[ i ].schema; i++ ) {
1875 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1877 code = register_oc( moc[ i ].schema, Oc, 0 );
1879 Debug( LDAP_DEBUG_ANY,
1880 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1883 (*Oc)->soc_flags |= moc[ i ].flags;
1886 bi->bi_controls = controls;
1890 bi->bi_config = monitor_back_config;
1894 bi->bi_db_init = monitor_back_db_init;
1896 bi->bi_db_config = monitor_back_db_config;
1898 bi->bi_db_open = monitor_back_db_open;
1899 bi->bi_db_close = 0;
1900 bi->bi_db_destroy = monitor_back_db_destroy;
1902 bi->bi_op_bind = monitor_back_bind;
1903 bi->bi_op_unbind = 0;
1904 bi->bi_op_search = monitor_back_search;
1905 bi->bi_op_compare = monitor_back_compare;
1906 bi->bi_op_modify = monitor_back_modify;
1907 bi->bi_op_modrdn = 0;
1909 bi->bi_op_delete = 0;
1910 bi->bi_op_abandon = 0;
1912 bi->bi_extended = 0;
1914 bi->bi_entry_release_rw = 0;
1915 bi->bi_chk_referrals = 0;
1916 bi->bi_operational = monitor_back_operational;
1919 * hooks for slap tools
1921 bi->bi_tool_entry_open = 0;
1922 bi->bi_tool_entry_close = 0;
1923 bi->bi_tool_entry_first = 0;
1924 bi->bi_tool_entry_next = 0;
1925 bi->bi_tool_entry_get = 0;
1926 bi->bi_tool_entry_put = 0;
1927 bi->bi_tool_entry_reindex = 0;
1928 bi->bi_tool_sync = 0;
1929 bi->bi_tool_dn2id_get = 0;
1930 bi->bi_tool_id2entry_get = 0;
1931 bi->bi_tool_entry_modify = 0;
1933 bi->bi_connection_init = 0;
1934 bi->bi_connection_destroy = 0;
1936 bi->bi_extra = (void *)&monitor_extra;
1939 * configuration objectClasses (fake)
1941 bi->bi_cf_ocs = monitorocs;
1943 rc = config_register_schema( monitorcfg, monitorocs );
1952 monitor_back_db_init(
1956 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1961 monitor_subsys_t *ms;
1966 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1967 if ( monitor_back_register_subsys( ms ) ) {
1973 * database monitor can be defined once only
1975 if ( be_monitor != NULL ) {
1976 Debug( LDAP_DEBUG_ANY,
1977 "only one monitor database is allowed\n", 0, 0, 0 );
1982 /* indicate system schema supported */
1983 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1985 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1986 if( rc != LDAP_SUCCESS ) {
1987 Debug( LDAP_DEBUG_ANY,
1988 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
1993 ber_bvarray_add( &be->be_suffix, &pdn );
1994 ber_bvarray_add( &be->be_nsuffix, &ndn );
1996 /* NOTE: only one monitor database is allowed,
1997 * so we use static storage */
1998 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2000 be->be_private = &monitor_info;
2002 be2 = select_backend( &ndn, 0, 0 );
2004 char *type = be2->bd_info->bi_type;
2006 if ( overlay_is_over( be2 ) ) {
2007 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2008 type = oi->oi_orig->bi_type;
2011 Debug( LDAP_DEBUG_ANY,
2012 "\"monitor\" database serving namingContext \"%s\" "
2013 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2014 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2022 monitor_back_db_open(
2025 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2026 struct monitor_subsys_t **ms;
2027 Entry *e, **ep, *root;
2028 monitor_entry_t *mp;
2030 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2032 #ifdef HAVE_GMTIME_R
2035 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2036 struct berval desc[] = {
2037 BER_BVC("This subtree contains monitoring/managing objects."),
2038 BER_BVC("This object contains information about this server."),
2039 BER_BVC("Most of the information is held in operational"
2040 " attributes, which must be explicitly requested."),
2043 assert( be_monitor != NULL );
2044 if ( be != be_monitor ) {
2051 #ifndef HAVE_GMTIME_R
2052 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2054 #ifdef HACK_LOCAL_TIME
2055 # ifdef HAVE_LOCALTIME_R
2056 tms = localtime_r( &starttime, &tm_buf );
2058 tms = localtime( &starttime );
2059 # endif /* HAVE_LOCALTIME_R */
2060 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2061 #else /* !HACK_LOCAL_TIME */
2062 # ifdef HAVE_GMTIME_R
2063 tms = gmtime_r( &starttime, &tm_buf );
2065 tms = gmtime( &starttime );
2066 # endif /* HAVE_GMTIME_R */
2067 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2068 #endif /* !HACK_LOCAL_TIME */
2069 #ifndef HAVE_GMTIME_R
2070 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2073 mi->mi_startTime.bv_val = tmbuf;
2074 mi->mi_startTime.bv_len = strlen( tmbuf );
2076 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2077 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2078 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2080 mi->mi_creatorsName = be->be_rootdn;
2081 mi->mi_ncreatorsName = be->be_rootndn;
2085 * creates the "cn=Monitor" entry
2087 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2091 Debug( LDAP_DEBUG_ANY,
2092 "unable to create \"%s\" entry\n",
2093 SLAPD_MONITOR_DN, 0, 0 );
2097 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2099 bv.bv_val = strchr( (char *) Versionstr, '$' );
2100 if ( bv.bv_val != NULL ) {
2104 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2107 end = strchr( bv.bv_val, '$' );
2108 if ( end != NULL ) {
2111 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2116 bv.bv_len = end - bv.bv_val;
2119 bv.bv_len = strlen( bv.bv_val );
2122 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2124 Debug( LDAP_DEBUG_ANY,
2125 "unable to add monitoredInfo to \"%s\" entry\n",
2126 SLAPD_MONITOR_DN, 0, 0 );
2131 mp = monitor_entrypriv_create();
2135 e->e_private = ( void * )mp;
2136 ep = &mp->mp_children;
2138 if ( monitor_cache_add( mi, e ) ) {
2139 Debug( LDAP_DEBUG_ANY,
2140 "unable to add entry \"%s\" to cache\n",
2141 SLAPD_MONITOR_DN, 0, 0 );
2147 * Create all the subsystem specific entries
2149 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2150 int len = strlen( monitor_subsys[ i ]->mss_name );
2154 dn.bv_len = len + sizeof( "cn=" ) - 1;
2155 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2156 strcpy( dn.bv_val, "cn=" );
2157 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2158 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2160 if ( rc != LDAP_SUCCESS ) {
2161 Debug( LDAP_DEBUG_ANY,
2162 "monitor RDN \"%s\" is invalid\n",
2167 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2168 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2172 Debug( LDAP_DEBUG_ANY,
2173 "unable to create \"%s\" entry\n",
2174 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2177 monitor_subsys[i]->mss_dn = e->e_name;
2178 monitor_subsys[i]->mss_ndn = e->e_nname;
2180 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2181 attr_merge_normalize( e, slap_schema.si_ad_description,
2182 monitor_subsys[ i ]->mss_desc, NULL );
2185 mp = monitor_entrypriv_create();
2189 e->e_private = ( void * )mp;
2190 mp->mp_info = monitor_subsys[ i ];
2191 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2193 if ( monitor_cache_add( mi, e ) ) {
2194 Debug( LDAP_DEBUG_ANY,
2195 "unable to add entry \"%s\" to cache\n",
2196 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2204 assert( be != NULL );
2206 be->be_private = mi;
2209 * opens the monitor backend subsystems
2211 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2212 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2216 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2219 monitor_subsys_opened = 1;
2221 if ( mi->mi_entry_limbo ) {
2222 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
2227 switch ( el->el_type ) {
2229 monitor_back_register_entry(
2236 case LIMBO_ENTRY_PARENT:
2237 monitor_back_register_entry_parent(
2249 monitor_back_register_entry_attrs(
2259 monitor_back_register_entry_callback(
2272 entry_free( el->el_e );
2275 attrs_free( el->el_a );
2277 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2278 ber_memfree( el->el_ndn.bv_val );
2280 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2281 ber_memfree( el->el_nbase.bv_val );
2283 if ( !BER_BVISNULL( &el->el_filter ) ) {
2284 ber_memfree( el->el_filter.bv_val );
2292 mi->mi_entry_limbo = NULL;
2299 monitor_back_config(
2307 * eventually, will hold backend specific configuration parameters
2309 return SLAP_CONF_UNKNOWN;
2314 monitor_back_db_config(
2321 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2324 * eventually, will hold database specific configuration parameters
2326 return SLAP_CONF_UNKNOWN;
2331 monitor_back_db_destroy(
2334 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2341 * FIXME: destroys all the data
2343 /* NOTE: mi points to static storage; don't free it */
2345 (void)monitor_cache_destroy( mi );
2347 if ( monitor_subsys ) {
2350 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2351 if ( monitor_subsys[ i ]->mss_destroy ) {
2352 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2355 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2356 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2360 ch_free( monitor_subsys );
2363 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2365 be->be_private = NULL;
2370 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2372 /* conditionally define the init_module() function */
2373 SLAP_BACKEND_INIT_MODULE( monitor )
2375 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */