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 BackendDB *be_monitor = NULL;
39 static struct monitor_subsys_t **monitor_subsys = NULL;
40 static int monitor_subsys_opened = 0;
45 * the known subsystems are added to the subsystems
46 * array at backend initialization; other subsystems
47 * may be added by calling monitor_back_register_subsys()
48 * before the database is opened (e.g. by other backends
49 * or by overlays or modules).
51 static struct monitor_subsys_t known_monitor_subsys[] = {
53 SLAPD_MONITOR_BACKEND_NAME,
54 BER_BVNULL, BER_BVNULL, BER_BVNULL,
55 MONITOR_F_PERSISTENT_CH,
56 monitor_subsys_backend_init,
61 SLAPD_MONITOR_CONN_NAME,
62 BER_BVNULL, BER_BVNULL, BER_BVNULL,
63 MONITOR_F_VOLATILE_CH,
64 monitor_subsys_conn_init,
65 monitor_subsys_conn_update,
66 monitor_subsys_conn_create,
69 SLAPD_MONITOR_DATABASE_NAME,
70 BER_BVNULL, BER_BVNULL, BER_BVNULL,
71 MONITOR_F_PERSISTENT_CH,
72 monitor_subsys_database_init,
75 monitor_subsys_database_modify
77 SLAPD_MONITOR_LISTENER_NAME,
78 BER_BVNULL, BER_BVNULL, BER_BVNULL,
79 MONITOR_F_PERSISTENT_CH,
80 monitor_subsys_listener_init,
85 SLAPD_MONITOR_LOG_NAME,
86 BER_BVNULL, BER_BVNULL, BER_BVNULL,
88 monitor_subsys_log_init,
91 monitor_subsys_log_modify
93 SLAPD_MONITOR_OPS_NAME,
94 BER_BVNULL, BER_BVNULL, BER_BVNULL,
95 MONITOR_F_PERSISTENT_CH,
96 monitor_subsys_ops_init,
97 monitor_subsys_ops_update,
101 SLAPD_MONITOR_OVERLAY_NAME,
102 BER_BVNULL, BER_BVNULL, BER_BVNULL,
103 MONITOR_F_PERSISTENT_CH,
104 monitor_subsys_overlay_init,
109 SLAPD_MONITOR_SASL_NAME,
110 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 SLAPD_MONITOR_SENT_NAME,
118 BER_BVNULL, BER_BVNULL, BER_BVNULL,
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_sent_init,
121 monitor_subsys_sent_update,
125 SLAPD_MONITOR_THREAD_NAME,
126 BER_BVNULL, BER_BVNULL, BER_BVNULL,
127 MONITOR_F_PERSISTENT_CH,
128 monitor_subsys_thread_init,
129 monitor_subsys_thread_update,
133 SLAPD_MONITOR_TIME_NAME,
134 BER_BVNULL, BER_BVNULL, BER_BVNULL,
135 MONITOR_F_PERSISTENT_CH,
136 monitor_subsys_time_init,
137 monitor_subsys_time_update,
141 SLAPD_MONITOR_TLS_NAME,
142 BER_BVNULL, BER_BVNULL, BER_BVNULL,
149 SLAPD_MONITOR_RWW_NAME,
150 BER_BVNULL, BER_BVNULL, BER_BVNULL,
151 MONITOR_F_PERSISTENT_CH,
152 monitor_subsys_rww_init,
153 monitor_subsys_rww_update,
159 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
162 init_module( int argc, char *argv[] )
166 memset( &bi, '\0', sizeof(bi) );
167 bi.bi_type = "monitor";
168 bi.bi_init = monitor_back_initialize;
173 #endif /* SLAPD_MONITOR */
176 monitor_back_register_subsys( monitor_subsys_t *ms )
180 if ( monitor_subsys ) {
181 for ( ; monitor_subsys[ i ] != NULL; i++ )
182 /* just count'em */ ;
185 monitor_subsys = ch_realloc( monitor_subsys,
186 ( 2 + i ) * sizeof( monitor_subsys_t * ) );
188 if ( monitor_subsys == NULL ) {
192 monitor_subsys[ i ] = ms;
193 monitor_subsys[ i + 1 ] = NULL;
195 /* if a subsystem is registered __AFTER__ subsystem
196 * initialization (depending on the sequence the databases
197 * are listed in slapd.conf), init it */
198 if ( monitor_subsys_opened ) {
200 /* FIXME: this should only be possible
201 * if be_monitor is already initialized */
202 assert( be_monitor );
204 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
208 ms->mss_flags |= MONITOR_F_OPENED;
214 typedef struct entry_limbo_t {
215 struct berval el_ndn;
217 monitor_callback_t *el_cb;
219 struct entry_limbo_t *el_next;
223 monitor_back_register_entry(
225 monitor_callback_t *cb,
228 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
230 assert( mi != NULL );
232 assert( e->e_private == NULL );
234 if ( monitor_subsys_opened ) {
237 struct berval pdn = BER_BVNULL;
238 monitor_entry_t *mp = NULL,
241 if ( monitor_cache_get( mi, &e->e_nname, &e2 ) == 0 ) {
243 Debug( LDAP_DEBUG_ANY,
244 "monitor_back_register_entry(\"%s\"): "
246 e->e_name.bv_val, 0, 0 );
247 monitor_cache_release( mi, e2 );
251 dnParent( &e->e_nname, &pdn );
252 if ( monitor_cache_get( mi, &pdn, &e2 ) != 0 ) {
253 /* parent does not exist */
254 Debug( LDAP_DEBUG_ANY,
255 "monitor_back_register_entry(\"%s\"): "
256 "parent \"%s\" not found\n",
257 e->e_name.bv_val, pdn.bv_val, 0 );
261 assert( e2->e_private != NULL );
262 pmp = ( monitor_entry_t * )e2->e_private;
264 if ( pmp->mp_flags & MONITOR_F_VOLATILE ) {
265 /* entry is volatile; cannot append children */
266 Debug( LDAP_DEBUG_ANY,
267 "monitor_back_register_entry(\"%s\"): "
268 "parent \"%s\" is volatile\n",
269 e->e_name.bv_val, e2->e_name.bv_val, 0 );
270 monitor_cache_release( mi, e2 );
274 mp = monitor_entrypriv_create();
276 Debug( LDAP_DEBUG_ANY,
277 "monitor_back_register_entry(\"%s\"): "
278 "monitor_entrypriv_create failed\n",
279 e->e_name.bv_val, 0, 0 );
282 e->e_private = ( void * )mp;
283 mp->mp_info = pmp->mp_info;
284 mp->mp_flags = pmp->mp_flags | MONITOR_F_SUB;
286 ep = &pmp->mp_children;
288 pmp = ( monitor_entry_t * )(*ep)->e_private;
293 if ( monitor_cache_add( mi, e ) ) {
294 Debug( LDAP_DEBUG_ANY,
295 "monitor_back_register_entry(\"%s\"): "
296 "unable to add entry\n",
297 e->e_name.bv_val, 0, 0 );
298 ch_free( e->e_private );
306 el = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
308 BER_BVZERO( &el->el_ndn );
311 el->el_private = private;
312 el->el_next = (entry_limbo_t *)mi->mi_entry_limbo;
319 monitor_back_register_entry_callback(
321 struct monitor_callback_t *cb,
324 monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private;
326 assert( mi != NULL );
327 assert( ndn != NULL );
328 assert( !BER_BVISNULL( ndn ) );
330 if ( monitor_subsys_opened ) {
332 monitor_entry_t *mp = NULL;
333 struct monitor_callback_t **mcp = NULL;
335 if ( monitor_cache_get( mi, ndn, &e ) != 0 ) {
336 /* entry does not exist */
337 Debug( LDAP_DEBUG_ANY,
338 "monitor_back_register_entry_callback(\"%s\"): "
339 "entry does not exist\n",
340 e->e_name.bv_val, 0, 0 );
344 assert( e->e_private != NULL );
345 mp = ( monitor_entry_t * )e->e_private;
347 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
348 /* entry is volatile; cannot append callback */
349 Debug( LDAP_DEBUG_ANY,
350 "monitor_back_register_entry_callback(\"%s\"): "
351 "entry is volatile\n",
352 e->e_name.bv_val, 0, 0 );
353 monitor_cache_release( mi, e );
357 for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
360 /* NOTE: we do not clear cb->mc_next, so this function
361 * can be used to append a list of callbacks */
364 monitor_cache_release( mi, e );
369 el = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
371 ber_dupbv( &el->el_ndn, ndn );
374 el->el_private = private;
375 el->el_next = (entry_limbo_t *)mi->mi_entry_limbo;
382 monitor_back_get_subsys( const char *name )
384 if ( monitor_subsys != NULL ) {
387 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
388 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
389 return monitor_subsys[ i ];
398 monitor_back_get_subsys_by_dn( struct berval *ndn, int sub )
400 if ( monitor_subsys != NULL ) {
404 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
405 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
406 return monitor_subsys[ i ];
411 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
412 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
413 return monitor_subsys[ i ];
423 monitor_back_initialize(
427 monitor_subsys_t *ms;
428 static char *controls[] = {
429 LDAP_CONTROL_MANAGEDSAIT,
430 LDAP_CONTROL_VALUESRETURNFILTER,
434 bi->bi_controls = controls;
438 bi->bi_config = monitor_back_config;
442 bi->bi_db_init = monitor_back_db_init;
443 bi->bi_db_config = monitor_back_db_config;
444 bi->bi_db_open = monitor_back_db_open;
446 bi->bi_db_destroy = monitor_back_db_destroy;
448 bi->bi_op_bind = monitor_back_bind;
449 bi->bi_op_unbind = 0;
450 bi->bi_op_search = monitor_back_search;
451 bi->bi_op_compare = monitor_back_compare;
452 bi->bi_op_modify = monitor_back_modify;
453 bi->bi_op_modrdn = 0;
455 bi->bi_op_delete = 0;
456 bi->bi_op_abandon = 0;
460 bi->bi_entry_release_rw = 0;
461 bi->bi_chk_referrals = 0;
462 bi->bi_operational = monitor_back_operational;
465 * hooks for slap tools
467 bi->bi_tool_entry_open = 0;
468 bi->bi_tool_entry_close = 0;
469 bi->bi_tool_entry_first = 0;
470 bi->bi_tool_entry_next = 0;
471 bi->bi_tool_entry_get = 0;
472 bi->bi_tool_entry_put = 0;
473 bi->bi_tool_entry_reindex = 0;
474 bi->bi_tool_sync = 0;
475 bi->bi_tool_dn2id_get = 0;
476 bi->bi_tool_id2entry_get = 0;
477 bi->bi_tool_entry_modify = 0;
479 bi->bi_connection_init = 0;
480 bi->bi_connection_destroy = 0;
482 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
483 if ( monitor_back_register_subsys( ms ) ) {
492 monitor_back_db_init(
498 struct berval dn, ndn;
508 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
510 "DESC 'OpenLDAP system monitoring' "
511 "SUP top STRUCTURAL "
516 #if 0 /* temporarily disabled */
527 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
528 offsetof(monitor_info_t, mi_oc_monitor) },
529 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
530 "NAME 'monitorServer' "
531 "DESC 'Server monitoring root entry' "
532 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
533 offsetof(monitor_info_t, mi_oc_monitorServer) },
534 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
535 "NAME 'monitorContainer' "
536 "DESC 'monitor container class' "
537 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
538 offsetof(monitor_info_t, mi_oc_monitorContainer) },
539 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
540 "NAME 'monitorCounterObject' "
541 "DESC 'monitor counter class' "
542 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
543 offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
544 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
545 "NAME 'monitorOperation' "
546 "DESC 'monitor operation class' "
547 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
548 offsetof(monitor_info_t, mi_oc_monitorOperation) },
549 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
550 "NAME 'monitorConnection' "
551 "DESC 'monitor connection class' "
552 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
553 offsetof(monitor_info_t, mi_oc_monitorConnection) },
554 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
555 "NAME 'managedObject' "
556 "DESC 'monitor managed entity class' "
557 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
558 offsetof(monitor_info_t, mi_oc_managedObject) },
559 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.13 "
560 "NAME 'monitoredObject' "
561 "DESC 'monitor monitored entity class' "
562 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
563 offsetof(monitor_info_t, mi_oc_monitoredObject) },
564 { NULL, NULL, 0, -1 }
566 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
567 "NAME 'monitoredInfo' "
568 "DESC 'monitored info' "
570 "EQUALITY caseIgnoreMatch "
571 "SUBSTR caseIgnoreSubstringsMatch "
572 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
573 "NO-USER-MODIFICATION "
574 "USAGE directoryOperation )", SLAP_AT_HIDE,
575 offsetof(monitor_info_t, mi_ad_monitoredInfo) },
576 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
577 "NAME 'managedInfo' "
578 "DESC 'monitor managed info' "
579 "SUP name )", SLAP_AT_HIDE,
580 offsetof(monitor_info_t, mi_ad_managedInfo) },
581 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
582 "NAME 'monitorCounter' "
583 "DESC 'monitor counter' "
584 "EQUALITY integerMatch "
585 "ORDERING integerOrderingMatch "
586 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
587 "NO-USER-MODIFICATION "
588 "USAGE directoryOperation )", SLAP_AT_HIDE,
589 offsetof(monitor_info_t, mi_ad_monitorCounter) },
590 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
591 "NAME 'monitorOpCompleted' "
592 "DESC 'monitor completed operations' "
593 "SUP monitorCounter "
594 "NO-USER-MODIFICATION "
595 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
596 offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
597 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
598 "NAME 'monitorOpInitiated' "
599 "DESC 'monitor initiated operations' "
600 "SUP monitorCounter "
601 "NO-USER-MODIFICATION "
602 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
603 offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
604 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
605 "NAME 'monitorConnectionNumber' "
606 "DESC 'monitor connection number' "
607 "SUP monitorCounter "
608 "NO-USER-MODIFICATION "
609 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
610 offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
611 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
612 "NAME 'monitorConnectionAuthzDN' "
613 "DESC 'monitor connection authorization DN' "
614 /* "SUP distinguishedName " */
615 "EQUALITY distinguishedNameMatch "
616 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
617 "NO-USER-MODIFICATION "
618 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
619 offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
620 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
621 "NAME 'monitorConnectionLocalAddress' "
622 "DESC 'monitor connection local address' "
624 "NO-USER-MODIFICATION "
625 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
626 offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
627 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
628 "NAME 'monitorConnectionPeerAddress' "
629 "DESC 'monitor connection peer address' "
631 "NO-USER-MODIFICATION "
632 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
633 offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
634 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.24 "
635 "NAME 'monitorTimestamp' "
636 "DESC 'monitor timestamp' "
637 "EQUALITY generalizedTimeMatch "
638 "ORDERING generalizedTimeOrderingMatch "
639 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
641 "NO-USER-MODIFICATION "
642 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
643 offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
644 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.27 "
645 "NAME 'monitorOverlay' "
646 "DESC 'name of overlays defined for a give database' "
648 "NO-USER-MODIFICATION "
649 "USAGE directoryOperation )", SLAP_AT_HIDE,
650 offsetof(monitor_info_t, mi_ad_monitorOverlay) },
651 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.31 "
653 "DESC 'read/write status of a given database' "
654 "EQUALITY booleanMatch "
655 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
657 "USAGE directoryOperation )", SLAP_AT_HIDE,
658 offsetof(monitor_info_t, mi_ad_readOnly) },
659 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.32 "
660 "NAME 'restrictedOperation' "
661 "DESC 'name of restricted operation for a given database' "
662 "SUP managedInfo )", SLAP_AT_HIDE,
663 offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
664 #ifdef INTEGRATE_CORE_SCHEMA
665 { NULL, NULL, 0, -1 }, /* description */
666 { NULL, NULL, 0, -1 }, /* seeAlso */
667 { NULL, NULL, 0, -1 }, /* l */
668 { NULL, NULL, 0, -1 }, /* labeledURI */
669 #endif /* INTEGRATE_CORE_SCHEMA */
670 { NULL, NULL, 0, -1 }
672 { "description", "( 2.5.4.13 "
673 "NAME 'description' "
674 "DESC 'RFC2256: descriptive information' "
675 "EQUALITY caseIgnoreMatch "
676 "SUBSTR caseIgnoreSubstringsMatch "
677 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )", 0,
678 offsetof(monitor_info_t, mi_ad_description) },
679 { "seeAlso", "( 2.5.4.34 "
681 "DESC 'RFC2256: DN of related object' "
682 "SUP distinguishedName )", 0,
683 offsetof(monitor_info_t, mi_ad_seeAlso) },
685 "NAME ( 'l' 'localityName' ) "
686 "DESC 'RFC2256: locality which this object resides in' "
688 offsetof(monitor_info_t, mi_ad_l) },
689 { "labeledURI", "( 1.3.6.1.4.1.250.1.57 "
691 "DESC 'RFC2079: Uniform Resource Identifier with optional label' "
692 "EQUALITY caseExactMatch "
693 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )", 0,
694 offsetof(monitor_info_t, mi_ad_labeledURI) },
695 { NULL, NULL, 0, -1 }
699 * database monitor can be defined once only
702 Debug( LDAP_DEBUG_ANY,
703 "only one monitor backend is allowed\n", 0, 0, 0 );
708 /* indicate system schema supported */
709 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
711 dn.bv_val = SLAPD_MONITOR_DN;
712 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
714 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
715 if( rc != LDAP_SUCCESS ) {
716 Debug( LDAP_DEBUG_ANY,
717 "unable to normalize monitor DN \"%s\"\n",
718 SLAPD_MONITOR_DN, 0, 0 );
722 ber_dupbv( &bv, &dn );
723 ber_bvarray_add( &be->be_suffix, &bv );
724 ber_bvarray_add( &be->be_nsuffix, &ndn );
726 mi = ( monitor_info_t * )ch_calloc( sizeof( monitor_info_t ), 1 );
728 Debug( LDAP_DEBUG_ANY,
729 "unable to initialize monitor backend\n", 0, 0, 0 );
733 memset( mi, 0, sizeof( monitor_info_t ) );
735 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
739 #ifdef INTEGRATE_CORE_SCHEMA
740 /* prepare for schema integration */
741 for ( k = 0; mat[ k ].name != NULL; k++ );
742 #endif /* INTEGRATE_CORE_SCHEMA */
744 for ( i = 0; mat_core[ i ].name != NULL; i++ ) {
745 AttributeDescription **ad;
748 ad = ((AttributeDescription **)&(((char *)mi)[ mat_core[ i ].offset ]));
751 switch (slap_str2ad( mat_core[ i ].name, ad, &text ) ) {
755 #ifdef INTEGRATE_CORE_SCHEMA
756 case LDAP_UNDEFINED_TYPE:
757 mat[ k ] = mat_core[ i ];
760 #endif /* INTEGRATE_CORE_SCHEMA */
763 Debug( LDAP_DEBUG_ANY,
764 "monitor_back_db_init: %s: %s\n",
765 mat_core[ i ].name, text, 0 );
770 /* schema integration */
771 for ( i = 0; mat[ i ].name; i++ ) {
772 LDAPAttributeType *at;
775 AttributeDescription **ad;
777 at = ldap_str2attributetype( mat[ i ].schema, &code,
778 &err, LDAP_SCHEMA_ALLOW_ALL );
780 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
781 "in AttributeType \"%s\" %s before %s\n",
782 mat[ i ].name, ldap_scherr2str(code), err );
786 if ( at->at_oid == NULL ) {
787 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
788 "null OID for attributeType \"%s\"\n",
789 mat[ i ].name, 0, 0 );
793 code = at_add(at, &err);
795 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
796 "%s in attributeType \"%s\"\n",
797 scherr2str(code), mat[ i ].name, 0 );
802 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
804 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
805 Debug( LDAP_DEBUG_ANY,
806 "monitor_back_db_init: %s\n", text, 0, 0 );
810 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
813 for ( i = 0; moc[ i ].name; i++ ) {
819 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
820 LDAP_SCHEMA_ALLOW_ALL );
822 Debug( LDAP_DEBUG_ANY,
823 "unable to parse monitor objectclass \"%s\": "
824 "%s before %s\n" , moc[ i ].name,
825 ldap_scherr2str(code), err );
829 if ( oc->oc_oid == NULL ) {
830 Debug( LDAP_DEBUG_ANY,
831 "objectclass \"%s\" has no OID\n" ,
832 moc[ i ].name, 0, 0 );
836 code = oc_add(oc, 0, &err);
838 Debug( LDAP_DEBUG_ANY,
839 "objectclass \"%s\": %s \"%s\"\n" ,
840 moc[ i ].name, scherr2str(code), err );
846 Oc = oc_find( moc[ i ].name );
848 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
849 "unable to find objectClass %s "
850 "(just added)\n", moc[ i ].name, 0, 0 );
854 Oc->soc_flags |= moc[ i ].flags;
856 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
863 monitor_back_db_open(
867 monitor_info_t *mi = (monitor_info_t *)be->be_private;
868 struct monitor_subsys_t **ms;
872 char buf[ BACKMONITOR_BUFSIZE ],
879 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
884 #ifndef HAVE_GMTIME_R
885 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
887 #ifdef HACK_LOCAL_TIME
888 # ifdef HAVE_LOCALTIME_R
889 tms = localtime_r( &starttime, &tm_buf );
891 tms = localtime( &starttime );
892 # endif /* HAVE_LOCALTIME_R */
893 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
894 #else /* !HACK_LOCAL_TIME */
895 # ifdef HAVE_GMTIME_R
896 tms = gmtime_r( &starttime, &tm_buf );
898 tms = gmtime( &starttime );
899 # endif /* HAVE_GMTIME_R */
900 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
901 #endif /* !HACK_LOCAL_TIME */
902 #ifndef HAVE_GMTIME_R
903 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
906 mi->mi_startTime.bv_val = tmbuf;
907 mi->mi_startTime.bv_len = strlen( tmbuf );
909 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
910 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
912 mi->mi_creatorsName = be->be_rootdn;
916 * creates the "cn=Monitor" entry
918 snprintf( buf, sizeof( buf ),
921 "structuralObjectClass: %s\n"
923 "%s: This subtree contains monitoring/managing objects.\n"
924 "%s: This object contains information about this server.\n"
926 "%s: createTimestamp reflects the time this server instance was created.\n"
927 "%s: modifyTimestamp reflects the time this server instance was last accessed.\n"
930 "modifiersName: %s\n"
931 "createTimestamp: %s\n"
932 "modifyTimestamp: %s\n",
934 mi->mi_oc_monitorServer->soc_cname.bv_val,
935 mi->mi_oc_monitorServer->soc_cname.bv_val,
936 mi->mi_ad_description->ad_cname.bv_val,
937 mi->mi_ad_description->ad_cname.bv_val,
939 mi->mi_ad_description->ad_cname.bv_val,
940 mi->mi_ad_description->ad_cname.bv_val,
942 mi->mi_creatorsName.bv_val,
943 mi->mi_creatorsName.bv_val,
944 mi->mi_startTime.bv_val,
945 mi->mi_startTime.bv_val );
947 e = str2entry( buf );
949 Debug( LDAP_DEBUG_ANY,
950 "unable to create \"%s\" entry\n",
951 SLAPD_MONITOR_DN, 0, 0 );
955 bv.bv_val = (char *) Versionstr;
956 end_of_line = strchr( Versionstr, '\n' );
958 bv.bv_len = end_of_line - Versionstr;
960 bv.bv_len = strlen( Versionstr );
963 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
965 Debug( LDAP_DEBUG_ANY,
966 "unable to add monitoredInfo to \"%s\" entry\n",
967 SLAPD_MONITOR_DN, 0, 0 );
971 if ( mi->mi_l.bv_len ) {
972 if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) {
973 Debug( LDAP_DEBUG_ANY,
974 "unable to add locality to \"%s\" entry\n",
975 SLAPD_MONITOR_DN, 0, 0 );
980 mp = monitor_entrypriv_create();
984 e->e_private = ( void * )mp;
985 ep = &mp->mp_children;
987 if ( monitor_cache_add( mi, e ) ) {
988 Debug( LDAP_DEBUG_ANY,
989 "unable to add entry \"%s\" to cache\n",
990 SLAPD_MONITOR_DN, 0, 0 );
995 * Create all the subsystem specific entries
997 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
998 int len = strlen( monitor_subsys[ i ]->mss_name );
1002 dn.bv_len = len + sizeof( "cn=" ) - 1;
1003 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1004 strcpy( dn.bv_val, "cn=" );
1005 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1006 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1008 if ( rc != LDAP_SUCCESS ) {
1009 Debug( LDAP_DEBUG_ANY,
1010 "monitor RDN \"%s\" is invalid\n",
1015 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
1016 dn.bv_val = ch_malloc( dn.bv_len + 1 );
1017 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
1018 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
1019 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
1020 &monitor_subsys[ i ]->mss_ndn, NULL );
1022 if ( rc != LDAP_SUCCESS ) {
1023 Debug( LDAP_DEBUG_ANY,
1024 "monitor DN \"%s\" is invalid\n",
1029 snprintf( buf, sizeof( buf ),
1032 "structuralObjectClass: %s\n"
1034 "creatorsName: %s\n"
1035 "modifiersName: %s\n"
1036 "createTimestamp: %s\n"
1037 "modifyTimestamp: %s\n",
1038 monitor_subsys[ i ]->mss_dn.bv_val,
1039 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1040 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1041 monitor_subsys[ i ]->mss_name,
1042 mi->mi_creatorsName.bv_val,
1043 mi->mi_creatorsName.bv_val,
1044 mi->mi_startTime.bv_val,
1045 mi->mi_startTime.bv_val );
1047 e = str2entry( buf );
1050 Debug( LDAP_DEBUG_ANY,
1051 "unable to create \"%s\" entry\n",
1052 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1056 mp = monitor_entrypriv_create();
1060 e->e_private = ( void * )mp;
1061 mp->mp_info = monitor_subsys[ i ];
1062 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1064 if ( monitor_cache_add( mi, e ) ) {
1065 Debug( LDAP_DEBUG_ANY,
1066 "unable to add entry \"%s\" to cache\n",
1067 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1077 be->be_private = mi;
1080 * opens the monitor backend subsystems
1082 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1083 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1087 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1090 monitor_subsys_opened = 1;
1092 if ( mi->mi_entry_limbo ) {
1093 entry_limbo_t *el = (entry_limbo_t *)mi->mi_entry_limbo;
1099 monitor_back_register_entry( el->el_e, el->el_cb, el->el_private );
1101 } else if ( !BER_BVISNULL( &el->el_ndn ) ) {
1102 monitor_back_register_entry_callback( &el->el_ndn, el->el_cb, el->el_private );
1103 ber_memfree( el->el_ndn.bv_val );
1111 mi->mi_entry_limbo = NULL;
1118 monitor_back_config(
1127 * eventually, will hold backend specific configuration parameters
1129 return SLAP_CONF_UNKNOWN;
1133 monitor_back_db_config(
1141 monitor_info_t *mi = ( monitor_info_t * )be->be_private;
1144 * eventually, will hold database specific configuration parameters
1146 if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
1151 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_l );
1154 return SLAP_CONF_UNKNOWN;
1161 monitor_back_db_destroy(
1166 * FIXME: destroys all the data