1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2012 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
31 #include "back-monitor.h"
35 #undef INTEGRATE_CORE_SCHEMA
38 * used by many functions to add description to entries
40 * WARNING: be_monitor may change as new databases are added,
41 * so it should not be used outside monitor_back_db_init()
42 * until monitor_back_db_open is called.
44 BackendDB *be_monitor;
46 static struct monitor_subsys_t **monitor_subsys;
47 static int monitor_subsys_opened;
48 static monitor_info_t monitor_info;
49 static const monitor_extra_t monitor_extra = {
50 monitor_back_is_configured,
51 monitor_back_get_subsys,
52 monitor_back_get_subsys_by_dn,
54 monitor_back_register_subsys,
55 monitor_back_register_backend,
56 monitor_back_register_database,
57 monitor_back_register_overlay_info,
58 monitor_back_register_overlay,
59 monitor_back_register_entry,
60 monitor_back_register_entry_parent,
61 monitor_back_register_entry_attrs,
62 monitor_back_register_entry_callback,
64 monitor_back_unregister_entry,
65 monitor_back_unregister_entry_parent,
66 monitor_back_unregister_entry_attrs,
67 monitor_back_unregister_entry_callback,
69 monitor_back_entry_stub
76 * the known subsystems are added to the subsystems
77 * array at backend initialization; other subsystems
78 * may be added by calling monitor_back_register_subsys()
79 * before the database is opened (e.g. by other backends
80 * or by overlays or modules).
82 static struct monitor_subsys_t known_monitor_subsys[] = {
84 SLAPD_MONITOR_BACKEND_NAME,
85 BER_BVNULL, BER_BVNULL, BER_BVNULL,
86 { BER_BVC( "This subsystem contains information about available backends." ),
88 MONITOR_F_PERSISTENT_CH,
89 monitor_subsys_backend_init,
95 SLAPD_MONITOR_CONN_NAME,
96 BER_BVNULL, BER_BVNULL, BER_BVNULL,
97 { BER_BVC( "This subsystem contains information about connections." ),
99 MONITOR_F_VOLATILE_CH,
100 monitor_subsys_conn_init,
106 SLAPD_MONITOR_DATABASE_NAME,
107 BER_BVNULL, BER_BVNULL, BER_BVNULL,
108 { BER_BVC( "This subsystem contains information about configured databases." ),
110 MONITOR_F_PERSISTENT_CH,
111 monitor_subsys_database_init,
117 SLAPD_MONITOR_LISTENER_NAME,
118 BER_BVNULL, BER_BVNULL, BER_BVNULL,
119 { BER_BVC( "This subsystem contains information about active listeners." ),
121 MONITOR_F_PERSISTENT_CH,
122 monitor_subsys_listener_init,
128 SLAPD_MONITOR_LOG_NAME,
129 BER_BVNULL, BER_BVNULL, BER_BVNULL,
130 { BER_BVC( "This subsystem contains information about logging." ),
131 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
134 monitor_subsys_log_init,
140 SLAPD_MONITOR_OPS_NAME,
141 BER_BVNULL, BER_BVNULL, BER_BVNULL,
142 { BER_BVC( "This subsystem contains information about performed operations." ),
144 MONITOR_F_PERSISTENT_CH,
145 monitor_subsys_ops_init,
151 SLAPD_MONITOR_OVERLAY_NAME,
152 BER_BVNULL, BER_BVNULL, BER_BVNULL,
153 { BER_BVC( "This subsystem contains information about available overlays." ),
155 MONITOR_F_PERSISTENT_CH,
156 monitor_subsys_overlay_init,
162 SLAPD_MONITOR_SASL_NAME,
163 BER_BVNULL, BER_BVNULL, BER_BVNULL,
164 { BER_BVC( "This subsystem contains information about SASL." ),
173 SLAPD_MONITOR_SENT_NAME,
174 BER_BVNULL, BER_BVNULL, BER_BVNULL,
175 { BER_BVC( "This subsystem contains statistics." ),
177 MONITOR_F_PERSISTENT_CH,
178 monitor_subsys_sent_init,
184 SLAPD_MONITOR_THREAD_NAME,
185 BER_BVNULL, BER_BVNULL, BER_BVNULL,
186 { BER_BVC( "This subsystem contains information about threads." ),
188 MONITOR_F_PERSISTENT_CH,
189 monitor_subsys_thread_init,
195 SLAPD_MONITOR_TIME_NAME,
196 BER_BVNULL, BER_BVNULL, BER_BVNULL,
197 { BER_BVC( "This subsystem contains information about time." ),
199 MONITOR_F_PERSISTENT_CH,
200 monitor_subsys_time_init,
206 SLAPD_MONITOR_TLS_NAME,
207 BER_BVNULL, BER_BVNULL, BER_BVNULL,
208 { BER_BVC( "This subsystem contains information about TLS." ),
217 SLAPD_MONITOR_RWW_NAME,
218 BER_BVNULL, BER_BVNULL, BER_BVNULL,
219 { BER_BVC( "This subsystem contains information about read/write waiters." ),
221 MONITOR_F_PERSISTENT_CH,
222 monitor_subsys_rww_init,
231 monitor_subsys_is_opened( void )
233 return monitor_subsys_opened;
237 monitor_back_register_subsys(
238 monitor_subsys_t *ms )
242 if ( monitor_subsys ) {
243 for ( ; monitor_subsys[ i ] != NULL; i++ )
244 /* just count'em */ ;
247 monitor_subsys = ch_realloc( monitor_subsys,
248 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
250 if ( monitor_subsys == NULL ) {
254 monitor_subsys[ i ] = ms;
255 monitor_subsys[ i + 1 ] = NULL;
257 /* if a subsystem is registered __AFTER__ subsystem
258 * initialization (depending on the sequence the databases
259 * are listed in slapd.conf), init it */
260 if ( monitor_subsys_is_opened() ) {
262 /* FIXME: this should only be possible
263 * if be_monitor is already initialized */
264 assert( be_monitor != NULL );
266 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
270 ms->mss_flags |= MONITOR_F_OPENED;
289 typedef struct entry_limbo_t {
293 slap_overinst *el_on;
296 struct berval *el_ndn;
297 struct berval el_nbase;
299 struct berval el_filter;
300 monitor_callback_t *el_cb;
301 monitor_subsys_t *el_mss;
302 unsigned long el_flags;
303 struct entry_limbo_t *el_next;
307 monitor_back_is_configured( void )
309 return be_monitor != NULL;
313 monitor_back_register_backend(
320 monitor_back_register_overlay_info(
327 monitor_back_register_backend_limbo(
334 monitor_back_register_database_limbo(
336 struct berval *ndn_out )
338 entry_limbo_t **elpp, el = { 0 };
341 if ( be_monitor == NULL ) {
342 Debug( LDAP_DEBUG_ANY,
343 "monitor_back_register_database_limbo: "
344 "monitor database not configured.\n",
349 mi = ( monitor_info_t * )be_monitor->be_private;
352 el.el_type = LIMBO_DATABASE;
354 el.el_be = be->bd_self;
357 for ( elpp = &mi->mi_entry_limbo;
359 elpp = &(*elpp)->el_next )
362 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
371 monitor_back_register_overlay_info_limbo(
378 monitor_back_register_overlay_limbo(
380 struct slap_overinst *on,
381 struct berval *ndn_out )
383 entry_limbo_t **elpp, el = { 0 };
386 if ( be_monitor == NULL ) {
387 Debug( LDAP_DEBUG_ANY,
388 "monitor_back_register_overlay_limbo: "
389 "monitor database not configured.\n",
394 mi = ( monitor_info_t * )be_monitor->be_private;
397 el.el_type = LIMBO_OVERLAY;
399 el.el_be = be->bd_self;
403 for ( elpp = &mi->mi_entry_limbo;
405 elpp = &(*elpp)->el_next )
408 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
417 monitor_back_register_entry(
419 monitor_callback_t *cb,
420 monitor_subsys_t *mss,
421 unsigned long flags )
425 if ( be_monitor == NULL ) {
426 Debug( LDAP_DEBUG_ANY,
427 "monitor_back_register_entry(\"%s\"): "
428 "monitor database not configured.\n",
429 e->e_name.bv_val, 0, 0 );
433 mi = ( monitor_info_t * )be_monitor->be_private;
435 assert( mi != NULL );
437 assert( e->e_private == NULL );
439 if ( monitor_subsys_is_opened() ) {
440 Entry *e_parent = NULL,
443 struct berval pdn = BER_BVNULL;
444 monitor_entry_t *mp = NULL,
448 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
450 Debug( LDAP_DEBUG_ANY,
451 "monitor_back_register_entry(\"%s\"): "
453 e->e_name.bv_val, 0, 0 );
454 monitor_cache_release( mi, e_parent );
458 dnParent( &e->e_nname, &pdn );
459 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
460 /* parent does not exist */
461 Debug( LDAP_DEBUG_ANY,
462 "monitor_back_register_entry(\"%s\"): "
463 "parent \"%s\" not found\n",
464 e->e_name.bv_val, pdn.bv_val, 0 );
468 assert( e_parent->e_private != NULL );
469 mp_parent = ( monitor_entry_t * )e_parent->e_private;
471 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
472 /* entry is volatile; cannot append children */
473 Debug( LDAP_DEBUG_ANY,
474 "monitor_back_register_entry(\"%s\"): "
475 "parent \"%s\" is volatile\n",
476 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
481 mp = monitor_entrypriv_create();
483 Debug( LDAP_DEBUG_ANY,
484 "monitor_back_register_entry(\"%s\"): "
485 "monitor_entrypriv_create() failed\n",
486 e->e_name.bv_val, 0, 0 );
491 e_new = entry_dup( e );
492 if ( e_new == NULL ) {
493 Debug( LDAP_DEBUG_ANY,
494 "monitor_back_register_entry(\"%s\"): "
495 "entry_dup() failed\n",
496 e->e_name.bv_val, 0, 0 );
501 e_new->e_private = ( void * )mp;
504 mp->mp_flags = flags;
507 mp->mp_info = mp_parent->mp_info;
508 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
512 ep = &mp_parent->mp_children;
514 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
515 ep = &mp_parent->mp_next;
519 if ( monitor_cache_add( mi, e_new ) ) {
520 Debug( LDAP_DEBUG_ANY,
521 "monitor_back_register_entry(\"%s\"): "
522 "unable to add entry\n",
523 e->e_name.bv_val, 0, 0 );
534 e_new->e_private = NULL;
540 monitor_cache_release( mi, e_parent );
544 entry_limbo_t **elpp, el = { 0 };
546 el.el_type = LIMBO_ENTRY;
548 el.el_e = entry_dup( e );
549 if ( el.el_e == NULL ) {
550 Debug( LDAP_DEBUG_ANY,
551 "monitor_back_register_entry(\"%s\"): "
552 "entry_dup() failed\n",
553 e->e_name.bv_val, 0, 0 );
561 for ( elpp = &mi->mi_entry_limbo;
563 elpp = &(*elpp)->el_next )
566 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
567 if ( *elpp == NULL ) {
568 el.el_e->e_private = NULL;
569 entry_free( el.el_e );
581 monitor_back_register_entry_parent(
583 monitor_callback_t *cb,
584 monitor_subsys_t *mss,
586 struct berval *nbase,
588 struct berval *filter )
591 struct berval ndn = BER_BVNULL;
593 if ( be_monitor == NULL ) {
594 Debug( LDAP_DEBUG_ANY,
595 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
596 "monitor database not configured.\n",
597 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
598 ldap_pvt_scope2str( scope ),
599 BER_BVISNULL( filter ) ? "" : filter->bv_val );
603 mi = ( monitor_info_t * )be_monitor->be_private;
605 assert( mi != NULL );
607 assert( e->e_private == NULL );
609 if ( BER_BVISNULL( filter ) ) {
611 Debug( LDAP_DEBUG_ANY,
612 "monitor_back_register_entry_parent(\"\"): "
613 "need a valid filter\n",
618 if ( monitor_subsys_is_opened() ) {
619 Entry *e_parent = NULL,
622 struct berval e_name = BER_BVNULL,
623 e_nname = BER_BVNULL;
624 monitor_entry_t *mp = NULL,
628 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
629 /* entry does not exist */
630 Debug( LDAP_DEBUG_ANY,
631 "monitor_back_register_entry_parent(\"\"): "
632 "base=\"%s\" scope=%s filter=\"%s\": "
633 "unable to find entry\n",
634 nbase->bv_val ? nbase->bv_val : "\"\"",
635 ldap_pvt_scope2str( scope ),
640 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
641 /* entry does not exist */
642 Debug( LDAP_DEBUG_ANY,
643 "monitor_back_register_entry_parent(\"%s\"): "
644 "parent entry does not exist\n",
650 assert( e_parent->e_private != NULL );
651 mp_parent = ( monitor_entry_t * )e_parent->e_private;
653 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
654 /* entry is volatile; cannot append callback */
655 Debug( LDAP_DEBUG_ANY,
656 "monitor_back_register_entry_parent(\"%s\"): "
657 "entry is volatile\n",
658 e_parent->e_name.bv_val, 0, 0 );
663 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
664 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
666 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
667 /* entry already exists */
668 Debug( LDAP_DEBUG_ANY,
669 "monitor_back_register_entry_parent(\"%s\"): "
670 "entry already exists\n",
671 e_name.bv_val, 0, 0 );
672 monitor_cache_release( mi, e_new );
678 mp = monitor_entrypriv_create();
680 Debug( LDAP_DEBUG_ANY,
681 "monitor_back_register_entry_parent(\"%s\"): "
682 "monitor_entrypriv_create() failed\n",
683 e->e_name.bv_val, 0, 0 );
688 e_new = entry_dup( e );
689 if ( e_new == NULL ) {
690 Debug( LDAP_DEBUG_ANY,
691 "monitor_back_register_entry(\"%s\"): "
692 "entry_dup() failed\n",
693 e->e_name.bv_val, 0, 0 );
697 ch_free( e_new->e_name.bv_val );
698 ch_free( e_new->e_nname.bv_val );
699 e_new->e_name = e_name;
700 e_new->e_nname = e_nname;
702 e_new->e_private = ( void * )mp;
705 mp->mp_flags = flags;
708 mp->mp_info = mp_parent->mp_info;
709 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
713 ep = &mp_parent->mp_children;
715 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
716 ep = &mp_parent->mp_next;
720 if ( monitor_cache_add( mi, e_new ) ) {
721 Debug( LDAP_DEBUG_ANY,
722 "monitor_back_register_entry(\"%s\"): "
723 "unable to add entry\n",
724 e->e_name.bv_val, 0, 0 );
730 if ( !BER_BVISNULL( &ndn ) ) {
731 ch_free( ndn.bv_val );
739 e_new->e_private = NULL;
745 monitor_cache_release( mi, e_parent );
749 entry_limbo_t **elpp = NULL, el = { 0 };
751 el.el_type = LIMBO_ENTRY_PARENT;
753 el.el_e = entry_dup( e );
754 if ( el.el_e == NULL ) {
755 Debug( LDAP_DEBUG_ANY,
756 "monitor_back_register_entry(\"%s\"): "
757 "entry_dup() failed\n",
758 e->e_name.bv_val, 0, 0 );
762 if ( !BER_BVISNULL( nbase ) ) {
763 ber_dupbv( &el.el_nbase, nbase );
767 if ( !BER_BVISNULL( filter ) ) {
768 ber_dupbv( &el.el_filter, filter );
775 for ( elpp = &mi->mi_entry_limbo;
777 elpp = &(*elpp)->el_next )
780 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
781 if ( *elpp == NULL ) {
786 if ( *elpp != NULL ) {
791 if ( !BER_BVISNULL( &el.el_filter ) ) {
792 ch_free( el.el_filter.bv_val );
794 if ( !BER_BVISNULL( &el.el_nbase ) ) {
795 ch_free( el.el_nbase.bv_val );
797 entry_free( el.el_e );
806 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
808 if ( rs->sr_type == REP_SEARCH ) {
809 struct berval *ndn = op->o_callback->sc_private;
811 if ( !BER_BVISNULL( ndn ) ) {
812 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
813 ch_free( ndn->bv_val );
818 ber_dupbv( ndn, &rs->sr_entry->e_nname );
826 struct berval *nbase,
828 struct berval *filter,
831 Connection conn = { 0 };
832 OperationBuffer opbuf;
835 SlapReply rs = { REP_RESULT };
836 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
841 if ( be_monitor == NULL ) {
845 thrctx = ldap_pvt_thread_pool_context();
846 connection_fake_init2( &conn, &opbuf, thrctx, 0 );
849 op->o_tag = LDAP_REQ_SEARCH;
851 /* use global malloc for now */
852 if ( op->o_tmpmemctx ) {
853 op->o_tmpmemctx = NULL;
855 op->o_tmpmfuncs = &ch_mfuncs;
857 op->o_bd = be_monitor;
858 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
859 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
861 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
865 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
866 op->o_tmpmemctx ) ) {
871 op->o_callback = &cb;
872 cb.sc_private = (void *)ndn;
874 op->ors_scope = scope;
875 op->ors_filter = str2filter_x( op, filter->bv_val );
876 if ( op->ors_filter == NULL ) {
880 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
881 op->ors_attrs = slap_anlist_no_attrs;
882 op->ors_attrsonly = 0;
883 op->ors_tlimit = SLAP_NO_LIMIT;
885 op->ors_limit = NULL;
886 op->ors_deref = LDAP_DEREF_NEVER;
889 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
891 op->o_dn = be_monitor->be_rootdn;
892 op->o_ndn = be_monitor->be_rootndn;
894 rc = op->o_bd->be_search( op, &rs );
897 if ( op->ors_filter != NULL ) {
898 filter_free_x( op, op->ors_filter, 1 );
900 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
901 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
903 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
904 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
906 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
907 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
914 switch ( rs.sr_err ) {
916 if ( BER_BVISNULL( ndn ) ) {
921 case LDAP_SIZELIMIT_EXCEEDED:
923 if ( !BER_BVISNULL( ndn ) ) {
924 ber_memfree( ndn->bv_val );
935 monitor_back_register_entry_attrs(
936 struct berval *ndn_in,
938 monitor_callback_t *cb,
939 struct berval *nbase,
941 struct berval *filter )
944 struct berval ndn = BER_BVNULL;
945 char *fname = ( a == NULL ? "callback" : "attrs" );
946 struct berval empty_bv = BER_BVC("");
948 if ( nbase == NULL ) nbase = &empty_bv;
949 if ( filter == NULL ) filter = &empty_bv;
951 if ( be_monitor == NULL ) {
952 char buf[ SLAP_TEXT_BUFLEN ];
954 snprintf( buf, sizeof( buf ),
955 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
956 "monitor database not configured.\n",
958 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
959 ldap_pvt_scope2str( scope ),
960 BER_BVISNULL( filter ) ? "" : filter->bv_val );
961 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
966 mi = ( monitor_info_t * )be_monitor->be_private;
968 assert( mi != NULL );
970 if ( ndn_in != NULL ) {
974 if ( a == NULL && cb == NULL ) {
979 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
980 && BER_BVISNULL( filter ) )
983 Debug( LDAP_DEBUG_ANY,
984 "monitor_back_register_entry_%s(\"\"): "
985 "need a valid filter\n",
990 if ( monitor_subsys_is_opened() ) {
992 Attribute **atp = NULL;
993 monitor_entry_t *mp = NULL;
994 monitor_callback_t **mcp = NULL;
998 if ( BER_BVISNULL( &ndn ) ) {
999 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1000 char buf[ SLAP_TEXT_BUFLEN ];
1002 snprintf( buf, sizeof( buf ),
1003 "monitor_back_register_entry_%s(\"\"): "
1004 "base=\"%s\" scope=%s filter=\"%s\": "
1005 "unable to find entry\n",
1007 nbase->bv_val ? nbase->bv_val : "\"\"",
1008 ldap_pvt_scope2str( scope ),
1011 /* entry does not exist */
1012 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1019 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1020 /* entry does not exist */
1021 Debug( LDAP_DEBUG_ANY,
1022 "monitor_back_register_entry_%s(\"%s\"): "
1023 "entry does not exist\n",
1024 fname, ndn.bv_val, 0 );
1029 assert( e->e_private != NULL );
1030 mp = ( monitor_entry_t * )e->e_private;
1032 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
1033 /* entry is volatile; cannot append callback */
1034 Debug( LDAP_DEBUG_ANY,
1035 "monitor_back_register_entry_%s(\"%s\"): "
1036 "entry is volatile\n",
1037 fname, e->e_name.bv_val, 0 );
1043 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
1044 /* just get to last */ ;
1046 for ( ; a != NULL; a = a->a_next ) {
1047 assert( a->a_desc != NULL );
1048 assert( a->a_vals != NULL );
1050 if ( attr_find( e->e_attrs, a->a_desc ) ) {
1051 attr_merge( e, a->a_desc, a->a_vals,
1052 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
1055 *atp = attr_dup( a );
1056 if ( *atp == NULL ) {
1057 Debug( LDAP_DEBUG_ANY,
1058 "monitor_back_register_entry_%s(\"%s\"): "
1059 "attr_dup() failed\n",
1060 fname, e->e_name.bv_val, 0 );
1064 atp = &(*atp)->a_next;
1070 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
1073 /* NOTE: we do not clear cb->mc_next, so this function
1074 * can be used to append a list of callbacks */
1080 if ( atp && *atp ) {
1087 ber_memfree( ndn.bv_val );
1091 monitor_cache_release( mi, e );
1095 entry_limbo_t **elpp, el = { 0 };
1097 el.el_type = LIMBO_ATTRS;
1099 if ( !BER_BVISNULL( nbase ) ) {
1100 ber_dupbv( &el.el_nbase, nbase);
1102 el.el_scope = scope;
1103 if ( !BER_BVISNULL( filter ) ) {
1104 ber_dupbv( &el.el_filter, filter );
1107 el.el_a = attrs_dup( a );
1110 for ( elpp = &mi->mi_entry_limbo;
1112 elpp = &(*elpp)->el_next )
1115 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
1116 if ( *elpp == NULL ) {
1117 if ( !BER_BVISNULL( &el.el_filter ) ) {
1118 ch_free( el.el_filter.bv_val );
1120 if ( el.el_a != NULL ) {
1121 attrs_free( el.el_a );
1123 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1124 ch_free( &el.el_nbase.bv_val );
1137 monitor_back_register_entry_callback(
1139 monitor_callback_t *cb,
1140 struct berval *nbase,
1142 struct berval *filter )
1144 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1145 nbase, scope, filter );
1149 * TODO: add corresponding calls to remove installed callbacks, entries
1150 * and so, in case the entity that installed them is removed (e.g. a
1151 * database, via back-config)
1154 monitor_back_unregister_entry(
1155 struct berval *ndn )
1159 if ( be_monitor == NULL ) {
1160 Debug( LDAP_DEBUG_ANY,
1161 "monitor_back_unregister_entry(\"%s\"): "
1162 "monitor database not configured.\n",
1163 ndn->bv_val, 0, 0 );
1168 /* entry will be regularly freed, and resources released
1169 * according to callbacks */
1170 if ( slapd_shutdown ) {
1174 mi = ( monitor_info_t * )be_monitor->be_private;
1176 assert( mi != NULL );
1178 if ( monitor_subsys_is_opened() ) {
1180 monitor_entry_t *mp = NULL;
1181 monitor_callback_t *cb = NULL;
1183 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1184 /* entry does not exist */
1185 Debug( LDAP_DEBUG_ANY,
1186 "monitor_back_unregister_entry(\"%s\"): "
1187 "entry removal failed.\n",
1188 ndn->bv_val, 0, 0 );
1192 mp = (monitor_entry_t *)e->e_private;
1193 assert( mp != NULL );
1195 for ( cb = mp->mp_cb; cb != NULL; ) {
1196 monitor_callback_t *next = cb->mc_next;
1198 if ( cb->mc_free ) {
1199 (void)cb->mc_free( e, &cb->mc_private );
1207 e->e_private = NULL;
1211 entry_limbo_t **elpp;
1213 for ( elpp = &mi->mi_entry_limbo;
1215 elpp = &(*elpp)->el_next )
1217 entry_limbo_t *elp = *elpp;
1219 if ( elp->el_type == LIMBO_ENTRY
1220 && dn_match( ndn, &elp->el_e->e_nname ) )
1222 monitor_callback_t *cb, *next;
1224 for ( cb = elp->el_cb; cb; cb = next ) {
1225 /* FIXME: call callbacks? */
1227 if ( cb->mc_dispose ) {
1228 cb->mc_dispose( &cb->mc_private );
1232 assert( elp->el_e != NULL );
1233 elp->el_e->e_private = NULL;
1234 entry_free( elp->el_e );
1235 *elpp = elp->el_next;
1242 if ( elpp != NULL ) {
1243 /* not found! where did it go? */
1252 monitor_back_unregister_entry_parent(
1253 struct berval *nrdn,
1254 monitor_callback_t *target_cb,
1255 struct berval *nbase,
1257 struct berval *filter )
1260 struct berval ndn = BER_BVNULL;
1262 if ( be_monitor == NULL ) {
1263 Debug( LDAP_DEBUG_ANY,
1264 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1265 "monitor database not configured.\n",
1266 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1267 ldap_pvt_scope2str( scope ),
1268 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1273 /* entry will be regularly freed, and resources released
1274 * according to callbacks */
1275 if ( slapd_shutdown ) {
1279 mi = ( monitor_info_t * )be_monitor->be_private;
1281 assert( mi != NULL );
1283 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1284 && BER_BVISNULL( filter ) )
1287 Debug( LDAP_DEBUG_ANY,
1288 "monitor_back_unregister_entry_parent(\"\"): "
1289 "need a valid filter\n",
1294 if ( monitor_subsys_is_opened() ) {
1296 monitor_entry_t *mp = NULL;
1298 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1299 /* entry does not exist */
1300 Debug( LDAP_DEBUG_ANY,
1301 "monitor_back_unregister_entry_parent(\"\"): "
1302 "base=\"%s\" scope=%s filter=\"%s\": "
1303 "unable to find entry\n",
1304 nbase->bv_val ? nbase->bv_val : "\"\"",
1305 ldap_pvt_scope2str( scope ),
1310 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1311 /* entry does not exist */
1312 Debug( LDAP_DEBUG_ANY,
1313 "monitor_back_unregister_entry(\"%s\"): "
1314 "entry removal failed.\n",
1316 ber_memfree( ndn.bv_val );
1319 ber_memfree( ndn.bv_val );
1321 mp = (monitor_entry_t *)e->e_private;
1322 assert( mp != NULL );
1324 if ( target_cb != NULL ) {
1325 monitor_callback_t **cbp;
1327 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1328 if ( *cbp == target_cb ) {
1329 if ( (*cbp)->mc_free ) {
1330 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1332 *cbp = (*cbp)->mc_next;
1333 ch_free( target_cb );
1341 e->e_private = NULL;
1345 entry_limbo_t **elpp;
1347 for ( elpp = &mi->mi_entry_limbo;
1349 elpp = &(*elpp)->el_next )
1351 entry_limbo_t *elp = *elpp;
1353 if ( elp->el_type == LIMBO_ENTRY_PARENT
1354 && dn_match( nrdn, &elp->el_e->e_nname )
1355 && dn_match( nbase, &elp->el_nbase )
1356 && scope == elp->el_scope
1357 && bvmatch( filter, &elp->el_filter ) )
1359 monitor_callback_t *cb, *next;
1361 for ( cb = elp->el_cb; cb; cb = next ) {
1362 /* FIXME: call callbacks? */
1364 if ( cb->mc_dispose ) {
1365 cb->mc_dispose( &cb->mc_private );
1369 assert( elp->el_e != NULL );
1370 elp->el_e->e_private = NULL;
1371 entry_free( elp->el_e );
1372 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1373 ch_free( elp->el_nbase.bv_val );
1375 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1376 ch_free( elp->el_filter.bv_val );
1378 *elpp = elp->el_next;
1385 if ( elpp != NULL ) {
1386 /* not found! where did it go? */
1395 monitor_back_unregister_entry_attrs(
1396 struct berval *ndn_in,
1397 Attribute *target_a,
1398 monitor_callback_t *target_cb,
1399 struct berval *nbase,
1401 struct berval *filter )
1404 struct berval ndn = BER_BVNULL;
1405 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1407 if ( be_monitor == NULL ) {
1408 char buf[ SLAP_TEXT_BUFLEN ];
1410 snprintf( buf, sizeof( buf ),
1411 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1412 "monitor database not configured.\n",
1414 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1415 ldap_pvt_scope2str( scope ),
1416 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1417 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1422 /* entry will be regularly freed, and resources released
1423 * according to callbacks */
1424 if ( slapd_shutdown ) {
1428 mi = ( monitor_info_t * )be_monitor->be_private;
1430 assert( mi != NULL );
1432 if ( ndn_in != NULL ) {
1436 if ( target_a == NULL && target_cb == NULL ) {
1441 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1442 && BER_BVISNULL( filter ) )
1445 Debug( LDAP_DEBUG_ANY,
1446 "monitor_back_unregister_entry_%s(\"\"): "
1447 "need a valid filter\n",
1452 if ( monitor_subsys_is_opened() ) {
1454 monitor_entry_t *mp = NULL;
1457 if ( BER_BVISNULL( &ndn ) ) {
1458 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1459 char buf[ SLAP_TEXT_BUFLEN ];
1461 snprintf( buf, sizeof( buf ),
1462 "monitor_back_unregister_entry_%s(\"\"): "
1463 "base=\"%s\" scope=%d filter=\"%s\": "
1464 "unable to find entry\n",
1466 nbase->bv_val ? nbase->bv_val : "\"\"",
1467 scope, filter->bv_val );
1469 /* entry does not exist */
1470 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1477 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1478 /* entry does not exist */
1479 Debug( LDAP_DEBUG_ANY,
1480 "monitor_back_unregister_entry(\"%s\"): "
1481 "entry removal failed.\n",
1486 mp = (monitor_entry_t *)e->e_private;
1487 assert( mp != NULL );
1489 if ( target_cb != NULL ) {
1490 monitor_callback_t **cbp;
1492 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1493 if ( *cbp == target_cb ) {
1494 if ( (*cbp)->mc_free ) {
1495 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1497 *cbp = (*cbp)->mc_next;
1498 ch_free( target_cb );
1504 if ( target_a != NULL ) {
1507 for ( a = target_a; a != NULL; a = a->a_next ) {
1508 Modification mod = { 0 };
1510 char textbuf[ SLAP_TEXT_BUFLEN ];
1512 mod.sm_op = LDAP_MOD_DELETE;
1513 mod.sm_desc = a->a_desc;
1514 mod.sm_values = a->a_vals;
1515 mod.sm_nvalues = a->a_nvals;
1517 (void)modify_delete_values( e, &mod, 1,
1518 &text, textbuf, sizeof( textbuf ) );
1523 ber_memfree( ndn.bv_val );
1526 monitor_cache_release( mi, e );
1529 entry_limbo_t **elpp;
1531 for ( elpp = &mi->mi_entry_limbo;
1533 elpp = &(*elpp)->el_next )
1535 entry_limbo_t *elp = *elpp;
1537 if ( elp->el_type == LIMBO_ATTRS
1538 && dn_match( nbase, &elp->el_nbase )
1539 && scope == elp->el_scope
1540 && bvmatch( filter, &elp->el_filter ) )
1542 monitor_callback_t *cb, *next;
1544 for ( cb = elp->el_cb; cb; cb = next ) {
1545 /* FIXME: call callbacks? */
1547 if ( cb->mc_dispose ) {
1548 cb->mc_dispose( &cb->mc_private );
1552 assert( elp->el_e == NULL );
1553 if ( elp->el_a != NULL ) {
1554 attrs_free( elp->el_a );
1556 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1557 ch_free( elp->el_nbase.bv_val );
1559 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1560 ch_free( elp->el_filter.bv_val );
1562 *elpp = elp->el_next;
1569 if ( elpp != NULL ) {
1570 /* not found! where did it go? */
1579 monitor_back_unregister_entry_callback(
1581 monitor_callback_t *cb,
1582 struct berval *nbase,
1584 struct berval *filter )
1586 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1587 * unregister the callback; if a is not null, unregister the
1588 * given attrs. In any case, call cb->cb_free */
1589 return monitor_back_unregister_entry_attrs( ndn,
1590 NULL, cb, nbase, scope, filter );
1594 monitor_back_get_subsys( const char *name )
1596 if ( monitor_subsys != NULL ) {
1599 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1600 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1601 return monitor_subsys[ i ];
1610 monitor_back_get_subsys_by_dn(
1614 if ( monitor_subsys != NULL ) {
1618 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1619 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1620 return monitor_subsys[ i ];
1625 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1626 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1627 return monitor_subsys[ i ];
1637 monitor_back_initialize(
1640 static char *controls[] = {
1641 LDAP_CONTROL_MANAGEDSAIT,
1645 static ConfigTable monitorcfg[] = {
1646 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1647 NULL, NULL, NULL, NULL }
1650 static ConfigOCs monitorocs[] = {
1651 { "( OLcfgDbOc:4.1 "
1652 "NAME 'olcMonitorConfig' "
1653 "DESC 'Monitor backend configuration' "
1654 "SUP olcDatabaseConfig "
1656 Cft_Database, monitorcfg },
1665 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1667 "DESC 'OpenLDAP system monitoring' "
1668 "SUP top STRUCTURAL "
1677 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1678 offsetof(monitor_info_t, mi_oc_monitor) },
1679 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1680 "NAME 'monitorServer' "
1681 "DESC 'Server monitoring root entry' "
1682 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1683 offsetof(monitor_info_t, mi_oc_monitorServer) },
1684 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1685 "NAME 'monitorContainer' "
1686 "DESC 'monitor container class' "
1687 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1688 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1689 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1690 "NAME 'monitorCounterObject' "
1691 "DESC 'monitor counter class' "
1692 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1693 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1694 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1695 "NAME 'monitorOperation' "
1696 "DESC 'monitor operation class' "
1697 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1698 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1699 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1700 "NAME 'monitorConnection' "
1701 "DESC 'monitor connection class' "
1702 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1703 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1704 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1705 "NAME 'managedObject' "
1706 "DESC 'monitor managed entity class' "
1707 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1708 offsetof(monitor_info_t, mi_oc_managedObject) },
1709 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1710 "NAME 'monitoredObject' "
1711 "DESC 'monitor monitored entity class' "
1712 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1713 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1716 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1717 "NAME 'monitoredInfo' "
1718 "DESC 'monitored info' "
1720 "EQUALITY caseIgnoreMatch "
1721 "SUBSTR caseIgnoreSubstringsMatch "
1722 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1723 "NO-USER-MODIFICATION "
1724 "USAGE dSAOperation )", SLAP_AT_HIDE,
1725 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1726 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1727 "NAME 'managedInfo' "
1728 "DESC 'monitor managed info' "
1729 "SUP name )", SLAP_AT_HIDE,
1730 offsetof(monitor_info_t, mi_ad_managedInfo) },
1731 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1732 "NAME 'monitorCounter' "
1733 "DESC 'monitor counter' "
1734 "EQUALITY integerMatch "
1735 "ORDERING integerOrderingMatch "
1736 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1737 "NO-USER-MODIFICATION "
1738 "USAGE dSAOperation )", SLAP_AT_HIDE,
1739 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1740 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1741 "NAME 'monitorOpCompleted' "
1742 "DESC 'monitor completed operations' "
1743 "SUP monitorCounter "
1744 "NO-USER-MODIFICATION "
1745 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1746 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1747 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1748 "NAME 'monitorOpInitiated' "
1749 "DESC 'monitor initiated operations' "
1750 "SUP monitorCounter "
1751 "NO-USER-MODIFICATION "
1752 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1753 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1754 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1755 "NAME 'monitorConnectionNumber' "
1756 "DESC 'monitor connection number' "
1757 "SUP monitorCounter "
1758 "NO-USER-MODIFICATION "
1759 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1760 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1761 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1762 "NAME 'monitorConnectionAuthzDN' "
1763 "DESC 'monitor connection authorization DN' "
1764 /* "SUP distinguishedName " */
1765 "EQUALITY distinguishedNameMatch "
1766 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1767 "NO-USER-MODIFICATION "
1768 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1769 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1770 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1771 "NAME 'monitorConnectionLocalAddress' "
1772 "DESC 'monitor connection local address' "
1773 "SUP monitoredInfo "
1774 "NO-USER-MODIFICATION "
1775 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1776 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1777 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1778 "NAME 'monitorConnectionPeerAddress' "
1779 "DESC 'monitor connection peer address' "
1780 "SUP monitoredInfo "
1781 "NO-USER-MODIFICATION "
1782 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1783 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1784 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1785 "NAME 'monitorTimestamp' "
1786 "DESC 'monitor timestamp' "
1787 "EQUALITY generalizedTimeMatch "
1788 "ORDERING generalizedTimeOrderingMatch "
1789 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1791 "NO-USER-MODIFICATION "
1792 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1793 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1794 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1795 "NAME 'monitorOverlay' "
1796 "DESC 'name of overlays defined for a given database' "
1797 "SUP monitoredInfo "
1798 "NO-USER-MODIFICATION "
1799 "USAGE dSAOperation )", SLAP_AT_HIDE,
1800 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1801 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1803 "DESC 'read/write status of a given database' "
1804 "EQUALITY booleanMatch "
1805 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1807 "USAGE dSAOperation )", SLAP_AT_HIDE,
1808 offsetof(monitor_info_t, mi_ad_readOnly) },
1809 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1810 "NAME 'restrictedOperation' "
1811 "DESC 'name of restricted operation for a given database' "
1812 "SUP managedInfo )", SLAP_AT_HIDE,
1813 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1814 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1815 "NAME 'monitorConnectionProtocol' "
1816 "DESC 'monitor connection protocol' "
1817 "SUP monitoredInfo "
1818 "NO-USER-MODIFICATION "
1819 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1820 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1821 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1822 "NAME 'monitorConnectionOpsReceived' "
1823 "DESC 'monitor number of operations received by the connection' "
1824 "SUP monitorCounter "
1825 "NO-USER-MODIFICATION "
1826 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1827 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1828 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1829 "NAME 'monitorConnectionOpsExecuting' "
1830 "DESC 'monitor number of operations in execution within the connection' "
1831 "SUP monitorCounter "
1832 "NO-USER-MODIFICATION "
1833 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1834 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1835 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1836 "NAME 'monitorConnectionOpsPending' "
1837 "DESC 'monitor number of pending operations within the connection' "
1838 "SUP monitorCounter "
1839 "NO-USER-MODIFICATION "
1840 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1841 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1842 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1843 "NAME 'monitorConnectionOpsCompleted' "
1844 "DESC 'monitor number of operations completed within the connection' "
1845 "SUP monitorCounter "
1846 "NO-USER-MODIFICATION "
1847 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1848 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1849 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1850 "NAME 'monitorConnectionGet' "
1851 "DESC 'number of times connection_get() was called so far' "
1852 "SUP monitorCounter "
1853 "NO-USER-MODIFICATION "
1854 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1855 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1856 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1857 "NAME 'monitorConnectionRead' "
1858 "DESC 'number of times connection_read() was called so far' "
1859 "SUP monitorCounter "
1860 "NO-USER-MODIFICATION "
1861 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1862 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1863 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1864 "NAME 'monitorConnectionWrite' "
1865 "DESC 'number of times connection_write() was called so far' "
1866 "SUP monitorCounter "
1867 "NO-USER-MODIFICATION "
1868 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1869 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1870 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1871 "NAME 'monitorConnectionMask' "
1872 "DESC 'monitor connection mask' "
1873 "SUP monitoredInfo "
1874 "NO-USER-MODIFICATION "
1875 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1876 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1877 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1878 "NAME 'monitorConnectionListener' "
1879 "DESC 'monitor connection listener' "
1880 "SUP monitoredInfo "
1881 "NO-USER-MODIFICATION "
1882 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1883 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1884 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1885 "NAME 'monitorConnectionPeerDomain' "
1886 "DESC 'monitor connection peer domain' "
1887 "SUP monitoredInfo "
1888 "NO-USER-MODIFICATION "
1889 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1890 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1891 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1892 "NAME 'monitorConnectionStartTime' "
1893 "DESC 'monitor connection start time' "
1894 "SUP monitorTimestamp "
1896 "NO-USER-MODIFICATION "
1897 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1898 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1899 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1900 "NAME 'monitorConnectionActivityTime' "
1901 "DESC 'monitor connection activity time' "
1902 "SUP monitorTimestamp "
1904 "NO-USER-MODIFICATION "
1905 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1906 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1907 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1908 "NAME 'monitorIsShadow' "
1909 "DESC 'TRUE if the database is shadow' "
1910 "EQUALITY booleanMatch "
1911 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1913 "USAGE dSAOperation )", SLAP_AT_HIDE,
1914 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1915 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1916 "NAME 'monitorUpdateRef' "
1917 "DESC 'update referral for shadow databases' "
1918 "SUP monitoredInfo "
1920 "USAGE dSAOperation )", SLAP_AT_HIDE,
1921 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1922 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1923 "NAME 'monitorRuntimeConfig' "
1924 "DESC 'TRUE if component allows runtime configuration' "
1925 "EQUALITY booleanMatch "
1926 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1928 "USAGE dSAOperation )", SLAP_AT_HIDE,
1929 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1930 { "( 1.3.6.1.4.1.4203.666.1.55.30 "
1931 "NAME 'monitorSuperiorDN' "
1932 "DESC 'monitor superior DN' "
1933 /* "SUP distinguishedName " */
1934 "EQUALITY distinguishedNameMatch "
1935 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1936 "NO-USER-MODIFICATION "
1937 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1938 offsetof(monitor_info_t, mi_ad_monitorSuperiorDN) },
1946 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1947 { "olmSubSystemAttributes", "olmAttributes:0" },
1948 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1949 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1951 /* for example, back-bdb specific attrs
1952 * are in "olmDatabaseAttributes:1"
1954 * NOTE: developers, please record here OID assignments
1955 * for other modules */
1957 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1958 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1959 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1960 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1962 /* for example, back-bdb specific objectClasses
1963 * are in "olmDatabaseObjectClasses:1"
1965 * NOTE: developers, please record here OID assignments
1966 * for other modules */
1972 monitor_info_t *mi = &monitor_info;
1976 argv[ 0 ] = "monitor";
1981 for ( i = 0; s_oid[ i ].name; i++ ) {
1982 argv[ 1 ] = s_oid[ i ].name;
1983 argv[ 2 ] = s_oid[ i ].oid;
1985 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1986 Debug( LDAP_DEBUG_ANY,
1987 "monitor_back_initialize: unable to add "
1988 "objectIdentifier \"%s=%s\"\n",
1989 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1994 /* schema integration */
1995 for ( i = 0; mat[ i ].schema; i++ ) {
1997 AttributeDescription **ad =
1998 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
2001 code = register_at( mat[ i ].schema, ad, 0 );
2004 Debug( LDAP_DEBUG_ANY,
2005 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
2008 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
2011 for ( i = 0; moc[ i ].schema; i++ ) {
2014 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
2016 code = register_oc( moc[ i ].schema, Oc, 0 );
2018 Debug( LDAP_DEBUG_ANY,
2019 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
2022 (*Oc)->soc_flags |= moc[ i ].flags;
2025 bi->bi_controls = controls;
2029 bi->bi_config = monitor_back_config;
2033 bi->bi_db_init = monitor_back_db_init;
2035 bi->bi_db_config = monitor_back_db_config;
2037 bi->bi_db_open = monitor_back_db_open;
2038 bi->bi_db_close = 0;
2039 bi->bi_db_destroy = monitor_back_db_destroy;
2041 bi->bi_op_bind = monitor_back_bind;
2042 bi->bi_op_unbind = 0;
2043 bi->bi_op_search = monitor_back_search;
2044 bi->bi_op_compare = monitor_back_compare;
2045 bi->bi_op_modify = monitor_back_modify;
2046 bi->bi_op_modrdn = 0;
2048 bi->bi_op_delete = 0;
2049 bi->bi_op_abandon = 0;
2051 bi->bi_extended = 0;
2053 bi->bi_entry_release_rw = monitor_back_release;
2054 bi->bi_chk_referrals = 0;
2055 bi->bi_operational = monitor_back_operational;
2058 * hooks for slap tools
2060 bi->bi_tool_entry_open = 0;
2061 bi->bi_tool_entry_close = 0;
2062 bi->bi_tool_entry_first = 0;
2063 bi->bi_tool_entry_first_x = 0;
2064 bi->bi_tool_entry_next = 0;
2065 bi->bi_tool_entry_get = 0;
2066 bi->bi_tool_entry_put = 0;
2067 bi->bi_tool_entry_reindex = 0;
2068 bi->bi_tool_sync = 0;
2069 bi->bi_tool_dn2id_get = 0;
2070 bi->bi_tool_entry_modify = 0;
2072 bi->bi_connection_init = 0;
2073 bi->bi_connection_destroy = 0;
2075 bi->bi_extra = (void *)&monitor_extra;
2078 * configuration objectClasses (fake)
2080 bi->bi_cf_ocs = monitorocs;
2082 rc = config_register_schema( monitorcfg, monitorocs );
2091 monitor_back_db_init(
2096 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
2101 monitor_subsys_t *ms;
2104 * database monitor can be defined once only
2106 if ( be_monitor != NULL ) {
2108 snprintf(c->msg, sizeof(c->msg),"only one monitor database allowed");
2117 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2118 if ( monitor_back_register_subsys( ms ) ) {
2123 /* indicate system schema supported */
2124 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2126 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2127 if( rc != LDAP_SUCCESS ) {
2128 Debug( LDAP_DEBUG_ANY,
2129 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2134 ber_bvarray_add( &be->be_suffix, &pdn );
2135 ber_bvarray_add( &be->be_nsuffix, &ndn );
2137 /* NOTE: only one monitor database is allowed,
2138 * so we use static storage */
2139 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2141 be->be_private = &monitor_info;
2143 be2 = select_backend( &ndn, 0 );
2145 char *type = be2->bd_info->bi_type;
2147 if ( overlay_is_over( be2 ) ) {
2148 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2149 type = oi->oi_orig->bi_type;
2153 snprintf(c->msg, sizeof(c->msg),
2154 "\"monitor\" database serving namingContext \"%s\" "
2155 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2156 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2165 monitor_back_destroy_limbo_entry(
2170 entry_free( el->el_e );
2173 attrs_free( el->el_a );
2175 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2176 ber_memfree( el->el_nbase.bv_val );
2178 if ( !BER_BVISNULL( &el->el_filter ) ) {
2179 ber_memfree( el->el_filter.bv_val );
2182 /* NOTE: callbacks are not copied; so only free them
2183 * if disposing of */
2184 if ( el->el_cb && dispose != 0 ) {
2185 monitor_callback_t *next;
2187 for ( ; el->el_cb; el->el_cb = next ) {
2188 next = el->el_cb->mc_next;
2189 if ( el->el_cb->mc_dispose ) {
2190 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2192 ch_free( el->el_cb );
2200 monitor_back_db_open(
2204 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2205 struct monitor_subsys_t **ms;
2206 Entry *e, **ep, *root;
2207 monitor_entry_t *mp;
2209 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2211 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2212 struct berval desc[] = {
2213 BER_BVC("This subtree contains monitoring/managing objects."),
2214 BER_BVC("This object contains information about this server."),
2215 BER_BVC("Most of the information is held in operational"
2216 " attributes, which must be explicitly requested."),
2221 assert( be_monitor != NULL );
2222 if ( be != be_monitor ) {
2229 ldap_pvt_gmtime( &starttime, &tms );
2230 lutil_gentime( tmbuf, sizeof(tmbuf), &tms );
2232 mi->mi_startTime.bv_val = tmbuf;
2233 mi->mi_startTime.bv_len = strlen( tmbuf );
2235 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2236 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2237 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2239 mi->mi_creatorsName = be->be_rootdn;
2240 mi->mi_ncreatorsName = be->be_rootndn;
2244 * creates the "cn=Monitor" entry
2246 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2250 Debug( LDAP_DEBUG_ANY,
2251 "unable to create \"%s\" entry\n",
2252 SLAPD_MONITOR_DN, 0, 0 );
2256 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2258 bv.bv_val = strchr( (char *) Versionstr, '$' );
2259 if ( bv.bv_val != NULL ) {
2263 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2266 end = strchr( bv.bv_val, '$' );
2267 if ( end != NULL ) {
2270 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2275 bv.bv_len = end - bv.bv_val;
2278 bv.bv_len = strlen( bv.bv_val );
2281 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2283 Debug( LDAP_DEBUG_ANY,
2284 "unable to add monitoredInfo to \"%s\" entry\n",
2285 SLAPD_MONITOR_DN, 0, 0 );
2290 mp = monitor_entrypriv_create();
2294 e->e_private = ( void * )mp;
2295 ep = &mp->mp_children;
2297 if ( monitor_cache_add( mi, e ) ) {
2298 Debug( LDAP_DEBUG_ANY,
2299 "unable to add entry \"%s\" to cache\n",
2300 SLAPD_MONITOR_DN, 0, 0 );
2306 * Create all the subsystem specific entries
2308 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2309 int len = strlen( monitor_subsys[ i ]->mss_name );
2313 dn.bv_len = len + sizeof( "cn=" ) - 1;
2314 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2315 strcpy( dn.bv_val, "cn=" );
2316 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2317 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2319 if ( rc != LDAP_SUCCESS ) {
2320 Debug( LDAP_DEBUG_ANY,
2321 "monitor RDN \"%s\" is invalid\n",
2326 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2327 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2331 Debug( LDAP_DEBUG_ANY,
2332 "unable to create \"%s\" entry\n",
2333 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2336 monitor_subsys[i]->mss_dn = e->e_name;
2337 monitor_subsys[i]->mss_ndn = e->e_nname;
2339 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2340 attr_merge_normalize( e, slap_schema.si_ad_description,
2341 monitor_subsys[ i ]->mss_desc, NULL );
2344 mp = monitor_entrypriv_create();
2348 e->e_private = ( void * )mp;
2349 mp->mp_info = monitor_subsys[ i ];
2350 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2352 if ( monitor_cache_add( mi, e ) ) {
2353 Debug( LDAP_DEBUG_ANY,
2354 "unable to add entry \"%s\" to cache\n",
2355 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2363 assert( be != NULL );
2365 be->be_private = mi;
2368 * opens the monitor backend subsystems
2370 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2371 if ( ms[ 0 ]->mss_open && ms[ 0 ]->mss_open( be, ms[ 0 ] ) ) {
2374 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2377 monitor_subsys_opened = 1;
2379 if ( mi->mi_entry_limbo ) {
2380 entry_limbo_t *el = mi->mi_entry_limbo;
2386 switch ( el->el_type ) {
2388 rc = monitor_back_register_entry(
2395 case LIMBO_ENTRY_PARENT:
2396 rc = monitor_back_register_entry_parent(
2408 rc = monitor_back_register_entry_attrs(
2418 rc = monitor_back_register_entry_callback(
2427 rc = monitor_back_register_backend( el->el_bi );
2430 case LIMBO_DATABASE:
2431 rc = monitor_back_register_database( el->el_be, el->el_ndn );
2434 case LIMBO_OVERLAY_INFO:
2435 rc = monitor_back_register_overlay_info( el->el_on );
2439 rc = monitor_back_register_overlay( el->el_be, el->el_on, el->el_ndn );
2448 monitor_back_destroy_limbo_entry( tmp, rc );
2451 /* try all, but report error at end */
2456 mi->mi_entry_limbo = NULL;
2463 monitor_back_config(
2471 * eventually, will hold backend specific configuration parameters
2473 return SLAP_CONF_UNKNOWN;
2478 monitor_back_db_config(
2485 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2488 * eventually, will hold database specific configuration parameters
2490 return SLAP_CONF_UNKNOWN;
2495 monitor_back_db_destroy(
2499 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2506 * FIXME: destroys all the data
2508 /* NOTE: mi points to static storage; don't free it */
2510 (void)monitor_cache_destroy( mi );
2512 if ( monitor_subsys ) {
2515 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2516 if ( monitor_subsys[ i ]->mss_destroy ) {
2517 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2520 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2521 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2525 ch_free( monitor_subsys );
2528 if ( mi->mi_entry_limbo ) {
2529 entry_limbo_t *el = mi->mi_entry_limbo;
2532 entry_limbo_t *tmp = el;
2534 monitor_back_destroy_limbo_entry( tmp, 1 );
2538 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2540 be->be_private = NULL;
2545 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2547 /* conditionally define the init_module() function */
2548 SLAP_BACKEND_INIT_MODULE( monitor )
2550 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */