1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 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>
30 #include "back-monitor.h"
32 #undef INTEGRATE_CORE_SCHEMA
35 * used by many functions to add description to entries
37 * WARNING: be_monitor may change as new databases are added,
38 * so it should not be used outside monitor_back_db_init()
39 * until monitor_back_db_open is called.
41 BackendDB *be_monitor = NULL;
43 static struct monitor_subsys_t **monitor_subsys = NULL;
44 static int monitor_subsys_opened = 0;
49 * the known subsystems are added to the subsystems
50 * array at backend initialization; other subsystems
51 * may be added by calling monitor_back_register_subsys()
52 * before the database is opened (e.g. by other backends
53 * or by overlays or modules).
55 static struct monitor_subsys_t known_monitor_subsys[] = {
57 SLAPD_MONITOR_BACKEND_NAME,
58 BER_BVNULL, BER_BVNULL, BER_BVNULL,
59 MONITOR_F_PERSISTENT_CH,
60 monitor_subsys_backend_init,
65 SLAPD_MONITOR_CONN_NAME,
66 BER_BVNULL, BER_BVNULL, BER_BVNULL,
67 MONITOR_F_VOLATILE_CH,
68 monitor_subsys_conn_init,
69 monitor_subsys_conn_update,
70 monitor_subsys_conn_create,
73 SLAPD_MONITOR_DATABASE_NAME,
74 BER_BVNULL, BER_BVNULL, BER_BVNULL,
75 MONITOR_F_PERSISTENT_CH,
76 monitor_subsys_database_init,
79 monitor_subsys_database_modify
81 SLAPD_MONITOR_LISTENER_NAME,
82 BER_BVNULL, BER_BVNULL, BER_BVNULL,
83 MONITOR_F_PERSISTENT_CH,
84 monitor_subsys_listener_init,
89 SLAPD_MONITOR_LOG_NAME,
90 BER_BVNULL, BER_BVNULL, BER_BVNULL,
92 monitor_subsys_log_init,
95 monitor_subsys_log_modify
97 SLAPD_MONITOR_OPS_NAME,
98 BER_BVNULL, BER_BVNULL, BER_BVNULL,
99 MONITOR_F_PERSISTENT_CH,
100 monitor_subsys_ops_init,
101 monitor_subsys_ops_update,
105 SLAPD_MONITOR_OVERLAY_NAME,
106 BER_BVNULL, BER_BVNULL, BER_BVNULL,
107 MONITOR_F_PERSISTENT_CH,
108 monitor_subsys_overlay_init,
113 SLAPD_MONITOR_SASL_NAME,
114 BER_BVNULL, BER_BVNULL, BER_BVNULL,
121 SLAPD_MONITOR_SENT_NAME,
122 BER_BVNULL, BER_BVNULL, BER_BVNULL,
123 MONITOR_F_PERSISTENT_CH,
124 monitor_subsys_sent_init,
125 monitor_subsys_sent_update,
129 SLAPD_MONITOR_THREAD_NAME,
130 BER_BVNULL, BER_BVNULL, BER_BVNULL,
131 MONITOR_F_PERSISTENT_CH,
132 monitor_subsys_thread_init,
133 monitor_subsys_thread_update,
137 SLAPD_MONITOR_TIME_NAME,
138 BER_BVNULL, BER_BVNULL, BER_BVNULL,
139 MONITOR_F_PERSISTENT_CH,
140 monitor_subsys_time_init,
141 monitor_subsys_time_update,
145 SLAPD_MONITOR_TLS_NAME,
146 BER_BVNULL, BER_BVNULL, BER_BVNULL,
153 SLAPD_MONITOR_RWW_NAME,
154 BER_BVNULL, BER_BVNULL, BER_BVNULL,
155 MONITOR_F_PERSISTENT_CH,
156 monitor_subsys_rww_init,
157 monitor_subsys_rww_update,
164 monitor_back_register_subsys( monitor_subsys_t *ms )
168 if ( monitor_subsys ) {
169 for ( ; monitor_subsys[ i ] != NULL; i++ )
170 /* just count'em */ ;
173 monitor_subsys = ch_realloc( monitor_subsys,
174 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
176 if ( monitor_subsys == NULL ) {
180 monitor_subsys[ i ] = ms;
181 monitor_subsys[ i + 1 ] = NULL;
183 /* if a subsystem is registered __AFTER__ subsystem
184 * initialization (depending on the sequence the databases
185 * are listed in slapd.conf), init it */
186 if ( monitor_subsys_opened ) {
188 /* FIXME: this should only be possible
189 * if be_monitor is already initialized */
190 assert( be_monitor );
192 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
196 ms->mss_flags |= MONITOR_F_OPENED;
208 typedef struct entry_limbo_t {
212 struct berval el_ndn;
213 struct berval el_base;
215 struct berval el_filter;
216 monitor_callback_t *el_cb;
217 struct entry_limbo_t *el_next;
221 monitor_back_register_entry(
223 monitor_callback_t *cb )
225 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
227 assert( mi != NULL );
229 assert( e->e_private == NULL );
231 if ( monitor_subsys_opened ) {
232 Entry *e_parent = NULL,
235 struct berval pdn = BER_BVNULL;
236 monitor_entry_t *mp = NULL,
240 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
242 Debug( LDAP_DEBUG_ANY,
243 "monitor_back_register_entry(\"%s\"): "
245 e->e_name.bv_val, 0, 0 );
246 monitor_cache_release( mi, e_parent );
250 dnParent( &e->e_nname, &pdn );
251 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
252 /* parent does not exist */
253 Debug( LDAP_DEBUG_ANY,
254 "monitor_back_register_entry(\"%s\"): "
255 "parent \"%s\" not found\n",
256 e->e_name.bv_val, pdn.bv_val, 0 );
260 assert( e_parent->e_private != NULL );
261 mp_parent = ( monitor_entry_t * )e_parent->e_private;
263 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
264 /* entry is volatile; cannot append children */
265 Debug( LDAP_DEBUG_ANY,
266 "monitor_back_register_entry(\"%s\"): "
267 "parent \"%s\" is volatile\n",
268 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
273 mp = monitor_entrypriv_create();
275 Debug( LDAP_DEBUG_ANY,
276 "monitor_back_register_entry(\"%s\"): "
277 "monitor_entrypriv_create() failed\n",
278 e->e_name.bv_val, 0, 0 );
283 e_new = entry_dup( e );
285 Debug( LDAP_DEBUG_ANY,
286 "monitor_back_register_entry(\"%s\"): "
287 "entry_dup() failed\n",
288 e->e_name.bv_val, 0, 0 );
293 e_new->e_private = ( void * )mp;
294 mp->mp_info = mp_parent->mp_info;
295 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
297 ep = &mp_parent->mp_children;
299 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
300 ep = &mp_parent->mp_next;
304 if ( monitor_cache_add( mi, e_new ) ) {
305 Debug( LDAP_DEBUG_ANY,
306 "monitor_back_register_entry(\"%s\"): "
307 "unable to add entry\n",
308 e->e_name.bv_val, 0, 0 );
319 e_new->e_private = NULL;
325 monitor_cache_release( mi, e_parent );
329 entry_limbo_t *elp, el = { 0 };
331 el.el_type = LIMBO_ENTRY;
333 el.el_e = entry_dup( e );
334 if ( el.el_e == NULL ) {
335 Debug( LDAP_DEBUG_ANY,
336 "monitor_back_register_entry(\"%s\"): "
337 "entry_dup() failed\n",
338 e->e_name.bv_val, 0, 0 );
344 elp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
346 el.el_e->e_private = NULL;
347 entry_free( el.el_e );
351 el.el_next = (entry_limbo_t *)mi->mi_entry_limbo;
353 mi->mi_entry_limbo = (void *)elp;
360 monitor_filter2ndn_cb( Operation *op, SlapReply *rs )
362 if ( rs->sr_type == REP_SEARCH ) {
363 struct berval *ndn = op->o_callback->sc_private;
365 ber_dupbv( ndn, &rs->sr_entry->e_nname );
372 monitor_filter2ndn( struct berval *base, int scope, struct berval *filter,
375 Connection conn = { 0 };
376 Operation op = { 0 };
377 SlapReply rs = { 0 };
378 slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
379 AttributeName anlist[ 2 ];
384 if ( be_monitor == NULL ) {
388 connection_fake_init( &conn, &op, &conn );
390 op.o_tag = LDAP_REQ_SEARCH;
392 /* use global malloc for now */
393 op.o_tmpmemctx = NULL;
394 op.o_tmpmfuncs = &ch_mfuncs;
396 op.o_bd = be_monitor;
397 if ( base == NULL || BER_BVISNULL( base ) ) {
398 ber_dupbv_x( &op.o_req_dn, &op.o_bd->be_suffix[ 0 ],
400 ber_dupbv_x( &op.o_req_ndn, &op.o_bd->be_nsuffix[ 0 ],
404 if ( dnPrettyNormal( NULL, base, &op.o_req_dn, &op.o_req_ndn,
411 cb.sc_private = (void *)ndn;
413 op.ors_scope = scope;
414 ber_dupbv_x( &op.ors_filterstr, filter, op.o_tmpmemctx );
415 op.ors_filter = str2filter_x( &op, filter->bv_val );
416 op.ors_attrs = anlist;
417 BER_BVSTR( &anlist[ 0 ].an_name, LDAP_NO_ATTRS );
418 BER_BVZERO( &anlist[ 1 ].an_name );
419 op.ors_attrsonly = 0;
420 op.ors_tlimit = SLAP_NO_LIMIT;
423 op.ors_deref = LDAP_DEREF_NEVER;
426 op.o_managedsait = 1;
428 rc = op.o_bd->be_search( &op, &rs );
430 filter_free_x( &op, op.ors_filter );
431 op.o_tmpfree( op.ors_filterstr.bv_val, op.o_tmpmemctx );
432 op.o_tmpfree( op.o_req_dn.bv_val, op.o_tmpmemctx );
433 op.o_tmpfree( op.o_req_ndn.bv_val, op.o_tmpmemctx );
439 switch ( rs.sr_err ) {
441 if ( BER_BVISNULL( ndn ) ) {
446 case LDAP_SIZELIMIT_EXCEEDED:
448 if ( !BER_BVISNULL( ndn ) ) {
449 ber_memfree( ndn->bv_val );
460 monitor_back_register_entry_attrs(
461 struct berval *ndn_in,
463 monitor_callback_t *cb,
466 struct berval *filter )
468 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
469 struct berval ndn = BER_BVNULL;
471 assert( mi != NULL );
473 if ( ndn_in != NULL ) {
477 if ( a == NULL && cb == NULL ) {
482 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
483 && BER_BVISNULL( filter ) )
486 Debug( LDAP_DEBUG_ANY,
487 "monitor_back_register_entry_*(\"\"): "
488 "need a valid filter\n",
493 if ( monitor_subsys_opened ) {
495 Attribute **atp = NULL;
496 monitor_entry_t *mp = NULL;
497 monitor_callback_t **mcp = NULL;
501 if ( BER_BVISNULL( &ndn ) ) {
502 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
503 /* entry does not exist */
504 Debug( LDAP_DEBUG_ANY,
505 "monitor_back_register_entry_*(\"\"): "
506 "base=%s scope=%d filter=%s : "
507 "unable to find entry\n",
508 base->bv_val ? base->bv_val : "\"\"",
509 scope, filter->bv_val );
516 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
517 /* entry does not exist */
518 Debug( LDAP_DEBUG_ANY,
519 "monitor_back_register_entry_*(\"%s\"): "
520 "entry does not exist\n",
526 assert( e->e_private != NULL );
527 mp = ( monitor_entry_t * )e->e_private;
529 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
530 /* entry is volatile; cannot append callback */
531 Debug( LDAP_DEBUG_ANY,
532 "monitor_back_register_entry_*(\"%s\"): "
533 "entry is volatile\n",
534 e->e_name.bv_val, 0, 0 );
540 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
541 /* just get to last */ ;
543 *atp = attrs_dup( a );
544 if ( *atp == NULL ) {
545 Debug( LDAP_DEBUG_ANY,
546 "monitor_back_register_entry_*(\"%s\"): "
547 "attrs_dup() failed\n",
548 e->e_name.bv_val, 0, 0 );
555 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
558 /* NOTE: we do not clear cb->mc_next, so this function
559 * can be used to append a list of callbacks */
572 ber_memfree( ndn.bv_val );
576 monitor_cache_release( mi, e );
580 entry_limbo_t *elp, el = { 0 };
582 el.el_type = LIMBO_ATTRS;
583 if ( !BER_BVISNULL( &ndn ) ) {
584 ber_dupbv( &el.el_ndn, &ndn );
586 if ( !BER_BVISNULL( base ) ) {
587 ber_dupbv( &el.el_base, base);
590 if ( !BER_BVISNULL( filter ) ) {
591 ber_dupbv( &el.el_filter, filter );
594 el.el_a = attrs_dup( a );
597 elp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
603 el.el_next = (entry_limbo_t *)mi->mi_entry_limbo;
605 mi->mi_entry_limbo = (void *)elp;;
612 monitor_back_register_entry_callback(
614 monitor_callback_t *cb,
617 struct berval *filter )
619 return monitor_back_register_entry_attrs( ndn, NULL, cb,
620 base, scope, filter );
624 monitor_back_get_subsys( const char *name )
626 if ( monitor_subsys != NULL ) {
629 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
630 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
631 return monitor_subsys[ i ];
640 monitor_back_get_subsys_by_dn( struct berval *ndn, int sub )
642 if ( monitor_subsys != NULL ) {
646 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
647 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
648 return monitor_subsys[ i ];
653 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
654 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
655 return monitor_subsys[ i ];
665 monitor_back_initialize(
669 monitor_subsys_t *ms;
670 static char *controls[] = {
671 LDAP_CONTROL_MANAGEDSAIT,
672 LDAP_CONTROL_VALUESRETURNFILTER,
676 bi->bi_controls = controls;
680 bi->bi_config = monitor_back_config;
684 bi->bi_db_init = monitor_back_db_init;
685 bi->bi_db_config = monitor_back_db_config;
686 bi->bi_db_open = monitor_back_db_open;
688 bi->bi_db_destroy = monitor_back_db_destroy;
690 bi->bi_op_bind = monitor_back_bind;
691 bi->bi_op_unbind = 0;
692 bi->bi_op_search = monitor_back_search;
693 bi->bi_op_compare = monitor_back_compare;
694 bi->bi_op_modify = monitor_back_modify;
695 bi->bi_op_modrdn = 0;
697 bi->bi_op_delete = 0;
698 bi->bi_op_abandon = 0;
702 bi->bi_entry_release_rw = 0;
703 bi->bi_chk_referrals = 0;
704 bi->bi_operational = monitor_back_operational;
707 * hooks for slap tools
709 bi->bi_tool_entry_open = 0;
710 bi->bi_tool_entry_close = 0;
711 bi->bi_tool_entry_first = 0;
712 bi->bi_tool_entry_next = 0;
713 bi->bi_tool_entry_get = 0;
714 bi->bi_tool_entry_put = 0;
715 bi->bi_tool_entry_reindex = 0;
716 bi->bi_tool_sync = 0;
717 bi->bi_tool_dn2id_get = 0;
718 bi->bi_tool_id2entry_get = 0;
719 bi->bi_tool_entry_modify = 0;
721 bi->bi_connection_init = 0;
722 bi->bi_connection_destroy = 0;
724 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
725 if ( monitor_back_register_subsys( ms ) ) {
734 monitor_back_db_init(
740 struct berval dn, ndn;
750 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
752 "DESC 'OpenLDAP system monitoring' "
753 "SUP top STRUCTURAL "
758 #if 0 /* temporarily disabled */
769 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
770 offsetof(monitor_info_t, mi_oc_monitor) },
771 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
772 "NAME 'monitorServer' "
773 "DESC 'Server monitoring root entry' "
774 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
775 offsetof(monitor_info_t, mi_oc_monitorServer) },
776 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
777 "NAME 'monitorContainer' "
778 "DESC 'monitor container class' "
779 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
780 offsetof(monitor_info_t, mi_oc_monitorContainer) },
781 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
782 "NAME 'monitorCounterObject' "
783 "DESC 'monitor counter class' "
784 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
785 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
786 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
787 "NAME 'monitorOperation' "
788 "DESC 'monitor operation class' "
789 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
790 offsetof(monitor_info_t, mi_oc_monitorOperation) },
791 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
792 "NAME 'monitorConnection' "
793 "DESC 'monitor connection class' "
794 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
795 offsetof(monitor_info_t, mi_oc_monitorConnection) },
796 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
797 "NAME 'managedObject' "
798 "DESC 'monitor managed entity class' "
799 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
800 offsetof(monitor_info_t, mi_oc_managedObject) },
801 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.13 "
802 "NAME 'monitoredObject' "
803 "DESC 'monitor monitored entity class' "
804 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
805 offsetof(monitor_info_t, mi_oc_monitoredObject) },
806 { NULL, NULL, 0, -1 }
808 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
809 "NAME 'monitoredInfo' "
810 "DESC 'monitored info' "
812 "EQUALITY caseIgnoreMatch "
813 "SUBSTR caseIgnoreSubstringsMatch "
814 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
815 "NO-USER-MODIFICATION "
816 "USAGE directoryOperation )", SLAP_AT_HIDE,
817 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
818 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
819 "NAME 'managedInfo' "
820 "DESC 'monitor managed info' "
821 "SUP name )", SLAP_AT_HIDE,
822 offsetof(monitor_info_t, mi_ad_managedInfo) },
823 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
824 "NAME 'monitorCounter' "
825 "DESC 'monitor counter' "
826 "EQUALITY integerMatch "
827 "ORDERING integerOrderingMatch "
828 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
829 "NO-USER-MODIFICATION "
830 "USAGE directoryOperation )", SLAP_AT_HIDE,
831 offsetof(monitor_info_t, mi_ad_monitorCounter) },
832 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
833 "NAME 'monitorOpCompleted' "
834 "DESC 'monitor completed operations' "
835 "SUP monitorCounter "
836 "NO-USER-MODIFICATION "
837 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
838 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
839 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
840 "NAME 'monitorOpInitiated' "
841 "DESC 'monitor initiated operations' "
842 "SUP monitorCounter "
843 "NO-USER-MODIFICATION "
844 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
845 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
846 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
847 "NAME 'monitorConnectionNumber' "
848 "DESC 'monitor connection number' "
849 "SUP monitorCounter "
850 "NO-USER-MODIFICATION "
851 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
852 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
853 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
854 "NAME 'monitorConnectionAuthzDN' "
855 "DESC 'monitor connection authorization DN' "
856 /* "SUP distinguishedName " */
857 "EQUALITY distinguishedNameMatch "
858 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
859 "NO-USER-MODIFICATION "
860 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
861 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
862 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
863 "NAME 'monitorConnectionLocalAddress' "
864 "DESC 'monitor connection local address' "
866 "NO-USER-MODIFICATION "
867 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
868 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
869 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
870 "NAME 'monitorConnectionPeerAddress' "
871 "DESC 'monitor connection peer address' "
873 "NO-USER-MODIFICATION "
874 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
875 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
876 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.24 "
877 "NAME 'monitorTimestamp' "
878 "DESC 'monitor timestamp' "
879 "EQUALITY generalizedTimeMatch "
880 "ORDERING generalizedTimeOrderingMatch "
881 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
883 "NO-USER-MODIFICATION "
884 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
885 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
886 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.27 "
887 "NAME 'monitorOverlay' "
888 "DESC 'name of overlays defined for a give database' "
890 "NO-USER-MODIFICATION "
891 "USAGE directoryOperation )", SLAP_AT_HIDE,
892 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
893 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.31 "
895 "DESC 'read/write status of a given database' "
896 "EQUALITY booleanMatch "
897 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
899 "USAGE directoryOperation )", SLAP_AT_HIDE,
900 offsetof(monitor_info_t, mi_ad_readOnly) },
901 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.32 "
902 "NAME 'restrictedOperation' "
903 "DESC 'name of restricted operation for a given database' "
904 "SUP managedInfo )", SLAP_AT_HIDE,
905 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
906 #ifdef INTEGRATE_CORE_SCHEMA
907 { NULL, NULL, 0, -1 }, /* description */
908 { NULL, NULL, 0, -1 }, /* seeAlso */
909 { NULL, NULL, 0, -1 }, /* l */
910 { NULL, NULL, 0, -1 }, /* labeledURI */
911 #endif /* INTEGRATE_CORE_SCHEMA */
912 { NULL, NULL, 0, -1 }
914 { "description", "( 2.5.4.13 "
915 "NAME 'description' "
916 "DESC 'RFC2256: descriptive information' "
917 "EQUALITY caseIgnoreMatch "
918 "SUBSTR caseIgnoreSubstringsMatch "
919 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )", 0,
920 offsetof(monitor_info_t, mi_ad_description) },
921 { "seeAlso", "( 2.5.4.34 "
923 "DESC 'RFC2256: DN of related object' "
924 "SUP distinguishedName )", 0,
925 offsetof(monitor_info_t, mi_ad_seeAlso) },
927 "NAME ( 'l' 'localityName' ) "
928 "DESC 'RFC2256: locality which this object resides in' "
930 offsetof(monitor_info_t, mi_ad_l) },
931 #ifdef MONITOR_DEFINE_LABELEDURI
932 { "labeledURI", "( 1.3.6.1.4.1.250.1.57 "
934 "DESC 'RFC2079: Uniform Resource Identifier with optional label' "
935 "EQUALITY caseExactMatch "
936 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )", 0,
937 offsetof(monitor_info_t, mi_ad_labeledURI) },
938 #endif /* MONITOR_DEFINE_LABELEDURI */
939 { NULL, NULL, 0, -1 }
943 * database monitor can be defined once only
946 Debug( LDAP_DEBUG_ANY,
947 "only one monitor backend is allowed\n", 0, 0, 0 );
952 /* indicate system schema supported */
953 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
955 dn.bv_val = SLAPD_MONITOR_DN;
956 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
958 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
959 if( rc != LDAP_SUCCESS ) {
960 Debug( LDAP_DEBUG_ANY,
961 "unable to normalize monitor DN \"%s\"\n",
962 SLAPD_MONITOR_DN, 0, 0 );
966 ber_dupbv( &bv, &dn );
967 ber_bvarray_add( &be->be_suffix, &bv );
968 ber_bvarray_add( &be->be_nsuffix, &ndn );
970 mi = ( monitor_info_t * )ch_calloc( sizeof( monitor_info_t ), 1 );
972 Debug( LDAP_DEBUG_ANY,
973 "unable to initialize monitor backend\n", 0, 0, 0 );
977 memset( mi, 0, sizeof( monitor_info_t ) );
979 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
983 #ifdef INTEGRATE_CORE_SCHEMA
984 /* prepare for schema integration */
985 for ( k = 0; mat[ k ].name != NULL; k++ );
986 #endif /* INTEGRATE_CORE_SCHEMA */
988 for ( i = 0; mat_core[ i ].name != NULL; i++ ) {
989 AttributeDescription **ad;
992 ad = ((AttributeDescription **)&(((char *)mi)[ mat_core[ i ].offset ]));
995 switch (slap_str2ad( mat_core[ i ].name, ad, &text ) ) {
999 #ifdef INTEGRATE_CORE_SCHEMA
1000 case LDAP_UNDEFINED_TYPE:
1001 mat[ k ] = mat_core[ i ];
1004 #endif /* INTEGRATE_CORE_SCHEMA */
1007 Debug( LDAP_DEBUG_ANY,
1008 "monitor_back_db_init: %s: %s\n",
1009 mat_core[ i ].name, text, 0 );
1014 /* schema integration */
1015 for ( i = 0; mat[ i ].name; i++ ) {
1016 LDAPAttributeType *at;
1019 AttributeDescription **ad;
1021 at = ldap_str2attributetype( mat[ i ].schema, &code,
1022 &err, LDAP_SCHEMA_ALLOW_ALL );
1024 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1025 "in AttributeType \"%s\" %s before %s\n",
1026 mat[ i ].name, ldap_scherr2str(code), err );
1030 if ( at->at_oid == NULL ) {
1031 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1032 "null OID for attributeType \"%s\"\n",
1033 mat[ i ].name, 0, 0 );
1037 code = at_add(at, &err);
1039 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1040 "%s in attributeType \"%s\"\n",
1041 scherr2str(code), mat[ i ].name, 0 );
1046 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1048 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1049 Debug( LDAP_DEBUG_ANY,
1050 "monitor_back_db_init: %s\n", text, 0, 0 );
1054 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1057 for ( i = 0; moc[ i ].name; i++ ) {
1058 LDAPObjectClass *oc;
1063 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1064 LDAP_SCHEMA_ALLOW_ALL );
1066 Debug( LDAP_DEBUG_ANY,
1067 "unable to parse monitor objectclass \"%s\": "
1068 "%s before %s\n" , moc[ i ].name,
1069 ldap_scherr2str(code), err );
1073 if ( oc->oc_oid == NULL ) {
1074 Debug( LDAP_DEBUG_ANY,
1075 "objectclass \"%s\" has no OID\n" ,
1076 moc[ i ].name, 0, 0 );
1080 code = oc_add(oc, 0, &err);
1082 Debug( LDAP_DEBUG_ANY,
1083 "objectclass \"%s\": %s \"%s\"\n" ,
1084 moc[ i ].name, scherr2str(code), err );
1090 Oc = oc_find( moc[ i ].name );
1092 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1093 "unable to find objectClass %s "
1094 "(just added)\n", moc[ i ].name, 0, 0 );
1098 Oc->soc_flags |= moc[ i ].flags;
1100 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1107 monitor_back_db_open(
1111 monitor_info_t *mi = (monitor_info_t *)be->be_private;
1112 struct monitor_subsys_t **ms;
1114 monitor_entry_t *mp;
1116 char buf[ BACKMONITOR_BUFSIZE ],
1120 #ifdef HAVE_GMTIME_R
1123 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
1125 assert( be_monitor );
1126 if ( be != be_monitor ) {
1133 #ifndef HAVE_GMTIME_R
1134 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
1136 #ifdef HACK_LOCAL_TIME
1137 # ifdef HAVE_LOCALTIME_R
1138 tms = localtime_r( &starttime, &tm_buf );
1140 tms = localtime( &starttime );
1141 # endif /* HAVE_LOCALTIME_R */
1142 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
1143 #else /* !HACK_LOCAL_TIME */
1144 # ifdef HAVE_GMTIME_R
1145 tms = gmtime_r( &starttime, &tm_buf );
1147 tms = gmtime( &starttime );
1148 # endif /* HAVE_GMTIME_R */
1149 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
1150 #endif /* !HACK_LOCAL_TIME */
1151 #ifndef HAVE_GMTIME_R
1152 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
1155 mi->mi_startTime.bv_val = tmbuf;
1156 mi->mi_startTime.bv_len = strlen( tmbuf );
1158 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
1159 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
1161 mi->mi_creatorsName = be->be_rootdn;
1165 * creates the "cn=Monitor" entry
1167 snprintf( buf, sizeof( buf ),
1170 "structuralObjectClass: %s\n"
1172 "%s: This subtree contains monitoring/managing objects.\n"
1173 "%s: This object contains information about this server.\n"
1175 "%s: createTimestamp reflects the time this server instance was created.\n"
1176 "%s: modifyTimestamp reflects the time this server instance was last accessed.\n"
1178 "creatorsName: %s\n"
1179 "modifiersName: %s\n"
1180 "createTimestamp: %s\n"
1181 "modifyTimestamp: %s\n",
1183 mi->mi_oc_monitorServer->soc_cname.bv_val,
1184 mi->mi_oc_monitorServer->soc_cname.bv_val,
1185 mi->mi_ad_description->ad_cname.bv_val,
1186 mi->mi_ad_description->ad_cname.bv_val,
1188 mi->mi_ad_description->ad_cname.bv_val,
1189 mi->mi_ad_description->ad_cname.bv_val,
1191 mi->mi_creatorsName.bv_val,
1192 mi->mi_creatorsName.bv_val,
1193 mi->mi_startTime.bv_val,
1194 mi->mi_startTime.bv_val );
1196 e = str2entry( buf );
1198 Debug( LDAP_DEBUG_ANY,
1199 "unable to create \"%s\" entry\n",
1200 SLAPD_MONITOR_DN, 0, 0 );
1204 bv.bv_val = (char *) Versionstr;
1205 end_of_line = strchr( Versionstr, '\n' );
1206 if ( end_of_line ) {
1207 bv.bv_len = end_of_line - Versionstr;
1209 bv.bv_len = strlen( Versionstr );
1212 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
1214 Debug( LDAP_DEBUG_ANY,
1215 "unable to add monitoredInfo to \"%s\" entry\n",
1216 SLAPD_MONITOR_DN, 0, 0 );
1220 if ( mi->mi_l.bv_len ) {
1221 if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) {
1222 Debug( LDAP_DEBUG_ANY,
1223 "unable to add locality to \"%s\" entry\n",
1224 SLAPD_MONITOR_DN, 0, 0 );
1229 mp = monitor_entrypriv_create();
1233 e->e_private = ( void * )mp;
1234 ep = &mp->mp_children;
1236 if ( monitor_cache_add( mi, e ) ) {
1237 Debug( LDAP_DEBUG_ANY,
1238 "unable to add entry \"%s\" to cache\n",
1239 SLAPD_MONITOR_DN, 0, 0 );
1244 * Create all the subsystem specific entries
1246 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1247 int len = strlen( monitor_subsys[ i ]->mss_name );
1251 dn.bv_len = len + sizeof( "cn=" ) - 1;
1252 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1253 strcpy( dn.bv_val, "cn=" );
1254 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1255 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1257 if ( rc != LDAP_SUCCESS ) {
1258 Debug( LDAP_DEBUG_ANY,
1259 "monitor RDN \"%s\" is invalid\n",
1264 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
1265 dn.bv_val = ch_malloc( dn.bv_len + 1 );
1266 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
1267 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
1268 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
1269 &monitor_subsys[ i ]->mss_ndn, NULL );
1271 if ( rc != LDAP_SUCCESS ) {
1272 Debug( LDAP_DEBUG_ANY,
1273 "monitor DN \"%s\" is invalid\n",
1278 snprintf( buf, sizeof( buf ),
1281 "structuralObjectClass: %s\n"
1283 "creatorsName: %s\n"
1284 "modifiersName: %s\n"
1285 "createTimestamp: %s\n"
1286 "modifyTimestamp: %s\n",
1287 monitor_subsys[ i ]->mss_dn.bv_val,
1288 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1289 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1290 monitor_subsys[ i ]->mss_name,
1291 mi->mi_creatorsName.bv_val,
1292 mi->mi_creatorsName.bv_val,
1293 mi->mi_startTime.bv_val,
1294 mi->mi_startTime.bv_val );
1296 e = str2entry( buf );
1299 Debug( LDAP_DEBUG_ANY,
1300 "unable to create \"%s\" entry\n",
1301 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1305 mp = monitor_entrypriv_create();
1309 e->e_private = ( void * )mp;
1310 mp->mp_info = monitor_subsys[ i ];
1311 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1313 if ( monitor_cache_add( mi, e ) ) {
1314 Debug( LDAP_DEBUG_ANY,
1315 "unable to add entry \"%s\" to cache\n",
1316 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1326 be->be_private = mi;
1329 * opens the monitor backend subsystems
1331 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1332 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1336 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1339 monitor_subsys_opened = 1;
1341 if ( mi->mi_entry_limbo ) {
1342 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
1347 switch ( el->el_type ) {
1349 monitor_back_register_entry(
1355 monitor_back_register_entry_attrs(
1365 monitor_back_register_entry_callback(
1378 entry_free( el->el_e );
1381 attrs_free( el->el_a );
1383 if ( !BER_BVISNULL( &el->el_ndn ) ) {
1384 ber_memfree( el->el_ndn.bv_val );
1386 if ( !BER_BVISNULL( &el->el_base ) ) {
1387 ber_memfree( el->el_base.bv_val );
1389 if ( !BER_BVISNULL( &el->el_filter ) ) {
1390 ber_memfree( el->el_filter.bv_val );
1398 mi->mi_entry_limbo = NULL;
1405 monitor_back_config(
1414 * eventually, will hold backend specific configuration parameters
1416 return SLAP_CONF_UNKNOWN;
1420 monitor_back_db_config(
1428 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1431 * eventually, will hold database specific configuration parameters
1433 if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
1438 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_l );
1441 return SLAP_CONF_UNKNOWN;
1448 monitor_back_db_destroy(
1453 * FIXME: destroys all the data
1458 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
1461 init_module( int argc, char *argv[] )
1465 memset( &bi, '\0', sizeof( bi ) );
1466 bi.bi_type = "monitor";
1467 bi.bi_init = monitor_back_initialize;
1474 #endif /* SLAPD_MONITOR */