1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 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 char opbuf[OPERATION_BUFFER_SIZE];
378 SlapReply rs = { 0 };
379 slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
380 AttributeName anlist[ 2 ];
385 if ( be_monitor == NULL ) {
389 op = (Operation *)opbuf;
390 connection_fake_init( &conn, op, &conn );
392 op->o_tag = LDAP_REQ_SEARCH;
394 /* use global malloc for now */
395 op->o_tmpmemctx = NULL;
396 op->o_tmpmfuncs = &ch_mfuncs;
398 op->o_bd = be_monitor;
399 if ( base == NULL || BER_BVISNULL( base ) ) {
400 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
402 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
406 if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn,
407 op->o_tmpmemctx ) ) {
412 op->o_callback = &cb;
413 cb.sc_private = (void *)ndn;
415 op->ors_scope = scope;
416 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
417 op->ors_filter = str2filter_x( op, filter->bv_val );
418 op->ors_attrs = anlist;
419 BER_BVSTR( &anlist[ 0 ].an_name, LDAP_NO_ATTRS );
420 BER_BVZERO( &anlist[ 1 ].an_name );
421 op->ors_attrsonly = 0;
422 op->ors_tlimit = SLAP_NO_LIMIT;
424 op->ors_limit = NULL;
425 op->ors_deref = LDAP_DEREF_NEVER;
428 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
430 rc = op->o_bd->be_search( op, &rs );
432 filter_free_x( op, op->ors_filter );
433 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
434 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
435 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
441 switch ( rs.sr_err ) {
443 if ( BER_BVISNULL( ndn ) ) {
448 case LDAP_SIZELIMIT_EXCEEDED:
450 if ( !BER_BVISNULL( ndn ) ) {
451 ber_memfree( ndn->bv_val );
462 monitor_back_register_entry_attrs(
463 struct berval *ndn_in,
465 monitor_callback_t *cb,
468 struct berval *filter )
470 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
471 struct berval ndn = BER_BVNULL;
473 assert( mi != NULL );
475 if ( ndn_in != NULL ) {
479 if ( a == NULL && cb == NULL ) {
484 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
485 && BER_BVISNULL( filter ) )
488 Debug( LDAP_DEBUG_ANY,
489 "monitor_back_register_entry_*(\"\"): "
490 "need a valid filter\n",
495 if ( monitor_subsys_opened ) {
497 Attribute **atp = NULL;
498 monitor_entry_t *mp = NULL;
499 monitor_callback_t **mcp = NULL;
503 if ( BER_BVISNULL( &ndn ) ) {
504 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
505 /* entry does not exist */
506 Debug( LDAP_DEBUG_ANY,
507 "monitor_back_register_entry_*(\"\"): "
508 "base=%s scope=%d filter=%s : "
509 "unable to find entry\n",
510 base->bv_val ? base->bv_val : "\"\"",
511 scope, filter->bv_val );
518 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
519 /* entry does not exist */
520 Debug( LDAP_DEBUG_ANY,
521 "monitor_back_register_entry_*(\"%s\"): "
522 "entry does not exist\n",
528 assert( e->e_private != NULL );
529 mp = ( monitor_entry_t * )e->e_private;
531 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
532 /* entry is volatile; cannot append callback */
533 Debug( LDAP_DEBUG_ANY,
534 "monitor_back_register_entry_*(\"%s\"): "
535 "entry is volatile\n",
536 e->e_name.bv_val, 0, 0 );
542 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
543 /* just get to last */ ;
545 *atp = attrs_dup( a );
546 if ( *atp == NULL ) {
547 Debug( LDAP_DEBUG_ANY,
548 "monitor_back_register_entry_*(\"%s\"): "
549 "attrs_dup() failed\n",
550 e->e_name.bv_val, 0, 0 );
557 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
560 /* NOTE: we do not clear cb->mc_next, so this function
561 * can be used to append a list of callbacks */
574 ber_memfree( ndn.bv_val );
578 monitor_cache_release( mi, e );
582 entry_limbo_t *elp, el = { 0 };
584 el.el_type = LIMBO_ATTRS;
585 if ( !BER_BVISNULL( &ndn ) ) {
586 ber_dupbv( &el.el_ndn, &ndn );
588 if ( !BER_BVISNULL( base ) ) {
589 ber_dupbv( &el.el_base, base);
592 if ( !BER_BVISNULL( filter ) ) {
593 ber_dupbv( &el.el_filter, filter );
596 el.el_a = attrs_dup( a );
599 elp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
605 el.el_next = (entry_limbo_t *)mi->mi_entry_limbo;
607 mi->mi_entry_limbo = (void *)elp;;
614 monitor_back_register_entry_callback(
616 monitor_callback_t *cb,
619 struct berval *filter )
621 return monitor_back_register_entry_attrs( ndn, NULL, cb,
622 base, scope, filter );
626 monitor_back_get_subsys( const char *name )
628 if ( monitor_subsys != NULL ) {
631 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
632 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
633 return monitor_subsys[ i ];
642 monitor_back_get_subsys_by_dn( struct berval *ndn, int sub )
644 if ( monitor_subsys != NULL ) {
648 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
649 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
650 return monitor_subsys[ i ];
655 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
656 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
657 return monitor_subsys[ i ];
667 monitor_back_initialize(
671 monitor_subsys_t *ms;
672 static char *controls[] = {
673 LDAP_CONTROL_MANAGEDSAIT,
674 LDAP_CONTROL_VALUESRETURNFILTER,
678 bi->bi_controls = controls;
682 bi->bi_config = monitor_back_config;
686 bi->bi_db_init = monitor_back_db_init;
687 bi->bi_db_config = monitor_back_db_config;
688 bi->bi_db_open = monitor_back_db_open;
690 bi->bi_db_destroy = monitor_back_db_destroy;
692 bi->bi_op_bind = monitor_back_bind;
693 bi->bi_op_unbind = 0;
694 bi->bi_op_search = monitor_back_search;
695 bi->bi_op_compare = monitor_back_compare;
696 bi->bi_op_modify = monitor_back_modify;
697 bi->bi_op_modrdn = 0;
699 bi->bi_op_delete = 0;
700 bi->bi_op_abandon = 0;
704 bi->bi_entry_release_rw = 0;
705 bi->bi_chk_referrals = 0;
706 bi->bi_operational = monitor_back_operational;
709 * hooks for slap tools
711 bi->bi_tool_entry_open = 0;
712 bi->bi_tool_entry_close = 0;
713 bi->bi_tool_entry_first = 0;
714 bi->bi_tool_entry_next = 0;
715 bi->bi_tool_entry_get = 0;
716 bi->bi_tool_entry_put = 0;
717 bi->bi_tool_entry_reindex = 0;
718 bi->bi_tool_sync = 0;
719 bi->bi_tool_dn2id_get = 0;
720 bi->bi_tool_id2entry_get = 0;
721 bi->bi_tool_entry_modify = 0;
723 bi->bi_connection_init = 0;
724 bi->bi_connection_destroy = 0;
726 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
727 if ( monitor_back_register_subsys( ms ) ) {
736 monitor_back_db_init(
742 struct berval dn, ndn;
752 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
754 "DESC 'OpenLDAP system monitoring' "
755 "SUP top STRUCTURAL "
760 #if 0 /* temporarily disabled */
771 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
772 offsetof(monitor_info_t, mi_oc_monitor) },
773 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
774 "NAME 'monitorServer' "
775 "DESC 'Server monitoring root entry' "
776 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
777 offsetof(monitor_info_t, mi_oc_monitorServer) },
778 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
779 "NAME 'monitorContainer' "
780 "DESC 'monitor container class' "
781 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
782 offsetof(monitor_info_t, mi_oc_monitorContainer) },
783 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
784 "NAME 'monitorCounterObject' "
785 "DESC 'monitor counter class' "
786 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
787 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
788 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
789 "NAME 'monitorOperation' "
790 "DESC 'monitor operation class' "
791 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
792 offsetof(monitor_info_t, mi_oc_monitorOperation) },
793 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
794 "NAME 'monitorConnection' "
795 "DESC 'monitor connection class' "
796 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
797 offsetof(monitor_info_t, mi_oc_monitorConnection) },
798 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
799 "NAME 'managedObject' "
800 "DESC 'monitor managed entity class' "
801 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
802 offsetof(monitor_info_t, mi_oc_managedObject) },
803 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.14 "
804 "NAME 'monitoredObject' "
805 "DESC 'monitor monitored entity class' "
806 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
807 offsetof(monitor_info_t, mi_oc_monitoredObject) },
808 { NULL, NULL, 0, -1 }
810 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
811 "NAME 'monitoredInfo' "
812 "DESC 'monitored info' "
814 "EQUALITY caseIgnoreMatch "
815 "SUBSTR caseIgnoreSubstringsMatch "
816 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
817 "NO-USER-MODIFICATION "
818 "USAGE directoryOperation )", SLAP_AT_HIDE,
819 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
820 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
821 "NAME 'managedInfo' "
822 "DESC 'monitor managed info' "
823 "SUP name )", SLAP_AT_HIDE,
824 offsetof(monitor_info_t, mi_ad_managedInfo) },
825 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
826 "NAME 'monitorCounter' "
827 "DESC 'monitor counter' "
828 "EQUALITY integerMatch "
829 "ORDERING integerOrderingMatch "
830 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
831 "NO-USER-MODIFICATION "
832 "USAGE directoryOperation )", SLAP_AT_HIDE,
833 offsetof(monitor_info_t, mi_ad_monitorCounter) },
834 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
835 "NAME 'monitorOpCompleted' "
836 "DESC 'monitor completed operations' "
837 "SUP monitorCounter "
838 "NO-USER-MODIFICATION "
839 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
840 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
841 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
842 "NAME 'monitorOpInitiated' "
843 "DESC 'monitor initiated operations' "
844 "SUP monitorCounter "
845 "NO-USER-MODIFICATION "
846 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
847 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
848 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
849 "NAME 'monitorConnectionNumber' "
850 "DESC 'monitor connection number' "
851 "SUP monitorCounter "
852 "NO-USER-MODIFICATION "
853 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
854 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
855 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
856 "NAME 'monitorConnectionAuthzDN' "
857 "DESC 'monitor connection authorization DN' "
858 /* "SUP distinguishedName " */
859 "EQUALITY distinguishedNameMatch "
860 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
861 "NO-USER-MODIFICATION "
862 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
863 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
864 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
865 "NAME 'monitorConnectionLocalAddress' "
866 "DESC 'monitor connection local address' "
868 "NO-USER-MODIFICATION "
869 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
870 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
871 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
872 "NAME 'monitorConnectionPeerAddress' "
873 "DESC 'monitor connection peer address' "
875 "NO-USER-MODIFICATION "
876 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
877 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
878 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.24 "
879 "NAME 'monitorTimestamp' "
880 "DESC 'monitor timestamp' "
881 "EQUALITY generalizedTimeMatch "
882 "ORDERING generalizedTimeOrderingMatch "
883 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
885 "NO-USER-MODIFICATION "
886 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
887 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
888 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.27 "
889 "NAME 'monitorOverlay' "
890 "DESC 'name of overlays defined for a give database' "
892 "NO-USER-MODIFICATION "
893 "USAGE directoryOperation )", SLAP_AT_HIDE,
894 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
895 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.31 "
897 "DESC 'read/write status of a given database' "
898 "EQUALITY booleanMatch "
899 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
901 "USAGE directoryOperation )", SLAP_AT_HIDE,
902 offsetof(monitor_info_t, mi_ad_readOnly) },
903 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.32 "
904 "NAME 'restrictedOperation' "
905 "DESC 'name of restricted operation for a given database' "
906 "SUP managedInfo )", SLAP_AT_HIDE,
907 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
908 #ifdef INTEGRATE_CORE_SCHEMA
909 { NULL, NULL, 0, -1 }, /* description */
910 { NULL, NULL, 0, -1 }, /* seeAlso */
911 { NULL, NULL, 0, -1 }, /* l */
912 { NULL, NULL, 0, -1 }, /* labeledURI */
913 #endif /* INTEGRATE_CORE_SCHEMA */
914 { NULL, NULL, 0, -1 }
916 { "description", "( 2.5.4.13 "
917 "NAME 'description' "
918 "DESC 'RFC2256: descriptive information' "
919 "EQUALITY caseIgnoreMatch "
920 "SUBSTR caseIgnoreSubstringsMatch "
921 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )", 0,
922 offsetof(monitor_info_t, mi_ad_description) },
923 { "seeAlso", "( 2.5.4.34 "
925 "DESC 'RFC2256: DN of related object' "
926 "SUP distinguishedName )", 0,
927 offsetof(monitor_info_t, mi_ad_seeAlso) },
929 "NAME ( 'l' 'localityName' ) "
930 "DESC 'RFC2256: locality which this object resides in' "
932 offsetof(monitor_info_t, mi_ad_l) },
933 #ifdef MONITOR_DEFINE_LABELEDURI
934 { "labeledURI", "( 1.3.6.1.4.1.250.1.57 "
936 "DESC 'RFC2079: Uniform Resource Identifier with optional label' "
937 "EQUALITY caseExactMatch "
938 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )", 0,
939 offsetof(monitor_info_t, mi_ad_labeledURI) },
940 #endif /* MONITOR_DEFINE_LABELEDURI */
941 { NULL, NULL, 0, -1 }
945 * database monitor can be defined once only
948 Debug( LDAP_DEBUG_ANY,
949 "only one monitor backend is allowed\n", 0, 0, 0 );
954 /* indicate system schema supported */
955 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
957 dn.bv_val = SLAPD_MONITOR_DN;
958 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
960 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
961 if( rc != LDAP_SUCCESS ) {
962 Debug( LDAP_DEBUG_ANY,
963 "unable to normalize monitor DN \"%s\"\n",
964 SLAPD_MONITOR_DN, 0, 0 );
968 ber_dupbv( &bv, &dn );
969 ber_bvarray_add( &be->be_suffix, &bv );
970 ber_bvarray_add( &be->be_nsuffix, &ndn );
972 mi = ( monitor_info_t * )ch_calloc( sizeof( monitor_info_t ), 1 );
974 Debug( LDAP_DEBUG_ANY,
975 "unable to initialize monitor backend\n", 0, 0, 0 );
979 memset( mi, 0, sizeof( monitor_info_t ) );
981 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
985 #ifdef INTEGRATE_CORE_SCHEMA
986 /* prepare for schema integration */
987 for ( k = 0; mat[ k ].name != NULL; k++ );
988 #endif /* INTEGRATE_CORE_SCHEMA */
990 for ( i = 0; mat_core[ i ].name != NULL; i++ ) {
991 AttributeDescription **ad;
994 ad = ((AttributeDescription **)&(((char *)mi)[ mat_core[ i ].offset ]));
997 switch (slap_str2ad( mat_core[ i ].name, ad, &text ) ) {
1001 #ifdef INTEGRATE_CORE_SCHEMA
1002 case LDAP_UNDEFINED_TYPE:
1003 mat[ k ] = mat_core[ i ];
1006 #endif /* INTEGRATE_CORE_SCHEMA */
1009 Debug( LDAP_DEBUG_ANY,
1010 "monitor_back_db_init: %s: %s\n",
1011 mat_core[ i ].name, text, 0 );
1016 /* schema integration */
1017 for ( i = 0; mat[ i ].name; i++ ) {
1018 LDAPAttributeType *at;
1021 AttributeDescription **ad;
1023 at = ldap_str2attributetype( mat[ i ].schema, &code,
1024 &err, LDAP_SCHEMA_ALLOW_ALL );
1026 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1027 "in AttributeType \"%s\" %s before %s\n",
1028 mat[ i ].name, ldap_scherr2str(code), err );
1032 if ( at->at_oid == NULL ) {
1033 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1034 "null OID for attributeType \"%s\"\n",
1035 mat[ i ].name, 0, 0 );
1039 code = at_add(at, &err);
1041 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1042 "%s in attributeType \"%s\"\n",
1043 scherr2str(code), mat[ i ].name, 0 );
1048 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1050 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1051 Debug( LDAP_DEBUG_ANY,
1052 "monitor_back_db_init: %s\n", text, 0, 0 );
1056 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1059 for ( i = 0; moc[ i ].name; i++ ) {
1060 LDAPObjectClass *oc;
1065 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1066 LDAP_SCHEMA_ALLOW_ALL );
1068 Debug( LDAP_DEBUG_ANY,
1069 "unable to parse monitor objectclass \"%s\": "
1070 "%s before %s\n" , moc[ i ].name,
1071 ldap_scherr2str(code), err );
1075 if ( oc->oc_oid == NULL ) {
1076 Debug( LDAP_DEBUG_ANY,
1077 "objectclass \"%s\" has no OID\n" ,
1078 moc[ i ].name, 0, 0 );
1082 code = oc_add(oc, 0, &err);
1084 Debug( LDAP_DEBUG_ANY,
1085 "objectclass \"%s\": %s \"%s\"\n" ,
1086 moc[ i ].name, scherr2str(code), err );
1092 Oc = oc_find( moc[ i ].name );
1094 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1095 "unable to find objectClass %s "
1096 "(just added)\n", moc[ i ].name, 0, 0 );
1100 Oc->soc_flags |= moc[ i ].flags;
1102 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1109 monitor_back_db_open(
1113 monitor_info_t *mi = (monitor_info_t *)be->be_private;
1114 struct monitor_subsys_t **ms;
1116 monitor_entry_t *mp;
1118 char buf[ BACKMONITOR_BUFSIZE ],
1122 #ifdef HAVE_GMTIME_R
1125 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
1127 assert( be_monitor );
1128 if ( be != be_monitor ) {
1135 #ifndef HAVE_GMTIME_R
1136 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
1138 #ifdef HACK_LOCAL_TIME
1139 # ifdef HAVE_LOCALTIME_R
1140 tms = localtime_r( &starttime, &tm_buf );
1142 tms = localtime( &starttime );
1143 # endif /* HAVE_LOCALTIME_R */
1144 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
1145 #else /* !HACK_LOCAL_TIME */
1146 # ifdef HAVE_GMTIME_R
1147 tms = gmtime_r( &starttime, &tm_buf );
1149 tms = gmtime( &starttime );
1150 # endif /* HAVE_GMTIME_R */
1151 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
1152 #endif /* !HACK_LOCAL_TIME */
1153 #ifndef HAVE_GMTIME_R
1154 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
1157 mi->mi_startTime.bv_val = tmbuf;
1158 mi->mi_startTime.bv_len = strlen( tmbuf );
1160 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
1161 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
1163 mi->mi_creatorsName = be->be_rootdn;
1167 * creates the "cn=Monitor" entry
1169 snprintf( buf, sizeof( buf ),
1172 "structuralObjectClass: %s\n"
1174 "%s: This subtree contains monitoring/managing objects.\n"
1175 "%s: This object contains information about this server.\n"
1177 "%s: createTimestamp reflects the time this server instance was created.\n"
1178 "%s: modifyTimestamp reflects the time this server instance was last accessed.\n"
1180 "creatorsName: %s\n"
1181 "modifiersName: %s\n"
1182 "createTimestamp: %s\n"
1183 "modifyTimestamp: %s\n",
1185 mi->mi_oc_monitorServer->soc_cname.bv_val,
1186 mi->mi_oc_monitorServer->soc_cname.bv_val,
1187 mi->mi_ad_description->ad_cname.bv_val,
1188 mi->mi_ad_description->ad_cname.bv_val,
1190 mi->mi_ad_description->ad_cname.bv_val,
1191 mi->mi_ad_description->ad_cname.bv_val,
1193 mi->mi_creatorsName.bv_val,
1194 mi->mi_creatorsName.bv_val,
1195 mi->mi_startTime.bv_val,
1196 mi->mi_startTime.bv_val );
1198 e = str2entry( buf );
1200 Debug( LDAP_DEBUG_ANY,
1201 "unable to create \"%s\" entry\n",
1202 SLAPD_MONITOR_DN, 0, 0 );
1206 bv.bv_val = (char *) Versionstr;
1207 end_of_line = strchr( Versionstr, '\n' );
1208 if ( end_of_line ) {
1209 bv.bv_len = end_of_line - Versionstr;
1211 bv.bv_len = strlen( Versionstr );
1214 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
1216 Debug( LDAP_DEBUG_ANY,
1217 "unable to add monitoredInfo to \"%s\" entry\n",
1218 SLAPD_MONITOR_DN, 0, 0 );
1222 if ( mi->mi_l.bv_len ) {
1223 if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) {
1224 Debug( LDAP_DEBUG_ANY,
1225 "unable to add locality to \"%s\" entry\n",
1226 SLAPD_MONITOR_DN, 0, 0 );
1231 mp = monitor_entrypriv_create();
1235 e->e_private = ( void * )mp;
1236 ep = &mp->mp_children;
1238 if ( monitor_cache_add( mi, e ) ) {
1239 Debug( LDAP_DEBUG_ANY,
1240 "unable to add entry \"%s\" to cache\n",
1241 SLAPD_MONITOR_DN, 0, 0 );
1246 * Create all the subsystem specific entries
1248 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1249 int len = strlen( monitor_subsys[ i ]->mss_name );
1253 dn.bv_len = len + sizeof( "cn=" ) - 1;
1254 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1255 strcpy( dn.bv_val, "cn=" );
1256 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1257 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1259 if ( rc != LDAP_SUCCESS ) {
1260 Debug( LDAP_DEBUG_ANY,
1261 "monitor RDN \"%s\" is invalid\n",
1266 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
1267 dn.bv_val = ch_malloc( dn.bv_len + 1 );
1268 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
1269 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
1270 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
1271 &monitor_subsys[ i ]->mss_ndn, NULL );
1273 if ( rc != LDAP_SUCCESS ) {
1274 Debug( LDAP_DEBUG_ANY,
1275 "monitor DN \"%s\" is invalid\n",
1280 snprintf( buf, sizeof( buf ),
1283 "structuralObjectClass: %s\n"
1285 "creatorsName: %s\n"
1286 "modifiersName: %s\n"
1287 "createTimestamp: %s\n"
1288 "modifyTimestamp: %s\n",
1289 monitor_subsys[ i ]->mss_dn.bv_val,
1290 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1291 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1292 monitor_subsys[ i ]->mss_name,
1293 mi->mi_creatorsName.bv_val,
1294 mi->mi_creatorsName.bv_val,
1295 mi->mi_startTime.bv_val,
1296 mi->mi_startTime.bv_val );
1298 e = str2entry( buf );
1301 Debug( LDAP_DEBUG_ANY,
1302 "unable to create \"%s\" entry\n",
1303 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1307 mp = monitor_entrypriv_create();
1311 e->e_private = ( void * )mp;
1312 mp->mp_info = monitor_subsys[ i ];
1313 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1315 if ( monitor_cache_add( mi, e ) ) {
1316 Debug( LDAP_DEBUG_ANY,
1317 "unable to add entry \"%s\" to cache\n",
1318 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1328 be->be_private = mi;
1331 * opens the monitor backend subsystems
1333 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1334 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1338 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1341 monitor_subsys_opened = 1;
1343 if ( mi->mi_entry_limbo ) {
1344 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
1349 switch ( el->el_type ) {
1351 monitor_back_register_entry(
1357 monitor_back_register_entry_attrs(
1367 monitor_back_register_entry_callback(
1380 entry_free( el->el_e );
1383 attrs_free( el->el_a );
1385 if ( !BER_BVISNULL( &el->el_ndn ) ) {
1386 ber_memfree( el->el_ndn.bv_val );
1388 if ( !BER_BVISNULL( &el->el_base ) ) {
1389 ber_memfree( el->el_base.bv_val );
1391 if ( !BER_BVISNULL( &el->el_filter ) ) {
1392 ber_memfree( el->el_filter.bv_val );
1400 mi->mi_entry_limbo = NULL;
1407 monitor_back_config(
1416 * eventually, will hold backend specific configuration parameters
1418 return SLAP_CONF_UNKNOWN;
1422 monitor_back_db_config(
1430 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1433 * eventually, will hold database specific configuration parameters
1435 if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
1440 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_l );
1443 return SLAP_CONF_UNKNOWN;
1450 monitor_back_db_destroy(
1455 * FIXME: destroys all the data
1460 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
1462 /* conditionally define the init_module() function */
1463 SLAP_BACKEND_INIT_MODULE( monitor )
1465 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */