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=%s filter=\"%s\": "
506 "unable to find entry\n",
507 nbase->bv_val ? nbase->bv_val : "\"\"",
508 ldap_pvt_scope2str( scope ),
513 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
514 /* entry does not exist */
515 Debug( LDAP_DEBUG_ANY,
516 "monitor_back_register_entry_parent(\"%s\"): "
517 "parent entry does not exist\n",
523 assert( e_parent->e_private != NULL );
524 mp_parent = ( monitor_entry_t * )e_parent->e_private;
526 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
527 /* entry is volatile; cannot append callback */
528 Debug( LDAP_DEBUG_ANY,
529 "monitor_back_register_entry_parent(\"%s\"): "
530 "entry is volatile\n",
531 e_parent->e_name.bv_val, 0, 0 );
536 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
537 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
539 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
540 /* entry already exists */
541 Debug( LDAP_DEBUG_ANY,
542 "monitor_back_register_entry_parent(\"%s\"): "
543 "entry already exists\n",
544 e_name.bv_val, 0, 0 );
545 monitor_cache_release( mi, e_new );
551 mp = monitor_entrypriv_create();
553 Debug( LDAP_DEBUG_ANY,
554 "monitor_back_register_entry_parent(\"%s\"): "
555 "monitor_entrypriv_create() failed\n",
556 e->e_name.bv_val, 0, 0 );
561 e_new = entry_dup( e );
562 if ( e_new == NULL ) {
563 Debug( LDAP_DEBUG_ANY,
564 "monitor_back_register_entry(\"%s\"): "
565 "entry_dup() failed\n",
566 e->e_name.bv_val, 0, 0 );
570 ch_free( e_new->e_name.bv_val );
571 ch_free( e_new->e_nname.bv_val );
572 e_new->e_name = e_name;
573 e_new->e_nname = e_nname;
575 e_new->e_private = ( void * )mp;
578 mp->mp_flags = flags;
581 mp->mp_info = mp_parent->mp_info;
582 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
586 ep = &mp_parent->mp_children;
588 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
589 ep = &mp_parent->mp_next;
593 if ( monitor_cache_add( mi, e_new ) ) {
594 Debug( LDAP_DEBUG_ANY,
595 "monitor_back_register_entry(\"%s\"): "
596 "unable to add entry\n",
597 e->e_name.bv_val, 0, 0 );
603 if ( !BER_BVISNULL( &ndn ) ) {
604 ch_free( ndn.bv_val );
612 e_new->e_private = NULL;
618 monitor_cache_release( mi, e_parent );
622 entry_limbo_t **elpp = NULL, el = { 0 };
624 el.el_type = LIMBO_ENTRY_PARENT;
626 el.el_e = entry_dup( e );
627 if ( el.el_e == NULL ) {
628 Debug( LDAP_DEBUG_ANY,
629 "monitor_back_register_entry(\"%s\"): "
630 "entry_dup() failed\n",
631 e->e_name.bv_val, 0, 0 );
635 if ( !BER_BVISNULL( nbase ) ) {
636 ber_dupbv( &el.el_nbase, nbase );
640 if ( !BER_BVISNULL( filter ) ) {
641 ber_dupbv( &el.el_filter, filter );
648 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
650 elpp = &(*elpp)->el_next )
653 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
654 if ( *elpp == NULL ) {
659 if ( *elpp != NULL ) {
664 if ( !BER_BVISNULL( &el.el_filter ) ) {
665 ch_free( el.el_filter.bv_val );
667 if ( !BER_BVISNULL( &el.el_nbase ) ) {
668 ch_free( el.el_nbase.bv_val );
670 entry_free( el.el_e );
679 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
681 if ( rs->sr_type == REP_SEARCH ) {
682 struct berval *ndn = op->o_callback->sc_private;
684 if ( !BER_BVISNULL( ndn ) ) {
685 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
686 ch_free( ndn->bv_val );
691 ber_dupbv( ndn, &rs->sr_entry->e_nname );
699 struct berval *nbase,
701 struct berval *filter,
704 Connection conn = { 0 };
705 OperationBuffer opbuf;
707 SlapReply rs = { 0 };
708 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
713 if ( be_monitor == NULL ) {
717 op = (Operation *) &opbuf;
718 connection_fake_init( &conn, op, &conn );
720 op->o_tag = LDAP_REQ_SEARCH;
722 /* use global malloc for now */
723 if ( op->o_tmpmemctx ) {
724 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
725 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
726 op->o_tmpmemctx = NULL;
728 op->o_tmpmfuncs = &ch_mfuncs;
730 op->o_bd = be_monitor;
731 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
732 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
734 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
738 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
739 op->o_tmpmemctx ) ) {
744 op->o_callback = &cb;
745 cb.sc_private = (void *)ndn;
747 op->ors_scope = scope;
748 op->ors_filter = str2filter_x( op, filter->bv_val );
749 if ( op->ors_filter == NULL ) {
753 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
754 op->ors_attrs = slap_anlist_no_attrs;
755 op->ors_attrsonly = 0;
756 op->ors_tlimit = SLAP_NO_LIMIT;
758 op->ors_limit = NULL;
759 op->ors_deref = LDAP_DEREF_NEVER;
762 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
764 op->o_dn = be_monitor->be_rootdn;
765 op->o_ndn = be_monitor->be_rootndn;
767 rc = op->o_bd->be_search( op, &rs );
770 if ( op->ors_filter != NULL ) {
771 filter_free_x( op, op->ors_filter );
773 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
774 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
776 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
777 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
779 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
780 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
787 switch ( rs.sr_err ) {
789 if ( BER_BVISNULL( ndn ) ) {
794 case LDAP_SIZELIMIT_EXCEEDED:
796 if ( !BER_BVISNULL( ndn ) ) {
797 ber_memfree( ndn->bv_val );
808 monitor_back_register_entry_attrs(
809 struct berval *ndn_in,
811 monitor_callback_t *cb,
812 struct berval *nbase,
814 struct berval *filter )
817 struct berval ndn = BER_BVNULL;
818 char *fname = ( a == NULL ? "callback" : "attrs" );
820 if ( be_monitor == NULL ) {
821 char buf[ SLAP_TEXT_BUFLEN ];
823 snprintf( buf, sizeof( buf ),
824 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
825 "monitor database not configured.\n",
827 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
828 ldap_pvt_scope2str( scope ),
829 BER_BVISNULL( filter ) ? "" : filter->bv_val );
830 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
835 mi = ( monitor_info_t * )be_monitor->be_private;
837 assert( mi != NULL );
839 if ( ndn_in != NULL ) {
843 if ( a == NULL && cb == NULL ) {
848 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
849 && BER_BVISNULL( filter ) )
852 Debug( LDAP_DEBUG_ANY,
853 "monitor_back_register_entry_%s(\"\"): "
854 "need a valid filter\n",
859 if ( monitor_subsys_opened ) {
861 Attribute **atp = NULL;
862 monitor_entry_t *mp = NULL;
863 monitor_callback_t **mcp = NULL;
867 if ( BER_BVISNULL( &ndn ) ) {
868 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
869 char buf[ SLAP_TEXT_BUFLEN ];
871 snprintf( buf, sizeof( buf ),
872 "monitor_back_register_entry_%s(\"\"): "
873 "base=\"%s\" scope=%s filter=\"%s\": "
874 "unable to find entry\n",
876 nbase->bv_val ? nbase->bv_val : "\"\"",
877 ldap_pvt_scope2str( scope ),
880 /* entry does not exist */
881 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
888 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
889 /* entry does not exist */
890 Debug( LDAP_DEBUG_ANY,
891 "monitor_back_register_entry_%s(\"%s\"): "
892 "entry does not exist\n",
893 fname, ndn.bv_val, 0 );
898 assert( e->e_private != NULL );
899 mp = ( monitor_entry_t * )e->e_private;
901 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
902 /* entry is volatile; cannot append callback */
903 Debug( LDAP_DEBUG_ANY,
904 "monitor_back_register_entry_%s(\"%s\"): "
905 "entry is volatile\n",
906 fname, e->e_name.bv_val, 0 );
912 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
913 /* just get to last */ ;
915 for ( ; a != NULL; a = a->a_next ) {
916 assert( a->a_desc != NULL );
917 assert( a->a_vals != NULL );
919 if ( attr_find( e->e_attrs, a->a_desc ) ) {
920 attr_merge( e, a->a_desc, a->a_vals,
921 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
924 *atp = attr_dup( a );
925 if ( *atp == NULL ) {
926 Debug( LDAP_DEBUG_ANY,
927 "monitor_back_register_entry_%s(\"%s\"): "
928 "attr_dup() failed\n",
929 fname, e->e_name.bv_val, 0 );
933 atp = &(*atp)->a_next;
939 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
942 /* NOTE: we do not clear cb->mc_next, so this function
943 * can be used to append a list of callbacks */
956 ber_memfree( ndn.bv_val );
960 monitor_cache_release( mi, e );
964 entry_limbo_t **elpp, el = { 0 };
966 el.el_type = LIMBO_ATTRS;
967 if ( !BER_BVISNULL( &ndn ) ) {
968 ber_dupbv( &el.el_ndn, &ndn );
970 if ( !BER_BVISNULL( nbase ) ) {
971 ber_dupbv( &el.el_nbase, nbase);
974 if ( !BER_BVISNULL( filter ) ) {
975 ber_dupbv( &el.el_filter, filter );
978 el.el_a = attrs_dup( a );
981 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
983 elpp = &(*elpp)->el_next )
986 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
987 if ( *elpp == NULL ) {
988 el.el_e->e_private = NULL;
989 entry_free( el.el_e );
994 if ( *elpp != NULL ) {
999 if ( !BER_BVISNULL( &el.el_filter ) ) {
1000 ch_free( el.el_filter.bv_val );
1002 if ( el.el_a != NULL ) {
1003 attrs_free( el.el_a );
1005 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1006 ch_free( &el.el_nbase.bv_val );
1008 if ( !BER_BVISNULL( &el.el_ndn ) ) {
1009 ch_free( el.el_ndn.bv_val );
1019 monitor_back_register_entry_callback(
1021 monitor_callback_t *cb,
1022 struct berval *nbase,
1024 struct berval *filter )
1026 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1027 nbase, scope, filter );
1031 * TODO: add corresponding calls to remove installed callbacks, entries
1032 * and so, in case the entity that installed them is removed (e.g. a
1033 * database, via back-config)
1036 monitor_back_unregister_entry(
1037 struct berval *ndn )
1041 if ( be_monitor == NULL ) {
1042 Debug( LDAP_DEBUG_ANY,
1043 "monitor_back_unregister_entry(\"%s\"): "
1044 "monitor database not configured.\n",
1045 ndn->bv_val, 0, 0 );
1050 /* entry will be regularly freed, and resources released
1051 * according to callbacks */
1052 if ( slapd_shutdown ) {
1056 mi = ( monitor_info_t * )be_monitor->be_private;
1058 assert( mi != NULL );
1060 if ( monitor_subsys_opened ) {
1062 monitor_entry_t *mp = NULL;
1063 monitor_callback_t *cb = NULL;
1065 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1066 /* entry does not exist */
1067 Debug( LDAP_DEBUG_ANY,
1068 "monitor_back_unregister_entry(\"%s\"): "
1069 "entry removal failed.\n",
1070 ndn->bv_val, 0, 0 );
1074 mp = (monitor_entry_t *)e->e_private;
1075 assert( mp != NULL );
1077 for ( cb = mp->mp_cb; cb != NULL; ) {
1078 monitor_callback_t *next = cb->mc_next;
1080 if ( cb->mc_free ) {
1081 (void)cb->mc_free( e, cb->mc_private );
1089 e->e_private = NULL;
1093 entry_limbo_t **elpp;
1095 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1097 elpp = &(*elpp)->el_next )
1099 entry_limbo_t *elp = *elpp;
1101 if ( elp->el_type == LIMBO_ENTRY
1102 && dn_match( ndn, &elp->el_e->e_nname ) )
1104 monitor_callback_t *cb, *next;
1106 for ( cb = elp->el_cb; cb; cb = next ) {
1107 /* FIXME: call callbacks? */
1111 assert( elp->el_e != NULL );
1112 elp->el_e->e_private = NULL;
1113 entry_free( elp->el_e );
1114 *elpp = elp->el_next;
1121 if ( elpp != NULL ) {
1122 /* not found! where did it go? */
1131 monitor_back_unregister_entry_parent(
1132 struct berval *nrdn,
1133 monitor_callback_t *target_cb,
1134 struct berval *nbase,
1136 struct berval *filter )
1139 struct berval ndn = BER_BVNULL;
1141 if ( be_monitor == NULL ) {
1142 Debug( LDAP_DEBUG_ANY,
1143 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1144 "monitor database not configured.\n",
1145 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1146 ldap_pvt_scope2str( scope ),
1147 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1152 /* entry will be regularly freed, and resources released
1153 * according to callbacks */
1154 if ( slapd_shutdown ) {
1158 mi = ( monitor_info_t * )be_monitor->be_private;
1160 assert( mi != NULL );
1162 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1163 && BER_BVISNULL( filter ) )
1166 Debug( LDAP_DEBUG_ANY,
1167 "monitor_back_unregister_entry_parent(\"\"): "
1168 "need a valid filter\n",
1173 if ( monitor_subsys_opened ) {
1175 monitor_entry_t *mp = NULL;
1177 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1178 /* entry does not exist */
1179 Debug( LDAP_DEBUG_ANY,
1180 "monitor_back_unregister_entry_parent(\"\"): "
1181 "base=\"%s\" scope=%s filter=\"%s\": "
1182 "unable to find entry\n",
1183 nbase->bv_val ? nbase->bv_val : "\"\"",
1184 ldap_pvt_scope2str( scope ),
1189 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1190 /* entry does not exist */
1191 Debug( LDAP_DEBUG_ANY,
1192 "monitor_back_unregister_entry(\"%s\"): "
1193 "entry removal failed.\n",
1195 ber_memfree( ndn.bv_val );
1198 ber_memfree( ndn.bv_val );
1200 mp = (monitor_entry_t *)e->e_private;
1201 assert( mp != NULL );
1203 if ( target_cb != NULL ) {
1204 monitor_callback_t **cbp;
1206 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1207 if ( *cbp == target_cb ) {
1208 if ( (*cbp)->mc_free ) {
1209 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1211 *cbp = (*cbp)->mc_next;
1212 ch_free( target_cb );
1220 e->e_private = NULL;
1224 entry_limbo_t **elpp;
1226 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1228 elpp = &(*elpp)->el_next )
1230 entry_limbo_t *elp = *elpp;
1232 if ( elp->el_type == LIMBO_ENTRY_PARENT
1233 && dn_match( nrdn, &elp->el_e->e_nname )
1234 && dn_match( nbase, &elp->el_nbase )
1235 && scope == elp->el_scope
1236 && bvmatch( filter, &elp->el_filter ) )
1238 monitor_callback_t *cb, *next;
1240 for ( cb = elp->el_cb; cb; cb = next ) {
1241 /* FIXME: call callbacks? */
1245 assert( elp->el_e != NULL );
1246 elp->el_e->e_private = NULL;
1247 entry_free( elp->el_e );
1248 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1249 ch_free( elp->el_nbase.bv_val );
1251 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1252 ch_free( elp->el_filter.bv_val );
1254 *elpp = elp->el_next;
1261 if ( elpp != NULL ) {
1262 /* not found! where did it go? */
1271 monitor_back_unregister_entry_attrs(
1272 struct berval *ndn_in,
1273 Attribute *target_a,
1274 monitor_callback_t *target_cb,
1275 struct berval *nbase,
1277 struct berval *filter )
1280 struct berval ndn = BER_BVNULL;
1281 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1283 if ( be_monitor == NULL ) {
1284 char buf[ SLAP_TEXT_BUFLEN ];
1286 snprintf( buf, sizeof( buf ),
1287 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1288 "monitor database not configured.\n",
1290 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1291 ldap_pvt_scope2str( scope ),
1292 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1293 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1298 /* entry will be regularly freed, and resources released
1299 * according to callbacks */
1300 if ( slapd_shutdown ) {
1304 mi = ( monitor_info_t * )be_monitor->be_private;
1306 assert( mi != NULL );
1308 if ( ndn_in != NULL ) {
1312 if ( target_a == NULL && target_cb == NULL ) {
1317 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1318 && BER_BVISNULL( filter ) )
1321 Debug( LDAP_DEBUG_ANY,
1322 "monitor_back_unregister_entry_%s(\"\"): "
1323 "need a valid filter\n",
1328 if ( monitor_subsys_opened ) {
1330 monitor_entry_t *mp = NULL;
1333 if ( BER_BVISNULL( &ndn ) ) {
1334 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1335 char buf[ SLAP_TEXT_BUFLEN ];
1337 snprintf( buf, sizeof( buf ),
1338 "monitor_back_unregister_entry_%s(\"\"): "
1339 "base=\"%s\" scope=%d filter=\"%s\": "
1340 "unable to find entry\n",
1342 nbase->bv_val ? nbase->bv_val : "\"\"",
1343 scope, filter->bv_val );
1345 /* entry does not exist */
1346 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1353 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1354 /* entry does not exist */
1355 Debug( LDAP_DEBUG_ANY,
1356 "monitor_back_unregister_entry(\"%s\"): "
1357 "entry removal failed.\n",
1362 mp = (monitor_entry_t *)e->e_private;
1363 assert( mp != NULL );
1365 if ( target_cb != NULL ) {
1366 monitor_callback_t **cbp;
1368 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1369 if ( *cbp == target_cb ) {
1370 if ( (*cbp)->mc_free ) {
1371 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1373 *cbp = (*cbp)->mc_next;
1374 ch_free( target_cb );
1380 if ( target_a != NULL ) {
1383 for ( a = target_a; a != NULL; a = a->a_next ) {
1384 Modification mod = { 0 };
1386 char textbuf[ SLAP_TEXT_BUFLEN ];
1388 mod.sm_op = LDAP_MOD_DELETE;
1389 mod.sm_desc = a->a_desc;
1390 mod.sm_values = a->a_vals;
1391 mod.sm_nvalues = a->a_nvals;
1393 (void)modify_delete_values( e, &mod, 1,
1394 &text, textbuf, sizeof( textbuf ) );
1399 ber_memfree( ndn.bv_val );
1403 monitor_cache_release( mi, e );
1407 entry_limbo_t **elpp;
1409 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1411 elpp = &(*elpp)->el_next )
1413 entry_limbo_t *elp = *elpp;
1415 if ( elp->el_type == LIMBO_ATTRS
1416 && dn_match( nbase, &elp->el_nbase )
1417 && scope == elp->el_scope
1418 && bvmatch( filter, &elp->el_filter ) )
1420 monitor_callback_t *cb, *next;
1422 for ( cb = elp->el_cb; cb; cb = next ) {
1423 /* FIXME: call callbacks? */
1427 assert( elp->el_e == NULL );
1428 if ( elp->el_a != NULL ) {
1429 attrs_free( elp->el_a );
1431 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1432 ch_free( elp->el_nbase.bv_val );
1434 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1435 ch_free( elp->el_filter.bv_val );
1437 *elpp = elp->el_next;
1444 if ( elpp != NULL ) {
1445 /* not found! where did it go? */
1454 monitor_back_unregister_entry_callback(
1456 monitor_callback_t *cb,
1457 struct berval *nbase,
1459 struct berval *filter )
1461 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1462 * unregister the callback; if a is not null, unregister the
1463 * given attrs. In any case, call cb->cb_free */
1464 return monitor_back_unregister_entry_attrs( ndn,
1465 NULL, cb, nbase, scope, filter );
1469 monitor_back_get_subsys( const char *name )
1471 if ( monitor_subsys != NULL ) {
1474 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1475 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1476 return monitor_subsys[ i ];
1485 monitor_back_get_subsys_by_dn(
1489 if ( monitor_subsys != NULL ) {
1493 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1494 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1495 return monitor_subsys[ i ];
1500 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1501 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1502 return monitor_subsys[ i ];
1512 monitor_back_initialize(
1515 static char *controls[] = {
1516 LDAP_CONTROL_MANAGEDSAIT,
1520 static ConfigTable monitorcfg[] = {
1521 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1522 NULL, NULL, NULL, NULL }
1525 static ConfigOCs monitorocs[] = {
1526 { "( OLcfgDbOc:4.1 "
1527 "NAME 'olcMonitorConfig' "
1528 "DESC 'Monitor backend configuration' "
1529 "SUP olcDatabaseConfig "
1531 Cft_Database, monitorcfg },
1540 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1542 "DESC 'OpenLDAP system monitoring' "
1543 "SUP top STRUCTURAL "
1552 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1553 offsetof(monitor_info_t, mi_oc_monitor) },
1554 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1555 "NAME 'monitorServer' "
1556 "DESC 'Server monitoring root entry' "
1557 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1558 offsetof(monitor_info_t, mi_oc_monitorServer) },
1559 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1560 "NAME 'monitorContainer' "
1561 "DESC 'monitor container class' "
1562 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1563 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1564 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1565 "NAME 'monitorCounterObject' "
1566 "DESC 'monitor counter class' "
1567 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1568 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1569 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1570 "NAME 'monitorOperation' "
1571 "DESC 'monitor operation class' "
1572 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1573 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1574 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1575 "NAME 'monitorConnection' "
1576 "DESC 'monitor connection class' "
1577 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1578 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1579 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1580 "NAME 'managedObject' "
1581 "DESC 'monitor managed entity class' "
1582 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1583 offsetof(monitor_info_t, mi_oc_managedObject) },
1584 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1585 "NAME 'monitoredObject' "
1586 "DESC 'monitor monitored entity class' "
1587 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1588 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1591 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1592 "NAME 'monitoredInfo' "
1593 "DESC 'monitored info' "
1595 "EQUALITY caseIgnoreMatch "
1596 "SUBSTR caseIgnoreSubstringsMatch "
1597 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1598 "NO-USER-MODIFICATION "
1599 "USAGE directoryOperation )", SLAP_AT_HIDE,
1600 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1601 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1602 "NAME 'managedInfo' "
1603 "DESC 'monitor managed info' "
1604 "SUP name )", SLAP_AT_HIDE,
1605 offsetof(monitor_info_t, mi_ad_managedInfo) },
1606 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1607 "NAME 'monitorCounter' "
1608 "DESC 'monitor counter' "
1609 "EQUALITY integerMatch "
1610 "ORDERING integerOrderingMatch "
1611 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1612 "NO-USER-MODIFICATION "
1613 "USAGE directoryOperation )", SLAP_AT_HIDE,
1614 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1615 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1616 "NAME 'monitorOpCompleted' "
1617 "DESC 'monitor completed operations' "
1618 "SUP monitorCounter "
1619 "NO-USER-MODIFICATION "
1620 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1621 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1622 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1623 "NAME 'monitorOpInitiated' "
1624 "DESC 'monitor initiated operations' "
1625 "SUP monitorCounter "
1626 "NO-USER-MODIFICATION "
1627 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1628 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1629 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1630 "NAME 'monitorConnectionNumber' "
1631 "DESC 'monitor connection number' "
1632 "SUP monitorCounter "
1633 "NO-USER-MODIFICATION "
1634 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1635 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1636 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1637 "NAME 'monitorConnectionAuthzDN' "
1638 "DESC 'monitor connection authorization DN' "
1639 /* "SUP distinguishedName " */
1640 "EQUALITY distinguishedNameMatch "
1641 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1642 "NO-USER-MODIFICATION "
1643 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1644 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1645 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1646 "NAME 'monitorConnectionLocalAddress' "
1647 "DESC 'monitor connection local address' "
1648 "SUP monitoredInfo "
1649 "NO-USER-MODIFICATION "
1650 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1651 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1652 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1653 "NAME 'monitorConnectionPeerAddress' "
1654 "DESC 'monitor connection peer address' "
1655 "SUP monitoredInfo "
1656 "NO-USER-MODIFICATION "
1657 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1658 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1659 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1660 "NAME 'monitorTimestamp' "
1661 "DESC 'monitor timestamp' "
1662 "EQUALITY generalizedTimeMatch "
1663 "ORDERING generalizedTimeOrderingMatch "
1664 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1666 "NO-USER-MODIFICATION "
1667 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1668 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1669 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1670 "NAME 'monitorOverlay' "
1671 "DESC 'name of overlays defined for a given database' "
1672 "SUP monitoredInfo "
1673 "NO-USER-MODIFICATION "
1674 "USAGE directoryOperation )", SLAP_AT_HIDE,
1675 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1676 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1678 "DESC 'read/write status of a given database' "
1679 "EQUALITY booleanMatch "
1680 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1682 "USAGE directoryOperation )", SLAP_AT_HIDE,
1683 offsetof(monitor_info_t, mi_ad_readOnly) },
1684 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1685 "NAME 'restrictedOperation' "
1686 "DESC 'name of restricted operation for a given database' "
1687 "SUP managedInfo )", SLAP_AT_HIDE,
1688 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1689 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1690 "NAME 'monitorConnectionProtocol' "
1691 "DESC 'monitor connection protocol' "
1692 "SUP monitoredInfo "
1693 "NO-USER-MODIFICATION "
1694 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1695 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1696 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1697 "NAME 'monitorConnectionOpsReceived' "
1698 "DESC 'monitor number of operations received by the connection' "
1699 "SUP monitorCounter "
1700 "NO-USER-MODIFICATION "
1701 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1702 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1703 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1704 "NAME 'monitorConnectionOpsExecuting' "
1705 "DESC 'monitor number of operations in execution within the connection' "
1706 "SUP monitorCounter "
1707 "NO-USER-MODIFICATION "
1708 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1709 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1710 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1711 "NAME 'monitorConnectionOpsPending' "
1712 "DESC 'monitor number of pending operations within the connection' "
1713 "SUP monitorCounter "
1714 "NO-USER-MODIFICATION "
1715 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1716 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1717 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1718 "NAME 'monitorConnectionOpsCompleted' "
1719 "DESC 'monitor number of operations completed within the connection' "
1720 "SUP monitorCounter "
1721 "NO-USER-MODIFICATION "
1722 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1723 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1724 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1725 "NAME 'monitorConnectionGet' "
1726 "DESC 'number of times connection_get() was called so far' "
1727 "SUP monitorCounter "
1728 "NO-USER-MODIFICATION "
1729 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1730 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1731 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1732 "NAME 'monitorConnectionRead' "
1733 "DESC 'number of times connection_read() was called so far' "
1734 "SUP monitorCounter "
1735 "NO-USER-MODIFICATION "
1736 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1737 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1738 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1739 "NAME 'monitorConnectionWrite' "
1740 "DESC 'number of times connection_write() was called so far' "
1741 "SUP monitorCounter "
1742 "NO-USER-MODIFICATION "
1743 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1744 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1745 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1746 "NAME 'monitorConnectionMask' "
1747 "DESC 'monitor connection mask' "
1748 "SUP monitoredInfo "
1749 "NO-USER-MODIFICATION "
1750 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1751 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1752 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1753 "NAME 'monitorConnectionListener' "
1754 "DESC 'monitor connection listener' "
1755 "SUP monitoredInfo "
1756 "NO-USER-MODIFICATION "
1757 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1758 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1759 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1760 "NAME 'monitorConnectionPeerDomain' "
1761 "DESC 'monitor connection peer domain' "
1762 "SUP monitoredInfo "
1763 "NO-USER-MODIFICATION "
1764 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1765 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1766 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1767 "NAME 'monitorConnectionStartTime' "
1768 "DESC 'monitor connection start time' "
1769 "SUP monitorTimestamp "
1771 "NO-USER-MODIFICATION "
1772 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1773 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1774 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1775 "NAME 'monitorConnectionActivityTime' "
1776 "DESC 'monitor connection activity time' "
1777 "SUP monitorTimestamp "
1779 "NO-USER-MODIFICATION "
1780 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1781 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1782 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1783 "NAME 'monitorIsShadow' "
1784 "DESC 'TRUE if the database is shadow' "
1785 "EQUALITY booleanMatch "
1786 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1788 "USAGE directoryOperation )", SLAP_AT_HIDE,
1789 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1790 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1791 "NAME 'monitorUpdateRef' "
1792 "DESC 'update referral for shadow databases' "
1793 "SUP monitoredInfo "
1795 "USAGE directoryOperation )", SLAP_AT_HIDE,
1796 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1797 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1798 "NAME 'monitorRuntimeConfig' "
1799 "DESC 'TRUE if component allows runtime configuration' "
1800 "EQUALITY booleanMatch "
1801 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1803 "USAGE directoryOperation )", SLAP_AT_HIDE,
1804 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1812 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1813 { "olmSubSystemAttributes", "olmAttributes:0" },
1814 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1815 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1817 /* for example, back-bdb specific attrs
1818 * are in "olmDatabaseAttributes:1"
1820 * NOTE: developers, please record here OID assignments
1821 * for other modules */
1823 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1824 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1825 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1826 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1828 /* for example, back-bdb specific objectClasses
1829 * are in "olmDatabaseObjectClasses:1"
1831 * NOTE: developers, please record here OID assignments
1832 * for other modules */
1839 monitor_info_t *mi = &monitor_info;
1841 for ( i = 0; s_oid[ i ].name; i++ ) {
1844 argv[ 0 ] = "monitor";
1845 argv[ 1 ] = s_oid[ i ].name;
1846 argv[ 2 ] = s_oid[ i ].oid;
1848 if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) {
1849 Debug( LDAP_DEBUG_ANY,
1850 "monitor_back_initialize: unable to add "
1851 "objectIdentifier \"%s=%s\"\n",
1852 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1857 /* schema integration */
1858 for ( i = 0; mat[ i ].schema; i++ ) {
1860 AttributeDescription **ad =
1861 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1864 code = register_at( mat[ i ].schema, ad, 0 );
1867 Debug( LDAP_DEBUG_ANY,
1868 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1871 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1874 for ( i = 0; moc[ i ].schema; i++ ) {
1877 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1879 code = register_oc( moc[ i ].schema, Oc, 0 );
1881 Debug( LDAP_DEBUG_ANY,
1882 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1885 (*Oc)->soc_flags |= moc[ i ].flags;
1888 bi->bi_controls = controls;
1892 bi->bi_config = monitor_back_config;
1896 bi->bi_db_init = monitor_back_db_init;
1898 bi->bi_db_config = monitor_back_db_config;
1900 bi->bi_db_open = monitor_back_db_open;
1901 bi->bi_db_close = 0;
1902 bi->bi_db_destroy = monitor_back_db_destroy;
1904 bi->bi_op_bind = monitor_back_bind;
1905 bi->bi_op_unbind = 0;
1906 bi->bi_op_search = monitor_back_search;
1907 bi->bi_op_compare = monitor_back_compare;
1908 bi->bi_op_modify = monitor_back_modify;
1909 bi->bi_op_modrdn = 0;
1911 bi->bi_op_delete = 0;
1912 bi->bi_op_abandon = 0;
1914 bi->bi_extended = 0;
1916 bi->bi_entry_release_rw = 0;
1917 bi->bi_chk_referrals = 0;
1918 bi->bi_operational = monitor_back_operational;
1921 * hooks for slap tools
1923 bi->bi_tool_entry_open = 0;
1924 bi->bi_tool_entry_close = 0;
1925 bi->bi_tool_entry_first = 0;
1926 bi->bi_tool_entry_next = 0;
1927 bi->bi_tool_entry_get = 0;
1928 bi->bi_tool_entry_put = 0;
1929 bi->bi_tool_entry_reindex = 0;
1930 bi->bi_tool_sync = 0;
1931 bi->bi_tool_dn2id_get = 0;
1932 bi->bi_tool_id2entry_get = 0;
1933 bi->bi_tool_entry_modify = 0;
1935 bi->bi_connection_init = 0;
1936 bi->bi_connection_destroy = 0;
1938 bi->bi_extra = (void *)&monitor_extra;
1941 * configuration objectClasses (fake)
1943 bi->bi_cf_ocs = monitorocs;
1945 rc = config_register_schema( monitorcfg, monitorocs );
1954 monitor_back_db_init(
1958 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1963 monitor_subsys_t *ms;
1968 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1969 if ( monitor_back_register_subsys( ms ) ) {
1975 * database monitor can be defined once only
1977 if ( be_monitor != NULL ) {
1978 Debug( LDAP_DEBUG_ANY,
1979 "only one monitor database is allowed\n", 0, 0, 0 );
1984 /* indicate system schema supported */
1985 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1987 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1988 if( rc != LDAP_SUCCESS ) {
1989 Debug( LDAP_DEBUG_ANY,
1990 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
1995 ber_bvarray_add( &be->be_suffix, &pdn );
1996 ber_bvarray_add( &be->be_nsuffix, &ndn );
1998 /* NOTE: only one monitor database is allowed,
1999 * so we use static storage */
2000 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2002 be->be_private = &monitor_info;
2004 be2 = select_backend( &ndn, 0, 0 );
2006 char *type = be2->bd_info->bi_type;
2008 if ( overlay_is_over( be2 ) ) {
2009 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2010 type = oi->oi_orig->bi_type;
2013 Debug( LDAP_DEBUG_ANY,
2014 "\"monitor\" database serving namingContext \"%s\" "
2015 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2016 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2024 monitor_back_db_open(
2027 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2028 struct monitor_subsys_t **ms;
2029 Entry *e, **ep, *root;
2030 monitor_entry_t *mp;
2032 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2034 #ifdef HAVE_GMTIME_R
2037 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2038 struct berval desc[] = {
2039 BER_BVC("This subtree contains monitoring/managing objects."),
2040 BER_BVC("This object contains information about this server."),
2041 BER_BVC("Most of the information is held in operational"
2042 " attributes, which must be explicitly requested."),
2045 assert( be_monitor != NULL );
2046 if ( be != be_monitor ) {
2053 #ifndef HAVE_GMTIME_R
2054 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2056 #ifdef HACK_LOCAL_TIME
2057 # ifdef HAVE_LOCALTIME_R
2058 tms = localtime_r( &starttime, &tm_buf );
2060 tms = localtime( &starttime );
2061 # endif /* HAVE_LOCALTIME_R */
2062 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2063 #else /* !HACK_LOCAL_TIME */
2064 # ifdef HAVE_GMTIME_R
2065 tms = gmtime_r( &starttime, &tm_buf );
2067 tms = gmtime( &starttime );
2068 # endif /* HAVE_GMTIME_R */
2069 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2070 #endif /* !HACK_LOCAL_TIME */
2071 #ifndef HAVE_GMTIME_R
2072 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2075 mi->mi_startTime.bv_val = tmbuf;
2076 mi->mi_startTime.bv_len = strlen( tmbuf );
2078 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2079 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2080 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2082 mi->mi_creatorsName = be->be_rootdn;
2083 mi->mi_ncreatorsName = be->be_rootndn;
2087 * creates the "cn=Monitor" entry
2089 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2093 Debug( LDAP_DEBUG_ANY,
2094 "unable to create \"%s\" entry\n",
2095 SLAPD_MONITOR_DN, 0, 0 );
2099 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2101 bv.bv_val = strchr( (char *) Versionstr, '$' );
2102 if ( bv.bv_val != NULL ) {
2106 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2109 end = strchr( bv.bv_val, '$' );
2110 if ( end != NULL ) {
2113 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2118 bv.bv_len = end - bv.bv_val;
2121 bv.bv_len = strlen( bv.bv_val );
2124 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2126 Debug( LDAP_DEBUG_ANY,
2127 "unable to add monitoredInfo to \"%s\" entry\n",
2128 SLAPD_MONITOR_DN, 0, 0 );
2133 mp = monitor_entrypriv_create();
2137 e->e_private = ( void * )mp;
2138 ep = &mp->mp_children;
2140 if ( monitor_cache_add( mi, e ) ) {
2141 Debug( LDAP_DEBUG_ANY,
2142 "unable to add entry \"%s\" to cache\n",
2143 SLAPD_MONITOR_DN, 0, 0 );
2149 * Create all the subsystem specific entries
2151 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2152 int len = strlen( monitor_subsys[ i ]->mss_name );
2156 dn.bv_len = len + sizeof( "cn=" ) - 1;
2157 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2158 strcpy( dn.bv_val, "cn=" );
2159 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2160 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2162 if ( rc != LDAP_SUCCESS ) {
2163 Debug( LDAP_DEBUG_ANY,
2164 "monitor RDN \"%s\" is invalid\n",
2169 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2170 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2174 Debug( LDAP_DEBUG_ANY,
2175 "unable to create \"%s\" entry\n",
2176 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2179 monitor_subsys[i]->mss_dn = e->e_name;
2180 monitor_subsys[i]->mss_ndn = e->e_nname;
2182 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2183 attr_merge_normalize( e, slap_schema.si_ad_description,
2184 monitor_subsys[ i ]->mss_desc, NULL );
2187 mp = monitor_entrypriv_create();
2191 e->e_private = ( void * )mp;
2192 mp->mp_info = monitor_subsys[ i ];
2193 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2195 if ( monitor_cache_add( mi, e ) ) {
2196 Debug( LDAP_DEBUG_ANY,
2197 "unable to add entry \"%s\" to cache\n",
2198 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2206 assert( be != NULL );
2208 be->be_private = mi;
2211 * opens the monitor backend subsystems
2213 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2214 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2218 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2221 monitor_subsys_opened = 1;
2223 if ( mi->mi_entry_limbo ) {
2224 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
2229 switch ( el->el_type ) {
2231 monitor_back_register_entry(
2238 case LIMBO_ENTRY_PARENT:
2239 monitor_back_register_entry_parent(
2251 monitor_back_register_entry_attrs(
2261 monitor_back_register_entry_callback(
2274 entry_free( el->el_e );
2277 attrs_free( el->el_a );
2279 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2280 ber_memfree( el->el_ndn.bv_val );
2282 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2283 ber_memfree( el->el_nbase.bv_val );
2285 if ( !BER_BVISNULL( &el->el_filter ) ) {
2286 ber_memfree( el->el_filter.bv_val );
2294 mi->mi_entry_limbo = NULL;
2301 monitor_back_config(
2309 * eventually, will hold backend specific configuration parameters
2311 return SLAP_CONF_UNKNOWN;
2316 monitor_back_db_config(
2323 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2326 * eventually, will hold database specific configuration parameters
2328 return SLAP_CONF_UNKNOWN;
2333 monitor_back_db_destroy(
2336 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2343 * FIXME: destroys all the data
2345 /* NOTE: mi points to static storage; don't free it */
2347 (void)monitor_cache_destroy( mi );
2349 if ( monitor_subsys ) {
2352 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2353 if ( monitor_subsys[ i ]->mss_destroy ) {
2354 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2357 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2358 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2362 ch_free( monitor_subsys );
2365 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2367 be->be_private = NULL;
2372 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2374 /* conditionally define the init_module() function */
2375 SLAP_BACKEND_INIT_MODULE( monitor )
2377 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */