1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
31 #include "back-monitor.h"
33 #undef INTEGRATE_CORE_SCHEMA
36 * used by many functions to add description to entries
38 * WARNING: be_monitor may change as new databases are added,
39 * so it should not be used outside monitor_back_db_init()
40 * until monitor_back_db_open is called.
42 BackendDB *be_monitor;
44 static struct monitor_subsys_t **monitor_subsys;
45 static int monitor_subsys_opened;
46 static monitor_info_t monitor_info;
51 * the known subsystems are added to the subsystems
52 * array at backend initialization; other subsystems
53 * may be added by calling monitor_back_register_subsys()
54 * before the database is opened (e.g. by other backends
55 * or by overlays or modules).
57 static struct monitor_subsys_t known_monitor_subsys[] = {
59 SLAPD_MONITOR_BACKEND_NAME,
60 BER_BVNULL, BER_BVNULL, BER_BVNULL,
61 { BER_BVC( "This subsystem contains information about available backends." ),
63 MONITOR_F_PERSISTENT_CH,
64 monitor_subsys_backend_init,
70 SLAPD_MONITOR_CONN_NAME,
71 BER_BVNULL, BER_BVNULL, BER_BVNULL,
72 { BER_BVC( "This subsystem contains information about connections." ),
74 MONITOR_F_VOLATILE_CH,
75 monitor_subsys_conn_init,
81 SLAPD_MONITOR_DATABASE_NAME,
82 BER_BVNULL, BER_BVNULL, BER_BVNULL,
83 { BER_BVC( "This subsystem contains information about configured databases." ),
85 MONITOR_F_PERSISTENT_CH,
86 monitor_subsys_database_init,
92 SLAPD_MONITOR_LISTENER_NAME,
93 BER_BVNULL, BER_BVNULL, BER_BVNULL,
94 { BER_BVC( "This subsystem contains information about active listeners." ),
96 MONITOR_F_PERSISTENT_CH,
97 monitor_subsys_listener_init,
103 SLAPD_MONITOR_LOG_NAME,
104 BER_BVNULL, BER_BVNULL, BER_BVNULL,
105 { BER_BVC( "This subsystem contains information about logging." ),
106 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
109 monitor_subsys_log_init,
115 SLAPD_MONITOR_OPS_NAME,
116 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 { BER_BVC( "This subsystem contains information about performed operations." ),
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_ops_init,
126 SLAPD_MONITOR_OVERLAY_NAME,
127 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128 { BER_BVC( "This subsystem contains information about available overlays." ),
130 MONITOR_F_PERSISTENT_CH,
131 monitor_subsys_overlay_init,
137 SLAPD_MONITOR_SASL_NAME,
138 BER_BVNULL, BER_BVNULL, BER_BVNULL,
139 { BER_BVC( "This subsystem contains information about SASL." ),
148 SLAPD_MONITOR_SENT_NAME,
149 BER_BVNULL, BER_BVNULL, BER_BVNULL,
150 { BER_BVC( "This subsystem contains statistics." ),
152 MONITOR_F_PERSISTENT_CH,
153 monitor_subsys_sent_init,
159 SLAPD_MONITOR_THREAD_NAME,
160 BER_BVNULL, BER_BVNULL, BER_BVNULL,
161 { BER_BVC( "This subsystem contains information about threads." ),
163 MONITOR_F_PERSISTENT_CH,
164 monitor_subsys_thread_init,
170 SLAPD_MONITOR_TIME_NAME,
171 BER_BVNULL, BER_BVNULL, BER_BVNULL,
172 { BER_BVC( "This subsystem contains information about time." ),
174 MONITOR_F_PERSISTENT_CH,
175 monitor_subsys_time_init,
181 SLAPD_MONITOR_TLS_NAME,
182 BER_BVNULL, BER_BVNULL, BER_BVNULL,
183 { BER_BVC( "This subsystem contains information about TLS." ),
192 SLAPD_MONITOR_RWW_NAME,
193 BER_BVNULL, BER_BVNULL, BER_BVNULL,
194 { BER_BVC( "This subsystem contains information about read/write waiters." ),
196 MONITOR_F_PERSISTENT_CH,
197 monitor_subsys_rww_init,
206 monitor_back_register_subsys(
207 monitor_subsys_t *ms )
211 if ( monitor_subsys ) {
212 for ( ; monitor_subsys[ i ] != NULL; i++ )
213 /* just count'em */ ;
216 monitor_subsys = ch_realloc( monitor_subsys,
217 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
219 if ( monitor_subsys == NULL ) {
223 monitor_subsys[ i ] = ms;
224 monitor_subsys[ i + 1 ] = NULL;
226 /* if a subsystem is registered __AFTER__ subsystem
227 * initialization (depending on the sequence the databases
228 * are listed in slapd.conf), init it */
229 if ( monitor_subsys_opened ) {
231 /* FIXME: this should only be possible
232 * if be_monitor is already initialized */
233 assert( be_monitor != NULL );
235 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
239 ms->mss_flags |= MONITOR_F_OPENED;
252 typedef struct entry_limbo_t {
256 struct berval el_ndn;
257 struct berval el_base;
259 struct berval el_filter;
260 monitor_callback_t *el_cb;
261 struct entry_limbo_t *el_next;
265 monitor_back_is_configured( void )
267 return be_monitor != NULL;
271 monitor_back_register_entry(
273 monitor_callback_t *cb )
277 if ( be_monitor == NULL ) {
278 Debug( LDAP_DEBUG_ANY,
279 "monitor_back_register_entry(\"%s\"): "
280 "monitor database not configured.\n",
281 e->e_name.bv_val, 0, 0 );
285 mi = ( monitor_info_t * )be_monitor->be_private;
287 assert( mi != NULL );
289 assert( e->e_private == NULL );
291 if ( monitor_subsys_opened ) {
292 Entry *e_parent = NULL,
295 struct berval pdn = BER_BVNULL;
296 monitor_entry_t *mp = NULL,
300 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
302 Debug( LDAP_DEBUG_ANY,
303 "monitor_back_register_entry(\"%s\"): "
305 e->e_name.bv_val, 0, 0 );
306 monitor_cache_release( mi, e_parent );
310 dnParent( &e->e_nname, &pdn );
311 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
312 /* parent does not exist */
313 Debug( LDAP_DEBUG_ANY,
314 "monitor_back_register_entry(\"%s\"): "
315 "parent \"%s\" not found\n",
316 e->e_name.bv_val, pdn.bv_val, 0 );
320 assert( e_parent->e_private != NULL );
321 mp_parent = ( monitor_entry_t * )e_parent->e_private;
323 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
324 /* entry is volatile; cannot append children */
325 Debug( LDAP_DEBUG_ANY,
326 "monitor_back_register_entry(\"%s\"): "
327 "parent \"%s\" is volatile\n",
328 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
333 mp = monitor_entrypriv_create();
335 Debug( LDAP_DEBUG_ANY,
336 "monitor_back_register_entry(\"%s\"): "
337 "monitor_entrypriv_create() failed\n",
338 e->e_name.bv_val, 0, 0 );
343 e_new = entry_dup( e );
344 if ( e_new == NULL ) {
345 Debug( LDAP_DEBUG_ANY,
346 "monitor_back_register_entry(\"%s\"): "
347 "entry_dup() failed\n",
348 e->e_name.bv_val, 0, 0 );
353 e_new->e_private = ( void * )mp;
354 mp->mp_info = mp_parent->mp_info;
355 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
358 ep = &mp_parent->mp_children;
360 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
361 ep = &mp_parent->mp_next;
365 if ( monitor_cache_add( mi, e_new ) ) {
366 Debug( LDAP_DEBUG_ANY,
367 "monitor_back_register_entry(\"%s\"): "
368 "unable to add entry\n",
369 e->e_name.bv_val, 0, 0 );
380 e_new->e_private = NULL;
386 monitor_cache_release( mi, e_parent );
390 entry_limbo_t **elpp, el = { 0 };
392 el.el_type = LIMBO_ENTRY;
394 el.el_e = entry_dup( e );
395 if ( el.el_e == NULL ) {
396 Debug( LDAP_DEBUG_ANY,
397 "monitor_back_register_entry(\"%s\"): "
398 "entry_dup() failed\n",
399 e->e_name.bv_val, 0, 0 );
405 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
407 elpp = &(*elpp)->el_next )
410 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
411 if ( *elpp == NULL ) {
412 el.el_e->e_private = NULL;
413 entry_free( el.el_e );
425 monitor_back_register_entry_parent(
427 monitor_callback_t *cb,
430 struct berval *filter )
433 struct berval ndn = BER_BVNULL;
435 if ( be_monitor == NULL ) {
436 Debug( LDAP_DEBUG_ANY,
437 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
438 "monitor database not configured.\n",
439 BER_BVISNULL( base ) ? "" : base->bv_val,
440 ldap_pvt_scope2str( scope ),
441 BER_BVISNULL( filter ) ? "" : filter->bv_val );
445 mi = ( monitor_info_t * )be_monitor->be_private;
447 assert( mi != NULL );
449 assert( e->e_private == NULL );
451 if ( BER_BVISNULL( filter ) ) {
453 Debug( LDAP_DEBUG_ANY,
454 "monitor_back_register_entry_parent(\"\"): "
455 "need a valid filter\n",
460 if ( monitor_subsys_opened ) {
461 Entry *e_parent = NULL,
464 struct berval e_name = BER_BVNULL,
465 e_nname = BER_BVNULL;
466 monitor_entry_t *mp = NULL,
470 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
471 /* entry does not exist */
472 Debug( LDAP_DEBUG_ANY,
473 "monitor_back_register_entry_parent(\"\"): "
474 "base=\"%s\" scope=%d filter=\"%s\": "
475 "unable to find entry\n",
476 base->bv_val ? base->bv_val : "\"\"",
477 scope, filter->bv_val );
481 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
482 /* entry does not exist */
483 Debug( LDAP_DEBUG_ANY,
484 "monitor_back_register_entry_parent(\"%s\"): "
485 "parent entry does not exist\n",
491 assert( e_parent->e_private != NULL );
492 mp_parent = ( monitor_entry_t * )e_parent->e_private;
494 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
495 /* entry is volatile; cannot append callback */
496 Debug( LDAP_DEBUG_ANY,
497 "monitor_back_register_entry_parent(\"%s\"): "
498 "entry is volatile\n",
499 e_parent->e_name.bv_val, 0, 0 );
504 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
505 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
507 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
508 /* entry already exists */
509 Debug( LDAP_DEBUG_ANY,
510 "monitor_back_register_entry_parent(\"%s\"): "
511 "entry already exists\n",
512 e_name.bv_val, 0, 0 );
513 monitor_cache_release( mi, e_new );
518 mp = monitor_entrypriv_create();
520 Debug( LDAP_DEBUG_ANY,
521 "monitor_back_register_entry_parent(\"%s\"): "
522 "monitor_entrypriv_create() failed\n",
523 e->e_name.bv_val, 0, 0 );
528 e_new = entry_dup( e );
529 if ( e_new == NULL ) {
530 Debug( LDAP_DEBUG_ANY,
531 "monitor_back_register_entry(\"%s\"): "
532 "entry_dup() failed\n",
533 e->e_name.bv_val, 0, 0 );
537 ch_free( e_new->e_name.bv_val );
538 ch_free( e_new->e_nname.bv_val );
539 e_new->e_name = e_name;
540 e_new->e_nname = e_nname;
542 e_new->e_private = ( void * )mp;
543 mp->mp_info = mp_parent->mp_info;
544 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
547 ep = &mp_parent->mp_children;
549 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
550 ep = &mp_parent->mp_next;
554 if ( monitor_cache_add( mi, e_new ) ) {
555 Debug( LDAP_DEBUG_ANY,
556 "monitor_back_register_entry(\"%s\"): "
557 "unable to add entry\n",
558 e->e_name.bv_val, 0, 0 );
564 if ( !BER_BVISNULL( &ndn ) ) {
565 ch_free( ndn.bv_val );
573 e_new->e_private = NULL;
579 monitor_cache_release( mi, e_parent );
583 entry_limbo_t **elpp, el = { 0 };
585 el.el_type = LIMBO_ENTRY_PARENT;
587 el.el_e = entry_dup( e );
588 if ( el.el_e == NULL ) {
589 Debug( LDAP_DEBUG_ANY,
590 "monitor_back_register_entry(\"%s\"): "
591 "entry_dup() failed\n",
592 e->e_name.bv_val, 0, 0 );
596 if ( !BER_BVISNULL( base ) ) {
597 ber_dupbv( &el.el_base, base );
600 if ( !BER_BVISNULL( filter ) ) {
601 ber_dupbv( &el.el_filter, filter );
606 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
608 elpp = &(*elpp)->el_next )
611 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
612 if ( *elpp == NULL ) {
613 el.el_e->e_private = NULL;
614 entry_free( el.el_e );
626 monitor_filter2ndn_cb( Operation *op, SlapReply *rs )
628 if ( rs->sr_type == REP_SEARCH ) {
629 struct berval *ndn = op->o_callback->sc_private;
631 ber_dupbv( ndn, &rs->sr_entry->e_nname );
641 struct berval *filter,
644 Connection conn = { 0 };
645 OperationBuffer opbuf;
647 SlapReply rs = { 0 };
648 slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
653 if ( be_monitor == NULL ) {
657 op = (Operation *) &opbuf;
658 connection_fake_init( &conn, op, &conn );
660 op->o_tag = LDAP_REQ_SEARCH;
662 /* use global malloc for now */
663 if ( op->o_tmpmemctx ) {
664 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
665 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
666 op->o_tmpmemctx = NULL;
668 op->o_tmpmfuncs = &ch_mfuncs;
670 op->o_bd = be_monitor;
671 if ( base == NULL || BER_BVISNULL( base ) ) {
672 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
674 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
678 if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn,
679 op->o_tmpmemctx ) ) {
684 op->o_callback = &cb;
685 cb.sc_private = (void *)ndn;
687 op->ors_scope = scope;
688 op->ors_filter = str2filter_x( op, filter->bv_val );
689 if ( op->ors_filter == NULL ) {
693 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
694 op->ors_attrs = slap_anlist_no_attrs;
695 op->ors_attrsonly = 0;
696 op->ors_tlimit = SLAP_NO_LIMIT;
698 op->ors_limit = NULL;
699 op->ors_deref = LDAP_DEREF_NEVER;
702 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
704 op->o_dn = be_monitor->be_rootdn;
705 op->o_ndn = be_monitor->be_rootndn;
707 rc = op->o_bd->be_search( op, &rs );
710 if ( op->ors_filter != NULL ) {
711 filter_free_x( op, op->ors_filter );
713 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
714 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
716 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
717 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
719 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
720 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
727 switch ( rs.sr_err ) {
729 if ( BER_BVISNULL( ndn ) ) {
734 case LDAP_SIZELIMIT_EXCEEDED:
736 if ( !BER_BVISNULL( ndn ) ) {
737 ber_memfree( ndn->bv_val );
748 monitor_back_register_entry_attrs(
749 struct berval *ndn_in,
751 monitor_callback_t *cb,
754 struct berval *filter )
757 struct berval ndn = BER_BVNULL;
758 char *fname = ( a == NULL ? "callback" : "attrs" );
760 if ( be_monitor == NULL ) {
761 char buf[ SLAP_TEXT_BUFLEN ];
763 snprintf( buf, sizeof( buf ),
764 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
765 "monitor database not configured.\n",
767 BER_BVISNULL( base ) ? "" : base->bv_val,
768 ldap_pvt_scope2str( scope ),
769 BER_BVISNULL( filter ) ? "" : filter->bv_val );
770 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
775 mi = ( monitor_info_t * )be_monitor->be_private;
777 assert( mi != NULL );
779 if ( ndn_in != NULL ) {
783 if ( a == NULL && cb == NULL ) {
788 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
789 && BER_BVISNULL( filter ) )
792 Debug( LDAP_DEBUG_ANY,
793 "monitor_back_register_entry_%s(\"\"): "
794 "need a valid filter\n",
799 if ( monitor_subsys_opened ) {
801 Attribute **atp = NULL;
802 monitor_entry_t *mp = NULL;
803 monitor_callback_t **mcp = NULL;
807 if ( BER_BVISNULL( &ndn ) ) {
808 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
809 char buf[ SLAP_TEXT_BUFLEN ];
811 snprintf( buf, sizeof( buf ),
812 "monitor_back_register_entry_%s(\"\"): "
813 "base=\"%s\" scope=%d filter=\"%s\": "
814 "unable to find entry\n",
816 base->bv_val ? base->bv_val : "\"\"",
817 scope, filter->bv_val );
819 /* entry does not exist */
820 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
827 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
828 /* entry does not exist */
829 Debug( LDAP_DEBUG_ANY,
830 "monitor_back_register_entry_%s(\"%s\"): "
831 "entry does not exist\n",
832 fname, ndn.bv_val, 0 );
837 assert( e->e_private != NULL );
838 mp = ( monitor_entry_t * )e->e_private;
840 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
841 /* entry is volatile; cannot append callback */
842 Debug( LDAP_DEBUG_ANY,
843 "monitor_back_register_entry_%s(\"%s\"): "
844 "entry is volatile\n",
845 fname, e->e_name.bv_val, 0 );
851 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
852 /* just get to last */ ;
854 for ( ; a != NULL; a = a->a_next ) {
855 assert( a->a_desc != NULL );
856 assert( a->a_vals != NULL );
858 if ( attr_find( e->e_attrs, a->a_desc ) ) {
859 attr_merge( e, a->a_desc, a->a_vals,
860 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
863 *atp = attr_dup( a );
864 if ( *atp == NULL ) {
865 Debug( LDAP_DEBUG_ANY,
866 "monitor_back_register_entry_%s(\"%s\"): "
867 "attr_dup() failed\n",
868 fname, e->e_name.bv_val, 0 );
872 atp = &(*atp)->a_next;
878 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
881 /* NOTE: we do not clear cb->mc_next, so this function
882 * can be used to append a list of callbacks */
895 ber_memfree( ndn.bv_val );
899 monitor_cache_release( mi, e );
903 entry_limbo_t **elpp, el = { 0 };
905 el.el_type = LIMBO_ATTRS;
906 if ( !BER_BVISNULL( &ndn ) ) {
907 ber_dupbv( &el.el_ndn, &ndn );
909 if ( !BER_BVISNULL( base ) ) {
910 ber_dupbv( &el.el_base, base);
913 if ( !BER_BVISNULL( filter ) ) {
914 ber_dupbv( &el.el_filter, filter );
917 el.el_a = attrs_dup( a );
920 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
922 elpp = &(*elpp)->el_next )
925 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
926 if ( *elpp == NULL ) {
927 el.el_e->e_private = NULL;
928 entry_free( el.el_e );
940 monitor_back_register_entry_callback(
942 monitor_callback_t *cb,
945 struct berval *filter )
947 return monitor_back_register_entry_attrs( ndn, NULL, cb,
948 base, scope, filter );
952 * TODO: add corresponding calls to remove installed callbacks, entries
953 * and so, in case the entity that installed them is removed (e.g. a
954 * database, via back-config)
957 monitor_back_unregister_entry(
962 if ( be_monitor == NULL ) {
963 Debug( LDAP_DEBUG_ANY,
964 "monitor_back_unregister_entry(\"%s\"): "
965 "monitor database not configured.\n",
966 target_e->e_name.bv_val, 0, 0 );
971 mi = ( monitor_info_t * )be_monitor->be_private;
973 assert( mi != NULL );
975 if ( monitor_subsys_opened ) {
977 monitor_entry_t *mp = NULL;
978 monitor_callback_t *cb = NULL;
980 if ( monitor_cache_remove( mi, &target_e->e_nname, &e ) != 0 ) {
981 /* entry does not exist */
982 Debug( LDAP_DEBUG_ANY,
983 "monitor_back_unregister_entry(\"%s\"): "
984 "entry removal failed.\n",
985 target_e->e_name.bv_val, 0, 0 );
989 mp = (monitor_entry_t *)e->e_private;
990 assert( mp != NULL );
992 for ( cb = mp->mp_cb; cb != NULL; ) {
993 monitor_callback_t *next = cb->mc_next;
996 (void)cb->mc_free( e, cb->mc_private );
1004 /* TODO: remove from limbo */
1012 monitor_back_unregister_entry_attrs(
1013 struct berval *ndn_in,
1014 Attribute *target_a,
1015 monitor_callback_t *target_cb,
1016 struct berval *base,
1018 struct berval *filter )
1021 struct berval ndn = BER_BVNULL;
1022 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1024 if ( be_monitor == NULL ) {
1025 char buf[ SLAP_TEXT_BUFLEN ];
1027 snprintf( buf, sizeof( buf ),
1028 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1029 "monitor database not configured.\n",
1031 BER_BVISNULL( base ) ? "" : base->bv_val,
1032 (char *)ldap_pvt_scope2str( scope ),
1033 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1034 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1039 mi = ( monitor_info_t * )be_monitor->be_private;
1041 assert( mi != NULL );
1043 if ( ndn_in != NULL ) {
1047 if ( target_a == NULL && target_cb == NULL ) {
1052 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1053 && BER_BVISNULL( filter ) )
1056 Debug( LDAP_DEBUG_ANY,
1057 "monitor_back_unregister_entry_%s(\"\"): "
1058 "need a valid filter\n",
1063 if ( monitor_subsys_opened ) {
1065 monitor_entry_t *mp = NULL;
1068 if ( BER_BVISNULL( &ndn ) ) {
1069 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
1070 char buf[ SLAP_TEXT_BUFLEN ];
1072 snprintf( buf, sizeof( buf ),
1073 "monitor_back_unregister_entry_%s(\"\"): "
1074 "base=\"%s\" scope=%d filter=\"%s\": "
1075 "unable to find entry\n",
1077 base->bv_val ? base->bv_val : "\"\"",
1078 scope, filter->bv_val );
1080 /* entry does not exist */
1081 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1088 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1089 /* entry does not exist */
1090 Debug( LDAP_DEBUG_ANY,
1091 "monitor_back_unregister_entry(\"%s\"): "
1092 "entry removal failed.\n",
1097 mp = (monitor_entry_t *)e->e_private;
1098 assert( mp != NULL );
1100 if ( target_cb != NULL ) {
1101 monitor_callback_t **cbp;
1103 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1104 if ( *cbp == target_cb ) {
1105 if ( (*cbp)->mc_free ) {
1106 (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
1108 *cbp = (*cbp)->mc_next;
1109 ch_free( target_cb );
1115 if ( target_a != NULL ) {
1118 for ( a = target_a; a != NULL; a = a->a_next ) {
1119 Modification mod = { 0 };
1121 char textbuf[ SLAP_TEXT_BUFLEN ];
1123 mod.sm_op = LDAP_MOD_DELETE;
1124 mod.sm_desc = a->a_desc;
1125 mod.sm_values = a->a_vals;
1126 mod.sm_nvalues = a->a_nvals;
1128 (void)modify_delete_values( e, &mod, 1,
1129 &text, textbuf, sizeof( textbuf ) );
1134 ber_memfree( ndn.bv_val );
1138 monitor_cache_release( mi, e );
1142 /* TODO: remove from limbo */
1150 monitor_back_unregister_entry_callback(
1152 monitor_callback_t *cb,
1153 struct berval *base,
1155 struct berval *filter )
1157 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1158 * unregister the callback; if a is not null, unregister the
1159 * given attrs. In any case, call cb->cb_free */
1160 return monitor_back_unregister_entry_attrs( ndn,
1161 NULL, cb, base, scope, filter );
1165 monitor_back_get_subsys( const char *name )
1167 if ( monitor_subsys != NULL ) {
1170 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1171 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1172 return monitor_subsys[ i ];
1181 monitor_back_get_subsys_by_dn(
1185 if ( monitor_subsys != NULL ) {
1189 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1190 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1191 return monitor_subsys[ i ];
1196 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1197 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1198 return monitor_subsys[ i ];
1208 monitor_back_initialize(
1211 static char *controls[] = {
1212 LDAP_CONTROL_MANAGEDSAIT,
1216 static ConfigTable monitorcfg[] = {
1217 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1218 NULL, NULL, NULL, NULL }
1221 static ConfigOCs monitorocs[] = {
1222 { "( OLcfgDbOc:4.1 "
1223 "NAME 'olcMonitorConfig' "
1224 "DESC 'Monitor backend configuration' "
1225 "SUP olcDatabaseConfig "
1227 Cft_Database, monitorcfg },
1237 { "monitor", "( 1.3.6.1.4.1.4203.666.3.16.1 "
1239 "DESC 'OpenLDAP system monitoring' "
1240 "SUP top STRUCTURAL "
1249 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1250 offsetof(monitor_info_t, mi_oc_monitor) },
1251 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.16.2 "
1252 "NAME 'monitorServer' "
1253 "DESC 'Server monitoring root entry' "
1254 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1255 offsetof(monitor_info_t, mi_oc_monitorServer) },
1256 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.16.3 "
1257 "NAME 'monitorContainer' "
1258 "DESC 'monitor container class' "
1259 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1260 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1261 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.16.4 "
1262 "NAME 'monitorCounterObject' "
1263 "DESC 'monitor counter class' "
1264 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1265 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1266 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.16.5 "
1267 "NAME 'monitorOperation' "
1268 "DESC 'monitor operation class' "
1269 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1270 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1271 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.16.6 "
1272 "NAME 'monitorConnection' "
1273 "DESC 'monitor connection class' "
1274 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1275 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1276 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.16.7 "
1277 "NAME 'managedObject' "
1278 "DESC 'monitor managed entity class' "
1279 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1280 offsetof(monitor_info_t, mi_oc_managedObject) },
1281 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.16.8 "
1282 "NAME 'monitoredObject' "
1283 "DESC 'monitor monitored entity class' "
1284 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1285 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1286 { NULL, NULL, 0, -1 }
1288 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.55.1 "
1289 "NAME 'monitoredInfo' "
1290 "DESC 'monitored info' "
1292 "EQUALITY caseIgnoreMatch "
1293 "SUBSTR caseIgnoreSubstringsMatch "
1294 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1295 "NO-USER-MODIFICATION "
1296 "USAGE directoryOperation )", SLAP_AT_HIDE,
1297 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1298 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.55.2 "
1299 "NAME 'managedInfo' "
1300 "DESC 'monitor managed info' "
1301 "SUP name )", SLAP_AT_HIDE,
1302 offsetof(monitor_info_t, mi_ad_managedInfo) },
1303 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.55.3 "
1304 "NAME 'monitorCounter' "
1305 "DESC 'monitor counter' "
1306 "EQUALITY integerMatch "
1307 "ORDERING integerOrderingMatch "
1308 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1309 "NO-USER-MODIFICATION "
1310 "USAGE directoryOperation )", SLAP_AT_HIDE,
1311 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1312 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.55.4 "
1313 "NAME 'monitorOpCompleted' "
1314 "DESC 'monitor completed operations' "
1315 "SUP monitorCounter "
1316 "NO-USER-MODIFICATION "
1317 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1318 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1319 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.55.5 "
1320 "NAME 'monitorOpInitiated' "
1321 "DESC 'monitor initiated operations' "
1322 "SUP monitorCounter "
1323 "NO-USER-MODIFICATION "
1324 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1325 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1326 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.55.6 "
1327 "NAME 'monitorConnectionNumber' "
1328 "DESC 'monitor connection number' "
1329 "SUP monitorCounter "
1330 "NO-USER-MODIFICATION "
1331 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1332 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1333 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.55.7 "
1334 "NAME 'monitorConnectionAuthzDN' "
1335 "DESC 'monitor connection authorization DN' "
1336 /* "SUP distinguishedName " */
1337 "EQUALITY distinguishedNameMatch "
1338 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1339 "NO-USER-MODIFICATION "
1340 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1341 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1342 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.55.8 "
1343 "NAME 'monitorConnectionLocalAddress' "
1344 "DESC 'monitor connection local address' "
1345 "SUP monitoredInfo "
1346 "NO-USER-MODIFICATION "
1347 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1348 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1349 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.55.9 "
1350 "NAME 'monitorConnectionPeerAddress' "
1351 "DESC 'monitor connection peer address' "
1352 "SUP monitoredInfo "
1353 "NO-USER-MODIFICATION "
1354 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1355 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1356 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.55.10 "
1357 "NAME 'monitorTimestamp' "
1358 "DESC 'monitor timestamp' "
1359 "EQUALITY generalizedTimeMatch "
1360 "ORDERING generalizedTimeOrderingMatch "
1361 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1363 "NO-USER-MODIFICATION "
1364 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1365 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1366 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.55.11 "
1367 "NAME 'monitorOverlay' "
1368 "DESC 'name of overlays defined for a given database' "
1369 "SUP monitoredInfo "
1370 "NO-USER-MODIFICATION "
1371 "USAGE directoryOperation )", SLAP_AT_HIDE,
1372 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1373 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.55.12 "
1375 "DESC 'read/write status of a given database' "
1376 "EQUALITY booleanMatch "
1377 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1379 "USAGE directoryOperation )", SLAP_AT_HIDE,
1380 offsetof(monitor_info_t, mi_ad_readOnly) },
1381 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.55.13 "
1382 "NAME 'restrictedOperation' "
1383 "DESC 'name of restricted operation for a given database' "
1384 "SUP managedInfo )", SLAP_AT_HIDE,
1385 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1386 { "monitorConnectionProtocol", "( 1.3.6.1.4.1.4203.666.1.55.14 "
1387 "NAME 'monitorConnectionProtocol' "
1388 "DESC 'monitor connection protocol' "
1389 "SUP monitoredInfo "
1390 "NO-USER-MODIFICATION "
1391 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1392 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1393 { "monitorConnectionOpsReceived", "( 1.3.6.1.4.1.4203.666.1.55.15 "
1394 "NAME 'monitorConnectionOpsReceived' "
1395 "DESC 'monitor number of operations received by the connection' "
1396 "SUP monitorCounter "
1397 "NO-USER-MODIFICATION "
1398 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1399 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1400 { "monitorConnectionOpsExecuting", "( 1.3.6.1.4.1.4203.666.1.55.16 "
1401 "NAME 'monitorConnectionOpsExecuting' "
1402 "DESC 'monitor number of operations in execution within the connection' "
1403 "SUP monitorCounter "
1404 "NO-USER-MODIFICATION "
1405 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1406 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1407 { "monitorConnectionOpsPending", "( 1.3.6.1.4.1.4203.666.1.55.17 "
1408 "NAME 'monitorConnectionOpsPending' "
1409 "DESC 'monitor number of pending operations within the connection' "
1410 "SUP monitorCounter "
1411 "NO-USER-MODIFICATION "
1412 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1413 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1414 { "monitorConnectionOpsCompleted", "( 1.3.6.1.4.1.4203.666.1.55.18 "
1415 "NAME 'monitorConnectionOpsCompleted' "
1416 "DESC 'monitor number of operations completed within the connection' "
1417 "SUP monitorCounter "
1418 "NO-USER-MODIFICATION "
1419 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1420 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1421 { "monitorConnectionGet", "( 1.3.6.1.4.1.4203.666.1.55.19 "
1422 "NAME 'monitorConnectionGet' "
1423 "DESC 'number of times connection_get() was called so far' "
1424 "SUP monitorCounter "
1425 "NO-USER-MODIFICATION "
1426 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1427 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1428 { "monitorConnectionRead", "( 1.3.6.1.4.1.4203.666.1.55.20 "
1429 "NAME 'monitorConnectionRead' "
1430 "DESC 'number of times connection_read() was called so far' "
1431 "SUP monitorCounter "
1432 "NO-USER-MODIFICATION "
1433 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1434 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1435 { "monitorConnectionWrite", "( 1.3.6.1.4.1.4203.666.1.55.21 "
1436 "NAME 'monitorConnectionWrite' "
1437 "DESC 'number of times connection_write() was called so far' "
1438 "SUP monitorCounter "
1439 "NO-USER-MODIFICATION "
1440 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1441 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1442 { "monitorConnectionMask", "( 1.3.6.1.4.1.4203.666.1.55.22 "
1443 "NAME 'monitorConnectionMask' "
1444 "DESC 'monitor connection mask' "
1445 "SUP monitoredInfo "
1446 "NO-USER-MODIFICATION "
1447 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1448 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1449 { "monitorConnectionListener", "( 1.3.6.1.4.1.4203.666.1.55.23 "
1450 "NAME 'monitorConnectionListener' "
1451 "DESC 'monitor connection listener' "
1452 "SUP monitoredInfo "
1453 "NO-USER-MODIFICATION "
1454 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1455 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1456 { "monitorConnectionPeerDomain", "( 1.3.6.1.4.1.4203.666.1.55.24 "
1457 "NAME 'monitorConnectionPeerDomain' "
1458 "DESC 'monitor connection peer domain' "
1459 "SUP monitoredInfo "
1460 "NO-USER-MODIFICATION "
1461 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1462 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1463 { "monitorConnectionStartTime", "( 1.3.6.1.4.1.4203.666.1.55.25 "
1464 "NAME 'monitorConnectionStartTime' "
1465 "DESC 'monitor connection start time' "
1466 "SUP monitorTimestamp "
1468 "NO-USER-MODIFICATION "
1469 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1470 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1471 { "monitorConnectionActivityTime", "( 1.3.6.1.4.1.4203.666.1.55.26 "
1472 "NAME 'monitorConnectionActivityTime' "
1473 "DESC 'monitor connection activity time' "
1474 "SUP monitorTimestamp "
1476 "NO-USER-MODIFICATION "
1477 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1478 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1479 { "monitorIsShadow", "( 1.3.6.1.4.1.4203.666.1.55.27 "
1480 "NAME 'monitorIsShadow' "
1481 "DESC 'TRUE if the database is shadow' "
1482 "EQUALITY booleanMatch "
1483 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1485 "USAGE directoryOperation )", SLAP_AT_HIDE,
1486 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1487 { "monitorUpdateRef", "( 1.3.6.1.4.1.4203.666.1.55.28 "
1488 "NAME 'monitorUpdateRef' "
1489 "DESC 'update referral for shadow databases' "
1490 "SUP monitoredInfo "
1492 "USAGE directoryOperation )", SLAP_AT_HIDE,
1493 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1494 { "monitorRuntimeConfig", "( 1.3.6.1.4.1.4203.666.1.55.29 "
1495 "NAME 'monitorRuntimeConfig' "
1496 "DESC 'TRUE if component allows runtime configuration' "
1497 "EQUALITY booleanMatch "
1498 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1500 "USAGE directoryOperation )", SLAP_AT_HIDE,
1501 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1502 { NULL, NULL, 0, -1 }
1509 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1510 { "olmSubSystemAttributes", "olmAttributes:0" },
1511 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1512 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1514 /* for example, back-bdb specific attrs
1515 * are in "olmDatabaseAttributes:1"
1517 * NOTE: developers, please record here OID assignments
1518 * for other modules */
1520 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1521 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1522 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1523 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1525 /* for example, back-bdb specific objectClasses
1526 * are in "olmDatabaseObjectClasses:1"
1528 * NOTE: developers, please record here OID assignments
1529 * for other modules */
1536 monitor_info_t *mi = &monitor_info;
1538 for ( i = 0; s_oid[ i ].name; i++ ) {
1541 argv[ 0 ] = "monitor";
1542 argv[ 1 ] = s_oid[ i ].name;
1543 argv[ 2 ] = s_oid[ i ].oid;
1545 if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) {
1546 Debug( LDAP_DEBUG_ANY,
1547 "monitor_back_initialize: unable to add "
1548 "objectIdentifier \"%s=%s\"\n",
1549 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1554 /* schema integration */
1555 for ( i = 0; mat[ i ].name; i++ ) {
1556 LDAPAttributeType *at;
1559 AttributeDescription **ad;
1561 at = ldap_str2attributetype( mat[ i ].schema, &code,
1562 &err, LDAP_SCHEMA_ALLOW_ALL );
1564 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1565 "in AttributeType \"%s\" %s before %s\n",
1566 mat[ i ].name, ldap_scherr2str(code), err );
1570 if ( at->at_oid == NULL ) {
1571 ldap_attributetype_free(at);
1572 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1573 "null OID for attributeType \"%s\"\n",
1574 mat[ i ].name, 0, 0 );
1578 code = at_add(at, 0, NULL, &err);
1580 ldap_attributetype_free(at);
1581 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1582 "%s in attributeType \"%s\"\n",
1583 scherr2str(code), mat[ i ].name, 0 );
1588 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1590 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1591 Debug( LDAP_DEBUG_ANY,
1592 "monitor_back_db_init: %s\n", text, 0, 0 );
1596 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1599 for ( i = 0; moc[ i ].name; i++ ) {
1600 LDAPObjectClass *oc;
1605 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1606 LDAP_SCHEMA_ALLOW_ALL );
1608 Debug( LDAP_DEBUG_ANY,
1609 "unable to parse monitor objectclass \"%s\": "
1610 "%s before %s\n" , moc[ i ].name,
1611 ldap_scherr2str(code), err );
1615 if ( oc->oc_oid == NULL ) {
1616 ldap_objectclass_free(oc);
1617 Debug( LDAP_DEBUG_ANY,
1618 "objectclass \"%s\" has no OID\n" ,
1619 moc[ i ].name, 0, 0 );
1623 code = oc_add(oc, 0, NULL, &err);
1625 ldap_objectclass_free(oc);
1626 Debug( LDAP_DEBUG_ANY,
1627 "objectclass \"%s\": %s \"%s\"\n" ,
1628 moc[ i ].name, scherr2str(code), err );
1633 Oc = oc_find( moc[ i ].name );
1635 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1636 "unable to find objectClass %s "
1637 "(just added)\n", moc[ i ].name, 0, 0 );
1641 Oc->soc_flags |= moc[ i ].flags;
1643 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1646 bi->bi_controls = controls;
1650 bi->bi_config = monitor_back_config;
1654 bi->bi_db_init = monitor_back_db_init;
1656 bi->bi_db_config = monitor_back_db_config;
1658 bi->bi_db_open = monitor_back_db_open;
1659 bi->bi_db_close = 0;
1660 bi->bi_db_destroy = monitor_back_db_destroy;
1662 bi->bi_op_bind = monitor_back_bind;
1663 bi->bi_op_unbind = 0;
1664 bi->bi_op_search = monitor_back_search;
1665 bi->bi_op_compare = monitor_back_compare;
1666 bi->bi_op_modify = monitor_back_modify;
1667 bi->bi_op_modrdn = 0;
1669 bi->bi_op_delete = 0;
1670 bi->bi_op_abandon = 0;
1672 bi->bi_extended = 0;
1674 bi->bi_entry_release_rw = 0;
1675 bi->bi_chk_referrals = 0;
1676 bi->bi_operational = monitor_back_operational;
1679 * hooks for slap tools
1681 bi->bi_tool_entry_open = 0;
1682 bi->bi_tool_entry_close = 0;
1683 bi->bi_tool_entry_first = 0;
1684 bi->bi_tool_entry_next = 0;
1685 bi->bi_tool_entry_get = 0;
1686 bi->bi_tool_entry_put = 0;
1687 bi->bi_tool_entry_reindex = 0;
1688 bi->bi_tool_sync = 0;
1689 bi->bi_tool_dn2id_get = 0;
1690 bi->bi_tool_id2entry_get = 0;
1691 bi->bi_tool_entry_modify = 0;
1693 bi->bi_connection_init = 0;
1694 bi->bi_connection_destroy = 0;
1697 * configuration objectClasses (fake)
1699 bi->bi_cf_ocs = monitorocs;
1701 rc = config_register_schema( monitorcfg, monitorocs );
1710 monitor_back_db_init(
1714 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1719 monitor_subsys_t *ms;
1724 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1725 if ( monitor_back_register_subsys( ms ) ) {
1731 * database monitor can be defined once only
1733 if ( be_monitor != NULL ) {
1734 Debug( LDAP_DEBUG_ANY,
1735 "only one monitor database is allowed\n", 0, 0, 0 );
1740 /* indicate system schema supported */
1741 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1743 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1744 if( rc != LDAP_SUCCESS ) {
1745 Debug( LDAP_DEBUG_ANY,
1746 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
1751 ber_bvarray_add( &be->be_suffix, &pdn );
1752 ber_bvarray_add( &be->be_nsuffix, &ndn );
1754 /* NOTE: only one monitor database is allowed,
1755 * so we use static storage */
1756 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
1758 be->be_private = &monitor_info;
1760 be2 = select_backend( &ndn, 0, 0 );
1762 char *type = be2->bd_info->bi_type;
1764 if ( overlay_is_over( be2 ) ) {
1765 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
1766 type = oi->oi_orig->bi_type;
1769 Debug( LDAP_DEBUG_ANY,
1770 "\"monitor\" database serving namingContext \"%s\" "
1771 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
1772 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
1780 monitor_back_db_open(
1783 monitor_info_t *mi = (monitor_info_t *)be->be_private;
1784 struct monitor_subsys_t **ms;
1785 Entry *e, **ep, *root;
1786 monitor_entry_t *mp;
1788 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
1790 #ifdef HAVE_GMTIME_R
1793 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
1794 struct berval desc[] = {
1795 BER_BVC("This subtree contains monitoring/managing objects."),
1796 BER_BVC("This object contains information about this server."),
1797 BER_BVC("Most of the information is held in operational"
1798 " attributes, which must be explicitly requested."),
1801 assert( be_monitor != NULL );
1802 if ( be != be_monitor ) {
1809 #ifndef HAVE_GMTIME_R
1810 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
1812 #ifdef HACK_LOCAL_TIME
1813 # ifdef HAVE_LOCALTIME_R
1814 tms = localtime_r( &starttime, &tm_buf );
1816 tms = localtime( &starttime );
1817 # endif /* HAVE_LOCALTIME_R */
1818 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
1819 #else /* !HACK_LOCAL_TIME */
1820 # ifdef HAVE_GMTIME_R
1821 tms = gmtime_r( &starttime, &tm_buf );
1823 tms = gmtime( &starttime );
1824 # endif /* HAVE_GMTIME_R */
1825 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
1826 #endif /* !HACK_LOCAL_TIME */
1827 #ifndef HAVE_GMTIME_R
1828 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
1831 mi->mi_startTime.bv_val = tmbuf;
1832 mi->mi_startTime.bv_len = strlen( tmbuf );
1834 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
1835 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
1836 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
1838 mi->mi_creatorsName = be->be_rootdn;
1839 mi->mi_ncreatorsName = be->be_rootndn;
1843 * creates the "cn=Monitor" entry
1845 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
1849 Debug( LDAP_DEBUG_ANY,
1850 "unable to create \"%s\" entry\n",
1851 SLAPD_MONITOR_DN, 0, 0 );
1855 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
1857 bv.bv_val = strchr( (char *) Versionstr, '$' );
1858 if ( bv.bv_val != NULL ) {
1862 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
1865 end = strchr( bv.bv_val, '$' );
1866 if ( end != NULL ) {
1869 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
1874 bv.bv_len = end - bv.bv_val;
1877 bv.bv_len = strlen( bv.bv_val );
1880 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
1882 Debug( LDAP_DEBUG_ANY,
1883 "unable to add monitoredInfo to \"%s\" entry\n",
1884 SLAPD_MONITOR_DN, 0, 0 );
1889 mp = monitor_entrypriv_create();
1893 e->e_private = ( void * )mp;
1894 ep = &mp->mp_children;
1896 if ( monitor_cache_add( mi, e ) ) {
1897 Debug( LDAP_DEBUG_ANY,
1898 "unable to add entry \"%s\" to cache\n",
1899 SLAPD_MONITOR_DN, 0, 0 );
1905 * Create all the subsystem specific entries
1907 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1908 int len = strlen( monitor_subsys[ i ]->mss_name );
1912 dn.bv_len = len + sizeof( "cn=" ) - 1;
1913 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1914 strcpy( dn.bv_val, "cn=" );
1915 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1916 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1918 if ( rc != LDAP_SUCCESS ) {
1919 Debug( LDAP_DEBUG_ANY,
1920 "monitor RDN \"%s\" is invalid\n",
1925 e = monitor_entry_stub( &root->e_name, &root->e_nname,
1926 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
1930 Debug( LDAP_DEBUG_ANY,
1931 "unable to create \"%s\" entry\n",
1932 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1935 monitor_subsys[i]->mss_dn = e->e_name;
1936 monitor_subsys[i]->mss_ndn = e->e_nname;
1938 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
1939 attr_merge_normalize( e, slap_schema.si_ad_description,
1940 monitor_subsys[ i ]->mss_desc, NULL );
1943 mp = monitor_entrypriv_create();
1947 e->e_private = ( void * )mp;
1948 mp->mp_info = monitor_subsys[ i ];
1949 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1951 if ( monitor_cache_add( mi, e ) ) {
1952 Debug( LDAP_DEBUG_ANY,
1953 "unable to add entry \"%s\" to cache\n",
1954 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1962 assert( be != NULL );
1964 be->be_private = mi;
1967 * opens the monitor backend subsystems
1969 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1970 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1974 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1977 monitor_subsys_opened = 1;
1979 if ( mi->mi_entry_limbo ) {
1980 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
1985 switch ( el->el_type ) {
1987 monitor_back_register_entry(
1992 case LIMBO_ENTRY_PARENT:
1993 monitor_back_register_entry_parent(
2003 monitor_back_register_entry_attrs(
2013 monitor_back_register_entry_callback(
2026 entry_free( el->el_e );
2029 attrs_free( el->el_a );
2031 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2032 ber_memfree( el->el_ndn.bv_val );
2034 if ( !BER_BVISNULL( &el->el_base ) ) {
2035 ber_memfree( el->el_base.bv_val );
2037 if ( !BER_BVISNULL( &el->el_filter ) ) {
2038 ber_memfree( el->el_filter.bv_val );
2046 mi->mi_entry_limbo = NULL;
2053 monitor_back_config(
2061 * eventually, will hold backend specific configuration parameters
2063 return SLAP_CONF_UNKNOWN;
2068 monitor_back_db_config(
2075 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2078 * eventually, will hold database specific configuration parameters
2080 return SLAP_CONF_UNKNOWN;
2085 monitor_back_db_destroy(
2088 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2095 * FIXME: destroys all the data
2097 /* NOTE: mi points to static storage; don't free it */
2099 (void)monitor_cache_destroy( mi );
2101 if ( monitor_subsys ) {
2104 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2105 if ( monitor_subsys[ i ]->mss_destroy ) {
2106 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2109 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2110 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2114 ch_free( monitor_subsys );
2117 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2119 be->be_private = NULL;
2124 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2126 /* conditionally define the init_module() function */
2127 SLAP_BACKEND_INIT_MODULE( monitor )
2129 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */