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>
31 #include "back-monitor.h"
33 #undef INTEGRATE_CORE_SCHEMA
36 * used by many functions to add description to entries
38 * WARNING: be_monitor may change as new databases are added,
39 * so it should not be used outside monitor_back_db_init()
40 * until monitor_back_db_open is called.
42 BackendDB *be_monitor;
44 static struct monitor_subsys_t **monitor_subsys;
45 static int monitor_subsys_opened;
46 static monitor_info_t monitor_info;
51 * the known subsystems are added to the subsystems
52 * array at backend initialization; other subsystems
53 * may be added by calling monitor_back_register_subsys()
54 * before the database is opened (e.g. by other backends
55 * or by overlays or modules).
57 static struct monitor_subsys_t known_monitor_subsys[] = {
59 SLAPD_MONITOR_BACKEND_NAME,
60 BER_BVNULL, BER_BVNULL, BER_BVNULL,
61 { BER_BVC( "This subsystem contains information about available backends." ),
63 MONITOR_F_PERSISTENT_CH,
64 monitor_subsys_backend_init,
70 SLAPD_MONITOR_CONN_NAME,
71 BER_BVNULL, BER_BVNULL, BER_BVNULL,
72 { BER_BVC( "This subsystem contains information about connections." ),
74 MONITOR_F_VOLATILE_CH,
75 monitor_subsys_conn_init,
81 SLAPD_MONITOR_DATABASE_NAME,
82 BER_BVNULL, BER_BVNULL, BER_BVNULL,
83 { BER_BVC( "This subsystem contains information about configured databases." ),
85 MONITOR_F_PERSISTENT_CH,
86 monitor_subsys_database_init,
92 SLAPD_MONITOR_LISTENER_NAME,
93 BER_BVNULL, BER_BVNULL, BER_BVNULL,
94 { BER_BVC( "This subsystem contains information about active listeners." ),
96 MONITOR_F_PERSISTENT_CH,
97 monitor_subsys_listener_init,
103 SLAPD_MONITOR_LOG_NAME,
104 BER_BVNULL, BER_BVNULL, BER_BVNULL,
105 { BER_BVC( "This subsystem contains information about logging." ),
106 BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
109 monitor_subsys_log_init,
115 SLAPD_MONITOR_OPS_NAME,
116 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 { BER_BVC( "This subsystem contains information about performed operations." ),
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_ops_init,
126 SLAPD_MONITOR_OVERLAY_NAME,
127 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128 { BER_BVC( "This subsystem contains information about available overlays." ),
130 MONITOR_F_PERSISTENT_CH,
131 monitor_subsys_overlay_init,
137 SLAPD_MONITOR_SASL_NAME,
138 BER_BVNULL, BER_BVNULL, BER_BVNULL,
139 { BER_BVC( "This subsystem contains information about SASL." ),
148 SLAPD_MONITOR_SENT_NAME,
149 BER_BVNULL, BER_BVNULL, BER_BVNULL,
150 { BER_BVC( "This subsystem contains statistics." ),
152 MONITOR_F_PERSISTENT_CH,
153 monitor_subsys_sent_init,
159 SLAPD_MONITOR_THREAD_NAME,
160 BER_BVNULL, BER_BVNULL, BER_BVNULL,
161 { BER_BVC( "This subsystem contains information about threads." ),
163 MONITOR_F_PERSISTENT_CH,
164 monitor_subsys_thread_init,
170 SLAPD_MONITOR_TIME_NAME,
171 BER_BVNULL, BER_BVNULL, BER_BVNULL,
172 { BER_BVC( "This subsystem contains information about time." ),
174 MONITOR_F_PERSISTENT_CH,
175 monitor_subsys_time_init,
181 SLAPD_MONITOR_TLS_NAME,
182 BER_BVNULL, BER_BVNULL, BER_BVNULL,
183 { BER_BVC( "This subsystem contains information about TLS." ),
192 SLAPD_MONITOR_RWW_NAME,
193 BER_BVNULL, BER_BVNULL, BER_BVNULL,
194 { BER_BVC( "This subsystem contains information about read/write waiters." ),
196 MONITOR_F_PERSISTENT_CH,
197 monitor_subsys_rww_init,
206 monitor_back_register_subsys(
207 monitor_subsys_t *ms )
211 if ( monitor_subsys ) {
212 for ( ; monitor_subsys[ i ] != NULL; i++ )
213 /* just count'em */ ;
216 monitor_subsys = ch_realloc( monitor_subsys,
217 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
219 if ( monitor_subsys == NULL ) {
223 monitor_subsys[ i ] = ms;
224 monitor_subsys[ i + 1 ] = NULL;
226 /* if a subsystem is registered __AFTER__ subsystem
227 * initialization (depending on the sequence the databases
228 * are listed in slapd.conf), init it */
229 if ( monitor_subsys_opened ) {
231 /* FIXME: this should only be possible
232 * if be_monitor is already initialized */
233 assert( be_monitor != NULL );
235 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
239 ms->mss_flags |= MONITOR_F_OPENED;
252 typedef struct entry_limbo_t {
256 struct berval el_ndn;
257 struct berval el_base;
259 struct berval el_filter;
260 monitor_callback_t *el_cb;
261 struct entry_limbo_t *el_next;
265 monitor_back_is_configured( void )
267 return be_monitor != NULL;
271 monitor_back_register_entry(
273 monitor_callback_t *cb )
277 if ( be_monitor == NULL ) {
278 Debug( LDAP_DEBUG_ANY,
279 "monitor_back_register_entry(\"%s\"): "
280 "monitor database not configured.\n",
281 e->e_name.bv_val, 0, 0 );
285 mi = ( monitor_info_t * )be_monitor->be_private;
287 assert( mi != NULL );
289 assert( e->e_private == NULL );
291 if ( monitor_subsys_opened ) {
292 Entry *e_parent = NULL,
295 struct berval pdn = BER_BVNULL;
296 monitor_entry_t *mp = NULL,
300 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
302 Debug( LDAP_DEBUG_ANY,
303 "monitor_back_register_entry(\"%s\"): "
305 e->e_name.bv_val, 0, 0 );
306 monitor_cache_release( mi, e_parent );
310 dnParent( &e->e_nname, &pdn );
311 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
312 /* parent does not exist */
313 Debug( LDAP_DEBUG_ANY,
314 "monitor_back_register_entry(\"%s\"): "
315 "parent \"%s\" not found\n",
316 e->e_name.bv_val, pdn.bv_val, 0 );
320 assert( e_parent->e_private != NULL );
321 mp_parent = ( monitor_entry_t * )e_parent->e_private;
323 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
324 /* entry is volatile; cannot append children */
325 Debug( LDAP_DEBUG_ANY,
326 "monitor_back_register_entry(\"%s\"): "
327 "parent \"%s\" is volatile\n",
328 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
333 mp = monitor_entrypriv_create();
335 Debug( LDAP_DEBUG_ANY,
336 "monitor_back_register_entry(\"%s\"): "
337 "monitor_entrypriv_create() failed\n",
338 e->e_name.bv_val, 0, 0 );
343 e_new = entry_dup( e );
344 if ( e_new == NULL ) {
345 Debug( LDAP_DEBUG_ANY,
346 "monitor_back_register_entry(\"%s\"): "
347 "entry_dup() failed\n",
348 e->e_name.bv_val, 0, 0 );
353 e_new->e_private = ( void * )mp;
354 mp->mp_info = mp_parent->mp_info;
355 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
358 ep = &mp_parent->mp_children;
360 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
361 ep = &mp_parent->mp_next;
365 if ( monitor_cache_add( mi, e_new ) ) {
366 Debug( LDAP_DEBUG_ANY,
367 "monitor_back_register_entry(\"%s\"): "
368 "unable to add entry\n",
369 e->e_name.bv_val, 0, 0 );
380 e_new->e_private = NULL;
386 monitor_cache_release( mi, e_parent );
390 entry_limbo_t **elpp, el = { 0 };
392 el.el_type = LIMBO_ENTRY;
394 el.el_e = entry_dup( e );
395 if ( el.el_e == NULL ) {
396 Debug( LDAP_DEBUG_ANY,
397 "monitor_back_register_entry(\"%s\"): "
398 "entry_dup() failed\n",
399 e->e_name.bv_val, 0, 0 );
405 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
407 elpp = &(*elpp)->el_next )
410 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
411 if ( *elpp == NULL ) {
412 el.el_e->e_private = NULL;
413 entry_free( el.el_e );
425 monitor_back_register_entry_parent(
427 monitor_callback_t *cb,
430 struct berval *filter )
433 struct berval ndn = BER_BVNULL;
435 if ( be_monitor == NULL ) {
436 Debug( LDAP_DEBUG_ANY,
437 "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
438 "monitor database not configured.\n",
439 BER_BVISNULL( base ) ? "" : base->bv_val,
440 scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ),
441 BER_BVISNULL( filter ) ? "" : filter->bv_val );
445 mi = ( monitor_info_t * )be_monitor->be_private;
447 assert( mi != NULL );
449 assert( e->e_private == NULL );
451 if ( BER_BVISNULL( filter ) ) {
453 Debug( LDAP_DEBUG_ANY,
454 "monitor_back_register_entry_parent(\"\"): "
455 "need a valid filter\n",
460 if ( monitor_subsys_opened ) {
461 Entry *e_parent = NULL,
464 struct berval e_name = BER_BVNULL,
465 e_nname = BER_BVNULL;
466 monitor_entry_t *mp = NULL,
470 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
471 /* entry does not exist */
472 Debug( LDAP_DEBUG_ANY,
473 "monitor_back_register_entry_parent(\"\"): "
474 "base=%s scope=%d filter=%s : "
475 "unable to find entry\n",
476 base->bv_val ? base->bv_val : "\"\"",
477 scope, filter->bv_val );
481 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
482 /* entry does not exist */
483 Debug( LDAP_DEBUG_ANY,
484 "monitor_back_register_entry_parent(\"%s\"): "
485 "parent entry does not exist\n",
491 assert( e_parent->e_private != NULL );
492 mp_parent = ( monitor_entry_t * )e_parent->e_private;
494 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
495 /* entry is volatile; cannot append callback */
496 Debug( LDAP_DEBUG_ANY,
497 "monitor_back_register_entry_parent(\"%s\"): "
498 "entry is volatile\n",
499 e_parent->e_name.bv_val, 0, 0 );
504 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
505 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
507 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
508 /* entry already exists */
509 Debug( LDAP_DEBUG_ANY,
510 "monitor_back_register_entry_parent(\"%s\"): "
511 "entry already exists\n",
512 e_name.bv_val, 0, 0 );
513 monitor_cache_release( mi, e_new );
518 mp = monitor_entrypriv_create();
520 Debug( LDAP_DEBUG_ANY,
521 "monitor_back_register_entry_parent(\"%s\"): "
522 "monitor_entrypriv_create() failed\n",
523 e->e_name.bv_val, 0, 0 );
528 e_new = entry_dup( e );
529 if ( e_new == NULL ) {
530 Debug( LDAP_DEBUG_ANY,
531 "monitor_back_register_entry(\"%s\"): "
532 "entry_dup() failed\n",
533 e->e_name.bv_val, 0, 0 );
537 ch_free( e_new->e_name.bv_val );
538 ch_free( e_new->e_nname.bv_val );
539 e_new->e_name = e_name;
540 e_new->e_nname = e_nname;
542 e_new->e_private = ( void * )mp;
543 mp->mp_info = mp_parent->mp_info;
544 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
547 ep = &mp_parent->mp_children;
549 mp_parent = ( monitor_entry_t * )(*ep)->e_private;
550 ep = &mp_parent->mp_next;
554 if ( monitor_cache_add( mi, e_new ) ) {
555 Debug( LDAP_DEBUG_ANY,
556 "monitor_back_register_entry(\"%s\"): "
557 "unable to add entry\n",
558 e->e_name.bv_val, 0, 0 );
564 if ( !BER_BVISNULL( &ndn ) ) {
565 ch_free( ndn.bv_val );
573 e_new->e_private = NULL;
579 monitor_cache_release( mi, e_parent );
583 entry_limbo_t **elpp, el = { 0 };
585 el.el_type = LIMBO_ENTRY_PARENT;
587 el.el_e = entry_dup( e );
588 if ( el.el_e == NULL ) {
589 Debug( LDAP_DEBUG_ANY,
590 "monitor_back_register_entry(\"%s\"): "
591 "entry_dup() failed\n",
592 e->e_name.bv_val, 0, 0 );
596 if ( !BER_BVISNULL( base ) ) {
597 ber_dupbv( &el.el_base, base );
600 if ( !BER_BVISNULL( filter ) ) {
601 ber_dupbv( &el.el_filter, filter );
606 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
608 elpp = &(*elpp)->el_next )
611 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
612 if ( *elpp == NULL ) {
613 el.el_e->e_private = NULL;
614 entry_free( el.el_e );
626 monitor_filter2ndn_cb( Operation *op, SlapReply *rs )
628 if ( rs->sr_type == REP_SEARCH ) {
629 struct berval *ndn = op->o_callback->sc_private;
631 ber_dupbv( ndn, &rs->sr_entry->e_nname );
641 struct berval *filter,
644 Connection conn = { 0 };
645 OperationBuffer opbuf;
647 SlapReply rs = { 0 };
648 slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
653 if ( be_monitor == NULL ) {
657 op = (Operation *) &opbuf;
658 connection_fake_init( &conn, op, &conn );
660 op->o_tag = LDAP_REQ_SEARCH;
662 /* use global malloc for now */
663 if ( op->o_tmpmemctx ) {
664 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
665 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
666 op->o_tmpmemctx = NULL;
668 op->o_tmpmfuncs = &ch_mfuncs;
670 op->o_bd = be_monitor;
671 if ( base == NULL || BER_BVISNULL( base ) ) {
672 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
674 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
678 if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn,
679 op->o_tmpmemctx ) ) {
684 op->o_callback = &cb;
685 cb.sc_private = (void *)ndn;
687 op->ors_scope = scope;
688 ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
689 op->ors_filter = str2filter_x( op, filter->bv_val );
690 op->ors_attrs = slap_anlist_no_attrs;
691 op->ors_attrsonly = 0;
692 op->ors_tlimit = SLAP_NO_LIMIT;
694 op->ors_limit = NULL;
695 op->ors_deref = LDAP_DEREF_NEVER;
698 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
700 op->o_dn = be_monitor->be_rootdn;
701 op->o_ndn = be_monitor->be_rootndn;
703 rc = op->o_bd->be_search( op, &rs );
705 filter_free_x( op, op->ors_filter );
706 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
707 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
708 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
714 switch ( rs.sr_err ) {
716 if ( BER_BVISNULL( ndn ) ) {
721 case LDAP_SIZELIMIT_EXCEEDED:
723 if ( !BER_BVISNULL( ndn ) ) {
724 ber_memfree( ndn->bv_val );
735 monitor_back_register_entry_attrs(
736 struct berval *ndn_in,
738 monitor_callback_t *cb,
741 struct berval *filter )
744 struct berval ndn = BER_BVNULL;
745 char *fname = ( a == NULL ? "callback" : "attrs" );
747 if ( be_monitor == NULL ) {
748 char buf[ SLAP_TEXT_BUFLEN ];
750 snprintf( buf, sizeof( buf ),
751 "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
752 "monitor database not configured.\n",
754 BER_BVISNULL( base ) ? "" : base->bv_val,
755 scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ),
756 BER_BVISNULL( filter ) ? "" : filter->bv_val );
757 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
762 mi = ( monitor_info_t * )be_monitor->be_private;
764 assert( mi != NULL );
766 if ( ndn_in != NULL ) {
770 if ( a == NULL && cb == NULL ) {
775 if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
776 && BER_BVISNULL( filter ) )
779 Debug( LDAP_DEBUG_ANY,
780 "monitor_back_register_entry_%s(\"\"): "
781 "need a valid filter\n",
786 if ( monitor_subsys_opened ) {
788 Attribute **atp = NULL;
789 monitor_entry_t *mp = NULL;
790 monitor_callback_t **mcp = NULL;
794 if ( BER_BVISNULL( &ndn ) ) {
795 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
796 char buf[ SLAP_TEXT_BUFLEN ];
798 snprintf( buf, sizeof( buf ),
799 "monitor_back_register_entry_%s(\"\"): "
800 "base=%s scope=%d filter=%s : "
801 "unable to find entry\n",
803 base->bv_val ? base->bv_val : "\"\"",
804 scope, filter->bv_val );
806 /* entry does not exist */
807 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
814 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
815 /* entry does not exist */
816 Debug( LDAP_DEBUG_ANY,
817 "monitor_back_register_entry_%s(\"%s\"): "
818 "entry does not exist\n",
819 fname, ndn.bv_val, 0 );
824 assert( e->e_private != NULL );
825 mp = ( monitor_entry_t * )e->e_private;
827 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
828 /* entry is volatile; cannot append callback */
829 Debug( LDAP_DEBUG_ANY,
830 "monitor_back_register_entry_%s(\"%s\"): "
831 "entry is volatile\n",
832 fname, e->e_name.bv_val, 0 );
838 for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
839 /* just get to last */ ;
841 *atp = attrs_dup( a );
842 if ( *atp == NULL ) {
843 Debug( LDAP_DEBUG_ANY,
844 "monitor_back_register_entry_%s(\"%s\"): "
845 "attrs_dup() failed\n",
846 fname, e->e_name.bv_val, 0 );
853 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
856 /* NOTE: we do not clear cb->mc_next, so this function
857 * can be used to append a list of callbacks */
870 ber_memfree( ndn.bv_val );
874 monitor_cache_release( mi, e );
878 entry_limbo_t **elpp, el = { 0 };
880 el.el_type = LIMBO_ATTRS;
881 if ( !BER_BVISNULL( &ndn ) ) {
882 ber_dupbv( &el.el_ndn, &ndn );
884 if ( !BER_BVISNULL( base ) ) {
885 ber_dupbv( &el.el_base, base);
888 if ( !BER_BVISNULL( filter ) ) {
889 ber_dupbv( &el.el_filter, filter );
892 el.el_a = attrs_dup( a );
895 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
897 elpp = &(*elpp)->el_next )
900 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
901 if ( *elpp == NULL ) {
902 el.el_e->e_private = NULL;
903 entry_free( el.el_e );
915 monitor_back_register_entry_callback(
917 monitor_callback_t *cb,
920 struct berval *filter )
922 return monitor_back_register_entry_attrs( ndn, NULL, cb,
923 base, scope, filter );
927 monitor_back_get_subsys( const char *name )
929 if ( monitor_subsys != NULL ) {
932 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
933 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
934 return monitor_subsys[ i ];
943 monitor_back_get_subsys_by_dn(
947 if ( monitor_subsys != NULL ) {
951 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
952 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
953 return monitor_subsys[ i ];
958 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
959 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
960 return monitor_subsys[ i ];
970 monitor_back_initialize(
973 monitor_subsys_t *ms;
974 static char *controls[] = {
975 LDAP_CONTROL_MANAGEDSAIT,
978 monitor_info_t *mi = &monitor_info;
988 { "monitor", "( 1.3.6.1.4.1.4203.666.3.16.1 "
990 "DESC 'OpenLDAP system monitoring' "
991 "SUP top STRUCTURAL "
1000 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1001 offsetof(monitor_info_t, mi_oc_monitor) },
1002 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.16.2 "
1003 "NAME 'monitorServer' "
1004 "DESC 'Server monitoring root entry' "
1005 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1006 offsetof(monitor_info_t, mi_oc_monitorServer) },
1007 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.16.3 "
1008 "NAME 'monitorContainer' "
1009 "DESC 'monitor container class' "
1010 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1011 offsetof(monitor_info_t, mi_oc_monitorContainer) },
1012 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.16.4 "
1013 "NAME 'monitorCounterObject' "
1014 "DESC 'monitor counter class' "
1015 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1016 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1017 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.16.5 "
1018 "NAME 'monitorOperation' "
1019 "DESC 'monitor operation class' "
1020 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1021 offsetof(monitor_info_t, mi_oc_monitorOperation) },
1022 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.16.6 "
1023 "NAME 'monitorConnection' "
1024 "DESC 'monitor connection class' "
1025 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1026 offsetof(monitor_info_t, mi_oc_monitorConnection) },
1027 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.16.7 "
1028 "NAME 'managedObject' "
1029 "DESC 'monitor managed entity class' "
1030 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1031 offsetof(monitor_info_t, mi_oc_managedObject) },
1032 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.16.8 "
1033 "NAME 'monitoredObject' "
1034 "DESC 'monitor monitored entity class' "
1035 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1036 offsetof(monitor_info_t, mi_oc_monitoredObject) },
1037 { NULL, NULL, 0, -1 }
1039 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.55.1 "
1040 "NAME 'monitoredInfo' "
1041 "DESC 'monitored info' "
1043 "EQUALITY caseIgnoreMatch "
1044 "SUBSTR caseIgnoreSubstringsMatch "
1045 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1046 "NO-USER-MODIFICATION "
1047 "USAGE directoryOperation )", SLAP_AT_HIDE,
1048 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1049 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.55.2 "
1050 "NAME 'managedInfo' "
1051 "DESC 'monitor managed info' "
1052 "SUP name )", SLAP_AT_HIDE,
1053 offsetof(monitor_info_t, mi_ad_managedInfo) },
1054 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.55.3 "
1055 "NAME 'monitorCounter' "
1056 "DESC 'monitor counter' "
1057 "EQUALITY integerMatch "
1058 "ORDERING integerOrderingMatch "
1059 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1060 "NO-USER-MODIFICATION "
1061 "USAGE directoryOperation )", SLAP_AT_HIDE,
1062 offsetof(monitor_info_t, mi_ad_monitorCounter) },
1063 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.55.4 "
1064 "NAME 'monitorOpCompleted' "
1065 "DESC 'monitor completed operations' "
1066 "SUP monitorCounter "
1067 "NO-USER-MODIFICATION "
1068 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1069 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1070 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.55.5 "
1071 "NAME 'monitorOpInitiated' "
1072 "DESC 'monitor initiated operations' "
1073 "SUP monitorCounter "
1074 "NO-USER-MODIFICATION "
1075 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1076 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1077 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.55.6 "
1078 "NAME 'monitorConnectionNumber' "
1079 "DESC 'monitor connection number' "
1080 "SUP monitorCounter "
1081 "NO-USER-MODIFICATION "
1082 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1083 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1084 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.55.7 "
1085 "NAME 'monitorConnectionAuthzDN' "
1086 "DESC 'monitor connection authorization DN' "
1087 /* "SUP distinguishedName " */
1088 "EQUALITY distinguishedNameMatch "
1089 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1090 "NO-USER-MODIFICATION "
1091 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1092 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1093 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.55.8 "
1094 "NAME 'monitorConnectionLocalAddress' "
1095 "DESC 'monitor connection local address' "
1096 "SUP monitoredInfo "
1097 "NO-USER-MODIFICATION "
1098 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1099 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1100 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.55.9 "
1101 "NAME 'monitorConnectionPeerAddress' "
1102 "DESC 'monitor connection peer address' "
1103 "SUP monitoredInfo "
1104 "NO-USER-MODIFICATION "
1105 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1106 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1107 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.55.10 "
1108 "NAME 'monitorTimestamp' "
1109 "DESC 'monitor timestamp' "
1110 "EQUALITY generalizedTimeMatch "
1111 "ORDERING generalizedTimeOrderingMatch "
1112 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1114 "NO-USER-MODIFICATION "
1115 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1116 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1117 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.55.11 "
1118 "NAME 'monitorOverlay' "
1119 "DESC 'name of overlays defined for a given database' "
1120 "SUP monitoredInfo "
1121 "NO-USER-MODIFICATION "
1122 "USAGE directoryOperation )", SLAP_AT_HIDE,
1123 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1124 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.55.12 "
1126 "DESC 'read/write status of a given database' "
1127 "EQUALITY booleanMatch "
1128 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1130 "USAGE directoryOperation )", SLAP_AT_HIDE,
1131 offsetof(monitor_info_t, mi_ad_readOnly) },
1132 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.55.13 "
1133 "NAME 'restrictedOperation' "
1134 "DESC 'name of restricted operation for a given database' "
1135 "SUP managedInfo )", SLAP_AT_HIDE,
1136 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1137 { "monitorConnectionProtocol", "( 1.3.6.1.4.1.4203.666.1.55.14 "
1138 "NAME 'monitorConnectionProtocol' "
1139 "DESC 'monitor connection protocol' "
1140 "SUP monitoredInfo "
1141 "NO-USER-MODIFICATION "
1142 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1143 offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1144 { "monitorConnectionOpsReceived", "( 1.3.6.1.4.1.4203.666.1.55.15 "
1145 "NAME 'monitorConnectionOpsReceived' "
1146 "DESC 'monitor number of operations received by the connection' "
1147 "SUP monitorCounter "
1148 "NO-USER-MODIFICATION "
1149 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1150 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1151 { "monitorConnectionOpsExecuting", "( 1.3.6.1.4.1.4203.666.1.55.16 "
1152 "NAME 'monitorConnectionOpsExecuting' "
1153 "DESC 'monitor number of operations in execution within the connection' "
1154 "SUP monitorCounter "
1155 "NO-USER-MODIFICATION "
1156 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1157 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1158 { "monitorConnectionOpsPending", "( 1.3.6.1.4.1.4203.666.1.55.17 "
1159 "NAME 'monitorConnectionOpsPending' "
1160 "DESC 'monitor number of pending operations within the connection' "
1161 "SUP monitorCounter "
1162 "NO-USER-MODIFICATION "
1163 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1164 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1165 { "monitorConnectionOpsCompleted", "( 1.3.6.1.4.1.4203.666.1.55.18 "
1166 "NAME 'monitorConnectionOpsCompleted' "
1167 "DESC 'monitor number of operations completed within the connection' "
1168 "SUP monitorCounter "
1169 "NO-USER-MODIFICATION "
1170 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1171 offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1172 { "monitorConnectionGet", "( 1.3.6.1.4.1.4203.666.1.55.19 "
1173 "NAME 'monitorConnectionGet' "
1174 "DESC 'number of times connection_get() was called so far' "
1175 "SUP monitorCounter "
1176 "NO-USER-MODIFICATION "
1177 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1178 offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1179 { "monitorConnectionRead", "( 1.3.6.1.4.1.4203.666.1.55.20 "
1180 "NAME 'monitorConnectionRead' "
1181 "DESC 'number of times connection_read() was called so far' "
1182 "SUP monitorCounter "
1183 "NO-USER-MODIFICATION "
1184 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1185 offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1186 { "monitorConnectionWrite", "( 1.3.6.1.4.1.4203.666.1.55.21 "
1187 "NAME 'monitorConnectionWrite' "
1188 "DESC 'number of times connection_write() was called so far' "
1189 "SUP monitorCounter "
1190 "NO-USER-MODIFICATION "
1191 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1192 offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1193 { "monitorConnectionMask", "( 1.3.6.1.4.1.4203.666.1.55.22 "
1194 "NAME 'monitorConnectionMask' "
1195 "DESC 'monitor connection mask' "
1196 "SUP monitoredInfo "
1197 "NO-USER-MODIFICATION "
1198 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1199 offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1200 { "monitorConnectionListener", "( 1.3.6.1.4.1.4203.666.1.55.23 "
1201 "NAME 'monitorConnectionListener' "
1202 "DESC 'monitor connection listener' "
1203 "SUP monitoredInfo "
1204 "NO-USER-MODIFICATION "
1205 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1206 offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1207 { "monitorConnectionPeerDomain", "( 1.3.6.1.4.1.4203.666.1.55.24 "
1208 "NAME 'monitorConnectionPeerDomain' "
1209 "DESC 'monitor connection peer domain' "
1210 "SUP monitoredInfo "
1211 "NO-USER-MODIFICATION "
1212 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1213 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1214 { "monitorConnectionStartTime", "( 1.3.6.1.4.1.4203.666.1.55.25 "
1215 "NAME 'monitorConnectionStartTime' "
1216 "DESC 'monitor connection start time' "
1217 "SUP monitorTimestamp "
1219 "NO-USER-MODIFICATION "
1220 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1221 offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1222 { "monitorConnectionActivityTime", "( 1.3.6.1.4.1.4203.666.1.55.26 "
1223 "NAME 'monitorConnectionActivityTime' "
1224 "DESC 'monitor connection activity time' "
1225 "SUP monitorTimestamp "
1227 "NO-USER-MODIFICATION "
1228 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1229 offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1230 { "monitorIsShadow", "( 1.3.6.1.4.1.4203.666.1.55.27 "
1231 "NAME 'monitorIsShadow' "
1232 "DESC 'TRUE if the database is shadow' "
1233 "EQUALITY booleanMatch "
1234 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1236 "USAGE directoryOperation )", SLAP_AT_HIDE,
1237 offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1238 { "monitorUpdateRef", "( 1.3.6.1.4.1.4203.666.1.55.28 "
1239 "NAME 'monitorUpdateRef' "
1240 "DESC 'update referral for shadow databases' "
1241 "SUP monitoredInfo "
1243 "USAGE directoryOperation )", SLAP_AT_HIDE,
1244 offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1245 { "monitorRuntimeConfig", "( 1.3.6.1.4.1.4203.666.1.55.29 "
1246 "NAME 'monitorRuntimeConfig' "
1247 "DESC 'TRUE if component allows runtime configuration' "
1248 "EQUALITY booleanMatch "
1249 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1251 "USAGE directoryOperation )", SLAP_AT_HIDE,
1252 offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1253 { NULL, NULL, 0, -1 }
1255 static ConfigTable monitorcfg[] = {
1256 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1257 NULL, NULL, NULL, NULL }
1259 static ConfigOCs monitorocs[] = {
1260 { "( OLcfgDbOc:4.1 "
1261 "NAME 'olcMonitorConfig' "
1262 "DESC 'Monitor backend configuration' "
1263 "SUP olcDatabaseConfig "
1265 Cft_Database, monitorcfg },
1270 bi->bi_controls = controls;
1274 bi->bi_config = monitor_back_config;
1278 bi->bi_db_init = monitor_back_db_init;
1279 bi->bi_db_config = monitor_back_db_config;
1280 bi->bi_db_open = monitor_back_db_open;
1281 bi->bi_db_close = 0;
1282 bi->bi_db_destroy = monitor_back_db_destroy;
1284 bi->bi_op_bind = monitor_back_bind;
1285 bi->bi_op_unbind = 0;
1286 bi->bi_op_search = monitor_back_search;
1287 bi->bi_op_compare = monitor_back_compare;
1288 bi->bi_op_modify = monitor_back_modify;
1289 bi->bi_op_modrdn = 0;
1291 bi->bi_op_delete = 0;
1292 bi->bi_op_abandon = 0;
1294 bi->bi_extended = 0;
1296 bi->bi_entry_release_rw = 0;
1297 bi->bi_chk_referrals = 0;
1298 bi->bi_operational = monitor_back_operational;
1301 * hooks for slap tools
1303 bi->bi_tool_entry_open = 0;
1304 bi->bi_tool_entry_close = 0;
1305 bi->bi_tool_entry_first = 0;
1306 bi->bi_tool_entry_next = 0;
1307 bi->bi_tool_entry_get = 0;
1308 bi->bi_tool_entry_put = 0;
1309 bi->bi_tool_entry_reindex = 0;
1310 bi->bi_tool_sync = 0;
1311 bi->bi_tool_dn2id_get = 0;
1312 bi->bi_tool_id2entry_get = 0;
1313 bi->bi_tool_entry_modify = 0;
1315 bi->bi_connection_init = 0;
1316 bi->bi_connection_destroy = 0;
1319 * configuration objectClasses (fake)
1321 bi->bi_cf_ocs = monitorocs;
1323 rc = config_register_schema( monitorcfg, monitorocs );
1331 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1332 if ( monitor_back_register_subsys( ms ) ) {
1337 /* schema integration */
1338 for ( i = 0; mat[ i ].name; i++ ) {
1339 LDAPAttributeType *at;
1342 AttributeDescription **ad;
1344 at = ldap_str2attributetype( mat[ i ].schema, &code,
1345 &err, LDAP_SCHEMA_ALLOW_ALL );
1347 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1348 "in AttributeType \"%s\" %s before %s\n",
1349 mat[ i ].name, ldap_scherr2str(code), err );
1353 if ( at->at_oid == NULL ) {
1354 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1355 "null OID for attributeType \"%s\"\n",
1356 mat[ i ].name, 0, 0 );
1360 code = at_add(at, 0, NULL, &err);
1362 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1363 "%s in attributeType \"%s\"\n",
1364 scherr2str(code), mat[ i ].name, 0 );
1369 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1371 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1372 Debug( LDAP_DEBUG_ANY,
1373 "monitor_back_db_init: %s\n", text, 0, 0 );
1377 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1380 for ( i = 0; moc[ i ].name; i++ ) {
1381 LDAPObjectClass *oc;
1386 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1387 LDAP_SCHEMA_ALLOW_ALL );
1389 Debug( LDAP_DEBUG_ANY,
1390 "unable to parse monitor objectclass \"%s\": "
1391 "%s before %s\n" , moc[ i ].name,
1392 ldap_scherr2str(code), err );
1396 if ( oc->oc_oid == NULL ) {
1397 Debug( LDAP_DEBUG_ANY,
1398 "objectclass \"%s\" has no OID\n" ,
1399 moc[ i ].name, 0, 0 );
1403 code = oc_add(oc, 0, NULL, &err);
1405 Debug( LDAP_DEBUG_ANY,
1406 "objectclass \"%s\": %s \"%s\"\n" ,
1407 moc[ i ].name, scherr2str(code), err );
1413 Oc = oc_find( moc[ i ].name );
1415 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1416 "unable to find objectClass %s "
1417 "(just added)\n", moc[ i ].name, 0, 0 );
1421 Oc->soc_flags |= moc[ i ].flags;
1423 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1430 monitor_back_db_init(
1434 struct berval dn = BER_BVC( SLAPD_MONITOR_DN ),
1440 * database monitor can be defined once only
1442 if ( be_monitor != NULL ) {
1443 Debug( LDAP_DEBUG_ANY,
1444 "only one monitor database is allowed\n", 0, 0, 0 );
1449 /* indicate system schema supported */
1450 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1452 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1453 if( rc != LDAP_SUCCESS ) {
1454 Debug( LDAP_DEBUG_ANY,
1455 "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
1460 ber_bvarray_add( &be->be_suffix, &pdn );
1461 ber_bvarray_add( &be->be_nsuffix, &ndn );
1463 /* NOTE: only one monitor database is allowed,
1464 * so we use static storage */
1465 ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
1467 be->be_private = &monitor_info;
1469 be2 = select_backend( &ndn, 0, 0 );
1471 char *type = be2->bd_info->bi_type;
1473 if ( overlay_is_over( be2 ) ) {
1474 slap_overinfo *oi = (slap_overinfo *)be2->bd_info->bi_private;
1475 type = oi->oi_orig->bi_type;
1478 Debug( LDAP_DEBUG_ANY,
1479 "\"monitor\" database serving namingContext \"%s\" "
1480 "is hidden by \"%s\" database serving namingContext \"%s\".\n",
1481 pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
1489 monitor_back_db_open(
1492 monitor_info_t *mi = (monitor_info_t *)be->be_private;
1493 struct monitor_subsys_t **ms;
1495 monitor_entry_t *mp;
1497 char buf[ BACKMONITOR_BUFSIZE ];
1500 #ifdef HAVE_GMTIME_R
1503 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
1505 assert( be_monitor != NULL );
1506 if ( be != be_monitor ) {
1513 #ifndef HAVE_GMTIME_R
1514 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
1516 #ifdef HACK_LOCAL_TIME
1517 # ifdef HAVE_LOCALTIME_R
1518 tms = localtime_r( &starttime, &tm_buf );
1520 tms = localtime( &starttime );
1521 # endif /* HAVE_LOCALTIME_R */
1522 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
1523 #else /* !HACK_LOCAL_TIME */
1524 # ifdef HAVE_GMTIME_R
1525 tms = gmtime_r( &starttime, &tm_buf );
1527 tms = gmtime( &starttime );
1528 # endif /* HAVE_GMTIME_R */
1529 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
1530 #endif /* !HACK_LOCAL_TIME */
1531 #ifndef HAVE_GMTIME_R
1532 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
1535 mi->mi_startTime.bv_val = tmbuf;
1536 mi->mi_startTime.bv_len = strlen( tmbuf );
1538 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
1539 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
1541 mi->mi_creatorsName = be->be_rootdn;
1545 * creates the "cn=Monitor" entry
1547 snprintf( buf, sizeof( buf ),
1550 "structuralObjectClass: %s\n"
1552 "description: This subtree contains monitoring/managing objects.\n"
1553 "description: This object contains information about this server.\n"
1554 "description: Most of the information is held in operational"
1555 " attributeTypes, which must be explicitly requested.\n"
1556 "creatorsName: %s\n"
1557 "modifiersName: %s\n"
1558 "createTimestamp: %s\n"
1559 "modifyTimestamp: %s\n",
1561 mi->mi_oc_monitorServer->soc_cname.bv_val,
1562 mi->mi_oc_monitorServer->soc_cname.bv_val,
1563 mi->mi_creatorsName.bv_val,
1564 mi->mi_creatorsName.bv_val,
1565 mi->mi_startTime.bv_val,
1566 mi->mi_startTime.bv_val );
1568 e = str2entry( buf );
1570 Debug( LDAP_DEBUG_ANY,
1571 "unable to create \"%s\" entry\n",
1572 SLAPD_MONITOR_DN, 0, 0 );
1576 bv.bv_val = strchr( (char *) Versionstr, '$' );
1577 if ( bv.bv_val != NULL ) {
1581 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
1584 end = strchr( bv.bv_val, '$' );
1585 if ( end != NULL ) {
1588 for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
1593 bv.bv_len = end - bv.bv_val;
1596 bv.bv_len = strlen( bv.bv_val );
1599 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
1601 Debug( LDAP_DEBUG_ANY,
1602 "unable to add monitoredInfo to \"%s\" entry\n",
1603 SLAPD_MONITOR_DN, 0, 0 );
1608 mp = monitor_entrypriv_create();
1612 e->e_private = ( void * )mp;
1613 ep = &mp->mp_children;
1615 if ( monitor_cache_add( mi, e ) ) {
1616 Debug( LDAP_DEBUG_ANY,
1617 "unable to add entry \"%s\" to cache\n",
1618 SLAPD_MONITOR_DN, 0, 0 );
1623 * Create all the subsystem specific entries
1625 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1626 int len = strlen( monitor_subsys[ i ]->mss_name );
1630 dn.bv_len = len + sizeof( "cn=" ) - 1;
1631 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1632 strcpy( dn.bv_val, "cn=" );
1633 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1634 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1636 if ( rc != LDAP_SUCCESS ) {
1637 Debug( LDAP_DEBUG_ANY,
1638 "monitor RDN \"%s\" is invalid\n",
1643 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
1644 dn.bv_val = ch_malloc( dn.bv_len + 1 );
1645 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
1646 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
1647 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
1648 &monitor_subsys[ i ]->mss_ndn, NULL );
1650 if ( rc != LDAP_SUCCESS ) {
1651 Debug( LDAP_DEBUG_ANY,
1652 "monitor DN \"%s\" is invalid\n",
1657 snprintf( buf, sizeof( buf ),
1660 "structuralObjectClass: %s\n"
1662 "creatorsName: %s\n"
1663 "modifiersName: %s\n"
1664 "createTimestamp: %s\n"
1665 "modifyTimestamp: %s\n",
1666 monitor_subsys[ i ]->mss_dn.bv_val,
1667 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1668 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1669 monitor_subsys[ i ]->mss_name,
1670 mi->mi_creatorsName.bv_val,
1671 mi->mi_creatorsName.bv_val,
1672 mi->mi_startTime.bv_val,
1673 mi->mi_startTime.bv_val );
1675 e = str2entry( buf );
1678 Debug( LDAP_DEBUG_ANY,
1679 "unable to create \"%s\" entry\n",
1680 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1684 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
1685 attr_merge_normalize( e, slap_schema.si_ad_description,
1686 monitor_subsys[ i ]->mss_desc, NULL );
1689 mp = monitor_entrypriv_create();
1693 e->e_private = ( void * )mp;
1694 mp->mp_info = monitor_subsys[ i ];
1695 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1697 if ( monitor_cache_add( mi, e ) ) {
1698 Debug( LDAP_DEBUG_ANY,
1699 "unable to add entry \"%s\" to cache\n",
1700 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1708 assert( be != NULL );
1710 be->be_private = mi;
1713 * opens the monitor backend subsystems
1715 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1716 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1720 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1723 monitor_subsys_opened = 1;
1725 if ( mi->mi_entry_limbo ) {
1726 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
1731 switch ( el->el_type ) {
1733 monitor_back_register_entry(
1738 case LIMBO_ENTRY_PARENT:
1739 monitor_back_register_entry_parent(
1749 monitor_back_register_entry_attrs(
1759 monitor_back_register_entry_callback(
1772 entry_free( el->el_e );
1775 attrs_free( el->el_a );
1777 if ( !BER_BVISNULL( &el->el_ndn ) ) {
1778 ber_memfree( el->el_ndn.bv_val );
1780 if ( !BER_BVISNULL( &el->el_base ) ) {
1781 ber_memfree( el->el_base.bv_val );
1783 if ( !BER_BVISNULL( &el->el_filter ) ) {
1784 ber_memfree( el->el_filter.bv_val );
1792 mi->mi_entry_limbo = NULL;
1799 monitor_back_config(
1807 * eventually, will hold backend specific configuration parameters
1809 return SLAP_CONF_UNKNOWN;
1813 monitor_back_db_config(
1821 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1825 * eventually, will hold database specific configuration parameters
1827 return SLAP_CONF_UNKNOWN;
1831 monitor_back_db_destroy(
1834 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1841 * FIXME: destroys all the data
1843 /* NOTE: mi points to static storage; don't free it */
1845 (void)monitor_cache_destroy( mi );
1847 if ( monitor_subsys ) {
1850 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1851 if ( monitor_subsys[ i ]->mss_destroy ) {
1852 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
1855 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
1856 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
1859 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_dn ) ) {
1860 ch_free( monitor_subsys[ i ]->mss_dn.bv_val );
1863 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_ndn ) ) {
1864 ch_free( monitor_subsys[ i ]->mss_ndn.bv_val );
1868 ch_free( monitor_subsys );
1871 ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
1873 be->be_private = NULL;
1878 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
1880 /* conditionally define the init_module() function */
1881 SLAP_BACKEND_INIT_MODULE( monitor )
1883 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */