1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2007 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
31 #include "back-monitor.h"
35 #undef INTEGRATE_CORE_SCHEMA
38 * used by many functions to add description to entries
40 * WARNING: be_monitor may change as new databases are added,
41 * so it should not be used outside monitor_back_db_init()
42 * until monitor_back_db_open is called.
44 BackendDB *be_monitor;
46 static struct monitor_subsys_t **monitor_subsys;
47 static int monitor_subsys_opened;
48 static monitor_info_t monitor_info;
49 static const monitor_extra_t monitor_extra = {
50 monitor_back_is_configured,
51 monitor_back_get_subsys,
52 monitor_back_get_subsys_by_dn,
54 monitor_back_register_subsys,
55 NULL, /* monitor_back_register_backend */
56 NULL, /* monitor_back_register_database */
57 NULL, /* monitor_back_register_overlay_info */
58 NULL, /* 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
74 * the known subsystems are added to the subsystems
75 * array at backend initialization; other subsystems
76 * may be added by calling monitor_back_register_subsys()
77 * before the database is opened (e.g. by other backends
78 * or by overlays or modules).
80 static struct monitor_subsys_t known_monitor_subsys[] = {
82 SLAPD_MONITOR_BACKEND_NAME,
83 BER_BVNULL, BER_BVNULL, BER_BVNULL,
84 { BER_BVC( "This subsystem contains information about available backends." ),
86 MONITOR_F_PERSISTENT_CH,
87 monitor_subsys_backend_init,
93 SLAPD_MONITOR_CONN_NAME,
94 BER_BVNULL, BER_BVNULL, BER_BVNULL,
95 { BER_BVC( "This subsystem contains information about connections." ),
97 MONITOR_F_VOLATILE_CH,
98 monitor_subsys_conn_init,
104 SLAPD_MONITOR_DATABASE_NAME,
105 BER_BVNULL, BER_BVNULL, BER_BVNULL,
106 { BER_BVC( "This subsystem contains information about configured databases." ),
108 MONITOR_F_PERSISTENT_CH,
109 monitor_subsys_database_init,
115 SLAPD_MONITOR_LISTENER_NAME,
116 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 { BER_BVC( "This subsystem contains information about active listeners." ),
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_listener_init,
126 SLAPD_MONITOR_LOG_NAME,
127 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128 { BER_BVC( "This subsystem contains information about logging." ),
129 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
132 monitor_subsys_log_init,
138 SLAPD_MONITOR_OPS_NAME,
139 BER_BVNULL, BER_BVNULL, BER_BVNULL,
140 { BER_BVC( "This subsystem contains information about performed operations." ),
142 MONITOR_F_PERSISTENT_CH,
143 monitor_subsys_ops_init,
149 SLAPD_MONITOR_OVERLAY_NAME,
150 BER_BVNULL, BER_BVNULL, BER_BVNULL,
151 { BER_BVC( "This subsystem contains information about available overlays." ),
153 MONITOR_F_PERSISTENT_CH,
154 monitor_subsys_overlay_init,
160 SLAPD_MONITOR_SASL_NAME,
161 BER_BVNULL, BER_BVNULL, BER_BVNULL,
162 { BER_BVC( "This subsystem contains information about SASL." ),
171 SLAPD_MONITOR_SENT_NAME,
172 BER_BVNULL, BER_BVNULL, BER_BVNULL,
173 { BER_BVC( "This subsystem contains statistics." ),
175 MONITOR_F_PERSISTENT_CH,
176 monitor_subsys_sent_init,
182 SLAPD_MONITOR_THREAD_NAME,
183 BER_BVNULL, BER_BVNULL, BER_BVNULL,
184 { BER_BVC( "This subsystem contains information about threads." ),
186 MONITOR_F_PERSISTENT_CH,
187 monitor_subsys_thread_init,
193 SLAPD_MONITOR_TIME_NAME,
194 BER_BVNULL, BER_BVNULL, BER_BVNULL,
195 { BER_BVC( "This subsystem contains information about time." ),
197 MONITOR_F_PERSISTENT_CH,
198 monitor_subsys_time_init,
204 SLAPD_MONITOR_TLS_NAME,
205 BER_BVNULL, BER_BVNULL, BER_BVNULL,
206 { BER_BVC( "This subsystem contains information about TLS." ),
215 SLAPD_MONITOR_RWW_NAME,
216 BER_BVNULL, BER_BVNULL, BER_BVNULL,
217 { BER_BVC( "This subsystem contains information about read/write waiters." ),
219 MONITOR_F_PERSISTENT_CH,
220 monitor_subsys_rww_init,
229 monitor_back_register_subsys(
230 monitor_subsys_t *ms )
234 if ( monitor_subsys ) {
235 for ( ; monitor_subsys[ i ] != NULL; i++ )
236 /* just count'em */ ;
239 monitor_subsys = ch_realloc( monitor_subsys,
240 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
242 if ( monitor_subsys == NULL ) {
246 monitor_subsys[ i ] = ms;
247 monitor_subsys[ i + 1 ] = NULL;
249 /* if a subsystem is registered __AFTER__ subsystem
250 * initialization (depending on the sequence the databases
251 * are listed in slapd.conf), init it */
252 if ( monitor_subsys_opened ) {
254 /* FIXME: this should only be possible
255 * if be_monitor is already initialized */
256 assert( be_monitor != NULL );
258 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
262 ms->mss_flags |= MONITOR_F_OPENED;
275 typedef struct entry_limbo_t {
279 struct berval el_ndn;
280 struct berval el_nbase;
282 struct berval el_filter;
283 monitor_callback_t *el_cb;
284 monitor_subsys_t *el_mss;
285 unsigned long el_flags;
286 struct entry_limbo_t *el_next;
290 monitor_back_is_configured( void )
292 return be_monitor != NULL;
296 monitor_back_register_entry(
298 monitor_callback_t *cb,
299 monitor_subsys_t *mss,
300 unsigned long flags )
304 if ( be_monitor == NULL ) {
305 Debug( LDAP_DEBUG_ANY,
306 "monitor_back_register_entry(\"%s\"): "
307 "monitor database not configured.\n",
308 e->e_name.bv_val, 0, 0 );
312 mi = ( monitor_info_t * )be_monitor->be_private;
314 assert( mi != NULL );
316 assert( e->e_private == NULL );
318 if ( monitor_subsys_opened ) {
319 Entry *e_parent = NULL,
322 struct berval pdn = BER_BVNULL;
323 monitor_entry_t *mp = NULL,
327 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
329 Debug( LDAP_DEBUG_ANY,
330 "monitor_back_register_entry(\"%s\"): "
332 e->e_name.bv_val, 0, 0 );
333 monitor_cache_release( mi, e_parent );
337 dnParent( &e->e_nname, &pdn );
338 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
339 /* parent does not exist */
340 Debug( LDAP_DEBUG_ANY,
341 "monitor_back_register_entry(\"%s\"): "
342 "parent \"%s\" not found\n",
343 e->e_name.bv_val, pdn.bv_val, 0 );
347 assert( e_parent->e_private != NULL );
348 mp_parent = ( monitor_entry_t * )e_parent->e_private;
350 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
351 /* entry is volatile; cannot append children */
352 Debug( LDAP_DEBUG_ANY,
353 "monitor_back_register_entry(\"%s\"): "
354 "parent \"%s\" is volatile\n",
355 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
360 mp = monitor_entrypriv_create();
362 Debug( LDAP_DEBUG_ANY,
363 "monitor_back_register_entry(\"%s\"): "
364 "monitor_entrypriv_create() failed\n",
365 e->e_name.bv_val, 0, 0 );
370 e_new = entry_dup( e );
371 if ( e_new == NULL ) {
372 Debug( LDAP_DEBUG_ANY,
373 "monitor_back_register_entry(\"%s\"): "
374 "entry_dup() failed\n",
375 e->e_name.bv_val, 0, 0 );
380 e_new->e_private = ( void * )mp;
383 mp->mp_flags = flags;
386 mp->mp_info = mp_parent->mp_info;
387 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
391 ep = &mp_parent->mp_children;
393 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
394 ep = &mp_parent->mp_next;
398 if ( monitor_cache_add( mi, e_new ) ) {
399 Debug( LDAP_DEBUG_ANY,
400 "monitor_back_register_entry(\"%s\"): "
401 "unable to add entry\n",
402 e->e_name.bv_val, 0, 0 );
413 e_new->e_private = NULL;
419 monitor_cache_release( mi, e_parent );
423 entry_limbo_t **elpp, el = { 0 };
425 el.el_type = LIMBO_ENTRY;
427 el.el_e = entry_dup( e );
428 if ( el.el_e == NULL ) {
429 Debug( LDAP_DEBUG_ANY,
430 "monitor_back_register_entry(\"%s\"): "
431 "entry_dup() failed\n",
432 e->e_name.bv_val, 0, 0 );
440 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
442 elpp = &(*elpp)->el_next )
445 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
446 if ( *elpp == NULL ) {
447 el.el_e->e_private = NULL;
448 entry_free( el.el_e );
460 monitor_back_register_entry_parent(
462 monitor_callback_t *cb,
463 monitor_subsys_t *mss,
465 struct berval *nbase,
467 struct berval *filter )
470 struct berval ndn = BER_BVNULL;
472 if ( be_monitor == NULL ) {
473 Debug( LDAP_DEBUG_ANY,
474 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
475 "monitor database not configured.\n",
476 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
477 ldap_pvt_scope2str( scope ),
478 BER_BVISNULL( filter ) ? "" : filter->bv_val );
482 mi = ( monitor_info_t * )be_monitor->be_private;
484 assert( mi != NULL );
486 assert( e->e_private == NULL );
488 if ( BER_BVISNULL( filter ) ) {
490 Debug( LDAP_DEBUG_ANY,
491 "monitor_back_register_entry_parent(\"\"): "
492 "need a valid filter\n",
497 if ( monitor_subsys_opened ) {
498 Entry *e_parent = NULL,
501 struct berval e_name = BER_BVNULL,
502 e_nname = BER_BVNULL;
503 monitor_entry_t *mp = NULL,
507 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
508 /* entry does not exist */
509 Debug( LDAP_DEBUG_ANY,
510 "monitor_back_register_entry_parent(\"\"): "
511 "base=\"%s\" scope=%s filter=\"%s\": "
512 "unable to find entry\n",
513 nbase->bv_val ? nbase->bv_val : "\"\"",
514 ldap_pvt_scope2str( scope ),
519 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
520 /* entry does not exist */
521 Debug( LDAP_DEBUG_ANY,
522 "monitor_back_register_entry_parent(\"%s\"): "
523 "parent entry does not exist\n",
529 assert( e_parent->e_private != NULL );
530 mp_parent = ( monitor_entry_t * )e_parent->e_private;
532 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
533 /* entry is volatile; cannot append callback */
534 Debug( LDAP_DEBUG_ANY,
535 "monitor_back_register_entry_parent(\"%s\"): "
536 "entry is volatile\n",
537 e_parent->e_name.bv_val, 0, 0 );
542 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
543 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
545 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
546 /* entry already exists */
547 Debug( LDAP_DEBUG_ANY,
548 "monitor_back_register_entry_parent(\"%s\"): "
549 "entry already exists\n",
550 e_name.bv_val, 0, 0 );
551 monitor_cache_release( mi, e_new );
557 mp = monitor_entrypriv_create();
559 Debug( LDAP_DEBUG_ANY,
560 "monitor_back_register_entry_parent(\"%s\"): "
561 "monitor_entrypriv_create() failed\n",
562 e->e_name.bv_val, 0, 0 );
567 e_new = entry_dup( e );
568 if ( e_new == NULL ) {
569 Debug( LDAP_DEBUG_ANY,
570 "monitor_back_register_entry(\"%s\"): "
571 "entry_dup() failed\n",
572 e->e_name.bv_val, 0, 0 );
576 ch_free( e_new->e_name.bv_val );
577 ch_free( e_new->e_nname.bv_val );
578 e_new->e_name = e_name;
579 e_new->e_nname = e_nname;
581 e_new->e_private = ( void * )mp;
584 mp->mp_flags = flags;
587 mp->mp_info = mp_parent->mp_info;
588 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
592 ep = &mp_parent->mp_children;
594 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
595 ep = &mp_parent->mp_next;
599 if ( monitor_cache_add( mi, e_new ) ) {
600 Debug( LDAP_DEBUG_ANY,
601 "monitor_back_register_entry(\"%s\"): "
602 "unable to add entry\n",
603 e->e_name.bv_val, 0, 0 );
609 if ( !BER_BVISNULL( &ndn ) ) {
610 ch_free( ndn.bv_val );
618 e_new->e_private = NULL;
624 monitor_cache_release( mi, e_parent );
628 entry_limbo_t **elpp = NULL, el = { 0 };
630 el.el_type = LIMBO_ENTRY_PARENT;
632 el.el_e = entry_dup( e );
633 if ( el.el_e == NULL ) {
634 Debug( LDAP_DEBUG_ANY,
635 "monitor_back_register_entry(\"%s\"): "
636 "entry_dup() failed\n",
637 e->e_name.bv_val, 0, 0 );
641 if ( !BER_BVISNULL( nbase ) ) {
642 ber_dupbv( &el.el_nbase, nbase );
646 if ( !BER_BVISNULL( filter ) ) {
647 ber_dupbv( &el.el_filter, filter );
654 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
656 elpp = &(*elpp)->el_next )
659 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
660 if ( *elpp == NULL ) {
665 if ( *elpp != NULL ) {
670 if ( !BER_BVISNULL( &el.el_filter ) ) {
671 ch_free( el.el_filter.bv_val );
673 if ( !BER_BVISNULL( &el.el_nbase ) ) {
674 ch_free( el.el_nbase.bv_val );
676 entry_free( el.el_e );
685 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
687 if ( rs->sr_type == REP_SEARCH ) {
688 struct berval *ndn = op->o_callback->sc_private;
690 if ( !BER_BVISNULL( ndn ) ) {
691 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
692 ch_free( ndn->bv_val );
697 ber_dupbv( ndn, &rs->sr_entry->e_nname );
705 struct berval *nbase,
707 struct berval *filter,
710 Connection conn = { 0 };
711 OperationBuffer opbuf;
714 SlapReply rs = { 0 };
715 slap_callback cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
720 if ( be_monitor == NULL ) {
724 op = (Operation *) &opbuf;
725 thrctx = ldap_pvt_thread_pool_context();
726 connection_fake_init( &conn, op, thrctx );
728 op->o_tag = LDAP_REQ_SEARCH;
730 /* use global malloc for now */
731 if ( op->o_tmpmemctx ) {
732 op->o_tmpmemctx = NULL;
734 op->o_tmpmfuncs = &ch_mfuncs;
736 op->o_bd = be_monitor;
737 if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
738 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
740 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
744 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
745 op->o_tmpmemctx ) ) {
750 op->o_callback = &cb;
751 cb.sc_private = (void *)ndn;
753 op->ors_scope = scope;
754 op->ors_filter = str2filter_x( op, filter->bv_val );
755 if ( op->ors_filter == NULL ) {
759 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
760 op->ors_attrs = slap_anlist_no_attrs;
761 op->ors_attrsonly = 0;
762 op->ors_tlimit = SLAP_NO_LIMIT;
764 op->ors_limit = NULL;
765 op->ors_deref = LDAP_DEREF_NEVER;
768 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
770 op->o_dn = be_monitor->be_rootdn;
771 op->o_ndn = be_monitor->be_rootndn;
773 rc = op->o_bd->be_search( op, &rs );
776 if ( op->ors_filter != NULL ) {
777 filter_free_x( op, op->ors_filter );
779 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
780 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
782 if ( !BER_BVISNULL( &op->o_req_dn ) ) {
783 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
785 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
786 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
793 switch ( rs.sr_err ) {
795 if ( BER_BVISNULL( ndn ) ) {
800 case LDAP_SIZELIMIT_EXCEEDED:
802 if ( !BER_BVISNULL( ndn ) ) {
803 ber_memfree( ndn->bv_val );
814 monitor_back_register_entry_attrs(
815 struct berval *ndn_in,
817 monitor_callback_t *cb,
818 struct berval *nbase,
820 struct berval *filter )
823 struct berval ndn = BER_BVNULL;
824 char *fname = ( a == NULL ? "callback" : "attrs" );
826 if ( be_monitor == NULL ) {
827 char buf[ SLAP_TEXT_BUFLEN ];
829 snprintf( buf, sizeof( buf ),
830 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
831 "monitor database not configured.\n",
833 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
834 ldap_pvt_scope2str( scope ),
835 BER_BVISNULL( filter ) ? "" : filter->bv_val );
836 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
841 mi = ( monitor_info_t * )be_monitor->be_private;
843 assert( mi != NULL );
845 if ( ndn_in != NULL ) {
849 if ( a == NULL && cb == NULL ) {
854 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
855 && BER_BVISNULL( filter ) )
858 Debug( LDAP_DEBUG_ANY,
859 "monitor_back_register_entry_%s(\"\"): "
860 "need a valid filter\n",
865 if ( monitor_subsys_opened ) {
867 Attribute **atp = NULL;
868 monitor_entry_t *mp = NULL;
869 monitor_callback_t **mcp = NULL;
873 if ( BER_BVISNULL( &ndn ) ) {
874 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
875 char buf[ SLAP_TEXT_BUFLEN ];
877 snprintf( buf, sizeof( buf ),
878 "monitor_back_register_entry_%s(\"\"): "
879 "base=\"%s\" scope=%s filter=\"%s\": "
880 "unable to find entry\n",
882 nbase->bv_val ? nbase->bv_val : "\"\"",
883 ldap_pvt_scope2str( scope ),
886 /* entry does not exist */
887 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
894 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
895 /* entry does not exist */
896 Debug( LDAP_DEBUG_ANY,
897 "monitor_back_register_entry_%s(\"%s\"): "
898 "entry does not exist\n",
899 fname, ndn.bv_val, 0 );
904 assert( e->e_private != NULL );
905 mp = ( monitor_entry_t * )e->e_private;
907 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
908 /* entry is volatile; cannot append callback */
909 Debug( LDAP_DEBUG_ANY,
910 "monitor_back_register_entry_%s(\"%s\"): "
911 "entry is volatile\n",
912 fname, e->e_name.bv_val, 0 );
918 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
919 /* just get to last */ ;
921 for ( ; a != NULL; a = a->a_next ) {
922 assert( a->a_desc != NULL );
923 assert( a->a_vals != NULL );
925 if ( attr_find( e->e_attrs, a->a_desc ) ) {
926 attr_merge( e, a->a_desc, a->a_vals,
927 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
930 *atp = attr_dup( a );
931 if ( *atp == NULL ) {
932 Debug( LDAP_DEBUG_ANY,
933 "monitor_back_register_entry_%s(\"%s\"): "
934 "attr_dup() failed\n",
935 fname, e->e_name.bv_val, 0 );
939 atp = &(*atp)->a_next;
945 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
948 /* NOTE: we do not clear cb->mc_next, so this function
949 * can be used to append a list of callbacks */
962 ber_memfree( ndn.bv_val );
966 monitor_cache_release( mi, e );
970 entry_limbo_t **elpp, el = { 0 };
972 el.el_type = LIMBO_ATTRS;
973 if ( !BER_BVISNULL( &ndn ) ) {
974 ber_dupbv( &el.el_ndn, &ndn );
976 if ( !BER_BVISNULL( nbase ) ) {
977 ber_dupbv( &el.el_nbase, nbase);
980 if ( !BER_BVISNULL( filter ) ) {
981 ber_dupbv( &el.el_filter, filter );
984 el.el_a = attrs_dup( a );
987 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
989 elpp = &(*elpp)->el_next )
992 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
993 if ( *elpp == NULL ) {
994 el.el_e->e_private = NULL;
995 entry_free( el.el_e );
999 if ( *elpp != NULL ) {
1004 if ( !BER_BVISNULL( &el.el_filter ) ) {
1005 ch_free( el.el_filter.bv_val );
1007 if ( el.el_a != NULL ) {
1008 attrs_free( el.el_a );
1010 if ( !BER_BVISNULL( &el.el_nbase ) ) {
1011 ch_free( &el.el_nbase.bv_val );
1013 if ( !BER_BVISNULL( &el.el_ndn ) ) {
1014 ch_free( el.el_ndn.bv_val );
1024 monitor_back_register_entry_callback(
1026 monitor_callback_t *cb,
1027 struct berval *nbase,
1029 struct berval *filter )
1031 return monitor_back_register_entry_attrs( ndn, NULL, cb,
1032 nbase, scope, filter );
1036 * TODO: add corresponding calls to remove installed callbacks, entries
1037 * and so, in case the entity that installed them is removed (e.g. a
1038 * database, via back-config)
1041 monitor_back_unregister_entry(
1042 struct berval *ndn )
1046 if ( be_monitor == NULL ) {
1047 Debug( LDAP_DEBUG_ANY,
1048 "monitor_back_unregister_entry(\"%s\"): "
1049 "monitor database not configured.\n",
1050 ndn->bv_val, 0, 0 );
1055 /* entry will be regularly freed, and resources released
1056 * according to callbacks */
1057 if ( slapd_shutdown ) {
1061 mi = ( monitor_info_t * )be_monitor->be_private;
1063 assert( mi != NULL );
1065 if ( monitor_subsys_opened ) {
1067 monitor_entry_t *mp = NULL;
1068 monitor_callback_t *cb = NULL;
1070 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1071 /* entry does not exist */
1072 Debug( LDAP_DEBUG_ANY,
1073 "monitor_back_unregister_entry(\"%s\"): "
1074 "entry removal failed.\n",
1075 ndn->bv_val, 0, 0 );
1079 mp = (monitor_entry_t *)e->e_private;
1080 assert( mp != NULL );
1082 for ( cb = mp->mp_cb; cb != NULL; ) {
1083 monitor_callback_t *next = cb->mc_next;
1085 if ( cb->mc_free ) {
1086 (void)cb->mc_free( e, &cb->mc_private );
1094 e->e_private = NULL;
1098 entry_limbo_t **elpp;
1100 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1102 elpp = &(*elpp)->el_next )
1104 entry_limbo_t *elp = *elpp;
1106 if ( elp->el_type == LIMBO_ENTRY
1107 && dn_match( ndn, &elp->el_e->e_nname ) )
1109 monitor_callback_t *cb, *next;
1111 for ( cb = elp->el_cb; cb; cb = next ) {
1112 /* FIXME: call callbacks? */
1116 assert( elp->el_e != NULL );
1117 elp->el_e->e_private = NULL;
1118 entry_free( elp->el_e );
1119 *elpp = elp->el_next;
1126 if ( elpp != NULL ) {
1127 /* not found! where did it go? */
1136 monitor_back_unregister_entry_parent(
1137 struct berval *nrdn,
1138 monitor_callback_t *target_cb,
1139 struct berval *nbase,
1141 struct berval *filter )
1144 struct berval ndn = BER_BVNULL;
1146 if ( be_monitor == NULL ) {
1147 Debug( LDAP_DEBUG_ANY,
1148 "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1149 "monitor database not configured.\n",
1150 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1151 ldap_pvt_scope2str( scope ),
1152 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1157 /* entry will be regularly freed, and resources released
1158 * according to callbacks */
1159 if ( slapd_shutdown ) {
1163 mi = ( monitor_info_t * )be_monitor->be_private;
1165 assert( mi != NULL );
1167 if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1168 && BER_BVISNULL( filter ) )
1171 Debug( LDAP_DEBUG_ANY,
1172 "monitor_back_unregister_entry_parent(\"\"): "
1173 "need a valid filter\n",
1178 if ( monitor_subsys_opened ) {
1180 monitor_entry_t *mp = NULL;
1182 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1183 /* entry does not exist */
1184 Debug( LDAP_DEBUG_ANY,
1185 "monitor_back_unregister_entry_parent(\"\"): "
1186 "base=\"%s\" scope=%s filter=\"%s\": "
1187 "unable to find entry\n",
1188 nbase->bv_val ? nbase->bv_val : "\"\"",
1189 ldap_pvt_scope2str( scope ),
1194 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1195 /* entry does not exist */
1196 Debug( LDAP_DEBUG_ANY,
1197 "monitor_back_unregister_entry(\"%s\"): "
1198 "entry removal failed.\n",
1200 ber_memfree( ndn.bv_val );
1203 ber_memfree( ndn.bv_val );
1205 mp = (monitor_entry_t *)e->e_private;
1206 assert( mp != NULL );
1208 if ( target_cb != NULL ) {
1209 monitor_callback_t **cbp;
1211 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1212 if ( *cbp == target_cb ) {
1213 if ( (*cbp)->mc_free ) {
1214 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1216 *cbp = (*cbp)->mc_next;
1217 ch_free( target_cb );
1225 e->e_private = NULL;
1229 entry_limbo_t **elpp;
1231 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1233 elpp = &(*elpp)->el_next )
1235 entry_limbo_t *elp = *elpp;
1237 if ( elp->el_type == LIMBO_ENTRY_PARENT
1238 && dn_match( nrdn, &elp->el_e->e_nname )
1239 && dn_match( nbase, &elp->el_nbase )
1240 && scope == elp->el_scope
1241 && bvmatch( filter, &elp->el_filter ) )
1243 monitor_callback_t *cb, *next;
1245 for ( cb = elp->el_cb; cb; cb = next ) {
1246 /* FIXME: call callbacks? */
1250 assert( elp->el_e != NULL );
1251 elp->el_e->e_private = NULL;
1252 entry_free( elp->el_e );
1253 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1254 ch_free( elp->el_nbase.bv_val );
1256 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1257 ch_free( elp->el_filter.bv_val );
1259 *elpp = elp->el_next;
1266 if ( elpp != NULL ) {
1267 /* not found! where did it go? */
1276 monitor_back_unregister_entry_attrs(
1277 struct berval *ndn_in,
1278 Attribute *target_a,
1279 monitor_callback_t *target_cb,
1280 struct berval *nbase,
1282 struct berval *filter )
1285 struct berval ndn = BER_BVNULL;
1286 char *fname = ( target_a == NULL ? "callback" : "attrs" );
1288 if ( be_monitor == NULL ) {
1289 char buf[ SLAP_TEXT_BUFLEN ];
1291 snprintf( buf, sizeof( buf ),
1292 "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1293 "monitor database not configured.\n",
1295 BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1296 ldap_pvt_scope2str( scope ),
1297 BER_BVISNULL( filter ) ? "" : filter->bv_val );
1298 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1303 /* entry will be regularly freed, and resources released
1304 * according to callbacks */
1305 if ( slapd_shutdown ) {
1309 mi = ( monitor_info_t * )be_monitor->be_private;
1311 assert( mi != NULL );
1313 if ( ndn_in != NULL ) {
1317 if ( target_a == NULL && target_cb == NULL ) {
1322 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1323 && BER_BVISNULL( filter ) )
1326 Debug( LDAP_DEBUG_ANY,
1327 "monitor_back_unregister_entry_%s(\"\"): "
1328 "need a valid filter\n",
1333 if ( monitor_subsys_opened ) {
1335 monitor_entry_t *mp = NULL;
1338 if ( BER_BVISNULL( &ndn ) ) {
1339 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1340 char buf[ SLAP_TEXT_BUFLEN ];
1342 snprintf( buf, sizeof( buf ),
1343 "monitor_back_unregister_entry_%s(\"\"): "
1344 "base=\"%s\" scope=%d filter=\"%s\": "
1345 "unable to find entry\n",
1347 nbase->bv_val ? nbase->bv_val : "\"\"",
1348 scope, filter->bv_val );
1350 /* entry does not exist */
1351 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1358 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1359 /* entry does not exist */
1360 Debug( LDAP_DEBUG_ANY,
1361 "monitor_back_unregister_entry(\"%s\"): "
1362 "entry removal failed.\n",
1367 mp = (monitor_entry_t *)e->e_private;
1368 assert( mp != NULL );
1370 if ( target_cb != NULL ) {
1371 monitor_callback_t **cbp;
1373 for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1374 if ( *cbp == target_cb ) {
1375 if ( (*cbp)->mc_free ) {
1376 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1378 *cbp = (*cbp)->mc_next;
1379 ch_free( target_cb );
1385 if ( target_a != NULL ) {
1388 for ( a = target_a; a != NULL; a = a->a_next ) {
1389 Modification mod = { 0 };
1391 char textbuf[ SLAP_TEXT_BUFLEN ];
1393 mod.sm_op = LDAP_MOD_DELETE;
1394 mod.sm_desc = a->a_desc;
1395 mod.sm_values = a->a_vals;
1396 mod.sm_nvalues = a->a_nvals;
1398 (void)modify_delete_values( e, &mod, 1,
1399 &text, textbuf, sizeof( textbuf ) );
1404 ber_memfree( ndn.bv_val );
1408 monitor_cache_release( mi, e );
1412 entry_limbo_t **elpp;
1414 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
1416 elpp = &(*elpp)->el_next )
1418 entry_limbo_t *elp = *elpp;
1420 if ( elp->el_type == LIMBO_ATTRS
1421 && dn_match( nbase, &elp->el_nbase )
1422 && scope == elp->el_scope
1423 && bvmatch( filter, &elp->el_filter ) )
1425 monitor_callback_t *cb, *next;
1427 for ( cb = elp->el_cb; cb; cb = next ) {
1428 /* FIXME: call callbacks? */
1432 assert( elp->el_e == NULL );
1433 if ( elp->el_a != NULL ) {
1434 attrs_free( elp->el_a );
1436 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1437 ch_free( elp->el_nbase.bv_val );
1439 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1440 ch_free( elp->el_filter.bv_val );
1442 *elpp = elp->el_next;
1449 if ( elpp != NULL ) {
1450 /* not found! where did it go? */
1459 monitor_back_unregister_entry_callback(
1461 monitor_callback_t *cb,
1462 struct berval *nbase,
1464 struct berval *filter )
1466 /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1467 * unregister the callback; if a is not null, unregister the
1468 * given attrs. In any case, call cb->cb_free */
1469 return monitor_back_unregister_entry_attrs( ndn,
1470 NULL, cb, nbase, scope, filter );
1474 monitor_back_get_subsys( const char *name )
1476 if ( monitor_subsys != NULL ) {
1479 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1480 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1481 return monitor_subsys[ i ];
1490 monitor_back_get_subsys_by_dn(
1494 if ( monitor_subsys != NULL ) {
1498 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1499 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1500 return monitor_subsys[ i ];
1505 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1506 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1507 return monitor_subsys[ i ];
1517 monitor_back_initialize(
1520 static char *controls[] = {
1521 LDAP_CONTROL_MANAGEDSAIT,
1525 static ConfigTable monitorcfg[] = {
1526 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1527 NULL, NULL, NULL, NULL }
1530 static ConfigOCs monitorocs[] = {
1531 { "( OLcfgDbOc:4.1 "
1532 "NAME 'olcMonitorConfig' "
1533 "DESC 'Monitor backend configuration' "
1534 "SUP olcDatabaseConfig "
1536 Cft_Database, monitorcfg },
1545 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1547 "DESC 'OpenLDAP system monitoring' "
1548 "SUP top STRUCTURAL "
1557 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1558 offsetof(monitor_info_t, mi_oc_monitor) },
1559 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1560 "NAME 'monitorServer' "
1561 "DESC 'Server monitoring root entry' "
1562 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1563 offsetof(monitor_info_t, mi_oc_monitorServer) },
1564 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1565 "NAME 'monitorContainer' "
1566 "DESC 'monitor container class' "
1567 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1568 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1569 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1570 "NAME 'monitorCounterObject' "
1571 "DESC 'monitor counter class' "
1572 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1573 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1574 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1575 "NAME 'monitorOperation' "
1576 "DESC 'monitor operation class' "
1577 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1578 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1579 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1580 "NAME 'monitorConnection' "
1581 "DESC 'monitor connection class' "
1582 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1583 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1584 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1585 "NAME 'managedObject' "
1586 "DESC 'monitor managed entity class' "
1587 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1588 offsetof(monitor_info_t, mi_oc_managedObject) },
1589 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1590 "NAME 'monitoredObject' "
1591 "DESC 'monitor monitored entity class' "
1592 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1593 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1596 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1597 "NAME 'monitoredInfo' "
1598 "DESC 'monitored info' "
1600 "EQUALITY caseIgnoreMatch "
1601 "SUBSTR caseIgnoreSubstringsMatch "
1602 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1603 "NO-USER-MODIFICATION "
1604 "USAGE dSAOperation )", SLAP_AT_HIDE,
1605 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1606 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1607 "NAME 'managedInfo' "
1608 "DESC 'monitor managed info' "
1609 "SUP name )", SLAP_AT_HIDE,
1610 offsetof(monitor_info_t, mi_ad_managedInfo) },
1611 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1612 "NAME 'monitorCounter' "
1613 "DESC 'monitor counter' "
1614 "EQUALITY integerMatch "
1615 "ORDERING integerOrderingMatch "
1616 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1617 "NO-USER-MODIFICATION "
1618 "USAGE dSAOperation )", SLAP_AT_HIDE,
1619 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1620 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1621 "NAME 'monitorOpCompleted' "
1622 "DESC 'monitor completed operations' "
1623 "SUP monitorCounter "
1624 "NO-USER-MODIFICATION "
1625 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1626 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1627 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1628 "NAME 'monitorOpInitiated' "
1629 "DESC 'monitor initiated operations' "
1630 "SUP monitorCounter "
1631 "NO-USER-MODIFICATION "
1632 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1633 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1634 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1635 "NAME 'monitorConnectionNumber' "
1636 "DESC 'monitor connection number' "
1637 "SUP monitorCounter "
1638 "NO-USER-MODIFICATION "
1639 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1640 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1641 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1642 "NAME 'monitorConnectionAuthzDN' "
1643 "DESC 'monitor connection authorization DN' "
1644 /* "SUP distinguishedName " */
1645 "EQUALITY distinguishedNameMatch "
1646 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1647 "NO-USER-MODIFICATION "
1648 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1649 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1650 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1651 "NAME 'monitorConnectionLocalAddress' "
1652 "DESC 'monitor connection local address' "
1653 "SUP monitoredInfo "
1654 "NO-USER-MODIFICATION "
1655 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1656 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1657 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1658 "NAME 'monitorConnectionPeerAddress' "
1659 "DESC 'monitor connection peer address' "
1660 "SUP monitoredInfo "
1661 "NO-USER-MODIFICATION "
1662 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1663 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1664 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1665 "NAME 'monitorTimestamp' "
1666 "DESC 'monitor timestamp' "
1667 "EQUALITY generalizedTimeMatch "
1668 "ORDERING generalizedTimeOrderingMatch "
1669 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1671 "NO-USER-MODIFICATION "
1672 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1673 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1674 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1675 "NAME 'monitorOverlay' "
1676 "DESC 'name of overlays defined for a given database' "
1677 "SUP monitoredInfo "
1678 "NO-USER-MODIFICATION "
1679 "USAGE dSAOperation )", SLAP_AT_HIDE,
1680 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1681 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1683 "DESC 'read/write status of a given database' "
1684 "EQUALITY booleanMatch "
1685 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1687 "USAGE dSAOperation )", SLAP_AT_HIDE,
1688 offsetof(monitor_info_t, mi_ad_readOnly) },
1689 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1690 "NAME 'restrictedOperation' "
1691 "DESC 'name of restricted operation for a given database' "
1692 "SUP managedInfo )", SLAP_AT_HIDE,
1693 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1694 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1695 "NAME 'monitorConnectionProtocol' "
1696 "DESC 'monitor connection protocol' "
1697 "SUP monitoredInfo "
1698 "NO-USER-MODIFICATION "
1699 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1700 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1701 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1702 "NAME 'monitorConnectionOpsReceived' "
1703 "DESC 'monitor number of operations received by the connection' "
1704 "SUP monitorCounter "
1705 "NO-USER-MODIFICATION "
1706 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1707 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1708 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1709 "NAME 'monitorConnectionOpsExecuting' "
1710 "DESC 'monitor number of operations in execution within the connection' "
1711 "SUP monitorCounter "
1712 "NO-USER-MODIFICATION "
1713 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1714 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1715 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1716 "NAME 'monitorConnectionOpsPending' "
1717 "DESC 'monitor number of pending operations within the connection' "
1718 "SUP monitorCounter "
1719 "NO-USER-MODIFICATION "
1720 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1721 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1722 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1723 "NAME 'monitorConnectionOpsCompleted' "
1724 "DESC 'monitor number of operations completed within the connection' "
1725 "SUP monitorCounter "
1726 "NO-USER-MODIFICATION "
1727 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1728 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1729 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1730 "NAME 'monitorConnectionGet' "
1731 "DESC 'number of times connection_get() was called so far' "
1732 "SUP monitorCounter "
1733 "NO-USER-MODIFICATION "
1734 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1735 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1736 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1737 "NAME 'monitorConnectionRead' "
1738 "DESC 'number of times connection_read() was called so far' "
1739 "SUP monitorCounter "
1740 "NO-USER-MODIFICATION "
1741 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1742 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1743 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1744 "NAME 'monitorConnectionWrite' "
1745 "DESC 'number of times connection_write() was called so far' "
1746 "SUP monitorCounter "
1747 "NO-USER-MODIFICATION "
1748 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1749 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1750 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1751 "NAME 'monitorConnectionMask' "
1752 "DESC 'monitor connection mask' "
1753 "SUP monitoredInfo "
1754 "NO-USER-MODIFICATION "
1755 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1756 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1757 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1758 "NAME 'monitorConnectionListener' "
1759 "DESC 'monitor connection listener' "
1760 "SUP monitoredInfo "
1761 "NO-USER-MODIFICATION "
1762 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1763 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1764 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1765 "NAME 'monitorConnectionPeerDomain' "
1766 "DESC 'monitor connection peer domain' "
1767 "SUP monitoredInfo "
1768 "NO-USER-MODIFICATION "
1769 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1770 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1771 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1772 "NAME 'monitorConnectionStartTime' "
1773 "DESC 'monitor connection start time' "
1774 "SUP monitorTimestamp "
1776 "NO-USER-MODIFICATION "
1777 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1778 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1779 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1780 "NAME 'monitorConnectionActivityTime' "
1781 "DESC 'monitor connection activity time' "
1782 "SUP monitorTimestamp "
1784 "NO-USER-MODIFICATION "
1785 "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1786 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1787 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1788 "NAME 'monitorIsShadow' "
1789 "DESC 'TRUE if the database is shadow' "
1790 "EQUALITY booleanMatch "
1791 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1793 "USAGE dSAOperation )", SLAP_AT_HIDE,
1794 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1795 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1796 "NAME 'monitorUpdateRef' "
1797 "DESC 'update referral for shadow databases' "
1798 "SUP monitoredInfo "
1800 "USAGE dSAOperation )", SLAP_AT_HIDE,
1801 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1802 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1803 "NAME 'monitorRuntimeConfig' "
1804 "DESC 'TRUE if component allows runtime configuration' "
1805 "EQUALITY booleanMatch "
1806 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1808 "USAGE dSAOperation )", SLAP_AT_HIDE,
1809 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1817 { "olmAttributes", "1.3.6.1.4.1.4203.666.1.55" },
1818 { "olmSubSystemAttributes", "olmAttributes:0" },
1819 { "olmGenericAttributes", "olmSubSystemAttributes:0" },
1820 { "olmDatabaseAttributes", "olmSubSystemAttributes:1" },
1822 /* for example, back-bdb specific attrs
1823 * are in "olmDatabaseAttributes:1"
1825 * NOTE: developers, please record here OID assignments
1826 * for other modules */
1828 { "olmObjectClasses", "1.3.6.1.4.1.4203.666.3.16" },
1829 { "olmSubSystemObjectClasses", "olmObjectClasses:0" },
1830 { "olmGenericObjectClasses", "olmSubSystemObjectClasses:0" },
1831 { "olmDatabaseObjectClasses", "olmSubSystemObjectClasses:1" },
1833 /* for example, back-bdb specific objectClasses
1834 * are in "olmDatabaseObjectClasses:1"
1836 * NOTE: developers, please record here OID assignments
1837 * for other modules */
1843 monitor_info_t *mi = &monitor_info;
1847 argv[ 0 ] = "monitor";
1852 for ( i = 0; s_oid[ i ].name; i++ ) {
1853 argv[ 1 ] = s_oid[ i ].name;
1854 argv[ 2 ] = s_oid[ i ].oid;
1856 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1857 Debug( LDAP_DEBUG_ANY,
1858 "monitor_back_initialize: unable to add "
1859 "objectIdentifier \"%s=%s\"\n",
1860 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1865 /* schema integration */
1866 for ( i = 0; mat[ i ].schema; i++ ) {
1868 AttributeDescription **ad =
1869 ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1872 code = register_at( mat[ i ].schema, ad, 0 );
1875 Debug( LDAP_DEBUG_ANY,
1876 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1879 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1882 for ( i = 0; moc[ i ].schema; i++ ) {
1885 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1887 code = register_oc( moc[ i ].schema, Oc, 0 );
1889 Debug( LDAP_DEBUG_ANY,
1890 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1893 (*Oc)->soc_flags |= moc[ i ].flags;
1896 bi->bi_controls = controls;
1900 bi->bi_config = monitor_back_config;
1904 bi->bi_db_init = monitor_back_db_init;
1906 bi->bi_db_config = monitor_back_db_config;
1908 bi->bi_db_open = monitor_back_db_open;
1909 bi->bi_db_close = 0;
1910 bi->bi_db_destroy = monitor_back_db_destroy;
1912 bi->bi_op_bind = monitor_back_bind;
1913 bi->bi_op_unbind = 0;
1914 bi->bi_op_search = monitor_back_search;
1915 bi->bi_op_compare = monitor_back_compare;
1916 bi->bi_op_modify = monitor_back_modify;
1917 bi->bi_op_modrdn = 0;
1919 bi->bi_op_delete = 0;
1920 bi->bi_op_abandon = 0;
1922 bi->bi_extended = 0;
1924 bi->bi_entry_release_rw = 0;
1925 bi->bi_chk_referrals = 0;
1926 bi->bi_operational = monitor_back_operational;
1929 * hooks for slap tools
1931 bi->bi_tool_entry_open = 0;
1932 bi->bi_tool_entry_close = 0;
1933 bi->bi_tool_entry_first = 0;
1934 bi->bi_tool_entry_next = 0;
1935 bi->bi_tool_entry_get = 0;
1936 bi->bi_tool_entry_put = 0;
1937 bi->bi_tool_entry_reindex = 0;
1938 bi->bi_tool_sync = 0;
1939 bi->bi_tool_dn2id_get = 0;
1940 bi->bi_tool_id2entry_get = 0;
1941 bi->bi_tool_entry_modify = 0;
1943 bi->bi_connection_init = 0;
1944 bi->bi_connection_destroy = 0;
1946 bi->bi_extra = (void *)&monitor_extra;
1949 * configuration objectClasses (fake)
1951 bi->bi_cf_ocs = monitorocs;
1953 rc = config_register_schema( monitorcfg, monitorocs );
1962 monitor_back_db_init(
1966 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1971 monitor_subsys_t *ms;
1976 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1977 if ( monitor_back_register_subsys( ms ) ) {
1983 * database monitor can be defined once only
1985 if ( be_monitor != NULL ) {
1986 Debug( LDAP_DEBUG_ANY,
1987 "only one monitor database is allowed\n", 0, 0, 0 );
1992 /* indicate system schema supported */
1993 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1995 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1996 if( rc != LDAP_SUCCESS ) {
1997 Debug( LDAP_DEBUG_ANY,
1998 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2003 ber_bvarray_add( &be->be_suffix, &pdn );
2004 ber_bvarray_add( &be->be_nsuffix, &ndn );
2006 /* NOTE: only one monitor database is allowed,
2007 * so we use static storage */
2008 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2010 be->be_private = &monitor_info;
2012 be2 = select_backend( &ndn, 0, 0 );
2014 char *type = be2->bd_info->bi_type;
2016 if ( overlay_is_over( be2 ) ) {
2017 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
2018 type = oi->oi_orig->bi_type;
2021 Debug( LDAP_DEBUG_ANY,
2022 "\"monitor\" database serving namingContext \"%s\" "
2023 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2024 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2032 monitor_back_db_open(
2035 monitor_info_t *mi = (monitor_info_t *)be->be_private;
2036 struct monitor_subsys_t **ms;
2037 Entry *e, **ep, *root;
2038 monitor_entry_t *mp;
2040 struct berval bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2042 #ifdef HAVE_GMTIME_R
2045 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2046 struct berval desc[] = {
2047 BER_BVC("This subtree contains monitoring/managing objects."),
2048 BER_BVC("This object contains information about this server."),
2049 BER_BVC("Most of the information is held in operational"
2050 " attributes, which must be explicitly requested."),
2053 assert( be_monitor != NULL );
2054 if ( be != be_monitor ) {
2061 #ifndef HAVE_GMTIME_R
2062 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2064 #ifdef HACK_LOCAL_TIME
2065 # ifdef HAVE_LOCALTIME_R
2066 tms = localtime_r( &starttime, &tm_buf );
2068 tms = localtime( &starttime );
2069 # endif /* HAVE_LOCALTIME_R */
2070 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2071 #else /* !HACK_LOCAL_TIME */
2072 # ifdef HAVE_GMTIME_R
2073 tms = gmtime_r( &starttime, &tm_buf );
2075 tms = gmtime( &starttime );
2076 # endif /* HAVE_GMTIME_R */
2077 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2078 #endif /* !HACK_LOCAL_TIME */
2079 #ifndef HAVE_GMTIME_R
2080 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2083 mi->mi_startTime.bv_val = tmbuf;
2084 mi->mi_startTime.bv_len = strlen( tmbuf );
2086 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2087 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2088 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2090 mi->mi_creatorsName = be->be_rootdn;
2091 mi->mi_ncreatorsName = be->be_rootndn;
2095 * creates the "cn=Monitor" entry
2097 e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2101 Debug( LDAP_DEBUG_ANY,
2102 "unable to create \"%s\" entry\n",
2103 SLAPD_MONITOR_DN, 0, 0 );
2107 attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2109 bv.bv_val = strchr( (char *) Versionstr, '$' );
2110 if ( bv.bv_val != NULL ) {
2114 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2117 end = strchr( bv.bv_val, '$' );
2118 if ( end != NULL ) {
2121 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2126 bv.bv_len = end - bv.bv_val;
2129 bv.bv_len = strlen( bv.bv_val );
2132 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2134 Debug( LDAP_DEBUG_ANY,
2135 "unable to add monitoredInfo to \"%s\" entry\n",
2136 SLAPD_MONITOR_DN, 0, 0 );
2141 mp = monitor_entrypriv_create();
2145 e->e_private = ( void * )mp;
2146 ep = &mp->mp_children;
2148 if ( monitor_cache_add( mi, e ) ) {
2149 Debug( LDAP_DEBUG_ANY,
2150 "unable to add entry \"%s\" to cache\n",
2151 SLAPD_MONITOR_DN, 0, 0 );
2157 * Create all the subsystem specific entries
2159 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2160 int len = strlen( monitor_subsys[ i ]->mss_name );
2164 dn.bv_len = len + sizeof( "cn=" ) - 1;
2165 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2166 strcpy( dn.bv_val, "cn=" );
2167 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2168 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2170 if ( rc != LDAP_SUCCESS ) {
2171 Debug( LDAP_DEBUG_ANY,
2172 "monitor RDN \"%s\" is invalid\n",
2177 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2178 &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2182 Debug( LDAP_DEBUG_ANY,
2183 "unable to create \"%s\" entry\n",
2184 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2187 monitor_subsys[i]->mss_dn = e->e_name;
2188 monitor_subsys[i]->mss_ndn = e->e_nname;
2190 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2191 attr_merge_normalize( e, slap_schema.si_ad_description,
2192 monitor_subsys[ i ]->mss_desc, NULL );
2195 mp = monitor_entrypriv_create();
2199 e->e_private = ( void * )mp;
2200 mp->mp_info = monitor_subsys[ i ];
2201 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2203 if ( monitor_cache_add( mi, e ) ) {
2204 Debug( LDAP_DEBUG_ANY,
2205 "unable to add entry \"%s\" to cache\n",
2206 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2214 assert( be != NULL );
2216 be->be_private = mi;
2219 * opens the monitor backend subsystems
2221 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2222 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2226 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2229 monitor_subsys_opened = 1;
2231 if ( mi->mi_entry_limbo ) {
2232 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
2238 switch ( el->el_type ) {
2240 rc = monitor_back_register_entry(
2247 case LIMBO_ENTRY_PARENT:
2248 rc = monitor_back_register_entry_parent(
2260 rc = monitor_back_register_entry_attrs(
2270 rc = monitor_back_register_entry_callback(
2283 entry_free( el->el_e );
2286 attrs_free( el->el_a );
2288 if ( !BER_BVISNULL( &el->el_ndn ) ) {
2289 ber_memfree( el->el_ndn.bv_val );
2291 if ( !BER_BVISNULL( &el->el_nbase ) ) {
2292 ber_memfree( el->el_nbase.bv_val );
2294 if ( !BER_BVISNULL( &el->el_filter ) ) {
2295 ber_memfree( el->el_filter.bv_val );
2297 if ( el->el_cb && rc != 0 ) {
2298 if ( el->el_cb->mc_dispose ) {
2299 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2301 ch_free( el->el_cb );
2309 mi->mi_entry_limbo = NULL;
2316 monitor_back_config(
2324 * eventually, will hold backend specific configuration parameters
2326 return SLAP_CONF_UNKNOWN;
2331 monitor_back_db_config(
2338 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2341 * eventually, will hold database specific configuration parameters
2343 return SLAP_CONF_UNKNOWN;
2348 monitor_back_db_destroy(
2351 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
2358 * FIXME: destroys all the data
2360 /* NOTE: mi points to static storage; don't free it */
2362 (void)monitor_cache_destroy( mi );
2364 if ( monitor_subsys ) {
2367 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2368 if ( monitor_subsys[ i ]->mss_destroy ) {
2369 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2372 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2373 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2377 ch_free( monitor_subsys );
2380 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2382 be->be_private = NULL;
2387 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2389 /* conditionally define the init_module() function */
2390 SLAP_BACKEND_INIT_MODULE( monitor )
2392 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */